membership

package
v0.0.0-...-16dfdc2 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MembersKeyPrefix = "membership_membersKeyPrefix"
	MetaKeyPrefix    = "membership_metaKeyPrefix"
)

Variables

View Source
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")
)

Functions

func ValidateClusterAndAssignIDs

func ValidateClusterAndAssignIDs(local *Membership, existing *Membership) 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 Member

type Member struct {

	// Member ID, which generate by urls, raft group name and time(if exists)
	ID types.ID `json:"id"`

	// VDL server name
	Name string `json:"name,omitempty"`

	// peer urls
	PeerURLs []string `json:"peerURLs"`
}

func NewMember

func NewMember(serverName string, peerURLs types.URLs, groupName string, now *time.Time) *Member

NewMember creates a Member without an ID and generates one based on the raft group name, peer URLs and time(if not nil). This is used for bootstrapping/adding new member.

func (*Member) Clone

func (m *Member) Clone() *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 Membership

type Membership struct {
	MembershipMeta

	MembershipMembers

	// raft group name
	RaftGroupName string `json:"-"`

	//vdl server name
	ServerName string `json:"-"`

	// guards the fields below
	sync.Mutex
	// contains filtered or unexported fields
}

func NewMembershipFromInitialPeerURLsMap

func NewMembershipFromInitialPeerURLsMap(initialPeerURLsMap types.URLsMap, raftGroupName string,
	vdlServerName string, stableStore stablestore.StableStore) (*Membership, error)

use for start a new Raft Group it will use InitialPeerURLs on configuration NOTICE: it just load the InitialPeerURLs and put into memory struct, but didn't persistent

func NewMembershipFromStore

func NewMembershipFromStore(raftGroupName string, stableStore stablestore.StableStore,
	vdlServerName string) *Membership

func (*Membership) AddMemberAndPersistence

func (c *Membership) AddMemberAndPersistence(member *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 (*Membership) GetMemberFromStore

func (c *Membership) GetMemberFromStore(ID uint64) *Member

func (*Membership) GetSelfMemberID

func (c *Membership) GetSelfMemberID() types.ID

func (*Membership) IsIDInMembership

func (c *Membership) IsIDInMembership(id types.ID) bool

func (*Membership) IsIDRemoved

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

func (*Membership) IsMemberIDExistsInStore

func (c *Membership) IsMemberIDExistsInStore(ID uint64) bool

check whether ID exists in store(after apply)

func (*Membership) Member

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

func (*Membership) MemberByName

func (c *Membership) 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 (*Membership) MemberCount

func (c *Membership) MemberCount() int

func (*Membership) MemberIDs

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

func (*Membership) Members

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

func (*Membership) PersistenceMeta

func (c *Membership) PersistenceMeta()

func (*Membership) Print

func (c *Membership) Print()

func (*Membership) RemoveMemberAndPersistence

func (c *Membership) RemoveMemberAndPersistence(id types.ID)

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

func (*Membership) RemovedIDs

func (c *Membership) RemovedIDs() []types.ID

func (*Membership) UpdateMemberAndPersistence

func (c *Membership) UpdateMemberAndPersistence(member *Member)

func (*Membership) ValidateConfigurationChange

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

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

type MembershipMembers

type MembershipMembers struct {
	MembersMap map[types.ID]*Member `json:"members"`

	// removed contains the ids of removed members in the cluster.
	// removed id cannot be reused.
	RemovedMap map[types.ID]bool `json:"removed"`
}

type MembershipMeta

type MembershipMeta struct {

	// cluster ID
	// which generate by membersID which from initial-cluster when create new Raft Group
	// This ClusterID use to check whether the same cluster for cross-cluster-interaction
	ClusterID types.ID `json:"clusterID"`

	//version for membership
	Version MembershipVersion `json:"version"`

	//self memberid
	SelfMemberID types.ID `json:"name,omitempty"`
}

type MembershipStore

type MembershipStore struct {

	// guards the db
	sync.Mutex
	// contains filtered or unexported fields
}

func NewMembershipStore

func NewMembershipStore(stableStore stablestore.StableStore) *MembershipStore

func (*MembershipStore) AddMember

func (s *MembershipStore) AddMember(member *Member, groupName string)

func (*MembershipStore) DeleteMember

func (s *MembershipStore) DeleteMember(id types.ID, groupName string)

func (*MembershipStore) GetMembers

func (s *MembershipStore) GetMembers(groupName string) *MembershipMembers

when no members in store, return nil

func (*MembershipStore) GetMeta

func (s *MembershipStore) GetMeta(groupName string) *MembershipMeta

when no member meta in store, return nil

func (*MembershipStore) SaveMeta

func (s *MembershipStore) SaveMeta(meta *MembershipMeta, groupName string)

func (*MembershipStore) UpdateMember

func (s *MembershipStore) UpdateMember(member *Member, groupName string)

type MembershipVersion

type MembershipVersion uint32

0 for VDL 1.0.0 currently

Jump to

Keyboard shortcuts

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