Skip to content

Commit

Permalink
Update ehcache disk cache close() logic
Browse files Browse the repository at this point in the history
Signed-off-by: Sagar Upadhyaya <sagar.upadhyaya.121@gmail.com>
  • Loading branch information
sgup432 committed Jul 17, 2024
1 parent 925bd8d commit 4a666bb
Showing 1 changed file with 1 addition and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,23 +463,11 @@ public void refresh() {
@Override
@SuppressForbidden(reason = "Ehcache uses File.io")
public void close() {
// We are calling each of below function in its own try/catch block so that we still try to close the cache
// manager in case removeCache failed (for example)
try {
cacheManager.removeCache(this.diskCacheAlias);
} catch (Exception e) {
logger.error(() -> new ParameterizedMessage("Exception occurred while trying to remove cache from manager"), e);
}
try {
cacheManager.close();
} catch (Exception e) {
logger.error(() -> new ParameterizedMessage("Exception occurred while trying to close ehcache manager"), e);
}
try {
cacheManager.destroyCache(this.diskCacheAlias);
} catch (Exception e) {
logger.error(() -> new ParameterizedMessage("Exception occurred while trying to destroy cache and associated data"), e);
}
// Delete all the disk cache related files/data in case it is present
Path ehcacheDirectory = Paths.get(this.storagePath);
if (Files.exists(ehcacheDirectory)) {
Expand All @@ -489,6 +477,7 @@ public void close() {
logger.error(() -> new ParameterizedMessage("Failed to delete ehcache disk cache data under path: {}", this.storagePath));

Check warning on line 477 in plugins/cache-ehcache/src/main/java/org/opensearch/cache/store/disk/EhcacheDiskCache.java

View check run for this annotation

Codecov / codecov/patch

plugins/cache-ehcache/src/main/java/org/opensearch/cache/store/disk/EhcacheDiskCache.java#L476-L477

Added lines #L476 - L477 were not covered by tests
}
}

}

/**
Expand Down

0 comments on commit 4a666bb

Please sign in to comment.