Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: fix region stats check #7748

Merged
merged 8 commits into from
Feb 6, 2024
Merged

Conversation

CabinfeverB
Copy link
Member

@CabinfeverB CabinfeverB commented Jan 23, 2024

What problem does this PR solve?

Issue Number: Close #7728

What is changed and how does it work?

  1. isNew is useless because region source is inexact when leader transfer and no sync. Now, no need to hold isNew because saveCache must be true if the region in cache does not have leader.
  2. check whether the region is observed by its own map

Check List

Tests

  • Unit test
  • Manual test (add detailed scripts or steps below)

Code changes

Side effects

  • Possible performance regression
  • Increased code complexity
  • Breaking backward compatibility

Related changes

Release note

None.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Copy link
Contributor

ti-chi-bot bot commented Jan 23, 2024

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • HuSharp
  • rleungx

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

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

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot bot added 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. labels Jan 23, 2024
@CabinfeverB
Copy link
Member Author

/run-check-issue-triage-complete

if origin.GetLeader().GetId() == 0 {
isNew = true
} else if log.GetLevel() <= zap.InfoLevel {
if log.GetLevel() <= zap.InfoLevel {
info("leader changed",
Copy link
Member

Choose a reason for hiding this comment

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

Will it print leader 0?

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Copy link

codecov bot commented Jan 24, 2024

Codecov Report

Merging #7748 (43cc64d) into master (37be34e) will decrease coverage by 0.04%.
Report is 2 commits behind head on master.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7748      +/-   ##
==========================================
- Coverage   73.47%   73.44%   -0.04%     
==========================================
  Files         432      432              
  Lines       47842    47843       +1     
==========================================
- Hits        35151    35136      -15     
- Misses       9648     9666      +18     
+ Partials     3043     3041       -2     
Flag Coverage Δ
unittests 73.44% <100.00%> (-0.04%) ⬇️

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

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@@ -240,10 +250,10 @@ func (r *RegionStatistics) Observe(region *core.RegionInfo, stores []*core.Store
}
}
// Remove the info if any of the conditions are not met any more.
if oldIndex, ok := r.index[regionID]; ok {
deleteIndex = oldIndex &^ peerTypeIndex
if oldIndex, ok := r.index[regionID]; ok && oldIndex > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

for oldIndex > 0

0 for region state feels a bit weird, do you think we need to add a state name to 0? Like notRecord or something.
and maybe better != 0?

Copy link
Member Author

Choose a reason for hiding this comment

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

For bit operations. != doesn't seem to be used very often

@@ -718,19 +724,16 @@ func GenerateRegionGuideFunc(enableLog bool) RegionGuideFunc {
}
// Save to storage if meta is updated.
// Save to cache if meta or leader is updated, or contains any down/pending peer.
// Mark isNew if the region in cache does not have leader.
return func(region, origin *RegionInfo) (isNew, saveKV, saveCache, needSync bool) {
// Now, no need to hold `isNew` because `saveCache` must be true if the region in cache does not have leader.
Copy link
Member

Choose a reason for hiding this comment

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

maybe can move this statement to pr description

Suggested change
// Now, no need to hold `isNew` because `saveCache` must be true if the region in cache does not have leader.

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it. But I think we can keep this comment in code.

Copy link
Member

Choose a reason for hiding this comment

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

Oh 😯 I mean, after your code merged, isNew is a word which doesn't exist and could be confused others.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@ti-chi-bot ti-chi-bot bot added the status/LGT1 Indicates that a PR has LGTM 1. label Feb 1, 2024
@ti-chi-bot ti-chi-bot bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Feb 6, 2024
@CabinfeverB
Copy link
Member Author

/merge

Copy link
Contributor

ti-chi-bot bot commented Feb 6, 2024

@CabinfeverB: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

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 ti-community-infra/tichi repository.

Copy link
Contributor

ti-chi-bot bot commented Feb 6, 2024

This pull request has been accepted and is ready to merge.

Commit hash: cf03d8c

@ti-chi-bot ti-chi-bot bot added the status/can-merge Indicates a PR has been approved by a committer. label Feb 6, 2024
@ti-chi-bot ti-chi-bot bot merged commit cce1464 into tikv:master Feb 6, 2024
25 of 26 checks passed
@ti-chi-bot ti-chi-bot added the needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. label Feb 6, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #7812.

ti-chi-bot pushed a commit to ti-chi-bot/pd that referenced this pull request Feb 6, 2024
close tikv#7728

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
ti-chi-bot bot pushed a commit that referenced this pull request Feb 10, 2024
close #7728

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>

Co-authored-by: Yongbo Jiang <cabinfeveroier@gmail.com>
Co-authored-by: Cabinfever_B <cabinfeveroier@gmail.com>
@ti-chi-bot ti-chi-bot added the needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. label Feb 22, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.1: #7840.

ti-chi-bot pushed a commit to ti-chi-bot/pd that referenced this pull request Feb 22, 2024
close tikv#7728

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
ti-chi-bot bot pushed a commit that referenced this pull request Feb 23, 2024
close #7728

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>

Co-authored-by: Yongbo Jiang <cabinfeveroier@gmail.com>
Co-authored-by: Cabinfever_B <cabinfeveroier@gmail.com>
@CabinfeverB CabinfeverB deleted the fix_stats_region branch February 26, 2024 06:29
rleungx pushed a commit to rleungx/pd that referenced this pull request Feb 27, 2024
@ti-chi-bot ti-chi-bot added the needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. label Mar 25, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.5: #7976.

ti-chi-bot pushed a commit to ti-chi-bot/pd that referenced this pull request Mar 25, 2024
close tikv#7728

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
CabinfeverB added a commit to ti-chi-bot/pd that referenced this pull request Mar 27, 2024
close tikv#7728

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
ti-chi-bot bot pushed a commit that referenced this pull request Mar 27, 2024
close #7728

Signed-off-by: husharp <jinhao.hu@pingcap.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>

Co-authored-by: husharp <jinhao.hu@pingcap.com>
Co-authored-by: Yongbo Jiang <cabinfeveroier@gmail.com>
Co-authored-by: Cabinfever_B <cabinfeveroier@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. 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. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

metrics: The learner-peer-count cannot be restored after PD leader changes
4 participants