AerospikeC client manual --- data scanning-record Scanning

Source: Internet
Author: User

AerospikeC client manual --- data scanning-record Scanning
The Aerospike C client provides the ability to scan all records in a specified namespace and set.
Scan can be defined using the scan API. You can use the scan API to initialize and populate an as_scan object.
With the initialized as_scan, scan can be performed using any of the following operations:
Aerospike_scan_foreach ()-executes a scan and calls a function for each record.
Aerospike_scan_background ()-performs a scan but does not result in it. It provides the ability to check the scan status. Use foreach to process results

The aerospike_scan_foreach () function performs a scan and calls the callback function one by one for the searched records. The structure of the callback function is:

typedef bool (*aerospike_scan_foreach_callback)(const as_val *value, void *udata);

This callback function is called on each record found during the scan. The record is passed through the parameter value. The user provides data to be transmitted by the parameter udata. Note that the value type is const as_val *, which means that the callback function has no responsibility to destroy the value, and the value is only visible in the scope of the callback function. The callback function cannot pass the value beyond the function scope.

When no more results need to be processed, the callback function is called using NULL as the value of the parameter value.

For normal scan operations, value is a record, which can be simply converted to a record object using as_record_fromval. If the parameter value is a record, this function returns a record object; otherwise, NULL is returned ). You can also use as_val_type () to check the value type.

bool callback(const as_val *value, void *udata) { if (value == NULL) { // scan is complete return true; } as_record *rec = as_record_fromval(value); if (rec != NULL) { // process record } return true;}
Check the background scan status

The function aerospike_scan_background () sends a scan request to the database for execution. The client does not have to wait for the result. The client returns a scan id to check the running status of the scan.

Scan IDS can be used to periodically check the scanning status. Ideally, the application intelligently determines the frequency of the polling status based on the obtained scanning status.

The scanned status information is filled in the as_scane_info instance object:

as_scan_info scan_info;if (aerospike_scan_info(&as, &err, NULL, scan_id, &scan_info) != AEROSPIKE_OK) { fprintf(stderr, "err(%d) %s at [%s:%d]\n", err.code, err.message, err.file, err.line);}

The above Code simply checks the status and assumes that the status check is only performed once.

If the application continues to track the running time in use, you can check the member domain progress_pct of scan_info after obtaining the status, and estimate how long the scan will take ,.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.