1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Ensure add newly joined node to networknodes

In cases a node left the cluster and quickly rejoined before the node
entry is expired by other nodes in the cluster, when the node rejoins we
fail to add it to the quick lookup database. Fixed it.

Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
Jana Radhakrishnan 2016-08-19 17:18:15 -07:00
parent 9782a0b8d2
commit 1b027335f1
2 changed files with 16 additions and 1 deletions

View file

@ -53,6 +53,7 @@ func (nDB *NetworkDB) handleNetworkEvent(nEvent *NetworkEvent) bool {
n.leaveTime = time.Now() n.leaveTime = time.Now()
} }
nDB.addNetworkNode(nEvent.NetworkID, nEvent.NodeName)
return true return true
} }
@ -66,7 +67,7 @@ func (nDB *NetworkDB) handleNetworkEvent(nEvent *NetworkEvent) bool {
ltime: nEvent.LTime, ltime: nEvent.LTime,
} }
nDB.networkNodes[nEvent.NetworkID] = append(nDB.networkNodes[nEvent.NetworkID], nEvent.NodeName) nDB.addNetworkNode(nEvent.NetworkID, nEvent.NodeName)
return true return true
} }

View file

@ -453,6 +453,20 @@ func (nDB *NetworkDB) LeaveNetwork(nid string) error {
return nil return nil
} }
// addNetworkNode adds the node to the list of nodes which participate
// in the passed network only if it is not already present. Caller
// should hold the NetworkDB lock while calling this
func (nDB *NetworkDB) addNetworkNode(nid string, nodeName string) {
nodes := nDB.networkNodes[nid]
for _, node := range nodes {
if node == nodeName {
return
}
}
nDB.networkNodes[nid] = append(nDB.networkNodes[nid], nodeName)
}
// Deletes the node from the list of nodes which participate in the // Deletes the node from the list of nodes which participate in the
// passed network. Caller should hold the NetworkDB lock while calling // passed network. Caller should hold the NetworkDB lock while calling
// this // this