Search in sources :

Example 1 with ScanPolicy

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

the class AsyncScanPage method runScan.

private void runScan(AerospikeClient client, EventLoop eventLoop) {
    int pageSize = 30;
    console.info("Scan max " + pageSize + " records.");
    ScanPolicy policy = new ScanPolicy();
    policy.maxRecords = pageSize;
    PartitionFilter filter = PartitionFilter.all();
    RecordSequenceListener listener = new RecordSequenceListener() {

        private int count = 0;

        @Override
        public void onRecord(Key key, Record record) throws AerospikeException {
            count++;
        }

        @Override
        public void onSuccess() {
            console.info("Records returned: " + count);
            notifyComplete();
        }

        @Override
        public void onFailure(AerospikeException e) {
            console.error("Scan failed: " + Util.getErrorMessage(e));
            notifyComplete();
        }
    };
    client.scanPartitions(eventLoop, listener, policy, filter, params.namespace, setName);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) PartitionFilter(com.aerospike.client.query.PartitionFilter) RecordSequenceListener(com.aerospike.client.listener.RecordSequenceListener) ScanPolicy(com.aerospike.client.policy.ScanPolicy) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key)

Example 2 with ScanPolicy

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

the class ScanParallel method runExample.

/**
 * Scan all nodes in parallel and read all records in a set.
 */
@Override
public void runExample(AerospikeClient client, Parameters params) throws Exception {
    console.info("Scan parallel: namespace=" + params.namespace + " set=" + params.set);
    recordCount = new AtomicInteger();
    long begin = System.currentTimeMillis();
    ScanPolicy policy = new ScanPolicy();
    client.scanAll(policy, params.namespace, params.set, this);
    long end = System.currentTimeMillis();
    double seconds = (double) (end - begin) / 1000.0;
    int count = recordCount.get();
    console.info("Total records returned: " + count);
    console.info("Elapsed time: " + seconds + " seconds");
    double performance = Math.round((double) count / seconds);
    console.info("Records/second: " + performance);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScanPolicy(com.aerospike.client.policy.ScanPolicy)

Example 3 with ScanPolicy

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

the class TestScan method scanParallel.

@Test
public void scanParallel() {
    ScanPolicy policy = new ScanPolicy();
    client.scanAll(policy, args.namespace, args.set, this);
}
Also used : ScanPolicy(com.aerospike.client.policy.ScanPolicy) Test(org.junit.Test)

Example 4 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)

Example 5 with ScanPolicy

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

the class TestScan method scanSeries.

@Test
public void scanSeries() {
    ScanPolicy policy = new ScanPolicy();
    List<String> nodeList = client.getNodeNames();
    for (String nodeName : nodeList) {
        client.scanNode(policy, nodeName, args.namespace, args.set, this);
        for (Map.Entry<String, Metrics> entry : setMap.entrySet()) {
            entry.getValue().count = 0;
        }
    }
}
Also used : ScanPolicy(com.aerospike.client.policy.ScanPolicy) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

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