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 87851ca69dcae..7c9569f5defe2 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 @@ -18,9 +18,7 @@ import org.opensearch.common.cache.store.config.CacheConfig; import org.opensearch.common.cache.store.settings.OpenSearchOnHeapCacheSettings; import org.opensearch.common.metrics.CounterMetric; -import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Settings; -import org.opensearch.core.common.unit.ByteSizeValue; import org.opensearch.test.OpenSearchTestCase; import java.util.ArrayList; @@ -353,8 +351,6 @@ public void testComputeIfAbsentWithEvictionsFromBothTier() throws Exception { tieredSpilloverCache.computeIfAbsent(UUID.randomUUID().toString(), tieredCacheLoader); } assertTrue(removalListener.evictionsMetric.count() > 0); - // assertTrue(eventListener.enumMap.get(CacheStoreType.ON_HEAP).evictionsMetric.count() > 0); - // assertTrue(eventListener.enumMap.get(CacheStoreType.DISK).evictionsMetric.count() > 0); } public void testGetAndCount() throws Exception { @@ -433,7 +429,6 @@ public void testPut() { String key = UUID.randomUUID().toString(); String value = UUID.randomUUID().toString(); tieredSpilloverCache.put(key, value); - // assertEquals(1, eventListener.enumMap.get(CacheStoreType.ON_HEAP).cachedCount.count()); assertEquals(1, tieredSpilloverCache.count()); } @@ -532,12 +527,10 @@ public void testInvalidate() { String value = UUID.randomUUID().toString(); // First try to invalidate without the key present in cache. tieredSpilloverCache.invalidate(key); - // assertEquals(0, eventListener.enumMap.get(CacheStoreType.ON_HEAP).invalidationMetric.count()); // Now try to invalidate with the key present in onHeap cache. tieredSpilloverCache.put(key, value); tieredSpilloverCache.invalidate(key); - // assertEquals(1, eventListener.enumMap.get(CacheStoreType.ON_HEAP).invalidationMetric.count()); assertEquals(0, tieredSpilloverCache.count()); tieredSpilloverCache.put(key, value); @@ -547,7 +540,6 @@ public void testInvalidate() { assertEquals(2, tieredSpilloverCache.count()); // Again invalidate older key tieredSpilloverCache.invalidate(key); - // assertEquals(1, eventListener.enumMap.get(CacheStoreType.DISK).invalidationMetric.count()); assertEquals(1, tieredSpilloverCache.count()); } @@ -823,7 +815,6 @@ public String load(String key) { assertNotNull(actualValue.get()); countDownLatch1.await(); assertEquals(1, removalListener.evictionsMetric.count()); - // assertEquals(1, eventListener.enumMap.get(CacheStoreType.ON_HEAP).evictionsMetric.count()); assertEquals(1, tieredSpilloverCache.getOnHeapCache().count()); assertEquals(1, onDiskCache.count()); assertNotNull(onDiskCache.get(keyToBeEvicted)); @@ -862,7 +853,6 @@ private TieredSpilloverCache intializeTieredSpilloverCache( Settings settings, long diskDeliberateDelay ) { - // ICache.Factory onHeapCacheFactory = new OpenSearchOnHeapCache.OpenSearchOnHeapCacheFactory(); ICache.Factory onHeapCacheFactory = new OpenSearchOnHeapCache.OpenSearchOnHeapCacheFactory(); CacheConfig cacheConfig = new CacheConfig.Builder().setKeyType(String.class) .setKeyType(String.class) @@ -882,111 +872,6 @@ private TieredSpilloverCache intializeTieredSpilloverCache( } } -/** - * Wrapper OpenSearchOnHeap cache which tracks its own stats. - * @param Type of key - * @param Type of value - */ -class OpenSearchOnHeapCacheWrapper extends OpenSearchOnHeapCache { - - StatsHolder statsHolder = new StatsHolder(); - - public OpenSearchOnHeapCacheWrapper(Builder builder) { - super(builder); - } - - @Override - public V get(K key) { - V value = super.get(key); - if (value != null) { - statsHolder.hitCount.inc(); - } else { - statsHolder.missCount.inc(); - } - return value; - } - - @Override - public void put(K key, V value) { - super.put(key, value); - statsHolder.onCachedMetric.inc(); - } - - @Override - public V computeIfAbsent(K key, LoadAwareCacheLoader loader) throws Exception { - V value = super.computeIfAbsent(key, loader); - if (loader.isLoaded()) { - statsHolder.missCount.inc(); - statsHolder.onCachedMetric.inc(); - } else { - statsHolder.hitCount.inc(); - } - return value; - } - - @Override - public void invalidate(K key) { - super.invalidate(key); - } - - @Override - public void invalidateAll() { - super.invalidateAll(); - } - - @Override - public Iterable keys() { - return super.keys(); - } - - @Override - public long count() { - return super.count(); - } - - @Override - public void refresh() { - super.refresh(); - } - - @Override - public void close() {} - - @Override - public void onRemoval(RemovalNotification notification) { - super.onRemoval(notification); - } - - /** - * Factory for the wrapper cache class - */ - static class OpenSearchOnHeapCacheWrapperFactory extends OpenSearchOnHeapCacheFactory { - - @Override - public ICache create(CacheConfig config, CacheType cacheType, Map cacheFactories) { - Map> settingList = OpenSearchOnHeapCacheSettings.getSettingListForCacheType(cacheType); - Settings settings = config.getSettings(); - return new OpenSearchOnHeapCacheWrapper<>( - (Builder) new OpenSearchOnHeapCache.Builder().setMaximumWeightInBytes( - ((ByteSizeValue) settingList.get(MAXIMUM_SIZE_IN_BYTES_KEY).get(settings)).getBytes() - ).setWeigher(config.getWeigher()) - ); - } - - @Override - public String getCacheName() { - return super.getCacheName(); - } - } - - class StatsHolder { - CounterMetric hitCount = new CounterMetric(); - CounterMetric missCount = new CounterMetric(); - CounterMetric evictionMetric = new CounterMetric(); - CounterMetric onCachedMetric = new CounterMetric(); - } -} - class MockOnDiskCache implements ICache { Map cache; @@ -1008,8 +893,6 @@ public V get(K key) { @Override public void put(K key, V value) { if (this.cache.size() >= maxSize) { // For simplification - // eventListener.onRemoval(new StoreAwareCacheRemovalNotification<>(key, value, RemovalReason.EVICTED, - // CacheStoreType.DISK)); return; } try { @@ -1018,11 +901,10 @@ public void put(K key, V value) { throw new RuntimeException(e); } this.cache.put(key, value); - // eventListener.onCached(key, value, CacheStoreType.DISK); } @Override - public V computeIfAbsent(K key, LoadAwareCacheLoader loader) throws Exception { + public V computeIfAbsent(K key, LoadAwareCacheLoader loader) { V value = cache.computeIfAbsent(key, key1 -> { try { return loader.load(key); @@ -1030,20 +912,11 @@ public V computeIfAbsent(K key, LoadAwareCacheLoader loader) throws Except throw new RuntimeException(e); } }); - // if (!loader.isLoaded()) { - // eventListener.onHit(key, value, CacheStoreType.DISK); - // } else { - // eventListener.onMiss(key, CacheStoreType.DISK); - // eventListener.onCached(key, value, CacheStoreType.DISK); - // } return value; } @Override public void invalidate(K key) { - if (this.cache.containsKey(key)) { - // eventListener.onRemoval(new StoreAwareCacheRemovalNotification<>(key, null, RemovalReason.INVALIDATED, CacheStoreType.DISK)); - } this.cache.remove(key); }