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

Description

The Batch API is a collection of APIs that use multiple keys for looking up records in one call.

+ Collaboration diagram for Batch Operations:

Data Structures

struct  as_batch_apply_record
 
struct  as_batch_base_record
 
struct  as_batch_read_record
 
union  as_batch_record
 
struct  as_batch_records
 
struct  as_batch_remove_record
 
struct  as_batch_write_record
 

Typedefs

typedef as_batch_listener aerospike_batch_read_callback
 
typedef void(* as_async_batch_listener )(as_error *err, as_batch_records *records, void *udata, as_event_loop *event_loop)
 
typedef bool(* as_batch_listener )(const as_batch_result *results, uint32_t n, void *udata)
 
typedef as_batch_records as_batch_read_records
 
typedef uint8_t as_batch_type
 

Functions

AS_EXTERN as_status aerospike_batch_apply (aerospike *as, as_error *err, const as_policy_batch *policy, const as_policy_batch_apply *policy_apply, const as_batch *batch, const char *module, const char *function, as_list *arglist, as_batch_listener listener, void *udata)
 
AS_EXTERN as_status aerospike_batch_exists (aerospike *as, as_error *err, const as_policy_batch *policy, const as_batch *batch, as_batch_listener listener, void *udata)
 
AS_EXTERN as_status aerospike_batch_get (aerospike *as, as_error *err, const as_policy_batch *policy, const as_batch *batch, as_batch_listener listener, void *udata)
 
AS_EXTERN as_status aerospike_batch_get_bins (aerospike *as, as_error *err, const as_policy_batch *policy, const as_batch *batch, const char **bins, uint32_t n_bins, as_batch_listener listener, void *udata)
 
AS_EXTERN as_status aerospike_batch_get_ops (aerospike *as, as_error *err, const as_policy_batch *policy, const as_batch *batch, as_operations *ops, as_batch_listener listener, void *udata)
 
AS_EXTERN as_status aerospike_batch_operate (aerospike *as, as_error *err, const as_policy_batch *policy, const as_policy_batch_write *policy_write, const as_batch *batch, as_operations *ops, as_batch_listener listener, void *udata)
 
AS_EXTERN as_status aerospike_batch_read (aerospike *as, as_error *err, const as_policy_batch *policy, as_batch_records *records)
 
AS_EXTERN as_status aerospike_batch_read_async (aerospike *as, as_error *err, const as_policy_batch *policy, as_batch_records *records, as_async_batch_listener listener, void *udata, as_event_loop *event_loop)
 
AS_EXTERN as_status aerospike_batch_remove (aerospike *as, as_error *err, const as_policy_batch *policy, const as_policy_batch_remove *policy_remove, const as_batch *batch, as_batch_listener listener, void *udata)
 
AS_EXTERN as_status aerospike_batch_write (aerospike *as, as_error *err, const as_policy_batch *policy, as_batch_records *records)
 
AS_EXTERN as_status aerospike_batch_write_async (aerospike *as, as_error *err, const as_policy_batch *policy, as_batch_records *records, as_async_batch_listener listener, void *udata, as_event_loop *event_loop)
 
static as_batch_apply_recordas_batch_apply_reserve (as_batch_records *records)
 
static as_batch_recordsas_batch_read_create (uint32_t capacity)
 
static void as_batch_read_destroy (as_batch_records *records)
 
static void as_batch_read_init (as_batch_records *records, uint32_t capacity)
 
static as_batch_read_recordas_batch_read_reserve (as_batch_records *records)
 
static as_batch_recordsas_batch_records_create (uint32_t capacity)
 
AS_EXTERN void as_batch_records_destroy (as_batch_records *records)
 
static void as_batch_records_init (as_batch_records *records, uint32_t capacity)
 
static as_batch_remove_recordas_batch_remove_reserve (as_batch_records *records)
 
static as_batch_write_recordas_batch_write_reserve (as_batch_records *records)
 

Typedef Documentation

This listener will be called with the results of batch commands for all keys.

Deprecated:
Use as_batch_listener instead.

Definition at line 290 of file aerospike_batch.h.

typedef void(* as_async_batch_listener)(as_error *err, as_batch_records *records, void *udata, as_event_loop *event_loop)

Asynchronous batch user listener. This function is called once when the batch completes or an error has occurred.

Parameters
errError structure that is populated if an error occurs. NULL on success.
recordsRecord results. Records must be destroyed with as_batch_records_destroy() when done.
udataUser data that is forwarded from asynchronous command function.
event_loopEvent 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.

Definition at line 305 of file aerospike_batch.h.

typedef bool(* as_batch_listener)(const as_batch_result *results, uint32_t n, void *udata)

This listener will be called with the results of batch commands for all keys.

The results argument will be an array of n as_batch_result entries. The results argument is on the stack and is only available within the context of the listener. To use the data outside of the listener, copy the data.

bool my_listener(const as_batch_result* results, uint32_t n, void* udata) {
return true;
}
Parameters
resultsThe results from the batch request.
nThe number of results from the batch request.
udataUser-data provided to the calling function.
Returns
true on success. Otherwise, an error occurred.

Definition at line 282 of file aerospike_batch.h.

List of batch request/response (as_batch_base_record) records. The record types can be as_batch_read_record, as_batch_write_record, as_batch_apply_record or as_batch_remove_record.

Deprecated:
Use as_batch_records instead.

Definition at line 261 of file aerospike_batch.h.

typedef uint8_t as_batch_type

Batch record type. Values: AS_BATCH_READ, AS_BATCH_WRITE, AS_BATCH_APPLY or AS_BATCH_REMOVE

Definition at line 58 of file aerospike_batch.h.

Function Documentation

AS_EXTERN as_status aerospike_batch_apply ( aerospike as,
as_error err,
const as_policy_batch policy,
const as_policy_batch_apply policy_apply,
const as_batch batch,
const char *  module,
const char *  function,
as_list arglist,
as_batch_listener  listener,
void *  udata 
)

Apply UDF (user defined function) on multiple keys. Requires server version 6.0+

as_arraylist_init(&args, 2, 0);
as_batch batch;
as_batch_inita(&batch, 3);
as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
as_status status = aerospike_batch_apply(as, &err, NULL, NULL, &batch, "mod", "func",
(as_list*)&args, NULL, NULL);
// process results
Parameters
asAerospike cluster instance.
errError detail structure that is populated if an error occurs.
policyBatch policy configuration parameters, pass in NULL for default.
policy_applyUDF policy configuration parameters, pass in NULL for default.
batchList of keys.
moduleServer package name.
functionServer user defined function.
arglistServer user defined function arguments.
listenerUser function to be called with command results.
udataUser data to be forwarded to listener.
Returns
AEROSPIKE_OK if successful. Otherwise an error.
AS_EXTERN as_status aerospike_batch_exists ( aerospike as,
as_error err,
const as_policy_batch policy,
const as_batch batch,
as_batch_listener  listener,
void *  udata 
)

Test whether multiple records exist in the cluster.

as_batch batch;
as_batch_inita(&batch, 3);
as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
as_status status = aerospike_batch_exists(as, &err, NULL, &batch, listener, NULL);
// process results
Parameters
asAerospike cluster instance.
errError detail structure that is populated if an error occurs.
policyBatch policy configuration parameters, pass in NULL for default.
batchThe batch of keys to read.
listenerThe listener to invoke for each record read.
udataThe user-data for the listener.
Returns
AEROSPIKE_OK if successful. Otherwise an error.
AS_EXTERN as_status aerospike_batch_get ( aerospike as,
as_error err,
const as_policy_batch policy,
const as_batch batch,
as_batch_listener  listener,
void *  udata 
)

Look up multiple records by key, then return all bins.

as_batch batch;
as_batch_inita(&batch, 3);
as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
as_status status = aerospike_batch_get(as, &err, NULL, &batch, listener, NULL);
// process results
Parameters
asAerospike cluster instance.
errError detail structure that is populated if an error occurs.
policyBatch policy configuration parameters, pass in NULL for default.
batchList of keys.
listenerUser function to be called with command results.
udataUser data to be forwarded to listener.
Returns
AEROSPIKE_OK if successful. Otherwise an error.
AS_EXTERN as_status aerospike_batch_get_bins ( aerospike as,
as_error err,
const as_policy_batch policy,
const as_batch batch,
const char **  bins,
uint32_t  n_bins,
as_batch_listener  listener,
void *  udata 
)

Look up multiple records by key, then return specified bins.

as_batch batch;
as_batch_inita(&batch, 3);
as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
const char* bin_filters[] = {"bin1", "bin2"};
as_status status = aerospike_batch_get_bins(as, &err, NULL, &batch, bin_filters, 2, listener, NULL);
// process results
Parameters
asAerospike cluster instance.
errError detail structure that is populated if an error occurs.
policyBatch policy configuration parameters, pass in NULL for default.
batchThe batch of keys to read.
binsBin filters. Only return these bins.
n_binsThe number of bin filters.
listenerUser function to be called with command results.
udataUser data to be forwarded to listener.
Returns
AEROSPIKE_OK if successful. Otherwise an error.
AS_EXTERN as_status aerospike_batch_get_ops ( aerospike as,
as_error err,
const as_policy_batch policy,
const as_batch batch,
as_operations ops,
as_batch_listener  listener,
void *  udata 
)

Look up multiple records by key, then return results from specified read operations.

as_batch batch;
as_batch_inita(&batch, 3);
as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
as_operations_list_size(&ops, "list", NULL);
as_status status = aerospike_batch_get_ops(as, &err, NULL, &batch, &ops, listener, NULL);
// process results
Parameters
asAerospike cluster instance.
errError detail structure that is populated if an error occurs.
policyBatch policy configuration parameters, pass in NULL for default.
batchThe batch of keys to read.
opsRead operations.
listenerUser function to be called with command results.
udataUser data to be forwarded to listener.
Returns
AEROSPIKE_OK if successful. Otherwise an error.
AS_EXTERN as_status aerospike_batch_operate ( aerospike as,
as_error err,
const as_policy_batch policy,
const as_policy_batch_write policy_write,
const as_batch batch,
as_operations ops,
as_batch_listener  listener,
void *  udata 
)

Perform read/write operations on multiple keys. Requires server version 6.0+

as_integer_init(&val, 100);
as_operations_list_append(&ops, bin, NULL, NULL, (as_val*)&val);
as_operations_list_size(&ops, bin, NULL);
as_batch batch;
as_batch_inita(&batch, 3);
as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
as_status status = aerospike_batch_operate(as, &err, NULL, NULL, &batch, &ops, listener, NULL);
// process results
Parameters
asAerospike cluster instance.
errError detail structure that is populated if an error occurs.
policyBatch policy configuration parameters, pass in NULL for default.
policy_writeWrite policy configuration parameters, pass in NULL for default.
batchList of keys.
opsRead/Write operations.
listenerUser function to be called with command results.
udataUser data to be forwarded to listener.
Returns
AEROSPIKE_OK if successful. Otherwise an error.
AS_EXTERN as_status aerospike_batch_read ( aerospike as,
as_error err,
const as_policy_batch policy,
as_batch_records records 
)

Read multiple records for specified batch keys in one batch call. This method allows different namespaces/bins to be requested for each key in the batch. The returned records are located in the same batch array.

as_batch_records_inita(&records, 10);
char* bin_names[] = {"bin1", "bin2"};
char* ns = "ns";
char* set = "set";
as_key_init(&record->key, ns, set, "key1");
record->bin_names = bin_names;
record->n_bin_names = 2;
record = as_batch_read_reserve(&records);
as_key_init(&record->key, ns, set, "key2");
record->read_all_bins = true;
as_status status = aerospike_batch_read(as, &err, NULL, &records);
// process results
Parameters
asAerospike cluster instance.
errError detail structure that is populated if an error occurs.
policyBatch policy configuration parameters, pass in NULL for default.
recordsList of keys and records to retrieve. The returned records are located in the same array.
Returns
AEROSPIKE_OK if successful. Otherwise an error.
AS_EXTERN as_status aerospike_batch_read_async ( aerospike as,
as_error err,
const as_policy_batch policy,
as_batch_records records,
as_async_batch_listener  listener,
void *  udata,
as_event_loop event_loop 
)

Asynchronously read multiple records for specified batch keys in one batch call. This method allows different namespaces/bins to be requested for each key in the batch. The returned records are located in the same batch array.

void my_listener(as_error* err, as_batch_records* records, void* udata, as_event_loop* loop)
{
if (err) {
fprintf(stderr, "Command failed: %d %s\n", err->code, err->message);
}
else {
as_vector* list = &records->list;
for (uint32_t i = 0; i < list->size; i++) {
as_batch_read_record* record = as_vector_get(list, i);
// Process record
}
}
// Must free batch records on both success and error conditions because it was created
// before calling aerospike_batch_read_async().
}
// bin_names must point to a static/global array of literal/global strings.
char* bin_names[] = {"bin1", "bin2"};
char* ns = "ns";
char* set = "set";
as_key_init(&record->key, ns, set, "key1");
record->bin_names = bin_names;
record->n_bin_names = 2;
record = as_batch_read_reserve(records);
as_key_init(&record->key, ns, set, "key2");
record->read_all_bins = true;
as_status status = aerospike_batch_read_async(as, &err, NULL, records, NULL, my_listener, NULL);
if (status != AEROSPIKE_OK) {
// Must free batch records on queue error because the listener will not be called.
}
Parameters
asAerospike cluster instance.
errError detail structure that is populated if an error occurs.
policyBatch policy configuration parameters, pass in NULL for default.
recordsList of keys and records to retrieve. Returned records are located in the same list. Must create using as_batch_records_create() (allocates memory on heap) because the async method returns immediately after queueing command.
listenerUser function to be called with command results.
udataUser data to be forwarded to listener.
event_loopEvent loop assigned to run this command. If NULL, an event loop will be chosen by round-robin.
Returns
AEROSPIKE_OK if async command succesfully queued. Otherwise an error.
AS_EXTERN as_status aerospike_batch_remove ( aerospike as,
as_error err,
const as_policy_batch policy,
const as_policy_batch_remove policy_remove,
const as_batch batch,
as_batch_listener  listener,
void *  udata 
)

Remove multiple records. Requires server version 6.0+

as_batch batch;
as_batch_inita(&batch, 3);
as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
as_status status = aerospike_batch_remove(as, &err, NULL, NULL, &batch, listener, NULL);
// process results
Parameters
asAerospike cluster instance.
errError detail structure that is populated if an error occurs.
policyBatch policy configuration parameters, pass in NULL for default.
policy_removeRemove policy configuration parameters, pass in NULL for default.
batchList of keys.
listenerUser function to be called with command results.
udataUser data to be forwarded to listener.
Returns
AEROSPIKE_OK if successful. Otherwise an error.
AS_EXTERN as_status aerospike_batch_write ( aerospike as,
as_error err,
const as_policy_batch policy,
as_batch_records records 
)

Read/Write multiple records for specified batch keys in one batch call. This method allows different sub-commands for each key in the batch. The returned records are located in the same list.

Requires server version 6.0+

as_operations_add_write_int64(&ops1, "bin1", 100);
as_operations_add_write_int64(&ops2, "bin2", 200);
as_key_init_int64(&r->key, "test", "set", 1);
r->ops = &ops1;
as_key_init_int64(&r->key, "test", "set", 2);
r->ops = &ops2;
as_status status = aerospike_batch_write(as, err, NULL, &recs);
// Process results. Overall status contains first error, if any.
Parameters
asAerospike cluster instance.
errError detail structure that is populated if an error occurs.
policyBatch policy configuration parameters, pass in NULL for default.
recordsList of batch sub-commands to perform. The returned records are located in the same list.
Returns
AEROSPIKE_OK if successful. Otherwise an error.
AS_EXTERN as_status aerospike_batch_write_async ( aerospike as,
as_error err,
const as_policy_batch policy,
as_batch_records records,
as_async_batch_listener  listener,
void *  udata,
as_event_loop event_loop 
)

Asynchronously read/write multiple records for specified batch keys in one batch call. This method allows different sub-commands for each key in the batch. The returned records are located in the same list.

Requires server version 6.0+

void my_listener(as_error* err, as_batch_records* records, void* udata, as_event_loop* loop)
{
if (err) {
fprintf(stderr, "Command failed: %d %s\n", err->code, err->message);
}
else {
as_vector* list = &records->list;
for (uint32_t i = 0; i < list->size; i++) {
// Process record
}
}
// Must free batch records on both success and error conditions because it was created
// before calling aerospike_batch_read_async().
}
as_key_init_int64(&wr->key, NAMESPACE, SET, 1);
wr->ops = &ops1;
as_key_init_int64(&wr->key, NAMESPACE, SET, 6);
wr->ops = &ops2;
as_status status = aerospike_batch_write_async(as, &err, NULL, recs, my_listener, NULL, NULL);
if (status != AEROSPIKE_OK) {
// Must free batch records on queue error because the listener will not be called.
}
Parameters
asAerospike cluster instance.
errError detail structure that is populated if an error occurs.
policyBatch policy configuration parameters, pass in NULL for default.
recordsList of keys and records to retrieve. Returned records are located in the same list. Must create using as_batch_records_create() (allocates memory on heap) because the async method returns immediately after queueing command.
listenerUser function to be called with command results.
udataUser data to be forwarded to listener.
event_loopEvent loop assigned to run this command. If NULL, an event loop will be chosen by round-robin.
Returns
AEROSPIKE_OK if async command succesfully queued. Otherwise an error.
static as_batch_apply_record * as_batch_apply_reserve ( as_batch_records records)
related

Reserve a new as_batch_apply_record slot for UDF. Capacity will be increased when necessary. Return reference to record. The record is initialized to zeroes.

Definition at line 438 of file aerospike_batch.h.

References AS_BATCH_APPLY, as_vector_reserve(), as_batch_apply_record::has_write, as_batch_records::list, and as_batch_apply_record::type.

static as_batch_records * as_batch_read_create ( uint32_t  capacity)
related

Create batch records on heap with specified list capacity on the heap.

Deprecated:
Use as_batch_records_create() instead.

Definition at line 394 of file aerospike_batch.h.

References as_vector_create().

static void as_batch_read_destroy ( as_batch_records records)
related

Destroy keys and records in record list. It's the responsility of the caller to free additional user specified fields in the record.

Deprecated:
Use as_batch_records_destroy() instead.

Definition at line 481 of file aerospike_batch.h.

References as_batch_records::as_batch_records_destroy().

static void as_batch_read_init ( as_batch_records records,
uint32_t  capacity 
)
related

Initialize batch records with specified capacity on the heap.

Deprecated:
Use as_batch_records_init() instead.

Definition at line 363 of file aerospike_batch.h.

References as_vector_init(), and as_batch_records::list.

static as_batch_read_record * as_batch_read_reserve ( as_batch_records records)
related

Reserve a new as_batch_read_record slot. Capacity will be increased when necessary. Return reference to record. The record is initialized to zeroes.

Definition at line 407 of file aerospike_batch.h.

References AS_BATCH_READ, as_vector_reserve(), as_batch_records::list, and as_batch_read_record::type.

static as_batch_records * as_batch_records_create ( uint32_t  capacity)
related

Create batch records on heap with specified list capacity on the heap.

When the batch is no longer needed, then use as_batch_records_destroy() to release the batch and associated resources.

Parameters
capacityInitial capacity of batch record list. List will resize when necessary.
Returns
Batch record list.

Definition at line 381 of file aerospike_batch.h.

References as_vector_create().

AS_EXTERN void as_batch_records_destroy ( as_batch_records records)
related

Destroy keys and records in record list. It's the responsility of the caller to free additional user specified fields in the record.

static void as_batch_records_init ( as_batch_records records,
uint32_t  capacity 
)
related

Initialize batch records with specified capacity on the heap.

When the batch is no longer needed, then use as_batch_records_destroy() to release the batch and associated resources.

Parameters
recordsBatch record list.
capacityInitial capacity of batch record list. List will resize when necessary.

Definition at line 350 of file aerospike_batch.h.

References as_vector_init(), and as_batch_records::list.

static as_batch_remove_record * as_batch_remove_reserve ( as_batch_records records)
related

Reserve a new as_batch_remove_record slot. Capacity will be increased when necessary. Return reference to record. The record is initialized to zeroes.

Definition at line 454 of file aerospike_batch.h.

References AS_BATCH_REMOVE, as_vector_reserve(), as_batch_remove_record::has_write, as_batch_records::list, and as_batch_remove_record::type.

static as_batch_write_record * as_batch_write_reserve ( as_batch_records records)
related

Reserve a new as_batch_write_record slot. Capacity will be increased when necessary. Return reference to record. The record is initialized to zeroes.

Definition at line 422 of file aerospike_batch.h.

References AS_BATCH_WRITE, as_vector_reserve(), as_batch_write_record::has_write, as_batch_records::list, and as_batch_write_record::type.