Skip to content

Commit 215dc28

Browse files
add settings and validators
Signed-off-by: Kiran Prakash <awskiran@amazon.com>
1 parent c731564 commit 215dc28

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

server/src/main/java/org/opensearch/indices/IndicesRequestCache.java

+35
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.lucene.index.IndexReader;
3939
import org.apache.lucene.util.Accountable;
4040
import org.apache.lucene.util.RamUsageEstimator;
41+
import org.opensearch.OpenSearchParseException;
4142
import org.opensearch.common.CheckedSupplier;
4243
import org.opensearch.common.cache.CacheType;
4344
import org.opensearch.common.cache.ICache;
@@ -52,6 +53,7 @@
5253
import org.opensearch.common.settings.Setting;
5354
import org.opensearch.common.settings.Setting.Property;
5455
import org.opensearch.common.settings.Settings;
56+
import org.opensearch.common.unit.RatioValue;
5557
import org.opensearch.common.unit.TimeValue;
5658
import org.opensearch.common.util.concurrent.ConcurrentCollections;
5759
import org.opensearch.core.common.bytes.BytesReference;
@@ -123,6 +125,17 @@ public final class IndicesRequestCache extends AbstractLifecycleComponent
123125
new TimeValue(0),
124126
Property.NodeScope
125127
);
128+
public static final Setting<TimeValue> INDICES_REQUEST_CACHE_CLEAN_INTERVAL_SETTING = Setting.positiveTimeSetting(
129+
"indices.requests.cache.cleanup.interval",
130+
TimeValue.timeValueMinutes(1),
131+
Property.NodeScope
132+
);
133+
public static final Setting<String> INDICES_REQUEST_CACHE_STALENESS_THRESHOLD_SETTING = new Setting<>(
134+
"indices.requests.cache.cleanup.staleness_threshold",
135+
"0%",
136+
IndicesRequestCache::validateStalenessSetting,
137+
Property.NodeScope
138+
);
126139

127140
private final static long BASE_RAM_BYTES_USED = RamUsageEstimator.shallowSizeOfInstance(Key.class);
128141

@@ -729,4 +742,26 @@ long count() {
729742
int numRegisteredCloseListeners() { // for testing
730743
return registeredClosedListeners.size();
731744
}
745+
746+
/**
747+
* Validates the staleness setting for the cache cleanup threshold.
748+
*
749+
* <p>This method checks if the provided staleness threshold is a valid percentage or a valid double value.
750+
* If the staleness threshold is not valid, it throws an OpenSearchParseException.
751+
*
752+
* @param staleThreshold The staleness threshold to validate.
753+
* @return The validated staleness threshold.
754+
* @throws OpenSearchParseException If the staleness threshold is not a valid percentage or double value.
755+
*
756+
* <p>package private for testing
757+
*/
758+
static String validateStalenessSetting(String staleThreshold) {
759+
try {
760+
RatioValue.parseRatioValue(staleThreshold);
761+
} catch (OpenSearchParseException e) {
762+
e.addSuppressed(e);
763+
throw e;
764+
}
765+
return staleThreshold;
766+
}
732767
}

0 commit comments

Comments
 (0)