-
Notifications
You must be signed in to change notification settings - Fork 728
#7896 Fix zombie replication slot issue by canceling the underlying rebalance job on wait cancellation #7945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
m3hm3t
wants to merge
11
commits into
main
Choose a base branch
from
m3hm3t/issue_7896
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Codecov ReportAttention: Patch coverage is
❌ Your patch check has failed because the patch coverage (51.72%) is below the target coverage (75.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #7945 +/- ##
==========================================
- Coverage 89.18% 89.16% -0.03%
==========================================
Files 283 283
Lines 61023 61055 +32
Branches 7618 7626 +8
==========================================
+ Hits 54422 54437 +15
- Misses 4416 4436 +20
+ Partials 2185 2182 -3 🚀 New features to boost your workflow:
|
…oved clarity and maintainability
…t_min_messages settings for improved clarity
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.
This PR fixes #7896 a robustness bug in Citus where canceling the coordinator-side call to
citus_rebalance_wait()
(via a short statement timeout, Ctrl+C, or closing the session) does not cancel the underlying background rebalance operation. As a result, the background job continues running and leaves behind a “zombie” logical replication slot on a worker node. This active replication slot prevents subsequent operations (for example,DROP DATABASE WITH (force)
) from succeeding on the worker node.Background
When a rebalance is initiated using
citus_rebalance_start(..., shard_transfer_mode => 'force_logical')
, the background job creates a temporary logical replication slot on a source worker. If the coordinator-side wait is canceled (for example, due to a statement timeout), the background job is left running, and its replication slot remains active. This results in an inability to drop the database on the worker because PostgreSQL does not allow dropping a database that is in use by an active replication slot.Description of the Fix
This PR modifies the internal wait function (
citus_job_wait_internal
) as follows:PG_TRY/PG_CATCH Wrapping:
The polling loop inside
citus_job_wait_internal
is now wrapped in aPG_TRY
block. If the wait is canceled (e.g., by a timeout or Ctrl+C), the exception is caught in aPG_CATCH
block.Cancelling the Background Job:
In the
PG_CATCH
block, we now call the existing cancellation function (i.e.citus_job_cancel
) to mark the background rebalance job as canceled. This makes sure the background worker notices the canceled state and cleans up its temporary replication slot.Re-Throwing the Exception:
The original error (e.g., "canceling statement due to statement timeout") is rethrown via
PG_RE_THROW()
, so that users still receive the expected error message while ensuring that the underlying job is properly canceled.Impact and Verification
Correctness:
With this fix applied, if
citus_rebalance_wait()
is canceled, the underlying background job is also canceled. This prevents zombie replication slots from remaining on the worker nodes, thereby allowing operations likeDROP DATABASE WITH (force)
to succeed.Verification:
A new regression test has been added (see below) that:
pg_replication_slots
—in the fixed system, no active replication slot should be left.Main Branch Behavior
In the current main branch, the approach is somewhat flaky—sometimes an active replication slot remains even after canceling the wait. For example:
In the main branch you may still see an active replication slot on one of the workers (e.g., on worker_1), which then blocks DROP DATABASE on that node. With this fix, the cancellation should remove that zombie slot consistently.