Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add [set]DailyOffpeakTimeUTC option to Java API #13148

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions java/rocksjni/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2302,6 +2302,35 @@ jlong Java_org_rocksdb_Options_bgerrorResumeRetryInterval(JNIEnv*, jclass,
return static_cast<jlong>(opt->bgerror_resume_retry_interval);
}

/*
* Class: org_rocksdb_Options
* Method: setDailyOffpeakTimeUTC
* Signature: (JLjava/lang/String;)V
*/
void Java_org_rocksdb_Options_setDailyOffpeakTimeUTC(JNIEnv* env, jclass,
jlong jhandle,
jstring jtimeutc) {
auto* opt = reinterpret_cast<ROCKSDB_NAMESPACE::Options*>(jhandle);
jboolean has_exception;
auto timeutc =
ROCKSDB_NAMESPACE::JniUtil::copyStdString(env, jtimeutc, &has_exception);
if (has_exception == JNI_TRUE) {
return;
}
opt->daily_offpeak_time_utc = timeutc;
}

/*
* Class: org_rocksdb_Options
* Method: dailyOffpeakTimeUTC
* Signature: (J)Ljava/lang/String;
*/
jstring Java_org_rocksdb_Options_dailyOffpeakTimeUTC(JNIEnv* env, jclass,
jlong jhandle) {
auto* opt = reinterpret_cast<ROCKSDB_NAMESPACE::Options*>(jhandle);
return env->NewStringUTF(opt->daily_offpeak_time_utc.c_str());
}

/*
* Class: org_rocksdb_Options
* Method: setAvoidFlushDuringShutdown
Expand Down Expand Up @@ -7878,6 +7907,35 @@ jlong Java_org_rocksdb_DBOptions_bgerrorResumeRetryInterval(JNIEnv*, jclass,
return static_cast<jlong>(opt->bgerror_resume_retry_interval);
}

/*
* Class: org_rocksdb_DBOptions
* Method: setDailyOffpeakTimeUTC
* Signature: (JLjava/lang/String;)V
*/
void Java_org_rocksdb_DBOptions_setDailyOffpeakTimeUTC(JNIEnv* env, jclass,
jlong jhandle,
jstring jtimeutc) {
auto* opt = reinterpret_cast<ROCKSDB_NAMESPACE::DBOptions*>(jhandle);
const jsize jtimesz = env->GetStringUTFLength(jtimeutc);
const char* timeutc = env->GetStringUTFChars(jtimeutc, nullptr);
if (env->ExceptionCheck()) {
return;
}
opt->daily_offpeak_time_utc = std::string(timeutc, jtimesz);
env->ReleaseStringUTFChars(jtimeutc, timeutc);
}

/*
* Class: org_rocksdb_DBOptions
* Method: dailyOffpeakTimeUTC
* Signature: (J)Ljava/lang/String;
*/
jstring Java_org_rocksdb_DBOptions_dailyOffpeakTimeUTC(JNIEnv* env, jclass,
jlong jhandle) {
auto* opt = reinterpret_cast<ROCKSDB_NAMESPACE::DBOptions*>(jhandle);
return env->NewStringUTF(opt->daily_offpeak_time_utc.c_str());
}

//////////////////////////////////////////////////////////////////////////////
// ROCKSDB_NAMESPACE::WriteOptions

Expand Down
21 changes: 20 additions & 1 deletion java/src/main/java/org/rocksdb/AbstractMutableOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,22 @@ protected int[] getIntArray(final K key)
return value.asIntArray();
}

protected U setString(final K key, final String value) {
if (key.getValueType() != MutableOptionKey.ValueType.STRING) {
throw new IllegalArgumentException(key + " does not accept a string value");
}
options.put(key, MutableOptionValue.fromString(value));
return self();
}

protected String getString(final K key) {
final MutableOptionValue<?> value = options.get(key);
if (value == null) {
throw new NoSuchElementException(key.name() + HAS_NOT_BEEN_SET);
}
return value.asString();
}

protected <N extends Enum<N>> U setEnum(
final K key, final N value) {
if(key.getValueType() != MutableOptionKey.ValueType.ENUM) {
Expand Down Expand Up @@ -316,7 +332,8 @@ private U fromOptionString(final OptionString.Entry option, final boolean ignore
}

// Check that simple values are the single item in the array
if (key.getValueType() != MutableOptionKey.ValueType.INT_ARRAY) {
if (key.getValueType() != MutableOptionKey.ValueType.INT_ARRAY
&& key.getValueType() != MutableOptionKey.ValueType.STRING) {
{
if (option.value.list.size() != 1) {
throw new IllegalArgumentException(
Expand Down Expand Up @@ -361,6 +378,8 @@ private U fromOptionString(final OptionString.Entry option, final boolean ignore
} else {
throw new IllegalArgumentException("Unknown enum type: " + key.name());
}
case STRING:
return setString(key, option.value.toString());

default:
throw new IllegalStateException(key + " has unknown value type: " + key.getValueType());
Expand Down
16 changes: 16 additions & 0 deletions java/src/main/java/org/rocksdb/DBOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,19 @@ public long compactionReadaheadSize() {
return compactionReadaheadSize(nativeHandle_);
}

@Override
public DBOptions setDailyOffpeakTimeUTC(String offpeakTimeUTC) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good design. Somebody can say that java date/time data structures can be better, but conversion will probably make more problems. 👍

Copy link
Contributor Author

@alanpaxton alanpaxton Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought hard about that. If I would use the the java date/time, I need to parse the HH:mm-HH:mm format. Better to just present the same string as RockSDB does.

assert (isOwningHandle());
setDailyOffpeakTimeUTC(nativeHandle_, offpeakTimeUTC);
return this;
}

@Override
public String dailyOffpeakTimeUTC() {
assert (isOwningHandle());
return dailyOffpeakTimeUTC(nativeHandle_);
}

@Override
public DBOptions setRandomAccessMaxBufferSize(final long randomAccessMaxBufferSize) {
assert(isOwningHandle());
Expand Down Expand Up @@ -1348,6 +1361,9 @@ private static native void setWriteBufferManager(
private static native void setCompactionReadaheadSize(
final long handle, final long compactionReadaheadSize);
private static native long compactionReadaheadSize(final long handle);
private static native void setDailyOffpeakTimeUTC(
final long handle, final String dailyOffpeakTimeUTC);
private static native String dailyOffpeakTimeUTC(final long handle);
private static native void setRandomAccessMaxBufferSize(
final long handle, final long randomAccessMaxBufferSize);
private static native long randomAccessMaxBufferSize(final long handle);
Expand Down
43 changes: 43 additions & 0 deletions java/src/main/java/org/rocksdb/DBOptionsInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -1744,4 +1744,47 @@ T setEnableWriteThreadAdaptiveYield(
* @return the instance of the current object.
*/
long bgerrorResumeRetryInterval();

/**
* Implementing off-peak duration awareness in RocksDB. In this context,
* "off-peak time" signifies periods characterized by significantly less read
* and write activity compared to other times. By leveraging this knowledge,
* we can prevent low-priority tasks, such as TTL-based compactions, from
* competing with read and write operations during peak hours. Essentially, we
* preprocess these tasks during the preceding off-peak period, just before
* the next peak cycle begins. For example, if the TTL is configured for 25
* days, we may compact the files during the off-peak hours of the 24th day.
*
* Time of the day in UTC, start_time-end_time inclusive.
* Format - HH:mm-HH:mm (00:00-23:59)
* If the start time exceeds the end time, it will be considered that the time period
* spans to the next day (e.g., 23:30-04:00). To make an entire day off-peak,
* use "0:00-23:59". To make an entire day have no offpeak period, leave
* this field blank. Default: Empty string (no offpeak).
*
* @param offpeakTimeUTC String value from which to parse offpeak time range
*/
T setDailyOffpeakTimeUTC(final String offpeakTimeUTC);

/**
*
* Implementing off-peak duration awareness in RocksDB. In this context,
* "off-peak time" signifies periods characterized by significantly less read
* and write activity compared to other times. By leveraging this knowledge,
* we can prevent low-priority tasks, such as TTL-based compactions, from
* competing with read and write operations during peak hours. Essentially, we
* preprocess these tasks during the preceding off-peak period, just before
* the next peak cycle begins. For example, if the TTL is configured for 25
* days, we may compact the files during the off-peak hours of the 24th day.
*
* Time of the day in UTC, start_time-end_time inclusive.
* Format - HH:mm-HH:mm (00:00-23:59)
* If the start time exceeds the end time, it will be considered that the time period
* spans to the next day (e.g., 23:30-04:00). To make an entire day off-peak,
* use "0:00-23:59". To make an entire day have no offpeak period, leave
* this field blank. Default: Empty string (no offpeak).
*
* @return String value of current offpeak time range, "" if none is set.
*/
String dailyOffpeakTimeUTC();
}
14 changes: 13 additions & 1 deletion java/src/main/java/org/rocksdb/MutableDBOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public enum DBOption implements MutableDBOptionKey {
bytes_per_sync(ValueType.LONG),
wal_bytes_per_sync(ValueType.LONG),
strict_bytes_per_sync(ValueType.BOOLEAN),
compaction_readahead_size(ValueType.LONG);
compaction_readahead_size(ValueType.LONG),

daily_offpeak_time_utc(ValueType.STRING);

private final ValueType valueType;
DBOption(final ValueType valueType) {
Expand Down Expand Up @@ -288,5 +290,15 @@ public MutableDBOptionsBuilder setCompactionReadaheadSize(
public long compactionReadaheadSize() {
return getLong(DBOption.compaction_readahead_size);
}

@Override
public MutableDBOptionsBuilder setDailyOffpeakTimeUTC(final String offpeakTimeUTC) {
return setString(DBOption.daily_offpeak_time_utc, offpeakTimeUTC);
}

@Override
public String dailyOffpeakTimeUTC() {
return getString(DBOption.daily_offpeak_time_utc);
}
}
}
43 changes: 43 additions & 0 deletions java/src/main/java/org/rocksdb/MutableDBOptionsInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -437,4 +437,47 @@ public interface MutableDBOptionsInterface<T extends MutableDBOptionsInterface<T
* @return The compaction read-ahead size
*/
long compactionReadaheadSize();

/**
* Implementing off-peak duration awareness in RocksDB. In this context,
* "off-peak time" signifies periods characterized by significantly less read
* and write activity compared to other times. By leveraging this knowledge,
* we can prevent low-priority tasks, such as TTL-based compactions, from
* competing with read and write operations during peak hours. Essentially, we
* preprocess these tasks during the preceding off-peak period, just before
* the next peak cycle begins. For example, if the TTL is configured for 25
* days, we may compact the files during the off-peak hours of the 24th day.
*
* Time of the day in UTC, start_time-end_time inclusive.
* Format - HH:mm-HH:mm (00:00-23:59)
* If the start time exceeds the end time, it will be considered that the time period
* spans to the next day (e.g., 23:30-04:00). To make an entire day off-peak,
* use "0:00-23:59". To make an entire day have no offpeak period, leave
* this field blank. Default: Empty string (no offpeak).
*
* @param offpeakTimeUTC String value from which to parse offpeak time range
*/
T setDailyOffpeakTimeUTC(final String offpeakTimeUTC);

/**
*
* Implementing off-peak duration awareness in RocksDB. In this context,
* "off-peak time" signifies periods characterized by significantly less read
* and write activity compared to other times. By leveraging this knowledge,
* we can prevent low-priority tasks, such as TTL-based compactions, from
* competing with read and write operations during peak hours. Essentially, we
* preprocess these tasks during the preceding off-peak period, just before
* the next peak cycle begins. For example, if the TTL is configured for 25
* days, we may compact the files during the off-peak hours of the 24th day.
*
* Time of the day in UTC, start_time-end_time inclusive.
* Format - HH:mm-HH:mm (00:00-23:59)
* If the start time exceeds the end time, it will be considered that the time period
* spans to the next day (e.g., 23:30-04:00). To make an entire day off-peak,
* use "0:00-23:59". To make an entire day have no offpeak period, leave
* this field blank. Default: Empty string (no offpeak).
*
* @return String value of current offpeak time range, "" if none is set.
*/
String dailyOffpeakTimeUTC();
}
4 changes: 3 additions & 1 deletion java/src/main/java/org/rocksdb/MutableOptionKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ enum ValueType {
INT,
BOOLEAN,
INT_ARRAY,
ENUM
ENUM,
STRING,

}

String name();
Expand Down
5 changes: 5 additions & 0 deletions java/src/main/java/org/rocksdb/OptionString.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class OptionString {
private static final char wrappedValueEnd = '}';
private static final char arrayValueSeparator = ':';

private static final char escapeChar = '\\';

static class Value {
final List<String> list;
final List<Entry> complex;
Expand Down Expand Up @@ -177,6 +179,9 @@ private List<String> parseList() {
final List<String> list = new ArrayList<>(1);
while (true) {
list.add(parseSimpleValue());
if (isChar(escapeChar)) {
next();
}
if (!isChar(arrayValueSeparator))
break;

Expand Down
15 changes: 15 additions & 0 deletions java/src/main/java/org/rocksdb/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,19 @@ public long compactionReadaheadSize() {
return compactionReadaheadSize(nativeHandle_);
}

@Override
public Options setDailyOffpeakTimeUTC(String offpeakTimeUTC) {
assert (isOwningHandle());
setDailyOffpeakTimeUTC(nativeHandle_, offpeakTimeUTC);
return this;
}

@Override
public String dailyOffpeakTimeUTC() {
assert (isOwningHandle());
return dailyOffpeakTimeUTC(nativeHandle_);
}

@Override
public Options setRandomAccessMaxBufferSize(final long randomAccessMaxBufferSize) {
assert(isOwningHandle());
Expand Down Expand Up @@ -2256,6 +2269,8 @@ private static native void setWriteBufferManager(
private static native void setCompactionReadaheadSize(
final long handle, final long compactionReadaheadSize);
private static native long compactionReadaheadSize(final long handle);
private static native void setDailyOffpeakTimeUTC(final long handle, final String offpeakTimeUTC);
private static native String dailyOffpeakTimeUTC(final long handle);
private static native void setRandomAccessMaxBufferSize(
final long handle, final long randomAccessMaxBufferSize);
private static native long randomAccessMaxBufferSize(final long handle);
Expand Down
Loading
Loading