From 565ee05cda600b8cdb595e56039ad1370510832e Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Thu, 5 Mar 2015 21:41:01 +0100 Subject: [PATCH] [ENGINE] Inc store reference before reading segments info If a tragic even happens while we are reading the segments info from the store the store might have been closed concurrently. We had this behavior before and was lost in a refactoring. --- .../elasticsearch/index/engine/InternalEngine.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/index/engine/InternalEngine.java b/src/main/java/org/elasticsearch/index/engine/InternalEngine.java index acf207f70b3..76ab3e9ce2b 100644 --- a/src/main/java/org/elasticsearch/index/engine/InternalEngine.java +++ b/src/main/java/org/elasticsearch/index/engine/InternalEngine.java @@ -654,8 +654,15 @@ public class InternalEngine extends Engine { } } - // reread the last committed segment infos + /* + * we have to inc-ref the store here since if the engine is closed by a tragic event + * we don't acquire the write lock and wait until we have exclusive access. This might also + * dec the store reference which can essentially close the store and unless we can inc the reference + * we can't use it. + */ + store.incRef(); try { + // reread the last committed segment infos lastCommittedSegmentInfos = store.readLastCommittedSegmentsInfo(); } catch (Throwable e) { if (isClosed.get() == false) { @@ -664,6 +671,8 @@ public class InternalEngine extends Engine { throw new FlushFailedEngineException(shardId, e); } } + } finally { + store.decRef(); } } catch (FlushFailedEngineException ex) { maybeFailEngine("flush", ex);