Merge pull request #522 from fyrz/RocksJava-Optimize-Filters-For-Hits

[RocksJava] OptimizeFiltersForHits
This commit is contained in:
Yueh-Hsuan Chiang 2015-03-15 21:32:06 -07:00
commit ac03c4d511
6 changed files with 140 additions and 0 deletions

View file

@ -1731,6 +1731,30 @@ void Java_org_rocksdb_Options_setMinPartialMergeOperands(
static_cast<int32_t>(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<rocksdb::Options*>(
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<rocksdb::Options*>(
jhandle)->optimize_filters_for_hits =
static_cast<bool>(joptimize_filters_for_hits);
}
/*
* Method: optimizeForPointLookup
* Signature: (JJ)V
@ -2778,6 +2802,30 @@ void Java_org_rocksdb_ColumnFamilyOptions_setMinPartialMergeOperands(
static_cast<int32_t>(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<rocksdb::ColumnFamilyOptions*>(
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<rocksdb::ColumnFamilyOptions*>(
jhandle)->optimize_filters_for_hits =
static_cast<bool>(joptimize_filters_for_hits);
}
/////////////////////////////////////////////////////////////////////
// rocksdb::DBOptions

View file

@ -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_;

View file

@ -975,6 +975,38 @@ public interface ColumnFamilyOptionsInterface {
*/
int minPartialMergeOperands();
/**
* <p>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.</p>
*
* <p>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.</p>
*
* <p><strong>NOTE</strong>: 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.</p>
*
* <p>Default: false<p>
*
* @param optimizeFiltersForHits boolean value indicating if this flag is set.
* @return the reference to the current option.
*/
Object setOptimizeFiltersForHits(boolean optimizeFiltersForHits);
/**
* <p>Returns the current state of the {@code optimize_filters_for_hits}
* setting.</p>
*
* @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:
*

View file

@ -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_;

View file

@ -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;

View file

@ -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;