diff --git a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java index 1bf25a5..0fb285c 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java @@ -17,6 +17,15 @@ import it.cavallium.dbengine.database.SubStageEntry; import it.cavallium.dbengine.database.UpdateMode; import it.cavallium.dbengine.database.UpdateReturnMode; import it.cavallium.dbengine.database.disk.CachedSerializationFunction; +import it.cavallium.dbengine.database.disk.LLLocalDictionary; +import it.cavallium.dbengine.database.disk.RocksDBFile; +import it.cavallium.dbengine.database.disk.RocksDBFile.RocksDBFileIterationKeyState.RocksDBFileIterationStateKeyError; +import it.cavallium.dbengine.database.disk.RocksDBFile.RocksDBFileIterationKeyState.RocksDBFileIterationStateKeyOk; +import it.cavallium.dbengine.database.disk.RocksDBFile.RocksDBFileIterationState.RocksDBFileIterationStateBegin; +import it.cavallium.dbengine.database.disk.RocksDBFile.RocksDBFileIterationState.RocksDBFileIterationStateEnd; +import it.cavallium.dbengine.database.disk.RocksDBFile.RocksDBFileIterationState.RocksDBFileIterationStateKey; +import it.cavallium.dbengine.database.disk.SSTRange; +import it.cavallium.dbengine.database.disk.SSTRange.SSTRangeFull; import it.cavallium.dbengine.database.serialization.KVSerializationFunction; import it.cavallium.dbengine.database.serialization.SerializationException; import it.cavallium.dbengine.database.serialization.SerializationFunction; @@ -26,6 +35,7 @@ import it.cavallium.dbengine.utils.StreamUtils; import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectSortedMap; import it.unimi.dsi.fastutil.objects.Object2ObjectSortedMaps; +import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; @@ -38,6 +48,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.rocksdb.RocksDBException; /** * Optimized implementation of "DatabaseMapDictionary with SubStageGetterSingle" @@ -554,4 +565,27 @@ public class DatabaseMapDictionary extends DatabaseMapDictionaryDeep Stream>> getAllEntriesFastUnsafe(DatabaseMapDictionary dict) { + try { + return ((LLLocalDictionary) dict.dictionary) + .getAllLiveFiles() + .map(file -> file.iterate(new SSTRangeFull()).map(state -> switch (state) { + case RocksDBFileIterationStateBegin rocksDBFileIterationStateBegin: + yield null; + case RocksDBFileIterationStateEnd rocksDBFileIterationStateEnd: + yield null; + case RocksDBFileIterationStateKey rocksDBFileIterationStateKey: + yield switch (rocksDBFileIterationStateKey.state()) { + case RocksDBFileIterationStateKeyError e -> null; + case RocksDBFileIterationStateKeyOk rocksDBFileIterationStateKeyOk -> + Map.entry(dict.deserializeSuffix(BufDataInput.create(rocksDBFileIterationStateKey.key())), + dict.deserializeValue(rocksDBFileIterationStateKeyOk.value()) + ); + }; + })); + } catch (RocksDBException e) { + throw new RuntimeException(e); + } + } + } diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalDictionary.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalDictionary.java index 76c9697..1e4a502 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalDictionary.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalDictionary.java @@ -15,7 +15,6 @@ import io.micrometer.core.instrument.Counter; import io.micrometer.core.instrument.Timer; import it.cavallium.buffer.Buf; import it.cavallium.dbengine.client.DbProgress; -import it.cavallium.dbengine.client.DbProgress.DbSSTProgress; import it.cavallium.dbengine.client.SSTProgress.SSTOk; import it.cavallium.dbengine.client.SSTProgress.SSTProgressReport; import it.cavallium.dbengine.client.SSTProgress.SSTStart; @@ -1206,4 +1205,8 @@ public class LLLocalDictionary implements LLDictionary { } } + public Stream getAllLiveFiles() throws RocksDBException { + return db.getAllLiveFiles(); + } + }