From 8a949d4404cf40d1dd20d9c10d5c9ee5a6bcfea3 Mon Sep 17 00:00:00 2001 From: Kiran Prakash Date: Mon, 17 Jun 2024 14:28:34 -0700 Subject: [PATCH] Update IndicesRequestCache.java Signed-off-by: Kiran Prakash --- .../org/opensearch/indices/IndicesRequestCache.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/server/src/main/java/org/opensearch/indices/IndicesRequestCache.java b/server/src/main/java/org/opensearch/indices/IndicesRequestCache.java index cc07e491b43b0..c45334201e9b8 100644 --- a/server/src/main/java/org/opensearch/indices/IndicesRequestCache.java +++ b/server/src/main/java/org/opensearch/indices/IndicesRequestCache.java @@ -573,14 +573,8 @@ private void updateStaleCountOnCacheInsert(CleanupKey cleanupKey) { // pkg-private for testing void addToCleanupKeyToCountMap(ShardId shardId, String readerCacheKeyId) { - cleanupKeyToCountMap.compute(shardId, (currentShardId, readerCacheKeyMap) -> { - final ConcurrentHashMap updatedReaderCacheKeyMap = Objects.requireNonNullElseGet( - readerCacheKeyMap, - ConcurrentHashMap::new - ); - updatedReaderCacheKeyMap.compute(readerCacheKeyId, (currentReaderCacheKeyId, count) -> (count == null) ? 1 : count + 1); - return updatedReaderCacheKeyMap; - }); + cleanupKeyToCountMap.computeIfAbsent(shardId, k -> new ConcurrentHashMap<>()) + .merge(readerCacheKeyId, 1, Integer::sum); } /**