From 3a2e8520de0f246a31e120221d83a78a296a058d Mon Sep 17 00:00:00 2001 From: Kiran Prakash Date: Wed, 10 Apr 2024 10:13:48 -0700 Subject: [PATCH] code comments only Signed-off-by: Kiran Prakash --- .../java/org/opensearch/indices/IndicesRequestCache.java | 4 ++-- .../org/opensearch/indices/IndicesRequestCacheTests.java | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/opensearch/indices/IndicesRequestCache.java b/server/src/main/java/org/opensearch/indices/IndicesRequestCache.java index c18cc87bc700e..ad6fe1242b941 100644 --- a/server/src/main/java/org/opensearch/indices/IndicesRequestCache.java +++ b/server/src/main/java/org/opensearch/indices/IndicesRequestCache.java @@ -260,8 +260,8 @@ BytesReference getOrCompute( if (logger.isDebugEnabled()) { logger.debug("cleanupKey in Indices Request Cache failed to register close listener due to : " + e.getCause()); } - // On failing to register the cleanupkey, this cache entry is immediately stale and could live indefinitely - // hence enqueuing it to clean-up + // On failing to register the cleanupkey, this cache entry is immediately stale and could live indefinitely in the cache + // hence enqueuing it for clean-up cacheCleanupManager.updateCleanupKeyToCountMapOnCacheInsertion(cleanupKey); cacheCleanupManager.enqueueCleanupKey(cleanupKey); throw e; diff --git a/server/src/test/java/org/opensearch/indices/IndicesRequestCacheTests.java b/server/src/test/java/org/opensearch/indices/IndicesRequestCacheTests.java index af08851917295..faa03cd6706ad 100644 --- a/server/src/test/java/org/opensearch/indices/IndicesRequestCacheTests.java +++ b/server/src/test/java/org/opensearch/indices/IndicesRequestCacheTests.java @@ -655,7 +655,9 @@ public void testCleanupKeyToCountMapAreSetAppropriately() throws Exception { assertEquals(0, cleanupKeyToCountMap.size()); } - // test the cleanupKeyToCountMap are set appropriately when readers are closed + // test the cleanupKeyToCountMap are set appropriately in a case where the reader gets closed + // after putting an entry into the cache and before registering a close listener + // in this case, the entry is stale and needs to be accounted right and cleaned up accordingly public void testCleanupKeyToOnClosedReader_cleansupStalenessAsExpected() throws Exception { threadPool = getThreadPool(); Settings settings = Settings.builder() @@ -670,6 +672,7 @@ public void testCleanupKeyToOnClosedReader_cleansupStalenessAsExpected() throws assertTrue(cache.cacheCleanupManager.getCleanupKeyToCountMap().isEmpty()); try { + // use auto close loader to close the reader right after adding cache entry cache.getOrCompute(getEntity(indexShard), getAutoCloseLoader(reader), reader, getTermBytes()); } catch (Exception e) { assertThat(e, instanceOf(AlreadyClosedException.class));