Search in sources :

Example 6 with ScanPolicy

use of com.aerospike.client.policy.ScanPolicy in project aerospike-client-java by aerospike.

the class ScanSeries method runExample.

/**
 * Scan all nodes in series and read all records in all sets.
 */
@Override
public void runExample(AerospikeClient client, Parameters params) throws Exception {
    console.info("Scan series: namespace=" + params.namespace + " set=" + params.set);
    // Use low scan priority.  This will take more time, but it will reduce
    // the load on the server.
    ScanPolicy policy = new ScanPolicy();
    policy.maxRetries = 1;
    policy.priority = Priority.LOW;
    List<String> nodeList = client.getNodeNames();
    long begin = System.currentTimeMillis();
    for (String nodeName : nodeList) {
        console.info("Scan node " + nodeName);
        client.scanNode(policy, nodeName, params.namespace, params.set, this);
        for (Map.Entry<String, Metrics> entry : setMap.entrySet()) {
            console.info("Node " + nodeName + " set " + entry.getKey() + " count: " + entry.getValue().count);
            entry.getValue().count = 0;
        }
    }
    long end = System.currentTimeMillis();
    double seconds = (double) (end - begin) / 1000.0;
    console.info("Elapsed time: " + seconds + " seconds");
    long total = 0;
    for (Map.Entry<String, Metrics> entry : setMap.entrySet()) {
        console.info("Total set " + entry.getKey() + " count: " + entry.getValue().total);
        total += entry.getValue().total;
    }
    console.info("Grand total: " + total);
    double performance = Math.round((double) total / seconds);
    console.info("Records/second: " + performance);
}
Also used : ScanPolicy(com.aerospike.client.policy.ScanPolicy) Map(java.util.Map) HashMap(java.util.HashMap)

Example 7 with ScanPolicy

use of com.aerospike.client.policy.ScanPolicy in project aerospike-client-java by aerospike.

the class AsyncClient method scanAll.

// -------------------------------------------------------
// Scan Operations
// -------------------------------------------------------
/**
 * Asynchronously read all records in specified namespace and set.  If the policy's
 * <code>concurrentNodes</code> is specified, each server node will be read in
 * parallel.  Otherwise, server nodes are read in series.
 * <p>
 * This method schedules the scan command with a channel selector and returns.
 * Another thread will process the command and send the results to the listener.
 *
 * @param policy				scan configuration parameters, pass in null for defaults
 * @param listener				where to send results
 * @param namespace				namespace - equivalent to database name
 * @param setName				optional set name - equivalent to database table
 * @param binNames				optional bin to retrieve. All bins will be returned if not specified.
 * 								Aerospike 2 servers ignore this parameter.
 * @throws AerospikeException	if queue is full
 */
public final void scanAll(final ScanPolicy policy, final RecordSequenceListener listener, final String namespace, final String setName, final String... binNames) throws AerospikeException {
    final ScanPolicy sp = (policy != null) ? policy : asyncScanPolicyDefault;
    if (useListener) {
        // Reserve one command for each node.
        final int commands = cluster.getNodes().length;
        commandBegin(commands, new Runnable() {

            public void run() {
                scanAll(findEventLoop(), new ARecordSequenceListener(listener, commands), sp, namespace, setName, binNames);
            }
        });
    } else {
        scanAll(findEventLoop(), listener, sp, namespace, setName, binNames);
    }
}
Also used : ScanPolicy(com.aerospike.client.policy.ScanPolicy)

Aggregations

ScanPolicy (com.aerospike.client.policy.ScanPolicy)7 Test (org.junit.Test)3 AerospikeException (com.aerospike.client.AerospikeException)2 Key (com.aerospike.client.Key)2 Record (com.aerospike.client.Record)2 RecordSequenceListener (com.aerospike.client.listener.RecordSequenceListener)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1