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 pd and tikv concurrent update #234

Merged
merged 8 commits into from
Dec 24, 2018
2 changes: 1 addition & 1 deletion pkg/manager/member/tidb_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (tmm *tidbMemberManager) syncTidbClusterStatus(tc *v1alpha1.TidbCluster, se
if err != nil {
return err
}
if upgrading {
if upgrading && tc.Status.TiKV.Phase != v1alpha1.UpgradePhase && tc.Status.PD.Phase != v1alpha1.UpgradePhase {
tc.Status.TiDB.Phase = v1alpha1.UpgradePhase
} else {
tc.Status.TiDB.Phase = v1alpha1.NormalPhase
Expand Down
32 changes: 32 additions & 0 deletions pkg/manager/member/tidb_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ func TestTiDBMemberManagerSyncTidbClusterStatus(t *testing.T) {
now := metav1.Time{Time: time.Now()}
testFn := func(test *testcase, t *testing.T) {
tc := newTidbClusterForPD()
tc.Status.PD.Phase = v1alpha1.NormalPhase
tc.Status.TiKV.Phase = v1alpha1.NormalPhase
set := &apps.StatefulSet{
Status: status,
}
Expand Down Expand Up @@ -384,6 +386,36 @@ func TestTiDBMemberManagerSyncTidbClusterStatus(t *testing.T) {
g.Expect(tc.Status.TiDB.Phase).To(Equal(v1alpha1.UpgradePhase))
},
},
{
name: "statefulset is upgrading but pd is upgrading",
updateTC: func(tc *v1alpha1.TidbCluster) {
tc.Status.PD.Phase = v1alpha1.UpgradePhase
},
upgradingFn: func(lister corelisters.PodLister, set *apps.StatefulSet, cluster *v1alpha1.TidbCluster) (bool, error) {
return true, nil
},
healthInfo: map[string]bool{},
errExpectFn: nil,
tcExpectFn: func(g *GomegaWithT, tc *v1alpha1.TidbCluster) {
g.Expect(tc.Status.TiDB.StatefulSet.Replicas).To(Equal(int32(3)))
g.Expect(tc.Status.TiDB.Phase).To(Equal(v1alpha1.NormalPhase))
},
},
{
name: "statefulset is upgrading but tikv is upgrading",
updateTC: func(tc *v1alpha1.TidbCluster) {
tc.Status.TiKV.Phase = v1alpha1.UpgradePhase
},
upgradingFn: func(lister corelisters.PodLister, set *apps.StatefulSet, cluster *v1alpha1.TidbCluster) (bool, error) {
return true, nil
},
healthInfo: map[string]bool{},
errExpectFn: nil,
tcExpectFn: func(g *GomegaWithT, tc *v1alpha1.TidbCluster) {
g.Expect(tc.Status.TiDB.StatefulSet.Replicas).To(Equal(int32(3)))
g.Expect(tc.Status.TiDB.Phase).To(Equal(v1alpha1.NormalPhase))
},
},
{
name: "statefulset is not upgrading",
updateTC: nil,
Expand Down
2 changes: 1 addition & 1 deletion pkg/manager/member/tikv_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func (tkmm *tikvMemberManager) syncTidbClusterStatus(tc *v1alpha1.TidbCluster, s
if err != nil {
return err
}
if upgrading {
if upgrading && tc.Status.PD.Phase != v1alpha1.UpgradePhase {
tc.Status.TiKV.Phase = v1alpha1.UpgradePhase
} else {
tc.Status.TiKV.Phase = v1alpha1.NormalPhase
Expand Down
19 changes: 19 additions & 0 deletions pkg/manager/member/tikv_member_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ func TestTiKVMemberManagerSyncTidbClusterStatus(t *testing.T) {
now := metav1.Time{Time: time.Now()}
testFn := func(test *testcase, t *testing.T) {
tc := newTidbClusterForPD()
tc.Status.PD.Phase = v1alpha1.NormalPhase
set := &apps.StatefulSet{
Status: status,
}
Expand Down Expand Up @@ -939,6 +940,24 @@ func TestTiKVMemberManagerSyncTidbClusterStatus(t *testing.T) {
g.Expect(tc.Status.TiKV.Phase).To(Equal(v1alpha1.UpgradePhase))
},
},
{
name: "statefulset is upgrading but pd is upgrading",
updateTC: func(tc *v1alpha1.TidbCluster) {
tc.Status.PD.Phase = v1alpha1.UpgradePhase
},
upgradingFn: func(lister corelisters.PodLister, controlInterface controller.PDControlInterface, set *apps.StatefulSet, cluster *v1alpha1.TidbCluster) (bool, error) {
return true, nil
},
errWhenGetStores: false,
storeInfo: nil,
errWhenGetTombstoneStores: false,
tombstoneStoreInfo: nil,
errExpectFn: nil,
tcExpectFn: func(g *GomegaWithT, tc *v1alpha1.TidbCluster) {
g.Expect(tc.Status.TiKV.StatefulSet.Replicas).To(Equal(int32(3)))
g.Expect(tc.Status.TiKV.Phase).To(Equal(v1alpha1.NormalPhase))
},
},
{
name: "statefulset is not upgrading",
updateTC: nil,
Expand Down