From aab2c7a4444624eee9babbcdef8c99a3b6c285eb Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Thu, 6 Feb 2014 20:58:57 +0100 Subject: [PATCH] Be paranoid about double release. --- .../elasticsearch/index/engine/internal/InternalEngine.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/index/engine/internal/InternalEngine.java b/src/main/java/org/elasticsearch/index/engine/internal/InternalEngine.java index 88f70c13955..29ab0e9ce2b 100644 --- a/src/main/java/org/elasticsearch/index/engine/internal/InternalEngine.java +++ b/src/main/java/org/elasticsearch/index/engine/internal/InternalEngine.java @@ -32,7 +32,6 @@ import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.IOUtils; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchIllegalStateException; -import org.elasticsearch.Version; import org.elasticsearch.cluster.routing.operation.hash.djb.DjbHashFunction; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Preconditions; @@ -1468,11 +1467,13 @@ public class InternalEngine extends AbstractIndexShardComponent implements Engin private final String source; private final IndexSearcher searcher; private final SearcherManager manager; + private final AtomicBoolean released; private EngineSearcher(String source, IndexSearcher searcher, SearcherManager manager) { this.source = source; this.searcher = searcher; this.manager = manager; + this.released = new AtomicBoolean(false); } @Override @@ -1492,6 +1493,9 @@ public class InternalEngine extends AbstractIndexShardComponent implements Engin @Override public boolean release() throws ElasticsearchException { + if (!released.compareAndSet(false, true)) { + throw new ElasticsearchIllegalStateException("Double release"); + } try { manager.release(searcher); return true;