private static void ExecuteNode(Cluster cluster, BatchNode batchNode, BatchPolicy policy, Key[] keys, bool[] existsArray, Record[] records, string[] binNames, int readAttr)
 {
     if (records != null)
     {
         MultiCommand command = new BatchGetArrayCommand(cluster, null, batchNode, policy, keys, binNames, records, readAttr);
         command.Execute();
     }
     else
     {
         MultiCommand command = new BatchExistsArrayCommand(cluster, null, batchNode, policy, keys, existsArray);
         command.Execute();
     }
 }
Ejemplo n.º 2
0
        protected internal override bool RetryBatch(Cluster cluster, int socketTimeout, int totalTimeout, DateTime deadline, int iteration, int commandSentCounter)
        {
            // Retry requires keys for this node to be split among other nodes.
            // This is both recursive and exponential.
            List <BatchNode> batchNodes = BatchNode.GenerateList(cluster, policy, keys, sequence, batch);

            if (batchNodes.Count == 1 && batchNodes[0].node == batch.node)
            {
                // Batch node is the same.  Go through normal retry.
                return(false);
            }

            // Run batch requests sequentially in same thread.
            foreach (BatchNode batchNode in batchNodes)
            {
                MultiCommand command = new BatchGetArrayCommand(parent, batchNode, policy, keys, binNames, records, readAttr);
                command.sequence = sequence;
                command.Execute(cluster, policy, null, batchNode.node, true, socketTimeout, totalTimeout, deadline, iteration, commandSentCounter);
            }
            return(true);
        }
        private static void ExecuteNode(Cluster cluster, BatchNode batchNode, BatchPolicy policy, Key[] keys, bool[] existsArray, Record[] records, string[] binNames, int readAttr)
        {
            if (batchNode.node.UseNewBatch(policy))
            {
                // New batch
                if (records != null)
                {
                    MultiCommand command = new BatchGetArrayCommand(batchNode, policy, keys, binNames, records, readAttr);
                    command.Execute(cluster, policy, null, batchNode.node, true);
                }
                else
                {
                    MultiCommand command = new BatchExistsArrayCommand(batchNode, policy, keys, existsArray);
                    command.Execute(cluster, policy, null, batchNode.node, true);
                }
            }
            else
            {
                // Old batch only allows one namespace per call.
                batchNode.SplitByNamespace(keys);

                foreach (BatchNode.BatchNamespace batchNamespace in batchNode.batchNamespaces)
                {
                    if (records != null)
                    {
                        MultiCommand command = new BatchGetArrayDirect(batchNamespace, policy, keys, binNames, records, readAttr);
                        command.Execute(cluster, policy, null, batchNode.node, true);
                    }
                    else
                    {
                        MultiCommand command = new BatchExistsArrayDirect(batchNamespace, policy, keys, existsArray);
                        command.Execute(cluster, policy, null, batchNode.node, true);
                    }
                }
            }
        }
        public static void Execute
        (
            Cluster cluster,
            BatchPolicy policy,
            Key[] keys,
            bool[] existsArray,
            Record[] records,
            string[] binNames,
            int readAttr
        )
        {
            if (keys.Length == 0)
            {
                return;
            }

            if (policy.allowProleReads)
            {
                // Send all requests to a single node chosen in round-robin fashion in this transaction thread.
                Node      node      = cluster.GetRandomNode();
                BatchNode batchNode = new BatchNode(node, keys);
                ExecuteNode(cluster, batchNode, policy, keys, existsArray, records, binNames, readAttr);
                return;
            }

            List <BatchNode> batchNodes = BatchNode.GenerateList(cluster, policy, keys);

            if (policy.maxConcurrentThreads == 1 || batchNodes.Count <= 1)
            {
                // Run batch requests sequentially in same thread.
                foreach (BatchNode batchNode in batchNodes)
                {
                    ExecuteNode(cluster, batchNode, policy, keys, existsArray, records, binNames, readAttr);
                }
            }
            else
            {
                // Run batch requests in parallel in separate threads.
                //
                // Multiple threads write to the record/exists array, so one might think that
                // volatile or memory barriers are needed on the write threads and this read thread.
                // This should not be necessary here because it happens in Executor which does a
                // volatile write (Interlocked.Increment(ref completedCount)) at the end of write threads
                // and a synchronized WaitTillComplete() in this thread.
                Executor executor = new Executor(batchNodes.Count * 2);

                // Initialize threads.
                foreach (BatchNode batchNode in batchNodes)
                {
                    if (records != null)
                    {
                        MultiCommand command = new BatchGetArrayCommand(cluster, executor, batchNode, policy, keys, binNames, records, readAttr);
                        executor.AddCommand(command);
                    }
                    else
                    {
                        MultiCommand command = new BatchExistsArrayCommand(cluster, executor, batchNode, policy, keys, existsArray);
                        executor.AddCommand(command);
                    }
                }
                executor.Execute(policy.maxConcurrentThreads);
            }
        }
        public static void Execute(Cluster cluster, BatchPolicy policy, Key[] keys, bool[] existsArray, Record[] records, string[] binNames, int readAttr)
        {
            if (keys.Length == 0)
            {
                return;
            }

            if (policy.allowProleReads)
            {
                // Send all requests to a single node chosen in round-robin fashion in this transaction thread.
                Node node = cluster.GetRandomNode();
                BatchNode batchNode = new BatchNode(node, keys);
                ExecuteNode(batchNode, policy, keys, existsArray, records, binNames, readAttr);
                return;
            }

            List<BatchNode> batchNodes = BatchNode.GenerateList(cluster, policy, keys);

            if (policy.maxConcurrentThreads == 1 || batchNodes.Count <= 1)
            {
                // Run batch requests sequentially in same thread.
                foreach (BatchNode batchNode in batchNodes)
                {
                    ExecuteNode(batchNode, policy, keys, existsArray, records, binNames, readAttr);
                }
            }
            else
            {
                // Run batch requests in parallel in separate threads.
                //
                // Multiple threads write to the record/exists array, so one might think that
                // volatile or memory barriers are needed on the write threads and this read thread.
                // This should not be necessary here because it happens in Executor which does a
                // volatile write (Interlocked.Increment(ref completedCount)) at the end of write threads
                // and a synchronized WaitTillComplete() in this thread.
                Executor executor = new Executor(batchNodes.Count * 2);

                // Initialize threads.
                foreach (BatchNode batchNode in batchNodes)
                {
                    if (batchNode.node.UseNewBatch(policy))
                    {
                        // New batch
                        if (records != null)
                        {
                            MultiCommand command = new BatchGetArrayCommand(batchNode, policy, keys, binNames, records, readAttr);
                            executor.AddCommand(command);
                        }
                        else
                        {
                            MultiCommand command = new BatchExistsArrayCommand(batchNode, policy, keys, existsArray);
                            executor.AddCommand(command);
                        }
                    }
                    else
                    {
                        // There may be multiple threads for a single node because the
                        // wire protocol only allows one namespace per command.  Multiple namespaces
                        // require multiple threads per node.
                        batchNode.SplitByNamespace(keys);

                        foreach (BatchNode.BatchNamespace batchNamespace in batchNode.batchNamespaces)
                        {
                            if (records != null)
                            {
                                MultiCommand command = new BatchGetArrayDirect(batchNode.node, batchNamespace, policy, keys, binNames, records, readAttr);
                                executor.AddCommand(command);
                            }
                            else
                            {
                                MultiCommand command = new BatchExistsArrayDirect(batchNode.node, batchNamespace, policy, keys, existsArray);
                                executor.AddCommand(command);
                            }
                        }
                    }
                }
                executor.Execute(policy.maxConcurrentThreads);
            }
        }
        private static void ExecuteNode(BatchNode batchNode, BatchPolicy policy, Key[] keys, bool[] existsArray, Record[] records, string[] binNames, int readAttr)
        {
            if (batchNode.node.UseNewBatch(policy))
            {
                // New batch
                if (records != null)
                {
                    MultiCommand command = new BatchGetArrayCommand(batchNode, policy, keys, binNames, records, readAttr);
                    command.Execute();
                }
                else
                {
                    MultiCommand command = new BatchExistsArrayCommand(batchNode, policy, keys, existsArray);
                    command.Execute();
                }
            }
            else
            {
                // Old batch only allows one namespace per call.
                batchNode.SplitByNamespace(keys);

                foreach (BatchNode.BatchNamespace batchNamespace in batchNode.batchNamespaces)
                {
                    if (records != null)
                    {
                        MultiCommand command = new BatchGetArrayDirect(batchNode.node, batchNamespace, policy, keys, binNames, records, readAttr);
                        command.Execute();
                    }
                    else
                    {
                        MultiCommand command = new BatchExistsArrayDirect(batchNode.node, batchNamespace, policy, keys, existsArray);
                        command.Execute();
                    }
                }
            }
        }