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
main
Radek Hubner 3 years ago committed by Facebook GitHub Bot
parent 2c3a780901
commit 42c8afd85a
  1. 23
      java/rocksjni/options.cc
  2. 37
      java/src/main/java/org/rocksdb/WriteOptions.java
  3. 16
      java/src/test/java/org/rocksdb/WriteOptionsTest.java

@ -7801,6 +7801,29 @@ jboolean Java_org_rocksdb_WriteOptions_lowPri(
return reinterpret_cast<ROCKSDB_NAMESPACE::WriteOptions*>(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<ROCKSDB_NAMESPACE::WriteOptions*>(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<ROCKSDB_NAMESPACE::WriteOptions*>(jhandle)
->memtable_insert_hint_per_batch =
static_cast<bool>(jmemtable_insert_hint_per_batch);
}
/////////////////////////////////////////////////////////////////////
// ROCKSDB_NAMESPACE::ReadOptions

@ -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);
}

@ -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());
}
}

Loading…
Cancel
Save