From ceff8f50229b4b95d0eb11f5f306d7128777a8bf Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Sat, 28 Sep 2024 15:14:18 +0200 Subject: [PATCH] Handle errors --- .../collections/DatabaseMapDictionary.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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 d63a5aa..14de17c 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java @@ -42,7 +42,9 @@ import java.util.Map.Entry; import java.util.Objects; import java.util.Optional; import java.util.concurrent.atomic.AtomicLong; +import java.util.function.BiConsumer; import java.util.function.BiFunction; +import java.util.function.Consumer; import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.logging.log4j.LogManager; @@ -566,7 +568,8 @@ public class DatabaseMapDictionary extends DatabaseMapDictionaryDeep Stream>> getAllEntriesFastUnsafe(DatabaseMapDictionary dict) { + public static Stream>> getAllEntriesFastUnsafe(DatabaseMapDictionary dict, + BiConsumer, Throwable> deserializationErrorHandler) { try { Comparator comparator = Comparator.comparingInt(x -> x.getMetadata().level()).reversed(); return ((LLLocalDictionary) dict.dictionary) @@ -580,10 +583,22 @@ public class DatabaseMapDictionary extends DatabaseMapDictionaryDeep null; - case RocksDBFileIterationStateKeyOk rocksDBFileIterationStateKeyOk -> - Map.entry(dict.deserializeSuffix(BufDataInput.create(rocksDBFileIterationStateKey.key())), + case RocksDBFileIterationStateKeyOk rocksDBFileIterationStateKeyOk -> { + try { + yield Map.entry(dict.deserializeSuffix(BufDataInput.create(rocksDBFileIterationStateKey.key())), dict.deserializeValue(rocksDBFileIterationStateKeyOk.value()) ); + } catch (Throwable t) { + if (deserializationErrorHandler != null) { + deserializationErrorHandler.accept(Map.entry(rocksDBFileIterationStateKey.key().copy(), + rocksDBFileIterationStateKeyOk.value().copy()), t); + yield null; + } else { + throw t; + } + } + } + }; }).filter(Objects::nonNull)); } catch (RocksDBException e) {