private bool PrepareFriend(Host host, Peers peers) { try { NodeValidator nv = new NodeValidator(); nv.ValidateNode(cluster, host); // Check for duplicate nodes in nodes slated to be added. Node node; if (peers.nodes.TryGetValue(nv.name, out node)) { // Duplicate node name found. This usually occurs when the server // services list contains both internal and external IP addresses // for the same node. nv.primaryConn.Close(); peers.hosts.Add(host); node.aliases.Add(host); return(true); } // Check for duplicate nodes in cluster. if (cluster.nodesMap.TryGetValue(nv.name, out node)) { nv.primaryConn.Close(); peers.hosts.Add(host); node.aliases.Add(host); node.referenceCount++; cluster.aliases[host] = node; return(true); } node = cluster.CreateNode(nv); peers.hosts.Add(host); peers.nodes[nv.name] = node; return(true); } catch (Exception e) { if (Log.WarnEnabled()) { Log.Warn("Add node " + host + " failed: " + Util.GetErrorMessage(e)); } return(false); } }
private List <Node> FindNodesToAdd(List <Host> hosts) { List <Node> list = new List <Node>(hosts.Count); foreach (Host host in hosts) { try { NodeValidator nv = new NodeValidator(); nv.ValidateNode(this, host); Node node = FindNode(nv.name, list); if (node != null) { // Duplicate node name found. This usually occurs when the server // services list contains both internal and external IP addresses // for the same node. Add new host to list of alias filters // and do not add new node. nv.conn.Close(); node.referenceCount++; node.AddAlias(host); aliases[host] = node; continue; } node = CreateNode(nv); list.Add(node); } catch (Exception e) { if (Log.WarnEnabled()) { Log.Warn("Add node " + host + " failed: " + Util.GetErrorMessage(e)); } } } return(list); }
protected internal void RefreshPeers(Peers peers) { // Do not refresh peers when node connection has already failed during this cluster tend iteration. if (failures > 0 || !active) { return; } try { if (Log.DebugEnabled()) { Log.Debug("Update peers for node " + this); } PeerParser parser = new PeerParser(cluster, tendConnection, peers.peers); peersCount = peers.peers.Count; bool peersValidated = true; foreach (Peer peer in peers.peers) { if (FindPeerNode(cluster, peers, peer.nodeName)) { // Node already exists. Do not even try to connect to hosts. continue; } bool nodeValidated = false; // Find first host that connects. foreach (Host host in peer.hosts) { try { // Attempt connection to host. NodeValidator nv = new NodeValidator(); nv.ValidateNode(cluster, host); if (!peer.nodeName.Equals(nv.name)) { // Must look for new node name in the unlikely event that node names do not agree. if (Log.WarnEnabled()) { Log.Warn("Peer node " + peer.nodeName + " is different than actual node " + nv.name + " for host " + host); } if (FindPeerNode(cluster, peers, nv.name)) { // Node already exists. Do not even try to connect to hosts. nv.primaryConn.Close(); nodeValidated = true; break; } } // Create new node. Node node = cluster.CreateNode(nv); peers.nodes[nv.name] = node; nodeValidated = true; break; } catch (Exception e) { if (Log.WarnEnabled()) { Log.Warn("Add node " + host + " failed: " + Util.GetErrorMessage(e)); } } } if (!nodeValidated) { peersValidated = false; } } // Only set new peers generation if all referenced peers are added to the cluster. if (peersValidated) { peersGeneration = parser.generation; } peers.refreshCount++; } catch (Exception e) { RefreshFailed(e); } }
private List<Node> FindNodesToAdd(List<Host> hosts) { List<Node> list = new List<Node>(hosts.Count); foreach (Host host in hosts) { try { NodeValidator nv = new NodeValidator(); nv.ValidateNode(this, host); Node node = FindNode(nv.name, list); if (node != null) { // Duplicate node name found. This usually occurs when the server // services list contains both internal and external IP addresses // for the same node. Add new host to list of alias filters // and do not add new node. nv.conn.Close(); node.referenceCount++; node.AddAlias(host); aliases[host] = node; continue; } node = CreateNode(nv); list.Add(node); } catch (Exception e) { if (Log.WarnEnabled()) { Log.Warn("Add node " + host + " failed: " + Util.GetErrorMessage(e)); } } } return list; }