From b774ae29a642d321aee14b15fe1d84a38b5e4771 Mon Sep 17 00:00:00 2001 From: Peter Alfonsi Date: Thu, 3 Oct 2024 12:13:51 -0700 Subject: [PATCH] cleanup Signed-off-by: Peter Alfonsi --- .../indices/IndicesRequestCache.java | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/server/src/main/java/org/opensearch/indices/IndicesRequestCache.java b/server/src/main/java/org/opensearch/indices/IndicesRequestCache.java index bb8cf161c3395..7320dddfcab8c 100644 --- a/server/src/main/java/org/opensearch/indices/IndicesRequestCache.java +++ b/server/src/main/java/org/opensearch/indices/IndicesRequestCache.java @@ -747,7 +747,6 @@ private synchronized void cleanCache(double stalenessThreshold) { if (canSkipCacheCleanup(stalenessThreshold)) { return; } - ThreadPoolExecutor removalPool = (ThreadPoolExecutor) Executors.newFixedThreadPool(NUM_CLEANUP_KEY_THREADS); // Contains CleanupKey objects with open shard but invalidated readerCacheKeyId. final Set cleanupKeysFromOutdatedReaders = new HashSet<>(); // Contains CleanupKey objects for a full cache cleanup. @@ -789,7 +788,6 @@ private synchronized void cleanCache(double stalenessThreshold) { Key delegatingKey = key.key; Tuple shardIdInfo = new Tuple<>(delegatingKey.shardId, delegatingKey.indexShardHashCode); if (cleanupKeysFromFullClean.contains(shardIdInfo) || cleanupKeysFromClosedShards.contains(shardIdInfo)) { - //iterator.remove(); removeKey(threadPool, phaser, key); } else { CacheEntity cacheEntity = cacheEntityLookup.apply(delegatingKey.shardId).orElse(null); @@ -797,12 +795,10 @@ private synchronized void cleanCache(double stalenessThreshold) { // If cache entity is null, it means that index or shard got deleted/closed meanwhile. // So we will delete this key. dimensionListsToDrop.add(key.dimensions); - //iterator.remove(); removeKey(threadPool, phaser, key); } else { CleanupKey cleanupKey = new CleanupKey(cacheEntity, delegatingKey.readerCacheKeyId); if (cleanupKeysFromOutdatedReaders.contains(cleanupKey)) { - //iterator.remove(); removeKey(threadPool, phaser, key); } } @@ -819,12 +815,6 @@ private synchronized void cleanCache(double stalenessThreshold) { removeBatch(threadPool, phaser); } phaser.arriveAndAwaitAdvance(); // Wait for all batches to signal completion - // How to await the pool being done? - // This is only TODO proof of concept - /*removalPool.shutdown(); - try { - removalPool.awaitTermination(1, TimeUnit.MINUTES); - } catch (Exception ignored) {}*/ for (List closedDimensions : dimensionListsToDrop) { // Invalidate a dummy key containing the dimensions we need to drop stats for @@ -833,9 +823,6 @@ private synchronized void cleanCache(double stalenessThreshold) { cache.invalidate(dummyKey); } cache.refresh(); - /*try { - Thread.sleep(1000); // TODO: Debug only for tests - } catch (Exception ignored) {}*/ } private void removeKey(ThreadPool pool, Phaser phaser, ICacheKey key) { @@ -862,20 +849,6 @@ private synchronized void removeBatch(ThreadPool pool, Phaser phaser) { }); } - private void removeKey(ThreadPoolExecutor pool, ICacheKey key) { - // Shouldn't have to worry about other threads interfering with contents of batch. This should only be called by one thread at a time - // so long as cleanupCache isn't running over itself. - currentDeletionBatch.add(key); - if (currentDeletionBatch.size() >= KEYS_TO_DELETE_BATCH_SIZE) { - pool.execute(() -> { - for (ICacheKey batchKey : currentDeletionBatch) { - cache.invalidate(batchKey); - } - }); - currentDeletionBatch = new HashSet<>(); - } - } - /** * Determines whether the cache cleanup process can be skipped based on the staleness threshold. *