From 9aeb82d641220dfeae46d103a47575cc10c4cc0c Mon Sep 17 00:00:00 2001 From: Kiran Prakash Date: Fri, 12 Apr 2024 08:43:50 -0700 Subject: [PATCH] Update IndicesRequestCache.java Signed-off-by: Kiran Prakash --- .../indices/IndicesRequestCache.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/server/src/main/java/org/opensearch/indices/IndicesRequestCache.java b/server/src/main/java/org/opensearch/indices/IndicesRequestCache.java index c8e8fb10efd2e..3ee57fdb7efff 100644 --- a/server/src/main/java/org/opensearch/indices/IndicesRequestCache.java +++ b/server/src/main/java/org/opensearch/indices/IndicesRequestCache.java @@ -509,19 +509,15 @@ private void updateStaleCountOnCacheInsert(CleanupKey cleanupKey) { * @param notification RemovalNotification of the cache entry evicted */ private void updateStaleCountOnEntryRemoval(CleanupKey cleanupKey, RemovalNotification notification) { - if (cleanupKey.entity == null) { - /* - * on shard close, the shard is still lying around so this will only happen when the shard is deleted. - * we would have accounted this in staleKeysCount when the deletion of shard would have closed the associated readers - * */ - staleKeysCount.decrementAndGet(); + if (notification.getRemovalReason() == RemovalReason.REPLACED) { + // The reason of the notification is REPLACED when a cache entry's value is updated, since replacing an entry + // does not affect the staleness count, we skip such notifications. return; } - /* - * The reason of the notification is REPLACED when a cache entry's value is updated, since replacing an entry - * does not affect the staleness count, we skip such notifications. - * */ - if (notification.getRemovalReason() == RemovalReason.REPLACED) { + if (cleanupKey.entity == null) { + // on shard close, the shard is still lying around so this will only happen when the shard is deleted. + // we would have accounted this in staleKeysCount when the deletion of shard would have closed the associated readers + staleKeysCount.decrementAndGet(); return; } IndexShard indexShard = (IndexShard) cleanupKey.entity.getCacheIdentity();