member

package
v1.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrResetLeader        = coderr.NewCodeError(coderr.Internal, "reset leader by deleting leader key")
	ErrGetLeader          = coderr.NewCodeError(coderr.Internal, "get leader by querying leader key")
	ErrTxnPutLeader       = coderr.NewCodeError(coderr.Internal, "put leader key in txn")
	ErrMultipleLeader     = coderr.NewCodeError(coderr.Internal, "multiple leaders found")
	ErrInvalidLeaderValue = coderr.NewCodeError(coderr.Internal, "invalid leader value")
	ErrMarshalMember      = coderr.NewCodeError(coderr.Internal, "marshal member information")
	ErrGrantLease         = coderr.NewCodeError(coderr.Internal, "grant lease")
	ErrRevokeLease        = coderr.NewCodeError(coderr.Internal, "revoke lease")
	ErrCloseLease         = coderr.NewCodeError(coderr.Internal, "close lease")
)

Functions

This section is empty.

Types

type GetLeaderAddrResp added in v1.2.1

type GetLeaderAddrResp struct {
	LeaderEndpoint string
	IsLocal        bool
}

type LeaderWatcher

type LeaderWatcher struct {
	// contains filtered or unexported fields
}

func NewLeaderWatcher

func NewLeaderWatcher(ctx WatchContext, self *Member, leaseTTLSec int64) *LeaderWatcher

func (*LeaderWatcher) Watch

func (l *LeaderWatcher) Watch(ctx context.Context, callbacks LeadershipEventCallbacks)

Watch watches the leader changes:

  1. Check whether the leader is valid (same as the etcd leader) if leader exists. - Leader is valid: wait for the leader changes. - Leader is not valid: reset the leader by the current leader.
  2. Campaign the leadership if leader does not exist. - Elect the etcd leader as the ceresmeta leader. - The leader keeps the leadership lease alive. - The other members keeps waiting for the leader changes.

The LeadershipCallbacks `callbacks` will be triggered when specific events occur.

type LeadershipEventCallbacks

type LeadershipEventCallbacks interface {
	AfterElected(ctx context.Context)
	BeforeTransfer(ctx context.Context)
}

type Member

type Member struct {
	ID       uint64
	Name     string
	Endpoint string
	// contains filtered or unexported fields
}

Member manages the leadership and the role of the node in the ceresmeta cluster.

func NewMember

func NewMember(rootPath string, id uint64, name, endpoint string, etcdCli *clientv3.Client, etcdLeaderGetter etcdutil.EtcdLeaderGetter, rpcTimeout time.Duration) *Member

func (*Member) CampaignAndKeepLeader

func (m *Member) CampaignAndKeepLeader(ctx context.Context, leaseTTLSec int64, callbacks LeadershipEventCallbacks) error

func (*Member) GetLeaderAddr added in v1.2.1

func (m *Member) GetLeaderAddr(_ context.Context) (GetLeaderAddrResp, error)

GetLeaderAddr gets the leader address of the cluster with memory cache. return error if no leader found.

func (*Member) Marshal

func (m *Member) Marshal() (string, error)

func (*Member) ResetLeader

func (m *Member) ResetLeader(ctx context.Context) error

func (*Member) WaitForLeaderChange

func (m *Member) WaitForLeaderChange(ctx context.Context, revision int64)

type WatchContext

type WatchContext interface {
	etcdutil.EtcdLeaderGetter
	ShouldStop() bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL