Optimistic updates

This commit is contained in:
Andrea Cavalli 2021-10-17 19:52:43 +02:00
parent df2b757fdd
commit aad5f8c96c
4 changed files with 363 additions and 626 deletions

View File

@ -74,9 +74,9 @@ public class LLDelta extends ResourceSupport<LLDelta, LLDelta> {
return true;
}
public static LLDelta of(Send<Buffer> min, Send<Buffer> max) {
assert (min == null && max == null) || (min != max);
return new LLDelta(min, max, null);
public static LLDelta of(Send<Buffer> previous, Send<Buffer> current) {
assert (previous == null && current == null) || (previous != current);
return new LLDelta(previous, current, null);
}
public Send<Buffer> previous() {

View File

@ -44,11 +44,14 @@ import org.rocksdb.DBOptions;
import org.rocksdb.DbPath;
import org.rocksdb.FlushOptions;
import org.rocksdb.IndexType;
import org.rocksdb.MergeOperator;
import org.rocksdb.OptimisticTransactionDB;
import org.rocksdb.Options;
import org.rocksdb.RateLimiter;
import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException;
import org.rocksdb.Snapshot;
import org.rocksdb.TransactionDB;
import org.rocksdb.WALRecoveryMode;
import org.rocksdb.WriteBufferManager;
import org.warp.commonutils.log.Logger;
@ -77,7 +80,7 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
private final DatabaseOptions databaseOptions;
private final boolean enableColumnsBug;
private RocksDB db;
private OptimisticTransactionDB db;
private final Map<Column, ColumnFamilyHandle> handles;
private final ConcurrentHashMap<Long, Snapshot> snapshotsHandles = new ConcurrentHashMap<>();
private final AtomicLong nextSnapshotNumbers = new AtomicLong(1);
@ -146,7 +149,7 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
while (true) {
try {
// a factory method that returns a RocksDB instance
this.db = RocksDB.open(new DBOptions(rocksdbOptions),
this.db = OptimisticTransactionDB.open(new DBOptions(rocksdbOptions),
dbPathString,
descriptors,
handles
@ -194,7 +197,7 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
return name;
}
private void flushAndCloseDb(RocksDB db, List<ColumnFamilyHandle> handles)
private void flushAndCloseDb(OptimisticTransactionDB db, List<ColumnFamilyHandle> handles)
throws RocksDBException {
flushDb(db, handles);
@ -223,7 +226,7 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
}
}
private void flushDb(RocksDB db, List<ColumnFamilyHandle> handles) throws RocksDBException {
private void flushDb(OptimisticTransactionDB db, List<ColumnFamilyHandle> handles) throws RocksDBException {
if (Schedulers.isInNonBlockingThread()) {
logger.error("Called flushDb in a nonblocking thread");
}
@ -240,7 +243,7 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
}
@SuppressWarnings("unused")
private void compactDb(RocksDB db, List<ColumnFamilyHandle> handles) {
private void compactDb(OptimisticTransactionDB db, List<ColumnFamilyHandle> handles) {
if (Schedulers.isInNonBlockingThread()) {
logger.error("Called compactDb in a nonblocking thread");
}
@ -452,7 +455,7 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
LinkedList<ColumnFamilyHandle> handles = new LinkedList<>();
this.db = RocksDB.open(options, dbPathString);
this.db = OptimisticTransactionDB.open(options, dbPathString);
for (ColumnFamilyDescriptor columnFamilyDescriptor : descriptorsToCreate) {
handles.add(db.createColumnFamily(columnFamilyDescriptor));
}

View File

@ -48,9 +48,12 @@ public class CappedWriteBatch extends WriteBatch {
private synchronized void flushIfNeeded(boolean force) throws RocksDBException {
if (this.count() >= (force ? 1 : cap)) {
db.write(writeOptions, this.getWriteBatch());
this.clear();
releaseAllBuffers();
try {
db.write(writeOptions, this.getWriteBatch());
this.clear();
} finally {
releaseAllBuffers();
}
}
}