[RocksJava] Added LevelCompactionDynamicLevelBytes to Options

Summary: Added LevelCompactionDynamicLevelBytes to Options.

Test Plan:
make clean jclean rocksdbjava jtest
mvn -f rocksjni.pom package

Reviewers: adamretter, ankgup87, yhchiang

Subscribers: dhruba

Differential Revision: https://reviews.facebook.net/D34857
This commit is contained in:
fyrz 2015-03-11 21:50:10 +01:00
parent 230e68727a
commit 12350115da
6 changed files with 200 additions and 3 deletions

View File

@ -1264,6 +1264,30 @@ void Java_org_rocksdb_Options_setMaxBytesForLevelBase(
static_cast<int64_t>(jmax_bytes_for_level_base);
}
/*
* Class: org_rocksdb_Options
* Method: levelCompactionDynamicLevelBytes
* Signature: (J)Z
*/
jboolean Java_org_rocksdb_Options_levelCompactionDynamicLevelBytes(
JNIEnv* env, jobject jobj, jlong jhandle) {
return reinterpret_cast<rocksdb::Options*>(
jhandle)->level_compaction_dynamic_level_bytes;
}
/*
* Class: org_rocksdb_Options
* Method: setLevelCompactionDynamicLevelBytes
* Signature: (JZ)V
*/
void Java_org_rocksdb_Options_setLevelCompactionDynamicLevelBytes(
JNIEnv* env, jobject jobj, jlong jhandle,
jboolean jenable_dynamic_level_bytes) {
reinterpret_cast<rocksdb::Options*>(
jhandle)->level_compaction_dynamic_level_bytes =
(jenable_dynamic_level_bytes);
}
/*
* Class: org_rocksdb_Options
* Method: maxBytesForLevelMultiplier
@ -2329,6 +2353,30 @@ void Java_org_rocksdb_ColumnFamilyOptions_setMaxBytesForLevelBase(
static_cast<int64_t>(jmax_bytes_for_level_base);
}
/*
* Class: org_rocksdb_ColumnFamilyOptions
* Method: levelCompactionDynamicLevelBytes
* Signature: (J)Z
*/
jboolean Java_org_rocksdb_ColumnFamilyOptions_levelCompactionDynamicLevelBytes(
JNIEnv* env, jobject jobj, jlong jhandle) {
return reinterpret_cast<rocksdb::ColumnFamilyOptions*>(
jhandle)->level_compaction_dynamic_level_bytes;
}
/*
* Class: org_rocksdb_ColumnFamilyOptions
* Method: setLevelCompactionDynamicLevelBytes
* Signature: (JZ)V
*/
void Java_org_rocksdb_ColumnFamilyOptions_setLevelCompactionDynamicLevelBytes(
JNIEnv* env, jobject jobj, jlong jhandle,
jboolean jenable_dynamic_level_bytes) {
reinterpret_cast<rocksdb::ColumnFamilyOptions*>(
jhandle)->level_compaction_dynamic_level_bytes =
(jenable_dynamic_level_bytes);
}
/*
* Class: org_rocksdb_ColumnFamilyOptions
* Method: maxBytesForLevelMultiplier

View File

@ -296,6 +296,19 @@ public class ColumnFamilyOptions extends RocksObject
return maxBytesForLevelBase(nativeHandle_);
}
@Override
public ColumnFamilyOptions setLevelCompactionDynamicLevelBytes(
final boolean enableLevelCompactionDynamicLevelBytes) {
setLevelCompactionDynamicLevelBytes(nativeHandle_,
enableLevelCompactionDynamicLevelBytes);
return this;
}
@Override
public boolean levelCompactionDynamicLevelBytes() {
return levelCompactionDynamicLevelBytes(nativeHandle_);
}
@Override
public ColumnFamilyOptions setMaxBytesForLevelMultiplier(
final int multiplier) {
@ -667,6 +680,10 @@ public class ColumnFamilyOptions extends RocksObject
private native void setMaxBytesForLevelBase(
long handle, long maxBytesForLevelBase);
private native long maxBytesForLevelBase(long handle);
private native void setLevelCompactionDynamicLevelBytes(
long handle, boolean enableLevelCompactionDynamicLevelBytes);
private native boolean levelCompactionDynamicLevelBytes(
long handle);
private native void setMaxBytesForLevelMultiplier(
long handle, int multiplier);
private native int maxBytesForLevelMultiplier(long handle);

View File

@ -435,11 +435,94 @@ public interface ColumnFamilyOptionsInterface {
* and total file size for level-3 will be 2GB.
* by default 'maxBytesForLevelBase' is 10MB.
*
* @return the upper-bound of the total size of leve-1 files in bytes.
* @return the upper-bound of the total size of level-1 files
* in bytes.
* @see #maxBytesForLevelMultiplier()
*/
long maxBytesForLevelBase();
/**
* <p>If {@code true}, RocksDB will pick target size of each level
* dynamically. We will pick a base level b &gt;= 1. L0 will be
* directly merged into level b, instead of always into level 1.
* Level 1 to b-1 need to be empty. We try to pick b and its target
* size so that</p>
*
* <ol>
* <li>target size is in the range of
* (max_bytes_for_level_base / max_bytes_for_level_multiplier,
* max_bytes_for_level_base]</li>
* <li>target size of the last level (level num_levels-1) equals to extra size
* of the level.</li>
* </ol>
*
* <p>At the same time max_bytes_for_level_multiplier and
* max_bytes_for_level_multiplier_additional are still satisfied.</p>
*
* <p>With this option on, from an empty DB, we make last level the base
* level, which means merging L0 data into the last level, until it exceeds
* max_bytes_for_level_base. And then we make the second last level to be
* base level, to start to merge L0 data to second last level, with its
* target size to be {@code 1/max_bytes_for_level_multiplier} of the last
* levels extra size. After the data accumulates more so that we need to
* move the base level to the third last one, and so on.</p>
*
* <h2>Example</h2>
* <p>For example, assume {@code max_bytes_for_level_multiplier=10},
* {@code num_levels=6}, and {@code max_bytes_for_level_base=10MB}.</p>
*
* <p>Target sizes of level 1 to 5 starts with:</p>
* {@code [- - - - 10MB]}
* <p>with base level is level. Target sizes of level 1 to 4 are not applicable
* because they will not be used.
* Until the size of Level 5 grows to more than 10MB, say 11MB, we make
* base target to level 4 and now the targets looks like:</p>
* {@code [- - - 1.1MB 11MB]}
* <p>While data are accumulated, size targets are tuned based on actual data
* of level 5. When level 5 has 50MB of data, the target is like:</p>
* {@code [- - - 5MB 50MB]}
* <p>Until level 5's actual size is more than 100MB, say 101MB. Now if we
* keep level 4 to be the base level, its target size needs to be 10.1MB,
* which doesn't satisfy the target size range. So now we make level 3
* the target size and the target sizes of the levels look like:</p>
* {@code [- - 1.01MB 10.1MB 101MB]}
* <p>In the same way, while level 5 further grows, all levels' targets grow,
* like</p>
* {@code [- - 5MB 50MB 500MB]}
* <p>Until level 5 exceeds 1000MB and becomes 1001MB, we make level 2 the
* base level and make levels' target sizes like this:</p>
* {@code [- 1.001MB 10.01MB 100.1MB 1001MB]}
* <p>and go on...</p>
*
* <p>By doing it, we give {@code max_bytes_for_level_multiplier} a priority
* against {@code max_bytes_for_level_base}, for a more predictable LSM tree
* shape. It is useful to limit worse case space amplification.</p>
*
* <p>{@code max_bytes_for_level_multiplier_additional} is ignored with
* this flag on.</p>
*
* <p>Turning this feature on or off for an existing DB can cause unexpected
* LSM tree structure so it's not recommended.</p>
*
* <p><strong>Caution</strong>: this option is experimental</p>
*
* <p>Default: false</p>
*/
Object setLevelCompactionDynamicLevelBytes(
boolean enableLevelCompactionDynamicLevelBytes);
/**
* <p>Return if {@code LevelCompactionDynamicLevelBytes} is enabled.
* </p>
*
* <p>For further information see
* {@link #setLevelCompactionDynamicLevelBytes(boolean)}</p>
*
* @return boolean value indicating if
* {@code levelCompactionDynamicLevelBytes} is enabled.
*/
boolean levelCompactionDynamicLevelBytes();
/**
* The ratio between the total size of level-(L+1) files and the total
* size of level-L files for all L.

View File

@ -790,17 +790,30 @@ public class Options extends RocksObject
return this;
}
@Override
public Options setMaxBytesForLevelBase(final long maxBytesForLevelBase) {
setMaxBytesForLevelBase(nativeHandle_, maxBytesForLevelBase);
return this;
}
@Override
public long maxBytesForLevelBase() {
return maxBytesForLevelBase(nativeHandle_);
}
@Override
public Options setMaxBytesForLevelBase(final long maxBytesForLevelBase) {
setMaxBytesForLevelBase(nativeHandle_, maxBytesForLevelBase);
public Options setLevelCompactionDynamicLevelBytes(
final boolean enableLevelCompactionDynamicLevelBytes) {
setLevelCompactionDynamicLevelBytes(nativeHandle_,
enableLevelCompactionDynamicLevelBytes);
return this;
}
@Override
public boolean levelCompactionDynamicLevelBytes() {
return levelCompactionDynamicLevelBytes(nativeHandle_);
}
@Override
public int maxBytesForLevelMultiplier() {
return maxBytesForLevelMultiplier(nativeHandle_);
@ -1223,6 +1236,10 @@ public class Options extends RocksObject
private native void setMaxBytesForLevelBase(
long handle, long maxBytesForLevelBase);
private native long maxBytesForLevelBase(long handle);
private native void setLevelCompactionDynamicLevelBytes(
long handle, boolean enableLevelCompactionDynamicLevelBytes);
private native boolean levelCompactionDynamicLevelBytes(
long handle);
private native void setMaxBytesForLevelMultiplier(
long handle, int multiplier);
private native int maxBytesForLevelMultiplier(long handle);

View File

@ -238,6 +238,22 @@ public class ColumnFamilyOptionsTest {
}
}
@Test
public void levelCompactionDynamicLevelBytes() {
ColumnFamilyOptions opt = null;
try {
opt = new ColumnFamilyOptions();
boolean boolValue = rand.nextBoolean();
opt.setLevelCompactionDynamicLevelBytes(boolValue);
assertThat(opt.levelCompactionDynamicLevelBytes())
.isEqualTo(boolValue);
} finally {
if (opt != null) {
opt.dispose();
}
}
}
@Test
public void maxBytesForLevelMultiplier() {
ColumnFamilyOptions opt = null;

View File

@ -200,6 +200,22 @@ public class OptionsTest {
}
}
@Test
public void levelCompactionDynamicLevelBytes() {
Options opt = null;
try {
opt = new Options();
boolean boolValue = rand.nextBoolean();
opt.setLevelCompactionDynamicLevelBytes(boolValue);
assertThat(opt.levelCompactionDynamicLevelBytes())
.isEqualTo(boolValue);
} finally {
if (opt != null) {
opt.dispose();
}
}
}
@Test
public void maxBytesForLevelMultiplier() {
Options opt = null;