Skip to content

Conversation

you06
Copy link
Contributor

@you06 you06 commented Dec 23, 2024

What problem does this PR solve?

Issue Number: close #58405

Problem Summary:

The labels of TiDB are stored within a static structure, meanwhile TiDB have update-label API. Before this PR, the way TiDB handles the mutations of labels have data-race risk.

What changed and how does it work?

Refactor the ServerInfo into static and dynamic sections and fix the data race by atomic operations.

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

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-tests-checked release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 23, 2024
Copy link

tiprow bot commented Dec 23, 2024

Hi @you06. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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.

Copy link

codecov bot commented Dec 23, 2024

Codecov Report

Attention: Patch coverage is 96.20253% with 3 lines in your changes missing coverage. Please review.

Project coverage is 75.0679%. Comparing base (918fcdb) to head (dd0f4e1).
Report is 155 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #58473        +/-   ##
================================================
+ Coverage   73.0774%   75.0679%   +1.9904%     
================================================
  Files          1701       1753        +52     
  Lines        469836     489261     +19425     
================================================
+ Hits         343344     367278     +23934     
+ Misses       105319      99432      -5887     
- Partials      21173      22551      +1378     
Flag Coverage Δ
integration 48.8982% <20.2531%> (?)
unit 72.8059% <96.2025%> (+0.2159%) ⬆️

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

Components Coverage Δ
dumpling ∅ <ø> (∅)
parser ∅ <ø> (∅)
br 60.8374% <ø> (+12.6785%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@you06
Copy link
Contributor Author

you06 commented Dec 25, 2024

/retest

Copy link

tiprow bot commented Dec 25, 2024

@you06: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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.

// which will be changed on occasions such as connection to PD is restored after broken.
ServerIDGetter func() uint64 `json:"-"`
StaticServerInfo
DynamicServerInfo
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems DynamicServerInfo is also static because its value never changes for ServerInfo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's updated in setDynamicServerInfo, which replaces InfoSyncer.info with a new ServerInfo.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it's better to move StaticServerInfo out of atomic.Pointer[ServerInfo]? We can let info become a struct { staticServerInfo, atomic.Pointer[dynamicServerInfo] }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current implementation provides a simpler interface for user, just call getLocalServerInfo to get the entire ServerInfo object.

ServerIDGetter: serverIDGetter,
},
DynamicServerInfo: DynamicServerInfo{
Labels: labels,
Copy link
Collaborator

Choose a reason for hiding this comment

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

seems to use maps.Clone is more elegant here?

Signed-off-by: you06 <[email protected]>

fix lint & update mem after etcd

Signed-off-by: you06 <[email protected]>

wait goroutine quit

Signed-off-by: you06 <[email protected]>

fix update label

Signed-off-by: you06 <[email protected]>

update func name

Signed-off-by: you06 <[email protected]>

remove import

Signed-off-by: you06 <[email protected]>

address comment

Signed-off-by: you06 <[email protected]>

add comments

Signed-off-by: you06 <[email protected]>

bazel

Signed-off-by: you06 <[email protected]>
@you06 you06 force-pushed the fix/update-label-race branch from 47bb12d to c50fa72 Compare March 7, 2025 07:36
Signed-off-by: you06 <[email protected]>
@you06
Copy link
Contributor Author

you06 commented Mar 10, 2025

/retest

Copy link

tiprow bot commented Mar 10, 2025

@you06: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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.

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Mar 12, 2025
@you06
Copy link
Contributor Author

you06 commented Mar 12, 2025

@lance6716, @time-and-fate
This PR has a refactor of server info, and change the tests in some modules, need your approve so, PTAL

Copy link
Member

@YangKeao YangKeao left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Mar 12, 2025
Copy link

ti-chi-bot bot commented Mar 12, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-03-12 04:57:25.813979157 +0000 UTC m=+331801.419508083: ☑️ agreed by lcwangchao.
  • 2025-03-12 05:51:21.044820058 +0000 UTC m=+335036.650348985: ☑️ agreed by YangKeao.

Copy link

ti-chi-bot bot commented Mar 12, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hawkingrei, lance6716, lcwangchao, YangKeao

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

The pull request process is described here

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

@ti-chi-bot ti-chi-bot bot added the approved label Mar 12, 2025
@you06
Copy link
Contributor Author

you06 commented Mar 12, 2025

/retest

Copy link

tiprow bot commented Mar 12, 2025

@you06: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Mar 27, 2025
@ti-chi-bot
Copy link
Member

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

@ti-chi-bot
Copy link
Member

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

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Mar 27, 2025
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Mar 27, 2025
@ti-chi-bot
Copy link
Member

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

you06 added a commit to ti-chi-bot/tidb that referenced this pull request Mar 27, 2025
Signed-off-by: ti-chi-bot <[email protected]>

resolve conflict

Signed-off-by: you06 <[email protected]>
you06 added a commit to ti-chi-bot/tidb that referenced this pull request Mar 27, 2025
Signed-off-by: ti-chi-bot <[email protected]>

Revert "This is an automated cherry-pick of pingcap#58473"

This reverts commit bf5fda5.

resolve conflict

Signed-off-by: you06 <[email protected]>

fix build

Signed-off-by: you06 <[email protected]>
you06 added a commit to ti-chi-bot/tidb that referenced this pull request Mar 27, 2025
Signed-off-by: ti-chi-bot <[email protected]>

Revert "This is an automated cherry-pick of pingcap#58473"

This reverts commit bf5fda5.

resolve conflict

Signed-off-by: you06 <[email protected]>

fix build

Signed-off-by: you06 <[email protected]>

fix test

Signed-off-by: you06 <[email protected]>

fix test

Signed-off-by: you06 <[email protected]>

fix test

Signed-off-by: you06 <[email protected]>
you06 added a commit to ti-chi-bot/tidb that referenced this pull request Mar 27, 2025
you06 added a commit to ti-chi-bot/tidb that referenced this pull request Mar 28, 2025
Signed-off-by: you06 <[email protected]>

enabel race

Signed-off-by: you06 <[email protected]>

fix build

Signed-off-by: you06 <[email protected]>

fix build

Signed-off-by: you06 <[email protected]>

fix test

Signed-off-by: you06 <[email protected]>

fix test

Signed-off-by: you06 <[email protected]>
you06 added a commit to ti-chi-bot/tidb that referenced this pull request Mar 28, 2025
Signed-off-by: you06 <[email protected]>

enabel race

Signed-off-by: you06 <[email protected]>

fix build

Signed-off-by: you06 <[email protected]>

fix build

Signed-off-by: you06 <[email protected]>

fix test

Signed-off-by: you06 <[email protected]>

fix test

Signed-off-by: you06 <[email protected]>

debug

Signed-off-by: you06 <[email protected]>

ensure the test chan is init

Signed-off-by: you06 <[email protected]>

do not test with race mode

Signed-off-by: you06 <[email protected]>
@ti-chi-bot ti-chi-bot bot added needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. and removed needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. labels Apr 9, 2025
@ti-chi-bot
Copy link
Member

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

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Apr 9, 2025
@ti-chi-bot ti-chi-bot bot removed the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Apr 9, 2025
@ti-chi-bot ti-chi-bot bot removed needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. labels Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner 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.

race when updating labels and store topology runs concurrently
6 participants