@@ -118,7 +118,7 @@ public void testSanityChecksWithIndicesRequestCache() throws InterruptedExceptio
118
118
);
119
119
}
120
120
121
- public void testWithDynamicTookTimePolicyWithMultiSegments () throws Exception {
121
+ public void testWithDynamicDiskTookTimePolicyWithMultiSegments () throws Exception {
122
122
int numberOfSegments = getNumberOfSegments ();
123
123
int onHeapCacheSizePerSegmentInBytes = 800 ; // Per cache entry below is around ~700 bytes, so keeping this
124
124
// just a bit higher so that each segment can atleast hold 1 entry.
@@ -139,12 +139,13 @@ public void testWithDynamicTookTimePolicyWithMultiSegments() throws Exception {
139
139
)
140
140
.get ()
141
141
);
142
- // Set a very high value for took time policy so that no items evicted from onHeap cache are spilled
142
+ // Set a very high value for took time disk policy so that no items evicted from onHeap cache are spilled
143
143
// to disk. And then hit requests so that few items are cached into cache.
144
144
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest ().transientSettings (
145
145
Settings .builder ()
146
146
.put (
147
- TieredSpilloverCacheSettings .TOOK_TIME_POLICY_CONCRETE_SETTINGS_MAP .get (CacheType .INDICES_REQUEST_CACHE ).getKey (),
147
+ TieredSpilloverCacheSettings .TOOK_TIME_DISK_TIER_POLICY_CONCRETE_SETTINGS_MAP .get (CacheType .INDICES_REQUEST_CACHE )
148
+ .getKey (),
148
149
new TimeValue (100 , TimeUnit .SECONDS )
149
150
)
150
151
.build ()
@@ -182,12 +183,13 @@ public void testWithDynamicTookTimePolicyWithMultiSegments() throws Exception {
182
183
assertEquals (0 , requestCacheStats .getHitCount ());
183
184
long lastEvictionSeen = requestCacheStats .getEvictions ();
184
185
185
- // Decrease took time policy to zero so that disk cache also comes into play. Now we should be able
186
+ // Decrease disk took time policy to zero so that disk cache also comes into play. Now we should be able
186
187
// to cache all entries.
187
188
updateSettingsRequest = new ClusterUpdateSettingsRequest ().transientSettings (
188
189
Settings .builder ()
189
190
.put (
190
- TieredSpilloverCacheSettings .TOOK_TIME_POLICY_CONCRETE_SETTINGS_MAP .get (CacheType .INDICES_REQUEST_CACHE ).getKey (),
191
+ TieredSpilloverCacheSettings .TOOK_TIME_DISK_TIER_POLICY_CONCRETE_SETTINGS_MAP .get (CacheType .INDICES_REQUEST_CACHE )
192
+ .getKey (),
191
193
new TimeValue (0 , TimeUnit .MILLISECONDS )
192
194
)
193
195
.build ()
@@ -206,7 +208,7 @@ public void testWithDynamicTookTimePolicyWithMultiSegments() throws Exception {
206
208
assertEquals (lastEvictionSeen , requestCacheStats .getEvictions ());
207
209
}
208
210
209
- public void testWithDynamicTookTimePolicy () throws Exception {
211
+ public void testWithDynamicHeapTookTimePolicy () throws Exception {
210
212
int onHeapCacheSizeInBytes = 2000 ;
211
213
internalCluster ().startNode (Settings .builder ().put (defaultSettings (onHeapCacheSizeInBytes + "b" , 1 )).build ());
212
214
Client client = client ();
@@ -224,8 +226,7 @@ public void testWithDynamicTookTimePolicy() throws Exception {
224
226
)
225
227
.get ()
226
228
);
227
- // Step 1 : Set a very high value for took time policy so that no items evicted from onHeap cache are spilled
228
- // to disk. And then hit requests so that few items are cached into cache.
229
+ // Set a high threshold for the overall cache took time policy so nothing will enter the cache.
229
230
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest ().transientSettings (
230
231
Settings .builder ()
231
232
.put (
@@ -245,6 +246,57 @@ public void testWithDynamicTookTimePolicy() throws Exception {
245
246
ForceMergeResponse forceMergeResponse = client .admin ().indices ().prepareForceMerge ("index" ).setFlush (true ).get ();
246
247
OpenSearchAssertions .assertAllSuccessful (forceMergeResponse );
247
248
long perQuerySizeInCacheInBytes = -1 ;
249
+ for (int iterator = 0 ; iterator < numberOfIndexedItems ; iterator ++) {
250
+ SearchResponse resp = client .prepareSearch ("index" )
251
+ .setRequestCache (true )
252
+ .setQuery (QueryBuilders .termQuery ("k" + iterator , "hello" + iterator ))
253
+ .get ();
254
+ assertSearchResponse (resp );
255
+ }
256
+ RequestCacheStats requestCacheStats = getRequestCacheStats (client , "index" );
257
+ assertEquals (0 , requestCacheStats .getEvictions ());
258
+ }
259
+
260
+ public void testWithDynamicDiskTookTimePolicy () throws Exception {
261
+ int onHeapCacheSizeInBytes = 2000 ;
262
+ internalCluster ().startNode (Settings .builder ().put (defaultSettings (onHeapCacheSizeInBytes + "b" , 1 )).build ());
263
+ Client client = client ();
264
+ assertAcked (
265
+ client .admin ()
266
+ .indices ()
267
+ .prepareCreate ("index" )
268
+ .setMapping ("k" , "type=keyword" )
269
+ .setSettings (
270
+ Settings .builder ()
271
+ .put (IndicesRequestCache .INDEX_CACHE_REQUEST_ENABLED_SETTING .getKey (), true )
272
+ .put (IndexMetadata .SETTING_NUMBER_OF_SHARDS , 1 )
273
+ .put (IndexMetadata .SETTING_NUMBER_OF_REPLICAS , 0 )
274
+ .put ("index.refresh_interval" , -1 )
275
+ )
276
+ .get ()
277
+ );
278
+ // Step 1 : Set a very high value for disk took time policy so that no items evicted from onHeap cache are spilled
279
+ // to disk. And then hit requests so that few items are cached into cache.
280
+ ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest ().transientSettings (
281
+ Settings .builder ()
282
+ .put (
283
+ TieredSpilloverCacheSettings .TOOK_TIME_DISK_TIER_POLICY_CONCRETE_SETTINGS_MAP .get (CacheType .INDICES_REQUEST_CACHE )
284
+ .getKey (),
285
+ new TimeValue (100 , TimeUnit .SECONDS )
286
+ )
287
+ .build ()
288
+ );
289
+ assertAcked (internalCluster ().client ().admin ().cluster ().updateSettings (updateSettingsRequest ).get ());
290
+ int numberOfIndexedItems = randomIntBetween (6 , 10 );
291
+ for (int iterator = 0 ; iterator < numberOfIndexedItems ; iterator ++) {
292
+ indexRandom (true , client .prepareIndex ("index" ).setSource ("k" + iterator , "hello" + iterator ));
293
+ }
294
+ ensureSearchable ("index" );
295
+ refreshAndWaitForReplication ();
296
+ // Force merge the index to ensure there can be no background merges during the subsequent searches that would invalidate the cache
297
+ ForceMergeResponse forceMergeResponse = client .admin ().indices ().prepareForceMerge ("index" ).setFlush (true ).get ();
298
+ OpenSearchAssertions .assertAllSuccessful (forceMergeResponse );
299
+ long perQuerySizeInCacheInBytes = -1 ;
248
300
for (int iterator = 0 ; iterator < numberOfIndexedItems ; iterator ++) {
249
301
SearchResponse resp = client .prepareSearch ("index" )
250
302
.setRequestCache (true )
@@ -282,12 +334,13 @@ public void testWithDynamicTookTimePolicy() throws Exception {
282
334
assertEquals (0 , requestCacheStats .getHitCount ());
283
335
long lastEvictionSeen = requestCacheStats .getEvictions ();
284
336
285
- // Step 3: Decrease took time policy to zero so that disk cache also comes into play. Now we should be able
337
+ // Step 3: Decrease disk took time policy to zero so that disk cache also comes into play. Now we should be able
286
338
// to cache all entries.
287
339
updateSettingsRequest = new ClusterUpdateSettingsRequest ().transientSettings (
288
340
Settings .builder ()
289
341
.put (
290
- TieredSpilloverCacheSettings .TOOK_TIME_POLICY_CONCRETE_SETTINGS_MAP .get (CacheType .INDICES_REQUEST_CACHE ).getKey (),
342
+ TieredSpilloverCacheSettings .TOOK_TIME_DISK_TIER_POLICY_CONCRETE_SETTINGS_MAP .get (CacheType .INDICES_REQUEST_CACHE )
343
+ .getKey (),
291
344
new TimeValue (0 , TimeUnit .MILLISECONDS )
292
345
)
293
346
.build ()
@@ -352,11 +405,12 @@ public void testInvalidationWithIndicesRequestCache() throws Exception {
352
405
)
353
406
.get ()
354
407
);
355
- // Update took time policy to zero so that all entries are eligible to be cached on disk.
408
+ // Update disk took time policy to zero so that all entries are eligible to be cached on disk.
356
409
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest ().transientSettings (
357
410
Settings .builder ()
358
411
.put (
359
- TieredSpilloverCacheSettings .TOOK_TIME_POLICY_CONCRETE_SETTINGS_MAP .get (CacheType .INDICES_REQUEST_CACHE ).getKey (),
412
+ TieredSpilloverCacheSettings .TOOK_TIME_DISK_TIER_POLICY_CONCRETE_SETTINGS_MAP .get (CacheType .INDICES_REQUEST_CACHE )
413
+ .getKey (),
360
414
new TimeValue (0 , TimeUnit .MILLISECONDS )
361
415
)
362
416
.build ()
@@ -437,11 +491,12 @@ public void testWithExplicitCacheClear() throws Exception {
437
491
)
438
492
.get ()
439
493
);
440
- // Update took time policy to zero so that all entries are eligible to be cached on disk.
494
+ // Update disk took time policy to zero so that all entries are eligible to be cached on disk.
441
495
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest ().transientSettings (
442
496
Settings .builder ()
443
497
.put (
444
- TieredSpilloverCacheSettings .TOOK_TIME_POLICY_CONCRETE_SETTINGS_MAP .get (CacheType .INDICES_REQUEST_CACHE ).getKey (),
498
+ TieredSpilloverCacheSettings .TOOK_TIME_DISK_TIER_POLICY_CONCRETE_SETTINGS_MAP .get (CacheType .INDICES_REQUEST_CACHE )
499
+ .getKey (),
445
500
new TimeValue (0 , TimeUnit .MILLISECONDS )
446
501
)
447
502
.build ()
@@ -512,11 +567,12 @@ public void testWithDynamicDiskCacheSetting() throws Exception {
512
567
)
513
568
.get ()
514
569
);
515
- // Update took time policy to zero so that all entries are eligible to be cached on disk.
570
+ // Update disk took time policy to zero so that all entries are eligible to be cached on disk.
516
571
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest ().transientSettings (
517
572
Settings .builder ()
518
573
.put (
519
- TieredSpilloverCacheSettings .TOOK_TIME_POLICY_CONCRETE_SETTINGS_MAP .get (CacheType .INDICES_REQUEST_CACHE ).getKey (),
574
+ TieredSpilloverCacheSettings .TOOK_TIME_DISK_TIER_POLICY_CONCRETE_SETTINGS_MAP .get (CacheType .INDICES_REQUEST_CACHE )
575
+ .getKey (),
520
576
new TimeValue (0 , TimeUnit .MILLISECONDS )
521
577
)
522
578
.build ()
0 commit comments