public static void ScanNodes(Cluster cluster, ScanPolicy policy, string ns, string setName, string[] binNames, ScanCallback callback, Node[] nodes)
        {
            policy.Validate();

            // Detect cluster migrations when performing scan.
            ulong taskId     = RandomShift.ThreadLocalInstance.NextLong();
            ulong clusterKey = policy.failOnClusterChange ? QueryValidate.ValidateBegin(nodes[0], ns) : 0;
            bool  first      = true;

            if (policy.concurrentNodes && nodes.Length > 1)
            {
                Executor executor = new Executor(nodes.Length);

                foreach (Node node in nodes)
                {
                    ScanCommand command = new ScanCommand(cluster, node, policy, ns, setName, binNames, callback, taskId, clusterKey, first);
                    executor.AddCommand(command);
                    first = false;
                }
                executor.Execute(policy.maxConcurrentNodes);
            }
            else
            {
                foreach (Node node in nodes)
                {
                    ScanCommand command = new ScanCommand(cluster, node, policy, ns, setName, binNames, callback, taskId, clusterKey, first);
                    command.Execute();
                    first = false;
                }
            }
        }
        public static void ScanPartitions(Cluster cluster, ScanPolicy policy, string ns, string setName, string[] binNames, ScanCallback callback, PartitionTracker tracker)
        {
            policy.Validate();

            while (true)
            {
                ulong taskId = RandomShift.ThreadLocalInstance.NextLong();

                try
                {
                    List <NodePartitions> list = tracker.AssignPartitionsToNodes(cluster, ns);

                    if (policy.concurrentNodes && list.Count > 1)
                    {
                        Executor executor = new Executor(list.Count);

                        foreach (NodePartitions nodePartitions in list)
                        {
                            ScanPartitionCommand command = new ScanPartitionCommand(cluster, policy, ns, setName, binNames, callback, taskId, tracker, nodePartitions);
                            executor.AddCommand(command);
                        }

                        executor.Execute(policy.maxConcurrentNodes);
                    }
                    else
                    {
                        foreach (NodePartitions nodePartitions in list)
                        {
                            ScanPartitionCommand command = new ScanPartitionCommand(cluster, policy, ns, setName, binNames, callback, taskId, tracker, nodePartitions);
                            command.Execute();
                        }
                    }
                }
                catch (AerospikeException ae)
                {
                    ae.Iteration = tracker.iteration;
                    throw ae;
                }

                if (tracker.IsComplete(policy))
                {
                    // Scan is complete.
                    return;
                }

                if (policy.sleepBetweenRetries > 0)
                {
                    // Sleep before trying again.
                    Util.Sleep(policy.sleepBetweenRetries);
                }
            }
        }
        public AsyncScanExecutor
        (
            AsyncCluster cluster,
            ScanPolicy policy,
            RecordSequenceListener listener,
            string ns,
            string setName,
            string[] binNames,
            Node[] nodes
        ) : base(cluster)
        {
            this.listener = listener;
            policy.Validate();

            ulong taskId = RandomShift.ThreadLocalInstance.NextLong();

            // Create commands.
            AsyncScan[] tasks            = new AsyncScan[nodes.Length];
            int         count            = 0;
            bool        hasClusterStable = true;

            foreach (Node node in nodes)
            {
                if (!node.HasClusterStable)
                {
                    hasClusterStable = false;
                }
                tasks[count++] = new AsyncScan(this, cluster, (AsyncNode)node, policy, listener, ns, setName, binNames, taskId);
            }

            // Dispatch commands to nodes.
            if (policy.failOnClusterChange && hasClusterStable)
            {
                ExecuteValidate(tasks, policy.maxConcurrentNodes, ns);
            }
            else
            {
                Execute(tasks, policy.maxConcurrentNodes);
            }
        }
Exemplo n.º 4
0
        public AsyncScanPartitionExecutor
        (
            AsyncCluster cluster,
            ScanPolicy policy,
            RecordSequenceListener listener,
            string ns,
            string setName,
            string[] binNames,
            PartitionTracker tracker
        ) : base(cluster)
        {
            this.policy   = policy;
            this.listener = listener;
            this.ns       = ns;
            this.setName  = setName;
            this.binNames = binNames;
            this.tracker  = tracker;

            policy.Validate();
            tracker.SleepBetweenRetries = 0;
            ScanPartitions();
        }