![]() |
Aerospike Scan Operations provide the ability to scan all record of a namespace and set in an Aerospike database.
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().
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.
Now that we have a scan defined, we want to execute it using aerospike_scan_foreach().
The callback provided to the function above is implemented as:
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:
Typedefs | |
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) |
as_status | aerospike_scan_node (aerospike *as, as_error *err, const as_policy_scan *policy, const as_scan *scan, const char *node_name, aerospike_scan_foreach_callback callback, void *udata) |
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. Multiple threads will likely be calling this callback in parallel. Therefore, your callback implementation should be thread safe.
The following functions accept the callback:
val | The value received from the query. |
udata | User-data provided to the calling function. |
true
to continue to the next value. Otherwise, iteration will end. Definition at line 132 of file aerospike_scan.h.
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.
The scanid can be used to query the status of the scan running in the database via aerospike_scan_info().
as | The aerospike instance to use for this operation. |
err | The as_error to be populated if an error occurs. |
policy | The policy to use for this operation. If NULL, then the default policy will be used. |
scan | The scan to execute against the cluster. |
scan_id | The id for the scan job, which can be used for querying the status of the scan. |
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.
Multiple threads will likely be calling the callback in parallel. Therefore, your callback implementation should be thread safe.
as | The aerospike instance to use for this operation. |
err | The as_error to be populated if an error occurs. |
policy | The policy to use for this operation. If NULL, then the default policy will be used. |
scan | The scan to execute against the cluster. |
callback | The function to be called for each record scanned. |
udata | User-data to be passed to the callback. |
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.
as | The aerospike instance to use for this operation. |
err | The as_error to be populated if an error occurs. |
policy | The policy to use for this operation. If NULL, then the default policy will be used. |
scan_id | The id for the scan job to check the status of. |
info | Information about this scan, to be populated by this operation. |
as_status aerospike_scan_node | ( | aerospike * | as, |
as_error * | err, | ||
const as_policy_scan * | policy, | ||
const as_scan * | scan, | ||
const char * | node_name, | ||
aerospike_scan_foreach_callback | callback, | ||
void * | udata | ||
) |
Scan the records in the specified namespace and set for a single node.
The callback function will be called for each record scanned. When all records have been scanned, then callback will be called with a NULL value for the record.
as | The aerospike instance to use for this operation. |
err | The as_error to be populated if an error occurs. |
policy | The policy to use for this operation. If NULL, then the default policy will be used. |
scan | The scan to execute against the cluster. |
node_name | The node name to scan. |
callback | The function to be called for each record scanned. |
udata | User-data to be passed to the callback. |