Search in sources :

Example 1 with NodePartitions

use of com.aerospike.client.query.PartitionTracker.NodePartitions in project aerospike-client-java by aerospike.

the class AsyncQueryPartitionExecutor method queryPartitions.

private void queryPartitions() {
    statement.setTaskId(RandomShift.instance().nextLong());
    List<NodePartitions> nodePartitionsList = tracker.assignPartitionsToNodes(cluster, statement.getNamespace());
    AsyncQueryPartition[] tasks = new AsyncQueryPartition[nodePartitionsList.size()];
    int count = 0;
    for (NodePartitions nodePartitions : nodePartitionsList) {
        tasks[count++] = new AsyncQueryPartition(this, policy, listener, statement, tracker, nodePartitions);
    }
    execute(tasks, policy.maxConcurrentNodes);
}
Also used : NodePartitions(com.aerospike.client.query.PartitionTracker.NodePartitions)

Example 2 with NodePartitions

use of com.aerospike.client.query.PartitionTracker.NodePartitions in project aerospike-client-java by aerospike.

the class AsyncScanPartitionExecutor method scanPartitions.

private void scanPartitions() {
    long taskId = RandomShift.instance().nextLong();
    List<NodePartitions> nodePartitionsList = tracker.assignPartitionsToNodes(cluster, namespace);
    AsyncScanPartition[] tasks = new AsyncScanPartition[nodePartitionsList.size()];
    int count = 0;
    for (NodePartitions nodePartitions : nodePartitionsList) {
        tasks[count++] = new AsyncScanPartition(this, policy, listener, namespace, setName, binNames, taskId, tracker, nodePartitions);
    }
    execute(tasks, policy.maxConcurrentNodes);
}
Also used : NodePartitions(com.aerospike.client.query.PartitionTracker.NodePartitions)

Example 3 with NodePartitions

use of com.aerospike.client.query.PartitionTracker.NodePartitions in project aerospike-client-java by aerospike.

the class ScanExecutor method scanPartitions.

public static void scanPartitions(Cluster cluster, ScanPolicy policy, String namespace, String setName, String[] binNames, ScanCallback callback, PartitionTracker tracker) {
    policy.validate();
    while (true) {
        long taskId = RandomShift.instance().nextLong();
        try {
            List<NodePartitions> list = tracker.assignPartitionsToNodes(cluster, namespace);
            if (policy.concurrentNodes && list.size() > 1) {
                Executor executor = new Executor(cluster, list.size());
                for (NodePartitions nodePartitions : list) {
                    ScanPartitionCommand command = new ScanPartitionCommand(cluster, policy, namespace, setName, binNames, callback, taskId, tracker, nodePartitions);
                    executor.addCommand(command);
                }
                executor.execute(policy.maxConcurrentNodes);
            } else {
                for (NodePartitions nodePartitions : list) {
                    ScanPartitionCommand command = new ScanPartitionCommand(cluster, policy, namespace, setName, binNames, callback, taskId, tracker, nodePartitions);
                    command.execute();
                }
            }
        } catch (AerospikeException ae) {
            ae.setIteration(tracker.iteration);
            throw ae;
        }
        if (tracker.isComplete(policy)) {
            // Scan is complete.
            return;
        }
        if (policy.sleepBetweenRetries > 0) {
            // Sleep before trying again.
            Util.sleep(policy.sleepBetweenRetries);
        }
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) NodePartitions(com.aerospike.client.query.PartitionTracker.NodePartitions)

Example 4 with NodePartitions

use of com.aerospike.client.query.PartitionTracker.NodePartitions in project aerospike-client-java by aerospike.

the class QueryPartitionExecutor method execute.

private void execute() {
    while (true) {
        statement.taskId = RandomShift.instance().nextLong();
        List<NodePartitions> list = tracker.assignPartitionsToNodes(cluster, statement.namespace);
        // Initialize maximum number of nodes to query in parallel.
        maxConcurrentThreads = (policy.maxConcurrentNodes == 0 || policy.maxConcurrentNodes >= list.size()) ? list.size() : policy.maxConcurrentNodes;
        boolean parallel = maxConcurrentThreads > 1 && list.size() > 1;
        synchronized (threads) {
            // RecordSet thread may have aborted query, so check done under lock.
            if (done.get()) {
                break;
            }
            threads.clear();
            if (parallel) {
                for (NodePartitions nodePartitions : list) {
                    MultiCommand command = new QueryPartitionCommand(cluster, nodePartitions.node, policy, statement, recordSet, tracker, nodePartitions);
                    threads.add(new QueryThread(command));
                }
                for (int i = 0; i < maxConcurrentThreads; i++) {
                    threadPool.execute(threads.get(i));
                }
            }
        }
        if (parallel) {
            waitTillComplete();
        } else {
            for (NodePartitions nodePartitions : list) {
                MultiCommand command = new QueryPartitionCommand(cluster, nodePartitions.node, policy, statement, recordSet, tracker, nodePartitions);
                command.execute();
            }
        }
        if (exception != null) {
            break;
        }
        if (tracker.isComplete(policy)) {
            // All partitions received.
            recordSet.put(RecordSet.END);
            break;
        }
        // Set done to false so RecordSet thread has chance to close early again.
        done.set(false);
        if (policy.sleepBetweenRetries > 0) {
            // Sleep before trying again.
            Util.sleep(policy.sleepBetweenRetries);
        }
        completedCount.set(0);
        threadsComplete = false;
        exception = null;
    }
}
Also used : NodePartitions(com.aerospike.client.query.PartitionTracker.NodePartitions) MultiCommand(com.aerospike.client.command.MultiCommand)

Aggregations

NodePartitions (com.aerospike.client.query.PartitionTracker.NodePartitions)4 AerospikeException (com.aerospike.client.AerospikeException)1 MultiCommand (com.aerospike.client.command.MultiCommand)1