|
38 | 38 | import org.apache.lucene.index.IndexReader;
|
39 | 39 | import org.apache.lucene.util.Accountable;
|
40 | 40 | import org.apache.lucene.util.RamUsageEstimator;
|
| 41 | +import org.opensearch.OpenSearchParseException; |
41 | 42 | import org.opensearch.common.CheckedSupplier;
|
42 | 43 | import org.opensearch.common.cache.CacheType;
|
43 | 44 | import org.opensearch.common.cache.ICache;
|
|
52 | 53 | import org.opensearch.common.settings.Setting;
|
53 | 54 | import org.opensearch.common.settings.Setting.Property;
|
54 | 55 | import org.opensearch.common.settings.Settings;
|
| 56 | +import org.opensearch.common.unit.RatioValue; |
55 | 57 | import org.opensearch.common.unit.TimeValue;
|
56 | 58 | import org.opensearch.common.util.concurrent.ConcurrentCollections;
|
57 | 59 | import org.opensearch.core.common.bytes.BytesReference;
|
@@ -123,6 +125,17 @@ public final class IndicesRequestCache extends AbstractLifecycleComponent
|
123 | 125 | new TimeValue(0),
|
124 | 126 | Property.NodeScope
|
125 | 127 | );
|
| 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 | + ); |
126 | 139 |
|
127 | 140 | private final static long BASE_RAM_BYTES_USED = RamUsageEstimator.shallowSizeOfInstance(Key.class);
|
128 | 141 |
|
@@ -729,4 +742,26 @@ long count() {
|
729 | 742 | int numRegisteredCloseListeners() { // for testing
|
730 | 743 | return registeredClosedListeners.size();
|
731 | 744 | }
|
| 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 | + } |
732 | 767 | }
|
0 commit comments