membership

package
v0.0.0-...-3ee4cf2 Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrIDRemoved return for the id of member is removed
	ErrIDRemoved = errors.New("membership: id RemovedMap")
	//ErrIDExists return for the id of member exists
	ErrIDExists = errors.New("membership: id exists")
	//ErrIDNotFound return for the id of member not found
	ErrIDNotFound = errors.New("membership: id not found")
	//ErrPeerURLexists return for the peer url of member exists
	ErrPeerURLexists = errors.New("membership: peerURL exists")
)

Functions

func GetRemotePeerURLs

func GetRemotePeerURLs(cl *RaftCluster, local string) []string

GetRemotePeerURLs returns peer urls of remote MembersMap in the cluster. The returned list is sorted in ascending lexicographical order.

func IsMemberBootstrapped

func IsMemberBootstrapped(cl *RaftCluster, member string, rt http.RoundTripper, timeout time.Duration) bool

IsMemberBootstrapped tries to check if the given member has been bootstrapped in the given cluster.

func ValidateClusterAndAssignIDs

func ValidateClusterAndAssignIDs(local *RaftCluster, existing *RaftCluster) error

ValidateClusterAndAssignIDs validates the local cluster by matching the PeerURLs with the existing cluster. If the validation succeeds, it assigns the IDs from the existing cluster to the local cluster. If the validation fails, an error will be returned.

Types

type Attributes

type Attributes struct {
	Name      string   `json:"name,omitempty"`
	AdminURLs []string `json:"adminURLs,omitempty"`
}

Attributes represents all the non-raft related attributes of an etcd member.

type Member

type Member struct {
	ID types.ID `json:"Id"`
	RaftAttributes
	Attributes
}

Member is a member in raft cluster

func NewMember

func NewMember(name string, peerURLs types.URLs, adminURLs types.URLs, now *time.Time) *Member

NewMember creates a Member without an id and generates one based on the raftNodeName, peer URLs, and time. This is used for bootstrapping/adding new member.

func (*Member) Clone

func (m *Member) Clone() *Member

Clone implements member info deep copy

func (*Member) IsStarted

func (m *Member) IsStarted() bool

IsStarted check the member is started

func (*Member) PickPeerURL

func (m *Member) PickPeerURL() string

PickPeerURL chooses a random address from a given Member's PeerURLs. It will panic if there is no PeerURLs available in Member.

type MembersByID

type MembersByID []*Member

MembersByID implements sort by id interface

func (MembersByID) Len

func (ms MembersByID) Len() int

func (MembersByID) Less

func (ms MembersByID) Less(i, j int) bool

func (MembersByID) Swap

func (ms MembersByID) Swap(i, j int)

type MembersByPeerURLs

type MembersByPeerURLs []*Member

MembersByPeerURLs implements sort by peer urls interface

func (MembersByPeerURLs) Len

func (ms MembersByPeerURLs) Len() int

func (MembersByPeerURLs) Less

func (ms MembersByPeerURLs) Less(i, j int) bool

func (MembersByPeerURLs) Swap

func (ms MembersByPeerURLs) Swap(i, j int)

type RaftAttributes

type RaftAttributes struct {
	// PeerURLs is the list of peers in the raft cluster.
	// TODO(philips): ensure these are URLs
	PeerURLs []string `json:"peerURLs"`
}

RaftAttributes represents the raft related attributes of an etcd member.

type RaftCluster

type RaftCluster struct {
	ID    types.ID        `json:"id"`
	Store storage.Storage `json:"-"`

	sync.Mutex `json:"-"`
	MembersMap map[types.ID]*Member `json:"members_map"`
	// RemovedMap contains the ids of RemovedMap MembersMap in the cluster.
	// RemovedMap id cannot be reused.
	RemovedMap map[types.ID]bool `json:"removed_map"`
}

RaftCluster is a list of MembersMap that belong to the same raft cluster

func GetClusterFromRemotePeers

func GetClusterFromRemotePeers(urls []string, rt http.RoundTripper) (*RaftCluster, error)

GetClusterFromRemotePeers takes a set of URLs representing etcd peers, and attempts to construct a Cluster by accessing the MembersMap endpoint on one of these URLs. The first URL to provide a response is used. If no URLs provide a response, or a Cluster cannot be successfully created from a received response, an error is returned. Each request has a 10-second timeout. Because the upper limit of TTL is 5s, 10 second is enough for building connection and finishing request.

func GetRaftClusterFromStorage

func GetRaftClusterFromStorage(s storage.Storage) (*RaftCluster, error)

GetRaftClusterFromStorage get the raft cluster information from storage

func NewCluster

func NewCluster() *RaftCluster

NewCluster create a new cluster struct

func NewClusterFromMembers

func NewClusterFromMembers(id types.ID, membs []*Member) *RaftCluster

NewClusterFromMembers implements init member map

func NewClusterFromURLsMap

func NewClusterFromURLsMap(urlsmap types.URLsMap) (*RaftCluster, error)

NewClusterFromURLsMap implements init raft cluster from config

func (*RaftCluster) AddMember

func (c *RaftCluster) AddMember(m *Member)

AddMember adds a new Member into the cluster, and saves the given member's raftAttributes into the Store. The given member should have empty attributes. A Member with a matching id must not exist.

func (*RaftCluster) GetID

func (c *RaftCluster) GetID() types.ID

GetID get the id of raft cluster

func (*RaftCluster) IsIDRemoved

func (c *RaftCluster) IsIDRemoved(id types.ID) bool

IsIDRemoved check the id of member is removed

func (*RaftCluster) IsReadyToAddNewMember

func (c *RaftCluster) IsReadyToAddNewMember() bool

IsReadyToAddNewMember check the raft cluster is ready to add member

func (*RaftCluster) IsReadyToRemoveMember

func (c *RaftCluster) IsReadyToRemoveMember(id uint64) bool

IsReadyToRemoveMember check the raft cluster is ready to remove member

func (*RaftCluster) Member

func (c *RaftCluster) Member(id types.ID) *Member

Member get the member by id

func (*RaftCluster) MemberByName

func (c *RaftCluster) MemberByName(name string) *Member

MemberByName returns a Member with the given name if exists. If more than one member has the given name, it will panic.

func (*RaftCluster) MemberIDs

func (c *RaftCluster) MemberIDs() []types.ID

MemberIDs get the IDs of members

func (*RaftCluster) Members

func (c *RaftCluster) Members() []*Member

Members get the members of raft cluster

func (*RaftCluster) PeerURLs

func (c *RaftCluster) PeerURLs() []string

PeerURLs returns a list of all peer addresses. The returned list is sorted in ascending lexicographical order.

func (*RaftCluster) RemoveMember

func (c *RaftCluster) RemoveMember(id types.ID)

RemoveMember removes a member from the Store. The given id MUST exist, or the function panics.

func (*RaftCluster) SaveToStorage

func (c *RaftCluster) SaveToStorage() error

SaveToStorage implements save the raft cluster information into storage

func (*RaftCluster) SetID

func (c *RaftCluster) SetID(id types.ID)

SetID set the id of raft cluster

func (*RaftCluster) SetStore

func (c *RaftCluster) SetStore(st storage.Storage)

SetStore set the storage of raft cluster

func (*RaftCluster) String

func (c *RaftCluster) String() string

String implements dump raft cluster into string

func (*RaftCluster) UpdateAttributes

func (c *RaftCluster) UpdateAttributes(id types.ID, attr Attributes)

UpdateAttributes update the attributes of raft cluster

func (*RaftCluster) UpdateRaftAttributes

func (c *RaftCluster) UpdateRaftAttributes(id types.ID, raftAttr RaftAttributes)

UpdateRaftAttributes update the raft attributes of raft cluster

func (*RaftCluster) ValidateConfigurationChange

func (c *RaftCluster) ValidateConfigurationChange(cc raftpb.ConfChange) error

ValidateConfigurationChange takes a proposed ConfChange and ensures that it is still valid.

Jump to

Keyboard shortcuts

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