This commit is contained in:
Andrea Cavalli 2022-05-04 12:36:32 +02:00
parent a1c0e19adc
commit 02f1276181
5 changed files with 112 additions and 95 deletions

View File

@ -16,6 +16,7 @@ import io.netty5.buffer.api.Send;
import io.netty5.buffer.api.WritableComponent;
import io.netty5.buffer.api.internal.Statics;
import io.netty5.util.IllegalReferenceCountException;
import it.cavallium.dbengine.database.disk.RocksIteratorTuple;
import it.cavallium.dbengine.database.disk.UpdateAtomicResultCurrent;
import it.cavallium.dbengine.database.disk.UpdateAtomicResultDelta;
import it.cavallium.dbengine.database.disk.UpdateAtomicResultPrevious;
@ -1012,6 +1013,8 @@ public class LLUtils {
iterable.forEach(LLUtils::onNextDropped);
} else if (next instanceof SafeCloseable safeCloseable) {
safeCloseable.close();
} else if (next instanceof RocksIteratorTuple iteratorTuple) {
iteratorTuple.close();
} else if (next instanceof UpdateAtomicResultDelta delta) {
delta.delta().close();
} else if (next instanceof UpdateAtomicResultCurrent cur) {

View File

@ -302,6 +302,7 @@ public sealed abstract class AbstractRocksDBColumn<T extends RocksDB> implements
sliceMax = emptyReleasableSlice();
}
var rocksIterator = this.newIterator(readOptions);
try {
SafeCloseable seekFromOrTo;
if (reverse) {
if (!LLLocalDictionary.PREFER_AUTO_SEEK_BOUND && range.hasMax()) {
@ -321,6 +322,10 @@ public sealed abstract class AbstractRocksDBColumn<T extends RocksDB> implements
}
}
return new RocksIteratorTuple(List.of(readOptions), rocksIterator, sliceMin, sliceMax, seekFromOrTo);
} catch (Throwable ex) {
rocksIterator.close();
throw ex;
}
}
protected T getDb() {
@ -904,6 +909,7 @@ public sealed abstract class AbstractRocksDBColumn<T extends RocksDB> implements
ensureOpen();
ensureOwned(readOptions);
var it = db.newIterator(cfh, readOptions);
try {
return new RocksDBIterator(it,
nettyDirect,
this.startedIterSeek,
@ -913,6 +919,10 @@ public sealed abstract class AbstractRocksDBColumn<T extends RocksDB> implements
this.endedIterNext,
this.iterNextTime
);
} catch (Throwable ex) {
it.close();
throw ex;
}
} finally {
closeLock.unlockRead(closeReadLock);
}

View File

@ -89,8 +89,7 @@ public abstract class LLLocalGroupedReactiveRocksIterator<T> extends
public final Flux<List<T>> flux() {
return Flux
.generate(() -> {
return Flux.generate(() -> {
var readOptions = generateCustomReadOptions(this.readOptions, true, isBoundedRange(range), smallRange);
if (logger.isTraceEnabled()) {
logger.trace(MARKER_ROCKSDB, "Range {} started", LLUtils.toStringSafe(range));
@ -106,8 +105,12 @@ public abstract class LLLocalGroupedReactiveRocksIterator<T> extends
try (Buffer key = LLUtils.readDirectNioBuffer(db.getAllocator(), rocksIterator::key)) {
if (firstGroupKey == null) {
firstGroupKey = key.copy();
} else if (!LLUtils.equals(firstGroupKey, firstGroupKey.readerOffset(),
key, key.readerOffset(), prefixLength)) {
} else if (!LLUtils.equals(firstGroupKey,
firstGroupKey.readerOffset(),
key,
key.readerOffset(),
prefixLength
)) {
break;
}
@Nullable Buffer value;

View File

@ -667,7 +667,7 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
if (closed) {
return 0d;
}
return database.getLongProperty(propertyName);
return database.getAggregatedLongProperty(propertyName) / (double) handles.size();
} catch (RocksDBException e) {
if ("NotFound".equals(e.getMessage())) {
return 0d;

View File

@ -668,7 +668,7 @@ public class RocksdbFileStore {
private List<String> listKeyInternal() {
List<String> keys = new ArrayList<>();
RocksIterator iterator = db.newIterator(filename);
try (RocksIterator iterator = db.newIterator(filename)) {
iterator.seekToFirst();
while (iterator.isValid()) {
keys.add(new String(iterator.key(), StandardCharsets.US_ASCII).intern());
@ -676,6 +676,7 @@ public class RocksdbFileStore {
}
return keys;
}
}
public void append(String name, Buffer buf, int offset, int len) throws IOException {
var l = metaLock.get(name).writeLock();