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:
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) |
typedef bool(* | as_async_scan_listener )(as_error *err, as_record *record, void *udata, as_event_loop *event_loop) |
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 synchronous scan. Multiple threads will likely be calling this callback in parallel. Therefore, your callback implementation should be thread safe.
val | The value received from the query. |
udata | User-data provided to the calling function. |
true
to continue to the next value. Otherwise, the scan will end. Definition at line 121 of file aerospike_scan.h.
typedef bool(* as_async_scan_listener)(as_error *err, as_record *record, void *udata, as_event_loop *event_loop) |
Asynchronous scan user callback. This function is called for each record returned. This function is also called once when the scan completes or an error has occurred.
err | This error structure is only populated when the command fails. NULL on success. |
record | Returned record. The record will be NULL on final scan completion or scan error. |
udata | User data that is forwarded from asynchronous command function. |
event_loop | Event loop that this command was executed on. Use this event loop when running nested asynchronous commands when single threaded behavior is desired for the group of commands. |
true
to continue to the next value. Otherwise, the scan will end. Definition at line 140 of file aerospike_scan.h.
AS_EXTERN as_status aerospike_scan_async | ( | aerospike * | as, |
as_error * | err, | ||
const as_policy_scan * | policy, | ||
as_scan * | scan, | ||
uint64_t * | scan_id, | ||
as_async_scan_listener | listener, | ||
void * | udata, | ||
as_event_loop * | event_loop | ||
) |
Asynchronously scan the records in the specified namespace and set in the cluster.
Call the listener function for each record scanned. When all records have been scanned, then listener will be called with a NULL value for the record.
Scans of each node will be run on the same event loop, so the listener's implementation does not need to be thread safe.
as | The aerospike instance to use for this operation. |
err | The as_error to be populated if an error occurs. |
policy | Scan policy configuration parameters, pass in NULL for default. |
scan | The scan to execute against the cluster. |
scan_id | The id for the scan job. Use NULL if the scan_id will not be used. |
listener | The function to be called for each record scanned. |
udata | User-data to be passed to the callback. |
event_loop | Event loop assigned to run this command. If NULL, an event loop will be chosen by round-robin. |
AS_EXTERN 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 | Scan policy configuration parameters, pass in NULL for default. |
scan | The scan to execute against the cluster. |
scan_id | The id for the scan job, which can be used for obtaining scan status. |
AS_EXTERN as_status aerospike_scan_foreach | ( | aerospike * | as, |
as_error * | err, | ||
const as_policy_scan * | policy, | ||
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.
If "scan.concurrent" is true (default false), the callback code must be thread-safe.
as | The aerospike instance to use for this operation. |
err | The as_error to be populated if an error occurs. |
policy | Scan policy configuration parameters, pass in NULL for default. |
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_EXTERN 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 | Scan policy configuration parameters, pass in NULL for default. |
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_EXTERN as_status aerospike_scan_node | ( | aerospike * | as, |
as_error * | err, | ||
const as_policy_scan * | policy, | ||
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 | Scan policy configuration parameters, pass in NULL for default. |
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. |
AS_EXTERN as_status aerospike_scan_node_async | ( | aerospike * | as, |
as_error * | err, | ||
const as_policy_scan * | policy, | ||
as_scan * | scan, | ||
uint64_t * | scan_id, | ||
const char * | node_name, | ||
as_async_scan_listener | listener, | ||
void * | udata, | ||
as_event_loop * | event_loop | ||
) |
Asynchronously scan the records in the specified namespace and set for a single node.
The listener 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 | Scan policy configuration parameters, pass in NULL for default. |
scan | The scan to execute against the cluster. |
scan_id | The id for the scan job. Use NULL if the scan_id will not be used. |
node_name | The node name to scan. |
listener | The function to be called for each record scanned. |
udata | User-data to be passed to the callback. |
event_loop | Event loop assigned to run this command. If NULL, an event loop will be chosen by round-robin. |
AS_EXTERN as_status aerospike_scan_partitions | ( | aerospike * | as, |
as_error * | err, | ||
const as_policy_scan * | policy, | ||
as_scan * | scan, | ||
as_partition_filter * | pf, | ||
aerospike_scan_foreach_callback | callback, | ||
void * | udata | ||
) |
Scan records in specified namespace, set and partition filter.
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.
If "scan.concurrent" is true (default false), the callback code must be thread-safe.
as | The aerospike instance to use for this operation. |
err | The as_error to be populated if an error occurs. |
policy | Scan policy configuration parameters, pass in NULL for default. |
scan | The scan to execute against the cluster. |
pf | Partition filter. |
callback | The function to be called for each record scanned. |
udata | User-data to be passed to the callback. |
AS_EXTERN as_status aerospike_scan_partitions_async | ( | aerospike * | as, |
as_error * | err, | ||
const as_policy_scan * | policy, | ||
as_scan * | scan, | ||
as_partition_filter * | pf, | ||
as_async_scan_listener | listener, | ||
void * | udata, | ||
as_event_loop * | event_loop | ||
) |
Asynchronously scan records in specified namespace, set and partition filter.
Call the listener function for each record scanned. When all records have been scanned, then listener will be called with a NULL value for the record.
Scans of each node will be run on the same event loop, so the listener's implementation does not need to be thread safe.
as | The aerospike instance to use for this operation. |
err | The as_error to be populated if an error occurs. |
policy | Scan policy configuration parameters, pass in NULL for default. |
scan | The scan to execute against the cluster. |
pf | Partition filter. |
listener | The function to be called for each record scanned. |
udata | User-data to be passed to the callback. |
event_loop | Event loop assigned to run this command. If NULL, an event loop will be chosen by round-robin. |