|
10 | 10 |
|
11 | 11 | import org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest;
|
12 | 12 | import org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse;
|
| 13 | +import org.opensearch.action.admin.indices.delete.DeleteIndexRequest; |
13 | 14 | import org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse;
|
14 | 15 | import org.opensearch.action.admin.indices.stats.CommonStatsFlags;
|
15 | 16 | import org.opensearch.action.search.SearchResponse;
|
|
40 | 41 | import static org.opensearch.cache.common.tier.TieredSpilloverCacheStatsHolder.TIER_DIMENSION_NAME;
|
41 | 42 | import static org.opensearch.cache.common.tier.TieredSpilloverCacheStatsHolder.TIER_DIMENSION_VALUE_DISK;
|
42 | 43 | import static org.opensearch.cache.common.tier.TieredSpilloverCacheStatsHolder.TIER_DIMENSION_VALUE_ON_HEAP;
|
| 44 | +import static org.opensearch.indices.IndicesService.INDICES_CACHE_CLEAN_INTERVAL_SETTING; |
43 | 45 | import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
|
44 | 46 | import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse;
|
45 | 47 |
|
@@ -417,6 +419,55 @@ public void testStatsWithMultipleSegments() throws Exception {
|
417 | 419 | assertTrue(diskCacheStat.getEvictions() == 0);
|
418 | 420 | }
|
419 | 421 |
|
| 422 | + public void testClosingShard() throws Exception { |
| 423 | + // Closing the shard should totally remove the stats associated with that shard. |
| 424 | + internalCluster().startNodes( |
| 425 | + 1, |
| 426 | + Settings.builder() |
| 427 | + .put(defaultSettings(HEAP_CACHE_SIZE_STRING, getNumberOfSegments())) |
| 428 | + .put( |
| 429 | + TieredSpilloverCacheSettings.TOOK_TIME_POLICY_CONCRETE_SETTINGS_MAP.get(CacheType.INDICES_REQUEST_CACHE).getKey(), |
| 430 | + new TimeValue(0, TimeUnit.SECONDS) |
| 431 | + ) |
| 432 | + .put(INDICES_CACHE_CLEAN_INTERVAL_SETTING.getKey(), new TimeValue(1)) |
| 433 | + .build() |
| 434 | + ); |
| 435 | + String index = "index"; |
| 436 | + Client client = client(); |
| 437 | + startIndex(client, index); |
| 438 | + |
| 439 | + // First search one time to see how big a single value will be |
| 440 | + searchIndex(client, index, 0); |
| 441 | + // get total stats |
| 442 | + long singleSearchSize = getTotalStats(client).getSizeInBytes(); |
| 443 | + // Select numbers so we get some values on both heap and disk |
| 444 | + int itemsOnHeap = HEAP_CACHE_SIZE / (int) singleSearchSize; |
| 445 | + int itemsOnDisk = 1 + randomInt(30); // The first one we search (to get the size) always goes to disk |
| 446 | + int expectedEntries = itemsOnHeap + itemsOnDisk; |
| 447 | + |
| 448 | + for (int i = 1; i < expectedEntries; i++) { |
| 449 | + // Cause misses |
| 450 | + searchIndex(client, index, i); |
| 451 | + } |
| 452 | + int expectedMisses = itemsOnHeap + itemsOnDisk; |
| 453 | + |
| 454 | + // Cause some hits |
| 455 | + int expectedHits = randomIntBetween(itemsOnHeap, expectedEntries); // Select it so some hits come from both tiers |
| 456 | + for (int i = 0; i < expectedHits; i++) { |
| 457 | + searchIndex(client, index, i); |
| 458 | + } |
| 459 | + |
| 460 | + // Check the new stats API values are as expected |
| 461 | + assertEquals( |
| 462 | + new ImmutableCacheStats(expectedHits, expectedMisses, 0, expectedEntries * singleSearchSize, expectedEntries), |
| 463 | + getTotalStats(client) |
| 464 | + ); |
| 465 | + |
| 466 | + // Closing the index should close the shard |
| 467 | + assertAcked(client().admin().indices().delete(new DeleteIndexRequest("index")).get()); |
| 468 | + assertEquals(new ImmutableCacheStats(0, 0, 0, 0, 0), getTotalStats(client)); |
| 469 | + } |
| 470 | + |
420 | 471 | private void startIndex(Client client, String indexName) throws InterruptedException {
|
421 | 472 | assertAcked(
|
422 | 473 | client.admin()
|
|
0 commit comments