Skip to content

Commit

Permalink
sync pump before tidb (pingcap#2515)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielZhangQD authored and sre-bot committed May 21, 2020
1 parent ed779d5 commit bb20aa5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
9 changes: 9 additions & 0 deletions pkg/apis/pingcap/v1alpha1/tidbcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,15 @@ func (tc *TidbCluster) TiKVIsAvailable() bool {
return true
}

func (tc *TidbCluster) PumpIsAvailable() bool {
var lowerLimit int32 = 1
if tc.Status.Pump.StatefulSet == nil || tc.Status.Pump.StatefulSet.ReadyReplicas < lowerLimit {
return false
}

return true
}

func (tc *TidbCluster) GetClusterID() string {
return tc.Status.ClusterID
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/tidbcluster/tidb_cluster_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ func (tcc *defaultTidbClusterControl) updateTidbCluster(tc *v1alpha1.TidbCluster
return err
}

// syncing the pump cluster
if err := tcc.pumpMemberManager.Sync(tc); err != nil {
return err
}

// works that should do to making the tidb cluster current state match the desired state:
// - waiting for the tikv cluster available(at least one peer works)
// - create or update tidb headless service
Expand Down Expand Up @@ -230,11 +235,6 @@ func (tcc *defaultTidbClusterControl) updateTidbCluster(tc *v1alpha1.TidbCluster
return err
}

// syncing the pump cluster
if err := tcc.pumpMemberManager.Sync(tc); err != nil {
return err
}

// syncing the some tidbcluster status attributes
// - sync tidbmonitor reference
return tcc.tidbClusterStatusManager.Sync(tc)
Expand Down
5 changes: 5 additions & 0 deletions pkg/manager/member/pump_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ func (pmm *pumpMemberManager) syncPumpStatefulSetForTidbCluster(tc *v1alpha1.Tid
return pmm.setControl.CreateStatefulSet(tc, newPumpSet)
}

// Wait for PD & TiKV upgrading done
if tc.Status.PD.Phase == v1alpha1.UpgradePhase || tc.Status.TiKV.Phase == v1alpha1.UpgradePhase {
return nil
}

return updateStatefulSet(pmm.setControl, tc, newPumpSet, oldPumpSet)
}

Expand Down
9 changes: 7 additions & 2 deletions pkg/manager/member/tidb_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ func (tmm *tidbMemberManager) Sync(tc *v1alpha1.TidbCluster) error {
if !tc.TiKVIsAvailable() {
return controller.RequeueErrorf("TidbCluster: [%s/%s], waiting for TiKV cluster running", ns, tcName)
}

if tc.Spec.Pump != nil {
if !tc.PumpIsAvailable() {
return controller.RequeueErrorf("TidbCluster: [%s/%s], waiting for Pump cluster running", ns, tcName)
}
}
// Sync TiDB Headless Service
if err := tmm.syncTiDBHeadlessServiceForTidbCluster(tc); err != nil {
return err
Expand Down Expand Up @@ -763,7 +767,8 @@ func (tmm *tidbMemberManager) syncTidbClusterStatus(tc *v1alpha1.TidbCluster, se
if err != nil {
return err
}
if upgrading && tc.Status.TiKV.Phase != v1alpha1.UpgradePhase && tc.Status.PD.Phase != v1alpha1.UpgradePhase {
if upgrading && tc.Status.TiKV.Phase != v1alpha1.UpgradePhase &&
tc.Status.PD.Phase != v1alpha1.UpgradePhase && tc.Status.Pump.Phase != v1alpha1.UpgradePhase {
tc.Status.TiDB.Phase = v1alpha1.UpgradePhase
} else {
tc.Status.TiDB.Phase = v1alpha1.NormalPhase
Expand Down
3 changes: 2 additions & 1 deletion pkg/manager/member/tidb_upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func (tdu *tidbUpgrader) Upgrade(tc *v1alpha1.TidbCluster, oldSet *apps.Stateful
ns := tc.GetNamespace()
tcName := tc.GetName()

if tc.Status.PD.Phase == v1alpha1.UpgradePhase || tc.Status.TiKV.Phase == v1alpha1.UpgradePhase {
if tc.Status.PD.Phase == v1alpha1.UpgradePhase || tc.Status.TiKV.Phase == v1alpha1.UpgradePhase ||
tc.Status.Pump.Phase == v1alpha1.UpgradePhase {
_, podSpec, err := GetLastAppliedConfig(oldSet)
if err != nil {
return err
Expand Down

0 comments on commit bb20aa5

Please sign in to comment.