[core] Delete the output of a discarded compaction instead of leaking it - #9345
Closed
Stephen0421 wants to merge 1 commit into
Closed
[core] Delete the output of a discarded compaction instead of leaking it#9345Stephen0421 wants to merge 1 commit into
Stephen0421 wants to merge 1 commit into
Conversation
The files written by a compaction whose result is never committed were left behind as orphans. FutureTask silently drops the value returned by a task when cancellation wins the race against its completion, so nobody could account for those files, and a task failing halfway lost the output of the steps which had already finished. Compact tasks now accumulate their output, and publishing a finished result is mutually exclusive with declaring it cancelled, so the files are always owned by exactly one side: either the caller learns about them or the task deletes them itself. The cleanup clears the cancellation interrupt while deleting, otherwise the calls of a distributed file system fail immediately and the cleanup silently does nothing.
Stephen0421
force-pushed
the
compact-cancel-orphan
branch
from
August 21, 2026 12:53
1bf8688 to
7a3505c
Compare
Contributor
|
Deleting files is a high-risk operation; simply avoiding their deletion poses no problem at all. |
Contributor
Author
Got it. I will close the pr. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
The files written by a compaction whose result is never committed are left behind as orphan files. There are two ways to lose track of them:
CompactFutureManager#cancelCompactioncancels the future withtaskFuture.cancel(true). When the cancellation wins the race against the completion of the task,FutureTasksilently drops the value returned bycall(). The files of that result are already on disk, but the reference to them is gone, so no caller can account for them.This change makes the ownership of the produced files explicit:
CompactTaskaccumulates its output into a single result, so a partial result of a failed task is still known.FutureTaskdropped it, or the cancellation wins and the task is the one which deletes the files. There is no state in which both sides believe the other one takes care of them.deleteQuietlyonly warns, so the cleanup would silently leave exactly the orphan files it is supposed to remove.The deletion hooks (
CompactRewriter#deleteProducedand thedeleteof the append rewriters) are abstract rather than defaulted to a no-op, so a rewriter which produces files and forgets to implement them is a compile error instead of a runtime leak.Note that only file-side cleanup is performed. In-memory side effects applied during compaction (deletion-vector removals, clustering key-index updates) are not rolled back; the invariant that a cancelled result must not be consumed by the same writer's
prepareCommitis documented onCompactTask#cancel. TodaycancelCompactionis only reachable from writerclose(), where the maintainer is thrown away together with the writer.Tests
New
CompactCancellationTestcovers the discarded-output paths:FutureTaskrace;