From 3a76ffc9464eafc073b69fbe56b179c4c3077444 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Fri, 15 Jan 2021 13:42:28 +0100 Subject: [PATCH] Add assertion message when decrementing cache file (#67561) (#67567) --- .../index/store/cache/CacheFile.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/index/store/cache/CacheFile.java b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/index/store/cache/CacheFile.java index 5793f4d33c5b3..6d84fd72d23f2 100644 --- a/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/index/store/cache/CacheFile.java +++ b/x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/index/store/cache/CacheFile.java @@ -228,7 +228,21 @@ private boolean assertNoPendingListeners() { private void decrementRefCount() { final boolean released = refCounter.decRef(); - assert released == false || (evicted.get() && Files.notExists(file)); + assert assertRefCounted(released); + } + + private boolean assertRefCounted(boolean isReleased) { + final boolean isEvicted = evicted.get(); + final boolean notExists = Files.notExists(file); + assert isReleased == false || (isEvicted && notExists) : "fully released cache file should be deleted from disk but got [" + + "released=" + + isReleased + + ", evicted=" + + isEvicted + + ", file not exists=" + + notExists + + ']'; + return true; } /** @@ -487,7 +501,7 @@ public SortedSet> fsync() throws IOException { } } } finally { - refCounter.decRef(); + decrementRefCount(); } } else { assert evicted.get();