Skip to content

Commit

Permalink
Remove resign ddl owner logic for tidb-servers
Browse files Browse the repository at this point in the history
Signed-off-by: Aylei <rayingecho@gmail.com>
  • Loading branch information
aylei committed Nov 26, 2019
1 parent f67ed33 commit d86e6bb
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 50 deletions.
19 changes: 0 additions & 19 deletions pkg/manager/member/tidb_upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ import (
glog "k8s.io/klog"
)

const (
// MaxResignDDLOwnerCount is the max regign DDL owner count
MaxResignDDLOwnerCount = 3
)

type tidbUpgrader struct {
podLister corelisters.PodLister
tidbControl controller.TiDBControlInterface
Expand Down Expand Up @@ -96,20 +91,6 @@ func (tdu *tidbUpgrader) Upgrade(tc *v1alpha1.TidbCluster, oldSet *apps.Stateful
}

func (tdu *tidbUpgrader) upgradeTiDBPod(tc *v1alpha1.TidbCluster, ordinal int32, newSet *apps.StatefulSet) error {
tcName := tc.GetName()
if tc.Spec.TiDB.Replicas > 1 {
if member, exist := tc.Status.TiDB.Members[tidbPodName(tcName, ordinal)]; exist && member.Health {
hasResign, err := tdu.tidbControl.ResignDDLOwner(tc, ordinal)
if (!hasResign || err != nil) && tc.Status.TiDB.ResignDDLOwnerRetryCount < MaxResignDDLOwnerCount {
glog.Errorf("tidb upgrader: failed to resign ddl owner to %s, %v", member.Name, err)
tc.Status.TiDB.ResignDDLOwnerRetryCount++
return err
}
glog.Infof("tidb upgrader: resign ddl owner to %s successfully", member.Name)
}
}

tc.Status.TiDB.ResignDDLOwnerRetryCount = 0
setUpgradePartition(newSet, ordinal)
return nil
}
Expand Down
32 changes: 1 addition & 31 deletions tests/pkg/webhook/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ package webhook
import (
"fmt"
"os"
"strconv"
"strings"
"time"

"github.com/pingcap/tidb-operator/tests/slack"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/pingcap/tidb-operator/pkg/controller"
"github.com/pingcap/tidb-operator/pkg/label"
"github.com/pingcap/tidb-operator/pkg/pdapi"
"github.com/pingcap/tidb-operator/tests/pkg/client"
Expand Down Expand Up @@ -62,7 +59,6 @@ func (wh *webhook) admitPods(ar v1beta1.AdmissionReview) *v1beta1.AdmissionRespo
}

pdClient := pdapi.NewDefaultPDControl(kubeCli).GetPDClient(pdapi.Namespace(tc.GetNamespace()), tc.GetName(), tc.Spec.EnableTLSCluster)
tidbController := controller.NewDefaultTiDBControl()

// if pod is already deleting, return Allowed
if pod.DeletionTimestamp != nil {
Expand All @@ -71,33 +67,7 @@ func (wh *webhook) admitPods(ar v1beta1.AdmissionReview) *v1beta1.AdmissionRespo
return &reviewResponse
}

if pod.Labels[label.ComponentLabelKey] == "tidb" {
ordinal, err := strconv.ParseInt(strings.Split(name, "-")[len(strings.Split(name, "-"))-1], 10, 32)
if err != nil {
glog.Errorf("fail to convert string to int while deleting TiDB err %v", err)
return &reviewResponse
}

info, err := tidbController.GetInfo(tc, int32(ordinal))
if err != nil {
glog.Errorf("fail to get tidb info error:%v", err)
return &reviewResponse
}

if info.IsOwner && tc.Status.TiDB.StatefulSet.Replicas > 1 {
time.Sleep(10 * time.Second)
err := fmt.Errorf("tidb is ddl owner, can't be deleted namespace %s name %s", namespace, name)
glog.Error(err)
sendErr := slack.SendErrMsg(err.Error())
if sendErr != nil {
glog.Error(sendErr)
}
// TODO use context instead
os.Exit(3)
}
glog.Infof("savely delete pod namespace %s name %s isowner %t", namespace, name, info.IsOwner)

} else if pod.Labels[label.ComponentLabelKey] == "pd" {
if pod.Labels[label.ComponentLabelKey] == "pd" {

leader, err := pdClient.GetPDLeader()
if err != nil {
Expand Down

0 comments on commit d86e6bb

Please sign in to comment.