Loading...
Searching...
No Matches
aerospike.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2024 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 * @mainpage Aerospike C Client
21 *
22 * @section intro_sec Introduction
23 *
24 * The Aerospike C client allows you to build C/C++ applications to store and retrieve data from the
25 * Aerospike cluster. The C client is a smart client that periodically pings nodes for cluster
26 * status and manages interactions with the cluster. The following functionality is supported.
27 *
28 * - Database commands
29 * - Key/Value
30 * - Map/List collections
31 * - Batch read
32 * - Scan
33 * - Secondary index query
34 * - User defined Lua functions
35 * - Expression filters
36 * - Both synchronous and asynchronous command models
37 * - Asynchronous model supports the following event frameworks.
38 * - libev
39 * - libevent
40 * - libuv
41 * - Thread safe API
42 * - Shared memory cluster tend state for multi-process applications
43 * - TLS secure sockets
44 *
45 * See <a href="files.html">Files</a> for aerospike header files.<br/>
46 * See <a href="classes.html">Types</a> for aerospike types.<br/>
47 * See <a href="https://aerospike.com/developer/client/install?client=c">Developer Guide</a> for installation
48 * instructions and example code.<br/>
49 */
50
51/**
52 * @defgroup client_objects Client Objects
53 */
54
55/**
56 * @defgroup client_operations Client Operations
57 *
58 * Client operations require an initialized aerospike client.
59 */
60
61/**
62 * @defgroup aerospike_t Client Types
63 */
64
65#include <aerospike/as_error.h>
66#include <aerospike/as_config.h>
67#include <aerospike/as_log.h>
68#include <aerospike/as_status.h>
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74//---------------------------------
75// Types
76//---------------------------------
77
78/**
79 * @private
80 * Forward declaration of a cluster object.
81 */
82struct as_cluster_s;
83
84/**
85 * The aerospike struct is used to connect and execute operations against an
86 * Aerospike database cluster.
87 *
88 * ## Configuration
89 *
90 * A client configuration is required to initialize an aerospike client.
91 * See as_config for details on configuration options.
92 *
93 * At least one seed host must be defined.
94 *
95 * ~~~~~~~~~~{.c}
96 * as_config config;
97 * as_config_init(&config);
98 * as_config_add_host(&config, "127.0.0.1", 3000);
99 * ~~~~~~~~~~
100 *
101 * Once connected to a host in the cluster, then client will gather information
102 * about the cluster, including all other nodes in the cluster. So, all that
103 * is needed is a single valid host. Multiple hosts can still be provided in
104 * case the first host is not currently active.
105 *
106 * ## Initialization
107 *
108 * Initialization requires a configuration to bind to the client instance.
109 *
110 * The aerospike instance can be initialized via either:
111 *
112 * - aerospike_init() — Initialize a stack allocated aerospike instance.
113 * - aerospike_new() — Create and initialize a heap allocated aerospike instance.
114 *
115 * Once initialized, the ownership of the as_config instance fields are transferred
116 * to the aerospike instance. The user should never call as_config_destroy() directly.
117 *
118 * The following uses a stack allocated aerospike instance and initializes it
119 * with aerospike_init():
120 *
121 * ~~~~~~~~~~{.c}
122 * aerospike as;
123 * aerospike_init(&as, &config);
124 * ~~~~~~~~~~
125 *
126 * ## Connecting
127 *
128 * The client will be connected if `aerospike_connect()` completes successfully:
129 *
130 * ~~~~~~~~~~{.c}
131 * if (aerospike_connect(&as, &err) != AEROSPIKE_OK) {
132 * fprintf(stderr, "error(%d) %s at [%s:%d]", err.code, err.message, err.file, err.line);
133 * }
134 * ~~~~~~~~~~
135 *
136 * The `err` parameter will be populated if an error occurs. See as_error for more information
137 * on error handling.
138 *
139 * An aerospike object internally keeps cluster state and maintains connection pools to the cluster.
140 * The same aerospike object should be reused by the application for database operations
141 * to a given cluster.
142 *
143 * If the application requires connecting to multiple Aerospike clusters, the application must
144 * create multiple aerospike objects, each connecting to a different cluster.
145 *
146 * ## Disconnecting
147 *
148 * When the connection to the database is not longer required, then the
149 * connection to the cluster can be closed via `aerospike_close()`:
150 *
151 * ~~~~~~~~~~{.c}
152 * aerospike_close(&as, &err);
153 * ~~~~~~~~~~
154 *
155 * ## Destruction
156 *
157 * When the client is not longer required, the client and its resources should
158 * be releases via `aerospike_destroy()`:
159 *
160 * ~~~~~~~~~~{.c}
161 * aerospike_destroy(&as);
162 * ~~~~~~~~~~
163 *
164 * @ingroup client_objects
165 */
166typedef struct aerospike_s {
167
168 /**
169 * @private
170 * Cluster state.
171 */
172 struct as_cluster_s* cluster;
173
174 /**
175 * Client configuration.
176 */
178
179 /**
180 * @private
181 * If true, then aerospike_destroy() will free this instance.
182 */
183 bool _free;
184
185} aerospike;
186
187//---------------------------------
188// Functions
189//---------------------------------
190
191/**
192 * Initialize a stack allocated aerospike instance.
193 *
194 * The config parameter can be an instance of `as_config` or `NULL`. If `NULL`,
195 * then the default configuration will be used.
196 *
197 * Ownership of the as_config instance fields are transferred to the aerospike instance.
198 * The user should never call as_config_destroy() directly.
199 *
200 * ~~~~~~~~~~{.c}
201 * aerospike as;
202 * aerospike_init(&as, &config);
203 * ~~~~~~~~~~
204 *
205 * Once you are finished using the instance, then you should destroy it via the
206 * `aerospike_destroy()` function.
207 *
208 * @param as The aerospike instance to initialize.
209 * @param config The configuration to use for the instance.
210 *
211 * @returns the initialized aerospike instance
212 *
213 * @see config for information on configuring the client.
214 *
215 * @relates aerospike
216 */
219
220/**
221 * Creates a new heap allocated aerospike instance.
222 *
223 * Ownership of the as_config instance fields are transferred to the aerospike instance.
224 * The user should never call as_config_destroy() directly.
225 *
226 * ~~~~~~~~~~{.c}
227 * aerospike* as = aerospike_new(&config);
228 * ~~~~~~~~~~
229 *
230 * Once you are finished using the instance, then you should destroy it via the
231 * `aerospike_destroy()` function.
232 *
233 * @param config The configuration to use for the instance.
234 *
235 * @returns a new aerospike instance
236 *
237 * @see config for information on configuring the client.
238 *
239 * @relates aerospike
240 */
243
244/**
245 * Initialize global lua configuration.
246 *
247 * @param config The lua configuration to use for all cluster instances.
248 *
249 * @relates aerospike
250 */
251AS_EXTERN void
253
254/**
255 * Destroy the aerospike instance and associated resources.
256 *
257 * ~~~~~~~~~~{.c}
258 * aerospike_destroy(&as);
259 * ~~~~~~~~~~
260 *
261 * @param as The aerospike instance to destroy
262 *
263 * @relates aerospike
264 */
265AS_EXTERN void
267
268/**
269 * Connect an aerospike instance to the cluster.
270 *
271 * ~~~~~~~~~~{.c}
272 * aerospike_connect(&as, &err);
273 * ~~~~~~~~~~
274 *
275 * Once you are finished using the connection, then you must close it via
276 * the `aerospike_close()` function.
277 *
278 * If connect fails, then you do not need to call `aerospike_close()`.
279 *
280 * @param as The aerospike instance to connect to a cluster.
281 * @param err If an error occurs, the err will be populated.
282 *
283 * @returns AEROSPIKE_OK on success. Otherwise an error occurred.
284 *
285 * @relates aerospike
286 */
289
290/**
291 * Close connections to the cluster.
292 *
293 * ~~~~~~~~~~{.c}
294 * aerospike_close(&as, &err);
295 * ~~~~~~~~~~
296 *
297 * @param as The aerospike instance to disconnect from a cluster.
298 * @param err If an error occurs, the err will be populated.
299 *
300 * @returns AEROSPIKE_OK on success. Otherwise an error occurred.
301 *
302 * @relates aerospike
303 */
306
307/**
308 * Is cluster connected to any server nodes.
309 *
310 * ~~~~~~~~~~{.c}
311 * bool connected = aerospike_cluster_is_connected(&as);
312 * ~~~~~~~~~~
313 *
314 * @param as The aerospike instance to check.
315 *
316 * @returns true when cluster is connected.
317 *
318 * @relates aerospike
319 */
320AS_EXTERN bool
322
323/**
324 * Should stop socket operation if interrupted by a signal. Default is false which means
325 * the socket operation will be retried until timeout.
326 *
327 * @relates aerospike
328 */
329AS_EXTERN void
331
332/**
333 * Remove records in specified namespace/set efficiently. This method is many orders of magnitude
334 * faster than deleting records one at a time.
335 *
336 * See <a href="https://www.aerospike.com/docs/reference/info#truncate">https://www.aerospike.com/docs/reference/info#truncate</a>
337 *
338 * This asynchronous server call may return before the truncation is complete. The user can still
339 * write new records after the server returns because new records will have last update times
340 * greater than the truncate cutoff (set at the time of truncate call).
341 *
342 * @param as Aerospike instance.
343 * @param err If an error occurs, the err will be populated.
344 * @param policy Info policy. If NULL, then the default policy will be used.
345 * @param ns Required namespace.
346 * @param set Optional set name. Pass in NULL to delete all sets in namespace.
347 * @param before_nanos Optionally delete records before record last update time.
348 * Units are in nanoseconds since unix epoch (1970-01-01).
349 * If specified, value must be before the current time.
350 * Pass in 0 to delete all records in namespace/set regardless of last update time.
351 * @returns AEROSPIKE_OK on success. Otherwise an error occurred.
352 *
353 * @relates aerospike
354 */
357 aerospike* as, as_error* err, as_policy_info* policy, const char* ns, const char* set,
358 uint64_t before_nanos
359 );
360
361/**
362 * Refresh the current TLS configuration by reloading its certificate, key, and blacklist files.
363 *
364 * @param as Aerospike instance whose TLS configuration to refresh.
365 * @param err If an error occurs, this will be populated.
366 *
367 * @returns AEROSPIKE_OK on success. Otherwise an error occurred.
368 *
369 * @relates aerospike
370 */
373
374/**
375 * Set XDR filter for given datacenter name and namespace. The expression filter indicates
376 * which records XDR should ship to the datacenter.
377 *
378 * @param as Aerospike instance.
379 * @param err If an error occurs, this will be populated.
380 * @param policy Info policy. If NULL, then the default policy will be used.
381 * @param dc Datacenter name.
382 * @param ns Namespace.
383 * @param filter_b64 expression filter in base64 encoding. Use as_exp_build_b64() to create.
384 *
385 * @returns AEROSPIKE_OK on success. Otherwise an error occurred.
386 *
387 * @relates aerospike
388 */
391 aerospike* as, as_error* err, as_policy_info* policy, const char* dc, const char* ns,
392 const char* filter_b64
393 );
394
395#ifdef __cplusplus
396} // end extern "C"
397#endif
as_status
Definition as_status.h:30
#define AS_EXTERN
Definition as_std.h:25
AS_EXTERN as_status aerospike_set_xdr_filter(aerospike *as, as_error *err, as_policy_info *policy, const char *dc, const char *ns, const char *filter_b64)
AS_EXTERN bool aerospike_cluster_is_connected(aerospike *as)
AS_EXTERN void aerospike_init_lua(as_config_lua *config)
AS_EXTERN void aerospike_destroy(aerospike *as)
AS_EXTERN aerospike * aerospike_new(as_config *config)
AS_EXTERN aerospike * aerospike_init(aerospike *as, as_config *config)
AS_EXTERN as_status aerospike_connect(aerospike *as, as_error *err)
as_config config
Definition aerospike.h:177
AS_EXTERN void aerospike_stop_on_interrupt(bool stop)
AS_EXTERN as_status aerospike_close(aerospike *as, as_error *err)
AS_EXTERN as_status aerospike_truncate(aerospike *as, as_error *err, as_policy_info *policy, const char *ns, const char *set, uint64_t before_nanos)
AS_EXTERN as_status aerospike_reload_tls_config(aerospike *as, as_error *err)
struct as_cluster_s * cluster
Definition aerospike.h:172