From e5081a62cdd3ea82b7c58acc6eb7cacc5fe996e7 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Thu, 11 Feb 2021 01:09:15 +0100 Subject: [PATCH] Bugfixes --- .../database/collections/DatabaseMapDictionary.java | 2 -- .../dbengine/database/disk/LLLocalDictionary.java | 2 +- .../database/serialization/CodecSerializer.java | 13 +++++++++++-- 3 files changed, 12 insertions(+), 5 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 4284cb9..a2bffe8 100644 --- a/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java +++ b/src/main/java/it/cavallium/dbengine/database/collections/DatabaseMapDictionary.java @@ -11,7 +11,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; import org.jetbrains.annotations.Nullable; import reactor.core.publisher.Flux; @@ -111,7 +110,6 @@ public class DatabaseMapDictionary extends DatabaseMapDictionaryDeep updateValue(T keySuffix, Function, Optional> updater) { - AtomicBoolean changed = new AtomicBoolean(false); return dictionary.update(toKey(serializeSuffix(keySuffix)), oldSerialized -> updater.apply(oldSerialized.map(this::deserialize)).map(this::serialize) ); 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 3d61c86..af1e1a5 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalDictionary.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalDictionary.java @@ -95,7 +95,7 @@ public class LLLocalDictionary implements LLDictionary { } private int getLockIndex(byte[] key) { - return Arrays.hashCode(key) % STRIPES; + return Math.abs(Arrays.hashCode(key) % STRIPES); } private IntArrayList getLockIndices(List keys) { diff --git a/src/main/java/it/cavallium/dbengine/database/serialization/CodecSerializer.java b/src/main/java/it/cavallium/dbengine/database/serialization/CodecSerializer.java index 71dcf77..7305187 100644 --- a/src/main/java/it/cavallium/dbengine/database/serialization/CodecSerializer.java +++ b/src/main/java/it/cavallium/dbengine/database/serialization/CodecSerializer.java @@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufInputStream; import io.netty.buffer.ByteBufOutputStream; import io.netty.buffer.Unpooled; +import java.io.IOError; import java.io.IOException; import org.jetbrains.annotations.NotNull; import org.warp.commonutils.error.IndexOutOfBoundsException; @@ -46,7 +47,7 @@ public class CodecSerializer implements Serializer { return serializer.deserialize(is); } catch (IOException ex) { // This shouldn't happen - throw new RuntimeException(ex); + throw new IOError(ex); } } @@ -66,7 +67,15 @@ public class CodecSerializer implements Serializer { return bytes; } catch (IOException ex) { // This shouldn't happen - throw new RuntimeException(ex); + throw new IOError(ex); + } + } + + public int getCodecHeadersBytes() { + if (microCodecs) { + return Byte.BYTES; + } else { + return Integer.BYTES; } } }