Ejemplo n.º 1
0
        private void ParseReplicasAll(Node node, string command)
        {
            // Use low-level info methods and parse byte array directly for maximum performance.
            // Receive format: replicas-all\t
            //                 <ns1>:[regime],<count>,<base 64 encoded bitmap1>,<base 64 encoded bitmap2>...;
            //                 <ns2>:[regime],<count>,<base 64 encoded bitmap1>,<base 64 encoded bitmap2>...;\n
            ExpectName(command);

            int begin  = offset;
            int regime = 0;

            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 regime.
                    if (command == Replicas)
                    {
                        while (offset < length)
                        {
                            byte b = buffer[offset];

                            if (b == ',')
                            {
                                break;
                            }
                            offset++;
                        }
                        regime = Convert.ToInt32(Encoding.UTF8.GetString(buffer, begin, offset - begin));
                        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 replicaCount is uniform.
                    Partitions partitions;

                    if (!map.TryGetValue(ns, out partitions))
                    {
                        // Create new replica array.
                        partitions = new Partitions(partitionCount, replicaCount, regime != 0);
                        CopyPartitionMap();
                        map[ns] = partitions;
                    }
                    else if (partitions.replicas.Length != replicaCount)
                    {
                        if (Log.InfoEnabled())
                        {
                            Log.Info("Namespace " + ns + " replication factor changed from " + partitions.replicas.Length + " to " + replicaCount);
                        }

                        // Resize partition map.
                        Partitions tmp = new Partitions(partitions, replicaCount);

                        CopyPartitionMap();
                        partitions = tmp;
                        map[ns]    = partitions;
                    }

                    // 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, partitions, i, regime, begin);
                    }
                    begin = ++offset;
                }
                else
                {
                    offset++;
                }
            }
        }