Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ private void prepareOptions(Options options) throws RocksDBException {
(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(
Expand Down Expand Up @@ -1116,6 +1117,14 @@ private enum Flag {
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.") {
Expand Down
44 changes: 44 additions & 0 deletions java/rocksjni/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,28 @@ void Java_org_rocksdb_Options_setMaxBackgroundFlushes(
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
* Method: maxLogFileSize
Expand Down Expand Up @@ -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<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
* Method: setMaxLogFileSize
Expand Down
18 changes: 16 additions & 2 deletions java/src/main/java/org/rocksdb/DBOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,20 @@ public int maxBackgroundFlushes() {
}

@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;
Expand Down Expand Up @@ -998,6 +1010,8 @@ private native void setMaxBackgroundCompactions(
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);
Expand Down
25 changes: 25 additions & 0 deletions java/src/main/java/org/rocksdb/DBOptionsInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ public interface DBOptionsInterface<T extends DBOptionsInterface> {
*
* @param baseBackgroundCompactions Suggested number of background compaction
* jobs
*
* @deprecated Use {@link #setMaxBackgroundJobs(int)}
*/
void setBaseBackgroundCompactions(int baseBackgroundCompactions);

Expand Down Expand Up @@ -485,6 +487,8 @@ public interface DBOptionsInterface<T extends 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();

Expand Down Expand Up @@ -522,6 +526,8 @@ public interface DBOptionsInterface<T extends DBOptionsInterface> {
* @see RocksEnv#setBackgroundThreads(int)
* @see RocksEnv#setBackgroundThreads(int, int)
* @see #maxBackgroundCompactions()
*
* @deprecated Use {@link #setMaxBackgroundJobs(int)}
*/
T setMaxBackgroundFlushes(int maxBackgroundFlushes);

Expand All @@ -537,6 +543,25 @@ public interface DBOptionsInterface<T extends 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
Expand Down
15 changes: 15 additions & 0 deletions java/src/main/java/org/rocksdb/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,19 @@ public Options setMaxBackgroundFlushes(
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());
Expand Down Expand Up @@ -1591,6 +1604,8 @@ private native void setMaxBackgroundCompactions(
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);
Expand Down
9 changes: 9 additions & 0 deletions java/src/test/java/org/rocksdb/DBOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ public void maxBackgroundFlushes() {
}
}

@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()) {
Expand Down
9 changes: 9 additions & 0 deletions java/src/test/java/org/rocksdb/OptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,15 @@ public void maxBackgroundFlushes() {
}
}

@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()) {
Expand Down