Skip to content

Commit cc0fea8

Browse files
committed
Changes to fix UT
Signed-off-by: Sagar Upadhyaya <[email protected]>
1 parent f66751d commit cc0fea8

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

plugins/cache-ehcache/src/main/java/org/opensearch/cache/store/disk/EhcacheDiskCacheManager.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,18 @@ public static void closeCache(CacheType cacheType, String diskCacheAlias, String
177177
PersistentCacheManager cacheManager = cacheManagerMap.get(cacheType).v1();
178178
try {
179179
lock.lock();
180-
cacheManager.removeCache(diskCacheAlias);
180+
try {
181+
cacheManager.removeCache(diskCacheAlias);
182+
} catch (Exception ex) {
183+
logger.error(() -> new ParameterizedMessage("Exception occurred while trying to close cache: " + diskCacheAlias), ex);
184+
}
185+
// Check again in case a different thread removed it.
186+
if (cacheManagerMap.get(cacheType) == null) {
187+
logger.warn(
188+
() -> new ParameterizedMessage("Trying to close cache for: {} but cache manager does not " + "exist", cacheType)
189+
);
190+
return;
191+
}
181192
int referenceCount = cacheManagerMap.get(cacheType).v2().decrementAndGet();
182193
// All caches have been closed associated with this cache manager, lets close this as well.
183194
if (referenceCount == 0) {
@@ -203,8 +214,6 @@ public static void closeCache(CacheType cacheType, String diskCacheAlias, String
203214
}
204215
cacheManagerMap.remove(cacheType);
205216
}
206-
} catch (Exception ex) {
207-
logger.error(() -> new ParameterizedMessage("Exception occurred while trying to close cache: " + diskCacheAlias), ex);
208217
} finally {
209218
lock.unlock();
210219
}

0 commit comments

Comments
 (0)