Search in sources :

Example 1 with BatchNode

use of com.aerospike.client.command.BatchNode in project aerospike-client-java by aerospike.

the class AerospikeClient method get.

// -------------------------------------------------------
// Batch Read Operations
// -------------------------------------------------------
/**
 * Read multiple records for specified batch keys in one batch call.
 * This method allows different namespaces/bins to be requested for each key in the batch.
 * The returned records are located in the same list.
 * If the BatchRead key field is not found, the corresponding record field will be null.
 * <p>
 * If a batch request to a node fails, the entire batch is cancelled.
 *
 * @param policy				batch configuration parameters, pass in null for defaults
 * @param records				list of unique record identifiers and the bins to retrieve.
 *							  The returned records are located in the same list.
 * @throws AerospikeException	if read fails
 */
public final void get(BatchPolicy policy, List<BatchRead> records) throws AerospikeException {
    if (records.size() == 0) {
        return;
    }
    if (policy == null) {
        policy = batchPolicyDefault;
    }
    List<BatchNode> batchNodes = BatchNodeList.generate(cluster, policy, records);
    if (policy.maxConcurrentThreads == 1 || batchNodes.size() <= 1) {
        // Run batch requests sequentially in same thread.
        for (BatchNode batchNode : batchNodes) {
            MultiCommand command = new Batch.ReadListCommand(cluster, null, batchNode, policy, records);
            command.execute();
        }
    } else {
        // Run batch requests in parallel in separate threads.
        // 
        // Multiple threads write to the record list, 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 (completedCount.incrementAndGet()) at the end of write threads
        // and a synchronized waitTillComplete() in this thread.
        Executor executor = new Executor(cluster, batchNodes.size());
        for (BatchNode batchNode : batchNodes) {
            MultiCommand command = new Batch.ReadListCommand(cluster, executor, batchNode, policy, records);
            executor.addCommand(command);
        }
        executor.execute(policy.maxConcurrentThreads);
    }
}
Also used : AsyncScanPartitionExecutor(com.aerospike.client.async.AsyncScanPartitionExecutor) AsyncQueryPartitionExecutor(com.aerospike.client.async.AsyncQueryPartitionExecutor) AsyncQueryExecutor(com.aerospike.client.async.AsyncQueryExecutor) QueryPartitionExecutor(com.aerospike.client.query.QueryPartitionExecutor) BatchExecutor(com.aerospike.client.command.BatchExecutor) QueryRecordExecutor(com.aerospike.client.query.QueryRecordExecutor) QueryAggregateExecutor(com.aerospike.client.query.QueryAggregateExecutor) ScanExecutor(com.aerospike.client.command.ScanExecutor) Executor(com.aerospike.client.command.Executor) BatchNode(com.aerospike.client.command.BatchNode) MultiCommand(com.aerospike.client.command.MultiCommand)

Aggregations

AsyncQueryExecutor (com.aerospike.client.async.AsyncQueryExecutor)1 AsyncQueryPartitionExecutor (com.aerospike.client.async.AsyncQueryPartitionExecutor)1 AsyncScanPartitionExecutor (com.aerospike.client.async.AsyncScanPartitionExecutor)1 BatchExecutor (com.aerospike.client.command.BatchExecutor)1 BatchNode (com.aerospike.client.command.BatchNode)1 Executor (com.aerospike.client.command.Executor)1 MultiCommand (com.aerospike.client.command.MultiCommand)1 ScanExecutor (com.aerospike.client.command.ScanExecutor)1 QueryAggregateExecutor (com.aerospike.client.query.QueryAggregateExecutor)1 QueryPartitionExecutor (com.aerospike.client.query.QueryPartitionExecutor)1 QueryRecordExecutor (com.aerospike.client.query.QueryRecordExecutor)1