Skip to content

Commit

Permalink
close if failed to install reference
Browse files Browse the repository at this point in the history
  • Loading branch information
dnhatn committed Aug 14, 2019
1 parent 6816960 commit 67badc6
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions server/src/main/java/org/elasticsearch/index/shard/IndexShard.java
Original file line number Diff line number Diff line change
Expand Up @@ -1606,21 +1606,19 @@ private void innerOpenEngineAndTranslog(LongSupplier globalCheckpointSupplier) t
synchronized (engineMutex) {
// we must create a new engine under mutex (see IndexShard#snapshotStoreMetadata).
final Engine newEngine = engineFactory.newReadWriteEngine(config);
boolean success = false;
try {
synchronized (mutex) {
synchronized (mutex) {
try {
verifyNotClosed();
assert currentEngineReference.get() == null : "engine is running";
onNewEngine(newEngine);
currentEngineReference.set(newEngine);
// We set active because we are now writing operations to the engine; this way,
// if we go idle after some time and become inactive, we still give sync'd flush a chance to run.
active.set(true);
success = true;
}
} finally {
if (success == false) {
newEngine.close();
} finally {
if (currentEngineReference.get() != newEngine) {
newEngine.close();
}
}
}
}
Expand Down Expand Up @@ -3372,16 +3370,14 @@ public void close() throws IOException {
IOUtils.close(super::close, newEngine);
}
};
boolean success = false;
try {
synchronized (mutex) {
synchronized (mutex) {
try {
verifyNotClosed();
IOUtils.close(currentEngineReference.getAndSet(readOnlyEngine));
success = true;
}
} finally {
if (success == false) {
readOnlyEngine.close();
} finally {
if (currentEngineReference.get() != readOnlyEngine) {
readOnlyEngine.close();
}
}
}
newEngineReference.set(engineFactory.newReadWriteEngine(newEngineConfig(replicationTracker)));
Expand Down

0 comments on commit 67badc6

Please sign in to comment.