Skip to content

Commit 24d8c74

Browse files
committed
Core: throttle delete-by-query when merges are falling behind
Delete-by-query is incredibly costly because it forces a refresh each time, so if you are also indexing this can cause massive segment explosion. This change throttles delete-by-query when merges can't keep up. It's likely not enough (#7052 is the long-term solution) but can only help. Closes #9986
1 parent 764901a commit 24d8c74

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/main/java/org/elasticsearch/index/engine/InternalEngine.java

+14
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ private void innerIndex(Index index) throws IOException {
440440
public void delete(Delete delete) throws EngineException {
441441
try (ReleasableLock _ = readLock.acquire()) {
442442
ensureOpen();
443+
// NOTE: we don't throttle this when merges fall behind because delete-by-id does not create new segments:
443444
innerDelete(delete);
444445
flushNeeded = true;
445446
} catch (OutOfMemoryError | IllegalStateException | IOException t) {
@@ -507,6 +508,19 @@ private void innerDelete(Delete delete) throws IOException {
507508
public void delete(DeleteByQuery delete) throws EngineException {
508509
try (ReleasableLock _ = readLock.acquire()) {
509510
ensureOpen();
511+
if (delete.origin() == Operation.Origin.RECOVERY) {
512+
// Don't throttle recovery operations
513+
innerDelete(delete);
514+
} else {
515+
try (Releasable r = throttle.acquireThrottle()) {
516+
innerDelete(delete);
517+
}
518+
}
519+
}
520+
}
521+
522+
private void innerDelete(DeleteByQuery delete) throws EngineException {
523+
try {
510524
Query query;
511525
if (delete.nested() && delete.aliasFilter() != null) {
512526
query = new IncludeNestedDocsQuery(new FilteredQuery(delete.query(), delete.aliasFilter()), delete.parentFilter());

0 commit comments

Comments
 (0)