Skip to content

feat: cancel local compaction for enter staging#7885

Draft
WenyXu wants to merge 1 commit intoGreptimeTeam:mainfrom
WenyXu:feat/compaction-cancel
Draft

feat: cancel local compaction for enter staging#7885
WenyXu wants to merge 1 commit intoGreptimeTeam:mainfrom
WenyXu:feat/compaction-cancel

Conversation

@WenyXu
Copy link
Copy Markdown
Member

@WenyXu WenyXu commented Mar 30, 2026

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

What's changed and what's your intention?

PR Checklist

Please convert it to a draft if some of the following conditions are not met.

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.
  • API changes are backward compatible.
  • Schema or data changes are backward compatible.

@github-actions github-actions bot added size/L docs-not-required This change does not impact docs. labels Mar 30, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements cooperative cancellation for local compaction tasks in the mito2 engine, allowing EnterStaging requests to preempt running compactions instead of waiting in the pending queue. The changes introduce task ID tracking in the CompactionScheduler, add cancellation checkpoints within the compaction runner, and update the worker loop to handle cancellation notifications. Feedback identifies a critical issue in the on_compaction_cancelled logic where waiters of a cancelled task might hang if a pending compaction is immediately scheduled without notifying them first.

Comment on lines +390 to +399
if self
.handle_pending_compaction_request(
region_id,
manifest_ctx,
schema_metadata_manager.clone(),
)
.await
{
return Vec::new();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to on_compaction_finished, if there are no pending DDLs and a pending compaction is scheduled, the waiters for the cancelled compaction are not notified. This will cause the waiters to hang.

You should notify the waiters before handling the pending compaction.

Suggested change
if self
.handle_pending_compaction_request(
region_id,
manifest_ctx,
schema_metadata_manager.clone(),
)
.await
{
return Vec::new();
}
if status.pending_request.is_some() {
// The current compaction task is cancelled. We must notify its waiters.
finish_compaction_waiters(std::mem::take(&mut status.waiters));
if self
.handle_pending_compaction_request(
region_id,
manifest_ctx,
schema_metadata_manager.clone(),
)
.await
{
// A new compaction is scheduled. Pending DDLs (if any) will wait for it.
return Vec::new();
}
}

Signed-off-by: WenyXu <wenymedia@gmail.com>
@WenyXu WenyXu force-pushed the feat/compaction-cancel branch from f50f9d4 to 0a60db0 Compare March 30, 2026 09:24
@github-actions github-actions bot added size/M and removed size/L labels Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-not-required This change does not impact docs. size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant