Skip to content

*: br,lightning,import use meta service group#69780

Open
ystaticy wants to merge 4 commits into
pingcap:masterfrom
ystaticy:msg_br_lighting_import
Open

*: br,lightning,import use meta service group#69780
ystaticy wants to merge 4 commits into
pingcap:masterfrom
ystaticy:msg_br_lighting_import

Conversation

@ystaticy

@ystaticy ystaticy commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: ref #68338

Problem Summary:

What changed and how does it work?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

Summary by CodeRabbit

Summary of updates

  • New Features

    • Improved keyspace-aware etcd connectivity by resolving the correct metadata service group endpoints and applying the appropriate keyspace namespace.
    • TLS-secured etcd dialing is supported during metadata-driven endpoint resolution.
  • Tests

    • Added integration tests covering metadata service group dialing and namespace-correct key placement for backup/restore, Lightning import, and allocator rebase flows.
    • Added regression coverage for etcd client namespace derivation.
  • Chores

    • Updated Bazel build wiring/dependencies and test shard counts to support the new metaservice-backed integration coverage.

Signed-off-by: ystaticy <y_static_y@sina.com>
@ti-chi-bot ti-chi-bot Bot added do-not-merge/needs-linked-issue do-not-merge/needs-tests-checked release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 12, 2026
@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 25277b99-2f2e-4c3a-95aa-23177e644ab6

📥 Commits

Reviewing files that changed from the base of the PR and between 5580cdb and e2058e0.

📒 Files selected for processing (10)
  • br/pkg/task/operator/BUILD.bazel
  • br/pkg/task/operator/crr_checkpoint.go
  • br/pkg/task/operator/crr_checkpoint_test.go
  • lightning/pkg/importer/BUILD.bazel
  • lightning/pkg/importer/import.go
  • lightning/pkg/importer/meta_service_group_test.go
  • pkg/executor/importer/BUILD.bazel
  • pkg/executor/importer/meta_service_group_test.go
  • pkg/executor/importer/table_import.go
  • pkg/metaservice/etcd.go
💤 Files with no reviewable changes (1)
  • lightning/pkg/importer/BUILD.bazel
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/metaservice/etcd.go

📝 Walkthrough

Walkthrough

BR, Lightning, executor importer, and store etcd paths now resolve metaservice endpoints and keyspace namespaces from PD metadata. Shared metaservice APIs centralize this behavior, with integration tests covering namespaced writes.

Changes

Keyspace-aware etcd resolution

Layer / File(s) Summary
Metaservice etcd dial resolution
pkg/metaservice/etcd.go, pkg/metaservice/BUILD.bazel
Adds PD-backed endpoint resolution, keyspace namespace derivation, and centralized etcd client creation.
BR task and operator dialing
br/pkg/task/..., br/pkg/task/operator/...
BR task and CRR checkpoint clients use metaservice dialing and test namespaced writes.
Lightning importer dialing
lightning/pkg/importer/...
Precheck and local-backend flows use PD/keyspace metadata for etcd clients and validate namespaced writes.
Executor allocator dialing
pkg/executor/importer/...
Allocator rebase uses TiKV storage metadata to create a namespaced etcd client.
Store namespace validation
pkg/store/etcd_test.go, pkg/store/BUILD.bazel
Store tests add codec-aware infrastructure and verify metaservice-group namespace placement.

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

Sequence Diagram(s)

sequenceDiagram
  participant Caller as BR or Lightning caller
  participant PD as PD client
  participant Meta as metaservice.DialEtcdClient
  participant Etcd as etcd client
  Caller->>Meta: Request etcd client with keyspace name
  Meta->>PD: Load keyspace metadata and members
  Meta->>Meta: Resolve endpoints and namespace
  Meta-->>Caller: Return configured etcd client
  Caller->>Etcd: Write keyspace-scoped task data
Loading

Possibly related PRs

Suggested labels: component/import

Suggested reviewers: d3hunter, yujuncen, yudongusa, changrui-ryan

Poem

I’m a rabbit with keys in my paw,
Guiding etcd by metadata law.
Through PD paths I hop and roam,
Namespaced writes arrive safely home.
BR and Lightning share the trail!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The template is mostly unfilled: Problem Summary and What changed/how it works are empty, so the PR lacks required context. Fill in Problem Summary and What changed and how it works with a clear description of the issue, the approach, and any notable effects.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and points to the main change: using metaservice group support in BR, Lightning, and Import.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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

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.

🧹 Nitpick comments (1)
pkg/store/etcd_test.go (1)

83-84: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider using metaservice.GroupIDKey and metaservice.GroupAddrsKey constants instead of string literals.

The Lightning test (lightning/pkg/importer/meta_service_group_test.go:64-65) uses the metaservice package constants for these config keys, while this test uses raw string literals. If the constant values ever change, this test would break silently. Using the constants would require adding //pkg/metaservice to the store_test BUILD.bazel deps.

♻️ Optional refactor for consistency
 		Config: map[string]string{
 			"gc_management_type":       "keyspace_level",
-			"meta_service_group_id":    "group1",
-			"meta_service_group_addrs": strings.Join(metaCluster.Client(0).Endpoints(), ","),
+			metaservice.GroupIDKey:     "group1",
+			metaservice.GroupAddrsKey:   strings.Join(metaCluster.Client(0).Endpoints(), ","),
 		}

This would also require adding the import and BUILD.bazel dependency:

+	"github.com/pingcap/tidb/pkg/metaservice"

In pkg/store/BUILD.bazel:

+        "//pkg/metaservice",
🤖 Prompt for 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.

In `@pkg/store/etcd_test.go` around lines 83 - 84, Replace the raw
"meta_service_group_id" and "meta_service_group_addrs" keys in the test
configuration with metaservice.GroupIDKey and metaservice.GroupAddrsKey. Add the
metaservice import and declare the corresponding //pkg/metaservice dependency in
the store_test BUILD.bazel target.
🤖 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.

Nitpick comments:
In `@pkg/store/etcd_test.go`:
- Around line 83-84: Replace the raw "meta_service_group_id" and
"meta_service_group_addrs" keys in the test configuration with
metaservice.GroupIDKey and metaservice.GroupAddrsKey. Add the metaservice import
and declare the corresponding //pkg/metaservice dependency in the store_test
BUILD.bazel target.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1b1a3e6e-bb12-4902-80ab-d18c8dda4ab3

📥 Commits

Reviewing files that changed from the base of the PR and between b94006d and d6df859.

📒 Files selected for processing (10)
  • br/pkg/task/BUILD.bazel
  • br/pkg/task/common.go
  • br/pkg/task/meta_service_group_test.go
  • lightning/pkg/importer/BUILD.bazel
  • lightning/pkg/importer/meta_service_group_test.go
  • lightning/pkg/importer/precheck_impl.go
  • pkg/metaservice/BUILD.bazel
  • pkg/metaservice/etcd.go
  • pkg/store/BUILD.bazel
  • pkg/store/etcd_test.go

@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 28.43137% with 73 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.8433%. Comparing base (b94006d) to head (e2058e0).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #69780        +/-   ##
================================================
- Coverage   76.3194%   75.8433%   -0.4762%     
================================================
  Files          2041       2082        +41     
  Lines        560102     580635     +20533     
================================================
+ Hits         427467     440373     +12906     
- Misses       131734     138133      +6399     
- Partials        901       2129      +1228     
Flag Coverage Δ
integration 45.8291% <28.4313%> (+6.1238%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 60.4471% <ø> (ø)
parser ∅ <ø> (∅)
br 64.0265% <64.2857%> (+1.3052%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

ystaticy added 2 commits July 12, 2026 21:45
Signed-off-by: ystaticy <y_static_y@sina.com>
Signed-off-by: ystaticy <y_static_y@sina.com>

@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: 1

🧹 Nitpick comments (1)
br/pkg/task/common.go (1)

222-222: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider updating the log message to reflect post-connection state.

With grpc.WithBlock() in the dial options, DialEtcdClient blocks until the etcd connection is established. By the time line 222 executes, the connection is already active, so "trying to connect to etcd" is slightly misleading. Consider "connected to etcd" for accuracy.

✏️ Proposed tweak
-	log.Info("trying to connect to etcd", zap.Strings("addr", etcdCLI.Endpoints()))
+	log.Info("connected to etcd", zap.Strings("addr", etcdCLI.Endpoints()))
🤖 Prompt for 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.

In `@br/pkg/task/common.go` at line 222, Update the log message in DialEtcdClient
after the blocking etcd dial to state that the client is connected rather than
still trying to connect, while preserving the existing endpoint fields.
🤖 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/metaservice/etcd.go`:
- Around line 77-126: Update the missing-metadata error in DialEtcdClient to
include the keyspaceName value, while preserving the existing error path and
message meaning.

---

Nitpick comments:
In `@br/pkg/task/common.go`:
- Line 222: Update the log message in DialEtcdClient after the blocking etcd
dial to state that the client is connected rather than still trying to connect,
while preserving the existing endpoint fields.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 78a32d2f-21e3-4bf3-899e-1665759aa001

📥 Commits

Reviewing files that changed from the base of the PR and between d6df859 and 5580cdb.

📒 Files selected for processing (9)
  • br/pkg/task/BUILD.bazel
  • br/pkg/task/common.go
  • br/pkg/task/meta_service_group_test.go
  • lightning/pkg/importer/BUILD.bazel
  • lightning/pkg/importer/meta_service_group_test.go
  • lightning/pkg/importer/precheck_impl.go
  • pkg/metaservice/BUILD.bazel
  • pkg/metaservice/etcd.go
  • pkg/store/etcd_test.go
💤 Files with no reviewable changes (2)
  • lightning/pkg/importer/BUILD.bazel
  • br/pkg/task/BUILD.bazel
🚧 Files skipped from review as they are similar to previous changes (4)
  • lightning/pkg/importer/meta_service_group_test.go
  • br/pkg/task/meta_service_group_test.go
  • pkg/store/etcd_test.go
  • lightning/pkg/importer/precheck_impl.go

Comment thread pkg/metaservice/etcd.go
Comment on lines +77 to +126
// DialEtcdClient resolves the target meta service group and returns a namespaced etcd client.
func DialEtcdClient(
ctx context.Context,
keyspaceName string,
pdAddrs []string,
security pd.SecurityOption,
pdClientFactory PDClientFactory,
callerComponent caller.Component,
pdClientOpts []opt.ClientOption,
etcdCfg clientv3.Config,
) (*clientv3.Client, error) {
if pdClientFactory == nil {
pdClientFactory = pd.NewClientWithAPIContext
}

pdCli, err := pdClientFactory(
ctx, keyspace.BuildAPIContext(keyspaceName), callerComponent, pdAddrs, security, pdClientOpts...,
)
if err != nil {
return nil, err
}
defer pdCli.Close()

var keyspaceMeta *keyspacepb.KeyspaceMeta
if keyspaceName != "" {
keyspaceMeta, err = pdCli.LoadKeyspace(ctx, keyspaceName)
if err != nil {
return nil, err
}
if keyspaceMeta == nil {
return nil, errors.New("keyspace meta not found")
}
}

dialInfo, err := ResolveEtcdDialInfo(ctx, pdCli, keyspaceMeta)
if err != nil {
return nil, err
}

etcdCfg.Context = ctx
etcdCfg.Endpoints = dialInfo.Endpoints
etcdCli, err := clientv3.New(etcdCfg)
if err != nil {
return nil, err
}
if dialInfo.Namespace != "" {
etcd.SetEtcdCliByNamespace(etcdCli, dialInfo.Namespace)
}
return etcdCli, nil
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Include keyspace name in the "not found" error message.

The error at line 107 (errors.New("keyspace meta not found")) is actionable but lacks context — when multiple keyspaces are in play, the operator cannot tell which keyspace failed to resolve. Adding the keyspace name makes triage significantly easier.

🛡️ Proposed fix
 	if keyspaceMeta == nil {
-		return nil, errors.New("keyspace meta not found")
+		return nil, errors.Errorf("keyspace meta not found for keyspace %q", keyspaceName)
 	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// DialEtcdClient resolves the target meta service group and returns a namespaced etcd client.
func DialEtcdClient(
ctx context.Context,
keyspaceName string,
pdAddrs []string,
security pd.SecurityOption,
pdClientFactory PDClientFactory,
callerComponent caller.Component,
pdClientOpts []opt.ClientOption,
etcdCfg clientv3.Config,
) (*clientv3.Client, error) {
if pdClientFactory == nil {
pdClientFactory = pd.NewClientWithAPIContext
}
pdCli, err := pdClientFactory(
ctx, keyspace.BuildAPIContext(keyspaceName), callerComponent, pdAddrs, security, pdClientOpts...,
)
if err != nil {
return nil, err
}
defer pdCli.Close()
var keyspaceMeta *keyspacepb.KeyspaceMeta
if keyspaceName != "" {
keyspaceMeta, err = pdCli.LoadKeyspace(ctx, keyspaceName)
if err != nil {
return nil, err
}
if keyspaceMeta == nil {
return nil, errors.New("keyspace meta not found")
}
}
dialInfo, err := ResolveEtcdDialInfo(ctx, pdCli, keyspaceMeta)
if err != nil {
return nil, err
}
etcdCfg.Context = ctx
etcdCfg.Endpoints = dialInfo.Endpoints
etcdCli, err := clientv3.New(etcdCfg)
if err != nil {
return nil, err
}
if dialInfo.Namespace != "" {
etcd.SetEtcdCliByNamespace(etcdCli, dialInfo.Namespace)
}
return etcdCli, nil
}
if keyspaceMeta == nil {
return nil, errors.Errorf("keyspace meta not found for keyspace %q", keyspaceName)
}
🤖 Prompt for 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.

In `@pkg/metaservice/etcd.go` around lines 77 - 126, Update the missing-metadata
error in DialEtcdClient to include the keyspaceName value, while preserving the
existing error path and message meaning.

@ystaticy

Copy link
Copy Markdown
Contributor Author

/retest-required

Signed-off-by: ystaticy <y_static_y@sina.com>
@ti-chi-bot ti-chi-bot Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jul 13, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

[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 d3hunter, leavrth 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

@ystaticy

Copy link
Copy Markdown
Contributor Author

/retest-required

@ti-chi-bot

ti-chi-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

@ystaticy: 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-unit-test-next-gen e2058e0 link true /test pull-unit-test-next-gen
idc-jenkins-ci-tidb/unit-test e2058e0 link true /test unit-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

release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant