diff --git a/pkg/manager/member/pd_upgrader.go b/pkg/manager/member/pd_upgrader.go index ea1d45ef1a..31d3aaaf03 100644 --- a/pkg/manager/member/pd_upgrader.go +++ b/pkg/manager/member/pd_upgrader.go @@ -57,6 +57,10 @@ func (pu *pdUpgrader) gracefulUpgrade(tc *v1alpha1.TidbCluster, oldSet *apps.Sta return nil } + if tc.Status.PD.StatefulSet.UpdateRevision == tc.Status.PD.StatefulSet.CurrentRevision { + return nil + } + setUpgradePartition(newSet, *oldSet.Spec.UpdateStrategy.RollingUpdate.Partition) for i := tc.Status.PD.StatefulSet.Replicas - 1; i >= 0; i-- { podName := pdPodName(tcName, i) diff --git a/pkg/manager/member/pd_upgrader_test.go b/pkg/manager/member/pd_upgrader_test.go index 88db2d860c..21dad8f060 100644 --- a/pkg/manager/member/pd_upgrader_test.go +++ b/pkg/manager/member/pd_upgrader_test.go @@ -120,6 +120,22 @@ func TestPDUpgraderUpgrade(t *testing.T) { g.Expect(newSet.Spec.UpdateStrategy.RollingUpdate.Partition).To(Equal(func() *int32 { i := int32(3); return &i }())) }, }, + { + name: "update revision equals current revision", + changeFn: func(tc *v1alpha1.TidbCluster) { + tc.Status.PD.Synced = true + tc.Status.PD.StatefulSet.UpdateRevision = tc.Status.PD.StatefulSet.CurrentRevision + }, + changePods: nil, + transferLeaderErr: false, + errExpectFn: func(g *GomegaWithT, err error) { + g.Expect(err).NotTo(HaveOccurred()) + }, + expectFn: func(g *GomegaWithT, tc *v1alpha1.TidbCluster, newSet *apps.StatefulSet) { + g.Expect(tc.Status.PD.Phase).To(Equal(v1alpha1.UpgradePhase)) + g.Expect(newSet.Spec.UpdateStrategy.RollingUpdate.Partition).To(Equal(func() *int32 { i := int32(3); return &i }())) + }, + }, { name: "skip to wait all members health", changeFn: func(tc *v1alpha1.TidbCluster) { diff --git a/pkg/manager/member/tidb_upgrader.go b/pkg/manager/member/tidb_upgrader.go index 0faba1a69e..fd52253b83 100644 --- a/pkg/manager/member/tidb_upgrader.go +++ b/pkg/manager/member/tidb_upgrader.go @@ -57,6 +57,10 @@ func (tdu *tidbUpgrader) Upgrade(tc *v1alpha1.TidbCluster, oldSet *apps.Stateful return nil } + if tc.Status.TiDB.StatefulSet.UpdateRevision == tc.Status.TiDB.StatefulSet.CurrentRevision { + return nil + } + setUpgradePartition(newSet, *oldSet.Spec.UpdateStrategy.RollingUpdate.Partition) for i := tc.Status.TiDB.StatefulSet.Replicas - 1; i >= 0; i-- { podName := tidbPodName(tcName, i) diff --git a/pkg/manager/member/tidb_upgrader_test.go b/pkg/manager/member/tidb_upgrader_test.go index a3a76ceaba..9c66f0e271 100644 --- a/pkg/manager/member/tidb_upgrader_test.go +++ b/pkg/manager/member/tidb_upgrader_test.go @@ -110,6 +110,18 @@ func TestTiDBUpgrader_Upgrade(t *testing.T) { g.Expect(newSet.Spec.UpdateStrategy.RollingUpdate.Partition).To(Equal((func() *int32 { i := int32(1); return &i }()))) }, }, + { + name: "upgrade revision equals current revision", + changeFn: func(tc *v1alpha1.TidbCluster) { + tc.Status.PD.Phase = v1alpha1.NormalPhase + tc.Status.TiKV.Phase = v1alpha1.NormalPhase + tc.Status.TiDB.StatefulSet.UpdateRevision = tc.Status.TiDB.StatefulSet.CurrentRevision + }, + getLastAppliedConfigErr: false, + expectFn: func(g *GomegaWithT, tc *v1alpha1.TidbCluster, newSet *apps.StatefulSet) { + g.Expect(newSet.Spec.UpdateStrategy.RollingUpdate.Partition).To(Equal((func() *int32 { i := int32(1); return &i }()))) + }, + }, { name: "get apply config error", changeFn: func(tc *v1alpha1.TidbCluster) { diff --git a/pkg/manager/member/tikv_upgrader.go b/pkg/manager/member/tikv_upgrader.go index fc9e05ba64..a7d6aa4109 100644 --- a/pkg/manager/member/tikv_upgrader.go +++ b/pkg/manager/member/tikv_upgrader.go @@ -72,6 +72,10 @@ func (tku *tikvUpgrader) Upgrade(tc *v1alpha1.TidbCluster, oldSet *apps.Stateful return nil } + if tc.Status.TiKV.StatefulSet.UpdateRevision == tc.Status.TiKV.StatefulSet.CurrentRevision { + return nil + } + setUpgradePartition(newSet, *oldSet.Spec.UpdateStrategy.RollingUpdate.Partition) for i := tc.Status.TiKV.StatefulSet.Replicas - 1; i >= 0; i-- { store := tku.getStoreByOrdinal(tc, i) diff --git a/pkg/manager/member/tikv_upgrader_test.go b/pkg/manager/member/tikv_upgrader_test.go index acab4ff139..e9f796d567 100644 --- a/pkg/manager/member/tikv_upgrader_test.go +++ b/pkg/manager/member/tikv_upgrader_test.go @@ -205,6 +205,26 @@ func TestTiKVUpgraderUpgrade(t *testing.T) { g.Expect(*newSet.Spec.UpdateStrategy.RollingUpdate.Partition).To(Equal(int32(3))) }, }, + { + name: "update revision equals current revision", + changeFn: func(tc *v1alpha1.TidbCluster) { + tc.Status.PD.Phase = v1alpha1.NormalPhase + tc.Status.TiKV.Phase = v1alpha1.NormalPhase + tc.Status.TiKV.Synced = true + tc.Status.TiKV.StatefulSet.UpdateRevision = tc.Status.TiKV.StatefulSet.CurrentRevision + }, + changePods: nil, + beginEvictLeaderErr: false, + endEvictLeaderErr: false, + updatePodErr: false, + errExpectFn: func(g *GomegaWithT, err error) { + g.Expect(err).NotTo(HaveOccurred()) + }, + expectFn: func(g *GomegaWithT, tc *v1alpha1.TidbCluster, newSet *apps.StatefulSet, pods map[string]*corev1.Pod) { + g.Expect(tc.Status.TiKV.Phase).To(Equal(v1alpha1.UpgradePhase)) + g.Expect(*newSet.Spec.UpdateStrategy.RollingUpdate.Partition).To(Equal(int32(3))) + }, + }, { name: "tikv can not upgrade when pd is upgrading", changeFn: func(tc *v1alpha1.TidbCluster) {