Skip to content

Commit 5d1c178

Browse files
sre-botweekface
authored andcommitted
do not limit failover count when maxFailoverCount = 0 (#978)
1 parent cf41bdd commit 5d1c178

File tree

4 files changed

+90
-2
lines changed

4 files changed

+90
-2
lines changed

pkg/manager/member/tidb_failover.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (tf *tidbFailover) Failover(tc *v1alpha1.TidbCluster) error {
4545
}
4646
}
4747

48-
if len(tc.Status.TiDB.FailureMembers) >= int(tc.Spec.TiDB.MaxFailoverCount) {
48+
if tc.Spec.TiDB.MaxFailoverCount > 0 && len(tc.Status.TiDB.FailureMembers) >= int(tc.Spec.TiDB.MaxFailoverCount) {
4949
glog.Warningf("the failure members count reached the limit:%d", tc.Spec.TiDB.MaxFailoverCount)
5050
return nil
5151
}

pkg/manager/member/tidb_failover_test.go

+46
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,52 @@ func TestFakeTiDBFailoverFailover(t *testing.T) {
157157
t.Expect(int(tc.Spec.TiDB.Replicas)).To(Equal(2))
158158
},
159159
},
160+
{
161+
name: "max failover count but maxFailoverCount = 0",
162+
update: func(tc *v1alpha1.TidbCluster) {
163+
tc.Spec.TiDB.MaxFailoverCount = 0
164+
tc.Status.TiDB.Members = map[string]v1alpha1.TiDBMember{
165+
"failover-tidb-0": {
166+
Name: "failover-tidb-0",
167+
Health: false,
168+
},
169+
"failover-tidb-1": {
170+
Name: "failover-tidb-1",
171+
Health: false,
172+
},
173+
"failover-tidb-2": {
174+
Name: "failover-tidb-2",
175+
Health: false,
176+
},
177+
"failover-tidb-3": {
178+
Name: "failover-tidb-3",
179+
Health: false,
180+
},
181+
"failover-tidb-4": {
182+
Name: "failover-tidb-4",
183+
Health: false,
184+
},
185+
}
186+
tc.Status.TiDB.FailureMembers = map[string]v1alpha1.TiDBFailureMember{
187+
"failover-tidb-0": {
188+
PodName: "failover-tidb-0",
189+
},
190+
"failover-tidb-1": {
191+
PodName: "failover-tidb-1",
192+
},
193+
"failover-tidb-2": {
194+
PodName: "failover-tidb-2",
195+
},
196+
}
197+
},
198+
errExpectFn: func(t *GomegaWithT, err error) {
199+
t.Expect(err).NotTo(HaveOccurred())
200+
},
201+
expectFn: func(t *GomegaWithT, tc *v1alpha1.TidbCluster) {
202+
t.Expect(len(tc.Status.TiDB.FailureMembers)).To(Equal(4))
203+
t.Expect(int(tc.Spec.TiDB.Replicas)).To(Equal(2))
204+
},
205+
},
160206
}
161207

162208
for i := range tests {

pkg/manager/member/tikv_failover.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (tf *tikvFailover) Failover(tc *v1alpha1.TidbCluster) error {
5151
if tc.Status.TiKV.FailureStores == nil {
5252
tc.Status.TiKV.FailureStores = map[string]v1alpha1.TiKVFailureStore{}
5353
}
54-
if len(tc.Status.TiKV.FailureStores) >= int(tc.Spec.TiKV.MaxFailoverCount) {
54+
if tc.Spec.TiKV.MaxFailoverCount > 0 && len(tc.Status.TiKV.FailureStores) >= int(tc.Spec.TiKV.MaxFailoverCount) {
5555
glog.Warningf("%s/%s failure stores count reached the limit: %d", ns, tcName, tc.Spec.TiKV.MaxFailoverCount)
5656
return nil
5757
}

pkg/manager/member/tikv_failover_test.go

+42
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,48 @@ func TestTiKVFailoverFailover(t *testing.T) {
254254
g.Expect(len(tc.Status.TiKV.FailureStores)).To(Equal(3))
255255
},
256256
},
257+
{
258+
name: "exceed max failover count2 but maxFailoverCount = 0",
259+
update: func(tc *v1alpha1.TidbCluster) {
260+
tc.Spec.TiKV.MaxFailoverCount = 0
261+
tc.Status.TiKV.Stores = map[string]v1alpha1.TiKVStore{
262+
"12": {
263+
State: v1alpha1.TiKVStateDown,
264+
PodName: "tikv-12",
265+
LastTransitionTime: metav1.Time{Time: time.Now().Add(-70 * time.Minute)},
266+
},
267+
"13": {
268+
State: v1alpha1.TiKVStateDown,
269+
PodName: "tikv-13",
270+
LastTransitionTime: metav1.Time{Time: time.Now().Add(-61 * time.Minute)},
271+
},
272+
"14": {
273+
State: v1alpha1.TiKVStateDown,
274+
PodName: "tikv-14",
275+
LastTransitionTime: metav1.Time{Time: time.Now().Add(-70 * time.Minute)},
276+
},
277+
}
278+
tc.Status.TiKV.FailureStores = map[string]v1alpha1.TiKVFailureStore{
279+
"1": {
280+
PodName: "tikv-1",
281+
StoreID: "1",
282+
},
283+
"2": {
284+
PodName: "tikv-2",
285+
StoreID: "2",
286+
},
287+
"3": {
288+
PodName: "tikv-3",
289+
StoreID: "3",
290+
},
291+
}
292+
},
293+
err: false,
294+
expectFn: func(tc *v1alpha1.TidbCluster) {
295+
g.Expect(int(tc.Spec.TiKV.Replicas)).To(Equal(3))
296+
g.Expect(len(tc.Status.TiKV.FailureStores)).To(Equal(6))
297+
},
298+
},
257299
}
258300
for i := range tests {
259301
testFn(&tests[i], t)

0 commit comments

Comments
 (0)