Skip to content

Commit 65ce504

Browse files
committed
Remove QueryCachingPolicy#ALWAYS_CACHE (#31451)
The QueryCachingPolicy#ALWAYS_CACHE was deprecated in Lucene-7.4 and will be removed in Lucene-8.0. This change replaces it with QueryCachingPolicy. This also makes INDEX_QUERY_CACHE_EVERYTHING_SETTING visible in testing only.
1 parent 0883ebe commit 65ce504

File tree

7 files changed

+38
-14
lines changed

7 files changed

+38
-14
lines changed

server/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java

-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
149149
IndexModule.INDEX_STORE_TYPE_SETTING,
150150
IndexModule.INDEX_STORE_PRE_LOAD_SETTING,
151151
IndexModule.INDEX_QUERY_CACHE_ENABLED_SETTING,
152-
IndexModule.INDEX_QUERY_CACHE_EVERYTHING_SETTING,
153152
FsDirectoryService.INDEX_LOCK_FACTOR_SETTING,
154153
EngineConfig.INDEX_CODEC_SETTING,
155154
EngineConfig.INDEX_OPTIMIZE_AUTO_GENERATED_IDS,

server/src/main/java/org/elasticsearch/index/shard/IndexShard.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.lucene.index.SegmentInfos;
3131
import org.apache.lucene.index.SegmentReader;
3232
import org.apache.lucene.index.Term;
33+
import org.apache.lucene.search.Query;
3334
import org.apache.lucene.search.QueryCachingPolicy;
3435
import org.apache.lucene.search.ReferenceManager;
3536
import org.apache.lucene.search.Sort;
@@ -298,7 +299,16 @@ public IndexShard(
298299
// the query cache is a node-level thing, however we want the most popular filters
299300
// to be computed on a per-shard basis
300301
if (IndexModule.INDEX_QUERY_CACHE_EVERYTHING_SETTING.get(settings)) {
301-
cachingPolicy = QueryCachingPolicy.ALWAYS_CACHE;
302+
cachingPolicy = new QueryCachingPolicy() {
303+
@Override
304+
public void onUse(Query query) {
305+
306+
}
307+
@Override
308+
public boolean shouldCache(Query query) {
309+
return true;
310+
}
311+
};
302312
} else {
303313
cachingPolicy = new UsageTrackingQueryCachingPolicy();
304314
}

server/src/test/java/org/elasticsearch/indices/IndicesQueryCacheTests.java

+18-5
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ public boolean isCacheable(LeafReaderContext ctx) {
8989

9090
}
9191

92+
private static QueryCachingPolicy alwaysCachePolicy() {
93+
return new QueryCachingPolicy() {
94+
@Override
95+
public void onUse(Query query) {
96+
97+
}
98+
@Override
99+
public boolean shouldCache(Query query) {
100+
return true;
101+
}
102+
};
103+
}
104+
92105
public void testBasics() throws IOException {
93106
Directory dir = newDirectory();
94107
IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
@@ -98,7 +111,7 @@ public void testBasics() throws IOException {
98111
ShardId shard = new ShardId("index", "_na_", 0);
99112
r = ElasticsearchDirectoryReader.wrap(r, shard);
100113
IndexSearcher s = new IndexSearcher(r);
101-
s.setQueryCachingPolicy(QueryCachingPolicy.ALWAYS_CACHE);
114+
s.setQueryCachingPolicy(alwaysCachePolicy());
102115

103116
Settings settings = Settings.builder()
104117
.put(IndicesQueryCache.INDICES_CACHE_QUERY_COUNT_SETTING.getKey(), 10)
@@ -169,7 +182,7 @@ public void testTwoShards() throws IOException {
169182
ShardId shard1 = new ShardId("index", "_na_", 0);
170183
r1 = ElasticsearchDirectoryReader.wrap(r1, shard1);
171184
IndexSearcher s1 = new IndexSearcher(r1);
172-
s1.setQueryCachingPolicy(QueryCachingPolicy.ALWAYS_CACHE);
185+
s1.setQueryCachingPolicy(alwaysCachePolicy());
173186

174187
Directory dir2 = newDirectory();
175188
IndexWriter w2 = new IndexWriter(dir2, newIndexWriterConfig());
@@ -179,7 +192,7 @@ public void testTwoShards() throws IOException {
179192
ShardId shard2 = new ShardId("index", "_na_", 1);
180193
r2 = ElasticsearchDirectoryReader.wrap(r2, shard2);
181194
IndexSearcher s2 = new IndexSearcher(r2);
182-
s2.setQueryCachingPolicy(QueryCachingPolicy.ALWAYS_CACHE);
195+
s2.setQueryCachingPolicy(alwaysCachePolicy());
183196

184197
Settings settings = Settings.builder()
185198
.put(IndicesQueryCache.INDICES_CACHE_QUERY_COUNT_SETTING.getKey(), 10)
@@ -295,7 +308,7 @@ public void testStatsOnEviction() throws IOException {
295308
ShardId shard1 = new ShardId("index", "_na_", 0);
296309
r1 = ElasticsearchDirectoryReader.wrap(r1, shard1);
297310
IndexSearcher s1 = new IndexSearcher(r1);
298-
s1.setQueryCachingPolicy(QueryCachingPolicy.ALWAYS_CACHE);
311+
s1.setQueryCachingPolicy(alwaysCachePolicy());
299312

300313
Directory dir2 = newDirectory();
301314
IndexWriter w2 = new IndexWriter(dir2, newIndexWriterConfig());
@@ -305,7 +318,7 @@ public void testStatsOnEviction() throws IOException {
305318
ShardId shard2 = new ShardId("index", "_na_", 1);
306319
r2 = ElasticsearchDirectoryReader.wrap(r2, shard2);
307320
IndexSearcher s2 = new IndexSearcher(r2);
308-
s2.setQueryCachingPolicy(QueryCachingPolicy.ALWAYS_CACHE);
321+
s2.setQueryCachingPolicy(alwaysCachePolicy());
309322

310323
Settings settings = Settings.builder()
311324
.put(IndicesQueryCache.INDICES_CACHE_QUERY_COUNT_SETTING.getKey(), 10)

server/src/test/java/org/elasticsearch/search/scriptfilter/ScriptQuerySearchIT.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
import org.elasticsearch.script.ScriptType;
3232
import org.elasticsearch.search.sort.SortOrder;
3333
import org.elasticsearch.test.ESIntegTestCase;
34+
import org.elasticsearch.test.InternalSettingsPlugin;
3435

3536
import java.io.IOException;
37+
import java.util.Arrays;
3638
import java.util.Base64;
3739
import java.util.Collection;
3840
import java.util.Collections;
@@ -52,7 +54,7 @@ public class ScriptQuerySearchIT extends ESIntegTestCase {
5254

5355
@Override
5456
protected Collection<Class<? extends Plugin>> nodePlugins() {
55-
return Collections.singleton(CustomScriptPlugin.class);
57+
return Arrays.asList(CustomScriptPlugin.class, InternalSettingsPlugin.class);
5658
}
5759

5860
public static class CustomScriptPlugin extends MockScriptPlugin {

test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java

-4
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,6 @@ public void randomIndexTemplate() throws IOException {
434434
if (randomBoolean()) {
435435
randomSettingsBuilder.put(IndexModule.INDEX_QUERY_CACHE_ENABLED_SETTING.getKey(), randomBoolean());
436436
}
437-
438-
if (randomBoolean()) {
439-
randomSettingsBuilder.put(IndexModule.INDEX_QUERY_CACHE_EVERYTHING_SETTING.getKey(), randomBoolean());
440-
}
441437
PutIndexTemplateRequestBuilder putTemplate = client().admin().indices()
442438
.preparePutTemplate("random_index_template")
443439
.setPatterns(Collections.singletonList("*"))

test/framework/src/main/java/org/elasticsearch/test/InternalSettingsPlugin.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.common.settings.Setting;
2323
import org.elasticsearch.common.settings.Setting.Property;
2424
import org.elasticsearch.common.unit.TimeValue;
25+
import org.elasticsearch.index.IndexModule;
2526
import org.elasticsearch.index.IndexService;
2627
import org.elasticsearch.plugins.Plugin;
2728

@@ -51,6 +52,8 @@ public List<Setting<?>> getSettings() {
5152
INDEX_CREATION_DATE_SETTING,
5253
PROVIDED_NAME_SETTING,
5354
TRANSLOG_RETENTION_CHECK_INTERVAL_SETTING,
54-
IndexService.GLOBAL_CHECKPOINT_SYNC_INTERVAL_SETTING);
55+
IndexService.GLOBAL_CHECKPOINT_SYNC_INTERVAL_SETTING,
56+
IndexModule.INDEX_QUERY_CACHE_EVERYTHING_SETTING
57+
);
5558
}
5659
}

x-pack/plugin/security/src/test/java/org/elasticsearch/test/SecuritySettingsSource.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ protected void addDefaultSecurityTransportType(Settings.Builder builder, Setting
169169

170170
@Override
171171
public Collection<Class<? extends Plugin>> nodePlugins() {
172-
return Arrays.asList(LocalStateSecurity.class, Netty4Plugin.class, ReindexPlugin.class, CommonAnalysisPlugin.class);
172+
return Arrays.asList(LocalStateSecurity.class, Netty4Plugin.class, ReindexPlugin.class, CommonAnalysisPlugin.class,
173+
InternalSettingsPlugin.class);
173174
}
174175

175176
@Override

0 commit comments

Comments
 (0)