Skip to content

Commit

Permalink
Fix the issue cluster sync stuck caused by suspending cluster when sc…
Browse files Browse the repository at this point in the history
…aling (#4679)
  • Loading branch information
KanShiori committed Aug 22, 2022
1 parent 8a4f171 commit b84b18b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
7 changes: 1 addition & 6 deletions pkg/manager/suspender/suspender.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (s *suspender) SuspendComponent(cluster v1alpha1.Cluster, comp v1alpha1.Mem
if !suspending {
if can, reason := canSuspendComponent(ctx.cluster, ctx.component); !can {
klog.Warningf("component %s can not be suspended now because: %s", ctx.ComponentID(), reason)
return true, nil
return false, nil
}

err := s.begin(ctx)
Expand Down Expand Up @@ -223,11 +223,6 @@ func needsSuspendComponent(cluster v1alpha1.Cluster, comp v1alpha1.MemberType) b

// canSuspendComponent checks whether suspender can start to suspend the component
func canSuspendComponent(cluster v1alpha1.Cluster, comp v1alpha1.MemberType) (bool, string) {
// only support to suspend Normal or Suspend cluster
if !cluster.ComponentIsNormal(comp) && !cluster.ComponentIsSuspending(comp) {
return false, "component phase is not Normal or Suspend"
}

// wait for other components to be suspended
var suspendOrder []v1alpha1.MemberType
switch cluster.(type) {
Expand Down
17 changes: 5 additions & 12 deletions pkg/manager/suspender/suspender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ func TestSuspendComponent(t *testing.T) {
tc.Spec.TiKV = &v1alpha1.TiKVSpec{}
tc.Status.TiKV = v1alpha1.TiKVStatus{}
tc.Spec.TiKV.SuspendAction = &v1alpha1.SuspendAction{SuspendStatefulSet: true}
tc.Status.TiKV.Phase = v1alpha1.UpgradePhase // can not suspend
// can not suspend
tc.Spec.TiDB = &v1alpha1.TiDBSpec{}
tc.Spec.TiDB.SuspendAction = &v1alpha1.SuspendAction{SuspendStatefulSet: true}
tc.Status.TiDB.Phase = v1alpha1.NormalPhase
},
component: v1alpha1.TiKVMemberType,
sts: nil,
expect: func(suspeded bool, err error) {
g.Expect(suspeded).To(BeTrue())
g.Expect(suspeded).To(BeFalse())
g.Expect(err).To(BeNil())
},
expectResource: func(cluster v1alpha1.Cluster, s *suspender) {},
Expand Down Expand Up @@ -386,16 +389,6 @@ func TestCanSuspendComponent(t *testing.T) {
g.Expect(reason).To(BeEmpty())
},
},
"component's phase is not Normal and Suspend": {
setup: func(tc *v1alpha1.TidbCluster) {
tc.Status.TiKV.Phase = v1alpha1.UpgradePhase
},
component: v1alpha1.TiKVMemberType,
expect: func(can bool, reason string) {
g.Expect(can).To(BeFalse())
g.Expect(reason).To(Equal("component phase is not Normal or Suspend"))
},
},
"wait for other components to be suspended": {
setup: func(tc *v1alpha1.TidbCluster) {
tc.Status.TiKV.Phase = v1alpha1.NormalPhase
Expand Down

0 comments on commit b84b18b

Please sign in to comment.