Expose max_background_jobs option in RocksJava

Summary:
This option was introduced in the C++ API in RocksDB 5.6 in bb01c1880c . Now, exposing it through RocksJava API.
Closes https://github.com/facebook/rocksdb/pull/2908

Differential Revision: D5864224

Pulled By: sagar0

fbshipit-source-id: 140aa55dcf74b14e4d11219d996735c7fdddf513
main
Sagar Vemuri 7 years ago committed by Facebook Github Bot
parent 8ae81684e9
commit 3fc08fa88e
  1. 9
      java/benchmark/src/main/java/org/rocksdb/benchmark/DbBenchmark.java
  2. 44
      java/rocksjni/options.cc
  3. 18
      java/src/main/java/org/rocksdb/DBOptions.java
  4. 25
      java/src/main/java/org/rocksdb/DBOptionsInterface.java
  5. 15
      java/src/main/java/org/rocksdb/Options.java
  6. 9
      java/src/test/java/org/rocksdb/DBOptionsTest.java
  7. 9
      java/src/test/java/org/rocksdb/OptionsTest.java

@ -543,6 +543,7 @@ public class DbBenchmark {
(Integer)flags_.get(Flag.max_background_compactions)); (Integer)flags_.get(Flag.max_background_compactions));
options.setMaxBackgroundFlushes( options.setMaxBackgroundFlushes(
(Integer)flags_.get(Flag.max_background_flushes)); (Integer)flags_.get(Flag.max_background_flushes));
options.setMaxBackgroundJobs((Integer) flags_.get(Flag.max_background_jobs));
options.setMaxOpenFiles( options.setMaxOpenFiles(
(Integer)flags_.get(Flag.open_files)); (Integer)flags_.get(Flag.open_files));
options.setUseFsync( options.setUseFsync(
@ -1116,6 +1117,14 @@ public class DbBenchmark {
return Integer.parseInt(value); 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 /* TODO(yhchiang): enable the following
compaction_style((int32_t) defaultOptions_.compactionStyle(), compaction_style((int32_t) defaultOptions_.compactionStyle(),
"style of compaction: level-based vs universal.") { "style of compaction: level-based vs universal.") {

@ -668,6 +668,28 @@ void Java_org_rocksdb_Options_setMaxBackgroundFlushes(
static_cast<int>(max_background_flushes); static_cast<int>(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<rocksdb::Options*>(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<rocksdb::Options*>(jhandle)->max_background_jobs =
static_cast<int>(max_background_jobs);
}
/* /*
* Class: org_rocksdb_Options * Class: org_rocksdb_Options
* Method: maxLogFileSize * Method: maxLogFileSize
@ -4700,6 +4722,28 @@ jint Java_org_rocksdb_DBOptions_maxBackgroundFlushes(
max_background_flushes; 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<rocksdb::DBOptions*>(jhandle)->max_background_jobs =
static_cast<int>(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<rocksdb::DBOptions*>(jhandle)->max_background_jobs;
}
/* /*
* Class: org_rocksdb_DBOptions * Class: org_rocksdb_DBOptions
* Method: setMaxLogFileSize * Method: setMaxLogFileSize

@ -390,8 +390,20 @@ public class DBOptions
} }
@Override @Override
public DBOptions setMaxLogFileSize( public DBOptions setMaxBackgroundJobs(final int maxBackgroundJobs) {
final long maxLogFileSize) { 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()); assert(isOwningHandle());
setMaxLogFileSize(nativeHandle_, maxLogFileSize); setMaxLogFileSize(nativeHandle_, maxLogFileSize);
return this; return this;
@ -998,6 +1010,8 @@ public class DBOptions
private native void setMaxBackgroundFlushes( private native void setMaxBackgroundFlushes(
long handle, int maxBackgroundFlushes); long handle, int maxBackgroundFlushes);
private native int maxBackgroundFlushes(long handle); 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) private native void setMaxLogFileSize(long handle, long maxLogFileSize)
throws IllegalArgumentException; throws IllegalArgumentException;
private native long maxLogFileSize(long handle); private native long maxLogFileSize(long handle);

@ -446,6 +446,8 @@ public interface DBOptionsInterface<T extends DBOptionsInterface> {
* *
* @param baseBackgroundCompactions Suggested number of background compaction * @param baseBackgroundCompactions Suggested number of background compaction
* jobs * jobs
*
* @deprecated Use {@link #setMaxBackgroundJobs(int)}
*/ */
void setBaseBackgroundCompactions(int baseBackgroundCompactions); void setBaseBackgroundCompactions(int baseBackgroundCompactions);
@ -485,6 +487,8 @@ public interface DBOptionsInterface<T extends DBOptionsInterface> {
* @return the maximum number of concurrent background compaction jobs. * @return the maximum number of concurrent background compaction jobs.
* @see RocksEnv#setBackgroundThreads(int) * @see RocksEnv#setBackgroundThreads(int)
* @see RocksEnv#setBackgroundThreads(int, int) * @see RocksEnv#setBackgroundThreads(int, int)
*
* @deprecated Use {@link #setMaxBackgroundJobs(int)}
*/ */
int maxBackgroundCompactions(); int maxBackgroundCompactions();
@ -522,6 +526,8 @@ public interface DBOptionsInterface<T extends DBOptionsInterface> {
* @see RocksEnv#setBackgroundThreads(int) * @see RocksEnv#setBackgroundThreads(int)
* @see RocksEnv#setBackgroundThreads(int, int) * @see RocksEnv#setBackgroundThreads(int, int)
* @see #maxBackgroundCompactions() * @see #maxBackgroundCompactions()
*
* @deprecated Use {@link #setMaxBackgroundJobs(int)}
*/ */
T setMaxBackgroundFlushes(int maxBackgroundFlushes); T setMaxBackgroundFlushes(int maxBackgroundFlushes);
@ -537,6 +543,25 @@ public interface DBOptionsInterface<T extends DBOptionsInterface> {
*/ */
int maxBackgroundFlushes(); 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 * 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 * is larger than `max_log_file_size`, a new info log file will

@ -443,6 +443,19 @@ public class Options extends RocksObject
return this; 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 @Override
public long maxLogFileSize() { public long maxLogFileSize() {
assert(isOwningHandle()); assert(isOwningHandle());
@ -1591,6 +1604,8 @@ public class Options extends RocksObject
private native void setMaxBackgroundFlushes( private native void setMaxBackgroundFlushes(
long handle, int maxBackgroundFlushes); long handle, int maxBackgroundFlushes);
private native int maxBackgroundFlushes(long handle); 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) private native void setMaxLogFileSize(long handle, long maxLogFileSize)
throws IllegalArgumentException; throws IllegalArgumentException;
private native long maxLogFileSize(long handle); private native long maxLogFileSize(long handle);

@ -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 @Test
public void maxLogFileSize() throws RocksDBException { public void maxLogFileSize() throws RocksDBException {
try(final DBOptions opt = new DBOptions()) { try(final DBOptions opt = new DBOptions()) {

@ -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 @Test
public void maxLogFileSize() throws RocksDBException { public void maxLogFileSize() throws RocksDBException {
try (final Options opt = new Options()) { try (final Options opt = new Options()) {

Loading…
Cancel
Save