Loading...
Searching...
No Matches
aerospike_batch.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2022 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
53/**
54 * Batch record type. Values: AS_BATCH_READ, AS_BATCH_WRITE, AS_BATCH_APPLY or AS_BATCH_REMOVE
55 *
56 * @ingroup batch_operations
57 */
58typedef uint8_t as_batch_type;
59
60/**
61 * Batch base request/response record. Used in batch commands where different command types are
62 * needed for different keys. All batch record types contain these base fields.
63 *
64 * @ingroup batch_operations
65 */
66typedef struct as_batch_base_record_s {
67 /**
68 * Requested key.
69 */
71
72 /**
73 * Record result for the requested key. This record will only be populated when the result is
74 * AEROSPIKE_OK or AEROSPIKE_ERR_UDF. If AEROSPIKE_ERR_UDF, use as_record_get_udf_error()
75 * to obtain the error message.
76 */
78
79 /**
80 * Result code.
81 */
83
84 /**
85 * Type of batch record.
86 */
88
89 /**
90 * Does batch sub-transaction contain a write operation.
91 */
93
94 /**
95 * Is it possible that the write transaction completed even though this error was generated.
96 * This may be the case when a client error occurs (like timeout) after the command was sent
97 * to the server.
98 */
101
102/**
103 * Batch key and read only operations with read policy.
104 *
105 * @relates as_batch_base_record
106 * @ingroup batch_operations
107 */
108typedef struct as_batch_read_record_s {
114 bool in_doubt; // Will always be false for reads.
115
116 /**
117 * Optional read policy.
118 */
120
121 /**
122 * Read operations for this key. ops are mutually exclusive with bin_names.
123 * If defined, the user must call as_operations_destroy() when done with the batch.
124 */
126
127 /**
128 * Bin names requested for this key. bin_names are mutually exclusive with ops.
129 * If heap defined, the user must free when done with the batch.
130 */
131 char** bin_names;
132
133 /**
134 * Count of bin names requested for this key.
135 */
136 uint32_t n_bin_names;
137
138 /**
139 * If true, ignore bin_names and read all bins.
140 * If false and bin_names are set, read specified bin_names.
141 * If false and bin_names are not set, read record header (generation, expiration) only.
142 */
145
146/**
147 * Batch key and read/write operations with write policy.
148 *
149 * @relates as_batch_base_record
150 * @ingroup batch_operations
151 */
152typedef struct as_batch_write_record_s {
154 as_record record; // Contains results of operations from ops field.
159
160 /**
161 * Optional write policy.
162 */
164
165 /**
166 * Required read/write operations for this key. The user must call as_operations_destroy()
167 * when done with the batch.
168 */
171
172/**
173 * Batch UDF (user defined function) apply.
174 *
175 * @relates as_batch_base_record
176 * @ingroup batch_operations
177 */
178typedef struct as_batch_apply_record_s {
185
186 /**
187 * Optional apply policy.
188 */
190
191 /**
192 * Package or lua module name.
193 * If heap defined, the user must free when done with the batch.
194 */
195 const char* module;
196
197 /**
198 * Lua function name.
199 * If heap defined, the user must free when done with the batch.
200 */
201 const char* function;
202
203 /**
204 * Optional arguments to lua function.
205 * If defined, the user must call as_arraylist_destroy() when done with the batch.
206 */
209
210/**
211 * Batch delete operation.
212 *
213 * @relates as_batch_base_record
214 * @ingroup batch_operations
215 */
216typedef struct as_batch_remove_record_s {
223
224 /**
225 * Optional remove policy.
226 */
229
230/**
231 * Batch request/response record union.
232 *
233 * @relates as_batch_base_record
234 * @ingroup batch_operations
235 */
243
244/**
245 * List of batch request/response (as_batch_base_record) records. The record types can be
246 * as_batch_read_record, as_batch_write_record, as_batch_apply_record or as_batch_remove_record.
247 *
248 * @ingroup batch_operations
249 */
250typedef struct as_batch_records_s {
253
254/**
255 * List of batch request/response (as_batch_base_record) records. The record types can be
256 * as_batch_read_record, as_batch_write_record, as_batch_apply_record or as_batch_remove_record.
257 *
258 * @deprecated Use as_batch_records instead.
259 * @ingroup batch_operations
260 */
262
263/**
264 * This listener will be called with the results of batch commands for all keys.
265 *
266 * The `results` argument will be an array of `n` as_batch_result entries. The
267 * `results` argument is on the stack and is only available within the context
268 * of the listener. To use the data outside of the listener, copy the data.
269 *
270 * ~~~~~~~~~~{.c}
271 * bool my_listener(const as_batch_result* results, uint32_t n, void* udata) {
272 * return true;
273 * }
274 * ~~~~~~~~~~
275 *
276 * @param results The results from the batch request.
277 * @param n The number of results from the batch request.
278 * @param udata User-data provided to the calling function.
279 * @return `true` on success. Otherwise, an error occurred.
280 * @ingroup batch_operations
281 */
282typedef bool (*as_batch_listener)(const as_batch_result* results, uint32_t n, void* udata);
283
284/**
285 * This listener will be called with the results of batch commands for all keys.
286 *
287 * @deprecated Use as_batch_listener instead.
288 * @ingroup batch_operations
289 */
291
292/**
293 * Asynchronous batch user listener. This function is called once when the batch completes or an
294 * error has occurred.
295 *
296 * @param err Error structure that is populated if an error occurs. NULL on success.
297 * @param records Record results. Records must be destroyed with as_batch_records_destroy()
298 * when done.
299 * @param udata User data that is forwarded from asynchronous command function.
300 * @param event_loop Event loop that this command was executed on. Use this event loop when
301 * running nested asynchronous commands when single threaded behavior is
302 * desired for the group of commands.
303 * @ingroup batch_operations
304 */
305typedef void (*as_async_batch_listener)(as_error* err, as_batch_records* records, void* udata,
306 as_event_loop* event_loop);
307
308//---------------------------------
309// Functions
310//---------------------------------
311
312/**
313 * Initialize batch records with specified capacity on the stack using alloca().
314 *
315 * When the batch is no longer needed, then use as_batch_records_destroy() to
316 * release the batch and associated resources.
317 *
318 * @param __records Batch record list.
319 * @param __capacity Initial capacity of batch record list. List will resize when necessary.
320 *
321 * @relates as_batch_records
322 * @ingroup batch_operations
323 */
324#define as_batch_records_inita(__records, __capacity) \
325 as_vector_inita(&((__records)->list), sizeof(as_batch_record), __capacity);
326
327/**
328 * Initialize batch records with specified capacity on the stack using alloca().
329 *
330 * @deprecated Use as_batch_records_inita() instead.
331 * @relates as_batch_records
332 * @ingroup batch_operations
333 */
334#define as_batch_read_inita(__records, __capacity) \
335 as_vector_inita(&((__records)->list), sizeof(as_batch_record), __capacity);
336
337/**
338 * Initialize batch records with specified capacity on the heap.
339 *
340 * When the batch is no longer needed, then use as_batch_records_destroy() to
341 * release the batch and associated resources.
342 *
343 * @param records Batch record list.
344 * @param capacity Initial capacity of batch record list. List will resize when necessary.
345 *
346 * @relates as_batch_records
347 * @ingroup batch_operations
348 */
349static inline void
350as_batch_records_init(as_batch_records* records, uint32_t capacity)
351{
352 as_vector_init(&records->list, sizeof(as_batch_record), capacity);
353}
354
355/**
356 * Initialize batch records with specified capacity on the heap.
357 *
358 * @deprecated Use as_batch_records_init() instead.
359 * @relates as_batch_records
360 * @ingroup batch_operations
361 */
362static inline void
363as_batch_read_init(as_batch_records* records, uint32_t capacity)
364{
365 as_vector_init(&records->list, sizeof(as_batch_record), capacity);
366}
367
368/**
369 * Create batch records on heap with specified list capacity on the heap.
370 *
371 * When the batch is no longer needed, then use as_batch_records_destroy() to
372 * release the batch and associated resources.
373 *
374 * @param capacity Initial capacity of batch record list. List will resize when necessary.
375 * @return Batch record list.
376 *
377 * @relates as_batch_records
378 * @ingroup batch_operations
379 */
380static inline as_batch_records*
381as_batch_records_create(uint32_t capacity)
382{
383 return (as_batch_records*)as_vector_create(sizeof(as_batch_record), capacity);
384}
385
386/**
387 * Create batch records on heap with specified list capacity on the heap.
388 *
389 * @deprecated Use as_batch_records_create() instead.
390 * @relates as_batch_records
391 * @ingroup batch_operations
392 */
393static inline as_batch_records*
394as_batch_read_create(uint32_t capacity)
395{
396 return (as_batch_records*)as_vector_create(sizeof(as_batch_record), capacity);
397}
398
399/**
400 * Reserve a new `as_batch_read_record` slot. Capacity will be increased when necessary.
401 * Return reference to record. The record is initialized to zeroes.
402 *
403 * @relates as_batch_records
404 * @ingroup batch_operations
405 */
406static inline as_batch_read_record*
413
414/**
415 * Reserve a new `as_batch_write_record` slot. Capacity will be increased when necessary.
416 * Return reference to record. The record is initialized to zeroes.
417 *
418 * @relates as_batch_records
419 * @ingroup batch_operations
420 */
421static inline as_batch_write_record*
423{
425 r->type = AS_BATCH_WRITE;
426 r->has_write = true;
427 return r;
428}
429
430/**
431 * Reserve a new `as_batch_apply_record` slot for UDF. Capacity will be increased when necessary.
432 * Return reference to record. The record is initialized to zeroes.
433 *
434 * @relates as_batch_records
435 * @ingroup batch_operations
436 */
437static inline as_batch_apply_record*
439{
441 r->type = AS_BATCH_APPLY;
442 r->has_write = true;
443 return r;
444}
445
446/**
447 * Reserve a new `as_batch_remove_record` slot. Capacity will be increased when necessary.
448 * Return reference to record. The record is initialized to zeroes.
449 *
450 * @relates as_batch_records
451 * @ingroup batch_operations
452 */
453static inline as_batch_remove_record*
455{
458 r->has_write = true;
459 return r;
460}
461
462/**
463 * Destroy keys and records in record list. It's the responsility of the caller to
464 * free additional user specified fields in the record.
465 *
466 * @relates as_batch_records
467 * @ingroup batch_operations
468 */
469AS_EXTERN void
471
472/**
473 * Destroy keys and records in record list. It's the responsility of the caller to
474 * free additional user specified fields in the record.
475 *
476 * @deprecated Use as_batch_records_destroy() instead.
477 * @relates as_batch_records
478 * @ingroup batch_operations
479 */
480static inline void
482{
483 as_batch_records_destroy(records);
484}
485
486/**
487 * Read multiple records for specified batch keys in one batch call.
488 * This method allows different namespaces/bins to be requested for each key in the batch.
489 * The returned records are located in the same batch array.
490 *
491 * ~~~~~~~~~~{.c}
492 * as_batch_records records;
493 * as_batch_records_inita(&records, 10);
494 *
495 * char* bin_names[] = {"bin1", "bin2"};
496 * char* ns = "ns";
497 * char* set = "set";
498 *
499 * as_batch_read_record* record = as_batch_read_reserve(&records);
500 * as_key_init(&record->key, ns, set, "key1");
501 * record->bin_names = bin_names;
502 * record->n_bin_names = 2;
503 *
504 * record = as_batch_read_reserve(&records);
505 * as_key_init(&record->key, ns, set, "key2");
506 * record->read_all_bins = true;
507 *
508 * as_status status = aerospike_batch_read(as, &err, NULL, &records);
509 * // process results
510 * as_batch_records_destroy(&records);
511 * ~~~~~~~~~~
512 *
513 * @param as Aerospike cluster instance.
514 * @param err Error detail structure that is populated if an error occurs.
515 * @param policy Batch policy configuration parameters, pass in NULL for default.
516 * @param records List of keys and records to retrieve.
517 * The returned records are located in the same array.
518 *
519 * @return AEROSPIKE_OK if successful. Otherwise an error.
520 * @ingroup batch_operations
521 */
524 aerospike* as, as_error* err, const as_policy_batch* policy, as_batch_records* records
525 );
526
527/**
528 * Asynchronously read multiple records for specified batch keys in one batch call.
529 * This method allows different namespaces/bins to be requested for each key in the batch.
530 * The returned records are located in the same batch array.
531 *
532 * ~~~~~~~~~~{.c}
533 * void my_listener(as_error* err, as_batch_records* records, void* udata, as_event_loop* loop)
534 * {
535 * if (err) {
536 * fprintf(stderr, "Command failed: %d %s\n", err->code, err->message);
537 * }
538 * else {
539 * as_vector* list = &records->list;
540 * for (uint32_t i = 0; i < list->size; i++) {
541 * as_batch_read_record* record = as_vector_get(list, i);
542 * // Process record
543 * }
544 * }
545 * // Must free batch records on both success and error conditions because it was created
546 * // before calling aerospike_batch_read_async().
547 * as_batch_records_destroy(records);
548 * }
549 *
550 * as_batch_records* records = as_batch_records_create(10);
551 *
552 * // bin_names must point to a static/global array of literal/global strings.
553 * char* bin_names[] = {"bin1", "bin2"};
554 * char* ns = "ns";
555 * char* set = "set";
556 *
557 * as_batch_read_record* record = as_batch_read_reserve(records);
558 * as_key_init(&record->key, ns, set, "key1");
559 * record->bin_names = bin_names;
560 * record->n_bin_names = 2;
561 *
562 * record = as_batch_read_reserve(records);
563 * as_key_init(&record->key, ns, set, "key2");
564 * record->read_all_bins = true;
565 *
566 * as_status status = aerospike_batch_read_async(as, &err, NULL, records, NULL, my_listener, NULL);
567 *
568 * if (status != AEROSPIKE_OK) {
569 * // Must free batch records on queue error because the listener will not be called.
570 * as_batch_records_destroy(records);
571 * }
572 * ~~~~~~~~~~
573 *
574 * @param as Aerospike cluster instance.
575 * @param err Error detail structure that is populated if an error occurs.
576 * @param policy Batch policy configuration parameters, pass in NULL for default.
577 * @param records List of keys and records to retrieve. Returned records are located in the
578 * same list. Must create using as_batch_records_create() (allocates memory on
579 * heap) because the async method returns immediately after queueing command.
580 * @param listener User function to be called with command results.
581 * @param udata User data to be forwarded to listener.
582 * @param event_loop Event loop assigned to run this command. If NULL, an event loop will be
583 * chosen by round-robin.
584 *
585 * @return AEROSPIKE_OK if async command succesfully queued. Otherwise an error.
586 * @ingroup batch_operations
587 */
590 aerospike* as, as_error* err, const as_policy_batch* policy, as_batch_records* records,
591 as_async_batch_listener listener, void* udata, as_event_loop* event_loop
592 );
593
594/**
595 * Read/Write multiple records for specified batch keys in one batch call.
596 * This method allows different sub-commands for each key in the batch.
597 * The returned records are located in the same list.
598 *
599 * Requires server version 6.0+
600 *
601 * ~~~~~~~~~~{.c}
602 * as_operations ops1;
603 * as_operations_inita(&ops1, 1);
604 * as_operations_add_write_int64(&ops1, "bin1", 100);
605 *
606 * as_operations ops2;
607 * as_operations_inita(&ops2, 1);
608 * as_operations_add_write_int64(&ops2, "bin2", 200);
609 *
610 * as_batch_records recs;
611 * as_batch_records_inita(&recs, 2);
612 *
613 * as_batch_write_record* r = as_batch_write_reserve(&recs);
614 * as_key_init_int64(&r->key, "test", "set", 1);
615 * r->ops = &ops1;
616 *
617 * r = as_batch_write_reserve(&recs);
618 * as_key_init_int64(&r->key, "test", "set", 2);
619 * r->ops = &ops2;
620 *
621 * as_status status = aerospike_batch_write(as, err, NULL, &recs);
622 *
623 * // Process results. Overall status contains first error, if any.
624 * as_operations_destroy(&ops1);
625 * as_operations_destroy(&ops2);
626 * as_batch_records_destroy(&recs);
627 * ~~~~~~~~~~
628 *
629 * @param as Aerospike cluster instance.
630 * @param err Error detail structure that is populated if an error occurs.
631 * @param policy Batch policy configuration parameters, pass in NULL for default.
632 * @param records List of batch sub-commands to perform. The returned records are located in the
633 * same list.
634 *
635 * @return AEROSPIKE_OK if successful. Otherwise an error.
636 * @ingroup batch_operations
637 */
640 aerospike* as, as_error* err, const as_policy_batch* policy, as_batch_records* records
641 );
642
643/**
644 * Asynchronously read/write multiple records for specified batch keys in one batch call.
645 * This method allows different sub-commands for each key in the batch.
646 * The returned records are located in the same list.
647 *
648 * Requires server version 6.0+
649 *
650 * ~~~~~~~~~~{.c}
651 * void my_listener(as_error* err, as_batch_records* records, void* udata, as_event_loop* loop)
652 * {
653 * if (err) {
654 * fprintf(stderr, "Command failed: %d %s\n", err->code, err->message);
655 * }
656 * else {
657 * as_vector* list = &records->list;
658 * for (uint32_t i = 0; i < list->size; i++) {
659 * as_batch_base_record* r = as_vector_get(list, i);
660 * // Process record
661 * }
662 * }
663 * // Must free batch records on both success and error conditions because it was created
664 * // before calling aerospike_batch_read_async().
665 * as_batch_records_destroy(records);
666 * }
667 *
668 * as_operations ops1;
669 * as_operations_inita(&ops1, 2);
670 * as_operations_add_write_int64(&ops1, bin1, 100);
671 * as_operations_add_read(&ops1, bin2);
672 *
673 * as_operations ops2;
674 * as_operations_inita(&ops2, 2);
675 * as_operations_add_write_int64(&ops1, bin3, 0);
676 * as_operations_add_read(&ops2, bin4);
677 *
678 * as_batch_records* recs = as_batch_records_create(2);
679 *
680 * as_batch_write_record* wr = as_batch_write_reserve(recs);
681 * as_key_init_int64(&wr->key, NAMESPACE, SET, 1);
682 * wr->ops = &ops1;
683 *
684 * wr = as_batch_write_reserve(recs);
685 * as_key_init_int64(&wr->key, NAMESPACE, SET, 6);
686 * wr->ops = &ops2;
687 *
688 * as_status status = aerospike_batch_write_async(as, &err, NULL, recs, my_listener, NULL, NULL);
689 *
690 * as_operations_destroy(&ops1);
691 * as_operations_destroy(&ops2);
692 *
693 * if (status != AEROSPIKE_OK) {
694 * // Must free batch records on queue error because the listener will not be called.
695 * as_batch_records_destroy(records);
696 * }
697 * ~~~~~~~~~~
698 *
699 * @param as Aerospike cluster instance.
700 * @param err Error detail structure that is populated if an error occurs.
701 * @param policy Batch policy configuration parameters, pass in NULL for default.
702 * @param records List of keys and records to retrieve. Returned records are located in the
703 * same list. Must create using as_batch_records_create() (allocates memory on
704 * heap) because the async method returns immediately after queueing command.
705 * @param listener User function to be called with command results.
706 * @param udata User data to be forwarded to listener.
707 * @param event_loop Event loop assigned to run this command. If NULL, an event loop will be
708 * chosen by round-robin.
709 *
710 * @return AEROSPIKE_OK if async command succesfully queued. Otherwise an error.
711 * @ingroup batch_operations
712 */
715 aerospike* as, as_error* err, const as_policy_batch* policy, as_batch_records* records,
716 as_async_batch_listener listener, void* udata, as_event_loop* event_loop
717 );
718
719/**
720 * Look up multiple records by key, then return all bins.
721 *
722 * ~~~~~~~~~~{.c}
723 * as_batch batch;
724 * as_batch_inita(&batch, 3);
725 *
726 * as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
727 * as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
728 * as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
729 *
730 * as_status status = aerospike_batch_get(as, &err, NULL, &batch, listener, NULL);
731 * // process results
732 * as_batch_destroy(&batch);
733 * ~~~~~~~~~~
734 *
735 * @param as Aerospike cluster instance.
736 * @param err Error detail structure that is populated if an error occurs.
737 * @param policy Batch policy configuration parameters, pass in NULL for default.
738 * @param batch List of keys.
739 * @param listener User function to be called with command results.
740 * @param udata User data to be forwarded to listener.
741 *
742 * @return AEROSPIKE_OK if successful. Otherwise an error.
743 * @ingroup batch_operations
744 */
747 aerospike* as, as_error* err, const as_policy_batch* policy, const as_batch* batch,
748 as_batch_listener listener, void* udata
749 );
750
751/**
752 * Look up multiple records by key, then return specified bins.
753 *
754 * ~~~~~~~~~~{.c}
755 * as_batch batch;
756 * as_batch_inita(&batch, 3);
757 *
758 * as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
759 * as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
760 * as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
761 *
762 * const char* bin_filters[] = {"bin1", "bin2"};
763 *
764 * as_status status = aerospike_batch_get_bins(as, &err, NULL, &batch, bin_filters, 2, listener, NULL);
765 * // process results
766 * as_batch_destroy(&batch);
767 * ~~~~~~~~~~
768 *
769 * @param as Aerospike cluster instance.
770 * @param err Error detail structure that is populated if an error occurs.
771 * @param policy Batch policy configuration parameters, pass in NULL for default.
772 * @param batch The batch of keys to read.
773 * @param bins Bin filters. Only return these bins.
774 * @param n_bins The number of bin filters.
775 * @param listener User function to be called with command results.
776 * @param udata User data to be forwarded to listener.
777 *
778 * @return AEROSPIKE_OK if successful. Otherwise an error.
779 * @ingroup batch_operations
780 */
783 aerospike* as, as_error* err, const as_policy_batch* policy, const as_batch* batch,
784 const char** bins, uint32_t n_bins, as_batch_listener listener, void* udata
785 );
786
787/**
788 * Look up multiple records by key, then return results from specified read operations.
789 *
790 * ~~~~~~~~~~{.c}
791 * as_batch batch;
792 * as_batch_inita(&batch, 3);
793 *
794 * as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
795 * as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
796 * as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
797 *
798 * as_operations ops;
799 * as_operations_inita(&ops, 1);
800 * as_operations_list_size(&ops, "list", NULL);
801 *
802 * as_status status = aerospike_batch_get_ops(as, &err, NULL, &batch, &ops, listener, NULL);
803 * // process results
804 * as_batch_destroy(&batch);
805 * as_operations_destroy(&ops);
806 * ~~~~~~~~~~
807 *
808 * @param as Aerospike cluster instance.
809 * @param err Error detail structure that is populated if an error occurs.
810 * @param policy Batch policy configuration parameters, pass in NULL for default.
811 * @param batch The batch of keys to read.
812 * @param ops Read operations.
813 * @param listener User function to be called with command results.
814 * @param udata User data to be forwarded to listener.
815 *
816 * @return AEROSPIKE_OK if successful. Otherwise an error.
817 * @ingroup batch_operations
818 */
821 aerospike* as, as_error* err, const as_policy_batch* policy, const as_batch* batch,
822 as_operations* ops, as_batch_listener listener, void* udata
823 );
824
825/**
826 * Test whether multiple records exist in the cluster.
827 *
828 * ~~~~~~~~~~{.c}
829 * as_batch batch;
830 * as_batch_inita(&batch, 3);
831 *
832 * as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
833 * as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
834 * as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
835 *
836 * as_status status = aerospike_batch_exists(as, &err, NULL, &batch, listener, NULL);
837 * // process results
838 * as_batch_destroy(&batch);
839 * ~~~~~~~~~~
840 *
841 * @param as Aerospike cluster instance.
842 * @param err Error detail structure that is populated if an error occurs.
843 * @param policy Batch policy configuration parameters, pass in NULL for default.
844 * @param batch The batch of keys to read.
845 * @param listener The listener to invoke for each record read.
846 * @param udata The user-data for the listener.
847 *
848 * @return AEROSPIKE_OK if successful. Otherwise an error.
849 * @ingroup batch_operations
850 */
853 aerospike* as, as_error* err, const as_policy_batch* policy, const as_batch* batch,
854 as_batch_listener listener, void* udata
855 );
856
857/**
858 * Perform read/write operations on multiple keys.
859 * Requires server version 6.0+
860 *
861 * ~~~~~~~~~~{.c}
862 * as_integer val;
863 * as_integer_init(&val, 100);
864 *
865 * as_operations ops;
866 * as_operations_inita(&ops, 3);
867 * as_operations_list_append(&ops, bin, NULL, NULL, (as_val*)&val);
868 * as_operations_list_size(&ops, bin, NULL);
869 * as_operations_list_get_by_index(&ops, bin, NULL, -1, AS_LIST_RETURN_VALUE);
870 *
871 * as_batch batch;
872 * as_batch_inita(&batch, 3);
873 *
874 * as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
875 * as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
876 * as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
877 *
878 * as_status status = aerospike_batch_operate(as, &err, NULL, NULL, &batch, &ops, listener, NULL);
879 * // process results
880 * as_operations_destroy(&ops);
881 * as_batch_destroy(&batch);
882 * ~~~~~~~~~~
883 *
884 * @param as Aerospike cluster instance.
885 * @param err Error detail structure that is populated if an error occurs.
886 * @param policy Batch policy configuration parameters, pass in NULL for default.
887 * @param policy_write Write policy configuration parameters, pass in NULL for default.
888 * @param batch List of keys.
889 * @param ops Read/Write operations.
890 * @param listener User function to be called with command results.
891 * @param udata User data to be forwarded to listener.
892 *
893 * @return AEROSPIKE_OK if successful. Otherwise an error.
894 * @ingroup batch_operations
895 */
898 aerospike* as, as_error* err, const as_policy_batch* policy,
899 const as_policy_batch_write* policy_write, const as_batch* batch,
900 as_operations* ops, as_batch_listener listener, void* udata
901 );
902
903/**
904 * Apply UDF (user defined function) on multiple keys.
905 * Requires server version 6.0+
906 *
907 * ~~~~~~~~~~{.c}
908 * as_arraylist args;
909 * as_arraylist_init(&args, 2, 0);
910 * as_arraylist_append_str(&args, "s1");
911 * as_arraylist_append_str(&args, "s2");
912 *
913 * as_batch batch;
914 * as_batch_inita(&batch, 3);
915 *
916 * as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
917 * as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
918 * as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
919 *
920 * as_status status = aerospike_batch_apply(as, &err, NULL, NULL, &batch, "mod", "func",
921 * (as_list*)&args, NULL, NULL);
922 *
923 * // process results
924 * as_arraylist_destroy(&args);
925 * as_operations_destroy(&ops);
926 * as_batch_destroy(&batch);
927 * ~~~~~~~~~~
928 *
929 * @param as Aerospike cluster instance.
930 * @param err Error detail structure that is populated if an error occurs.
931 * @param policy Batch policy configuration parameters, pass in NULL for default.
932 * @param policy_apply UDF policy configuration parameters, pass in NULL for default.
933 * @param batch List of keys.
934 * @param module Server package name.
935 * @param function Server user defined function.
936 * @param arglist Server user defined function arguments.
937 * @param listener User function to be called with command results.
938 * @param udata User data to be forwarded to listener.
939 *
940 * @return AEROSPIKE_OK if successful. Otherwise an error.
941 * @ingroup batch_operations
942 */
945 aerospike* as, as_error* err, const as_policy_batch* policy,
946 const as_policy_batch_apply* policy_apply, const as_batch* batch,
947 const char* module, const char* function, as_list* arglist,
948 as_batch_listener listener, void* udata
949 );
950
951/**
952 * Remove multiple records.
953 * Requires server version 6.0+
954 *
955 * ~~~~~~~~~~{.c}
956 * as_batch batch;
957 * as_batch_inita(&batch, 3);
958 *
959 * as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
960 * as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
961 * as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
962 *
963 * as_status status = aerospike_batch_remove(as, &err, NULL, NULL, &batch, listener, NULL);
964 * // process results
965 * as_batch_destroy(&batch);
966 * ~~~~~~~~~~
967 *
968 * @param as Aerospike cluster instance.
969 * @param err Error detail structure that is populated if an error occurs.
970 * @param policy Batch policy configuration parameters, pass in NULL for default.
971 * @param policy_remove Remove policy configuration parameters, pass in NULL for default.
972 * @param batch List of keys.
973 * @param listener User function to be called with command results.
974 * @param udata User data to be forwarded to listener.
975 *
976 * @return AEROSPIKE_OK if successful. Otherwise an error.
977 * @ingroup batch_operations
978 */
981 aerospike* as, as_error* err, const as_policy_batch* policy,
982 const as_policy_batch_remove* policy_remove, const as_batch* batch,
983 as_batch_listener listener, void* udata
984 );
985
986#ifdef __cplusplus
987} // end extern "C"
988#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_batch_write_record write
as_batch_read_record read
as_batch_apply_record apply
as_batch_remove_record remove
as_batch_base_record base