![]() |
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:
Data Structures | |
struct | as_scan |
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 | This legacy argument is ignored. scan_ids are now internally generated. Always pass in NULL. |
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 | This legacy argument is ignored. scan_ids are now internally generated. Always pass in NULL. |
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. |
|
related |
Apply a UDF to each record scanned on the server.
scan | The scan to apply the UDF to. |
module | The module containing the function to execute. |
function | The function to execute. |
arglist | The arguments for the function. |
Releases all resources allocated to the scan.
|
related |
Deserialize bytes to scan definition. Scan definition is assumed to be on the stack. as_scan_destroy() should be called when done with the scan definition.
Create scan definition on the heap and deserialize bytes to that scan definition. as_scan_destroy() should be called when done with the scan definition.
Initializes a scan.
When you no longer require the scan, you should release the scan and related resources via as_scan_destroy()
.
scan | The scan to initialize. |
ns | The namespace to scan. |
set | The set to scan. |
|
related |
If using scan pagination, did previous paginated scan with this scan instance return all records?
Definition at line 603 of file as_scan.h.
References as_partitions_status::done, and as_scan::parts_all.
Create and initializes a new scan on the heap.
When you no longer require the scan, you should release the scan and related resources via as_scan_destroy()
.
ns | The namespace to scan. |
set | The set to scan. |
Select bins to be projected from matching records.
You have to ensure as_scan.select has sufficient capacity, prior to adding a bin. If capacity is insufficient then false is returned.
scan | The scan to modify. |
bin | The name of the bin to select. |
Initializes as_scan.select
with a capacity of n
using malloc()
.
For stack allocation, use as_scan_select_inita()
.
scan | The scan to initialize. |
n | The number of bins to allocate. |
Scan all the nodes in prallel
scan | The scan to set the concurrency on. |
concurrent | If true, scan all the nodes in parallel |
Do not return bins. This will only return the metadata for the records.
scan | The scan to set the priority on. |
nobins | If true, then do not return bins. |
|
related |
Set to true if as_policy_scan.max_records is set and you need to scan data in pages.
Definition at line 577 of file as_scan.h.
References as_scan::paginate.
|
related |
Set completion status of all partitions from a previous scan that ended early. The scan will resume from this point.
Definition at line 590 of file as_scan.h.
References as_partitions_status_reserve(), and as_scan::parts_all.