diff --git a/modules/cache-common/src/main/java/org/opensearch/cache/common/tier/TieredSpilloverCache.java b/modules/cache-common/src/main/java/org/opensearch/cache/common/tier/TieredSpilloverCache.java index 443be0cf33567..d968e61cffcff 100644 --- a/modules/cache-common/src/main/java/org/opensearch/cache/common/tier/TieredSpilloverCache.java +++ b/modules/cache-common/src/main/java/org/opensearch/cache/common/tier/TieredSpilloverCache.java @@ -278,9 +278,6 @@ public void put(ICacheKey key, V value) { } updateStatsOnPut(cacheValueTuple.v2(), key, value); } - } else { - // Signal to the caller that the key didn't enter the cache by sending a removal notification. - removalListener.onRemoval(new RemovalNotification<>(key, value, RemovalReason.EXPLICIT)); } } @@ -403,11 +400,6 @@ private Tuple> compute( throw new IllegalStateException(ex); } } - if (wasRejectedByPolicy) { - // Signal to the caller that the key didn't enter the cache by sending a removal notification. - // This case does not count as a cache miss. - removalListener.onRemoval(new RemovalNotification<>(key, value, RemovalReason.EXPLICIT)); - } return new Tuple<>(value, new Tuple<>(wasCacheMiss, wasRejectedByPolicy)); } diff --git a/modules/cache-common/src/test/java/org/opensearch/cache/common/tier/TieredSpilloverCacheTests.java b/modules/cache-common/src/test/java/org/opensearch/cache/common/tier/TieredSpilloverCacheTests.java index c52551f764437..c74eb371709f6 100644 --- a/modules/cache-common/src/test/java/org/opensearch/cache/common/tier/TieredSpilloverCacheTests.java +++ b/modules/cache-common/src/test/java/org/opensearch/cache/common/tier/TieredSpilloverCacheTests.java @@ -1567,7 +1567,7 @@ public CachedQueryResult.PolicyValues apply(String s) { expectedKeys++; } } - assertEquals(keyValueMap.size() - expectedKeys, removalListener.evictionsMetric.count()); + assertEquals(0, removalListener.evictionsMetric.count()); assertEquals(0, getHitsForTier(tieredSpilloverCache, TIER_DIMENSION_VALUE_ON_HEAP)); assertEquals(expectedKeys, tieredSpilloverCache.count()); @@ -1657,8 +1657,7 @@ public void testEntryPoliciesWithPut() throws Exception { assertEquals(0, getEvictionsForTier(tieredSpilloverCache, TIER_DIMENSION_VALUE_ON_HEAP)); assertEquals(expectedKeys, getTotalStatsSnapshot(tieredSpilloverCache).getItems()); - assertEquals(keyValuePairs.size() - expectedKeys, removalListener.evictionsMetric.count()); // Policy rejects should send a removal - // notification + assertEquals(0, removalListener.evictionsMetric.count()); } public void testEntryPoliciesConcurrentlyWithComputeIfAbsent() throws Exception { @@ -1745,8 +1744,7 @@ public void testEntryPoliciesConcurrentlyWithComputeIfAbsent() throws Exception assertEquals(0, getEvictionsForTier(tieredSpilloverCache, TIER_DIMENSION_VALUE_ON_HEAP)); assertEquals(expectedKeys, getTotalStatsSnapshot(tieredSpilloverCache).getItems()); - // Policy rejects should send a removal notification every time the caller attempts to put them in - assertEquals((keyValuePairs.size() - expectedKeys) * numRepetitionsPerKey, removalListener.evictionsMetric.count()); + assertEquals(0, removalListener.evictionsMetric.count()); } public void testPutWithDiskCacheDisabledSetting() throws Exception {