From 04778a94c5721c7e5de303b7bd5375efaf1710da Mon Sep 17 00:00:00 2001 From: fyrz Date: Sat, 28 Feb 2015 22:38:58 +0100 Subject: [PATCH] [RocksJava] OptimizeFiltersForHits Summary: Added optimize_filters_for_hits option. Test Plan: make clean jclean rocksdbjava jtest mvn -f rocksjni.pom package Reviewers: adamretter, yhchiang, ankgup87 Subscribers: dhruba Differential Revision: https://reviews.facebook.net/D35013 --- java/rocksjni/options.cc | 48 +++++++++++++++++++ .../java/org/rocksdb/ColumnFamilyOptions.java | 15 ++++++ .../rocksdb/ColumnFamilyOptionsInterface.java | 32 +++++++++++++ java/src/main/java/org/rocksdb/Options.java | 15 ++++++ .../org/rocksdb/ColumnFamilyOptionsTest.java | 15 ++++++ .../test/java/org/rocksdb/OptionsTest.java | 15 ++++++ 6 files changed, 140 insertions(+) diff --git a/java/rocksjni/options.cc b/java/rocksjni/options.cc index 9f0875b32..9446cd8eb 100644 --- a/java/rocksjni/options.cc +++ b/java/rocksjni/options.cc @@ -1731,6 +1731,30 @@ void Java_org_rocksdb_Options_setMinPartialMergeOperands( static_cast(jmin_partial_merge_operands); } +/* + * Class: org_rocksdb_Options + * Method: optimizeFiltersForHits + * Signature: (J)Z + */ +jboolean Java_org_rocksdb_Options_optimizeFiltersForHits( + JNIEnv* env, jobject jobj, jlong jhandle) { + return reinterpret_cast( + jhandle)->optimize_filters_for_hits; +} + +/* + * Class: org_rocksdb_Options + * Method: setOptimizeFiltersForHits + * Signature: (JZ)V + */ +void Java_org_rocksdb_Options_setOptimizeFiltersForHits( + JNIEnv* env, jobject jobj, jlong jhandle, + jboolean joptimize_filters_for_hits) { + reinterpret_cast( + jhandle)->optimize_filters_for_hits = + static_cast(joptimize_filters_for_hits); +} + /* * Method: optimizeForPointLookup * Signature: (JJ)V @@ -2778,6 +2802,30 @@ void Java_org_rocksdb_ColumnFamilyOptions_setMinPartialMergeOperands( static_cast(jmin_partial_merge_operands); } +/* + * Class: org_rocksdb_ColumnFamilyOptions + * Method: optimizeFiltersForHits + * Signature: (J)Z + */ +jboolean Java_org_rocksdb_ColumnFamilyOptions_optimizeFiltersForHits( + JNIEnv* env, jobject jobj, jlong jhandle) { + return reinterpret_cast( + jhandle)->optimize_filters_for_hits; +} + +/* + * Class: org_rocksdb_ColumnFamilyOptions + * Method: setOptimizeFiltersForHits + * Signature: (JZ)V + */ +void Java_org_rocksdb_ColumnFamilyOptions_setOptimizeFiltersForHits( + JNIEnv* env, jobject jobj, jlong jhandle, + jboolean joptimize_filters_for_hits) { + reinterpret_cast( + jhandle)->optimize_filters_for_hits = + static_cast(joptimize_filters_for_hits); +} + ///////////////////////////////////////////////////////////////////// // rocksdb::DBOptions diff --git a/java/src/main/java/org/rocksdb/ColumnFamilyOptions.java b/java/src/main/java/org/rocksdb/ColumnFamilyOptions.java index 84abb4607..a449a0b75 100644 --- a/java/src/main/java/org/rocksdb/ColumnFamilyOptions.java +++ b/java/src/main/java/org/rocksdb/ColumnFamilyOptions.java @@ -580,6 +580,18 @@ public class ColumnFamilyOptions extends RocksObject return minPartialMergeOperands(nativeHandle_); } + @Override + public ColumnFamilyOptions setOptimizeFiltersForHits( + final boolean optimizeFiltersForHits) { + setOptimizeFiltersForHits(nativeHandle_, optimizeFiltersForHits); + return this; + } + + @Override + public boolean optimizeFiltersForHits() { + return optimizeFiltersForHits(nativeHandle_); + } + /** * Release the memory allocated for the current instance * in the c++ side. @@ -721,6 +733,9 @@ public class ColumnFamilyOptions extends RocksObject private native void setMinPartialMergeOperands( long handle, int minPartialMergeOperands); private native int minPartialMergeOperands(long handle); + private native void setOptimizeFiltersForHits(long handle, + boolean optimizeFiltersForHits); + private native boolean optimizeFiltersForHits(long handle); MemTableConfig memTableConfig_; TableFormatConfig tableFormatConfig_; diff --git a/java/src/main/java/org/rocksdb/ColumnFamilyOptionsInterface.java b/java/src/main/java/org/rocksdb/ColumnFamilyOptionsInterface.java index 0cbc8ac6c..c79c8f9ba 100644 --- a/java/src/main/java/org/rocksdb/ColumnFamilyOptionsInterface.java +++ b/java/src/main/java/org/rocksdb/ColumnFamilyOptionsInterface.java @@ -975,6 +975,38 @@ public interface ColumnFamilyOptionsInterface { */ int minPartialMergeOperands(); + /** + *

This flag specifies that the implementation should optimize the filters + * mainly for cases where keys are found rather than also optimize for keys + * missed. This would be used in cases where the application knows that + * there are very few misses or the performance in the case of misses is not + * important.

+ * + *

For now, this flag allows us to not store filters for the last level i.e + * the largest level which contains data of the LSM store. For keys which + * are hits, the filters in this level are not useful because we will search + * for the data anyway.

+ * + *

NOTE: the filters in other levels are still useful + * even for key hit because they tell us whether to look in that level or go + * to the higher level.

+ * + *

Default: false

+ * + * @param optimizeFiltersForHits boolean value indicating if this flag is set. + * @return the reference to the current option. + */ + Object setOptimizeFiltersForHits(boolean optimizeFiltersForHits); + + /** + *

Returns the current state of the {@code optimize_filters_for_hits} + * setting.

+ * + * @return boolean value indicating if the flag + * {@code optimize_filters_for_hits} was set. + */ + boolean optimizeFiltersForHits(); + /** * Default memtable memory budget used with the following methods: * diff --git a/java/src/main/java/org/rocksdb/Options.java b/java/src/main/java/org/rocksdb/Options.java index 98e6b19c6..3b6b6301a 100644 --- a/java/src/main/java/org/rocksdb/Options.java +++ b/java/src/main/java/org/rocksdb/Options.java @@ -1044,6 +1044,18 @@ public class Options extends RocksObject return this; } + @Override + public Options setOptimizeFiltersForHits( + final boolean optimizeFiltersForHits) { + setOptimizeFiltersForHits(nativeHandle_, optimizeFiltersForHits); + return this; + } + + @Override + public boolean optimizeFiltersForHits() { + return optimizeFiltersForHits(nativeHandle_); + } + /** * Release the memory allocated for the current instance * in the c++ side. @@ -1268,6 +1280,9 @@ public class Options extends RocksObject private native void setMinPartialMergeOperands( long handle, int minPartialMergeOperands); private native int minPartialMergeOperands(long handle); + private native void setOptimizeFiltersForHits(long handle, + boolean optimizeFiltersForHits); + private native boolean optimizeFiltersForHits(long handle); // instance variables RocksEnv env_; MemTableConfig memTableConfig_; diff --git a/java/src/test/java/org/rocksdb/ColumnFamilyOptionsTest.java b/java/src/test/java/org/rocksdb/ColumnFamilyOptionsTest.java index 4082c602d..ad1a66617 100644 --- a/java/src/test/java/org/rocksdb/ColumnFamilyOptionsTest.java +++ b/java/src/test/java/org/rocksdb/ColumnFamilyOptionsTest.java @@ -538,6 +538,21 @@ public class ColumnFamilyOptionsTest { } } + @Test + public void optimizeFiltersForHits() { + ColumnFamilyOptions opt = null; + try { + boolean aBoolean = rand.nextBoolean(); + opt = new ColumnFamilyOptions(); + opt.setOptimizeFiltersForHits(aBoolean); + assertThat(opt.optimizeFiltersForHits()).isEqualTo(aBoolean); + } finally { + if (opt != null) { + opt.dispose(); + } + } + } + @Test public void memTable() throws RocksDBException { ColumnFamilyOptions opt = null; diff --git a/java/src/test/java/org/rocksdb/OptionsTest.java b/java/src/test/java/org/rocksdb/OptionsTest.java index 5b84d2510..97da9cfb1 100644 --- a/java/src/test/java/org/rocksdb/OptionsTest.java +++ b/java/src/test/java/org/rocksdb/OptionsTest.java @@ -500,6 +500,21 @@ public class OptionsTest { } } + @Test + public void optimizeFiltersForHits() { + Options opt = null; + try { + boolean aBoolean = rand.nextBoolean(); + opt = new Options(); + opt.setOptimizeFiltersForHits(aBoolean); + assertThat(opt.optimizeFiltersForHits()).isEqualTo(aBoolean); + } finally { + if (opt != null) { + opt.dispose(); + } + } + } + @Test public void createIfMissing() { Options opt = null;