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

View File

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

View File

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

View File

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

View File

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