Skip to content

Commit 1d955ef

Browse files
author
Peter Alfonsi
committed
Changed setting name
Signed-off-by: Peter Alfonsi <[email protected]>
1 parent f54a0cf commit 1d955ef

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

server/src/internalClusterTest/java/org/opensearch/indices/IndicesRequestCacheIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
9191
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
9292
import static org.opensearch.cluster.routing.allocation.decider.EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING;
93-
import static org.opensearch.indices.IndicesRequestCache.ALLOW_SIZE_NONZERO_SETTING;
93+
import static org.opensearch.indices.IndicesRequestCache.ENABLE_FOR_ALL_REQUESTS_SETTING;
9494
import static org.opensearch.search.SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING;
9595
import static org.opensearch.search.aggregations.AggregationBuilders.dateHistogram;
9696
import static org.opensearch.search.aggregations.AggregationBuilders.dateRange;
@@ -584,7 +584,7 @@ public void testCanCache() throws Exception {
584584

585585
// If size > 0 we should cache if this is enabled via cluster setting
586586
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
587-
updateSettingsRequest.persistentSettings(Settings.builder().put(ALLOW_SIZE_NONZERO_SETTING.getKey(), true));
587+
updateSettingsRequest.persistentSettings(Settings.builder().put(ENABLE_FOR_ALL_REQUESTS_SETTING.getKey(), true));
588588
assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet());
589589

590590
final SearchResponse r7 = client.prepareSearch(index)

server/src/main/java/org/opensearch/common/settings/ClusterSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ public void apply(Settings value, Settings current, Settings previous) {
519519
IndicesRequestCache.INDICES_CACHE_QUERY_EXPIRE,
520520
IndicesRequestCache.INDICES_REQUEST_CACHE_CLEANUP_INTERVAL_SETTING,
521521
IndicesRequestCache.INDICES_REQUEST_CACHE_STALENESS_THRESHOLD_SETTING,
522-
IndicesRequestCache.ALLOW_SIZE_NONZERO_SETTING,
522+
IndicesRequestCache.ENABLE_FOR_ALL_REQUESTS_SETTING,
523523
HunspellService.HUNSPELL_LAZY_LOAD,
524524
HunspellService.HUNSPELL_IGNORE_CASE,
525525
HunspellService.HUNSPELL_DICTIONARY_OPTIONS,

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,12 @@ public final class IndicesRequestCache implements RemovalListener<ICacheKey<Indi
148148
);
149149

150150
/**
151-
* If enabled, allows caching size > 0 queries.
151+
* If enabled, allows caching all cacheable queries. For now, this means also allowing size > 0 queries.
152+
* If enabled, fundamentally non-cacheable queries like DFS queries, queries using the `now` keyword, and
153+
* scroll requests are still not cached.
152154
*/
153-
public static final Setting<Boolean> ALLOW_SIZE_NONZERO_SETTING = Setting.boolSetting(
154-
"indices.requests.cache.allow_size_nonzero",
155+
public static final Setting<Boolean> ENABLE_FOR_ALL_REQUESTS_SETTING = Setting.boolSetting(
156+
"indices.requests.cache.enable_for_all_requests",
155157
false,
156158
Property.NodeScope,
157159
Property.Dynamic

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
import static org.opensearch.index.IndexService.IndexCreationContext.CREATE_INDEX;
206206
import static org.opensearch.index.IndexService.IndexCreationContext.METADATA_VERIFICATION;
207207
import static org.opensearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder;
208-
import static org.opensearch.indices.IndicesRequestCache.ALLOW_SIZE_NONZERO_SETTING;
208+
import static org.opensearch.indices.IndicesRequestCache.ENABLE_FOR_ALL_REQUESTS_SETTING;
209209
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.isRemoteDataAttributePresent;
210210
import static org.opensearch.search.SearchService.ALLOW_EXPENSIVE_QUERIES;
211211

@@ -361,7 +361,7 @@ public class IndicesService extends AbstractLifecycleComponent
361361
private final FileCache fileCache;
362362
private final CompositeIndexSettings compositeIndexSettings;
363363
private final Consumer<IndexShard> replicator;
364-
private volatile boolean canCacheSizeNonzeroRequests;
364+
private volatile boolean cachingEnabledForAllQueries;
365365

366366
@Override
367367
protected void doStart() {
@@ -509,8 +509,9 @@ protected void closeInternal() {
509509
this.compositeIndexSettings = compositeIndexSettings;
510510
this.fileCache = fileCache;
511511
this.replicator = replicator;
512-
this.canCacheSizeNonzeroRequests = ALLOW_SIZE_NONZERO_SETTING.get(clusterService.getSettings());
513-
clusterService.getClusterSettings().addSettingsUpdateConsumer(ALLOW_SIZE_NONZERO_SETTING, this::setCanCacheSizeNonzeroRequests);
512+
this.cachingEnabledForAllQueries = ENABLE_FOR_ALL_REQUESTS_SETTING.get(clusterService.getSettings());
513+
clusterService.getClusterSettings()
514+
.addSettingsUpdateConsumer(ENABLE_FOR_ALL_REQUESTS_SETTING, this::setCachingEnabledForAllQueries);
514515
}
515516

516517
public IndicesService(
@@ -1751,7 +1752,7 @@ public boolean canCache(ShardSearchRequest request, SearchContext context) {
17511752
// if not explicitly set in the request, use the index setting, if not, use the request
17521753
if (request.requestCache() == null) {
17531754
if (settings.getValue(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING) == false
1754-
|| (context.size() > 0 && !canCacheSizeNonzeroRequests)) {
1755+
|| (context.size() > 0 && !cachingEnabledForAllQueries)) {
17551756
// If no request cache query parameter and shard request cache
17561757
// is enabled in settings don't cache for requests with size > 0
17571758
// unless this is enabled via cluster setting
@@ -2124,7 +2125,7 @@ public CompositeIndexSettings getCompositeIndexSettings() {
21242125
}
21252126

21262127
// Package-private for testing
2127-
void setCanCacheSizeNonzeroRequests(Boolean canCacheSizeNonzeroRequests) {
2128-
this.canCacheSizeNonzeroRequests = canCacheSizeNonzeroRequests;
2128+
void setCachingEnabledForAllQueries(Boolean cachingEnabledForAllQueries) {
2129+
this.cachingEnabledForAllQueries = cachingEnabledForAllQueries;
21292130
}
21302131
}

server/src/test/java/org/opensearch/indices/IndicesServiceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ public void testCanCacheSizeNonzero() {
673673
assertEquals(entry.getValue(), indicesService.canCache(request, context));
674674
}
675675
// Simulate the cluster setting update by manually calling setCanCacheSizeNonzeroRequests
676-
indicesService.setCanCacheSizeNonzeroRequests(true);
676+
indicesService.setCachingEnabledForAllQueries(true);
677677
expectedResultMap = Map.of(sizeZeroContext, true, sizeNonzeroContext, true);
678678

679679
for (Map.Entry<TestSearchContext, Boolean> entry : expectedResultMap.entrySet()) {

0 commit comments

Comments
 (0)