All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
aerospike_batch.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2025 Aerospike, Inc.
3 *
4 * Portions may be licensed to Aerospike, Inc. under one or more contributor
5 * license agreements.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8 * use this file except in compliance with the License. You may obtain a copy of
9 * the License at http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17#pragma once
18
19/**
20 * @defgroup batch_operations Batch Operations
21 * @ingroup client_operations
22 *
23 * The Batch API is a collection of APIs that use multiple keys for looking up
24 * records in one call.
25 */
26
27#include <aerospike/aerospike.h>
28#include <aerospike/as_batch.h>
30#include <aerospike/as_error.h>
31#include <aerospike/as_key.h>
32#include <aerospike/as_list.h>
34#include <aerospike/as_policy.h>
35#include <aerospike/as_record.h>
36#include <aerospike/as_status.h>
37#include <aerospike/as_val.h>
38#include <aerospike/as_vector.h>
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44//---------------------------------
45// Types
46//---------------------------------
47
48#define AS_BATCH_READ 0
49#define AS_BATCH_WRITE 1
50#define AS_BATCH_APPLY 2
51#define AS_BATCH_REMOVE 3
52#define AS_BATCH_TXN_VERIFY 4
53#define AS_BATCH_TXN_ROLL 5
54
55/**
56 * Batch record type. Values: AS_BATCH_READ, AS_BATCH_WRITE, AS_BATCH_APPLY or AS_BATCH_REMOVE
57 *
58 * @ingroup batch_operations
59 */
60typedef uint8_t as_batch_type;
61
62/**
63 * Batch base request/response record. Used in batch commands where different command types are
64 * needed for different keys. All batch record types contain these base fields.
65 *
66 * @ingroup batch_operations
67 */
68typedef struct as_batch_base_record_s {
69 /**
70 * Requested key.
71 */
73
74 /**
75 * Record result for the requested key. This record will only be populated when the result is
76 * AEROSPIKE_OK or AEROSPIKE_ERR_UDF. If AEROSPIKE_ERR_UDF, use as_record_get_udf_error()
77 * to obtain the error message.
78 */
80
81 /**
82 * Result code.
83 */
85
86 /**
87 * Type of batch record.
88 */
90
91 /**
92 * Does batch sub-command contain a write operation.
93 */
95
96 /**
97 * Is it possible that the write command completed even though this error was generated.
98 * This may be the case when a client error occurs (like timeout) after the command was sent
99 * to the server.
100 */
103
104/**
105 * Batch key and read only operations with read policy.
106 *
107 * @relates as_batch_base_record
108 * @ingroup batch_operations
109 */
110typedef struct as_batch_read_record_s {
116 bool in_doubt; // Will always be false for reads.
117
118 /**
119 * Optional read policy.
120 */
122
123 /**
124 * Read operations for this key. ops are mutually exclusive with bin_names.
125 * If defined, the user must call as_operations_destroy() when done with the batch.
126 */
128
129 /**
130 * Bin names requested for this key. bin_names are mutually exclusive with ops.
131 * If heap defined, the user must free when done with the batch.
132 */
133 char** bin_names;
134
135 /**
136 * Count of bin names requested for this key.
137 */
138 uint32_t n_bin_names;
139
140 /**
141 * If true, ignore bin_names and read all bins.
142 * If false and bin_names are set, read specified bin_names.
143 * If false and bin_names are not set, read record header (generation, expiration) only.
144 */
147
148/**
149 * Batch key and read/write operations with write policy.
150 *
151 * All fields must be allocated on the heap (or global) when an async batch write is run under a
152 * transaction. The reason is transactions require an extra async call to add write keys to the
153 * transaction monitor record and this extra call causes stack variables to fall out of scope before
154 * the async batch is executed.
155 *
156 * @relates as_batch_base_record
157 * @ingroup batch_operations
158 */
159typedef struct as_batch_write_record_s {
161 as_record record; // Contains results of operations from ops field.
166
167 /**
168 * Optional write policy.
169 */
171
172 /**
173 * Required read/write operations for this key. The user must call as_operations_destroy()
174 * when done with the batch.
175 */
178
179/**
180 * Batch UDF (user defined function) apply.
181 *
182 * All fields must be allocated on the heap (or global) when an async batch UDF is run under a
183 * transaction. The reason is transactions require an extra async call to add write keys to the
184 * transaction monitor record and this extra call causes stack variables to fall out of scope before
185 * the async batch is executed.
186 *
187 * @relates as_batch_base_record
188 * @ingroup batch_operations
189 */
190typedef struct as_batch_apply_record_s {
197
198 /**
199 * Optional apply policy.
200 */
202
203 /**
204 * Package or lua module name.
205 * If heap defined, the user must free when done with the batch.
206 */
207 const char* module;
208
209 /**
210 * Lua function name.
211 * If heap defined, the user must free when done with the batch.
212 */
213 const char* function;
214
215 /**
216 * Optional arguments to lua function.
217 * If defined, the user must call as_arraylist_destroy() when done with the batch.
218 */
221
222/**
223 * Batch delete operation.
224 *
225 * All fields must be allocated on the heap (or global) when an async batch remove is run under a
226 * transaction. The reason is transactions require an extra async call to add write keys to the
227 * transaction monitor record and this extra call causes stack variables to fall out of scope before
228 * the async batch is executed.
229 *
230 * @relates as_batch_base_record
231 * @ingroup batch_operations
232 */
233typedef struct as_batch_remove_record_s {
240
241 /**
242 * Optional remove policy.
243 */
246
247/**
248 * Batch request/response record union.
249 *
250 * @relates as_batch_base_record
251 * @ingroup batch_operations
252 */
260
261/**
262 * List of batch request/response (as_batch_base_record) records. The record types can be
263 * as_batch_read_record, as_batch_write_record, as_batch_apply_record or as_batch_remove_record.
264 *
265 * @ingroup batch_operations
266 */
267typedef struct as_batch_records_s {
270
271/**
272 * List of batch request/response (as_batch_base_record) records. The record types can be
273 * as_batch_read_record, as_batch_write_record, as_batch_apply_record or as_batch_remove_record.
274 *
275 * @deprecated Use as_batch_records instead.
276 * @ingroup batch_operations
277 */
279
280/**
281 * This listener will be called with the results of batch commands for all keys.
282 *
283 * The `results` argument will be an array of `n` as_batch_result entries. The
284 * `results` argument is on the stack and is only available within the context
285 * of the listener. To use the data outside of the listener, copy the data.
286 *
287 * ~~~~~~~~~~{.c}
288 * bool my_listener(const as_batch_result* results, uint32_t n, void* udata) {
289 * return true;
290 * }
291 * ~~~~~~~~~~
292 *
293 * @param results The results from the batch request.
294 * @param n The number of results from the batch request.
295 * @param udata User-data provided to the calling function.
296 * @return `true` on success. Otherwise, an error occurred.
297 * @ingroup batch_operations
298 */
299typedef bool (*as_batch_listener)(const as_batch_result* results, uint32_t n, void* udata);
300
301/**
302 * This listener will be called with the results of batch commands for all keys.
303 *
304 * @deprecated Use as_batch_listener instead.
305 * @ingroup batch_operations
306 */
308
309/**
310 * Asynchronous batch user listener. This function is called once when the batch completes or an
311 * error has occurred.
312 *
313 * @param err Error structure that is populated if an error occurs. NULL on success.
314 * @param records Record results. Records must be destroyed with as_batch_records_destroy()
315 * when done.
316 * @param udata User data that is forwarded from asynchronous command function.
317 * @param event_loop Event loop that this command was executed on. Use this event loop when
318 * running nested asynchronous commands when single threaded behavior is
319 * desired for the group of commands.
320 * @ingroup batch_operations
321 */
322typedef void (*as_async_batch_listener)(as_error* err, as_batch_records* records, void* udata,
323 as_event_loop* event_loop);
324
325//---------------------------------
326// Functions
327//---------------------------------
328
329/**
330 * Initialize batch records with specified capacity on the stack using alloca().
331 *
332 * When the batch is no longer needed, then use as_batch_records_destroy() to
333 * release the batch and associated resources.
334 *
335 * @param __records Batch record list.
336 * @param __capacity Initial capacity of batch record list. List will resize when necessary.
337 *
338 * @relates as_batch_records
339 * @ingroup batch_operations
340 */
341#define as_batch_records_inita(__records, __capacity) \
342 as_vector_inita(&((__records)->list), sizeof(as_batch_record), __capacity);
343
344/**
345 * Initialize batch records with specified capacity on the stack using alloca().
346 *
347 * @deprecated Use as_batch_records_inita() instead.
348 * @relates as_batch_records
349 * @ingroup batch_operations
350 */
351#define as_batch_read_inita(__records, __capacity) \
352 as_vector_inita(&((__records)->list), sizeof(as_batch_record), __capacity);
353
354/**
355 * Initialize batch records with specified capacity on the heap.
356 *
357 * When the batch is no longer needed, then use as_batch_records_destroy() to
358 * release the batch and associated resources.
359 *
360 * @param records Batch record list.
361 * @param capacity Initial capacity of batch record list. List will resize when necessary.
362 *
363 * @relates as_batch_records
364 * @ingroup batch_operations
365 */
366static inline void
367as_batch_records_init(as_batch_records* records, uint32_t capacity)
368{
369 as_vector_init(&records->list, sizeof(as_batch_record), capacity);
370}
371
372/**
373 * Initialize batch records with specified capacity on the heap.
374 *
375 * @deprecated Use as_batch_records_init() instead.
376 * @relates as_batch_records
377 * @ingroup batch_operations
378 */
379static inline void
380as_batch_read_init(as_batch_records* records, uint32_t capacity)
381{
382 as_vector_init(&records->list, sizeof(as_batch_record), capacity);
383}
384
385/**
386 * Create batch records on heap with specified list capacity on the heap.
387 *
388 * When the batch is no longer needed, then use as_batch_records_destroy() to
389 * release the batch and associated resources.
390 *
391 * @param capacity Initial capacity of batch record list. List will resize when necessary.
392 * @return Batch record list.
393 *
394 * @relates as_batch_records
395 * @ingroup batch_operations
396 */
397static inline as_batch_records*
398as_batch_records_create(uint32_t capacity)
399{
400 return (as_batch_records*)as_vector_create(sizeof(as_batch_record), capacity);
401}
402
403/**
404 * Create batch records on heap with specified list capacity on the heap.
405 *
406 * @deprecated Use as_batch_records_create() instead.
407 * @relates as_batch_records
408 * @ingroup batch_operations
409 */
410static inline as_batch_records*
411as_batch_read_create(uint32_t capacity)
412{
413 return (as_batch_records*)as_vector_create(sizeof(as_batch_record), capacity);
414}
415
416/**
417 * Reserve a new `as_batch_read_record` slot. Capacity will be increased when necessary.
418 * Return reference to record. The record is initialized to zeroes.
419 *
420 * @relates as_batch_records
421 * @ingroup batch_operations
422 */
423static inline as_batch_read_record*
430
431/**
432 * Reserve a new `as_batch_write_record` slot. Capacity will be increased when necessary.
433 * Return reference to record. The record is initialized to zeroes.
434 *
435 * @relates as_batch_records
436 * @ingroup batch_operations
437 */
438static inline as_batch_write_record*
440{
442 r->type = AS_BATCH_WRITE;
443 r->has_write = true;
444 return r;
445}
446
447/**
448 * Reserve a new `as_batch_apply_record` slot for UDF. Capacity will be increased when necessary.
449 * Return reference to record. The record is initialized to zeroes.
450 *
451 * @relates as_batch_records
452 * @ingroup batch_operations
453 */
454static inline as_batch_apply_record*
456{
458 r->type = AS_BATCH_APPLY;
459 r->has_write = true;
460 return r;
461}
462
463/**
464 * Reserve a new `as_batch_remove_record` slot. Capacity will be increased when necessary.
465 * Return reference to record. The record is initialized to zeroes.
466 *
467 * @relates as_batch_records
468 * @ingroup batch_operations
469 */
470static inline as_batch_remove_record*
472{
475 r->has_write = true;
476 return r;
477}
478
479/**
480 * Destroy keys and records in record list. It's the responsility of the caller to
481 * free additional user specified fields in the record.
482 *
483 * @relates as_batch_records
484 * @ingroup batch_operations
485 */
486AS_EXTERN void
488
489/**
490 * Destroy keys and records in record list. It's the responsility of the caller to
491 * free additional user specified fields in the record.
492 *
493 * @deprecated Use as_batch_records_destroy() instead.
494 * @relates as_batch_records
495 * @ingroup batch_operations
496 */
497static inline void
499{
500 as_batch_records_destroy(records);
501}
502
503/**
504 * Read multiple records for specified batch keys in one batch call.
505 * This method allows different namespaces/bins to be requested for each key in the batch.
506 * The returned records are located in the same batch array.
507 *
508 * ~~~~~~~~~~{.c}
509 * as_batch_records records;
510 * as_batch_records_inita(&records, 10);
511 *
512 * char* bin_names[] = {"bin1", "bin2"};
513 * char* ns = "ns";
514 * char* set = "set";
515 *
516 * as_batch_read_record* record = as_batch_read_reserve(&records);
517 * as_key_init(&record->key, ns, set, "key1");
518 * record->bin_names = bin_names;
519 * record->n_bin_names = 2;
520 *
521 * record = as_batch_read_reserve(&records);
522 * as_key_init(&record->key, ns, set, "key2");
523 * record->read_all_bins = true;
524 *
525 * as_status status = aerospike_batch_read(as, &err, NULL, &records);
526 * // process results
527 * as_batch_records_destroy(&records);
528 * ~~~~~~~~~~
529 *
530 * @param as Aerospike cluster instance.
531 * @param err Error detail structure that is populated if an error occurs.
532 * @param policy Batch policy configuration parameters, pass in NULL for default.
533 * @param records List of keys and records to retrieve.
534 * The returned records are located in the same array.
535 *
536 * @return AEROSPIKE_OK if successful. Otherwise an error.
537 * @ingroup batch_operations
538 */
541 aerospike* as, as_error* err, const as_policy_batch* policy, as_batch_records* records
542 );
543
544/**
545 * Asynchronously read multiple records for specified batch keys in one batch call.
546 * This method allows different namespaces/bins to be requested for each key in the batch.
547 * The returned records are located in the same batch array.
548 *
549 * ~~~~~~~~~~{.c}
550 * void my_listener(as_error* err, as_batch_records* records, void* udata, as_event_loop* loop)
551 * {
552 * if (err) {
553 * fprintf(stderr, "Command failed: %d %s\n", err->code, err->message);
554 * }
555 * else {
556 * as_vector* list = &records->list;
557 * for (uint32_t i = 0; i < list->size; i++) {
558 * as_batch_read_record* record = as_vector_get(list, i);
559 * // Process record
560 * }
561 * }
562 * // Must free batch records on both success and error conditions because it was created
563 * // before calling aerospike_batch_read_async().
564 * as_batch_records_destroy(records);
565 * }
566 *
567 * as_batch_records* records = as_batch_records_create(10);
568 *
569 * // bin_names must point to a static/global array of literal/global strings.
570 * char* bin_names[] = {"bin1", "bin2"};
571 * char* ns = "ns";
572 * char* set = "set";
573 *
574 * as_batch_read_record* record = as_batch_read_reserve(records);
575 * as_key_init(&record->key, ns, set, "key1");
576 * record->bin_names = bin_names;
577 * record->n_bin_names = 2;
578 *
579 * record = as_batch_read_reserve(records);
580 * as_key_init(&record->key, ns, set, "key2");
581 * record->read_all_bins = true;
582 *
583 * as_status status = aerospike_batch_read_async(as, &err, NULL, records, NULL, my_listener, NULL);
584 *
585 * if (status != AEROSPIKE_OK) {
586 * // Must free batch records on queue error because the listener will not be called.
587 * as_batch_records_destroy(records);
588 * }
589 * ~~~~~~~~~~
590 *
591 * @param as Aerospike cluster instance.
592 * @param err Error detail structure that is populated if an error occurs.
593 * @param policy Batch policy configuration parameters, pass in NULL for default.
594 * @param records List of keys and records to retrieve. Returned records are located in the
595 * same list. Must create using as_batch_records_create() (allocates memory on
596 * heap) because the async method returns immediately after queueing command.
597 * @param listener User function to be called with command results.
598 * @param udata User data to be forwarded to listener.
599 * @param event_loop Event loop assigned to run this command. If NULL, an event loop will be
600 * chosen by round-robin.
601 *
602 * @return AEROSPIKE_OK if async command succesfully queued. Otherwise an error.
603 * @ingroup batch_operations
604 */
607 aerospike* as, as_error* err, const as_policy_batch* policy, as_batch_records* records,
608 as_async_batch_listener listener, void* udata, as_event_loop* event_loop
609 );
610
611/**
612 * Read/Write multiple records for specified batch keys in one batch call.
613 * This method allows different sub-commands for each key in the batch.
614 * The returned records are located in the same list.
615 *
616 * Requires server version 6.0+
617 *
618 * ~~~~~~~~~~{.c}
619 * as_operations ops1;
620 * as_operations_inita(&ops1, 1);
621 * as_operations_add_write_int64(&ops1, "bin1", 100);
622 *
623 * as_operations ops2;
624 * as_operations_inita(&ops2, 1);
625 * as_operations_add_write_int64(&ops2, "bin2", 200);
626 *
627 * as_batch_records recs;
628 * as_batch_records_inita(&recs, 2);
629 *
630 * as_batch_write_record* r = as_batch_write_reserve(&recs);
631 * as_key_init_int64(&r->key, "test", "set", 1);
632 * r->ops = &ops1;
633 *
634 * r = as_batch_write_reserve(&recs);
635 * as_key_init_int64(&r->key, "test", "set", 2);
636 * r->ops = &ops2;
637 *
638 * as_status status = aerospike_batch_write(as, err, NULL, &recs);
639 *
640 * // Process results. Overall status contains first error, if any.
641 * as_operations_destroy(&ops1);
642 * as_operations_destroy(&ops2);
643 * as_batch_records_destroy(&recs);
644 * ~~~~~~~~~~
645 *
646 * @param as Aerospike cluster instance.
647 * @param err Error detail structure that is populated if an error occurs.
648 * @param policy Batch policy configuration parameters, pass in NULL for default.
649 * @param records List of batch sub-commands to perform. The returned records are located in the
650 * same list.
651 *
652 * @return AEROSPIKE_OK if successful. Otherwise an error.
653 * @ingroup batch_operations
654 */
657 aerospike* as, as_error* err, const as_policy_batch* policy, as_batch_records* records
658 );
659
664
665/**
666 * Asynchronously read/write multiple records for specified batch keys in one batch call.
667 * This method allows different sub-commands for each key in the batch.
668 * The returned records are located in the same list.
669 *
670 * All as_batch_record pointer fields must be allocated on the heap (or global) when an async batch
671 * write is run under a transaction. The reason is transactions require an extra async call to add
672 * write keys to the transaction monitor record and this extra call causes stack variables to fall out
673 * of scope before the async batch is executed.
674 *
675 * Requires server version 6.0+
676 *
677 * ~~~~~~~~~~{.c}
678 * typedef struct {
679 * as_operations* ops1;
680 * as_operations* ops2;
681 * } heap_fields;
682 *
683 * void my_listener(as_error* err, as_batch_records* records, void* udata, as_event_loop* loop)
684 * {
685 * if (err) {
686 * fprintf(stderr, "Command failed: %d %s\n", err->code, err->message);
687 * }
688 * else {
689 * as_vector* list = &records->list;
690 * for (uint32_t i = 0; i < list->size; i++) {
691 * as_batch_base_record* r = as_vector_get(list, i);
692 * // Process record
693 * }
694 * }
695 *
696 * // Must free batch records on both success and error conditions because it was created
697 * // before calling aerospike_batch_read_async().
698 * as_batch_records_destroy(records);
699 *
700 * heap_fields* hf = udata;
701 * as_operations_destroy(hf->ops1);
702 * as_operations_destroy(hf->ops2);
703 * free(hf);
704 * }
705 *
706 * as_operations* ops1 = as_operations_new(2);
707 * as_operations_add_write_int64(ops1, bin1, 100);
708 * as_operations_add_read(ops1, bin2);
709 *
710 * as_operations* ops2 = as_operations_new(2);
711 * as_operations_add_write_int64(ops2, bin3, 0);
712 * as_operations_add_read(ops2, bin4);
713 *
714 * as_batch_records* recs = as_batch_records_create(2);
715 *
716 * as_batch_write_record* wr = as_batch_write_reserve(recs);
717 * as_key_init_int64(&wr->key, NAMESPACE, SET, 1);
718 * wr->ops = ops1;
719 *
720 * wr = as_batch_write_reserve(recs);
721 * as_key_init_int64(&wr->key, NAMESPACE, SET, 6);
722 * wr->ops = ops2;
723 *
724 * heap_fields* hf = malloc(sizeof(heap_fields));
725 * hf->ops1 = ops1;
726 * hf->ops2 = ops2;
727 *
728 * as_status status = aerospike_batch_write_async(as, &err, NULL, recs, my_listener, hf, NULL);
729 *
730 * if (status != AEROSPIKE_OK) {
731 * // Must free batch records on queue error because the listener will not be called.
732 * as_batch_records_destroy(records);
733 * as_operations_destroy(ops1);
734 * as_operations_destroy(ops2);
735 * free(hf);
736 * }
737 * ~~~~~~~~~~
738 *
739 * @param as Aerospike cluster instance.
740 * @param err Error detail structure that is populated if an error occurs.
741 * @param policy Batch policy configuration parameters, pass in NULL for default.
742 * @param records List of keys and records to retrieve. Returned records are located in the
743 * same list. Must create using as_batch_records_create() (allocates memory on
744 * heap) because the async method returns immediately after queueing command.
745 * @param listener User function to be called with command results.
746 * @param udata User data to be forwarded to listener.
747 * @param event_loop Event loop assigned to run this command. If NULL, an event loop will be
748 * chosen by round-robin.
749 *
750 * @return AEROSPIKE_OK if async command succesfully queued. Otherwise an error.
751 * @ingroup batch_operations
752 */
755 aerospike* as, as_error* err, const as_policy_batch* policy, as_batch_records* records,
756 as_async_batch_listener listener, void* udata, as_event_loop* event_loop
757 );
758
759/**
760 * Look up multiple records by key, then return all bins.
761 *
762 * ~~~~~~~~~~{.c}
763 * as_batch batch;
764 * as_batch_inita(&batch, 3);
765 *
766 * as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
767 * as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
768 * as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
769 *
770 * as_status status = aerospike_batch_get(as, &err, NULL, &batch, listener, NULL);
771 * // process results
772 * as_batch_destroy(&batch);
773 * ~~~~~~~~~~
774 *
775 * @param as Aerospike cluster instance.
776 * @param err Error detail structure that is populated if an error occurs.
777 * @param policy Batch policy configuration parameters, pass in NULL for default.
778 * @param batch List of keys.
779 * @param listener User function to be called with command results.
780 * @param udata User data to be forwarded to listener.
781 *
782 * @return AEROSPIKE_OK if successful. Otherwise an error.
783 * @ingroup batch_operations
784 */
787 aerospike* as, as_error* err, const as_policy_batch* policy, const as_batch* batch,
788 as_batch_listener listener, void* udata
789 );
790
791/**
792 * Look up multiple records by key, then return specified bins.
793 *
794 * ~~~~~~~~~~{.c}
795 * as_batch batch;
796 * as_batch_inita(&batch, 3);
797 *
798 * as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
799 * as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
800 * as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
801 *
802 * const char* bin_filters[] = {"bin1", "bin2"};
803 *
804 * as_status status = aerospike_batch_get_bins(as, &err, NULL, &batch, bin_filters, 2, listener, NULL);
805 * // process results
806 * as_batch_destroy(&batch);
807 * ~~~~~~~~~~
808 *
809 * @param as Aerospike cluster instance.
810 * @param err Error detail structure that is populated if an error occurs.
811 * @param policy Batch policy configuration parameters, pass in NULL for default.
812 * @param batch The batch of keys to read.
813 * @param bins Bin filters. Only return these bins.
814 * @param n_bins The number of bin filters.
815 * @param listener User function to be called with command results.
816 * @param udata User data to be forwarded to listener.
817 *
818 * @return AEROSPIKE_OK if successful. Otherwise an error.
819 * @ingroup batch_operations
820 */
823 aerospike* as, as_error* err, const as_policy_batch* policy, const as_batch* batch,
824 const char** bins, uint32_t n_bins, as_batch_listener listener, void* udata
825 );
826
827/**
828 * Look up multiple records by key, then return results from specified read operations.
829 *
830 * ~~~~~~~~~~{.c}
831 * as_batch batch;
832 * as_batch_inita(&batch, 3);
833 *
834 * as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
835 * as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
836 * as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
837 *
838 * as_operations ops;
839 * as_operations_inita(&ops, 1);
840 * as_operations_list_size(&ops, "list", NULL);
841 *
842 * as_status status = aerospike_batch_get_ops(as, &err, NULL, &batch, &ops, listener, NULL);
843 * // process results
844 * as_batch_destroy(&batch);
845 * as_operations_destroy(&ops);
846 * ~~~~~~~~~~
847 *
848 * @param as Aerospike cluster instance.
849 * @param err Error detail structure that is populated if an error occurs.
850 * @param policy Batch policy configuration parameters, pass in NULL for default.
851 * @param batch The batch of keys to read.
852 * @param ops Read operations.
853 * @param listener User function to be called with command results.
854 * @param udata User data to be forwarded to listener.
855 *
856 * @return AEROSPIKE_OK if successful. Otherwise an error.
857 * @ingroup batch_operations
858 */
861 aerospike* as, as_error* err, const as_policy_batch* policy, const as_batch* batch,
862 as_operations* ops, as_batch_listener listener, void* udata
863 );
864
865/**
866 * Test whether multiple records exist in the cluster.
867 *
868 * ~~~~~~~~~~{.c}
869 * as_batch batch;
870 * as_batch_inita(&batch, 3);
871 *
872 * as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
873 * as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
874 * as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
875 *
876 * as_status status = aerospike_batch_exists(as, &err, NULL, &batch, listener, NULL);
877 * // process results
878 * as_batch_destroy(&batch);
879 * ~~~~~~~~~~
880 *
881 * @param as Aerospike cluster instance.
882 * @param err Error detail structure that is populated if an error occurs.
883 * @param policy Batch policy configuration parameters, pass in NULL for default.
884 * @param batch The batch of keys to read.
885 * @param listener The listener to invoke for each record read.
886 * @param udata The user-data for the listener.
887 *
888 * @return AEROSPIKE_OK if successful. Otherwise an error.
889 * @ingroup batch_operations
890 */
893 aerospike* as, as_error* err, const as_policy_batch* policy, const as_batch* batch,
894 as_batch_listener listener, void* udata
895 );
896
897/**
898 * Perform read/write operations on multiple keys.
899 * Requires server version 6.0+
900 *
901 * ~~~~~~~~~~{.c}
902 * as_integer val;
903 * as_integer_init(&val, 100);
904 *
905 * as_operations ops;
906 * as_operations_inita(&ops, 3);
907 * as_operations_list_append(&ops, bin, NULL, NULL, (as_val*)&val);
908 * as_operations_list_size(&ops, bin, NULL);
909 * as_operations_list_get_by_index(&ops, bin, NULL, -1, AS_LIST_RETURN_VALUE);
910 *
911 * as_batch batch;
912 * as_batch_inita(&batch, 3);
913 *
914 * as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
915 * as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
916 * as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
917 *
918 * as_status status = aerospike_batch_operate(as, &err, NULL, NULL, &batch, &ops, listener, NULL);
919 * // process results
920 * as_operations_destroy(&ops);
921 * as_batch_destroy(&batch);
922 * ~~~~~~~~~~
923 *
924 * @param as Aerospike cluster instance.
925 * @param err Error detail structure that is populated if an error occurs.
926 * @param policy Batch policy configuration parameters, pass in NULL for default.
927 * @param policy_write Write policy configuration parameters, pass in NULL for default.
928 * @param batch List of keys.
929 * @param ops Read/Write operations.
930 * @param listener User function to be called with command results.
931 * @param udata User data to be forwarded to listener.
932 *
933 * @return AEROSPIKE_OK if successful. Otherwise an error.
934 * @ingroup batch_operations
935 */
938 aerospike* as, as_error* err, const as_policy_batch* policy,
939 const as_policy_batch_write* policy_write, const as_batch* batch,
940 as_operations* ops, as_batch_listener listener, void* udata
941 );
942
943/**
944 * Apply UDF (user defined function) on multiple keys.
945 * Requires server version 6.0+
946 *
947 * ~~~~~~~~~~{.c}
948 * as_arraylist args;
949 * as_arraylist_init(&args, 2, 0);
950 * as_arraylist_append_str(&args, "s1");
951 * as_arraylist_append_str(&args, "s2");
952 *
953 * as_batch batch;
954 * as_batch_inita(&batch, 3);
955 *
956 * as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
957 * as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
958 * as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
959 *
960 * as_status status = aerospike_batch_apply(as, &err, NULL, NULL, &batch, "mod", "func",
961 * (as_list*)&args, NULL, NULL);
962 *
963 * // process results
964 * as_arraylist_destroy(&args);
965 * as_operations_destroy(&ops);
966 * as_batch_destroy(&batch);
967 * ~~~~~~~~~~
968 *
969 * @param as Aerospike cluster instance.
970 * @param err Error detail structure that is populated if an error occurs.
971 * @param policy Batch policy configuration parameters, pass in NULL for default.
972 * @param policy_apply UDF policy configuration parameters, pass in NULL for default.
973 * @param batch List of keys.
974 * @param module Server package name.
975 * @param function Server user defined function.
976 * @param arglist Server user defined function arguments.
977 * @param listener User function to be called with command results.
978 * @param udata User data to be forwarded to listener.
979 *
980 * @return AEROSPIKE_OK if successful. Otherwise an error.
981 * @ingroup batch_operations
982 */
985 aerospike* as, as_error* err, const as_policy_batch* policy,
986 const as_policy_batch_apply* policy_apply, const as_batch* batch,
987 const char* module, const char* function, as_list* arglist,
988 as_batch_listener listener, void* udata
989 );
990
991/**
992 * Remove multiple records.
993 * Requires server version 6.0+
994 *
995 * ~~~~~~~~~~{.c}
996 * as_batch batch;
997 * as_batch_inita(&batch, 3);
998 *
999 * as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
1000 * as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
1001 * as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
1002 *
1003 * as_status status = aerospike_batch_remove(as, &err, NULL, NULL, &batch, listener, NULL);
1004 * // process results
1005 * as_batch_destroy(&batch);
1006 * ~~~~~~~~~~
1007 *
1008 * @param as Aerospike cluster instance.
1009 * @param err Error detail structure that is populated if an error occurs.
1010 * @param policy Batch policy configuration parameters, pass in NULL for default.
1011 * @param policy_remove Remove policy configuration parameters, pass in NULL for default.
1012 * @param batch List of keys.
1013 * @param listener User function to be called with command results.
1014 * @param udata User data to be forwarded to listener.
1015 *
1016 * @return AEROSPIKE_OK if successful. Otherwise an error.
1017 * @ingroup batch_operations
1018 */
1021 aerospike* as, as_error* err, const as_policy_batch* policy,
1022 const as_policy_batch_remove* policy_remove, const as_batch* batch,
1023 as_batch_listener listener, void* udata
1024 );
1025
1026#ifdef __cplusplus
1027} // end extern "C"
1028#endif
#define AS_BATCH_REMOVE
#define AS_BATCH_WRITE
#define AS_BATCH_APPLY
#define AS_BATCH_READ
as_status
Definition as_status.h:30
#define AS_EXTERN
Definition as_std.h:25
AS_EXTERN void as_vector_init(as_vector *vector, uint32_t item_size, uint32_t capacity)
AS_EXTERN as_vector * as_vector_create(uint32_t item_size, uint32_t capacity)
static void * as_vector_reserve(as_vector *vector)
Definition as_vector.h:171
static as_batch_read_record * as_batch_read_reserve(as_batch_records *records)
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)
uint8_t as_batch_type
static as_batch_write_record * as_batch_write_reserve(as_batch_records *records)
AS_EXTERN as_status aerospike_batch_write(aerospike *as, as_error *err, const as_policy_batch *policy, as_batch_records *records)
static void as_batch_records_init(as_batch_records *records, uint32_t capacity)
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)
static as_batch_records * as_batch_read_create(uint32_t capacity)
static as_batch_records * as_batch_records_create(uint32_t capacity)
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_remove_record * as_batch_remove_reserve(as_batch_records *records)
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_read(aerospike *as, as_error *err, const as_policy_batch *policy, as_batch_records *records)
static void as_batch_read_destroy(as_batch_records *records)
bool(* as_batch_listener)(const as_batch_result *results, uint32_t n, void *udata)
AS_EXTERN void as_batch_records_destroy(as_batch_records *records)
as_batch_listener aerospike_batch_read_callback
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)
static void as_batch_read_init(as_batch_records *records, uint32_t capacity)
void(* as_async_batch_listener)(as_error *err, as_batch_records *records, void *udata, as_event_loop *event_loop)
static as_batch_apply_record * as_batch_apply_reserve(as_batch_records *records)
as_batch_records as_batch_read_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_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_get(aerospike *as, as_error *err, const as_policy_batch *policy, const as_batch *batch, as_batch_listener listener, void *udata)
const char *const char * function
const as_policy_batch_apply * policy
const as_policy_batch_read * policy
const as_policy_batch_remove * policy
const as_policy_batch_write * policy
as_operations * ops2
as_operations * ops1
as_batch_write_record write
as_batch_read_record read
as_batch_apply_record apply
as_batch_remove_record remove
as_batch_base_record base