From 7e7e1c410b8d0055f9a1819fda3d85385bede7b9 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Tue, 23 May 2023 00:19:47 +0200 Subject: [PATCH] Add debug option to disable snapshots, optimize iterate bounds --- .../database/disk/AbstractRocksDBColumn.java | 18 ++++-------------- .../database/disk/LLLocalKeyValueDatabase.java | 1 + .../database/disk/rocksdb/LLReadOptions.java | 8 ++++++++ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/it/cavallium/dbengine/database/disk/AbstractRocksDBColumn.java b/src/main/java/it/cavallium/dbengine/database/disk/AbstractRocksDBColumn.java index 1cff031..186fd0e 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/AbstractRocksDBColumn.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/AbstractRocksDBColumn.java @@ -231,18 +231,6 @@ public sealed abstract class AbstractRocksDBColumn implements this.keyMayExistGetter = new DBColumnKeyMayExistGetter(); } - /** - * This method should not modify or move the writerIndex/readerIndex of the key - */ - static void setIterateBound(LLReadOptions readOpts, IterateBound boundType, Buf key) { - byte[] slice = key != null ? requireNonNull(LLUtils.asArray(key)) : null; - if (boundType == IterateBound.LOWER) { - readOpts.setIterateLowerBound(slice); - } else { - readOpts.setIterateUpperBound(slice); - } - } - /** * This method should not modify or move the writerIndex/readerIndex of the buffers inside the range */ @@ -557,8 +545,10 @@ public sealed abstract class AbstractRocksDBColumn implements try { ensureOpen(); ensureOwned(readOptions); - setIterateBound(readOptions, IterateBound.LOWER, min); - setIterateBound(readOptions, IterateBound.UPPER, max); + assert !readOptions.hasIterateLowerBound() : "ReadOptions has already a range!"; + assert !readOptions.hasIterateUpperBound() : "ReadOptions has already a range!"; + readOptions.setIterateLowerBound(min != null ? requireNonNull(LLUtils.asArray(min)) : null); + readOptions.setIterateUpperBound(max != null ? requireNonNull(LLUtils.asArray(max)) : null); return readOptions.newIterator(db, cfh, iteratorMetrics); } finally { closeLock.unlockRead(closeReadLock); 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 2ecfb54..fe293ff 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalKeyValueDatabase.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalKeyValueDatabase.java @@ -1462,6 +1462,7 @@ public class LLLocalKeyValueDatabase extends Backuppable implements LLKeyValueDa @Override public LLSnapshot takeSnapshot() { + if (!ALLOW_SNAPSHOTS) throw new UnsupportedOperationException("Snapshots are disabled!"); var closeReadLock = closeLock.readLock(); try { ensureOpen(); diff --git a/src/main/java/it/cavallium/dbengine/database/disk/rocksdb/LLReadOptions.java b/src/main/java/it/cavallium/dbengine/database/disk/rocksdb/LLReadOptions.java index b924eb2..95bb60a 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/rocksdb/LLReadOptions.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/rocksdb/LLReadOptions.java @@ -140,4 +140,12 @@ public final class LLReadOptions extends SimpleResource { public Snapshot snapshot() { return val.snapshot(); } + + public boolean hasIterateLowerBound() { + return val.iterateLowerBound() != null; + } + + public boolean hasIterateUpperBound() { + return val.iterateUpperBound() != null; + } }