2022-04-26 17:12:22 +02:00
|
|
|
package it.cavallium.dbengine.database.disk;
|
|
|
|
|
|
|
|
import static it.cavallium.dbengine.database.LLUtils.generateCustomReadOptions;
|
2023-02-22 22:31:36 +01:00
|
|
|
import static it.cavallium.dbengine.utils.StreamUtils.streamWhileNonNull;
|
2022-04-26 17:12:22 +02:00
|
|
|
|
2023-03-06 12:19:08 +01:00
|
|
|
import it.cavallium.buffer.Buf;
|
2023-02-09 23:34:25 +01:00
|
|
|
import it.cavallium.dbengine.database.LLEntry;
|
2022-04-26 17:12:22 +02:00
|
|
|
import it.cavallium.dbengine.database.LLRange;
|
2022-07-19 23:45:39 +02:00
|
|
|
import it.cavallium.dbengine.database.LLUtils;
|
2023-05-22 19:12:05 +02:00
|
|
|
import it.cavallium.dbengine.database.disk.rocksdb.LLReadOptions;
|
2023-02-09 23:34:25 +01:00
|
|
|
import it.cavallium.dbengine.database.disk.rocksdb.RocksIteratorObj;
|
|
|
|
import it.cavallium.dbengine.utils.DBException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.concurrent.CompletionException;
|
2022-05-20 10:20:00 +02:00
|
|
|
import java.util.function.Supplier;
|
2023-02-09 23:34:25 +01:00
|
|
|
import java.util.stream.Stream;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
2022-04-26 17:12:22 +02:00
|
|
|
import org.rocksdb.ReadOptions;
|
|
|
|
import org.rocksdb.RocksDBException;
|
|
|
|
|
2022-07-19 23:45:39 +02:00
|
|
|
public final class LLLocalMigrationReactiveRocksIterator {
|
2022-04-26 17:12:22 +02:00
|
|
|
|
|
|
|
private final RocksDBColumn db;
|
2023-03-20 00:36:27 +01:00
|
|
|
private final LLRange range;
|
2023-05-22 19:12:05 +02:00
|
|
|
private final Supplier<LLReadOptions> readOptions;
|
2022-04-26 17:12:22 +02:00
|
|
|
|
|
|
|
public LLLocalMigrationReactiveRocksIterator(RocksDBColumn db,
|
2023-02-09 23:34:25 +01:00
|
|
|
LLRange range,
|
2023-05-22 19:12:05 +02:00
|
|
|
Supplier<LLReadOptions> readOptions) {
|
2022-07-19 23:45:39 +02:00
|
|
|
this.db = db;
|
2023-02-09 23:34:25 +01:00
|
|
|
this.range = range;
|
2022-07-19 23:45:39 +02:00
|
|
|
this.readOptions = readOptions;
|
2022-04-26 17:12:22 +02:00
|
|
|
}
|
|
|
|
|
2023-02-09 23:34:25 +01:00
|
|
|
public Stream<LLEntry> stream() {
|
2023-02-22 22:31:36 +01:00
|
|
|
return streamWhileNonNull(() -> {
|
2023-05-23 01:05:03 +02:00
|
|
|
try (var readOptions = generateCustomReadOptions(this.readOptions.get(), false, false, false);
|
|
|
|
var rocksIterator = db.newRocksIterator(readOptions, range, false)) {
|
|
|
|
if (rocksIterator.isValid()) {
|
|
|
|
var key = rocksIterator.keyBuf().copy();
|
|
|
|
var value = rocksIterator.valueBuf().copy();
|
|
|
|
rocksIterator.next(false);
|
|
|
|
return LLEntry.of(key, value);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
} catch (RocksDBException e) {
|
|
|
|
throw new DBException("Failed to open iterator", e);
|
2022-04-26 17:12:22 +02:00
|
|
|
}
|
2023-02-09 23:34:25 +01:00
|
|
|
});
|
2022-04-26 17:12:22 +02:00
|
|
|
}
|
|
|
|
}
|