Add missing mutable DBOptions to RocksJava (#6152)

Summary:
As requested in https://github.com/facebook/rocksdb/issues/6127
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6152

Differential Revision: D18955608

Pulled By: pdillinger

fbshipit-source-id: 3e1367d944e44d5f1675a422f7dd2451c86feb6f
main
Adam Retter 5 years ago committed by Facebook Github Bot
parent 3b607610df
commit b433bbefe9
  1. 136
      java/rocksjni/options.cc
  2. 53
      java/src/main/java/org/rocksdb/DBOptions.java
  3. 36
      java/src/main/java/org/rocksdb/MutableDBOptions.java
  4. 74
      java/src/main/java/org/rocksdb/MutableDBOptionsInterface.java
  5. 53
      java/src/main/java/org/rocksdb/Options.java
  6. 27
      java/src/test/java/org/rocksdb/DBOptionsTest.java
  7. 7
      java/src/test/java/org/rocksdb/MutableDBOptionsTest.java
  8. 27
      java/src/test/java/org/rocksdb/OptionsTest.java

@ -1247,9 +1247,51 @@ jint Java_org_rocksdb_Options_statsDumpPeriodSec(
*/
void Java_org_rocksdb_Options_setStatsDumpPeriodSec(
JNIEnv*, jobject, jlong jhandle,
jint stats_dump_period_sec) {
jint jstats_dump_period_sec) {
reinterpret_cast<rocksdb::Options*>(jhandle)->stats_dump_period_sec =
static_cast<int>(stats_dump_period_sec);
static_cast<unsigned int>(jstats_dump_period_sec);
}
/*
* Class: org_rocksdb_Options
* Method: statsPersistPeriodSec
* Signature: (J)I
*/
jint Java_org_rocksdb_Options_statsPersistPeriodSec(
JNIEnv*, jobject, jlong jhandle) {
return reinterpret_cast<rocksdb::Options*>(jhandle)->stats_persist_period_sec;
}
/*
* Class: org_rocksdb_Options
* Method: setStatsPersistPeriodSec
* Signature: (JI)V
*/
void Java_org_rocksdb_Options_setStatsPersistPeriodSec(
JNIEnv*, jobject, jlong jhandle, jint jstats_persist_period_sec) {
reinterpret_cast<rocksdb::Options*>(jhandle)->stats_persist_period_sec =
static_cast<unsigned int>(jstats_persist_period_sec);
}
/*
* Class: org_rocksdb_Options
* Method: statsHistoryBufferSize
* Signature: (J)J
*/
jlong Java_org_rocksdb_Options_statsHistoryBufferSize(
JNIEnv*, jobject, jlong jhandle) {
return reinterpret_cast<rocksdb::Options*>(jhandle)->stats_history_buffer_size;
}
/*
* Class: org_rocksdb_Options
* Method: setStatsHistoryBufferSize
* Signature: (JJ)V
*/
void Java_org_rocksdb_Options_setStatsHistoryBufferSize(
JNIEnv*, jobject, jlong jhandle, jlong jstats_history_buffer_size) {
reinterpret_cast<rocksdb::Options*>(jhandle)->stats_history_buffer_size =
static_cast<size_t>(jstats_history_buffer_size);
}
/*
@ -1481,6 +1523,28 @@ jlong Java_org_rocksdb_Options_walBytesPerSync(
return static_cast<jlong>(opt->wal_bytes_per_sync);
}
/*
* Class: org_rocksdb_Options
* Method: setStrictBytesPerSync
* Signature: (JZ)V
*/
void Java_org_rocksdb_Options_setStrictBytesPerSync(
JNIEnv*, jobject, jlong jhandle, jboolean jstrict_bytes_per_sync) {
reinterpret_cast<rocksdb::Options*>(jhandle)->strict_bytes_per_sync =
jstrict_bytes_per_sync == JNI_TRUE;
}
/*
* Class: org_rocksdb_Options
* Method: strictBytesPerSync
* Signature: (J)Z
*/
jboolean Java_org_rocksdb_Options_strictBytesPerSync(
JNIEnv*, jobject, jlong jhandle) {
auto* opt = reinterpret_cast<rocksdb::Options*>(jhandle);
return static_cast<jboolean>(opt->strict_bytes_per_sync);
}
/*
* Class: org_rocksdb_Options
* Method: setEnableThreadTracking
@ -5441,9 +5505,9 @@ jboolean Java_org_rocksdb_DBOptions_isFdCloseOnExec(
* Signature: (JI)V
*/
void Java_org_rocksdb_DBOptions_setStatsDumpPeriodSec(
JNIEnv*, jobject, jlong jhandle, jint stats_dump_period_sec) {
JNIEnv*, jobject, jlong jhandle, jint jstats_dump_period_sec) {
reinterpret_cast<rocksdb::DBOptions*>(jhandle)->stats_dump_period_sec =
static_cast<int>(stats_dump_period_sec);
static_cast<unsigned int>(jstats_dump_period_sec);
}
/*
@ -5456,6 +5520,48 @@ jint Java_org_rocksdb_DBOptions_statsDumpPeriodSec(
return reinterpret_cast<rocksdb::DBOptions*>(jhandle)->stats_dump_period_sec;
}
/*
* Class: org_rocksdb_DBOptions
* Method: setStatsPersistPeriodSec
* Signature: (JI)V
*/
void Java_org_rocksdb_DBOptions_setStatsPersistPeriodSec(
JNIEnv*, jobject, jlong jhandle, jint jstats_persist_period_sec) {
reinterpret_cast<rocksdb::DBOptions*>(jhandle)->stats_persist_period_sec =
static_cast<unsigned int>(jstats_persist_period_sec);
}
/*
* Class: org_rocksdb_DBOptions
* Method: statsPersistPeriodSec
* Signature: (J)I
*/
jint Java_org_rocksdb_DBOptions_statsPersistPeriodSec(
JNIEnv*, jobject, jlong jhandle) {
return reinterpret_cast<rocksdb::DBOptions*>(jhandle)->stats_persist_period_sec;
}
/*
* Class: org_rocksdb_DBOptions
* Method: setStatsHistoryBufferSize
* Signature: (JJ)V
*/
void Java_org_rocksdb_DBOptions_setStatsHistoryBufferSize(
JNIEnv*, jobject, jlong jhandle, jlong jstats_history_buffer_size) {
reinterpret_cast<rocksdb::DBOptions*>(jhandle)->stats_history_buffer_size =
static_cast<size_t>(jstats_history_buffer_size);
}
/*
* Class: org_rocksdb_DBOptions
* Method: statsHistoryBufferSize
* Signature: (J)J
*/
jlong Java_org_rocksdb_DBOptions_statsHistoryBufferSize(
JNIEnv*, jobject, jlong jhandle) {
return reinterpret_cast<rocksdb::DBOptions*>(jhandle)->stats_history_buffer_size;
}
/*
* Class: org_rocksdb_DBOptions
* Method: setAdviseRandomOnOpen
@ -5694,6 +5800,28 @@ jlong Java_org_rocksdb_DBOptions_walBytesPerSync(
return static_cast<jlong>(opt->wal_bytes_per_sync);
}
/*
* Class: org_rocksdb_DBOptions
* Method: setStrictBytesPerSync
* Signature: (JZ)V
*/
void Java_org_rocksdb_DBOptions_setStrictBytesPerSync(
JNIEnv*, jobject, jlong jhandle, jboolean jstrict_bytes_per_sync) {
reinterpret_cast<rocksdb::DBOptions*>(jhandle)->strict_bytes_per_sync =
jstrict_bytes_per_sync == JNI_TRUE;
}
/*
* Class: org_rocksdb_DBOptions
* Method: strictBytesPerSync
* Signature: (J)Z
*/
jboolean Java_org_rocksdb_DBOptions_strictBytesPerSync(
JNIEnv*, jobject, jlong jhandle) {
return static_cast<jboolean>(
reinterpret_cast<rocksdb::DBOptions*>(jhandle)->strict_bytes_per_sync);
}
/*
* Class: org_rocksdb_DBOptions
* Method: setDelayedWriteRate

@ -660,6 +660,34 @@ public class DBOptions extends RocksObject
return statsDumpPeriodSec(nativeHandle_);
}
@Override
public DBOptions setStatsPersistPeriodSec(
final int statsPersistPeriodSec) {
assert(isOwningHandle());
setStatsPersistPeriodSec(nativeHandle_, statsPersistPeriodSec);
return this;
}
@Override
public int statsPersistPeriodSec() {
assert(isOwningHandle());
return statsPersistPeriodSec(nativeHandle_);
}
@Override
public DBOptions setStatsHistoryBufferSize(
final long statsHistoryBufferSize) {
assert(isOwningHandle());
setStatsHistoryBufferSize(nativeHandle_, statsHistoryBufferSize);
return this;
}
@Override
public long statsHistoryBufferSize() {
assert(isOwningHandle());
return statsHistoryBufferSize(nativeHandle_);
}
@Override
public DBOptions setAdviseRandomOnOpen(
final boolean adviseRandomOnOpen) {
@ -807,6 +835,19 @@ public class DBOptions extends RocksObject
return walBytesPerSync(nativeHandle_);
}
@Override
public DBOptions setStrictBytesPerSync(final boolean strictBytesPerSync) {
assert(isOwningHandle());
setStrictBytesPerSync(nativeHandle_, strictBytesPerSync);
return this;
}
@Override
public boolean strictBytesPerSync() {
assert(isOwningHandle());
return strictBytesPerSync(nativeHandle_);
}
//TODO(AR) NOW
// @Override
// public DBOptions setListeners(final List<EventListener> listeners) {
@ -1239,6 +1280,14 @@ public class DBOptions extends RocksObject
private native void setStatsDumpPeriodSec(
long handle, int statsDumpPeriodSec);
private native int statsDumpPeriodSec(long handle);
private native void setStatsPersistPeriodSec(
final long handle, final int statsPersistPeriodSec);
private native int statsPersistPeriodSec(
final long handle);
private native void setStatsHistoryBufferSize(
final long handle, final long statsHistoryBufferSize);
private native long statsHistoryBufferSize(
final long handle);
private native void setAdviseRandomOnOpen(
long handle, boolean adviseRandomOnOpen);
private native boolean adviseRandomOnOpen(long handle);
@ -1270,6 +1319,10 @@ public class DBOptions extends RocksObject
private native long bytesPerSync(long handle);
private native void setWalBytesPerSync(long handle, long walBytesPerSync);
private native long walBytesPerSync(long handle);
private native void setStrictBytesPerSync(
final long handle, final boolean strictBytesPerSync);
private native boolean strictBytesPerSync(
final long handle);
private native void setEnableThreadTracking(long handle,
boolean enableThreadTracking);
private native boolean enableThreadTracking(long handle);

@ -89,9 +89,12 @@ public class MutableDBOptions extends AbstractMutableOptions {
max_total_wal_size(ValueType.LONG),
delete_obsolete_files_period_micros(ValueType.LONG),
stats_dump_period_sec(ValueType.INT),
stats_persist_period_sec(ValueType.INT),
stats_history_buffer_size(ValueType.LONG),
max_open_files(ValueType.INT),
bytes_per_sync(ValueType.LONG),
wal_bytes_per_sync(ValueType.LONG),
strict_bytes_per_sync(ValueType.BOOLEAN),
compaction_readahead_size(ValueType.LONG);
private final ValueType valueType;
@ -240,6 +243,28 @@ public class MutableDBOptions extends AbstractMutableOptions {
return getInt(DBOption.stats_dump_period_sec);
}
@Override
public MutableDBOptionsBuilder setStatsPersistPeriodSec(
final int statsPersistPeriodSec) {
return setInt(DBOption.stats_persist_period_sec, statsPersistPeriodSec);
}
@Override
public int statsPersistPeriodSec() {
return getInt(DBOption.stats_persist_period_sec);
}
@Override
public MutableDBOptionsBuilder setStatsHistoryBufferSize(
final long statsHistoryBufferSize) {
return setLong(DBOption.stats_history_buffer_size, statsHistoryBufferSize);
}
@Override
public long statsHistoryBufferSize() {
return getLong(DBOption.stats_history_buffer_size);
}
@Override
public MutableDBOptionsBuilder setMaxOpenFiles(final int maxOpenFiles) {
return setInt(DBOption.max_open_files, maxOpenFiles);
@ -271,6 +296,17 @@ public class MutableDBOptions extends AbstractMutableOptions {
return getLong(DBOption.wal_bytes_per_sync);
}
@Override
public MutableDBOptionsBuilder setStrictBytesPerSync(
final boolean strictBytesPerSync) {
return setBoolean(DBOption.strict_bytes_per_sync, strictBytesPerSync);
}
@Override
public boolean strictBytesPerSync() {
return getBoolean(DBOption.strict_bytes_per_sync);
}
@Override
public MutableDBOptionsBuilder setCompactionReadaheadSize(
final long compactionReadaheadSize) {

@ -237,6 +237,44 @@ public interface MutableDBOptionsInterface<T extends MutableDBOptionsInterface<T
*/
int statsDumpPeriodSec();
/**
* If not zero, dump rocksdb.stats to RocksDB every
* {@code statsPersistPeriodSec}
*
* Default: 600
*
* @param statsPersistPeriodSec time interval in seconds.
* @return the instance of the current object.
*/
T setStatsPersistPeriodSec(int statsPersistPeriodSec);
/**
* If not zero, dump rocksdb.stats to RocksDB every
* {@code statsPersistPeriodSec}
*
* @return time interval in seconds.
*/
int statsPersistPeriodSec();
/**
* If not zero, periodically take stats snapshots and store in memory, the
* memory size for stats snapshots is capped at {@code statsHistoryBufferSize}
*
* Default: 1MB
*
* @param statsHistoryBufferSize the size of the buffer.
* @return the instance of the current object.
*/
T setStatsHistoryBufferSize(long statsHistoryBufferSize);
/**
* If not zero, periodically take stats snapshots and store in memory, the
* memory size for stats snapshots is capped at {@code statsHistoryBufferSize}
*
* @return the size of the buffer.
*/
long statsHistoryBufferSize();
/**
* Number of open files that can be used by the DB. You may need to
* increase this if your database has a large working set. Value -1 means
@ -303,6 +341,42 @@ public interface MutableDBOptionsInterface<T extends MutableDBOptionsInterface<T
*/
long walBytesPerSync();
/**
* When true, guarantees WAL files have at most {@link #walBytesPerSync()}
* bytes submitted for writeback at any given time, and SST files have at most
* {@link #bytesPerSync()} bytes pending writeback at any given time. This
* can be used to handle cases where processing speed exceeds I/O speed
* during file generation, which can lead to a huge sync when the file is
* finished, even with {@link #bytesPerSync()} / {@link #walBytesPerSync()}
* properly configured.
*
* - If `sync_file_range` is supported it achieves this by waiting for any
* prior `sync_file_range`s to finish before proceeding. In this way,
* processing (compression, etc.) can proceed uninhibited in the gap
* between `sync_file_range`s, and we block only when I/O falls
* behind.
* - Otherwise the `WritableFile::Sync` method is used. Note this mechanism
* always blocks, thus preventing the interleaving of I/O and processing.
*
* Note: Enabling this option does not provide any additional persistence
* guarantees, as it may use `sync_file_range`, which does not write out
* metadata.
*
* Default: false
*
* @param strictBytesPerSync the bytes per sync
* @return the instance of the current object.
*/
T setStrictBytesPerSync(boolean strictBytesPerSync);
/**
* Return the strict byte limit per sync.
*
* See {@link #setStrictBytesPerSync(boolean)}
*
* @return the limit in bytes.
*/
boolean strictBytesPerSync();
/**
* If non-zero, we perform bigger reads when doing compaction. If you're

@ -739,6 +739,34 @@ public class Options extends RocksObject
return this;
}
@Override
public Options setStatsPersistPeriodSec(
final int statsPersistPeriodSec) {
assert(isOwningHandle());
setStatsPersistPeriodSec(nativeHandle_, statsPersistPeriodSec);
return this;
}
@Override
public int statsPersistPeriodSec() {
assert(isOwningHandle());
return statsPersistPeriodSec(nativeHandle_);
}
@Override
public Options setStatsHistoryBufferSize(
final long statsHistoryBufferSize) {
assert(isOwningHandle());
setStatsHistoryBufferSize(nativeHandle_, statsHistoryBufferSize);
return this;
}
@Override
public long statsHistoryBufferSize() {
assert(isOwningHandle());
return statsHistoryBufferSize(nativeHandle_);
}
@Override
public boolean adviseRandomOnOpen() {
return adviseRandomOnOpen(nativeHandle_);
@ -883,6 +911,19 @@ public class Options extends RocksObject
return walBytesPerSync(nativeHandle_);
}
@Override
public Options setStrictBytesPerSync(final boolean strictBytesPerSync) {
assert(isOwningHandle());
setStrictBytesPerSync(nativeHandle_, strictBytesPerSync);
return this;
}
@Override
public boolean strictBytesPerSync() {
assert(isOwningHandle());
return strictBytesPerSync(nativeHandle_);
}
@Override
public Options setEnableThreadTracking(final boolean enableThreadTracking) {
assert(isOwningHandle());
@ -1858,6 +1899,14 @@ public class Options extends RocksObject
private native void setStatsDumpPeriodSec(
long handle, int statsDumpPeriodSec);
private native int statsDumpPeriodSec(long handle);
private native void setStatsPersistPeriodSec(
final long handle, final int statsPersistPeriodSec);
private native int statsPersistPeriodSec(
final long handle);
private native void setStatsHistoryBufferSize(
final long handle, final long statsHistoryBufferSize);
private native long statsHistoryBufferSize(
final long handle);
private native void setAdviseRandomOnOpen(
long handle, boolean adviseRandomOnOpen);
private native boolean adviseRandomOnOpen(long handle);
@ -1889,6 +1938,10 @@ public class Options extends RocksObject
private native long bytesPerSync(long handle);
private native void setWalBytesPerSync(long handle, long walBytesPerSync);
private native long walBytesPerSync(long handle);
private native void setStrictBytesPerSync(
final long handle, final boolean strictBytesPerSync);
private native boolean strictBytesPerSync(
final long handle);
private native void setEnableThreadTracking(long handle,
boolean enableThreadTracking);
private native boolean enableThreadTracking(long handle);

@ -406,6 +406,24 @@ public class DBOptionsTest {
}
}
@Test
public void statsPersistPeriodSec() {
try (final DBOptions opt = new DBOptions()) {
final int intValue = rand.nextInt();
opt.setStatsPersistPeriodSec(intValue);
assertThat(opt.statsPersistPeriodSec()).isEqualTo(intValue);
}
}
@Test
public void statsHistoryBufferSize() {
try (final DBOptions opt = new DBOptions()) {
final long longValue = rand.nextLong();
opt.setStatsHistoryBufferSize(longValue);
assertThat(opt.statsHistoryBufferSize()).isEqualTo(longValue);
}
}
@Test
public void adviseRandomOnOpen() {
try(final DBOptions opt = new DBOptions()) {
@ -516,6 +534,15 @@ public class DBOptionsTest {
}
}
@Test
public void strictBytesPerSync() {
try (final DBOptions opt = new DBOptions()) {
assertThat(opt.strictBytesPerSync()).isFalse();
opt.setStrictBytesPerSync(true);
assertThat(opt.strictBytesPerSync()).isTrue();
}
}
@Test
public void enableThreadTracking() {
try (final DBOptions opt = new DBOptions()) {

@ -56,21 +56,22 @@ public class MutableDBOptionsTest {
}
@Test
public void mutableColumnFamilyOptions_toString() {
public void mutableDBOptions_toString() {
final String str = MutableDBOptions
.builder()
.setMaxOpenFiles(99)
.setDelayedWriteRate(789)
.setAvoidFlushDuringShutdown(true)
.setStrictBytesPerSync(true)
.build()
.toString();
assertThat(str).isEqualTo("max_open_files=99;delayed_write_rate=789;"
+ "avoid_flush_during_shutdown=true");
+ "avoid_flush_during_shutdown=true;strict_bytes_per_sync=true");
}
@Test
public void mutableColumnFamilyOptions_parse() {
public void mutableDBOptions_parse() {
final String str = "max_open_files=99;delayed_write_rate=789;"
+ "avoid_flush_during_shutdown=true";

@ -625,6 +625,24 @@ public class OptionsTest {
}
}
@Test
public void statsPersistPeriodSec() {
try (final Options opt = new Options()) {
final int intValue = rand.nextInt();
opt.setStatsPersistPeriodSec(intValue);
assertThat(opt.statsPersistPeriodSec()).isEqualTo(intValue);
}
}
@Test
public void statsHistoryBufferSize() {
try (final Options opt = new Options()) {
final long longValue = rand.nextLong();
opt.setStatsHistoryBufferSize(longValue);
assertThat(opt.statsHistoryBufferSize()).isEqualTo(longValue);
}
}
@Test
public void adviseRandomOnOpen() {
try (final Options opt = new Options()) {
@ -735,6 +753,15 @@ public class OptionsTest {
}
}
@Test
public void strictBytesPerSync() {
try (final Options opt = new Options()) {
assertThat(opt.strictBytesPerSync()).isFalse();
opt.setStrictBytesPerSync(true);
assertThat(opt.strictBytesPerSync()).isTrue();
}
}
@Test
public void enableThreadTracking() {
try (final Options opt = new Options()) {

Loading…
Cancel
Save