Add periodic_compaction_seconds option to RocksJava (#8579)

Summary:
Fixes https://github.com/facebook/rocksdb/issues/8578

Pull Request resolved: https://github.com/facebook/rocksdb/pull/8579

Reviewed By: ajkr

Differential Revision: D29895081

Pulled By: mrambacher

fbshipit-source-id: 3e4120e26a3e8252f8301d657c0aaa0b8550cddf
This commit is contained in:
Anatolii Zhmaiev 2021-07-26 17:32:42 -07:00 committed by Facebook GitHub Bot
parent 4361d6d163
commit 9ddb55a8f6
7 changed files with 154 additions and 1 deletions

View File

@ -3624,6 +3624,29 @@ jlong Java_org_rocksdb_Options_ttl(
return static_cast<jlong>(opts->ttl);
}
/*
* Class: org_rocksdb_Options
* Method: setPeriodicCompactionSeconds
* Signature: (JJ)V
*/
void Java_org_rocksdb_Options_setPeriodicCompactionSeconds(
JNIEnv*, jobject, jlong jhandle, jlong jperiodicCompactionSeconds) {
auto* opts = reinterpret_cast<ROCKSDB_NAMESPACE::Options*>(jhandle);
opts->periodic_compaction_seconds =
static_cast<uint64_t>(jperiodicCompactionSeconds);
}
/*
* Class: org_rocksdb_Options
* Method: periodicCompactionSeconds
* Signature: (J)J
*/
jlong Java_org_rocksdb_Options_periodicCompactionSeconds(JNIEnv*, jobject,
jlong jhandle) {
auto* opts = reinterpret_cast<ROCKSDB_NAMESPACE::Options*>(jhandle);
return static_cast<jlong>(opts->periodic_compaction_seconds);
}
/*
* Class: org_rocksdb_Options
* Method: setCompactionOptionsUniversal
@ -5148,6 +5171,32 @@ JNIEXPORT jlong JNICALL Java_org_rocksdb_ColumnFamilyOptions_ttl(
return static_cast<jlong>(cf_opts->ttl);
}
/*
* Class: org_rocksdb_ColumnFamilyOptions
* Method: setPeriodicCompactionSeconds
* Signature: (JJ)V
*/
void Java_org_rocksdb_ColumnFamilyOptions_setPeriodicCompactionSeconds(
JNIEnv*, jobject, jlong jhandle, jlong jperiodicCompactionSeconds) {
auto* cf_opts =
reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyOptions*>(jhandle);
cf_opts->periodic_compaction_seconds =
static_cast<uint64_t>(jperiodicCompactionSeconds);
}
/*
* Class: org_rocksdb_ColumnFamilyOptions
* Method: periodicCompactionSeconds
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL
Java_org_rocksdb_ColumnFamilyOptions_periodicCompactionSeconds(JNIEnv*, jobject,
jlong jhandle) {
auto* cf_opts =
reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyOptions*>(jhandle);
return static_cast<jlong>(cf_opts->periodic_compaction_seconds);
}
/*
* Class: org_rocksdb_ColumnFamilyOptions
* Method: setCompactionOptionsUniversal

View File

@ -461,4 +461,52 @@ public interface AdvancedMutableColumnFamilyOptionsInterface<
* @return the time-to-live.
*/
long ttl();
/**
* Files older than this value will be picked up for compaction, and
* re-written to the same level as they were before.
* One main use of the feature is to make sure a file goes through compaction
* filters periodically. Users can also use the feature to clear up SST
* files using old format.
*
* A file's age is computed by looking at file_creation_time or creation_time
* table properties in order, if they have valid non-zero values; if not, the
* age is based on the file's last modified time (given by the underlying
* Env).
*
* Supported in Level and FIFO compaction.
* In FIFO compaction, this option has the same meaning as TTL and whichever
* stricter will be used.
* Pre-req: max_open_file == -1.
* unit: seconds. Ex: 7 days = 7 * 24 * 60 * 60
*
* Values:
* 0: Turn off Periodic compactions.
* UINT64_MAX - 1 (i.e 0xfffffffffffffffe): Let RocksDB control this feature
* as needed. For now, RocksDB will change this value to 30 days
* (i.e 30 * 24 * 60 * 60) so that every file goes through the compaction
* process at least once every 30 days if not compacted sooner.
* In FIFO compaction, since the option has the same meaning as ttl,
* when this value is left default, and ttl is left to 0, 30 days will be
* used. Otherwise, min(ttl, periodic_compaction_seconds) will be used.
*
* Default: 0xfffffffffffffffe (allow RocksDB to auto-tune)
*
* Dynamically changeable through
* {@link RocksDB#setOptions(ColumnFamilyHandle, MutableColumnFamilyOptions)}.
*
* @param periodicCompactionSeconds the periodic compaction in seconds.
*
* @return the reference to the current options.
*/
T setPeriodicCompactionSeconds(final long periodicCompactionSeconds);
/**
* Get the periodicCompactionSeconds.
*
* See {@link #setPeriodicCompactionSeconds(long)}.
*
* @return the periodic compaction in seconds.
*/
long periodicCompactionSeconds();
}

View File

@ -857,6 +857,17 @@ public class ColumnFamilyOptions extends RocksObject
return ttl(nativeHandle_);
}
@Override
public ColumnFamilyOptions setPeriodicCompactionSeconds(final long periodicCompactionSeconds) {
setPeriodicCompactionSeconds(nativeHandle_, periodicCompactionSeconds);
return this;
}
@Override
public long periodicCompactionSeconds() {
return periodicCompactionSeconds(nativeHandle_);
}
@Override
public ColumnFamilyOptions setCompactionOptionsUniversal(
final CompactionOptionsUniversal compactionOptionsUniversal) {
@ -1083,6 +1094,9 @@ public class ColumnFamilyOptions extends RocksObject
private native boolean reportBgIoStats(final long handle);
private native void setTtl(final long handle, final long ttl);
private native long ttl(final long handle);
private native void setPeriodicCompactionSeconds(
final long handle, final long periodicCompactionSeconds);
private native long periodicCompactionSeconds(final long handle);
private native void setCompactionOptionsUniversal(final long handle,
final long compactionOptionsUniversalHandle);
private native void setCompactionOptionsFIFO(final long handle,

View File

@ -117,7 +117,8 @@ public class MutableColumnFamilyOptions
max_bytes_for_level_base(ValueType.LONG),
max_bytes_for_level_multiplier(ValueType.INT),
max_bytes_for_level_multiplier_additional(ValueType.INT_ARRAY),
ttl(ValueType.LONG);
ttl(ValueType.LONG),
periodic_compaction_seconds(ValueType.LONG);
private final ValueType valueType;
CompactionOption(final ValueType valueType) {
@ -465,5 +466,16 @@ public class MutableColumnFamilyOptions
public long ttl() {
return getLong(CompactionOption.ttl);
}
@Override
public MutableColumnFamilyOptionsBuilder setPeriodicCompactionSeconds(
final long periodicCompactionSeconds) {
return setLong(CompactionOption.periodic_compaction_seconds, periodicCompactionSeconds);
}
@Override
public long periodicCompactionSeconds() {
return getLong(CompactionOption.periodic_compaction_seconds);
}
}
}

View File

@ -1848,6 +1848,17 @@ public class Options extends RocksObject
return ttl(nativeHandle_);
}
@Override
public Options setPeriodicCompactionSeconds(final long periodicCompactionSeconds) {
setPeriodicCompactionSeconds(nativeHandle_, periodicCompactionSeconds);
return this;
}
@Override
public long periodicCompactionSeconds() {
return periodicCompactionSeconds(nativeHandle_);
}
@Override
public Options setCompactionOptionsUniversal(
final CompactionOptionsUniversal compactionOptionsUniversal) {
@ -2383,6 +2394,9 @@ public class Options extends RocksObject
private native boolean reportBgIoStats(final long handle);
private native void setTtl(final long handle, final long ttl);
private native long ttl(final long handle);
private native void setPeriodicCompactionSeconds(
final long handle, final long periodicCompactionSeconds);
private native long periodicCompactionSeconds(final long handle);
private native void setCompactionOptionsUniversal(final long handle,
final long compactionOptionsUniversalHandle);
private native void setCompactionOptionsFIFO(final long handle,

View File

@ -589,6 +589,14 @@ public class ColumnFamilyOptionsTest {
}
}
@Test
public void periodicCompactionSeconds() {
try (final ColumnFamilyOptions options = new ColumnFamilyOptions()) {
options.setPeriodicCompactionSeconds(1000 * 60);
assertThat(options.periodicCompactionSeconds()).isEqualTo(1000 * 60);
}
}
@Test
public void compactionOptionsUniversal() {
try (final ColumnFamilyOptions opt = new ColumnFamilyOptions();

View File

@ -1256,6 +1256,14 @@ public class OptionsTest {
}
}
@Test
public void periodicCompactionSeconds() {
try (final Options options = new Options()) {
options.setPeriodicCompactionSeconds(1000 * 60);
assertThat(options.periodicCompactionSeconds()).isEqualTo(1000 * 60);
}
}
@Test
public void compactionOptionsUniversal() {
try (final Options options = new Options();