-
Notifications
You must be signed in to change notification settings - Fork 502
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: can't recover after a upgrade failed #120
Merged
Merged
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
a7de64c
tidb graceful upgrade
xiaojingchen 2cfbde5
Merge branch 'master' into tidb-graceful-upgrade
weekface 2b78c7b
Merge branch 'master' into tidb-graceful-upgrade
xiaojingchen fc67d9a
Merge branch 'tidb-graceful-upgrade' of https://github.com/xiaojingch…
xiaojingchen 19ac0fa
address comment
xiaojingchen 16b03a3
address comment
xiaojingchen 99f3a37
rewrite upgrade to fix some bugs
xiaojingchen bf8b5a4
Merge branch 'master' into fix-ugrade
xiaojingchen 5781db6
Merge branch 'master' into fix-ugrade
gregwebs 756691a
Merge branch 'master' into fix-ugrade
xiaojingchen 645f067
Merge branch 'fix-ugrade' of https://github.com/xiaojingchen/tidb-ope…
xiaojingchen 4cf1d11
fix bugs
xiaojingchen 24524f2
address comment
xiaojingchen 8d149b7
Merge branch 'master' into fix-ugrade
tennix 19eddb5
fix upgrade state sync bug
xiaojingchen 3afa97a
Merge branch 'fix-ugrade' of https://github.com/xiaojingchen/tidb-ope…
xiaojingchen 3caece1
Merge branch 'fix-ugrade' of https://github.com/xiaojingchen/tidb-ope…
xiaojingchen bd16aaf
Merge branch 'fix-ugrade' of https://github.com/xiaojingchen/tidb-ope…
xiaojingchen 2de52da
fix tikv upgrade bug
xiaojingchen f666f20
Merge branch 'master' into fix-ugrade
weekface 5938988
fix empty point bug
xiaojingchen 7cb3f53
Merge branch 'fix-ugrade' of https://github.com/xiaojingchen/tidb-ope…
xiaojingchen 5429058
address comment
xiaojingchen 8ea29e7
address comment
xiaojingchen 7239470
address comment
xiaojingchen e0b1163
Merge branch 'master' into fix-ugrade
xiaojingchen 63d333f
Merge branch 'master' into fix-ugrade
tennix 8b29919
Merge branch 'master' into fix-ugrade
weekface File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,38 +66,31 @@ func (pu *pdUpgrader) gracefulUpgrade(tc *v1alpha1.TidbCluster, oldSet *apps.Sta | |
} | ||
|
||
tc.Status.PD.Phase = v1alpha1.UpgradePhase | ||
setUpgradePartition(newSet, *oldSet.Spec.UpdateStrategy.RollingUpdate.Partition) | ||
|
||
if tc.Status.PD.StatefulSet.CurrentReplicas == 0 { | ||
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s pd doesn't have old version pod to upgrade", ns, tcName) | ||
if !templateEqual(newSet.Spec.Template, oldSet.Spec.Template) { | ||
return nil | ||
} | ||
|
||
if !tc.PDAllPodsStarted() { | ||
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s pd pods are not all created", ns, tcName) | ||
} | ||
|
||
for i := tc.Status.PD.StatefulSet.Replicas; i > tc.Status.PD.StatefulSet.CurrentReplicas; i-- { | ||
if member, exist := tc.Status.PD.Members[pdPodName(tcName, i-1)]; !exist || !member.Health { | ||
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s pd upgraded pods are not all ready", ns, tcName) | ||
setUpgradePartition(newSet, *oldSet.Spec.UpdateStrategy.RollingUpdate.Partition) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line should be added to the |
||
for i := tc.Status.PD.StatefulSet.Replicas - 1; i >= 0; i-- { | ||
podName := pdPodName(tcName, i) | ||
pod, err := pu.podLister.Pods(ns).Get(podName) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
ordinal := tc.Status.PD.StatefulSet.CurrentReplicas - 1 | ||
upgradePodName := pdPodName(tcName, ordinal) | ||
if tc.Status.PD.Leader.Name == upgradePodName { | ||
var targetName string | ||
if ordinal == *newSet.Spec.Replicas-1 { | ||
targetName = pdPodName(tcName, 0) | ||
} else { | ||
targetName = pdPodName(tcName, *newSet.Spec.Replicas-1) | ||
revision, exist := pod.Labels[apps.ControllerRevisionHashLabelKey] | ||
if !exist { | ||
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s pd pod: [%s] has no label: %s", ns, tcName, podName, apps.ControllerRevisionHashLabelKey) | ||
} | ||
err := pu.transferPDLeaderTo(tc, targetName) | ||
if err != nil { | ||
return err | ||
|
||
if revision == tc.Status.PD.StatefulSet.UpdateRevision { | ||
if member, exist := tc.Status.PD.Members[podName]; !exist || !member.Health { | ||
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s pd upgraded pod: [%s] is not ready", ns, tcName, podName) | ||
} | ||
continue | ||
} | ||
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s pd member: [%s] is transferring leader to pd member: [%s]", ns, tcName, upgradePodName, targetName) | ||
} else { | ||
setUpgradePartition(newSet, ordinal) | ||
|
||
return pu.upgradePDPod(tc, i, newSet) | ||
} | ||
|
||
return nil | ||
|
@@ -131,6 +124,29 @@ func (pu *pdUpgrader) needForceUpgrade(tc *v1alpha1.TidbCluster) (bool, error) { | |
return imagePullFailedCount >= int(tc.Status.PD.StatefulSet.Replicas)/2+1, nil | ||
} | ||
|
||
func (pu *pdUpgrader) upgradePDPod(tc *v1alpha1.TidbCluster, ordinal int32, newSet *apps.StatefulSet) error { | ||
ns := tc.GetNamespace() | ||
tcName := tc.GetName() | ||
upgradePodName := pdPodName(tcName, ordinal) | ||
if tc.Status.PD.Leader.Name == upgradePodName && tc.Status.PD.StatefulSet.Replicas > 1 { | ||
lastOrdinal := tc.Status.PD.StatefulSet.Replicas - 1 | ||
var targetName string | ||
if ordinal == lastOrdinal { | ||
targetName = pdPodName(tcName, 0) | ||
} else { | ||
targetName = pdPodName(tcName, lastOrdinal) | ||
} | ||
err := pu.transferPDLeaderTo(tc, targetName) | ||
if err != nil { | ||
return err | ||
} | ||
return controller.RequeueErrorf("tidbcluster: [%s/%s]'s pd member: [%s] is transferring leader to pd member: [%s]", ns, tcName, upgradePodName, targetName) | ||
} | ||
|
||
setUpgradePartition(newSet, ordinal) | ||
return nil | ||
} | ||
|
||
func (pu *pdUpgrader) transferPDLeaderTo(tc *v1alpha1.TidbCluster, targetName string) error { | ||
return pu.pdControl.GetPDClient(tc).TransferPDLeader(targetName) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set
Partition
to the maxThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And add a comment to indicate the reason why
return nil
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the Partition default is max