All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
aerospike_txn.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#include <aerospike/aerospike.h>
20#include <aerospike/as_txn.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26//---------------------------------
27// Types
28//---------------------------------
29
30struct as_event_loop;
31
32/**
33 * Transaction commit status code.
34 */
35typedef enum {
36 /**
37 * Commit succeeded.
38 */
40
41 /**
42 * Transaction has already been committed.
43 */
45
46 /**
47 * Transaction has already been aborted.
48 */
50
51 /**
52 * Transaction verify failed. Transaction will be aborted.
53 */
55
56 /**
57 * Transaction mark roll forward abandoned. Transaction will be aborted when error is not in doubt.
58 * If the error is in doubt (usually timeout), the commit is in doubt.
59 */
61
62 /**
63 * Client roll forward abandoned. Server will eventually commit the transaction.
64 */
66
67 /**
68 * Transaction has been rolled forward, but client transaction close was abandoned.
69 * Server will eventually close the transaction.
70 */
73
74/**
75 * Asynchronous commit listener. This function is called once when aerospike_commit_async() completes or an
76 * error has occurred.
77 *
78 * @param err Error structure that is populated if an error occurs. NULL on success.
79 * @param status Status of commit when err is NULL.
80 * @param udata User data that is forwarded from asynchronous command function.
81 * @param event_loop Event loop that this command was executed on. Use this event loop when
82 * running nested asynchronous commands when single threaded behavior is
83 * desired for the group of commands.
84 * @relates aerospike
85 */
86typedef void (*as_commit_listener)(
87 as_error* err, as_commit_status status, void* udata, struct as_event_loop* event_loop
88 );
89
90/**
91 * Transaction abort status code.
92 */
93typedef enum {
94 /**
95 * Abort succeeded.
96 */
98
99 /**
100 * Transaction has already been aborted.
101 */
103
104 /**
105 * Transaction has already been committed.
106 */
108
109 /**
110 * Client roll back abandoned. Server will eventually abort the transaction.
111 */
113
114 /**
115 * Transaction has been rolled back, but client transaction close was abandoned.
116 * Server will eventually close the transaction.
117 */
120
121/**
122 * Asynchronous commit listener. This function is called once when aerospike_abort_async() completes or an
123 * error has occurred.
124 *
125 * @param err Error structure that is populated if an error occurs. NULL on success.
126 * @param status Status of abort when err is NULL.
127 * @param udata User data that is forwarded from asynchronous command function.
128 * @param event_loop Event loop that this command was executed on. Use this event loop when
129 * running nested asynchronous commands when single threaded behavior is
130 * desired for the group of commands.
131 * @relates aerospike
132 */
133typedef void (*as_abort_listener)(
134 as_error* err, as_abort_status status, void* udata, struct as_event_loop* event_loop
135 );
136
137//---------------------------------
138// Functions
139//---------------------------------
140
141/**
142 * Attempt to commit the given transaction. First, the expected record versions are
143 * sent to the server nodes for verification. If all nodes return success, the transaction is
144 * committed. Otherwise, the transaction is aborted.
145 *
146 * Requires server version 8.0+
147 *
148 * @param as Aerospike instance.
149 * @param err Error detail structure that is populated if an error occurs.
150 * @param txn Transaction.
151 * @param commit_status Indicates success or the step in the commit process that failed.
152 * Pass in NULL to ignore.
153 *
154 * @return AEROSPIKE_OK if successful. Otherwise an error.
155 * @relates aerospike
156 */
159
160/**
161 * Abort and rollback the given transaction.
162 *
163 * Requires server version 8.0+
164 *
165 * @param as Aerospike instance.
166 * @param err Error detail structure that is populated if an error occurs.
167 * @param txn Transaction.
168 * @param abort_status Indicates success or the step in the abort process that failed.
169 * Pass in NULL to ignore.
170 *
171 * @return AEROSPIKE_OK if successful. Otherwise an error.
172 * @relates aerospike
173 */
176
177/**
178 * Asynchronously attempt to commit the given transaction. First, the expected record
179 * versions are sent to the server nodes for verification. If all nodes return success, the transaction
180 * is committed. Otherwise, the transaction is aborted.
181 *
182 * Requires server version 8.0+
183 *
184 * @param as Aerospike instance.
185 * @param err Error detail structure that is populated if an error occurs.
186 * @param txn Transaction.
187 * @param listener User function to be called with command results.
188 * @param udata User data that is forwarded from asynchronous command function.
189 * @param event_loop Event loop that this command was executed on. Use this event loop when
190 * running nested asynchronous commands when single threaded behavior is
191 * desired for the group of commands.
192 *
193 * @return AEROSPIKE_OK if async command succesfully queued. Otherwise an error.
194 * @relates aerospike
195 */
198 aerospike* as, as_error* err, as_txn* txn, as_commit_listener listener, void* udata,
199 struct as_event_loop* event_loop
200 );
201
202/**
203 * Asynchronously abort and rollback the given transaction.
204 *
205 * Requires server version 8.0+
206 *
207 * @param as Aerospike instance.
208 * @param err Error detail structure that is populated if an error occurs.
209 * @param txn Transaction.
210 * @param listener User function to be called with command results.
211 * @param udata User data that is forwarded from asynchronous command function.
212 * @param event_loop Event loop that this command was executed on. Use this event loop when
213 * running nested asynchronous commands when single threaded behavior is
214 * desired for the group of commands.
215 *
216 * @return AEROSPIKE_OK if async command succesfully queued. Otherwise an error.
217 * @relates aerospike
218 */
221 aerospike* as, as_error* err, as_txn* txn, as_abort_listener listener, void* udata,
222 struct as_event_loop* event_loop
223 );
224
225#ifdef __cplusplus
226} // end extern "C"
227#endif
as_commit_status
@ AS_COMMIT_ALREADY_COMMITTED
@ AS_COMMIT_MARK_ROLL_FORWARD_ABANDONED
@ AS_COMMIT_VERIFY_FAILED
@ AS_COMMIT_CLOSE_ABANDONED
@ AS_COMMIT_ROLL_FORWARD_ABANDONED
@ AS_COMMIT_ALREADY_ABORTED
@ AS_COMMIT_OK
as_abort_status
@ AS_ABORT_ALREADY_COMMITTED
@ AS_ABORT_ROLL_BACK_ABANDONED
@ AS_ABORT_ALREADY_ABORTED
@ AS_ABORT_OK
@ AS_ABORT_CLOSE_ABANDONED
as_status
Definition as_status.h:30
#define AS_EXTERN
Definition as_std.h:25
AS_EXTERN as_status aerospike_commit(aerospike *as, as_error *err, as_txn *txn, as_commit_status *commit_status)
AS_EXTERN as_status aerospike_abort(aerospike *as, as_error *err, as_txn *txn, as_abort_status *abort_status)
AS_EXTERN as_status aerospike_commit_async(aerospike *as, as_error *err, as_txn *txn, as_commit_listener listener, void *udata, struct as_event_loop *event_loop)
AS_EXTERN as_status aerospike_abort_async(aerospike *as, as_error *err, as_txn *txn, as_abort_listener listener, void *udata, struct as_event_loop *event_loop)