@@ -1157,7 +1157,6 @@ public void failEngine(String reason, @Nullable Exception failure) {
1157
1157
maybeDie (reason , failure );
1158
1158
}
1159
1159
if (failEngineLock .tryLock ()) {
1160
- store .incRef ();
1161
1160
try {
1162
1161
if (failedEngine .get () != null ) {
1163
1162
logger .warn (() ->
@@ -1179,11 +1178,19 @@ public void failEngine(String reason, @Nullable Exception failure) {
1179
1178
// on the same node that we don't see the corrupted marker file when
1180
1179
// the shard is initializing
1181
1180
if (Lucene .isCorruptionException (failure )) {
1182
- try {
1183
- store .markStoreCorrupted (new IOException ("failed engine (reason: [" + reason + "])" ,
1184
- ExceptionsHelper .unwrapCorruption (failure )));
1185
- } catch (IOException e ) {
1186
- logger .warn ("Couldn't mark store corrupted" , e );
1181
+ if (store .tryIncRef ()) {
1182
+ try {
1183
+ store .markStoreCorrupted (new IOException ("failed engine (reason: [" + reason + "])" ,
1184
+ ExceptionsHelper .unwrapCorruption (failure )));
1185
+ } catch (IOException e ) {
1186
+ logger .warn ("Couldn't mark store corrupted" , e );
1187
+ } finally {
1188
+ store .decRef ();
1189
+ }
1190
+ } else {
1191
+ logger .warn (() ->
1192
+ new ParameterizedMessage ("tried to mark store as corrupted but store is already closed. [{}]" , reason ),
1193
+ failure );
1187
1194
}
1188
1195
}
1189
1196
eventListener .onFailedEngine (reason , failure );
@@ -1192,8 +1199,6 @@ public void failEngine(String reason, @Nullable Exception failure) {
1192
1199
if (failure != null ) inner .addSuppressed (failure );
1193
1200
// don't bubble up these exceptions up
1194
1201
logger .warn ("failEngine threw exception" , inner );
1195
- } finally {
1196
- store .decRef ();
1197
1202
}
1198
1203
} else {
1199
1204
logger .debug (() -> new ParameterizedMessage ("tried to fail engine but could not acquire lock - engine should " +
0 commit comments