Skip to content

Commit

Permalink
etcdserver/membership: add "InitialAddNotify"
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Mar 8, 2018
1 parent 6371853 commit 1d215d8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions etcdserver/membership/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ type RaftCluster struct {
// removed contains the ids of removed members in the cluster.
// removed id cannot be reused.
removed map[types.ID]bool

initAddNotifyOnce *sync.Once
initAddNotifyCh chan struct{}
}

func NewClusterFromURLsMap(token string, urlsmap types.URLsMap) (*RaftCluster, error) {
Expand Down Expand Up @@ -81,9 +84,11 @@ func NewClusterFromMembers(token string, id types.ID, membs []*Member) *RaftClus

func NewCluster(token string) *RaftCluster {
return &RaftCluster{
token: token,
members: make(map[types.ID]*Member),
removed: make(map[types.ID]bool),
token: token,
members: make(map[types.ID]*Member),
removed: make(map[types.ID]bool),
initAddNotifyOnce: new(sync.Once),
initAddNotifyCh: make(chan struct{}),
}
}

Expand Down Expand Up @@ -295,9 +300,16 @@ func (c *RaftCluster) AddMember(m *Member) {

c.members[m.ID] = m

if c.initAddNotifyOnce != nil {
c.initAddNotifyOnce.Do(func() { close(c.initAddNotifyCh) })
}
plog.Infof("added member %s %v to cluster %s", m.ID, m.PeerURLs, c.id)
}

// InitialAddNotify returns a channel that closes when
// the first member is added to the cluster
func (c *RaftCluster) InitialAddNotify() <-chan struct{} { return c.initAddNotifyCh }

// RemoveMember removes a member from the store.
// The given id MUST exist, or the function panics.
func (c *RaftCluster) RemoveMember(id types.ID) {
Expand Down

0 comments on commit 1d215d8

Please sign in to comment.