All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Typedefs | Functions
Scan Operations

Description

Aerospike Scan Operations provide the ability to scan all record of a namespace and set in an Aerospike database.

Usage

Before you can execute a scan, you first need to define a scan using as_scan. See as_scan for details on defining scans.

Once you have a scan defined, then you can execute the scan using either:

When aerospike_scan_foreach() is executed, it will process the results and create records on the stack. Because the records are on the stack, they will only be available within the context of the callback function.

When aerospike_scan_background() is executed, the client will not wait for results from the database. Instead, the client will be given a scan_id, which can be used to query the scan status on the database via aerospike_scan_info().

Walk-through

First, we build a scan using as_scan. The scan will be on the "test" namespace and "demo" set. We will select only bins "a" and "b" to be returned for each record.

as_scan scan;
as_scan_init(&scan, "test", "demo");
as_scan_select(&scan, "a");
as_scan_select(&scan, "B");

Now that we have a scan defined, we want to execute it using aerospike_scan_foreach().

if ( aerospike_scan_foreach(&as, &err, NULL, &scan, callback, NULL) != AEROSPIKE_OK ) {
fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
}

The callback provided to the function above is implemented as:

bool callback(const as_val * val, void * udata) {
if ( !rec ) return false;
fprintf("record contains %d bins", as_record_numbins(rec));
return true;
}

An as_scan is simply a scan definition, so it does not contain any state, allowing it to be reused for multiple scan operations.

When you are finished with the scan, you should destroy the resources allocated to it:

+ Collaboration diagram for Scan Operations:

Typedefs

typedef bool(* aerospike_scan_foreach_callback )(const as_val *val, void *udata)
 
typedef bool(* aerospike_scan_foreach_callback )(const as_val *val, void *udata)
 

Functions

as_status aerospike_scan_background (aerospike *as, as_error *err, const as_policy_scan *policy, const as_scan *scan, uint64_t *scan_id)
 
as_status aerospike_scan_foreach (aerospike *as, as_error *err, const as_policy_scan *policy, const as_scan *scan, aerospike_scan_foreach_callback callback, void *udata)
 
as_status aerospike_scan_info (aerospike *as, as_error *err, const as_policy_info *policy, uint64_t scan_id, as_scan_info *info)
 

Typedef Documentation

typedef bool(* aerospike_scan_foreach_callback)(const as_val *val, void *udata)

This callback will be called for each value or record returned from a scan.

The following functions accept the callback:

bool my_callback(const as_val * val, void * udata) {
return true;
}
Parameters
valThe value received from the query.
udataUser-data provided to the calling function.
Returns
true to continue to the next value. Otherwise, iteration will end.

Definition at line 133 of file src/include/aerospike/aerospike_scan.h.

typedef bool(* aerospike_scan_foreach_callback)(const as_val *val, void *udata)

This callback will be called for each value or record returned from a scan.

The following functions accept the callback:

bool my_callback(const as_val * val, void * udata) {
return true;
}
Parameters
valThe value received from the query.
udataUser-data provided to the calling function.
Returns
true to continue to the next value. Otherwise, iteration will end.

Definition at line 133 of file target/Linux-x86_64/include/aerospike/aerospike_scan.h.

Function Documentation

as_status aerospike_scan_background ( aerospike as,
as_error err,
const as_policy_scan policy,
const as_scan scan,
uint64_t *  scan_id 
)

Scan the records in the specified namespace and set in the cluster.

Scan will be run in the background by a thread on client side. No callback will be called in this case.

as_scan scan;
as_scan_init(&scan, "test", "demo");
uint64_t scanid = 0;
if ( aerospike_scan_background(&as, &err, NULL, &scan, &scanid) != AEROSPIKE_OK ) {
fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
}
else {
printf("Running background scan job: %ll", scanid);
}

The scanid can be used to query the status of the scan running in the database via aerospike_scan_info().

Parameters
asThe aerospike instance to use for this operation.
errThe as_error to be populated if an error occurs.
policyThe policy to use for this operation. If NULL, then the default policy will be used.
scanThe scan to execute against the cluster.
scan_idThe id for the scan job, which can be used for querying the status of the scan.
Returns
AEROSPIKE_OK on success. Otherwise an error occurred.
as_status aerospike_scan_foreach ( aerospike as,
as_error err,
const as_policy_scan policy,
const as_scan scan,
aerospike_scan_foreach_callback  callback,
void *  udata 
)

Scan the records in the specified namespace and set in the cluster.

Call the callback function for each record scanned. When all records have been scanned, then callback will be called with a NULL value for the record.

as_scan scan;
as_scan_init(&scan, "test", "demo");
if ( aerospike_scan_foreach(&as, &err, NULL, &scan, callback, NULL) != AEROSPIKE_OK ) {
fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
}
Parameters
asThe aerospike instance to use for this operation.
errThe as_error to be populated if an error occurs.
policyThe policy to use for this operation. If NULL, then the default policy will be used.
scanThe scan to execute against the cluster.
callbackThe function to be called for each record scanned.
udataUser-data to be passed to the callback.
Returns
AEROSPIKE_OK on success. Otherwise an error occurred.
as_status aerospike_scan_info ( aerospike as,
as_error err,
const as_policy_info policy,
uint64_t  scan_id,
as_scan_info info 
)

Check the progress of a background scan running on the database. The status of the scan running on the datatabse will be populated into an as_scan_info.

uint64_t scan_id = 1234;
as_scan_info scan_info;
if ( aerospike_scan_info(&as, &err, NULL, &scan, scan_id, &scan_info) != AEROSPIKE_OK ) {
fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
}
else {
printf("Scan id=%ll, status=%d percent=%d", scan_id, scan_info.status, scan_info.progress_pct);
}
Parameters
asThe aerospike instance to use for this operation.
errThe as_error to be populated if an error occurs.
policyThe policy to use for this operation. If NULL, then the default policy will be used.
scan_idThe id for the scan job to check the status of.
infoInformation about this scan, to be populated by this operation.
Returns
AEROSPIKE_OK on success. Otherwise an error occurred.