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

Fast evict leader #4091

Merged
merged 16 commits into from Aug 25, 2021
Merged

Fast evict leader #4091

merged 16 commits into from Aug 25, 2021

Conversation

mianhk
Copy link
Contributor

@mianhk mianhk commented Jul 23, 2021

What problem does this PR solve?

Close #3902
Ref: #3918

What is changed and how does it work?

Code changes

  • Has Go code change
  • Has CI related scripts change

Tests

  • Unit test
  • E2E test
  • Manual test
  • No code

Side effects

  • Breaking backward compatibility
  • Other side effects:

Related changes

  • Need to cherry-pick to the release branch
  • Need to update the documentation

Release Notes

Please refer to Release Notes Language Style Guide before writing the release note.

Fast upgrade TiKV when tikv replicas number are less than 2

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Jul 23, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • DanielZhangQD
  • csuzhangxc

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.

@CLAassistant
Copy link

CLAassistant commented Jul 23, 2021

CLA assistant check
All committers have signed the CLA.

@codecov-commenter
Copy link

codecov-commenter commented Jul 23, 2021

Codecov Report

Merging #4091 (8e775bd) into master (f8224ad) will increase coverage by 1.87%.
The diff coverage is 62.50%.

@@            Coverage Diff             @@
##           master    #4091      +/-   ##
==========================================
+ Coverage   61.19%   63.06%   +1.87%     
==========================================
  Files         178      182       +4     
  Lines       18913    21219    +2306     
==========================================
+ Hits        11573    13381    +1808     
- Misses       6198     6593     +395     
- Partials     1142     1245     +103     
Flag Coverage Δ
e2e 31.30% <62.50%> (?)
unittest 61.18% <62.50%> (-0.01%) ⬇️

@DanielZhangQD
Copy link
Contributor

/run-all-tests

@@ -149,6 +149,12 @@ func (u *tikvUpgrader) Upgrade(meta metav1.Object, oldSet *apps.StatefulSet, new
return nil
}

if len(podOrdinals) < 2 {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about moving the check to L79 and just check the *oldSet.Spec.Replicas?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, not clear for meam of the partition of statefulset before.

@@ -203,6 +209,7 @@ func (u *tikvUpgrader) readyToUpgrade(upgradePod *corev1.Pod, tc *v1alpha1.TidbC
}

tlsEnabled := tc.IsTLSClusterEnabled()

Copy link
Contributor

Choose a reason for hiding this comment

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

No need to update this.

name := payload.pod.Name
namespace := payload.pod.Namespace
tc, ok := payload.controller.(*v1alpha1.TidbCluster)
if !ok {
err := fmt.Errorf("tikv pod[%s/%s]'s controller is not a tidbcluster", namespace, name)
return util.ARFail(err)
}

if tc.TiKVStsActualReplicas() < 2 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should use TiKVStsDesiredReplicas?

@@ -205,7 +211,7 @@ func (pc *PodAdmissionControl) admitDeleteUpTiKVPodDuringUpgrading(payload *admi
}
}

if !isTiKVReadyToUpgrade(payload.pod, store, tc.TiKVEvictLeaderTimeout()) {
if !isTiKVReadyToUpgrade(payload.pod, store, stores, tc.TiKVEvictLeaderTimeout()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to update this, right?

@DanielZhangQD DanielZhangQD mentioned this pull request Jul 26, 2021
10 tasks
Comment on lines 81 to 82
klog.Infof("TiKV statefulset replicas are less than 2, skip waiting to evict region leader for tc %s/%s", ns, tcName)
setUpgradePartition(newSet, *oldSet.Spec.UpdateStrategy.RollingUpdate.Partition)
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
klog.Infof("TiKV statefulset replicas are less than 2, skip waiting to evict region leader for tc %s/%s", ns, tcName)
setUpgradePartition(newSet, *oldSet.Spec.UpdateStrategy.RollingUpdate.Partition)
klog.Infof("TiKV statefulset replicas are less than 2, skip evicting region leader for tc %s/%s", ns, tcName)
setUpgradePartition(newSet, 0)

oldSet.Status.CurrentReplicas = 1
oldSet.Status.UpdatedReplicas = 1
oldSet.Spec.Replicas = pointer.Int32Ptr(1)
oldSet.Spec.UpdateStrategy.RollingUpdate.Partition = pointer.Int32Ptr(0)
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
oldSet.Spec.UpdateStrategy.RollingUpdate.Partition = pointer.Int32Ptr(0)
oldSet.Spec.UpdateStrategy.RollingUpdate.Partition = pointer.Int32Ptr(2)

@@ -190,6 +190,12 @@ func (pc *PodAdmissionControl) admitDeleteUpTiKVPodDuringUpgrading(payload *admi
err := fmt.Errorf("tikv pod[%s/%s]'s controller is not a tidbcluster", namespace, name)
return util.ARFail(err)
}

if tc.TiKVStsDesiredReplicas() < 2 {
klog.Infof("TiKV statefulset replicas are less than 2, skip waiting to evict region leader for Pod %s/%s", namespace, name)
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
klog.Infof("TiKV statefulset replicas are less than 2, skip waiting to evict region leader for Pod %s/%s", namespace, name)
klog.Infof("TiKV statefulset replicas are less than 2, skip evicting region leader for Pod %s/%s", namespace, name)

@@ -111,6 +111,7 @@ func isTiKVReadyToUpgrade(upgradePod *core.Pod, store *pdapi.StoreInfo, evictLea
klog.Errorf("parse annotation:[%s] to time failed.", EvictLeaderBeginTime)
return false
}

Copy link
Contributor

Choose a reason for hiding this comment

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

No need to update this.

@DanielZhangQD
Copy link
Contributor

@mianhk Please add the test result in the PR description, thanks!

@mianhk
Copy link
Contributor Author

mianhk commented Aug 11, 2021

@mianhk Please add the test result in the PR description, thanks!

I add e2e test and fix promblems above. @DanielZhangQD PTAL.

@DanielZhangQD
Copy link
Contributor

/run-all-tests

@DanielZhangQD
Copy link
Contributor

/run-all-tests

Copy link
Contributor

@DanielZhangQD DanielZhangQD left a comment

Choose a reason for hiding this comment

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

LGTM

@DanielZhangQD
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 27cfb19

@DanielZhangQD
Copy link
Contributor

/run-all-tests

@DanielZhangQD
Copy link
Contributor

/run-all-tests

@DanielZhangQD
Copy link
Contributor

/run-all-tests

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

Successfully merging this pull request may close these issues.

No need to wait tikv transfer leader timeout while upgrading tidb cluster with single tikv node
7 participants