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);
            }
        }
Exemplo n.º 2
0
 public BatchNode(Node node, int capacity, int offset)
 {
     this.node = node;
     this.offsets = new int[capacity];
     this.offsets[0] = offset;
     this.offsetsSize = 1;
 }
 private void GetNamespaceConfig(Node node)
 {
     string filter = "namespace/" + args.ns;
     string tokens = Info.Request(null, node, filter);
     Assert.IsNotNull(tokens);
     LogNameValueTokens(tokens);
 }
 public QueryRecordCommand(Node node, Policy policy, Statement statement, RecordSet recordSet)
     : base(node, true)
 {
     this.policy = policy;
     this.statement = statement;
     this.recordSet = recordSet;
 }
Exemplo n.º 5
0
        public BatchNode(Node node, Key[] keys)
        {
            this.node = node;
            this.offsets = new int[keys.Length];
            this.offsetsSize = keys.Length;

            for (int i = 0; i < offsetsSize; i++)
            {
                offsets[i] = i;
            }
        }
        public QueryAggregateCommand(
			Node node,
			Policy policy,
			Statement statement,
			BlockingCollection<object> inputQueue,
			CancellationToken cancelToken
		)
            : base(node, true)
        {
            this.policy = policy;
            this.statement = statement;
            this.inputQueue = inputQueue;
            this.cancelToken = cancelToken;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Query namespace configuration.
        /// </summary>
        private void GetNamespaceConfig(Node node, Arguments args)
        {
            console.Write("Namespace Configuration");
            string filter = "namespace/" + args.ns;
            string tokens = Info.Request(node, filter);

            if (tokens == null)
            {
                throw new Exception(string.Format("Failed to get namespace info: host={0} namespace={1}",
                    node, args.ns));
            }

            LogNameValueTokens(tokens);
        }
Exemplo n.º 8
0
        public ScanCommand(
			Node node, 
			ScanPolicy policy,
			string ns,
			string setName,
			ScanCallback callback,
			string[] binNames,
			long taskId
		)
            : base(node, true)
        {
            this.policy = policy;
            this.ns = ns;
            this.setName = setName;
            this.callback = callback;
            this.binNames = binNames;
            this.taskId = taskId;
        }
        private void GetServerConfig(Node node)
        {
            IDictionary<string, string> map = Info.Request(null, node);
            Assert.IsNotNull(map);

            foreach (KeyValuePair<string, string> entry in map)
            {
                string key = entry.Key;

                if (key.Equals("statistics") || key.Equals("query-stat"))
                {
                    LogNameValueTokens(entry.Value);
                }
                else
                {
                    if (!(key.Equals("services-alumni") || key.Equals("services")))
                    {
                        Assert.IsNotNull(entry.Value);
                    }
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Query server configuration and cluster status.
        /// </summary>
        private void GetServerConfig(Node node, Arguments args)
        {
            console.Write("Server Configuration");
            Dictionary<string, string> map = Info.Request(null, node);

            if (map == null)
            {
                throw new Exception("Failed to get server info: host=" + node);
            }

            foreach (KeyValuePair<string, string> entry in map)
            {
                string key = entry.Key;

                if (key.Equals("statistics") || key.Equals("query-stat"))
                {
                    LogNameValueTokens(entry.Value);
                }
                else
                {
                    console.Write(key + '=' + entry.Value);
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Remove nodes using copy on write semantics.
        /// </summary>
        private void RemoveNodesCopy(List<Node> nodesToRemove)
        {
            // Create temporary nodes array.
            // Since nodes are only marked for deletion using node references in the nodes array,
            // and the tend thread is the only thread modifying nodes, we are guaranteed that nodes
            // in nodesToRemove exist.  Therefore, we know the final array size.
            Node[] nodeArray = new Node[nodes.Length - nodesToRemove.Count];
            int count = 0;

            // Add nodes that are not in remove list.
            foreach (Node node in nodes)
            {
                if (FindNode(node, nodesToRemove))
                {
                    if (tendValid && Log.InfoEnabled())
                    {
                        Log.Info("Remove node " + node);
                    }
                }
                else
                {
                    nodeArray[count++] = node;
                }
            }

            // Do sanity check to make sure assumptions are correct.
            if (count < nodeArray.Length)
            {
                if (Log.WarnEnabled())
                {
                    Log.Warn("Node remove mismatch. Expected " + nodeArray.Length + " Received " + count);
                }
                // Resize array.
                Node[] nodeArray2 = new Node[count];
                Array.Copy(nodeArray, 0, nodeArray2, 0, count);
                nodeArray = nodeArray2;
            }

            // Replace nodes with copy.
            nodes = nodeArray;
        }
 protected internal override MultiCommand CreateCommand(Node node)
 {
     return new QueryAggregateCommand(node, policy, statement, inputQueue, cancel.Token);
 }
Exemplo n.º 13
0
        /// <summary>
        /// Add nodes using copy on write semantics.
        /// </summary>
        private void AddNodesCopy(List<Node> nodesToAdd)
        {
            // Create temporary nodes array.
            Node[] nodeArray = new Node[nodes.Length + nodesToAdd.Count];
            int count = 0;

            // Add existing nodes.
            foreach (Node node in nodes)
            {
                nodeArray[count++] = node;
            }

            // Add new nodes
            foreach (Node node in nodesToAdd)
            {
                if (Log.InfoEnabled())
                {
                    Log.Info("Add node " + node);
                }
                nodeArray[count++] = node;
            }

            // Replace nodes with copy.
            nodes = nodeArray;
        }
Exemplo n.º 14
0
 private bool FindNodeInPartitionMap(Node filter)
 {
     foreach (Node[][] replicaArray in partitionMap.Values)
     {
         foreach (Node[] nodeArray in replicaArray)
         {
             foreach (Node node in nodeArray)
             {
                 // Use reference equality for performance.
                 if (node == filter)
                 {
                     return true;
                 }
             }
         }
     }
     return false;
 }
Exemplo n.º 15
0
 private static bool FindNode(Node search, List<Node> nodeList)
 {
     foreach (Node node in nodeList)
     {
         if (node.Equals(search))
         {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 16
0
 private void AddAliases(Node node)
 {
     // Add node's aliases to global alias set.
     // Aliases are only used in tend thread, so synchronization is not necessary.
     foreach (Host alias in node.Aliases)
     {
         aliases[alias] = node;
     }
 }
Exemplo n.º 17
0
        /// <summary>
        /// Get default info values from the specified database server node.
        /// This method supports user authentication.
        /// </summary>
        /// <param name="policy">info command configuration parameters, pass in null for defaults</param>
        /// <param name="node">server node</param>
        public static Dictionary<string, string> Request(InfoPolicy policy, Node node)
        {
            int timeout = (policy == null) ? DEFAULT_TIMEOUT : policy.timeout;
            Connection conn = node.GetConnection(timeout);

            try
            {
                Dictionary<string, string> result = Request(conn);
                node.PutConnection(conn);
                return result;
            }
            catch (Exception)
            {
                // Garbage may be in socket.  Do not put back into pool.
                node.CloseConnection(conn);
                throw;
            }
        }
Exemplo n.º 18
0
 protected internal override QueryCommand CreateCommand(Node node)
 {
     return(new QueryAggregateCommand(node, policy, statement, inputQueue, cancel.Token));
 }
 /// <summary>
 /// Create timeout exception with statistics.
 /// </summary>
 public Timeout(Node node, int timeout, int iterations, int failedNodes, int failedConns)
     : base(ResultCode.TIMEOUT)
 {
     this.node = node;
     this.timeout = timeout;
     this.iterations = iterations;
     this.failedNodes = failedNodes;
     this.failedConns = failedConns;
 }
Exemplo n.º 20
0
 protected internal MultiCommand(Node node, bool stopOnNotFound)
 {
     this.node = node;
     this.stopOnNotFound = stopOnNotFound;
 }
Exemplo n.º 21
0
        public BatchGetArrayDirect(
			Node node,
			BatchNode.BatchNamespace batch,
			Policy policy,
			Key[] keys,
			string[] binNames,
			Record[] records,
			int readAttr
		)
            : base(node, false)
        {
            this.batch = batch;
            this.policy = policy;
            this.keys = keys;
            this.binNames = binNames;
            this.records = records;
            this.readAttr = readAttr;
        }
Exemplo n.º 22
0
        public BatchExistsArrayDirect(
			Node node,
			BatchNode.BatchNamespace batch,
			Policy policy,
			Key[] keys,
			bool[] existsArray
		)
            : base(node, false)
        {
            this.batch = batch;
            this.policy = policy;
            this.keys = keys;
            this.existsArray = existsArray;
        }
Exemplo n.º 23
0
 protected internal abstract MultiCommand CreateCommand(Node node);
        private void DecodeBitmap(Node node, Node[] nodeArray, int begin)
        {
            char[] chars = Encoding.ASCII.GetChars(buffer, begin, offset - begin);
            byte[] restoreBuffer = Convert.FromBase64CharArray(chars, 0, chars.Length);

            for (int i = 0; i < partitionCount; i++)
            {
                Node nodeOld = nodeArray[i];

                if ((restoreBuffer[i >> 3] & (0x80 >> (i & 7))) != 0)
                {
                    // Node owns this partition.
                    // Log.info("Map: " + i);
                    if (nodeOld != null && nodeOld != node)
                    {
                        // Force previously mapped node to refresh it's partition map on next cluster tend.
                        nodeOld.partitionGeneration = -1;
                    }
                    nodeArray[i] = node;
                }
                else
                {
                    // Node does not own partition.
                    if (node == nodeOld)
                    {
                        // Must erase previous map.
                        nodeArray[i] = null;
                    }
                }
            }
        }
        private void ParseReplicasAll(Node node)
        {
            // Use low-level info methods and parse byte array directly for maximum performance.
            // Receive format: replicas-all\t
            //                 <ns1>:<count>,<base 64 encoded bitmap1>,<base 64 encoded bitmap2>...;
            //                 <ns2>:<count>,<base 64 encoded bitmap1>,<base 64 encoded bitmap2>...;\n
            ExpectName(ReplicasAll);

            int begin = offset;

            while (offset < length)
            {
                if (buffer[offset] == ':')
                {
                    // Parse namespace.
                    string ns = ByteUtil.Utf8ToString(buffer, begin, offset - begin).Trim();

                    if (ns.Length <= 0 || ns.Length >= 32)
                    {
                        string response = GetTruncatedResponse();
                        throw new AerospikeException.Parse("Invalid partition namespace " + ns + ". Response=" + response);
                    }
                    begin = ++offset;

                    // Parse replica count.
                    while (offset < length)
                    {
                        byte b = buffer[offset];

                        if (b == ',')
                        {
                            break;
                        }
                        offset++;
                    }
                    int replicaCount = Convert.ToInt32(Encoding.UTF8.GetString(buffer, begin, offset - begin));

                    // Ensure replicaArray is correct size.
                    Node[][] replicaArray;

                    if (!map.TryGetValue(ns, out replicaArray))
                    {
                        // Create new replica array.
                        replicaArray = new Node[replicaCount][];

                        for (int i = 0; i < replicaCount; i++)
                        {
                            replicaArray[i] = new Node[partitionCount];
                        }

                        CopyPartitionMap();
                        map[ns] = replicaArray;
                    }
                    else if (replicaArray.Length != replicaCount)
                    {
                        if (Log.InfoEnabled())
                        {
                            Log.Info("Namespace " + ns + " replication factor changed from " + replicaArray.Length + " to " + replicaCount);
                        }

                        // Resize replica array.
                        Node[][] replicaTarget = new Node[replicaCount][];

                        if (replicaArray.Length < replicaCount)
                        {
                            int i = 0;

                            // Copy existing entries.
                            for (; i < replicaArray.Length; i++)
                            {
                                replicaTarget[i] = replicaArray[i];
                            }

                            // Create new entries.
                            for (; i < replicaCount; i++)
                            {
                                replicaTarget[i] = new Node[partitionCount];
                            }
                        }
                        else
                        {
                            // Copy existing entries.
                            for (int i = 0; i < replicaCount; i++)
                            {
                                replicaTarget[i] = replicaArray[i];
                            }
                        }

                        CopyPartitionMap();
                        replicaArray = replicaTarget;
                        map[ns] = replicaArray;
                    }

                    // Parse partition bitmaps.
                    for (int i = 0; i < replicaCount; i++)
                    {
                        begin = ++offset;

                        // Find bitmap endpoint
                        while (offset < length)
                        {
                            byte b = buffer[offset];

                            if (b == ',' || b == ';')
                            {
                                break;
                            }
                            offset++;
                        }

                        if (offset == begin)
                        {
                            string response = GetTruncatedResponse();
                            throw new AerospikeException.Parse("Empty partition id for namespace " + ns + ". Response=" + response);
                        }

                        // Log.info("Map: " + namespace + '[' + i + "] " + node);
                        DecodeBitmap(node, replicaArray[i], begin);
                    }
                    begin = ++offset;
                }
                else
                {
                    offset++;
                }
            }
        }
Exemplo n.º 26
0
 public void RefreshNamespaceData(Node node, Namespace ns)
 {
     /*
      * refresh namespace data
      */
     try {
         String nameSpaceString = Info.Request (infoPolicy, node, "namespace/" + ns);
         ns.MergeNamespaceInfo (nameSpaceString);
         String setsString = Info.Request (infoPolicy, node, "sets/" + ns);
         if (setsString.Length > 0) {
             String[] sets = setsString.Split (';');
             foreach (String setData in sets) {
                 ns.MergeSet (setData);
             }
         }
     } catch (AerospikeException e) {
         log.Error ("Error geting Namespace details", e);
     }
 }
        private void ParseReplicasMaster(Node node)
        {
            // Use low-level info methods and parse byte array directly for maximum performance.
            // Receive format: replicas-master\t<ns1>:<base 64 encoded bitmap1>;<ns2>:<base 64 encoded bitmap2>...\n
            ExpectName(ReplicasMaster);

            int begin = offset;

            while (offset < length)
            {
                if (buffer[offset] == ':')
                {
                    // Parse namespace.
                    string ns = ByteUtil.Utf8ToString(buffer, begin, offset - begin).Trim();

                    if (ns.Length <= 0 || ns.Length >= 32)
                    {
                        string response = GetTruncatedResponse();
                        throw new AerospikeException.Parse("Invalid partition namespace " + ns + ". Response=" + response);
                    }
                    begin = ++offset;

                    // Parse partition bitmap.
                    while (offset < length)
                    {
                        byte b = buffer[offset];

                        if (b == ';' || b == '\n')
                        {
                            break;
                        }
                        offset++;
                    }

                    if (offset == begin)
                    {
                        string response = GetTruncatedResponse();
                        throw new AerospikeException.Parse("Empty partition id for namespace " + ns + ". Response=" + response);
                    }

                    Node[][] replicaArray;

                    if (!map.TryGetValue(ns, out replicaArray))
                    {
                        replicaArray = new Node[1][];
                        replicaArray[0] = new Node[partitionCount];
                        CopyPartitionMap();
                        map[ns] = replicaArray;
                    }

                    // Log.info("Map: " + namespace + "[0] " + node);
                    DecodeBitmap(node, replicaArray[0], begin);
                    begin = ++offset;
                }
                else
                {
                    offset++;
                }
            }
        }
Exemplo n.º 28
0
        //-------------------------------------------------------
        // 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;
            }
        }
Exemplo n.º 29
0
        protected internal int UpdatePartitions(Connection conn, Node node)
        {
            PartitionParser parser = new PartitionParser(conn, node, partitionMap, Node.PARTITIONS, requestProleReplicas);

            if (parser.IsPartitionMapCopied)
            {
                partitionMap = parser.PartitionMap;
            }
            return parser.Generation;
        }
        /// <summary>
        /// Read all records in specified namespace and set for one node only.
        /// <para>
        /// This call will block until the scan is complete - callbacks are made
        /// within the scope of this call.
        /// </para>
        /// </summary>
        /// <param name="policy">scan configuration parameters, pass in null for defaults</param>
        /// <param name="node">server node</param>
        /// <param name="ns">namespace - equivalent to database name</param>
        /// <param name="setName">optional set name - equivalent to database table</param>
        /// <param name="callback">read callback method - called with record data</param>
        /// <param name="binNames">
        /// optional bin to retrieve. All bins will be returned if not specified.
        /// Aerospike 2 servers ignore this parameter.
        /// </param>
        /// <exception cref="AerospikeException">if transaction fails</exception>
        public void ScanNode(ScanPolicy policy, Node node, string ns, string setName, ScanCallback callback, params string[] binNames)
        {
            if (policy == null)
            {
                policy = scanPolicyDefault;
            }
            ulong taskId = RandomShift.ThreadLocalInstance.NextLong();

            ScanCommand command = new ScanCommand(node, policy, ns, setName, callback, binNames, taskId);
            command.Execute();
        }
Exemplo n.º 31
0
 private static BatchNode FindBatchNode(IList<BatchNode> nodes, Node node)
 {
     foreach (BatchNode batchNode in nodes)
     {
         // Note: using pointer equality for performance.
         if (batchNode.node == node)
         {
             return batchNode;
         }
     }
     return null;
 }