/// <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 bool EnsureLogin() { if (performLogin > 0 || (sessionExpiration.HasValue && DateTime.Compare(DateTime.UtcNow, sessionExpiration.Value) >= 0)) { AdminCommand admin = new AdminCommand(ThreadLocalData.GetBuffer(), 0); admin.Login(cluster, tendConnection, out sessionToken, out sessionExpiration); performLogin = 0; return(true); } return(false); }
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; } }
/// <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 { 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); } } } catch (Exception) { tendConnection.Close(); throw; } } } else { if (cluster.user != null) { EnsureLogin(); } } 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); } }