diff --git a/java/benchmark/src/main/java/org/rocksdb/benchmark/DbBenchmark.java b/java/benchmark/src/main/java/org/rocksdb/benchmark/DbBenchmark.java index 8af6d2edf..db69e58cc 100644 --- a/java/benchmark/src/main/java/org/rocksdb/benchmark/DbBenchmark.java +++ b/java/benchmark/src/main/java/org/rocksdb/benchmark/DbBenchmark.java @@ -543,6 +543,7 @@ public class DbBenchmark { (Integer)flags_.get(Flag.max_background_compactions)); options.setMaxBackgroundFlushes( (Integer)flags_.get(Flag.max_background_flushes)); + options.setMaxBackgroundJobs((Integer) flags_.get(Flag.max_background_jobs)); options.setMaxOpenFiles( (Integer)flags_.get(Flag.open_files)); options.setUseFsync( @@ -1116,6 +1117,14 @@ public class DbBenchmark { return Integer.parseInt(value); } }, + max_background_jobs(defaultOptions_.maxBackgroundJobs(), + "The maximum number of concurrent background jobs\n" + + "\tthat can occur in parallel.") { + @Override + public Object parseValue(String value) { + return Integer.parseInt(value); + } + }, /* TODO(yhchiang): enable the following compaction_style((int32_t) defaultOptions_.compactionStyle(), "style of compaction: level-based vs universal.") { diff --git a/java/rocksjni/options.cc b/java/rocksjni/options.cc index f52171244..4c71b5fad 100644 --- a/java/rocksjni/options.cc +++ b/java/rocksjni/options.cc @@ -668,6 +668,28 @@ void Java_org_rocksdb_Options_setMaxBackgroundFlushes( static_cast(max_background_flushes); } +/* + * Class: org_rocksdb_Options + * Method: maxBackgroundJobs + * Signature: (J)I + */ +jint Java_org_rocksdb_Options_maxBackgroundJobs(JNIEnv* env, jobject jobj, + jlong jhandle) { + return reinterpret_cast(jhandle)->max_background_jobs; +} + +/* + * Class: org_rocksdb_Options + * Method: setMaxBackgroundJobs + * Signature: (JI)V + */ +void Java_org_rocksdb_Options_setMaxBackgroundJobs(JNIEnv* env, jobject jobj, + jlong jhandle, + jint max_background_jobs) { + reinterpret_cast(jhandle)->max_background_jobs = + static_cast(max_background_jobs); +} + /* * Class: org_rocksdb_Options * Method: maxLogFileSize @@ -4700,6 +4722,28 @@ jint Java_org_rocksdb_DBOptions_maxBackgroundFlushes( max_background_flushes; } +/* + * Class: org_rocksdb_DBOptions + * Method: setMaxBackgroundJobs + * Signature: (JI)V + */ +void Java_org_rocksdb_DBOptions_setMaxBackgroundJobs(JNIEnv* env, jobject jobj, + jlong jhandle, + jint max_background_jobs) { + reinterpret_cast(jhandle)->max_background_jobs = + static_cast(max_background_jobs); +} + +/* + * Class: org_rocksdb_DBOptions + * Method: maxBackgroundJobs + * Signature: (J)I + */ +jint Java_org_rocksdb_DBOptions_maxBackgroundJobs(JNIEnv* env, jobject jobj, + jlong jhandle) { + return reinterpret_cast(jhandle)->max_background_jobs; +} + /* * Class: org_rocksdb_DBOptions * Method: setMaxLogFileSize diff --git a/java/src/main/java/org/rocksdb/DBOptions.java b/java/src/main/java/org/rocksdb/DBOptions.java index 14f0c6c7c..0e9bb1619 100644 --- a/java/src/main/java/org/rocksdb/DBOptions.java +++ b/java/src/main/java/org/rocksdb/DBOptions.java @@ -390,8 +390,20 @@ public class DBOptions } @Override - public DBOptions setMaxLogFileSize( - final long maxLogFileSize) { + public DBOptions setMaxBackgroundJobs(final int maxBackgroundJobs) { + assert(isOwningHandle()); + setMaxBackgroundJobs(nativeHandle_, maxBackgroundJobs); + return this; + } + + @Override + public int maxBackgroundJobs() { + assert(isOwningHandle()); + return maxBackgroundJobs(nativeHandle_); + } + + @Override + public DBOptions setMaxLogFileSize(final long maxLogFileSize) { assert(isOwningHandle()); setMaxLogFileSize(nativeHandle_, maxLogFileSize); return this; @@ -998,6 +1010,8 @@ public class DBOptions private native void setMaxBackgroundFlushes( long handle, int maxBackgroundFlushes); private native int maxBackgroundFlushes(long handle); + private native void setMaxBackgroundJobs(long handle, int maxBackgroundJobs); + private native int maxBackgroundJobs(long handle); private native void setMaxLogFileSize(long handle, long maxLogFileSize) throws IllegalArgumentException; private native long maxLogFileSize(long handle); diff --git a/java/src/main/java/org/rocksdb/DBOptionsInterface.java b/java/src/main/java/org/rocksdb/DBOptionsInterface.java index 50ca083d3..f42670190 100644 --- a/java/src/main/java/org/rocksdb/DBOptionsInterface.java +++ b/java/src/main/java/org/rocksdb/DBOptionsInterface.java @@ -446,6 +446,8 @@ public interface DBOptionsInterface { * * @param baseBackgroundCompactions Suggested number of background compaction * jobs + * + * @deprecated Use {@link #setMaxBackgroundJobs(int)} */ void setBaseBackgroundCompactions(int baseBackgroundCompactions); @@ -485,6 +487,8 @@ public interface DBOptionsInterface { * @return the maximum number of concurrent background compaction jobs. * @see RocksEnv#setBackgroundThreads(int) * @see RocksEnv#setBackgroundThreads(int, int) + * + * @deprecated Use {@link #setMaxBackgroundJobs(int)} */ int maxBackgroundCompactions(); @@ -522,6 +526,8 @@ public interface DBOptionsInterface { * @see RocksEnv#setBackgroundThreads(int) * @see RocksEnv#setBackgroundThreads(int, int) * @see #maxBackgroundCompactions() + * + * @deprecated Use {@link #setMaxBackgroundJobs(int)} */ T setMaxBackgroundFlushes(int maxBackgroundFlushes); @@ -537,6 +543,25 @@ public interface DBOptionsInterface { */ int maxBackgroundFlushes(); + /** + * Specifies the maximum number of concurrent background jobs (both flushes + * and compactions combined). + * Default: 2 + * + * @param maxBackgroundJobs number of max concurrent background jobs + * @return the instance of the current object. + */ + T setMaxBackgroundJobs(int maxBackgroundJobs); + + /** + * Returns the maximum number of concurrent background jobs (both flushes + * and compactions combined). + * Default: 2 + * + * @return the maximum number of concurrent background jobs. + */ + int maxBackgroundJobs(); + /** * Specifies the maximum size of a info log file. If the current log file * is larger than `max_log_file_size`, a new info log file will diff --git a/java/src/main/java/org/rocksdb/Options.java b/java/src/main/java/org/rocksdb/Options.java index dcd1138a8..8d2677824 100644 --- a/java/src/main/java/org/rocksdb/Options.java +++ b/java/src/main/java/org/rocksdb/Options.java @@ -443,6 +443,19 @@ public class Options extends RocksObject return this; } + @Override + public int maxBackgroundJobs() { + assert(isOwningHandle()); + return maxBackgroundJobs(nativeHandle_); + } + + @Override + public Options setMaxBackgroundJobs(final int maxBackgroundJobs) { + assert(isOwningHandle()); + setMaxBackgroundJobs(nativeHandle_, maxBackgroundJobs); + return this; + } + @Override public long maxLogFileSize() { assert(isOwningHandle()); @@ -1591,6 +1604,8 @@ public class Options extends RocksObject private native void setMaxBackgroundFlushes( long handle, int maxBackgroundFlushes); private native int maxBackgroundFlushes(long handle); + private native void setMaxBackgroundJobs(long handle, int maxMaxBackgroundJobs); + private native int maxBackgroundJobs(long handle); private native void setMaxLogFileSize(long handle, long maxLogFileSize) throws IllegalArgumentException; private native long maxLogFileSize(long handle); diff --git a/java/src/test/java/org/rocksdb/DBOptionsTest.java b/java/src/test/java/org/rocksdb/DBOptionsTest.java index 11b7435d8..416669e18 100644 --- a/java/src/test/java/org/rocksdb/DBOptionsTest.java +++ b/java/src/test/java/org/rocksdb/DBOptionsTest.java @@ -240,6 +240,15 @@ public class DBOptionsTest { } } + @Test + public void maxBackgroundJobs() { + try (final DBOptions opt = new DBOptions()) { + final int intValue = rand.nextInt(); + opt.setMaxBackgroundJobs(intValue); + assertThat(opt.maxBackgroundJobs()).isEqualTo(intValue); + } + } + @Test public void maxLogFileSize() throws RocksDBException { try(final DBOptions opt = new DBOptions()) { diff --git a/java/src/test/java/org/rocksdb/OptionsTest.java b/java/src/test/java/org/rocksdb/OptionsTest.java index 6afcab330..7a8142e7c 100644 --- a/java/src/test/java/org/rocksdb/OptionsTest.java +++ b/java/src/test/java/org/rocksdb/OptionsTest.java @@ -458,6 +458,15 @@ public class OptionsTest { } } + @Test + public void maxBackgroundJobs() { + try (final Options opt = new Options()) { + final int intValue = rand.nextInt(); + opt.setMaxBackgroundJobs(intValue); + assertThat(opt.maxBackgroundJobs()).isEqualTo(intValue); + } + } + @Test public void maxLogFileSize() throws RocksDBException { try (final Options opt = new Options()) {