From b7b92913d9c0013e21f7e582fcd9c0cb47565212 Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Tue, 6 Mar 2018 15:13:24 -0600 Subject: [PATCH] Add comment to listenForJoins --- cluster.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cluster.go b/cluster.go index 12d6fba50..dcb9e0ecc 100644 --- a/cluster.go +++ b/cluster.go @@ -1002,7 +1002,13 @@ func (c *Cluster) ListenForJoins() { } func (c *Cluster) listenForJoins() { - var uriJoined bool + // When a cluster starts, the state is STARTING. + // We first want to wait for at least one node to join. + // Then we want to clear out the joiningLeavingNodes queue (buffered channel). + // Then we want to set the cluster state to NORMAL and resume processing of joiningLeavingNodes events. + // We use a bool `setNormal` to indicate when at least one node has joined. + + var setNormal bool for { @@ -1014,13 +1020,13 @@ func (c *Cluster) listenForJoins() { c.logger().Printf("handleNodeAction error: err=%s", err) continue } - uriJoined = true + setNormal = true continue default: } // Only change state to NORMAL if we have successfully added at least one host. - if uriJoined { + if setNormal { // Put the cluster back to state NORMAL and broadcast. if err := c.setStateAndBroadcast(ClusterStateNormal); err != nil { c.logger().Printf("setStateAndBroadcast error: err=%s", err) @@ -1037,7 +1043,7 @@ func (c *Cluster) listenForJoins() { c.logger().Printf("handleNodeAction error: err=%s", err) continue } - uriJoined = true + setNormal = true continue } }