Skip to content

Commit

Permalink
safer
Browse files Browse the repository at this point in the history
  • Loading branch information
original-brownbear committed Oct 29, 2019
1 parent d5e7f27 commit b60b437
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions server/src/main/java/org/elasticsearch/index/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ public void failEngine(String reason, @Nullable Exception failure) {
if (failure != null) {
maybeDie(reason, failure);
}
if (failEngineLock.tryLock() && store.tryIncRef()) {
if (failEngineLock.tryLock()) {
try {
if (failedEngine.get() != null) {
logger.warn(() ->
Expand All @@ -1178,11 +1178,19 @@ public void failEngine(String reason, @Nullable Exception failure) {
// on the same node that we don't see the corrupted marker file when
// the shard is initializing
if (Lucene.isCorruptionException(failure)) {
try {
store.markStoreCorrupted(new IOException("failed engine (reason: [" + reason + "])",
ExceptionsHelper.unwrapCorruption(failure)));
} catch (IOException e) {
logger.warn("Couldn't mark store corrupted", e);
if (store.tryIncRef()) {
try {
store.markStoreCorrupted(new IOException("failed engine (reason: [" + reason + "])",
ExceptionsHelper.unwrapCorruption(failure)));
} catch (IOException e) {
logger.warn("Couldn't mark store corrupted", e);
} finally {
store.decRef();
}
} else {
logger.warn(() ->
new ParameterizedMessage("tried to mark store as corrupted but store is already closed. [{}]", reason),
failure);
}
}
eventListener.onFailedEngine(reason, failure);
Expand All @@ -1191,8 +1199,6 @@ public void failEngine(String reason, @Nullable Exception failure) {
if (failure != null) inner.addSuppressed(failure);
// don't bubble up these exceptions up
logger.warn("failEngine threw exception", inner);
} finally {
store.decRef();
}
} else {
logger.debug(() -> new ParameterizedMessage("tried to fail engine but could not acquire lock - engine should " +
Expand Down

0 comments on commit b60b437

Please sign in to comment.