Reformat iterator

This commit is contained in:
Andrea Cavalli 2021-10-30 12:21:28 +02:00
parent 1ea004630e
commit 98dcb39ce1

View File

@ -74,79 +74,78 @@ public abstract class LLLocalReactiveRocksIterator<T> extends
} }
public final Flux<T> flux() { public final Flux<T> flux() {
return Flux return Flux.generate(() -> {
.generate(() -> { var readOptions = new ReadOptions(this.readOptions);
var readOptions = new ReadOptions(this.readOptions); if (!range.hasMin() || !range.hasMax()) {
if (!range.hasMin() || !range.hasMax()) { readOptions.setReadaheadSize(32 * 1024); // 32KiB
readOptions.setReadaheadSize(32 * 1024); // 32KiB readOptions.setFillCache(false);
readOptions.setFillCache(false); }
if (logger.isTraceEnabled()) {
logger.trace(MARKER_ROCKSDB, "Range {} started", LLUtils.toStringSafe(range));
}
return getRocksIterator(db.getAllocator(), allowNettyDirect, readOptions, range.copy().send(), db);
}, (tuple, sink) -> {
try {
var rocksIterator = tuple.getT1();
rocksIterator.status();
if (rocksIterator.isValid()) {
Buffer key;
if (allowNettyDirect) {
key = LLUtils.readDirectNioBuffer(db.getAllocator(), rocksIterator::key);
} else {
key = LLUtils.fromByteArray(db.getAllocator(), rocksIterator.key());
} }
if (logger.isTraceEnabled()) { try (key) {
logger.trace(MARKER_ROCKSDB, "Range {} started", LLUtils.toStringSafe(range)); Buffer value;
} if (readValues) {
return getRocksIterator(db.getAllocator(), allowNettyDirect, readOptions, range.copy().send(), db);
}, (tuple, sink) -> {
try {
var rocksIterator = tuple.getT1();
rocksIterator.status();
if (rocksIterator.isValid()) {
Buffer key;
if (allowNettyDirect) { if (allowNettyDirect) {
key = LLUtils.readDirectNioBuffer(db.getAllocator(), rocksIterator::key); value = LLUtils.readDirectNioBuffer(db.getAllocator(), rocksIterator::value);
} else { } else {
key = LLUtils.fromByteArray(db.getAllocator(), rocksIterator.key()); value = LLUtils.fromByteArray(db.getAllocator(), rocksIterator.value());
}
try (key) {
Buffer value;
if (readValues) {
if (allowNettyDirect) {
value = LLUtils.readDirectNioBuffer(db.getAllocator(), rocksIterator::value);
} else {
value = LLUtils.fromByteArray(db.getAllocator(), rocksIterator.value());
}
} else {
value = null;
}
if (logger.isTraceEnabled()) {
logger.trace(MARKER_ROCKSDB,
"Range {} is reading {}: {}",
LLUtils.toStringSafe(range),
LLUtils.toStringSafe(key),
LLUtils.toStringSafe(value)
);
}
try {
rocksIterator.next();
rocksIterator.status();
sink.next(getEntry(key.send(), value == null ? null : value.send()));
} finally {
if (value != null) {
value.close();
}
}
} }
} else { } else {
if (logger.isTraceEnabled()) { value = null;
logger.trace(MARKER_ROCKSDB, "Range {} ended", LLUtils.toStringSafe(range));
}
sink.complete();
} }
} catch (RocksDBException ex) {
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace(MARKER_ROCKSDB, "Range {} failed", LLUtils.toStringSafe(range)); logger.trace(MARKER_ROCKSDB,
"Range {} is reading {}: {}",
LLUtils.toStringSafe(range),
LLUtils.toStringSafe(key),
LLUtils.toStringSafe(value)
);
}
try {
rocksIterator.next();
rocksIterator.status();
sink.next(getEntry(key.send(), value == null ? null : value.send()));
} finally {
if (value != null) {
value.close();
}
} }
sink.error(ex);
} }
return tuple; } else {
}, tuple -> { if (logger.isTraceEnabled()) {
var rocksIterator = tuple.getT1(); logger.trace(MARKER_ROCKSDB, "Range {} ended", LLUtils.toStringSafe(range));
rocksIterator.close(); }
tuple.getT2().close(); sink.complete();
tuple.getT3().close(); }
tuple.getT4().close(); } catch (RocksDBException ex) {
}); if (logger.isTraceEnabled()) {
logger.trace(MARKER_ROCKSDB, "Range {} failed", LLUtils.toStringSafe(range));
}
sink.error(ex);
}
return tuple;
}, tuple -> {
var rocksIterator = tuple.getT1();
rocksIterator.close();
tuple.getT2().close();
tuple.getT3().close();
tuple.getT4().close();
});
} }
public abstract T getEntry(@Nullable Send<Buffer> key, @Nullable Send<Buffer> value); public abstract T getEntry(@Nullable Send<Buffer> key, @Nullable Send<Buffer> value);