From 93096920626561ccdb017e171226cabe77a0c9a2 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Mon, 27 Dec 2021 17:45:52 +0100 Subject: [PATCH] Configurable optimistic transactions --- .../java/it/cavallium/dbengine/client/DatabaseOptions.java | 3 ++- .../dbengine/database/disk/LLLocalKeyValueDatabase.java | 6 +++++- .../it/cavallium/dbengine/LocalTemporaryDbGenerator.java | 2 +- .../it/cavallium/dbengine/MemoryTemporaryDbGenerator.java | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/it/cavallium/dbengine/client/DatabaseOptions.java b/src/main/java/it/cavallium/dbengine/client/DatabaseOptions.java index 977afae..d97c072 100644 --- a/src/main/java/it/cavallium/dbengine/client/DatabaseOptions.java +++ b/src/main/java/it/cavallium/dbengine/client/DatabaseOptions.java @@ -8,4 +8,5 @@ import org.jetbrains.annotations.Nullable; @RecordBuilder public record DatabaseOptions(List volumes, Map extraFlags, boolean absoluteConsistency, boolean lowMemory, boolean inMemory, boolean useDirectIO, boolean allowMemoryMapping, - boolean allowNettyDirect, int maxOpenFiles, @Nullable Long memtableMemoryBudgetBytes) {} + boolean allowNettyDirect, boolean optimistic, int maxOpenFiles, + @Nullable Long memtableMemoryBudgetBytes) {} diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalKeyValueDatabase.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalKeyValueDatabase.java index 8b880d1..a7661d4 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalKeyValueDatabase.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalKeyValueDatabase.java @@ -155,7 +155,11 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase { while (true) { try { // a factory method that returns a RocksDB instance - this.db = OptimisticTransactionDB.open(new DBOptions(rocksdbOptions), dbPathString, descriptors, handles); + if (databaseOptions.optimistic()) { + this.db = OptimisticTransactionDB.open(new DBOptions(rocksdbOptions), dbPathString, descriptors, handles); + } else { + this.db = TransactionDB.open(new DBOptions(rocksdbOptions), dbPathString, descriptors, handles); + } break; } catch (RocksDBException ex) { switch (ex.getMessage()) { diff --git a/src/test/java/it/cavallium/dbengine/LocalTemporaryDbGenerator.java b/src/test/java/it/cavallium/dbengine/LocalTemporaryDbGenerator.java index 9dc2192..41cc4f9 100644 --- a/src/test/java/it/cavallium/dbengine/LocalTemporaryDbGenerator.java +++ b/src/test/java/it/cavallium/dbengine/LocalTemporaryDbGenerator.java @@ -78,7 +78,7 @@ public class LocalTemporaryDbGenerator implements TemporaryDbGenerator { conn.getDatabase("testdb", List.of(Column.dictionary("testmap"), Column.special("ints"), Column.special("longs")), new DatabaseOptions(List.of(), Map.of(), true, false, true, false, - true, canUseNettyDirect, -1, null) + true, canUseNettyDirect, true, -1, null) ), conn.getLuceneIndex("testluceneindex1", 1, diff --git a/src/test/java/it/cavallium/dbengine/MemoryTemporaryDbGenerator.java b/src/test/java/it/cavallium/dbengine/MemoryTemporaryDbGenerator.java index 8f7c18d..cb23614 100644 --- a/src/test/java/it/cavallium/dbengine/MemoryTemporaryDbGenerator.java +++ b/src/test/java/it/cavallium/dbengine/MemoryTemporaryDbGenerator.java @@ -49,7 +49,7 @@ public class MemoryTemporaryDbGenerator implements TemporaryDbGenerator { .zip( conn.getDatabase("testdb", List.of(Column.dictionary("testmap"), Column.special("ints"), Column.special("longs")), - new DatabaseOptions(List.of(), Map.of(), true, false, true, false, true, canUseNettyDirect, -1, null) + new DatabaseOptions(List.of(), Map.of(), true, false, true, false, true, canUseNettyDirect, true, -1, null) ), conn.getLuceneIndex("testluceneindex1", 1,