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);
}
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);
}
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);
}
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);
}
}
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;
}
}
}
Aggregations