public PartitionParser(Connection conn, Node node, Dictionary<string, Node[][]> map, int partitionCount, bool requestProleReplicas)
        {
            // Send format 1:  partition-generation\nreplicas-master\n
            // Send format 2:  partition-generation\nreplicas-all\n
            this.partitionCount = partitionCount;
            this.map = map;

            string command = (requestProleReplicas) ? ReplicasAll : ReplicasMaster;
            Info info = new Info(conn, PartitionGeneration, command);
            this.length = info.GetLength();

            if (length == 0)
            {
                throw new AerospikeException.Parse("Partition info is empty");
            }
            this.buffer = info.GetBuffer();

            generation = ParseGeneration();

            if (requestProleReplicas)
            {
                ParseReplicasAll(node);
            }
            else
            {
                ParseReplicasMaster(node);
            }
        }
예제 #2
0
 public NameValueParser(Info parent)
 {
     this.parent = parent;
 }
예제 #3
0
 /// <summary>
 /// Get all the default info from the specified database server node.
 /// </summary>
 /// <param name="conn">socket connection to server node</param>
 public static Dictionary<string, string> Request(Connection conn)
 {
     Info info = new Info(conn);
     return info.ParseMultiResponse();
 }
예제 #4
0
 //-------------------------------------------------------
 // Get Info via Connection
 //-------------------------------------------------------
 /// <summary>
 /// Get one info value by name from the specified database server node.
 /// </summary>
 /// <param name="conn">socket connection to server node</param>
 /// <param name="name">name of value to retrieve</param>
 public static string Request(Connection conn, string name)
 {
     Info info = new Info(conn, name);
     return info.ParseSingleResponse(name);
 }
        public static RegisterTask Register(Cluster cluster, Policy policy, string content, string serverPath, Language language)
        {
            StringBuilder sb = new StringBuilder(serverPath.Length + content.Length + 100);
            sb.Append("udf-put:filename=");
            sb.Append(serverPath);
            sb.Append(";content=");
            sb.Append(content);
            sb.Append(";content-len=");
            sb.Append(content.Length);
            sb.Append(";udf-type=");
            sb.Append(language);
            sb.Append(";");

            // Send UDF to one node. That node will distribute the UDF to other nodes.
            string command = sb.ToString();
            Node node = cluster.GetRandomNode();
            Connection conn = node.GetConnection(policy.timeout);

            try
            {
                Info info = new Info(conn, command);
                Info.NameValueParser parser = info.GetNameValueParser();
                string error = null;
                string file = null;
                string line = null;
                string message = null;

                while (parser.Next())
                {
                    string name = parser.GetName();

                    if (name.Equals("error"))
                    {
                        error = parser.GetValue();
                    }
                    else if (name.Equals("file"))
                    {
                        file = parser.GetValue();
                    }
                    else if (name.Equals("line"))
                    {
                        line = parser.GetValue();
                    }
                    else if (name.Equals("message"))
                    {
                        message = parser.GetStringBase64();
                    }
                }

                if (error != null)
                {
                    throw new AerospikeException("Registration failed: " + error + Environment.NewLine +
                        "File: " + file + Environment.NewLine +
                        "Line: " + line + Environment.NewLine +
                        "Message: " + message
                        );
                }
                node.PutConnection(conn);
                return new RegisterTask(cluster, policy, serverPath);
            }
            catch (Exception)
            {
                conn.Close();
                throw;
            }
        }
        public static RegisterTask Register(Cluster cluster, Policy policy, string content, string serverPath, Language language)
        {
            StringBuilder sb = new StringBuilder(serverPath.Length + content.Length + 100);

            sb.Append("udf-put:filename=");
            sb.Append(serverPath);
            sb.Append(";content=");
            sb.Append(content);
            sb.Append(";content-len=");
            sb.Append(content.Length);
            sb.Append(";udf-type=");
            sb.Append(language);
            sb.Append(";");

            // Send UDF to one node. That node will distribute the UDF to other nodes.
            string     command = sb.ToString();
            Node       node    = cluster.GetRandomNode();
            int        timeout = (policy == null) ? 0 : policy.timeout;
            Connection conn    = node.GetConnection(timeout);

            try
            {
                Info info = new Info(conn, command);
                Info.NameValueParser parser = info.GetNameValueParser();
                string error   = null;
                string file    = null;
                string line    = null;
                string message = null;

                while (parser.Next())
                {
                    string name = parser.GetName();

                    if (name.Equals("error"))
                    {
                        error = parser.GetValue();
                    }
                    else if (name.Equals("file"))
                    {
                        file = parser.GetValue();
                    }
                    else if (name.Equals("line"))
                    {
                        line = parser.GetValue();
                    }
                    else if (name.Equals("message"))
                    {
                        message = parser.GetStringBase64();
                    }
                }

                if (error != null)
                {
                    throw new AerospikeException("Registration failed: " + error + Environment.NewLine +
                                                 "File: " + file + Environment.NewLine +
                                                 "Line: " + line + Environment.NewLine +
                                                 "Message: " + message
                                                 );
                }
                node.PutConnection(conn);
                return(new RegisterTask(cluster, serverPath));
            }
            catch (Exception)
            {
                conn.Close();
                throw;
            }
        }
        //-------------------------------------------------------
        // Internal Methods
        //-------------------------------------------------------
        private string SendInfoCommand(Policy policy, string command)
        {
            Node node = cluster.GetRandomNode();
            Connection conn = node.GetConnection(policy.timeout);
            Info info;

            try
            {
                info = new Info(conn, command);
                node.PutConnection(conn);
            }
            catch (Exception)
            {
                node.CloseConnection(conn);
                throw;
            }
            return info.GetValue();
        }
예제 #8
0
        /// <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)
                    {
                        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(this);
                            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);
            }
        }
예제 #9
0
 public NameValueParser(Info parent)
 {
     this.parent = parent;
 }
예제 #10
0
        /// <summary>
        /// Get all the default info from the specified database server node.
        /// </summary>
        /// <param name="conn">socket connection to server node</param>
        public static Dictionary <string, string> Request(Connection conn)
        {
            Info info = new Info(conn);

            return(info.ParseMultiResponse());
        }
예제 #11
0
        //-------------------------------------------------------
        // Get Info via Connection
        //-------------------------------------------------------

        /// <summary>
        /// Get one info value by name from the specified database server node.
        /// </summary>
        /// <param name="conn">socket connection to server node</param>
        /// <param name="name">name of value to retrieve</param>
        public static string Request(Connection conn, string name)
        {
            Info info = new Info(conn, name);

            return(info.ParseSingleResponse(name));
        }