Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

etcdserver: adjust election timeout on restart #9364

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
etcdserver/membership: add "InitialAddNotify"
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
gyuho committed Mar 8, 2018
commit 1d215d812a57da4d84698014444b5b0b62af15b6
18 changes: 15 additions & 3 deletions etcdserver/membership/cluster.go
Original file line number Diff line number Diff line change
@@ -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) {
@@ -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{}),
}
}

@@ -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) {