Skip to content

Commit 04a802a

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 4505aba commit 04a802a

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
@@ -452,6 +452,7 @@ private void innerIndex(Index index) throws IOException {
452452
public void delete(Delete delete) throws EngineException {
453453
try (ReleasableLock _ = readLock.acquire()) {
454454
ensureOpen();
455+
// NOTE: we don't throttle this when merges fall behind because delete-by-id does not create new segments:
455456
innerDelete(delete);
456457
flushNeeded = true;
457458
} catch (OutOfMemoryError | IllegalStateException | IOException t) {
@@ -519,6 +520,19 @@ private void innerDelete(Delete delete) throws IOException {
519520
public void delete(DeleteByQuery delete) throws EngineException {
520521
try (ReleasableLock _ = readLock.acquire()) {
521522
ensureOpen();
523+
if (delete.origin() == Operation.Origin.RECOVERY) {
524+
// Don't throttle recovery operations
525+
innerDelete(delete);
526+
} else {
527+
try (Releasable r = throttle.acquireThrottle()) {
528+
innerDelete(delete);
529+
}
530+
}
531+
}
532+
}
533+
534+
private void innerDelete(DeleteByQuery delete) throws EngineException {
535+
try {
522536
Query query;
523537
if (delete.nested() && delete.aliasFilter() != null) {
524538
query = new IncludeNestedDocsQuery(new XFilteredQuery(delete.query(), delete.aliasFilter()), delete.parentFilter());

0 commit comments

Comments
 (0)