Documentation ¶
Index ¶
- Variables
- func GetRemotePeerURLs(cl *RaftCluster, local string) []string
- func IsMemberBootstrapped(cl *RaftCluster, member string, rt http.RoundTripper, timeout time.Duration) bool
- func ValidateClusterAndAssignIDs(local *RaftCluster, existing *RaftCluster) error
- type Attributes
- type Member
- type MembersByID
- type MembersByPeerURLs
- type RaftAttributes
- type RaftCluster
- func GetClusterFromRemotePeers(urls []string, rt http.RoundTripper) (*RaftCluster, error)
- func GetRaftClusterFromStorage(s storage.Storage) (*RaftCluster, error)
- func NewCluster() *RaftCluster
- func NewClusterFromMembers(id types.ID, membs []*Member) *RaftCluster
- func NewClusterFromURLsMap(urlsmap types.URLsMap) (*RaftCluster, error)
- func (c *RaftCluster) AddMember(m *Member)
- func (c *RaftCluster) GetID() types.ID
- func (c *RaftCluster) IsIDRemoved(id types.ID) bool
- func (c *RaftCluster) IsReadyToAddNewMember() bool
- func (c *RaftCluster) IsReadyToRemoveMember(id uint64) bool
- func (c *RaftCluster) Member(id types.ID) *Member
- func (c *RaftCluster) MemberByName(name string) *Member
- func (c *RaftCluster) MemberIDs() []types.ID
- func (c *RaftCluster) Members() []*Member
- func (c *RaftCluster) PeerURLs() []string
- func (c *RaftCluster) RemoveMember(id types.ID)
- func (c *RaftCluster) SaveToStorage() error
- func (c *RaftCluster) SetID(id types.ID)
- func (c *RaftCluster) SetStore(st storage.Storage)
- func (c *RaftCluster) String() string
- func (c *RaftCluster) UpdateAttributes(id types.ID, attr Attributes)
- func (c *RaftCluster) UpdateRaftAttributes(id types.ID, raftAttr RaftAttributes)
- func (c *RaftCluster) ValidateConfigurationChange(cc raftpb.ConfChange) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
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) PickPeerURL ¶
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 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) 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.