From 238d4d79ea313fce2ad354cc1c2ee889ecad9441 Mon Sep 17 00:00:00 2001 From: okJiang <819421878@qq.com> Date: Mon, 11 Nov 2024 15:37:42 +0800 Subject: [PATCH] *: remove unused code from participant.go (#8782) ref tikv/pd#4399 Signed-off-by: okJiang <819421878@qq.com> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- pkg/member/participant.go | 69 --------------------------------------- 1 file changed, 69 deletions(-) diff --git a/pkg/member/participant.go b/pkg/member/participant.go index 599e56387d6..5ef997341de 100644 --- a/pkg/member/participant.go +++ b/pkg/member/participant.go @@ -18,7 +18,6 @@ import ( "context" "fmt" "path" - "strconv" "sync/atomic" "time" @@ -281,15 +280,6 @@ func (m *Participant) IsSameLeader(leader participant) bool { return leader.GetId() == m.ID() } -// CheckPriority checks whether there is another participant has higher priority and resign it as the leader if so. -func (*Participant) CheckPriority(_ context.Context) { - // TODO: implement weighted-election when it's in need -} - -func (m *Participant) getLeaderPriorityPath(id uint64) string { - return path.Join(m.rootPath, fmt.Sprintf("participant/%d/leader_priority", id)) -} - // GetDCLocationPathPrefix returns the dc-location path prefix of the cluster. func (m *Participant) GetDCLocationPathPrefix() string { return path.Join(m.rootPath, dcLocationConfigEtcdPrefix) @@ -300,65 +290,6 @@ func (m *Participant) GetDCLocationPath(id uint64) string { return path.Join(m.GetDCLocationPathPrefix(), fmt.Sprint(id)) } -// SetLeaderPriority saves the priority to be elected as the etcd leader. -func (m *Participant) SetLeaderPriority(id uint64, priority int) error { - key := m.getLeaderPriorityPath(id) - res, err := m.leadership.LeaderTxn().Then(clientv3.OpPut(key, strconv.Itoa(priority))).Commit() - if err != nil { - return errs.ErrEtcdTxnInternal.Wrap(err).GenWithStackByCause() - } - if !res.Succeeded { - log.Error("save etcd leader priority failed, maybe not the leader") - return errs.ErrEtcdTxnConflict.FastGenByArgs() - } - return nil -} - -// DeleteLeaderPriority removes the etcd leader priority config. -func (m *Participant) DeleteLeaderPriority(id uint64) error { - key := m.getLeaderPriorityPath(id) - res, err := m.leadership.LeaderTxn().Then(clientv3.OpDelete(key)).Commit() - if err != nil { - return errs.ErrEtcdTxnInternal.Wrap(err).GenWithStackByCause() - } - if !res.Succeeded { - log.Error("delete etcd leader priority failed, maybe not the leader") - return errs.ErrEtcdTxnConflict.FastGenByArgs() - } - return nil -} - -// DeleteDCLocationInfo removes the dc-location info. -func (m *Participant) DeleteDCLocationInfo(id uint64) error { - key := m.GetDCLocationPath(id) - res, err := m.leadership.LeaderTxn().Then(clientv3.OpDelete(key)).Commit() - if err != nil { - return errs.ErrEtcdTxnInternal.Wrap(err).GenWithStackByCause() - } - if !res.Succeeded { - log.Error("delete dc-location info failed, maybe not the leader") - return errs.ErrEtcdTxnConflict.FastGenByArgs() - } - return nil -} - -// GetLeaderPriority loads the priority to be elected as the etcd leader. -func (m *Participant) GetLeaderPriority(id uint64) (int, error) { - key := m.getLeaderPriorityPath(id) - res, err := etcdutil.EtcdKVGet(m.client, key) - if err != nil { - return 0, err - } - if len(res.Kvs) == 0 { - return 0, nil - } - priority, err := strconv.ParseInt(string(res.Kvs[0].Value), 10, 32) - if err != nil { - return 0, errs.ErrStrconvParseInt.Wrap(err).GenWithStackByCause() - } - return int(priority), nil -} - func (m *Participant) campaignCheck() bool { checker := m.campaignChecker.Load() if checker == nil {