private void ValidateAlias(Cluster cluster, IPAddress ipAddress, int port) { IPEndPoint address = new IPEndPoint(ipAddress, port); Connection conn = new Connection(address, cluster.connectionTimeout); try { if (cluster.user != null) { AdminCommand command = new AdminCommand(); command.Authenticate(conn, cluster.user, cluster.password); } Dictionary <string, string> map = Info.Request(conn, "node", "features"); string nodeName; if (map.TryGetValue("node", out nodeName)) { this.name = nodeName; this.address = address; this.conn = conn; SetFeatures(map); return; } else { throw new AerospikeException.InvalidNode(); } } catch (Exception) { conn.Close(); throw; } }
/// <summary> /// Request current status from server node. /// </summary> /// <param name="friends">other nodes in the cluster, populated by this method</param> /// <exception cref="Exception">if status request fails</exception> public void Refresh(List <Host> friends) { if (tendConnection.IsClosed()) { tendConnection = new Connection(address, cluster.connectionTimeout); } try { string[] commands = cluster.useServicesAlternate ? new string[] { "node", "partition-generation", "services-alternate" } : new string[] { "node", "partition-generation", "services" }; Dictionary <string, string> infoMap = Info.Request(tendConnection, commands); VerifyNodeName(infoMap); if (AddFriends(infoMap, friends)) { UpdatePartitions(tendConnection, infoMap); } } catch (Exception) { // Swallow exception if node was closed in another thread. if (!tendConnection.IsClosed()) { tendConnection.Close(); throw; } } }
/// <summary> /// Query all nodes for task completion status. /// </summary> public override bool QueryIfDone() { // All nodes must respond with complete to be considered done. Node[] nodes = cluster.Nodes; if (nodes.Length == 0) { return(false); } string command = "udf-list"; foreach (Node node in nodes) { string response = Info.Request(policy, node, command); string find = "filename=" + packageName; int index = response.IndexOf(find); if (index < 0) { return(false); } } return(true); }
/// <summary> /// Query all nodes for task completion status. /// </summary> public override int QueryStatus() { // All nodes must respond with complete to be considered done. Node[] nodes = cluster.Nodes; if (nodes.Length == 0) { throw new AerospikeException("Cluster is empty"); } string command = "udf-list"; foreach (Node node in nodes) { string response = Info.Request(policy, node, command); string find = "filename=" + packageName; int index = response.IndexOf(find); if (index < 0) { return(BaseTask.IN_PROGRESS); } } return(BaseTask.COMPLETE); }
// Switch from TLS connection to non-TLS connection. internal SwitchClear(Cluster cluster, Connection conn, byte[] sessionToken) { // Obtain non-TLS addresses. string command = cluster.useServicesAlternate ? "service-clear-alt" : "service-clear-std"; string result = Info.Request(conn, command); List <Host> hosts = Host.ParseServiceHosts(result); Host clearHost; // Find first valid non-TLS host. foreach (Host host in hosts) { try { clearHost = host; string alternativeHost; if (cluster.ipMap != null && cluster.ipMap.TryGetValue(clearHost.name, out alternativeHost)) { clearHost = new Host(alternativeHost, clearHost.port); } IPAddress[] addresses = Connection.GetHostAddresses(clearHost.name, cluster.connectionTimeout); foreach (IPAddress ia in addresses) { try { clearAddress = ia; clearSocketAddress = new IPEndPoint(ia, clearHost.port); clearConn = new Connection(clearSocketAddress, cluster.connectionTimeout, null); try { AdminCommand admin = new AdminCommand(ThreadLocalData.GetBuffer(), 0); if (!admin.Authenticate(cluster, clearConn, sessionToken)) { throw new AerospikeException("Authentication failed"); } return; // Authenticated clear connection. } catch (Exception) { clearConn.Close(); } } catch (Exception) { // Try next address. } } } catch (Exception) { // Try next host. } } throw new AerospikeException("Invalid non-TLS address: " + result); }
/// <summary> /// Query all nodes for task completion status. /// </summary> public override int QueryStatus() { // All nodes must respond with complete to be considered done. Node[] nodes = cluster.Nodes; if (nodes.Length == 0) { throw new AerospikeException("Cluster is empty"); } string command = "sindex/" + ns + '/' + indexName; foreach (Node node in nodes) { string response = Info.Request(policy, node, command); if (isCreate) { // Check if index has been created. string find = "load_pct="; int index = response.IndexOf(find); if (index < 0) { if (response.IndexOf("FAIL:201") >= 0 || response.IndexOf("FAIL:203") >= 0) { // Index not found or not readable. return(BaseTask.NOT_FOUND); } else { // Throw exception immediately. throw new AerospikeException(command + " failed: " + response); } } int begin = index + find.Length; int end = response.IndexOf(';', begin); string str = response.Substring(begin, end - begin); int pct = Convert.ToInt32(str); if (pct != 100) { return(BaseTask.IN_PROGRESS); } } else { // Check if index has been dropped. if (response.IndexOf("FAIL:201") < 0) { // Index still exists. return(BaseTask.IN_PROGRESS); } } } return(BaseTask.COMPLETE); }
/// <summary> /// Request current status from server node. /// </summary> public void Refresh(Peers peers) { if (!active) { return; } try { if (tendConnection.IsClosed()) { tendConnection = cluster.CreateConnection(host.tlsName, address, cluster.connectionTimeout, null); if (cluster.user != null) { try { AdminCommand command = new AdminCommand(ThreadLocalData.GetBuffer(), 0); command.Authenticate(tendConnection, cluster.user, cluster.password); } catch (Exception) { tendConnection.Close(); throw; } } } if (peers.usePeers) { Dictionary <string, string> infoMap = Info.Request(tendConnection, "node", "peers-generation", "partition-generation"); VerifyNodeName(infoMap); VerifyPeersGeneration(infoMap, peers); VerifyPartitionGeneration(infoMap); } else { string[] commands = cluster.useServicesAlternate ? new string[] { "node", "partition-generation", "services-alternate" } : new string[] { "node", "partition-generation", "services" }; Dictionary <string, string> infoMap = Info.Request(tendConnection, commands); VerifyNodeName(infoMap); VerifyPartitionGeneration(infoMap); AddFriends(infoMap, peers); } peers.refreshCount++; failures = 0; } catch (Exception e) { if (peers.usePeers) { peers.genChanged = true; } RefreshFailed(e); } }
/// <summary> /// Request current status from server node. /// </summary> public void Refresh(Peers peers) { if (!active) { return; } try { if (tendConnection.IsClosed()) { tendConnection = CreateConnection(host.tlsName, address, cluster.connectionTimeout, null); if (cluster.user != null) { if (!EnsureLogin()) { AdminCommand command = new AdminCommand(ThreadLocalData.GetBuffer(), 0); if (!command.Authenticate(cluster, tendConnection, sessionToken)) { // Authentication failed. Session token probably expired. // Must login again to get new session token. command.Login(cluster, tendConnection, out sessionToken, out sessionExpiration); } } } } else { if (cluster.user != null) { EnsureLogin(); } } string[] commands = cluster.rackAware ? INFO_PERIODIC_REB : INFO_PERIODIC; Dictionary <string, string> infoMap = Info.Request(tendConnection, commands); VerifyNodeName(infoMap); VerifyPeersGeneration(infoMap, peers); VerifyPartitionGeneration(infoMap); if (cluster.rackAware) { VerifyRebalanceGeneration(infoMap); } peers.refreshCount++; failures = 0; } catch (Exception e) { peers.genChanged = true; RefreshFailed(e); } }
private void ValidateAlias(Cluster cluster, IPAddress ipAddress, Host alias) { IPEndPoint address = new IPEndPoint(ipAddress, alias.port); Connection conn = cluster.CreateConnection(alias.tlsName, address, cluster.connectionTimeout); try { if (cluster.user != null) { AdminCommand command = new AdminCommand(ThreadLocalData.GetBuffer(), 0); command.Authenticate(conn, cluster.user, cluster.password); } Dictionary <string, string> map; bool hasClusterName = cluster.HasClusterName; if (hasClusterName) { map = Info.Request(conn, "node", "features", "cluster-name"); } else { map = Info.Request(conn, "node", "features"); } string nodeName; if (!map.TryGetValue("node", out nodeName)) { throw new AerospikeException.InvalidNode(); } if (hasClusterName) { string id; if (!map.TryGetValue("cluster-name", out id) || !cluster.clusterName.Equals(id)) { throw new AerospikeException.InvalidNode("Node " + nodeName + ' ' + alias + ' ' + " expected cluster name '" + cluster.clusterName + "' received '" + id + "'"); } } this.name = nodeName; this.primaryHost = alias; this.primaryAddress = address; this.conn = conn; SetFeatures(map); } catch (Exception) { conn.Close(); throw; } }
public static ulong ValidateBegin(Node node, string ns) { // Fail when cluster is in migration. string result = Info.Request(node, "cluster-stable:namespace=" + ns); try { return(Convert.ToUInt64(result, 16)); } catch (Exception) { // Yes, even scans return QUERY_ABORTED. throw new AerospikeException(ResultCode.QUERY_ABORTED, "Cluster is in migration: " + result); } }
//------------------------------------------------------- // Get Info via Node //------------------------------------------------------- /// <summary> /// Get one info value by name from the specified database server node. /// This method supports user authentication. /// </summary> /// <param name="node">server node</param> /// <param name="name">name of variable to retrieve</param> public static string Request(Node node, string name) { Connection conn = node.GetConnection(DEFAULT_TIMEOUT); try { string response = Info.Request(conn, name); node.PutConnection(conn); return(response); } catch (Exception) { node.CloseConnection(conn); throw; } }
/// <summary> /// Query all nodes for task completion status. /// </summary> public override bool QueryIfDone() { // All nodes must respond with complete to be considered done. Node[] nodes = cluster.Nodes; if (nodes.Length == 0) { return(false); } string command = "sindex/" + ns + '/' + indexName; foreach (Node node in nodes) { string response = Info.Request(policy, node, command); string find = "load_pct="; int index = response.IndexOf(find); if (index < 0) { if (response.IndexOf("FAIL:201") >= 0 || response.IndexOf("FAIL:203") >= 0) { // Index not found or not readable. Keep waiting because create index may not // have been started yet. throw new AerospikeException(command + " failed: " + response); } else { // Mark done and throw exception immediately. throw new DoneException(command + " failed: " + response); } } int begin = index + find.Length; int end = response.IndexOf(';', begin); string str = response.Substring(begin, end - begin); int pct = Convert.ToInt32(str); if (pct != 100) { return(false); } } return(true); }
/// <summary> /// Query all nodes for task completion status. /// </summary> public override int QueryStatus() { // All nodes must respond with complete to be considered done. Node[] nodes = cluster.ValidateNodes(); foreach (Node node in nodes) { if (isCreate) { // Check index status. if (statusCommand == null) { statusCommand = BuildStatusCommand(ns, indexName); } string response = Info.Request(policy, node, statusCommand); int status = ParseStatusResponse(statusCommand, response, isCreate); if (status != BaseTask.COMPLETE) { return(status); } } else { // Check if index exists. if (existsCommand == null) { existsCommand = BuildExistsCommand(ns, indexName); } string response = Info.Request(policy, node, existsCommand); int status = ParseExistsResponse(existsCommand, response); if (status != BaseTask.COMPLETE) { return(status); } } } return(BaseTask.COMPLETE); }
/// <summary> /// Query all nodes for task completion status. /// </summary> public override int QueryStatus() { // All nodes must respond with complete to be considered done. Node[] nodes = cluster.ValidateNodes(); string command = "udf-list"; foreach (Node node in nodes) { string response = Info.Request(policy, node, command); string find = "filename=" + packageName; int index = response.IndexOf(find); if (index < 0) { return(BaseTask.IN_PROGRESS); } } return(BaseTask.COMPLETE); }
/// <summary> /// Query all nodes for task completion status. /// </summary> public override bool QueryIfDone() { string command = "udf-list"; Node[] nodes = cluster.Nodes; bool done = false; foreach (Node node in nodes) { string response = Info.Request(node, command); string find = "filename=" + packageName; int index = response.IndexOf(find); if (index < 0) { return(false); } done = true; } return(done); }
/// <summary> /// Request current status from server node. /// </summary> /// <param name="friends">other nodes in the cluster, populated by this method</param> /// <exception cref="Exception">if status request fails</exception> public void Refresh(List <Host> friends) { Connection conn = GetConnection(1000); try { Dictionary <string, string> infoMap = Info.Request(conn, "node", "partition-generation", "services"); VerifyNodeName(infoMap); if (AddFriends(infoMap, friends)) { UpdatePartitions(conn, infoMap); } PutConnection(conn); } catch (Exception) { conn.Close(); throw; } }
/// <summary> /// Request current status from server node. /// </summary> public void Refresh(Peers peers) { if (!active) { return; } try { if (tendConnection.IsClosed()) { tendConnection = cluster.CreateConnection(host.tlsName, address, cluster.connectionTimeout); } if (peers.usePeers) { Dictionary <string, string> infoMap = Info.Request(tendConnection, "node", "peers-generation", "partition-generation"); VerifyNodeName(infoMap); VerifyPeersGeneration(infoMap, peers); VerifyPartitionGeneration(infoMap); } else { string[] commands = cluster.useServicesAlternate ? new string[] { "node", "partition-generation", "services-alternate" } : new string[] { "node", "partition-generation", "services" }; Dictionary <string, string> infoMap = Info.Request(tendConnection, commands); VerifyNodeName(infoMap); VerifyPartitionGeneration(infoMap); AddFriends(infoMap, peers); } peers.refreshCount++; failures = 0; } catch (Exception e) { RefreshFailed(e); } }
/// <summary> /// Query all nodes for task completion status. /// </summary> public override bool QueryIfDone() { string command = "sindex/" + ns + '/' + indexName; Node[] nodes = cluster.Nodes; bool complete = false; foreach (Node node in nodes) { try { string response = Info.Request(node, command); string find = "load_pct="; int index = response.IndexOf(find); if (index < 0) { complete = true; continue; } int begin = index + find.Length; int end = response.IndexOf(';', begin); string str = response.Substring(begin, end - begin); int pct = Convert.ToInt32(str); if (pct >= 0 && pct < 100) { return(false); } complete = true; } catch (Exception) { complete = true; } } return(complete); }
private void ValidateAddress(Cluster cluster, IPAddress address, string tlsName, int port, bool detectLoadBalancer) { IPEndPoint socketAddress = new IPEndPoint(address, port); Connection conn = (cluster.tlsPolicy != null) ? new TlsConnection(cluster.tlsPolicy, tlsName, socketAddress, cluster.connectionTimeout, null) : new Connection(socketAddress, cluster.connectionTimeout, null); try { if (cluster.user != null) { // Login AdminCommand admin = new AdminCommand(ThreadLocalData.GetBuffer(), 0); admin.Login(cluster, conn, out sessionToken, out sessionExpiration); if (cluster.tlsPolicy != null && cluster.tlsPolicy.forLoginOnly) { // Switch to using non-TLS socket. SwitchClear sc = new SwitchClear(cluster, conn, sessionToken); conn.Close(); address = sc.clearAddress; socketAddress = sc.clearSocketAddress; conn = sc.clearConn; // Disable load balancer detection since non-TLS address has already // been retrieved via service info command. detectLoadBalancer = false; } } List <string> commands = new List <string>(5); commands.Add("node"); commands.Add("partition-generation"); commands.Add("features"); bool hasClusterName = cluster.HasClusterName; if (hasClusterName) { commands.Add("cluster-name"); } string addressCommand = null; if (detectLoadBalancer) { // Seed may be load balancer with changing address. Determine real address. addressCommand = (cluster.tlsPolicy != null) ? cluster.useServicesAlternate ? "service-tls-alt" : "service-tls-std" : cluster.useServicesAlternate ? "service-clear-alt" : "service-clear-std"; commands.Add(addressCommand); } // Issue commands. Dictionary <string, string> map = Info.Request(conn, commands); // Node returned results. this.primaryHost = new Host(address.ToString(), tlsName, port); this.primaryAddress = socketAddress; this.primaryConn = conn; ValidateNode(map); ValidatePartitionGeneration(map); SetFeatures(map); if (hasClusterName) { ValidateClusterName(cluster, map); } if (addressCommand != null) { SetAddress(cluster, map, addressCommand, tlsName); } } catch (Exception) { conn.Close(); throw; } }
public NodeValidator(Cluster cluster, Host host) { IPAddress[] addresses = Connection.GetHostAddresses(host.name, DEFAULT_TIMEOUT); aliases = new Host[addresses.Length]; for (int i = 0; i < addresses.Length; i++) { aliases[i] = new Host(addresses[i].ToString(), host.port); } Exception exception = null; for (int i = 0; i < addresses.Length; i++) { try { IPEndPoint address = new IPEndPoint(addresses[i], host.port); Connection conn = new Connection(address, cluster.connectionTimeout); try { if (cluster.user != null) { AdminCommand command = new AdminCommand(); command.Authenticate(conn, cluster.user, cluster.password); } Dictionary <string, string> map = Info.Request(conn, "node", "features"); string nodeName; if (map.TryGetValue("node", out nodeName)) { this.name = nodeName; this.address = address; SetFeatures(map); return; } } finally { conn.Close(); } } catch (Exception e) { // Try next address. if (Log.DebugEnabled()) { Log.Debug("Alias " + addresses[i] + " failed: " + Util.GetErrorMessage(e)); } if (exception == null) { exception = e; } } } if (exception == null) { throw new AerospikeException.Connection("Failed to find addresses for " + host); } throw exception; }