From 7230e9634304457c342e63bb10b404ec8c344d80 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Mon, 6 Sep 2021 17:42:12 +0200 Subject: [PATCH] Bugfix --- .../disk/PooledIndexSearcherManager.java | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/main/java/it/cavallium/dbengine/database/disk/PooledIndexSearcherManager.java b/src/main/java/it/cavallium/dbengine/database/disk/PooledIndexSearcherManager.java index e70b773..39a1c70 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/PooledIndexSearcherManager.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/PooledIndexSearcherManager.java @@ -93,17 +93,15 @@ public class PooledIndexSearcherManager { ), indexSearcher -> { try { - //noinspection SynchronizationOnLocalVariableOrMethodParameter - synchronized (indexSearcher) { + // Mark as removed from cache + if (indexSearcher.removeFromCache()) { // Close - if (indexSearcher.removeFromCache()) { - try { - if (snapshot == null) { - searcherManager.release(indexSearcher.getIndexSearcher()); - } - } finally { - activeSearchers.decrementAndGet(); + try { + if (snapshot == null) { + searcherManager.release(indexSearcher.getIndexSearcher()); } + } finally { + activeSearchers.decrementAndGet(); } } } catch (IOException e) { @@ -177,18 +175,15 @@ public class PooledIndexSearcherManager { public Mono releaseUsedIndexSearcher(@Nullable LLSnapshot snapshot, CachedIndexSearcher indexSearcher) { return Mono.fromRunnable(() -> { try { - synchronized (indexSearcher) { - // Decrement reference count - indexSearcher.getIndexReader().decRef(); + // Decrement reference count + if (indexSearcher.decUsage()) { // Close - if (indexSearcher.decUsage()) { - try { - if (snapshot == null) { - searcherManager.release(indexSearcher.getIndexSearcher()); - } - } finally { - activeSearchers.decrementAndGet(); + try { + if (snapshot == null) { + searcherManager.release(indexSearcher.getIndexSearcher()); } + } finally { + activeSearchers.decrementAndGet(); } } } catch (IOException e) {