From 1b027335f1db74d8346e71f869897c4583a457a8 Mon Sep 17 00:00:00 2001 From: Jana Radhakrishnan Date: Fri, 19 Aug 2016 17:18:15 -0700 Subject: [PATCH] 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 --- libnetwork/networkdb/delegate.go | 3 ++- libnetwork/networkdb/networkdb.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libnetwork/networkdb/delegate.go b/libnetwork/networkdb/delegate.go index 98007516d4..c306e0366d 100644 --- a/libnetwork/networkdb/delegate.go +++ b/libnetwork/networkdb/delegate.go @@ -53,6 +53,7 @@ func (nDB *NetworkDB) handleNetworkEvent(nEvent *NetworkEvent) bool { n.leaveTime = time.Now() } + nDB.addNetworkNode(nEvent.NetworkID, nEvent.NodeName) return true } @@ -66,7 +67,7 @@ func (nDB *NetworkDB) handleNetworkEvent(nEvent *NetworkEvent) bool { ltime: nEvent.LTime, } - nDB.networkNodes[nEvent.NetworkID] = append(nDB.networkNodes[nEvent.NetworkID], nEvent.NodeName) + nDB.addNetworkNode(nEvent.NetworkID, nEvent.NodeName) return true } diff --git a/libnetwork/networkdb/networkdb.go b/libnetwork/networkdb/networkdb.go index f21e572e69..a7aa9bd299 100644 --- a/libnetwork/networkdb/networkdb.go +++ b/libnetwork/networkdb/networkdb.go @@ -453,6 +453,20 @@ func (nDB *NetworkDB) LeaveNetwork(nid string) error { 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 // passed network. Caller should hold the NetworkDB lock while calling // this