Skip to content
Snippets Groups Projects
Commit 426337d9 authored by kaiyou's avatar kaiyou
Browse files

Fix a startup race condition in sml

parent e97d555d
No related branches found
No related tags found
No related merge requests found
...@@ -54,15 +54,15 @@ func (m *Memberlist[M, S, MP, SP]) MergeRemoteState(buf []byte, join bool) { ...@@ -54,15 +54,15 @@ func (m *Memberlist[M, S, MP, SP]) MergeRemoteState(buf []byte, join bool) {
// Cluster implements the EventDelegate interface // Cluster implements the EventDelegate interface
func (m *Memberlist[M, S, MP, SP]) NotifyJoin(n *memberlist.Node) { func (m *Memberlist[M, S, MP, SP]) NotifyJoin(n *memberlist.Node) {
logrus.Debug("node joined: ", n.Name) logrus.Debug("node joined: ", n.Name)
go m.updateCache() m.nodeChanges <- struct{}{}
} }
// Node implements the EventDelegate interface // Node implements the EventDelegate interface
func (m *Memberlist[M, S, MP, SP]) NotifyLeave(n *memberlist.Node) { func (m *Memberlist[M, S, MP, SP]) NotifyLeave(n *memberlist.Node) {
go m.updateCache() m.nodeChanges <- struct{}{}
} }
// Node implements the EventDelegate interface // Node implements the EventDelegate interface
func (m *Memberlist[M, S, MP, SP]) NotifyUpdate(n *memberlist.Node) { func (m *Memberlist[M, S, MP, SP]) NotifyUpdate(n *memberlist.Node) {
go m.updateCache() m.nodeChanges <- struct{}{}
} }
...@@ -89,6 +89,7 @@ func (m *Memberlist[M, S, MP, SP]) Run() error { ...@@ -89,6 +89,7 @@ func (m *Memberlist[M, S, MP, SP]) Run() error {
go m.join() go m.join()
case <-m.nodeChanges: case <-m.nodeChanges:
logrus.Debug("network topology changed, a node just joined, left or was updated") logrus.Debug("network topology changed, a node just joined, left or was updated")
m.updateCache()
for _, node := range m.Nodes() { for _, node := range m.Nodes() {
logrus.Debugf("* %s [%s]\n", node.Name, node.NodeMeta.String()) logrus.Debugf("* %s [%s]\n", node.Name, node.NodeMeta.String())
} }
...@@ -127,11 +128,6 @@ func (m *Memberlist[M, S, MP, SP]) Update() { ...@@ -127,11 +128,6 @@ func (m *Memberlist[M, S, MP, SP]) Update() {
// Update the node cache after a network change, goes through all the // Update the node cache after a network change, goes through all the
// nodes and decodes metadata // nodes and decodes metadata
func (m *Memberlist[M, S, MP, SP]) updateCache() { func (m *Memberlist[M, S, MP, SP]) updateCache() {
// Do not update the node cache until memberlist is setup
if m.ml == nil {
logrus.Debug("not updating the node cache before memberlist is ready")
return
}
members := m.ml.Members() members := m.ml.Members()
logrus.Debugf("updating the node cache with %d members", len(members)) logrus.Debugf("updating the node cache with %d members", len(members))
var cache []Node[M, MP] var cache []Node[M, MP]
...@@ -146,7 +142,6 @@ func (m *Memberlist[M, S, MP, SP]) updateCache() { ...@@ -146,7 +142,6 @@ func (m *Memberlist[M, S, MP, SP]) updateCache() {
} }
} }
m.nodeCache = cache m.nodeCache = cache
m.nodeChanges <- struct{}{}
} }
// Try and join any anchor that is not currently a cluster member // Try and join any anchor that is not currently a cluster member
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment