Implement preClose
This commit is contained in:
parent
8083364ebf
commit
8c9aca21b3
@ -64,5 +64,6 @@ public interface LLKeyValueDatabase extends LLSnapshottable, LLKeyValueDatabaseS
|
||||
|
||||
MeterRegistry getMeterRegistry();
|
||||
|
||||
Mono<Void> preClose();
|
||||
Mono<Void> close();
|
||||
}
|
||||
|
@ -75,6 +75,8 @@ import org.rocksdb.IndexType;
|
||||
import org.rocksdb.InfoLogLevel;
|
||||
import org.rocksdb.IngestExternalFileOptions;
|
||||
import org.rocksdb.LRUCache;
|
||||
import org.rocksdb.LogFile;
|
||||
import org.rocksdb.MutableDBOptions;
|
||||
import org.rocksdb.OptimisticTransactionDB;
|
||||
import org.rocksdb.PersistentCache;
|
||||
import org.rocksdb.RocksDB;
|
||||
@ -317,10 +319,10 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
|
||||
// tableOptions.setOptimizeFiltersForMemory(true);
|
||||
columnFamilyOptions.setWriteBufferSize(256 * SizeUnit.MB);
|
||||
}
|
||||
}
|
||||
if (columnOptions.writeBufferSize().isPresent()) {
|
||||
columnFamilyOptions.setWriteBufferSize(columnOptions.writeBufferSize().get());
|
||||
}
|
||||
}
|
||||
tableOptions.setVerifyCompression(false);
|
||||
if (columnOptions.filter().isPresent()) {
|
||||
var filterOptions = columnOptions.filter().get();
|
||||
@ -660,12 +662,30 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
|
||||
try {
|
||||
ensureOpen();
|
||||
ensureOwned(flushOptions);
|
||||
db.flush(flushOptions);
|
||||
db.flush(flushOptions, List.copyOf(getAllColumnFamilyHandles().values()));
|
||||
db.flushWal(true);
|
||||
} finally {
|
||||
closeLock.unlockRead(closeReadLock);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> preClose() {
|
||||
return Mono.<Void>fromCallable(() -> {
|
||||
var closeReadLock = closeLock.readLock();
|
||||
try {
|
||||
ensureOpen();
|
||||
try (var fo = new FlushOptions().setWaitForFlush(true)) {
|
||||
flush(fo);
|
||||
}
|
||||
db.cancelAllBackgroundWork(true);
|
||||
return null;
|
||||
} finally {
|
||||
closeLock.unlockRead(closeReadLock);
|
||||
}
|
||||
}).subscribeOn(dbWScheduler);
|
||||
}
|
||||
|
||||
private record RocksLevelOptions(CompressionType compressionType, CompressionOptions compressionOptions) {}
|
||||
private RocksLevelOptions getRocksLevelOptions(DatabaseLevel levelOptions, RocksDBRefs refs) {
|
||||
var compressionType = levelOptions.compression().getType();
|
||||
@ -955,7 +975,7 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
|
||||
.setWalBytesPerSync(0) // default
|
||||
.setIncreaseParallelism(1)
|
||||
.setDbWriteBufferSize(8 * SizeUnit.MB)
|
||||
.setWalTtlSeconds(0)
|
||||
.setWalTtlSeconds(60)
|
||||
.setWalSizeLimitMB(0)
|
||||
.setMaxTotalWalSize(0) // automatic
|
||||
;
|
||||
@ -991,7 +1011,7 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
|
||||
.setBytesPerSync(64 * SizeUnit.MB)
|
||||
.setWalBytesPerSync(64 * SizeUnit.MB)
|
||||
|
||||
.setWalTtlSeconds(0) // Auto
|
||||
.setWalTtlSeconds(60) // Auto
|
||||
.setWalSizeLimitMB(0) // Auto
|
||||
.setMaxTotalWalSize(0) // Auto
|
||||
;
|
||||
@ -1507,8 +1527,13 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
|
||||
return Mono.<Void>fromCallable(() -> {
|
||||
try (var fo = new FlushOptions().setWaitForFlush(true)) {
|
||||
this.flush(fo);
|
||||
return null;
|
||||
} catch (RocksDBException ex) {
|
||||
if (!"ShutdownInProgress".equals(ex.getMessage())) {
|
||||
throw ex;
|
||||
}
|
||||
logger.warn("Shutdown in progress. Flush cancelled", ex);
|
||||
}
|
||||
return null;
|
||||
}).subscribeOn(dbWScheduler);
|
||||
}
|
||||
|
||||
|
@ -170,10 +170,14 @@ public class LLMemoryKeyValueDatabase implements LLKeyValueDatabase {
|
||||
return meterRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> preClose() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> close() {
|
||||
return Mono
|
||||
.fromRunnable(() -> {
|
||||
return Mono.fromRunnable(() -> {
|
||||
snapshots.forEach((snapshot, dbs) -> dbs.forEach((columnName, db) -> {
|
||||
db.clear();
|
||||
}));
|
||||
|
@ -398,6 +398,11 @@ public class LLQuicConnection implements LLDatabaseConnection {
|
||||
return meterRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> preClose() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> close() {
|
||||
return sendRequest(new CloseDatabase(id)).then();
|
||||
|
Loading…
Reference in New Issue
Block a user