Skip to content

Commit 5ce6331

Browse files
authored
Abort pending deletion on IndicesService stop (elastic#123569) (elastic#123669)
When IndicesService is closed, the pending deletion may still be in progress due to indices removed before IndicesService gets closed. If the deletion stucks for some reason, it can stall the node shutdown. This PR aborts the pending deletion more promptly by not retry after IndicesService is stopped. Resolves: elastic#121717 Resolves: elastic#121716 Resolves: elastic#122119 (cherry picked from commit c7e7dbe) # Conflicts: # muted-tests.yml
1 parent 5583d73 commit 5ce6331

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

docs/changelog/123569.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 123569
2+
summary: Abort pending deletion on `IndicesService` close
3+
area: Store
4+
type: enhancement
5+
issues: []

server/src/main/java/org/elasticsearch/indices/IndicesService.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ public class IndicesService extends AbstractLifecycleComponent
251251
private final Map<String, IndexStorePlugin.RecoveryStateFactory> recoveryStateFactories;
252252
private final IndexStorePlugin.IndexFoldersDeletionListener indexFoldersDeletionListeners;
253253
final AbstractRefCounted indicesRefCount; // pkg-private for testing
254+
private final CountDownLatch stopLatch = new CountDownLatch(1);
254255
private final CountDownLatch closeLatch = new CountDownLatch(1);
255256
private volatile boolean idFieldDataEnabled;
256257
private volatile boolean allowExpensiveQueries;
@@ -397,6 +398,7 @@ public ClusterService clusterService() {
397398

398399
@Override
399400
protected void doStop() {
401+
stopLatch.countDown();
400402
clusterService.removeApplier(timestampFieldMapperService);
401403
timestampFieldMapperService.doStop();
402404

@@ -1414,7 +1416,15 @@ public void processPendingDeletes(Index index, IndexSettings indexSettings, Time
14141416
}
14151417
if (remove.isEmpty() == false) {
14161418
logger.warn("{} still pending deletes present for shards {} - retrying", index, remove.toString());
1417-
Thread.sleep(sleepTime);
1419+
if (stopLatch.await(sleepTime, TimeUnit.MILLISECONDS)) {
1420+
logger.info(
1421+
"Indices service stopped. {} aborting pending deletes after [{}] for shards {}",
1422+
index,
1423+
TimeValue.timeValueNanos(System.nanoTime() - startTimeNS),
1424+
remove.toString()
1425+
);
1426+
break;
1427+
}
14181428
sleepTime = Math.min(maxSleepTimeMs, sleepTime * 2); // increase the sleep time gradually
14191429
logger.debug("{} schedule pending delete retry after {} ms", index, sleepTime);
14201430
}

0 commit comments

Comments
 (0)