All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
aerospike_batch.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2014 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  * Aerospike provides a batch API to access data in the cluster.
24  *
25  * The Batch API is a collection of APIs that use as_keyset as for looking up
26  * records for accessing in the cluster.
27  *
28  */
29 
30 #include <aerospike/aerospike.h>
31 #include <aerospike/as_batch.h>
32 #include <aerospike/as_error.h>
33 #include <aerospike/as_key.h>
34 #include <aerospike/as_list.h>
36 #include <aerospike/as_policy.h>
37 #include <aerospike/as_record.h>
38 #include <aerospike/as_status.h>
39 #include <aerospike/as_val.h>
40 
41 /******************************************************************************
42  * TYPES
43  *****************************************************************************/
44 
45 /**
46  * This callback will be called with the results of aerospike_batch_get(),
47  * or aerospike_batch_exists() functions.
48  *
49  * The `results` argument will be an array of `n` as_batch_read entries. The
50  * `results` argument is on the stack and is only available within the context
51  * of the callback. To use the data outside of the callback, copy the data.
52  *
53  * ~~~~~~~~~~{.c}
54  * bool my_callback(const as_batch_read * results, uint32_t n, void * udata) {
55  * return true;
56  * }
57  * ~~~~~~~~~~
58  *
59  * @param results The results from the batch request.
60  * @param n The number of results from the batch request.
61  * @param udata User-data provided to the calling function.
62  *
63  * @return `true` on success. Otherwise, an error occurred.
64  *
65  * @ingroup batch_operations
66  */
67 typedef bool (* aerospike_batch_read_callback)(const as_batch_read * results, uint32_t n, void * udata);
68 
69 /******************************************************************************
70  * FUNCTIONS
71  *****************************************************************************/
72 
73 /**
74  * Look up multiple records by key, then return all bins.
75  *
76  * ~~~~~~~~~~{.c}
77  * as_batch batch;
78  * as_batch_inita(&batch, 3);
79  *
80  * as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
81  * as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
82  * as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
83  *
84  * if ( aerospike_batch_get(&as, &err, NULL, &batch, callback, NULL) != AEROSPIKE_OK ) {
85  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
86  * }
87  *
88  * as_batch_destroy(&batch);
89  * ~~~~~~~~~~
90  *
91  * @param as The aerospike instance to use for this operation.
92  * @param err The as_error to be populated if an error occurs.
93  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
94  * @param batch The batch of keys to read.
95  * @param callback The callback to invoke for each record read.
96  * @param udata The user-data for the callback.
97  *
98  * @return AEROSPIKE_OK if successful. Otherwise an error.
99  *
100  * @ingroup batch_operations
101  */
103  aerospike * as, as_error * err, const as_policy_batch * policy,
104  const as_batch * batch,
105  aerospike_batch_read_callback callback, void * udata
106  );
107 
108 /**
109  * Test whether multiple records exist in the cluster.
110  *
111  * ~~~~~~~~~~{.c}
112  * as_batch batch;
113  * as_batch_inita(&batch, 3);
114  *
115  * as_key_init(as_batch_keyat(&batch,0), "ns", "set", "key1");
116  * as_key_init(as_batch_keyat(&batch,1), "ns", "set", "key2");
117  * as_key_init(as_batch_keyat(&batch,2), "ns", "set", "key3");
118  *
119  * if ( aerospike_batch_exists(&as, &err, NULL, &batch, callback, NULL) != AEROSPIKE_OK ) {
120  * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
121  * }
122  *
123  * as_batch_destroy(&batch);
124  * ~~~~~~~~~~
125  *
126  * @param as The aerospike instance to use for this operation.
127  * @param err The as_error to be populated if an error occurs.
128  * @param policy The policy to use for this operation. If NULL, then the default policy will be used.
129  * @param batch The batch of keys to read.
130  * @param callback The callback to invoke for each record read.
131  * @param udata The user-data for the callback.
132  *
133  * @return AEROSPIKE_OK if successful. Otherwise an error.
134  *
135  * @ingroup batch_operations
136  */
138  aerospike * as, as_error * err, const as_policy_batch * policy,
139  const as_batch * batch,
140  aerospike_batch_read_callback callback, void * udata
141  );
as_status
Definition: as_status.h:26
as_status aerospike_batch_get(aerospike *as, as_error *err, const as_policy_batch *policy, const as_batch *batch, aerospike_batch_read_callback callback, void *udata)
as_status aerospike_batch_exists(aerospike *as, as_error *err, const as_policy_batch *policy, const as_batch *batch, aerospike_batch_read_callback callback, void *udata)
bool(* aerospike_batch_read_callback)(const as_batch_read *results, uint32_t n, void *udata)