Skip to content

Commit

Permalink
Merge branch 'master' into min-ssl-version
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot[bot] authored Nov 11, 2024
2 parents 24ced32 + 238d4d7 commit 34f9291
Showing 1 changed file with 0 additions and 69 deletions.
69 changes: 0 additions & 69 deletions pkg/member/participant.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"
"fmt"
"path"
"strconv"
"sync/atomic"
"time"

Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit 34f9291

Please sign in to comment.