Skip to content

Commit

Permalink
Changed setting name
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Alfonsi <[email protected]>
  • Loading branch information
Peter Alfonsi committed Oct 28, 2024
1 parent f54a0cf commit 1d955ef
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
import static org.opensearch.cluster.routing.allocation.decider.EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING;
import static org.opensearch.indices.IndicesRequestCache.ALLOW_SIZE_NONZERO_SETTING;
import static org.opensearch.indices.IndicesRequestCache.ENABLE_FOR_ALL_REQUESTS_SETTING;
import static org.opensearch.search.SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING;
import static org.opensearch.search.aggregations.AggregationBuilders.dateHistogram;
import static org.opensearch.search.aggregations.AggregationBuilders.dateRange;
Expand Down Expand Up @@ -584,7 +584,7 @@ public void testCanCache() throws Exception {

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

final SearchResponse r7 = client.prepareSearch(index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public void apply(Settings value, Settings current, Settings previous) {
IndicesRequestCache.INDICES_CACHE_QUERY_EXPIRE,
IndicesRequestCache.INDICES_REQUEST_CACHE_CLEANUP_INTERVAL_SETTING,
IndicesRequestCache.INDICES_REQUEST_CACHE_STALENESS_THRESHOLD_SETTING,
IndicesRequestCache.ALLOW_SIZE_NONZERO_SETTING,
IndicesRequestCache.ENABLE_FOR_ALL_REQUESTS_SETTING,
HunspellService.HUNSPELL_LAZY_LOAD,
HunspellService.HUNSPELL_IGNORE_CASE,
HunspellService.HUNSPELL_DICTIONARY_OPTIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ public final class IndicesRequestCache implements RemovalListener<ICacheKey<Indi
);

/**
* If enabled, allows caching size > 0 queries.
* If enabled, allows caching all cacheable queries. For now, this means also allowing size > 0 queries.
* If enabled, fundamentally non-cacheable queries like DFS queries, queries using the `now` keyword, and
* scroll requests are still not cached.
*/
public static final Setting<Boolean> ALLOW_SIZE_NONZERO_SETTING = Setting.boolSetting(
"indices.requests.cache.allow_size_nonzero",
public static final Setting<Boolean> ENABLE_FOR_ALL_REQUESTS_SETTING = Setting.boolSetting(
"indices.requests.cache.enable_for_all_requests",
false,
Property.NodeScope,
Property.Dynamic
Expand Down
15 changes: 8 additions & 7 deletions server/src/main/java/org/opensearch/indices/IndicesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
import static org.opensearch.index.IndexService.IndexCreationContext.CREATE_INDEX;
import static org.opensearch.index.IndexService.IndexCreationContext.METADATA_VERIFICATION;
import static org.opensearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder;
import static org.opensearch.indices.IndicesRequestCache.ALLOW_SIZE_NONZERO_SETTING;
import static org.opensearch.indices.IndicesRequestCache.ENABLE_FOR_ALL_REQUESTS_SETTING;
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.isRemoteDataAttributePresent;
import static org.opensearch.search.SearchService.ALLOW_EXPENSIVE_QUERIES;

Expand Down Expand Up @@ -361,7 +361,7 @@ public class IndicesService extends AbstractLifecycleComponent
private final FileCache fileCache;
private final CompositeIndexSettings compositeIndexSettings;
private final Consumer<IndexShard> replicator;
private volatile boolean canCacheSizeNonzeroRequests;
private volatile boolean cachingEnabledForAllQueries;

@Override
protected void doStart() {
Expand Down Expand Up @@ -509,8 +509,9 @@ protected void closeInternal() {
this.compositeIndexSettings = compositeIndexSettings;
this.fileCache = fileCache;
this.replicator = replicator;
this.canCacheSizeNonzeroRequests = ALLOW_SIZE_NONZERO_SETTING.get(clusterService.getSettings());
clusterService.getClusterSettings().addSettingsUpdateConsumer(ALLOW_SIZE_NONZERO_SETTING, this::setCanCacheSizeNonzeroRequests);
this.cachingEnabledForAllQueries = ENABLE_FOR_ALL_REQUESTS_SETTING.get(clusterService.getSettings());
clusterService.getClusterSettings()
.addSettingsUpdateConsumer(ENABLE_FOR_ALL_REQUESTS_SETTING, this::setCachingEnabledForAllQueries);
}

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

// Package-private for testing
void setCanCacheSizeNonzeroRequests(Boolean canCacheSizeNonzeroRequests) {
this.canCacheSizeNonzeroRequests = canCacheSizeNonzeroRequests;
void setCachingEnabledForAllQueries(Boolean cachingEnabledForAllQueries) {
this.cachingEnabledForAllQueries = cachingEnabledForAllQueries;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ public void testCanCacheSizeNonzero() {
assertEquals(entry.getValue(), indicesService.canCache(request, context));
}
// Simulate the cluster setting update by manually calling setCanCacheSizeNonzeroRequests
indicesService.setCanCacheSizeNonzeroRequests(true);
indicesService.setCachingEnabledForAllQueries(true);
expectedResultMap = Map.of(sizeZeroContext, true, sizeNonzeroContext, true);

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

0 comments on commit 1d955ef

Please sign in to comment.