Skip to content

Commit 759e269

Browse files
Don't release budget when the merge task goes out of scope
1 parent 92596b0 commit 759e269

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

server/src/main/java/org/elasticsearch/index/engine/ThreadPoolMergeExecutorService.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,12 @@ private boolean enqueueMergeTaskExecution() {
332332
// The merge task is backlogged by the merge scheduler, try to get the next smallest one.
333333
// It's then the duty of the said merge scheduler to re-enqueue the backlogged merge task when
334334
// itself decides that the merge task could be run. Note that it is possible that this merge
335-
// task is re-enqueued and re-took before the budget hold-up here is released below.
335+
// task is re-enqueued and re-took before the budget hold-up here is released upon the next
336+
// {@link PriorityBlockingQueueWithBudget#updateBudget} invocation.
336337
}
337338
} finally {
338-
// releases any budget that is still being allocated for the merge task
339+
// signals that the merge task is not in use anymore, so the budget (i.e. disk space) it's holding so far won't be
340+
// deducted from the total available
339341
smallestMergeTaskWithReleasableBudget.close();
340342
}
341343
}
@@ -645,17 +647,18 @@ private ElementWithReleasableBudget(E element, long budget) {
645647
}
646648

647649
/**
648-
* Must be invoked when the caller is done with the element that it took from the queue.
650+
* Must be invoked when the caller is done with the element that it previously took from the queue.
651+
* The budget it's holding is not immediately released, but the next time {@link #updateBudget(long)}
652+
* is invoked this element's budget won't deduct from the total available.
649653
*/
650654
@Override
651655
public void close() {
652656
final ReentrantLock lock = PriorityBlockingQueueWithBudget.this.lock;
653657
lock.lock();
654658
try {
655659
assert unreleasedBudgetPerElement.containsKey(wrappedElement);
656-
// when the taken element is not used anymore, the budget it holds is released
657-
availableBudget += unreleasedBudgetPerElement.remove(wrappedElement);
658-
elementAvailable.signalAll();
660+
// when the taken element is not used anymore, it will not influence subsequent available budget computations
661+
unreleasedBudgetPerElement.remove(wrappedElement);
659662
} finally {
660663
lock.unlock();
661664
}

0 commit comments

Comments
 (0)