From 9956abcb842b9db1eff7bc9900237ae9ed9bc1a2 Mon Sep 17 00:00:00 2001 From: Sagar Upadhyaya Date: Mon, 8 Jan 2024 09:12:19 -0800 Subject: [PATCH] Removing TieredCache interface Signed-off-by: Sagar Upadhyaya --- .../common/cache/tier/TieredCache.java | 25 ----------- .../cache/tier/TieredSpilloverCache.java | 42 +------------------ .../cache/tier/TieredSpilloverCacheTests.java | 12 +++--- 3 files changed, 6 insertions(+), 73 deletions(-) delete mode 100644 server/src/main/java/org/opensearch/common/cache/tier/TieredCache.java diff --git a/server/src/main/java/org/opensearch/common/cache/tier/TieredCache.java b/server/src/main/java/org/opensearch/common/cache/tier/TieredCache.java deleted file mode 100644 index f99d1adb2ab7e..0000000000000 --- a/server/src/main/java/org/opensearch/common/cache/tier/TieredCache.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.common.cache.tier; - -import org.opensearch.common.cache.ICache; -import org.opensearch.common.cache.store.enums.CacheStoreType; - -/** - * This represents a cache comprising of multiple tiers/layers. - * @param Type of key - * @param Type of value - * - * @opensearch.experimental - */ -public interface TieredCache extends ICache { - Iterable cacheKeys(CacheStoreType type); - - void refresh(CacheStoreType type); -} diff --git a/server/src/main/java/org/opensearch/common/cache/tier/TieredSpilloverCache.java b/server/src/main/java/org/opensearch/common/cache/tier/TieredSpilloverCache.java index 4f5c378333f14..8b432c9484aed 100644 --- a/server/src/main/java/org/opensearch/common/cache/tier/TieredSpilloverCache.java +++ b/server/src/main/java/org/opensearch/common/cache/tier/TieredSpilloverCache.java @@ -39,7 +39,7 @@ * * @opensearch.experimental */ -public class TieredSpilloverCache implements TieredCache, StoreAwareCacheEventListener { +public class TieredSpilloverCache implements ICache, StoreAwareCacheEventListener { // TODO: Remove optional when diskCache implementation is integrated. private final Optional> onDiskCache; @@ -178,46 +178,6 @@ public void refresh() { } } - /** - * Provides an iteration over keys based on desired on cacheStoreType. This is not protected from any mutations - * to the cache. - * @param type Type of cacheStoreType - * @return An iterable over desired CacheStoreType keys - */ - @Override - public Iterable cacheKeys(CacheStoreType type) { - switch (type) { - case ON_HEAP: - return onHeapCache.keys(); - case DISK: - if (onDiskCache.isPresent()) { - return onDiskCache.get().keys(); - } else { - return Collections::emptyIterator; - } - default: - throw new IllegalArgumentException("Unsupported Cache store type: " + type); - } - } - - @Override - public void refresh(CacheStoreType type) { - switch (type) { - case ON_HEAP: - try (ReleasableLock ignore = writeLock.acquire()) { - onHeapCache.refresh(); - } - break; - case DISK: - try (ReleasableLock ignore = writeLock.acquire()) { - onDiskCache.ifPresent(ICache::refresh); - } - break; - default: - throw new IllegalArgumentException("Unsupported Cache store type: " + type); - } - } - @Override public void onMiss(K key, CacheStoreType cacheStoreType) { // Misses for tiered cache are tracked here itself. diff --git a/server/src/test/java/org/opensearch/common/cache/tier/TieredSpilloverCacheTests.java b/server/src/test/java/org/opensearch/common/cache/tier/TieredSpilloverCacheTests.java index e7a056b43e460..eb75244c6f8b1 100644 --- a/server/src/test/java/org/opensearch/common/cache/tier/TieredSpilloverCacheTests.java +++ b/server/src/test/java/org/opensearch/common/cache/tier/TieredSpilloverCacheTests.java @@ -114,8 +114,8 @@ public void testComputeIfAbsentWithEvictionsFromOnHeapCache() throws Exception { ); assertEquals(actualDiskCacheSize, eventListener.enumMap.get(CacheStoreType.DISK).cachedCount.count()); - tieredSpilloverCache.cacheKeys(CacheStoreType.ON_HEAP).forEach(onHeapKeys::add); - tieredSpilloverCache.cacheKeys(CacheStoreType.DISK).forEach(diskTierKeys::add); + tieredSpilloverCache.getOnHeapCache().keys().forEach(onHeapKeys::add); + tieredSpilloverCache.getOnDiskCache().get().keys().forEach(diskTierKeys::add); assertEquals(tieredSpilloverCache.getOnHeapCache().count(), onHeapKeys.size()); assertEquals(tieredSpilloverCache.getOnDiskCache().get().count(), diskTierKeys.size()); @@ -312,7 +312,7 @@ public String load(String key) { // Verify that new items are part of onHeap cache. List actualOnHeapCacheKeys = new ArrayList<>(); - tieredSpilloverCache.cacheKeys(CacheStoreType.ON_HEAP).forEach(actualOnHeapCacheKeys::add); + tieredSpilloverCache.getOnHeapCache().keys().forEach(actualOnHeapCacheKeys::add); assertEquals(newKeyList.size(), actualOnHeapCacheKeys.size()); for (int i = 0; i < actualOnHeapCacheKeys.size(); i++) { @@ -387,8 +387,8 @@ public void testCacheKeys() throws Exception { List actualOnHeapKeys = new ArrayList<>(); List actualOnDiskKeys = new ArrayList<>(); - Iterable onHeapiterable = tieredSpilloverCache.cacheKeys(CacheStoreType.ON_HEAP); - Iterable onDiskiterable = tieredSpilloverCache.cacheKeys(CacheStoreType.DISK); + Iterable onHeapiterable = tieredSpilloverCache.getOnHeapCache().keys(); + Iterable onDiskiterable = tieredSpilloverCache.getOnDiskCache().get().keys(); onHeapiterable.iterator().forEachRemaining(actualOnHeapKeys::add); onDiskiterable.iterator().forEachRemaining(actualOnDiskKeys::add); for (String onHeapKey : onHeapKeys) { @@ -424,8 +424,6 @@ public void testRefresh() { eventListener, 0 ); - tieredSpilloverCache.refresh(CacheStoreType.ON_HEAP); - tieredSpilloverCache.refresh(CacheStoreType.DISK); tieredSpilloverCache.refresh(); }