/// <summary> /// Initialize server node with connection parameters. /// </summary> /// <param name="cluster">collection of active server nodes</param> /// <param name="nv">connection parameters</param> public Node(Cluster cluster, NodeValidator nv) { this.cluster = cluster; this.name = nv.name; this.aliases = nv.aliases; this.host = nv.primaryHost; this.address = nv.primaryAddress; this.tendConnection = nv.primaryConn; this.sessionToken = nv.sessionToken; this.sessionExpiration = nv.sessionExpiration; this.features = nv.features; connectionPools = new Pool <Connection> [cluster.connPoolsPerNode]; int max = cluster.connectionQueueSize / cluster.connPoolsPerNode; int rem = cluster.connectionQueueSize - (max * cluster.connPoolsPerNode); for (int i = 0; i < connectionPools.Length; i++) { int capacity = i < rem ? max + 1 : max; connectionPools[i] = new Pool <Connection>(capacity); } if (cluster.rackAware) { this.racks = new Dictionary <string, int>(); } else { this.racks = null; } }
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(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. 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 virtual Node CreateNode(NodeValidator nv, bool createMinConn) { Node node = new Node(this, nv); if (createMinConn) { node.CreateMinConnections(); } return(node); }
protected internal override Node CreateNode(NodeValidator nv, bool createMinConn) { AsyncNode node = new AsyncNode(this, nv); if (createMinConn) { node.CreateMinConnections(); } return(node); }
/// <summary> /// Initialize server node with connection parameters. /// </summary> /// <param name="cluster">collection of active server nodes</param> /// <param name="nv">connection parameters</param> public AsyncNode(AsyncCluster cluster, NodeValidator nv) : base(cluster, nv) { this.cluster = cluster; asyncConnQueue = new Pool <AsyncConnection>(cluster.asyncMinConnsPerNode, cluster.asyncMaxConnsPerNode); if (cluster.asyncMinConnsPerNode > 0) { new AsyncConnectorExecutor(cluster, this, cluster.asyncMinConnsPerNode, 20, true); } }
/// <summary> /// Initialize server node with connection parameters. /// </summary> /// <param name="cluster">collection of active server nodes</param> /// <param name="nv">connection parameters</param> public Node(Cluster cluster, NodeValidator nv) { this.cluster = cluster; this.name = nv.name; this.aliases = nv.aliases; this.host = nv.primaryHost; this.address = nv.primaryAddress; this.tendConnection = nv.conn; this.features = nv.features; connectionQueue = new BlockingCollection <Connection>(cluster.connectionQueueSize); }
/// <summary> /// Initialize server node with connection parameters. /// </summary> /// <param name="cluster">collection of active server nodes</param> /// <param name="nv">connection parameters</param> public Node(Cluster cluster, NodeValidator nv) { this.cluster = cluster; this.name = nv.name; this.aliases = nv.aliases; this.address = nv.address; this.hasReplicasAll = nv.hasReplicasAll; // Assign host to first IP alias because the server identifies nodes // by IP address (not hostname). this.host = aliases[0]; connectionQueue = new BlockingCollection <Connection>(cluster.connectionQueueSize); }
/// <summary> /// Initialize server node with connection parameters. /// </summary> /// <param name="cluster">collection of active server nodes</param> /// <param name="nv">connection parameters</param> public Node(Cluster cluster, NodeValidator nv) { this.cluster = cluster; this.name = nv.name; this.aliases = nv.aliases; this.address = nv.address; this.hasDouble = nv.hasDouble; this.hasBatchIndex = nv.hasBatchIndex; this.hasReplicasAll = nv.hasReplicasAll; // Assign host to first IP alias because the server identifies nodes // by IP address (not hostname). this.host = aliases[0]; connectionQueue = new BlockingCollection<Connection>(cluster.connectionQueueSize); }
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); } }
/// <summary> /// Initialize server node with connection parameters. /// </summary> /// <param name="cluster">collection of active server nodes</param> /// <param name="nv">connection parameters</param> public Node(Cluster cluster, NodeValidator nv) { this.cluster = cluster; this.name = nv.name; this.aliases = nv.aliases; this.host = nv.primaryHost; this.address = nv.primaryAddress; this.tendConnection = nv.conn; this.features = nv.features; connectionPools = new Pool[cluster.connPoolsPerNode]; int max = cluster.connectionQueueSize / cluster.connPoolsPerNode; int rem = cluster.connectionQueueSize - (max * cluster.connPoolsPerNode); for (int i = 0; i < connectionPools.Length; i++) { int capacity = i < rem ? max + 1 : max; connectionPools[i] = new Pool(capacity); } }
/// <summary> /// Initialize server node with connection parameters. /// </summary> /// <param name="cluster">collection of active server nodes</param> /// <param name="nv">connection parameters</param> public Node(Cluster cluster, NodeValidator nv) { this.cluster = cluster; this.name = nv.name; this.aliases = nv.aliases; this.host = nv.primaryHost; this.address = nv.primaryAddress; this.tendConnection = nv.primaryConn; this.sessionToken = nv.sessionToken; this.sessionExpiration = nv.sessionExpiration; this.features = nv.features; if (cluster.rackAware) { this.racks = new Dictionary <string, int>(); } else { this.racks = null; } connectionPools = new Pool <Connection> [cluster.connPoolsPerNode]; int min = cluster.minConnsPerNode / cluster.connPoolsPerNode; int remMin = cluster.minConnsPerNode - (min * cluster.connPoolsPerNode); int max = cluster.maxConnsPerNode / cluster.connPoolsPerNode; int remMax = cluster.maxConnsPerNode - (max * cluster.connPoolsPerNode); for (int i = 0; i < connectionPools.Length; i++) { int minSize = i < remMin ? min + 1 : min; int maxSize = i < remMax ? max + 1 : max; Pool <Connection> pool = new Pool <Connection>(minSize, maxSize); connectionPools[i] = pool; if (minSize > 0) { CreateConnections(pool, minSize); } } }
protected internal virtual Node CreateNode(NodeValidator nv) { return(new Node(this, nv)); }
protected internal override Node CreateNode(NodeValidator nv) { return new AsyncNode(this, nv); }
/// <summary> /// Initialize server node with connection parameters. /// </summary> /// <param name="cluster">collection of active server nodes</param> /// <param name="nv">connection parameters</param> public AsyncNode(AsyncCluster cluster, NodeValidator nv) : base(cluster, nv) { this.cluster = cluster; asyncConnQueue = new Pool <AsyncConnection>(cluster.asyncMinConnsPerNode, cluster.asyncMaxConnsPerNode); }
private bool SeedNodes(bool failIfNotConnected) { // Must copy array reference for copy on write semantics to work. Host[] seedArray = seeds; Exception[] exceptions = null; // Add all nodes at once to avoid copying entire array multiple times. List <Node> list = new List <Node>(); for (int i = 0; i < seedArray.Length; i++) { Host seed = seedArray[i]; // Check if seed already exists in cluster. if (aliases.ContainsKey(seed)) { continue; } try { NodeValidator nv = new NodeValidator(); nv.SeedNodes(this, seed, list); } catch (Exception e) { if (Log.WarnEnabled()) { Log.Warn("Seed " + seed + " failed: " + Util.GetErrorMessage(e)); } // Store exception and try next host if (failIfNotConnected) { if (exceptions == null) { exceptions = new Exception[seedArray.Length]; } exceptions[i] = e; } } } if (list.Count > 0) { AddNodesCopy(list); return(true); } else if (failIfNotConnected) { StringBuilder sb = new StringBuilder(500); sb.AppendLine("Failed to connect to host(s): "); for (int i = 0; i < seedArray.Length; i++) { sb.Append(seedArray[i]); sb.Append(' '); Exception ex = exceptions[i]; if (ex != null) { sb.AppendLine(ex.Message); } } throw new AerospikeException.Connection(sb.ToString()); } return(false); }
private bool SeedNodes(bool failIfNotConnected) { // Must copy array reference for copy on write semantics to work. Host[] seedArray = seeds; Exception[] exceptions = null; // Add all nodes at once to avoid copying entire array multiple times. List <Node> list = new List <Node>(); for (int i = 0; i < seedArray.Length; i++) { Host seed = seedArray[i]; // Check if seed already exists in cluster. if (aliases.ContainsKey(seed)) { continue; } try { // Try to communicate with seed. NodeValidator seedNodeValidator = new NodeValidator(this, seed); // Seed host may have multiple aliases in the case of round-robin dns configurations. foreach (Host alias in seedNodeValidator.aliases) { NodeValidator nv; if (alias.Equals(seed)) { nv = seedNodeValidator; } else { nv = new NodeValidator(this, alias); } if (!FindNodeName(list, nv.name)) { Node node = CreateNode(nv); AddAliases(node); list.Add(node); } } } catch (Exception e) { if (Log.WarnEnabled()) { Log.Warn("Seed " + seed + " failed: " + Util.GetErrorMessage(e)); } // Store exception and try next host if (failIfNotConnected) { if (exceptions == null) { exceptions = new Exception[seedArray.Length]; } exceptions[i] = e; } } } if (list.Count > 0) { AddNodesCopy(list); return(true); } else if (failIfNotConnected) { StringBuilder sb = new StringBuilder(500); sb.AppendLine("Failed to connect to host(s): "); for (int i = 0; i < seedArray.Length; i++) { sb.Append(seedArray[i]); sb.Append(' '); Exception ex = exceptions[i]; if (ex != null) { sb.AppendLine(ex.Message); } } throw new AerospikeException.Connection(sb.ToString()); } return(false); }
private bool SeedNode(Peers peers, bool failIfNotConnected) { // Must copy array reference for copy on write semantics to work. Host[] seedArray = seeds; Exception[] exceptions = null; NodeValidator nv = new NodeValidator(); for (int i = 0; i < seedArray.Length; i++) { Host seed = seedArray[i]; try { Node node = nv.SeedNode(this, seed, peers); if (node != null) { AddNode(node); return(true); } } catch (Exception e) { // Store exception and try next seed. if (failIfNotConnected) { if (exceptions == null) { exceptions = new Exception[seedArray.Length]; } exceptions[i] = e; } else { if (Log.WarnEnabled()) { Log.Warn("Seed " + seed + " failed: " + Util.GetErrorMessage(e)); } } } } // No seeds valid. Use fallback node if it exists. if (nv.fallback != null) { AddNode(nv.fallback); return(true); } if (failIfNotConnected) { StringBuilder sb = new StringBuilder(500); sb.AppendLine("Failed to connect to host(s): "); for (int i = 0; i < seedArray.Length; i++) { sb.Append(seedArray[i]); sb.Append(' '); Exception ex = exceptions[i]; if (ex != null) { sb.AppendLine(ex.Message); } } throw new AerospikeException.Connection(sb.ToString()); } return(false); }
private bool SeedNodes(bool failIfNotConnected) { // Must copy array reference for copy on write semantics to work. Host[] seedArray = seeds; Exception[] exceptions = null; // Add all nodes at once to avoid copying entire array multiple times. List<Node> list = new List<Node>(); for (int i = 0; i < seedArray.Length; i++) { Host seed = seedArray[i]; // Check if seed already exists in cluster. if (aliases.ContainsKey(seed)) { continue; } try { // Try to communicate with seed. NodeValidator seedNodeValidator = new NodeValidator(this, seed); // Seed host may have multiple aliases in the case of round-robin dns configurations. foreach (Host alias in seedNodeValidator.aliases) { NodeValidator nv; if (alias.Equals(seed)) { nv = seedNodeValidator; } else { nv = new NodeValidator(this, alias); } if (!FindNodeName(list, nv.name)) { Node node = CreateNode(nv); AddAliases(node); list.Add(node); } } } catch (Exception e) { if (Log.WarnEnabled()) { Log.Warn("Seed " + seed + " failed: " + Util.GetErrorMessage(e)); } // Store exception and try next host if (failIfNotConnected) { if (exceptions == null) { exceptions = new Exception[seedArray.Length]; } exceptions[i] = e; } } } if (list.Count > 0) { AddNodesCopy(list); return true; } else if (failIfNotConnected) { StringBuilder sb = new StringBuilder(500); sb.AppendLine("Failed to connect to host(s): "); for (int i = 0; i < seedArray.Length; i++) { sb.Append(seedArray[i]); sb.Append(' '); Exception ex = exceptions[i]; if (ex != null) { sb.AppendLine(ex.Message); } } throw new AerospikeException.Connection(sb.ToString()); } return false; }
private bool SeedNodes(bool failIfNotConnected) { // Must copy array reference for copy on write semantics to work. Host[] seedArray = seeds; Exception[] exceptions = null; // Add all nodes at once to avoid copying entire array multiple times. List<Node> list = new List<Node>(); for (int i = 0; i < seedArray.Length; i++) { Host seed = seedArray[i]; // Check if seed already exists in cluster. if (aliases.ContainsKey(seed)) { continue; } try { NodeValidator nv = new NodeValidator(); nv.SeedNodes(this, seed, list); } catch (Exception e) { if (Log.WarnEnabled()) { Log.Warn("Seed " + seed + " failed: " + Util.GetErrorMessage(e)); } // Store exception and try next host if (failIfNotConnected) { if (exceptions == null) { exceptions = new Exception[seedArray.Length]; } exceptions[i] = e; } } } if (list.Count > 0) { AddNodesCopy(list); return true; } else if (failIfNotConnected) { StringBuilder sb = new StringBuilder(500); sb.AppendLine("Failed to connect to host(s): "); for (int i = 0; i < seedArray.Length; i++) { sb.Append(seedArray[i]); sb.Append(' '); Exception ex = exceptions[i]; if (ex != null) { sb.AppendLine(ex.Message); } } throw new AerospikeException.Connection(sb.ToString()); } return false; }
protected internal virtual Node CreateNode(NodeValidator nv) { return new Node(this, nv); }
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(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. 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; }
/// <summary> /// Initialize server node with connection parameters. /// </summary> /// <param name="cluster">collection of active server nodes</param> /// <param name="nv">connection parameters</param> public AsyncNode(AsyncCluster cluster, NodeValidator nv) : base(cluster, nv) { this.cluster = cluster; asyncConnQueue = new ConcurrentQueue <AsyncConnection>(); }
private bool SeedNode(bool failIfNotConnected) { // Must copy array reference for copy on write semantics to work. Host[] seedArray = seeds; Exception[] exceptions = null; for (int i = 0; i < seedArray.Length; i++) { Host seed = seedArray[i]; try { NodeValidator nv = new NodeValidator(); Node node = nv.SeedNode(this, seed); Dictionary <string, Node> nodesToAdd = new Dictionary <string, Node>(1); nodesToAdd[node.Name] = node; AddNodes(nodesToAdd); return(true); } catch (Exception e) { // Store exception and try next seed. if (failIfNotConnected) { if (exceptions == null) { exceptions = new Exception[seedArray.Length]; } exceptions[i] = e; } else { if (Log.WarnEnabled()) { Log.Warn("Seed " + seed + " failed: " + Util.GetErrorMessage(e)); } } } } if (failIfNotConnected) { StringBuilder sb = new StringBuilder(500); sb.AppendLine("Failed to connect to host(s): "); for (int i = 0; i < seedArray.Length; i++) { sb.Append(seedArray[i]); sb.Append(' '); Exception ex = exceptions[i]; if (ex != null) { sb.AppendLine(ex.Message); } } throw new AerospikeException.Connection(sb.ToString()); } return(false); }
/// <summary> /// Initialize server node with connection parameters. /// </summary> /// <param name="cluster">collection of active server nodes</param> /// <param name="nv">connection parameters</param> public AsyncNode(AsyncCluster cluster, NodeValidator nv) : base(cluster, nv) { this.cluster = cluster; asyncConnQueue = new Pool <AsyncConnection>(cluster.maxCommands); }
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); } }
protected internal override Node CreateNode(NodeValidator nv) { return(new AsyncNode(this, nv)); }
/// <summary> /// Initialize server node with connection parameters. /// </summary> /// <param name="cluster">collection of active server nodes</param> /// <param name="nv">connection parameters</param> public AsyncNode(AsyncCluster cluster, NodeValidator nv) : base(cluster, nv) { this.cluster = cluster; asyncConnQueue = new BlockingCollection<AsyncConnection>(cluster.MaxCommands); }
/// <summary> /// Initialize server node with connection parameters. /// </summary> /// <param name="cluster">collection of active server nodes</param> /// <param name="nv">connection parameters</param> public AsyncNode(AsyncCluster cluster, NodeValidator nv) : base(cluster, nv) { this.cluster = cluster; asyncConnQueue = new BlockingCollection <AsyncConnection>(cluster.MaxCommands); }