Ejemplo n.º 1
0
        public static List <BatchNode> GenerateList
        (
            Cluster cluster,
            BatchPolicy policy,
            Key[] keys,
            uint sequenceAP,
            uint sequenceSC,
            BatchNode batchSeed
        )
        {
            Node[] nodes = cluster.ValidateNodes();

            // Create initial key capacity for each node as average + 25%.
            int keysPerNode = batchSeed.offsetsSize / nodes.Length;

            keysPerNode += (int)((uint)keysPerNode >> 2);

            // The minimum key capacity is 10.
            if (keysPerNode < 10)
            {
                keysPerNode = 10;
            }

            Replica replica   = policy.replica;
            Replica replicaSC = Partition.GetReplicaSC(policy);

            // Split keys by server node.
            List <BatchNode> batchNodes = new List <BatchNode>(nodes.Length);

            for (int i = 0; i < batchSeed.offsetsSize; i++)
            {
                int offset = batchSeed.offsets[i];

                Node      node      = Partition.GetNodeBatchRead(cluster, keys[offset], replica, replicaSC, sequenceAP, sequenceSC);
                BatchNode batchNode = FindBatchNode(batchNodes, node);

                if (batchNode == null)
                {
                    batchNodes.Add(new BatchNode(node, keysPerNode, offset));
                }
                else
                {
                    batchNode.AddKey(offset);
                }
            }
            return(batchNodes);
        }
Ejemplo n.º 2
0
        public static List <BatchNode> GenerateList(Cluster cluster, BatchPolicy policy, List <BatchRead> records)
        {
            Node[] nodes = cluster.ValidateNodes();

            // Create initial key capacity for each node as average + 25%.
            int max         = records.Count;
            int keysPerNode = max / nodes.Length;

            keysPerNode += (int)((uint)keysPerNode >> 2);

            // The minimum key capacity is 10.
            if (keysPerNode < 10)
            {
                keysPerNode = 10;
            }

            Replica replica   = policy.replica;
            Replica replicaSC = Partition.GetReplicaSC(policy);

            // Split keys by server node.
            List <BatchNode> batchNodes = new List <BatchNode>(nodes.Length);

            for (int i = 0; i < max; i++)
            {
                Node      node      = Partition.GetNodeBatchRead(cluster, records[i].key, replica, replicaSC, 0, 0);
                BatchNode batchNode = FindBatchNode(batchNodes, node);

                if (batchNode == null)
                {
                    batchNodes.Add(new BatchNode(node, keysPerNode, i));
                }
                else
                {
                    batchNode.AddKey(i);
                }
            }
            return(batchNodes);
        }