Skip to content

keyspace: support global safe point v2#10918

Closed
bufferflies wants to merge 2 commits into
tikv:masterfrom
bufferflies:pr-cp-10886-keyspace-gc-v2
Closed

keyspace: support global safe point v2#10918
bufferflies wants to merge 2 commits into
tikv:masterfrom
bufferflies:pr-cp-10886-keyspace-gc-v2

Conversation

@bufferflies

@bufferflies bufferflies commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: Close #10886

CP from 78f39c6.

Original author: @ystaticy.

What is changed and how does it work?

cp GC: support new keyspace enable gc v2 (#287) (#367)

Support enabling global safe point v2 for newly created keyspaces. The keyspace manager persists the global safe point version, carries the value into reserved and newly created keyspace metadata, and reloads the flag when keyspace config changes.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Related changes

  • Need to cherry-pick to the release branch

Validation:

  • GOFLAGS=-buildvcs=false make gotest GOTEST_ARGS='./pkg/keyspace -run TestKeyspaceTestSuite -count=1 -timeout=5m'
  • GOFLAGS=-buildvcs=false make gotest GOTEST_ARGS='./pkg/keyspace ./pkg/storage/endpoint ./server/config ./pkg/gc ./server/cluster -run "TestKeyspaceTestSuite|TestKeyspaceGroupTestSuite|TestNonExistent|TestCollectStorageSize|TestGCStateManager" -count=1 -timeout=5m'
  • git diff --check && git diff --cached --check
  • GOFLAGS=-buildvcs=false make check

Release note

None.

Summary by CodeRabbit

  • New Features

    • Added Global Safe Point V2 support for keyspace management, including persisted global version and automatic keyspace safe-point version injection when enabled.
    • Introduced enable-global-safe-point-v2 configuration flag to activate Global Safe Point V2 support (default: disabled).
  • Bug Fixes

    • Improved error handling for keyspace manager creation, keyspace configuration updates, and configuration reloads to prevent silent failures and ensure consistent behavior.

(cherry picked from commit 78f39c6)
Signed-off-by: bufferflies <1045931706@qq.com>
@ti-chi-bot ti-chi-bot Bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed dco-signoff: yes Indicates the PR's author has signed the dco. labels Jun 22, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign lhy1024, yudongusa for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

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

Details Needs approval from an approver in each of these files:

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

@bufferflies

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@ti-chi-bot ti-chi-bot Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 22, 2026
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a4243978-c88d-4b10-b1b6-85ef18937bed

📥 Commits

Reviewing files that changed from the base of the PR and between 0d4f0c4 and bf2523c.

📒 Files selected for processing (3)
  • pkg/keyspace/keyspace.go
  • server/config/config.go
  • server/server.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • server/config/config.go
  • server/server.go
  • pkg/keyspace/keyspace.go

📝 Walkthrough

Walkthrough

Adds keyspace global safe point v2 support: introduces a new config flag, storage path, and manager-side initialization and update flow. Server startup and reload paths now propagate keyspace config errors. Tests and constructor call sites were updated for the new error returns.

Changes

Keyspace Global Safe Point V2

Layer / File(s) Summary
Config, storage, and path contracts
pkg/keyspace/keyspace.go, server/config/config.go, pkg/utils/keypath/absolute_key_path.go, pkg/storage/endpoint/keyspace.go
Defines safe point version constants and config accessors, adds KeyspaceGlobalSafePointVersionPath(), and extends keyspace storage with global safe point version load/save methods plus endpoint implementations.
Manager initialization and config alignment
pkg/keyspace/keyspace.go
NewKeyspaceManager now returns (*Manager, error) and calls SetGlobalSafePointV2; UpdateConfig now returns error; reserved keyspace initialization and keyspace creation conditionally set SafePointVersion = v2.
Server startup and reload error propagation
server/server.go
Startup, keyspace config updates, and config reload now propagate errors from keyspace manager construction and UpdateConfig.
Constructor updates and v2 keyspace tests
pkg/keyspace/keyspace_test.go, pkg/keyspace/tso_keyspace_group_test.go, pkg/gc/gc_state_manager_test.go, server/cluster/metering_test.go
Mocks and setup paths handle the new constructor error return, and a new test verifies v2 safe point stamping on created keyspaces.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • tikv/pd#10597: Modifies the same NewKeyspaceManager and Manager.UpdateConfig paths, including meta-service-group wiring touched by this change.

Suggested labels

needs-cherry-pick-release-8.5

Suggested reviewers

  • ystaticy
  • lhy1024
  • rleungx

🐇 A v2 flag hops into the hay,
Safe points now remember their stay.
The manager returns with an err in sight,
And keyspaces dress up in versioned light —
A tidy little hop for the day.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. 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 matches the main change: adding global safe point v2 support for keyspace.
Description check ✅ Passed The PR description covers the issue link, change summary, tests, code changes, related changes, and release note.
Linked Issues check ✅ Passed The changes implement #10886 by persisting, propagating, and reloading global safe point v2 in keyspace flows.
Out of Scope Changes check ✅ Passed The edits stay focused on global safe point v2 support and related tests/config wiring, with no obvious unrelated additions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch pr-cp-10886-keyspace-gc-v2

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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/keyspace/keyspace.go`:
- Around line 272-277: The UpdateConfig method in the Manager struct mutates
in-memory state by assigning to manager.config and calling
manager.mgm.updateGroups() before attempting the storage write in
SetGlobalSafePointV2(). If SetGlobalSafePointV2() fails, the method returns an
error but leaves the in-memory state partially modified. To fix this atomically,
reorder the operations so that SetGlobalSafePointV2() is called and checked for
errors first, then only if it succeeds should manager.config be assigned and
manager.mgm.updateGroups() be called. This ensures that if the storage operation
fails, no in-memory state is modified.

In `@server/config/config.go`:
- Around line 886-887: The EnableGlobalSafePointV2 field has a JSON tag with the
`,string` directive which forces it to accept only string-encoded boolean values
like "true" or "false", creating an inconsistency with other boolean fields like
WaitRegionSplit in the same struct that accept plain boolean literals. Remove
the `,string` directive from the json tag of EnableGlobalSafePointV2 to ensure
consistent wire-format handling of boolean types across all config fields in
KeyspaceConfig.

In `@server/server.go`:
- Around line 1219-1221: The UpdateConfig call on keyspaceManager occurs after a
successful Persist operation, creating a non-atomic sequence where Persist can
succeed but UpdateConfig can fail, leaving the caller with an error while the
config is already persisted. Either reorder the calls so UpdateConfig is invoked
before Persist to maintain atomicity, or implement a rollback mechanism that
undoes the Persist operation if UpdateConfig fails afterward.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: aca86e34-bce1-47e7-a497-8669d2da0601

📥 Commits

Reviewing files that changed from the base of the PR and between 4ae1408 and 0d4f0c4.

📒 Files selected for processing (9)
  • pkg/gc/gc_state_manager_test.go
  • pkg/keyspace/keyspace.go
  • pkg/keyspace/keyspace_test.go
  • pkg/keyspace/tso_keyspace_group_test.go
  • pkg/storage/endpoint/keyspace.go
  • pkg/utils/keypath/absolute_key_path.go
  • server/cluster/metering_test.go
  • server/config/config.go
  • server/server.go

Comment thread pkg/keyspace/keyspace.go Outdated
Comment thread server/config/config.go Outdated
Comment thread server/server.go
Address review comments:
- UpdateConfig rolls back in-memory config if SetGlobalSafePointV2 fails.
- SetKeyspaceConfig reverts the persisted config when the post-persist
  keyspace manager update fails, keeping the operation atomic.
- Drop the ,string json directive on enable-global-safe-point-v2 so it
  matches the other bool fields in KeyspaceConfig.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: tongjian <1045931706@qq.com>
@ti-chi-bot

ti-chi-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

@bufferflies: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-check-deps bf2523c link true /test pull-check-deps
pull-unit-test-next-gen-1 bf2523c link true /test pull-unit-test-next-gen-1
pull-build-next-gen bf2523c link true /test pull-build-next-gen
pull-unit-test-next-gen-3 bf2523c link true /test pull-unit-test-next-gen-3
pull-unit-test-next-gen-2 bf2523c link true /test pull-unit-test-next-gen-2
pull-build bf2523c link true /test pull-build
pull-integration-realcluster-test bf2523c link true /test pull-integration-realcluster-test

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

dco-signoff: yes Indicates the PR's author has signed the dco. do-not-merge/needs-triage-completed release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

78f39c6d support new keyspace enable gc v2

2 participants