Exemplo n.º 1
0
        /// <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);
            }
        }
Exemplo n.º 2
0
        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;
            }
        }
        /// <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);
            }
        }
Exemplo n.º 4
0
        /// <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)
                {
                    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);
                    }
                }
                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);
            }
        }