Skip to content

schemastore: clean up tombstone keyspace store - #6159

Merged
ti-chi-bot[bot] merged 4 commits into
pingcap:masterfrom
asddongmen:fix-tombstone-keyspace-gc-keeper
Sep 12, 2026
Merged

ti-chi-bot[bot] merged 4 commits into
pingcap:masterfrom
asddongmen:fix-tombstone-keyspace-gc-keeper

Conversation

@asddongmen

@asddongmen asddongmen commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

What problem does this PR solve?

Issue Number: close #6156

After PD tombstones a keyspace, each TiCDC node that registered it keeps the per-keyspace schema store alive. Its GC keeper retries the rejected safepoint update every two minutes, while the DDL subscription and other periodic schema-store tasks also remain active until process shutdown.

What is changed and how it works?

After a NextGen safepoint refresh fails, the keeper loads authoritative keyspace metadata from PD. If PD confirms the irreversible TOMBSTONE state, the schema store:

  • removes the exact store instance from keyspaceSchemaStoreMap and records the terminal keyspace ID to prevent lazy re-registration;
  • cancels the per-keyspace context and unblocks resolved-ts waiters;
  • drains active schema-store API calls and the resolved-ts apply goroutine;
  • unsubscribes the keyspace DDL spans and closes persistent storage.

The terminal lifecycle event is logged once. Successful refreshes add no PD request. Enabled keyspaces, temporary refresh failures, and metadata lookup failures keep the existing retry behavior.

Check List

Tests

  • Unit test
    • NextGen and classic schema-store lifecycle/GC-keeper tests
    • NextGen TOMBSTONE lifecycle tests with the race detector

Questions

Will it cause performance regression or break compatibility?

No. The additional PD metadata request and teardown occur only after a failed NextGen safepoint refresh. Healthy refreshes and classic behavior are unchanged.

Do you need to update user documentation, design documentation or monitoring documentation?

No. This fixes an internal lifecycle error path without changing user-facing APIs or configuration.

Release note

Fix TiCDC retaining schema-store tasks and repeatedly refreshing the GC safepoint after a keyspace becomes tombstone.

Summary by CodeRabbit

  • Bug Fixes
    • Schema stores now stop refreshing safepoints when a keyspace is tombstoned.
    • Tombstoned keyspaces are no longer recreated after shutdown.
    • Schema-store operations now terminate promptly when their context is canceled.
    • Shutdown waits for active operations and background processing before releasing storage.
    • DDL subscriptions are cleaned up when a schema store closes.
    • Temporary refresh failures continue to be handled without unnecessarily stopping processing.

@ti-chi-bot ti-chi-bot Bot added needs-cherry-pick-release-nextgen-202603 Should cherry pick this PR to release-nextgen-202603 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 3, 2026
@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 12254912-c087-4f94-b17a-2106009dbc10

📥 Commits

Reviewing files that changed from the base of the PR and between 40dbd02 and 6a1cb55.

📒 Files selected for processing (4)
  • logservice/schemastore/ddl_job_fetcher.go
  • logservice/schemastore/gc_keeper.go
  • logservice/schemastore/schema_store.go
  • logservice/schemastore/schema_store_test.go

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The schema store now stops GC refreshes for tombstoned keyspaces and removes their stores through synchronized cleanup. API access, background workers, DDL subscriptions, and persistent storage follow the store lifecycle.

Changes

Tombstoned keyspace lifecycle

Layer / File(s) Summary
Tombstone-aware GC refresh
logservice/schemastore/gc_keeper.go, logservice/schemastore/gc_keeper_test.go
The keeper checks PD state after refresh failures and stops for non-classic TOMBSTONE keyspaces. Tests cover successful refreshes, tombstones, temporary errors, and lookup failures.
Synchronized schema store shutdown
logservice/schemastore/schema_store.go, logservice/schemastore/ddl_job_fetcher.go
The store tracks active calls and workers, cancels operations, unsubscribes DDL jobs, waits for completion, and closes persistent storage.
Tombstone registry and API guards
logservice/schemastore/schema_store.go
The store records removed keyspaces as tombstones, rejects later registration, and uses lifecycle locks during API access and cleanup.
Cleanup validation
logservice/schemastore/schema_store_test.go
Tests verify that cleanup waits for active users and closes subscriptions, context, and Pebble storage.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Severity of issue fixed: Medium

Suggested reviewers: lidezhu, 3aceshowhand, tenfyzhong

Merge Risk: ⚪ Minimal · up to ff3ae

The change cleans up tombstoned keyspace schema stores while preserving retry behavior, with lifecycle cleanup covered by tests. No merge-blocking risk is currently established.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: cleaning up the schema store for a tombstoned keyspace.
Description check ✅ Passed The description includes the required issue reference, problem statement, implementation details, tests, compatibility assessment, documentation assessment, and release note.
Linked Issues check ✅ Passed The changes address issue #6156 by stopping GC safepoint retries after PD confirms TOMBSTONE, removing and tombstoning the store, canceling its lifecycle, unsubscribing DDL spans, closing storage, and…
Out of Scope Changes check ✅ Passed The modified implementation and tests are directly related to tombstoned keyspace cleanup, GC keeper shutdown, schema-store lifecycle management, and verification of those behaviors. No unrelated chan…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit reads each line,
The patch grows clear beneath the moon,
Small changes hop in place,
Tests guard the garden path,
Reviews bloom before the dawn.

Comment @coderabbitai help to get the list of available commands.

@ti-chi-bot ti-chi-bot Bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Sep 3, 2026
@asddongmen asddongmen added the hold This pull request is not ready to merge. label Sep 3, 2026
@ti-chi-bot

ti-chi-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 3AceShowHand, lidezhu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [3AceShowHand,lidezhu]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Sep 4, 2026
@ti-chi-bot

ti-chi-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

[LGTM Timeline notifier]

Timeline:

  • 2026-09-03 07:34:16.289044937 +0000 UTC m=+1351091.460139050: ☑️ agreed by lidezhu.
  • 2026-09-04 09:10:42.266935705 +0000 UTC m=+1443277.438029820: ☑️ agreed by 3AceShowHand.

@ti-chi-bot ti-chi-bot Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 8, 2026
@asddongmen asddongmen changed the title schemastore: stop GC keeper for tombstone keyspace schemastore: clean up tombstone keyspace store Sep 8, 2026
@asddongmen

Copy link
Copy Markdown
Collaborator Author

/retest

@asddongmen

Copy link
Copy Markdown
Collaborator Author

/test all

@asddongmen

Copy link
Copy Markdown
Collaborator Author

/retest

@asddongmen asddongmen removed the hold This pull request is not ready to merge. label Sep 9, 2026
@asddongmen

Copy link
Copy Markdown
Collaborator Author

/retest

@asddongmen

Copy link
Copy Markdown
Collaborator Author

/retest

@ti-chi-bot
ti-chi-bot Bot merged commit fe2ecad into pingcap:master Sep 12, 2026
40 checks passed
@ti-chi-bot

Copy link
Copy Markdown
Member

In response to a cherrypick label: new pull request created to branch release-nextgen-202603: #6231.
But this PR has conflicts, please resolve them!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm needs-cherry-pick-release-nextgen-202603 Should cherry pick this PR to release-nextgen-202603 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

schemastore: stop GC keeper after keyspace becomes tombstone

4 participants