From 42c8afd85a12935fdeddf62acccbbf5e39a84504 Mon Sep 17 00:00:00 2001 From: Radek Hubner Date: Fri, 4 Feb 2022 16:00:51 -0800 Subject: [PATCH] WriteOptions - add missing java API. (#9295) Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/9295 Reviewed By: riversand963 Differential Revision: D33672440 Pulled By: ajkr fbshipit-source-id: 85f73a9297888b00255b636e7826b37186aba45c --- java/rocksjni/options.cc | 23 ++++++++++++ .../main/java/org/rocksdb/WriteOptions.java | 37 +++++++++++++++++++ .../java/org/rocksdb/WriteOptionsTest.java | 16 +++++--- 3 files changed, 71 insertions(+), 5 deletions(-) diff --git a/java/rocksjni/options.cc b/java/rocksjni/options.cc index bb7c80ee3..05d73c552 100644 --- a/java/rocksjni/options.cc +++ b/java/rocksjni/options.cc @@ -7801,6 +7801,29 @@ jboolean Java_org_rocksdb_WriteOptions_lowPri( return reinterpret_cast(jhandle)->low_pri; } +/* + * Class: org_rocksdb_WriteOptions + * Method: memtableInsertHintPerBatch + * Signature: (J)Z + */ +jboolean Java_org_rocksdb_WriteOptions_memtableInsertHintPerBatch( + JNIEnv*, jobject, jlong jhandle) { + return reinterpret_cast(jhandle) + ->memtable_insert_hint_per_batch; +} + +/* + * Class: org_rocksdb_WriteOptions + * Method: setMemtableInsertHintPerBatch + * Signature: (JZ)V + */ +void Java_org_rocksdb_WriteOptions_setMemtableInsertHintPerBatch( + JNIEnv*, jobject, jlong jhandle, jboolean jmemtable_insert_hint_per_batch) { + reinterpret_cast(jhandle) + ->memtable_insert_hint_per_batch = + static_cast(jmemtable_insert_hint_per_batch); +} + ///////////////////////////////////////////////////////////////////// // ROCKSDB_NAMESPACE::ReadOptions diff --git a/java/src/main/java/org/rocksdb/WriteOptions.java b/java/src/main/java/org/rocksdb/WriteOptions.java index 9edf26071..5a3ffa6c5 100644 --- a/java/src/main/java/org/rocksdb/WriteOptions.java +++ b/java/src/main/java/org/rocksdb/WriteOptions.java @@ -200,6 +200,40 @@ public class WriteOptions extends RocksObject { return lowPri(nativeHandle_); } + /** + * If true, this writebatch will maintain the last insert positions of each + * memtable as hints in concurrent write. It can improve write performance + * in concurrent writes if keys in one writebatch are sequential. In + * non-concurrent writes (when {@code concurrent_memtable_writes} is false) this + * option will be ignored. + * + * Default: false + * + * @return true if writebatch will maintain the last insert positions of each memtable as hints in + * concurrent write. + */ + public boolean memtableInsertHintPerBatch() { + return memtableInsertHintPerBatch(nativeHandle_); + } + + /** + * If true, this writebatch will maintain the last insert positions of each + * memtable as hints in concurrent write. It can improve write performance + * in concurrent writes if keys in one writebatch are sequential. In + * non-concurrent writes (when {@code concurrent_memtable_writes} is false) this + * option will be ignored. + * + * Default: false + * + * @param memtableInsertHintPerBatch true if writebatch should maintain the last insert positions + * of each memtable as hints in concurrent write. + * @return the instance of the current WriteOptions. + */ + public WriteOptions setMemtableInsertHintPerBatch(final boolean memtableInsertHintPerBatch) { + setMemtableInsertHintPerBatch(nativeHandle_, memtableInsertHintPerBatch); + return this; + } + private native static long newWriteOptions(); private native static long copyWriteOptions(long handle); @Override protected final native void disposeInternal(final long handle); @@ -216,4 +250,7 @@ public class WriteOptions extends RocksObject { private native boolean noSlowdown(final long handle); private native void setLowPri(final long handle, final boolean lowPri); private native boolean lowPri(final long handle); + private native boolean memtableInsertHintPerBatch(final long handle); + private native void setMemtableInsertHintPerBatch( + final long handle, final boolean memtableInsertHintPerBatch); } diff --git a/java/src/test/java/org/rocksdb/WriteOptionsTest.java b/java/src/test/java/org/rocksdb/WriteOptionsTest.java index 1d5f3cc8d..735677cb7 100644 --- a/java/src/test/java/org/rocksdb/WriteOptionsTest.java +++ b/java/src/test/java/org/rocksdb/WriteOptionsTest.java @@ -5,12 +5,11 @@ package org.rocksdb; -import org.junit.ClassRule; -import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; import java.util.Random; - -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.ClassRule; +import org.junit.Test; public class WriteOptionsTest { @@ -50,6 +49,11 @@ public class WriteOptionsTest { assertThat(writeOptions.lowPri()).isTrue(); writeOptions.setLowPri(false); assertThat(writeOptions.lowPri()).isFalse(); + + writeOptions.setMemtableInsertHintPerBatch(true); + assertThat(writeOptions.memtableInsertHintPerBatch()).isTrue(); + writeOptions.setMemtableInsertHintPerBatch(false); + assertThat(writeOptions.memtableInsertHintPerBatch()).isFalse(); } } @@ -59,11 +63,13 @@ public class WriteOptionsTest { origOpts.setDisableWAL(rand.nextBoolean()); origOpts.setIgnoreMissingColumnFamilies(rand.nextBoolean()); origOpts.setSync(rand.nextBoolean()); + origOpts.setMemtableInsertHintPerBatch(true); WriteOptions copyOpts = new WriteOptions(origOpts); assertThat(origOpts.disableWAL()).isEqualTo(copyOpts.disableWAL()); assertThat(origOpts.ignoreMissingColumnFamilies()).isEqualTo( copyOpts.ignoreMissingColumnFamilies()); assertThat(origOpts.sync()).isEqualTo(copyOpts.sync()); + assertThat(origOpts.memtableInsertHintPerBatch()) + .isEqualTo(copyOpts.memtableInsertHintPerBatch()); } - }