[BACKPORT 2025.2][#31220] CDC: Add cleanup_stale_cdc_streams yb-admin command (#32025) - #33598
Open
egladysh wants to merge 1 commit into
Open
[BACKPORT 2025.2][#31220] CDC: Add cleanup_stale_cdc_streams yb-admin command (#32025)#33598egladysh wants to merge 1 commit into
egladysh wants to merge 1 commit into
Conversation
…yb-admin command (yugabyte#32025) ## Summary Adds a `CleanupStaleCDCStreams` RPC to the `MasterReplication` master service and a corresponding `cleanup_stale_cdc_streams` `yb-admin` command. The command scans the `cdc_state` table and identifies stale entries — rows whose CDC stream no longer exists, or whose tablet no longer exists. It supports: - A `dry_run` flag to report stale entries without deleting them. Example (dry run): ``` ./bin/yb-admin \ cleanup_stale_cdc_streams dry-run Found 2 stale cdc_state entries (dry run). tablet_id: 8f3b9b3a8b2c4e2b9c7d6a5f4e3d2c1b, stream_id: 3d9f1e2a4b6c4d8e9f0123456789abcd, table_id: 000033e8000030008000000000004000, table_name: orders, reason: stream not found tablet_id: missing_tablet_id, stream_id: 7a8b9c0d1e2f34567890abcdef123456, reason: tablet not found ``` Implementation notes: - The `cdc_state` table is scanned once and materialized so both the tablet-collection and classification loops share one consistent snapshot. - Tablet table metadata is resolved under a single `SharedLock` before the classification loop to avoid repeated lock acquisitions. - xCluster streams that carry an empty `namespace_id` have their namespace resolved via their first `table_id`. ## Upgrade/Rollback safety The proto change is purely additive: new messages (`CleanupStaleCDCStreamsRequestPB`, `CleanupStaleCDCStreamsResponsePB`) and a new RPC method (`CleanupStaleCDCStreams`) are added to `MasterReplication`. No existing message fields are modified. On a mixed-version cluster, an older master that does not have this RPC will return `UNIMPLEMENTED` when `cleanup_stale_cdc_streams` is invoked; all other CDC and xCluster operations are unaffected. Rolling back removes the `yb-admin` command and the RPC handler. No on-disk state, catalog schema, or gflag defaults are changed. Original commit: c02cbb5 / yugabyte#32025 ## Test plan - [ ] `CDCServiceTest.TestCleanupStaleCDCStreamsWithoutCDCStateTable` — verifies `OBJECT_NOT_FOUND` when the `cdc_state` table does not exist. - [ ] `CDCServiceTest.TestCleanupStaleCDCStreamsDryRunAndDelete` — dry-run returns stale entries without deleting; live run deletes exactly those entries and leaves the valid entry untouched. - [ ] `CDCServiceTest.TestCleanupStaleCDCStreamsNamespaceFilter` — with a namespace filter, only entries attributable to the selected namespace are deleted; cross-namespace and unattributable (both stream and tablet missing) entries are preserved. --------- Co-authored-by: Sumukh-Phalgaonkar <61342752+Sumukh-Phalgaonkar@users.noreply.github.com>
egladysh
requested review from
Sumukh-Phalgaonkar,
asrinivasanyb and
devansh5398
August 28, 2026 19:17
Collaborator
Author
|
Trigger Jenkins |
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.
Summary
Adds a
CleanupStaleCDCStreamsRPC to theMasterReplicationmasterservice and a corresponding
cleanup_stale_cdc_streamsyb-admincommand.
The command scans the
cdc_statetable and identifies stale entries —rows whose CDC stream no longer exists, or whose tablet no longer
exists. It supports:
dry_runflag to report stale entries without deleting them.Example (dry run):
Implementation notes:
cdc_statetable is scanned once and materialized so both thetablet-collection and classification loops share one consistent
snapshot.
SharedLockbeforethe classification loop to avoid repeated lock acquisitions.
namespace_idhave theirnamespace resolved via their first
table_id.Upgrade/Rollback safety
The proto change is purely additive: new messages
(
CleanupStaleCDCStreamsRequestPB,CleanupStaleCDCStreamsResponsePB)and a new RPC method (
CleanupStaleCDCStreams) are added toMasterReplication. No existing message fields are modified.On a mixed-version cluster, an older master that does not have this RPC
will return
UNIMPLEMENTEDwhencleanup_stale_cdc_streamsis invoked;all other CDC and xCluster operations are unaffected.
Rolling back removes the
yb-admincommand and the RPC handler. Noon-disk state, catalog schema, or gflag defaults are changed.
Original commit: c02cbb5 / #32025
Test plan
CDCServiceTest.TestCleanupStaleCDCStreamsWithoutCDCStateTable—verifies
OBJECT_NOT_FOUNDwhen thecdc_statetable does not exist.CDCServiceTest.TestCleanupStaleCDCStreamsDryRunAndDelete—dry-run returns stale entries without deleting; live run deletes exactly
those entries and leaves the valid entry untouched.
CDCServiceTest.TestCleanupStaleCDCStreamsNamespaceFilter— witha namespace filter, only entries attributable to the selected namespace
are deleted; cross-namespace and unattributable (both stream and tablet
missing) entries are preserved.
Co-authored-by: Sumukh-Phalgaonkar 61342752+Sumukh-Phalgaonkar@users.noreply.github.com