Skip to content

Conversation

okJiang
Copy link
Member

@okJiang okJiang commented Apr 9, 2025

What problem does this PR solve?

Issue Number: Close #9185

What is changed and how does it work?

store: update StoreInfo inside putStoreLocked

Check List

Tests

  • Unit test
  • Integration test

Release note

Fix the bug that StoreInfo may have erroneous overrides.

okJiang added 2 commits April 9, 2025 15:34
Signed-off-by: okJiang <819421878@qq.com>
Signed-off-by: okJiang <819421878@qq.com>
@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-triage-completed release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates the PR's author has signed the dco. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed do-not-merge/needs-triage-completed labels Apr 9, 2025
Signed-off-by: okJiang <819421878@qq.com>
@okJiang
Copy link
Member Author

okJiang commented Apr 9, 2025

/retest

Signed-off-by: okJiang <819421878@qq.com>
Comment on lines 777 to 784
if len(opts) > 0 {
store = s.stores[store.GetID()]
for _, opt := range opts {
opt(store)
}
} else {
s.stores[store.GetID()] = store
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if len(opts) > 0 {
store = s.stores[store.GetID()]
for _, opt := range opts {
opt(store)
}
} else {
s.stores[store.GetID()] = store
}
for _, opt := range opts {
opt(store)
}
s.stores[store.GetID()] = store

Copy link
Member Author

Choose a reason for hiding this comment

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

The internal store may have been modified before calling putStore, so here options are used to directly modify the internal store. If no options are provided, it indicates that the input should be a new store.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe it is better to split this function to Put and Modify


c.PutStore(newStore)
c.hotStat.Observe(storeID, newStore.GetStoreStats())
c.PutStore(store, core.SetStoreStats(stats), core.SetLastHeartbeatTS(time.Now()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add some tests about it?

Copy link
Member Author

Choose a reason for hiding this comment

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

@okJiang
Copy link
Member Author

okJiang commented Apr 10, 2025

/retest

Signed-off-by: okJiang <819421878@qq.com>
@okJiang
Copy link
Member Author

okJiang commented Apr 10, 2025

It seems that we are not allowed to modify the store in StoresInfo directly; instead, we have to clone it, make modifications, and then replace it directly. I think the reason for this is that we read it in too many places, so direct write operations have been prohibited. ref https://github.com/tikv/pd/actions/runs/14354291468/job/40301155373?pr=9187

Signed-off-by: okJiang <819421878@qq.com>
Copy link

codecov bot commented Apr 10, 2025

Codecov Report

Attention: Patch coverage is 95.55556% with 2 lines in your changes missing coverage. Please review.

Project coverage is 75.75%. Comparing base (aa28f66) to head (fc5cf7e).
Report is 24 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9187      +/-   ##
==========================================
- Coverage   75.77%   75.75%   -0.02%     
==========================================
  Files         477      477              
  Lines       73438    73439       +1     
==========================================
- Hits        55644    55634      -10     
- Misses      14320    14329       +9     
- Partials     3474     3476       +2     
Flag Coverage Δ
unittests 75.75% <95.55%> (-0.02%) ⬇️

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Apr 10, 2025
}
if err := c.checkStoreLabels(s); err != nil {
return err
}
return c.setStore(s)
return c.setStore(s, opts...)
Copy link
Member

Choose a reason for hiding this comment

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

clone twice?

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason is here 😂

zap.Bool("physically-destroyed", physicallyDestroyed))
if err := c.setStore(
store.Clone(core.SetStoreState(metapb.StoreState_Offline, physicallyDestroyed)),
core.SetStoreState(metapb.StoreState_Offline, physicallyDestroyed),
Copy link
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is because setStore may save meta to storage, so we need keep them latest.

image

err := c.setStore(newStore)
err := c.setStore(
store.Clone(core.SetStoreState(metapb.StoreState_Tombstone)),
core.SetStoreState(metapb.StoreState_Tombstone),
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@ti-chi-bot ti-chi-bot bot added the lgtm label Apr 14, 2025
Copy link
Contributor

ti-chi-bot bot commented Apr 14, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lhy1024, rleungx

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 removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Apr 14, 2025
Copy link
Contributor

ti-chi-bot bot commented Apr 14, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-04-10 07:11:52.118457248 +0000 UTC m=+2326805.802693341: ☑️ agreed by lhy1024.
  • 2025-04-14 03:39:15.762465003 +0000 UTC m=+2659649.446701084: ☑️ agreed by rleungx.

@ti-chi-bot ti-chi-bot bot merged commit a16b000 into tikv:master Apr 14, 2025
25 checks passed
@ti-chi-bot ti-chi-bot bot added needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. labels Apr 24, 2025
@ti-chi-bot ti-chi-bot bot added needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. labels Apr 24, 2025
ti-chi-bot pushed a commit to ti-chi-bot/pd that referenced this pull request Apr 24, 2025
close tikv#9185

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #9251.
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-8.1: #9252.
But this PR has conflicts, please resolve them!

ti-chi-bot pushed a commit to ti-chi-bot/pd that referenced this pull request Apr 24, 2025
close tikv#9185

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

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

ti-chi-bot pushed a commit to ti-chi-bot/pd that referenced this pull request Apr 24, 2025
close tikv#9185

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
ti-chi-bot pushed a commit to ti-chi-bot/pd that referenced this pull request Apr 24, 2025
close tikv#9185

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

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

ti-chi-bot pushed a commit to ti-chi-bot/pd that referenced this pull request Apr 24, 2025
close tikv#9185

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

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

@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 24, 2025
ti-chi-bot bot pushed a commit that referenced this pull request Apr 25, 2025
close #9185

store: update StoreInfo inside putStoreLocked

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
Signed-off-by: okJiang <819421878@qq.com>

Co-authored-by: okJiang <819421878@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved dco-signoff: yes Indicates the PR's author has signed the dco. lgtm needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

the leader of one tikv can not move back after tikv rolling restart
4 participants