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
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
* @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();
}
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) {
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,
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) {
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);
+ }
}
}
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) {
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,
}
}
+ @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();
}
}
+ @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();