Quick fix

This commit is contained in:
Andrea Cavalli 2021-03-19 20:55:38 +01:00
parent a80849f241
commit 8075694e15
5 changed files with 32 additions and 4 deletions

View File

@ -894,7 +894,7 @@ public class LLLocalDictionary implements LLDictionary {
private long exactSizeAll(@Nullable LLSnapshot snapshot) {
var readOpts = resolveSnapshot(snapshot);
readOpts.setFillCache(false);
readOpts.setReadaheadSize(2 * 1024 * 1024);
// readOpts.setReadaheadSize(2 * 1024 * 1024);
readOpts.setVerifyChecksums(VERIFY_CHECKSUMS_WHEN_NOT_NEEDED);
if (PARALLEL_EXACT_SIZE) {

View File

@ -43,7 +43,7 @@ public class LLLocalKeyPrefixReactiveRocksIterator {
.generate(() -> {
var readOptions = new ReadOptions(this.readOptions);
if (!range.hasMin() || !range.hasMax()) {
readOptions.setReadaheadSize(2 * 1024 * 1024);
// readOptions.setReadaheadSize(2 * 1024 * 1024);
readOptions.setFillCache(false);
}
Slice sliceMin;

View File

@ -27,6 +27,7 @@ import org.rocksdb.BlockBasedTableConfig;
import org.rocksdb.BloomFilter;
import org.rocksdb.ColumnFamilyDescriptor;
import org.rocksdb.ColumnFamilyHandle;
import org.rocksdb.CompactRangeOptions;
import org.rocksdb.CompactionStyle;
import org.rocksdb.CompressionType;
import org.rocksdb.DBOptions;
@ -37,6 +38,8 @@ import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException;
import org.rocksdb.Snapshot;
import org.rocksdb.WALRecoveryMode;
import org.warp.commonutils.log.Logger;
import org.warp.commonutils.log.LoggerFactory;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;
@ -47,6 +50,7 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
RocksDB.loadLibrary();
}
protected static final Logger logger = LoggerFactory.getLogger(LLLocalKeyValueDatabase.class);
private static final ColumnFamilyDescriptor DEFAULT_COLUMN_FAMILY = new ColumnFamilyDescriptor(
RocksDB.DEFAULT_COLUMN_FAMILY);
private static final Supplier<Scheduler> lowMemorySupplier = Suppliers.memoize(() ->
@ -101,6 +105,7 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
this.handles.put(columns.get(i), handles.get(i));
}
compactDb(db, handles);
flushDb(db, handles);
} catch (RocksDBException ex) {
throw new IOException(ex);
@ -133,6 +138,27 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
// end force flush
}
private void compactDb(RocksDB db, List<ColumnFamilyHandle> handles) throws RocksDBException {
// force compact the database
for (ColumnFamilyHandle cfh : handles) {
var t = new Thread(() -> {
try {
// Range rangeToCompact = db.suggestCompactRange(cfh);
db.compactRange(cfh, null, null, new CompactRangeOptions().setAllowWriteStall(false).setChangeLevel(false));
} catch (RocksDBException e) {
if ("Database shutdown".equalsIgnoreCase(e.getMessage())) {
logger.warn("Compaction cancelled: database shutdown");
} else {
logger.warn("Failed to compact range", e);
}
}
}, "Compaction");
t.setDaemon(true);
t.start();
}
// end force compact
}
@SuppressWarnings("CommentedOutCode")
private static Options openRocksDb(Path path, boolean crashIfWalError, boolean lowMemory)
throws IOException {
@ -415,7 +441,7 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
}
}
} catch (IOException ex) {
ex.printStackTrace();
logger.error("Error when deleting unused log files", ex);
return false;
}
return false;

View File

@ -637,12 +637,14 @@ public class LLLocalLuceneIndex implements LLLuceneIndex {
public Mono<Void> close() {
return Mono
.<Void>fromCallable(() -> {
logger.debug("Closing IndexWriter...");
this.blockingLuceneSearchScheduler.dispose();
scheduledTasksLifecycle.cancelAndWait();
//noinspection BlockingMethodInNonBlockingContext
indexWriter.close();
//noinspection BlockingMethodInNonBlockingContext
directory.close();
logger.debug("IndexWriter closed");
return null;
})
.subscribeOn(luceneHeavyTasksScheduler);

View File

@ -38,7 +38,7 @@ public abstract class LLLocalReactiveRocksIterator<T> {
.generate(() -> {
var readOptions = new ReadOptions(this.readOptions);
if (!range.hasMin() || !range.hasMax()) {
readOptions.setReadaheadSize(2 * 1024 * 1024);
// readOptions.setReadaheadSize(2 * 1024 * 1024);
readOptions.setFillCache(false);
}
Slice sliceMin;