[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.
This commit is contained in:
Simon Willnauer 2015-03-05 21:41:01 +01:00
parent 274da68040
commit 565ee05cda
1 changed files with 10 additions and 1 deletions

View File

@ -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);