Documentation ¶
Overview ¶
Package membership describes individual etcd members and clusters of members.
Index ¶
- Constants
- Variables
- func IsMetaStoreOnly(store v2store.Store) (bool, error)
- func MemberAttributesStorePath(id types.ID) string
- func MemberStoreKey(id types.ID) string
- func MustParseMemberIDFromKey(lg *zap.Logger, key string) types.ID
- func RemovedMemberStoreKey(id types.ID) string
- func StoreClusterVersionKey() string
- func TrimMembershipFromV2Store(lg *zap.Logger, s v2store.Store) error
- func ValidateClusterAndAssignIDs(lg *zap.Logger, local *RaftCluster, existing *RaftCluster) error
- func ValidateMaxLearnerConfig(maxLearners int, members []*Member, scaleUpLearners bool) error
- type Attributes
- type ClusterOption
- type ClusterOptions
- type ClusterVersionBackend
- type ConfigChangeContext
- type DowngradeInfoBackend
- type Member
- type MemberBackend
- type MembersByID
- type MembersByPeerURLs
- type MembershipBackend
- type RaftAttributes
- type RaftCluster
- func NewCluster(lg *zap.Logger, opts ...ClusterOption) *RaftCluster
- func NewClusterFromMembers(lg *zap.Logger, id types.ID, membs []*Member, opts ...ClusterOption) *RaftCluster
- func NewClusterFromURLsMap(lg *zap.Logger, token string, urlsmap types.URLsMap, opts ...ClusterOption) (*RaftCluster, error)
- func (c *RaftCluster) AddMember(m *Member, shouldApplyV3 ShouldApplyV3)
- func (c *RaftCluster) ClientURLs() []string
- func (c *RaftCluster) DowngradeInfo() *serverversion.DowngradeInfo
- func (c *RaftCluster) ID() types.ID
- func (c *RaftCluster) IsIDRemoved(id types.ID) bool
- func (c *RaftCluster) IsLocalMemberLearner() bool
- func (c *RaftCluster) IsMemberExist(id types.ID) bool
- func (c *RaftCluster) IsReadyToAddVotingMember() bool
- func (c *RaftCluster) IsReadyToPromoteMember(id uint64) bool
- func (c *RaftCluster) IsReadyToRemoveVotingMember(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) PromoteMember(id types.ID, shouldApplyV3 ShouldApplyV3)
- func (c *RaftCluster) PushMembershipToStorage()
- func (c *RaftCluster) Recover(onSet func(*zap.Logger, *semver.Version))
- func (c *RaftCluster) RemoveMember(id types.ID, shouldApplyV3 ShouldApplyV3)
- func (c *RaftCluster) SetBackend(be MembershipBackend)
- func (c *RaftCluster) SetDowngradeInfo(d *serverversion.DowngradeInfo, shouldApplyV3 ShouldApplyV3)
- func (c *RaftCluster) SetID(localID, cid types.ID)
- func (c *RaftCluster) SetStore(st v2store.Store)
- func (c *RaftCluster) SetVersion(ver *semver.Version, onSet func(*zap.Logger, *semver.Version), ...)
- func (c *RaftCluster) SetVersionChangedNotifier(n *notify.Notifier)
- func (c *RaftCluster) String() string
- func (c *RaftCluster) UpdateAttributes(id types.ID, attr Attributes, shouldApplyV3 ShouldApplyV3)
- func (c *RaftCluster) UpdateRaftAttributes(id types.ID, raftAttr RaftAttributes, shouldApplyV3 ShouldApplyV3)
- func (c *RaftCluster) ValidateConfigurationChange(cc raftpb.ConfChange) error
- func (c *RaftCluster) Version() *semver.Version
- func (c *RaftCluster) VotingMemberIDs() []types.ID
- func (c *RaftCluster) VotingMembers() []*Member
- type ShouldApplyV3
Constants ¶
const ( ApplyBoth = ShouldApplyV3(true) ApplyV2storeOnly = ShouldApplyV3(false) )
const DefaultMaxLearners = 1
Variables ¶
var ( ErrIDRemoved = errors.New("membership: ID removed") ErrIDExists = errors.New("membership: ID exists") ErrIDNotFound = errors.New("membership: ID not found") ErrPeerURLexists = errors.New("membership: peerURL exists") ErrMemberNotLearner = errors.New("membership: can only promote a learner member") ErrTooManyLearners = errors.New("membership: too many learner members in cluster") )
var ( ClusterVersionMetrics = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: "etcd", Subsystem: "cluster", Name: "version", Help: "Which version is running. 1 for 'cluster_version' label with current cluster version", }, []string{"cluster_version"}) )
var (
StoreMembersPrefix = path.Join(storePrefix, "members")
)
Functions ¶
func IsMetaStoreOnly ¶
IsMetaStoreOnly verifies if the given `store` contains only a meta-information (members, version) that can be recovered from the backend (storev3) as well as opposed to user-data.
func MemberStoreKey ¶
func RemovedMemberStoreKey ¶
func StoreClusterVersionKey ¶
func StoreClusterVersionKey() string
func TrimMembershipFromV2Store ¶
TrimMembershipFromV2Store removes all information about members & removed_members from the v2 store.
func ValidateClusterAndAssignIDs ¶
func ValidateClusterAndAssignIDs(lg *zap.Logger, 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"` ClientURLs []string `json:"clientURLs,omitempty"` }
Attributes represents all the non-raft related attributes of an etcd member.
type ClusterOption ¶
type ClusterOption func(*ClusterOptions)
ClusterOption are options which can be applied to the raft cluster.
func WithMaxLearners ¶
func WithMaxLearners(max int) ClusterOption
WithMaxLearners sets the maximum number of learners that can exist in the cluster membership.
type ClusterOptions ¶
type ClusterOptions struct {
// contains filtered or unexported fields
}
type ClusterVersionBackend ¶
type ConfigChangeContext ¶
type ConfigChangeContext struct { Member // IsPromote indicates if the config change is for promoting a learner member. // This flag is needed because both adding a new member and promoting a learner member // uses the same config change type 'ConfChangeAddNode'. IsPromote bool `json:"isPromote"` }
ConfigChangeContext represents a context for confChange.
type DowngradeInfoBackend ¶
type DowngradeInfoBackend interface { MustSaveDowngradeToBackend(*version.DowngradeInfo) DowngradeInfoFromBackend() *version.DowngradeInfo }
type Member ¶
type Member struct { ID types.ID `json:"id"` RaftAttributes Attributes }
func NewMember ¶
NewMember creates a Member without an ID and generates one based on the cluster name, peer URLs, and time. This is used for bootstrapping/adding new member.
type MemberBackend ¶
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 MembershipBackend ¶
type MembershipBackend interface { ClusterVersionBackend MemberBackend DowngradeInfoBackend MustCreateBackendBuckets() }
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"` // IsLearner indicates if the member is raft learner. IsLearner bool `json:"isLearner,omitempty"` }
RaftAttributes represents the raft related attributes of an etcd member.
type RaftCluster ¶
type RaftCluster struct { sync.Mutex // guards the fields below // contains filtered or unexported fields }
RaftCluster is a list of Members that belong to the same raft cluster
func NewCluster ¶
func NewCluster(lg *zap.Logger, opts ...ClusterOption) *RaftCluster
func NewClusterFromMembers ¶
func NewClusterFromMembers(lg *zap.Logger, id types.ID, membs []*Member, opts ...ClusterOption) *RaftCluster
func NewClusterFromURLsMap ¶
func NewClusterFromURLsMap(lg *zap.Logger, token string, urlsmap types.URLsMap, opts ...ClusterOption) (*RaftCluster, error)
NewClusterFromURLsMap creates a new raft cluster using provided urls map. Currently, it does not support creating cluster with raft learner member.
func (*RaftCluster) AddMember ¶
func (c *RaftCluster) AddMember(m *Member, shouldApplyV3 ShouldApplyV3)
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) ClientURLs ¶
func (c *RaftCluster) ClientURLs() []string
ClientURLs returns a list of all client addresses. The returned list is sorted in ascending lexicographical order.
func (*RaftCluster) DowngradeInfo ¶
func (c *RaftCluster) DowngradeInfo() *serverversion.DowngradeInfo
DowngradeInfo returns the downgrade status of the cluster
func (*RaftCluster) ID ¶
func (c *RaftCluster) ID() types.ID
func (*RaftCluster) IsIDRemoved ¶
func (c *RaftCluster) IsIDRemoved(id types.ID) bool
func (*RaftCluster) IsLocalMemberLearner ¶
func (c *RaftCluster) IsLocalMemberLearner() bool
IsLocalMemberLearner returns if the local member is raft learner
func (*RaftCluster) IsMemberExist ¶
func (c *RaftCluster) IsMemberExist(id types.ID) bool
IsMemberExist returns if the member with the given id exists in cluster.
func (*RaftCluster) IsReadyToAddVotingMember ¶
func (c *RaftCluster) IsReadyToAddVotingMember() bool
func (*RaftCluster) IsReadyToPromoteMember ¶
func (c *RaftCluster) IsReadyToPromoteMember(id uint64) bool
func (*RaftCluster) IsReadyToRemoveVotingMember ¶
func (c *RaftCluster) IsReadyToRemoveVotingMember(id uint64) bool
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
func (*RaftCluster) Members ¶
func (c *RaftCluster) Members() []*Member
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) PromoteMember ¶
func (c *RaftCluster) PromoteMember(id types.ID, shouldApplyV3 ShouldApplyV3)
PromoteMember marks the member's IsLearner RaftAttributes to false.
func (*RaftCluster) PushMembershipToStorage ¶
func (c *RaftCluster) PushMembershipToStorage()
PushMembershipToStorage is overriding storage information about cluster's members, such that they fully reflect internal RaftCluster's storage.
func (*RaftCluster) Recover ¶
func (c *RaftCluster) Recover(onSet func(*zap.Logger, *semver.Version))
func (*RaftCluster) RemoveMember ¶
func (c *RaftCluster) RemoveMember(id types.ID, shouldApplyV3 ShouldApplyV3)
RemoveMember removes a member from the store. The given id MUST exist, or the function panics.
func (*RaftCluster) SetBackend ¶
func (c *RaftCluster) SetBackend(be MembershipBackend)
func (*RaftCluster) SetDowngradeInfo ¶
func (c *RaftCluster) SetDowngradeInfo(d *serverversion.DowngradeInfo, shouldApplyV3 ShouldApplyV3)
func (*RaftCluster) SetID ¶
func (c *RaftCluster) SetID(localID, cid types.ID)
func (*RaftCluster) SetStore ¶
func (c *RaftCluster) SetStore(st v2store.Store)
func (*RaftCluster) SetVersion ¶
func (c *RaftCluster) SetVersion(ver *semver.Version, onSet func(*zap.Logger, *semver.Version), shouldApplyV3 ShouldApplyV3)
func (*RaftCluster) SetVersionChangedNotifier ¶
func (c *RaftCluster) SetVersionChangedNotifier(n *notify.Notifier)
func (*RaftCluster) String ¶
func (c *RaftCluster) String() string
func (*RaftCluster) UpdateAttributes ¶
func (c *RaftCluster) UpdateAttributes(id types.ID, attr Attributes, shouldApplyV3 ShouldApplyV3)
func (*RaftCluster) UpdateRaftAttributes ¶
func (c *RaftCluster) UpdateRaftAttributes(id types.ID, raftAttr RaftAttributes, shouldApplyV3 ShouldApplyV3)
func (*RaftCluster) ValidateConfigurationChange ¶
func (c *RaftCluster) ValidateConfigurationChange(cc raftpb.ConfChange) error
ValidateConfigurationChange takes a proposed ConfChange and ensures that it is still valid.
func (*RaftCluster) Version ¶
func (c *RaftCluster) Version() *semver.Version
func (*RaftCluster) VotingMemberIDs ¶
func (c *RaftCluster) VotingMemberIDs() []types.ID
VotingMemberIDs returns the ID of voting members in cluster.
func (*RaftCluster) VotingMembers ¶
func (c *RaftCluster) VotingMembers() []*Member
type ShouldApplyV3 ¶
type ShouldApplyV3 bool