diff --git a/java/rocksjni/options.cc b/java/rocksjni/options.cc index a6d46f24b..7fff7cdbe 100644 --- a/java/rocksjni/options.cc +++ b/java/rocksjni/options.cc @@ -5532,6 +5532,20 @@ void Java_org_rocksdb_DBOptions_setDbWriteBufferSize( opt->db_write_buffer_size = static_cast(jdb_write_buffer_size); } +/* + * Class: org_rocksdb_DBOptions + * Method: setWriteBufferManager + * Signature: (JJ)V + */ +void Java_org_rocksdb_DBOptions_setWriteBufferManager(JNIEnv* /*env*/, jobject /*jobj*/, + jlong jdb_options_handle, + jlong jwrite_buffer_manager_handle) { + auto* write_buffer_manager = + reinterpret_cast *>(jwrite_buffer_manager_handle); + reinterpret_cast(jdb_options_handle)->write_buffer_manager = + *write_buffer_manager; +} + /* * Class: org_rocksdb_DBOptions * Method: dbWriteBufferSize diff --git a/java/src/main/java/org/rocksdb/DBOptions.java b/java/src/main/java/org/rocksdb/DBOptions.java index 9623a1042..280623a20 100644 --- a/java/src/main/java/org/rocksdb/DBOptions.java +++ b/java/src/main/java/org/rocksdb/DBOptions.java @@ -46,6 +46,7 @@ public class DBOptions this.numShardBits_ = other.numShardBits_; this.rateLimiter_ = other.rateLimiter_; this.rowCache_ = other.rowCache_; + this.writeBufferManager_ = other.writeBufferManager_; } /** @@ -671,10 +672,17 @@ public class DBOptions public DBOptions setWriteBufferManager(final WriteBufferManager writeBufferManager) { assert(isOwningHandle()); setWriteBufferManager(nativeHandle_, writeBufferManager.nativeHandle_); + this.writeBufferManager_ = writeBufferManager; return this; } @Override + public WriteBufferManager writeBufferManager() { + assert(isOwningHandle()); + return this.writeBufferManager_; + } + + @Override public long dbWriteBufferSize() { assert(isOwningHandle()); return dbWriteBufferSize(nativeHandle_); @@ -1167,4 +1175,5 @@ public class DBOptions private int numShardBits_; private RateLimiter rateLimiter_; private Cache rowCache_; + private WriteBufferManager writeBufferManager_; } diff --git a/java/src/main/java/org/rocksdb/DBOptionsInterface.java b/java/src/main/java/org/rocksdb/DBOptionsInterface.java index d3a33b757..accfb4c59 100644 --- a/java/src/main/java/org/rocksdb/DBOptionsInterface.java +++ b/java/src/main/java/org/rocksdb/DBOptionsInterface.java @@ -1004,6 +1004,15 @@ public interface DBOptionsInterface { */ T setWriteBufferManager(final WriteBufferManager writeBufferManager); + /** + * Reference to {@link WriteBufferManager} used by it.
+ * + * Default: null (Disabled) + * + * @return a reference to WriteBufferManager + */ + WriteBufferManager writeBufferManager(); + /** * Amount of data to build up in memtables across all column * families before writing to disk. diff --git a/java/src/main/java/org/rocksdb/Options.java b/java/src/main/java/org/rocksdb/Options.java index e409d3466..2ff4ec120 100644 --- a/java/src/main/java/org/rocksdb/Options.java +++ b/java/src/main/java/org/rocksdb/Options.java @@ -70,6 +70,7 @@ public class Options extends RocksObject this.compactionOptionsFIFO_ = other.compactionOptionsFIFO_; this.compressionOptions_ = other.compressionOptions_; this.rowCache_ = other.rowCache_; + this.writeBufferManager_ = other.writeBufferManager_; } @Override @@ -727,10 +728,17 @@ public class Options extends RocksObject public Options setWriteBufferManager(final WriteBufferManager writeBufferManager) { assert(isOwningHandle()); setWriteBufferManager(nativeHandle_, writeBufferManager.nativeHandle_); + this.writeBufferManager_ = writeBufferManager; return this; } @Override + public WriteBufferManager writeBufferManager() { + assert(isOwningHandle()); + return this.writeBufferManager_; + } + + @Override public long dbWriteBufferSize() { assert(isOwningHandle()); return dbWriteBufferSize(nativeHandle_); @@ -1918,4 +1926,5 @@ public class Options extends RocksObject private CompactionOptionsFIFO compactionOptionsFIFO_; private CompressionOptions compressionOptions_; private Cache rowCache_; + private WriteBufferManager writeBufferManager_; } diff --git a/java/src/test/java/org/rocksdb/DBOptionsTest.java b/java/src/test/java/org/rocksdb/DBOptionsTest.java index 79cee3950..bad01c435 100644 --- a/java/src/test/java/org/rocksdb/DBOptionsTest.java +++ b/java/src/test/java/org/rocksdb/DBOptionsTest.java @@ -426,19 +426,21 @@ public class DBOptionsTest { @Test public void setWriteBufferManager() throws RocksDBException { - try (final Options opt = new Options(); + try (final DBOptions opt = new DBOptions(); final Cache cache = new LRUCache(1 * 1024 * 1024); final WriteBufferManager writeBufferManager = new WriteBufferManager(2000l, cache)) { opt.setWriteBufferManager(writeBufferManager); + assertThat(opt.writeBufferManager()).isEqualTo(writeBufferManager); } } @Test public void setWriteBufferManagerWithZeroBufferSize() throws RocksDBException { - try (final Options opt = new Options(); + try (final DBOptions opt = new DBOptions(); final Cache cache = new LRUCache(1 * 1024 * 1024); final WriteBufferManager writeBufferManager = new WriteBufferManager(0l, cache)) { opt.setWriteBufferManager(writeBufferManager); + assertThat(opt.writeBufferManager()).isEqualTo(writeBufferManager); } } diff --git a/java/src/test/java/org/rocksdb/OptionsTest.java b/java/src/test/java/org/rocksdb/OptionsTest.java index 44d70c16c..2571c3e26 100644 --- a/java/src/test/java/org/rocksdb/OptionsTest.java +++ b/java/src/test/java/org/rocksdb/OptionsTest.java @@ -651,6 +651,7 @@ public class OptionsTest { final Cache cache = new LRUCache(1 * 1024 * 1024); final WriteBufferManager writeBufferManager = new WriteBufferManager(2000l, cache)) { opt.setWriteBufferManager(writeBufferManager); + assertThat(opt.writeBufferManager()).isEqualTo(writeBufferManager); } } @@ -660,6 +661,7 @@ public class OptionsTest { final Cache cache = new LRUCache(1 * 1024 * 1024); final WriteBufferManager writeBufferManager = new WriteBufferManager(0l, cache)) { opt.setWriteBufferManager(writeBufferManager); + assertThat(opt.writeBufferManager()).isEqualTo(writeBufferManager); } }