From ebdfe34cc4ed2ab2b87d4eccefdd98f9ac38caf5 Mon Sep 17 00:00:00 2001 From: Adam Retter Date: Tue, 14 Jun 2016 16:51:56 +0100 Subject: [PATCH] Exposed further Java API options for controlling compaction --- java/rocksjni/options.cc | 88 +++++++++++++++++++ java/src/main/java/org/rocksdb/DBOptions.java | 30 +++++++ .../java/org/rocksdb/DBOptionsInterface.java | 41 +++++++++ java/src/main/java/org/rocksdb/Options.java | 30 +++++++ .../test/java/org/rocksdb/DBOptionsTest.java | 20 +++++ .../test/java/org/rocksdb/OptionsTest.java | 20 +++++ 6 files changed, 229 insertions(+) diff --git a/java/rocksjni/options.cc b/java/rocksjni/options.cc index 079c6b274..76dc1d145 100644 --- a/java/rocksjni/options.cc +++ b/java/rocksjni/options.cc @@ -453,6 +453,28 @@ void Java_org_rocksdb_Options_setDeleteObsoleteFilesPeriodMicros( static_cast(micros); } +/* + * Class: org_rocksdb_Options + * Method: setBaseBackgroundCompactions + * Signature: (JI)V + */ +void Java_org_rocksdb_Options_setBaseBackgroundCompactions( + JNIEnv* env, jobject jobj, jlong jhandle, jint max) { + reinterpret_cast(jhandle) + ->base_background_compactions = static_cast(max); +} + +/* + * Class: org_rocksdb_Options + * Method: baseBackgroundCompactions + * Signature: (J)I + */ +jint Java_org_rocksdb_Options_baseBackgroundCompactions( + JNIEnv* env, jobject jobj, jlong jhandle) { + return reinterpret_cast(jhandle) + ->base_background_compactions; +} + /* * Class: org_rocksdb_Options * Method: maxBackgroundCompactions @@ -475,6 +497,28 @@ void Java_org_rocksdb_Options_setMaxBackgroundCompactions( ->max_background_compactions = static_cast(max); } +/* + * Class: org_rocksdb_Options + * Method: setMaxSubcompactions + * Signature: (JI)V + */ +void Java_org_rocksdb_Options_setMaxSubcompactions( + JNIEnv* env, jobject jobj, jlong jhandle, jint max) { + reinterpret_cast(jhandle) + ->max_subcompactions = static_cast(max); +} + +/* + * Class: org_rocksdb_Options + * Method: maxSubcompactions + * Signature: (J)I + */ +jint Java_org_rocksdb_Options_maxSubcompactions( + JNIEnv* env, jobject jobj, jlong jhandle) { + return reinterpret_cast(jhandle) + ->max_subcompactions; +} + /* * Class: org_rocksdb_Options * Method: maxBackgroundFlushes @@ -3769,6 +3813,28 @@ jlong Java_org_rocksdb_DBOptions_deleteObsoleteFilesPeriodMicros( ->delete_obsolete_files_period_micros; } +/* + * Class: org_rocksdb_DBOptions + * Method: setBaseBackgroundCompactions + * Signature: (JI)V + */ +void Java_org_rocksdb_DBOptions_setBaseBackgroundCompactions( + JNIEnv* env, jobject jobj, jlong jhandle, jint max) { + reinterpret_cast(jhandle) + ->base_background_compactions = static_cast(max); +} + +/* + * Class: org_rocksdb_DBOptions + * Method: baseBackgroundCompactions + * Signature: (J)I + */ +jint Java_org_rocksdb_DBOptions_baseBackgroundCompactions( + JNIEnv* env, jobject jobj, jlong jhandle) { + return reinterpret_cast(jhandle) + ->base_background_compactions; +} + /* * Class: org_rocksdb_DBOptions * Method: setMaxBackgroundCompactions @@ -3791,6 +3857,28 @@ jint Java_org_rocksdb_DBOptions_maxBackgroundCompactions( jhandle)->max_background_compactions; } +/* + * Class: org_rocksdb_DBOptions + * Method: setMaxSubcompactions + * Signature: (JI)V + */ +void Java_org_rocksdb_DBOptions_setMaxSubcompactions( + JNIEnv* env, jobject jobj, jlong jhandle, jint max) { + reinterpret_cast(jhandle) + ->max_subcompactions = static_cast(max); +} + +/* + * Class: org_rocksdb_DBOptions + * Method: maxSubcompactions + * Signature: (J)I + */ +jint Java_org_rocksdb_DBOptions_maxSubcompactions( + JNIEnv* env, jobject jobj, jlong jhandle) { + return reinterpret_cast(jhandle) + ->max_subcompactions; +} + /* * Class: org_rocksdb_DBOptions * Method: setMaxBackgroundFlushes diff --git a/java/src/main/java/org/rocksdb/DBOptions.java b/java/src/main/java/org/rocksdb/DBOptions.java index 878dd4d70..967673d8b 100644 --- a/java/src/main/java/org/rocksdb/DBOptions.java +++ b/java/src/main/java/org/rocksdb/DBOptions.java @@ -283,6 +283,19 @@ public class DBOptions extends RocksObject implements DBOptionsInterface { return deleteObsoleteFilesPeriodMicros(nativeHandle_); } + @Override + public void setBaseBackgroundCompactions( + final int baseBackgroundCompactions) { + assert(isOwningHandle()); + setBaseBackgroundCompactions(nativeHandle_, baseBackgroundCompactions); + } + + @Override + public int baseBackgroundCompactions() { + assert(isOwningHandle()); + return baseBackgroundCompactions(nativeHandle_); + } + @Override public DBOptions setMaxBackgroundCompactions( final int maxBackgroundCompactions) { @@ -297,6 +310,18 @@ public class DBOptions extends RocksObject implements DBOptionsInterface { return maxBackgroundCompactions(nativeHandle_); } + @Override + public void setMaxSubcompactions(final int maxSubcompactions) { + assert(isOwningHandle()); + setMaxSubcompactions(nativeHandle_, maxSubcompactions); + } + + @Override + public int maxSubcompactions() { + assert(isOwningHandle()); + return maxSubcompactions(nativeHandle_); + } + @Override public DBOptions setMaxBackgroundFlushes( final int maxBackgroundFlushes) { @@ -586,9 +611,14 @@ public class DBOptions extends RocksObject implements DBOptionsInterface { private native void setDeleteObsoleteFilesPeriodMicros( long handle, long micros); private native long deleteObsoleteFilesPeriodMicros(long handle); + private native void setBaseBackgroundCompactions(long handle, + int baseBackgroundCompactions); + private native int baseBackgroundCompactions(long handle); private native void setMaxBackgroundCompactions( long handle, int maxBackgroundCompactions); private native int maxBackgroundCompactions(long handle); + private native void setMaxSubcompactions(long handle, int maxSubcompactions); + private native int maxSubcompactions(long handle); private native void setMaxBackgroundFlushes( long handle, int maxBackgroundFlushes); private native int maxBackgroundFlushes(long handle); diff --git a/java/src/main/java/org/rocksdb/DBOptionsInterface.java b/java/src/main/java/org/rocksdb/DBOptionsInterface.java index 917e26ab0..3fa34dae5 100644 --- a/java/src/main/java/org/rocksdb/DBOptionsInterface.java +++ b/java/src/main/java/org/rocksdb/DBOptionsInterface.java @@ -350,6 +350,25 @@ public interface DBOptionsInterface { */ long deleteObsoleteFilesPeriodMicros(); + /** + * Suggested number of concurrent background compaction jobs, submitted to + * the default LOW priority thread pool. + * Default: 1 + * + * @param baseBackgroundCompactions Suggested number of background compaction + * jobs + */ + void setBaseBackgroundCompactions(int baseBackgroundCompactions); + + /** + * Suggested number of concurrent background compaction jobs, submitted to + * the default LOW priority thread pool. + * Default: 1 + * + * @return Suggested number of background compaction jobs + */ + int baseBackgroundCompactions(); + /** * Specifies the maximum number of concurrent background compaction jobs, * submitted to the default LOW priority thread pool. @@ -380,6 +399,28 @@ public interface DBOptionsInterface { */ int maxBackgroundCompactions(); + /** + * This value represents the maximum number of threads that will + * concurrently perform a compaction job by breaking it into multiple, + * smaller ones that are run simultaneously. + * Default: 1 (i.e. no subcompactions) + * + * @param maxSubcompactions The maximum number of threads that will + * concurrently perform a compaction job + */ + void setMaxSubcompactions(int maxSubcompactions); + + /** + * This value represents the maximum number of threads that will + * concurrently perform a compaction job by breaking it into multiple, + * smaller ones that are run simultaneously. + * Default: 1 (i.e. no subcompactions) + * + * @return The maximum number of threads that will concurrently perform a + * compaction job + */ + int maxSubcompactions(); + /** * Specifies the maximum number of concurrent background flush jobs. * If you're increasing this, also consider increasing number of threads in diff --git a/java/src/main/java/org/rocksdb/Options.java b/java/src/main/java/org/rocksdb/Options.java index 8ca2ebd0c..39c48df06 100644 --- a/java/src/main/java/org/rocksdb/Options.java +++ b/java/src/main/java/org/rocksdb/Options.java @@ -362,6 +362,19 @@ public class Options extends RocksObject return new Statistics(statsPtr); } + @Override + public void setBaseBackgroundCompactions( + final int baseBackgroundCompactions) { + assert(isOwningHandle()); + setBaseBackgroundCompactions(nativeHandle_, baseBackgroundCompactions); + } + + @Override + public int baseBackgroundCompactions() { + assert(isOwningHandle()); + return baseBackgroundCompactions(nativeHandle_); + } + @Override public Options setMaxBackgroundCompactions( final int maxBackgroundCompactions) { @@ -370,6 +383,18 @@ public class Options extends RocksObject return this; } + @Override + public void setMaxSubcompactions(final int maxSubcompactions) { + assert(isOwningHandle()); + setMaxSubcompactions(nativeHandle_, maxSubcompactions); + } + + @Override + public int maxSubcompactions() { + assert(isOwningHandle()); + return maxSubcompactions(nativeHandle_); + } + @Override public int maxBackgroundFlushes() { assert(isOwningHandle()); @@ -1197,9 +1222,14 @@ public class Options extends RocksObject private native void setDeleteObsoleteFilesPeriodMicros( long handle, long micros); private native long deleteObsoleteFilesPeriodMicros(long handle); + private native void setBaseBackgroundCompactions(long handle, + int baseBackgroundCompactions); + private native int baseBackgroundCompactions(long handle); private native void setMaxBackgroundCompactions( long handle, int maxBackgroundCompactions); private native int maxBackgroundCompactions(long handle); + private native void setMaxSubcompactions(long handle, int maxSubcompactions); + private native int maxSubcompactions(long handle); private native void setMaxBackgroundFlushes( long handle, int maxBackgroundFlushes); private native int maxBackgroundFlushes(long handle); diff --git a/java/src/test/java/org/rocksdb/DBOptionsTest.java b/java/src/test/java/org/rocksdb/DBOptionsTest.java index 523e53784..2527ce949 100644 --- a/java/src/test/java/org/rocksdb/DBOptionsTest.java +++ b/java/src/test/java/org/rocksdb/DBOptionsTest.java @@ -170,6 +170,16 @@ public class DBOptionsTest { } } + @Test + public void baseBackgroundCompactions() { + try (final DBOptions opt = new DBOptions()) { + final int intValue = rand.nextInt(); + opt.setBaseBackgroundCompactions(intValue); + assertThat(opt.baseBackgroundCompactions()). + isEqualTo(intValue); + } + } + @Test public void maxBackgroundCompactions() { try(final DBOptions opt = new DBOptions()) { @@ -179,6 +189,16 @@ public class DBOptionsTest { } } + @Test + public void maxSubcompactions() { + try (final DBOptions opt = new DBOptions()) { + final int intValue = rand.nextInt(); + opt.setMaxSubcompactions(intValue); + assertThat(opt.maxSubcompactions()). + isEqualTo(intValue); + } + } + @Test public void maxBackgroundFlushes() { 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 2aa08c9a2..13d84bd58 100644 --- a/java/src/test/java/org/rocksdb/OptionsTest.java +++ b/java/src/test/java/org/rocksdb/OptionsTest.java @@ -473,6 +473,16 @@ public class OptionsTest { } } + @Test + public void baseBackgroundCompactions() { + try (final Options opt = new Options()) { + final int intValue = rand.nextInt(); + opt.setBaseBackgroundCompactions(intValue); + assertThat(opt.baseBackgroundCompactions()). + isEqualTo(intValue); + } + } + @Test public void maxBackgroundCompactions() { try (final Options opt = new Options()) { @@ -483,6 +493,16 @@ public class OptionsTest { } } + @Test + public void maxSubcompactions() { + try (final Options opt = new Options()) { + final int intValue = rand.nextInt(); + opt.setMaxSubcompactions(intValue); + assertThat(opt.maxSubcompactions()). + isEqualTo(intValue); + } + } + @Test public void maxBackgroundFlushes() { try (final Options opt = new Options()) {