Skip to content

Commit 2acc7cb

Browse files
committed
References lp:1216738, lp:1217567 - adjusted API accordingly.
1 parent 354e485 commit 2acc7cb

File tree

4 files changed

+67
-56
lines changed

4 files changed

+67
-56
lines changed

wsrep_api.h

+47-36
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ typedef _Bool wsrep_bool_t; //!< should be the same as standard bool
8888
/*! undefined seqno */
8989
#define WSREP_SEQNO_UNDEFINED (-1)
9090

91-
/*! wsrep status codes */
92-
typedef enum wsrep_status {
91+
/*! wsrep provider status codes */
92+
typedef enum wsrep_status
93+
{
9394
WSREP_OK = 0, //!< success
94-
WSREP_APPLIER_EXIT, //!< success, applier marked to terminate
9595
WSREP_WARNING, //!< minor warning, error logged
9696
WSREP_TRX_MISSING, //!< transaction is not known by wsrep
9797
WSREP_TRX_FAIL, //!< transaction aborted, server can continue
@@ -103,6 +103,19 @@ typedef enum wsrep_status {
103103
WSREP_NOT_IMPLEMENTED //!< feature not implemented
104104
} wsrep_status_t;
105105

106+
/*! wsrep callbacks status codes */
107+
typedef enum wsrep_cb_status
108+
{
109+
WSREP_CB_RETURN = -1, //!< success, thread wants to return from wsrep::recv() call
110+
WSREP_CB_SUCCESS = 0, //!< success (as in "not critical failure")
111+
WSREP_CB_FAILURE //!< critical failure (consistency violation)
112+
/* Technically, wsrep provider has no use for specific failure codes since
113+
* there is nothing it can do about it but abort execution. Therefore any
114+
* positive number shall indicate a critical failure. Optionally that value
115+
* may be used by provider to come to a consensus about state consistency
116+
* in a group of nodes. */
117+
} wsrep_cb_status_t;
118+
106119
/*!
107120
* @brief log severity levels, passed as first argument to log handler
108121
*/
@@ -130,7 +143,7 @@ typedef void (*wsrep_log_cb_t)(wsrep_log_level_t, const char *);
130143
* UUID type - for all unique IDs
131144
*/
132145
typedef struct wsrep_uuid {
133-
uint8_t uuid[16];
146+
uint8_t data[16];
134147
} wsrep_uuid_t;
135148

136149
/*! Undefined UUID */
@@ -234,8 +247,7 @@ typedef enum wsrep_view_status {
234247
* view of the group
235248
*/
236249
typedef struct wsrep_view_info {
237-
wsrep_uuid_t uuid; //!< global state UUID
238-
wsrep_seqno_t seqno; //!< global state seqno
250+
wsrep_gtid_t state_id; //!< global state ID
239251
wsrep_seqno_t view; //!< global view number
240252
wsrep_view_status_t status; //!< view status
241253
wsrep_bool_t state_gap; //!< gap between global and local states
@@ -282,13 +294,15 @@ typedef struct wsrep_view_info {
282294
* @param sst_req_len location to store SST request length or error code
283295
* value of 0 means no SST.
284296
*/
285-
typedef void (*wsrep_view_cb_t) (void* app_ctx,
286-
void* recv_ctx,
287-
const wsrep_view_info_t* view,
288-
const char* state,
289-
size_t state_len,
290-
void** sst_req,
291-
int* sst_req_len);
297+
typedef enum wsrep_cb_status (*wsrep_view_cb_t) (
298+
void* app_ctx,
299+
void* recv_ctx,
300+
const wsrep_view_info_t* view,
301+
const char* state,
302+
size_t state_len,
303+
void** sst_req,
304+
int* sst_req_len
305+
);
292306

293307
/*!
294308
* @brief apply callback
@@ -306,11 +320,12 @@ typedef void (*wsrep_view_cb_t) (void* app_ctx,
306320
* @retval WSREP_NOT_IMPLEMENTED appl. does not support the writeset format
307321
* @retval WSREP_ERROR failed to apply the writeset
308322
*/
309-
typedef enum wsrep_status (*wsrep_apply_cb_t) (
323+
typedef enum wsrep_cb_status (*wsrep_apply_cb_t) (
310324
void* recv_ctx,
311325
const void* data,
312326
size_t size,
313-
const wsrep_trx_meta_t* meta);
327+
const wsrep_trx_meta_t* meta
328+
);
314329

315330
/*!
316331
* @brief commit callback
@@ -325,10 +340,11 @@ typedef enum wsrep_status (*wsrep_apply_cb_t) (
325340
* @retval WSREP_OK
326341
* @retval WSREP_ERROR call failed
327342
*/
328-
typedef enum wsrep_status (*wsrep_commit_cb_t) (
343+
typedef enum wsrep_cb_status (*wsrep_commit_cb_t) (
329344
void* recv_ctx,
330345
const wsrep_trx_meta_t* meta,
331-
wsrep_bool_t commit);
346+
wsrep_bool_t commit
347+
);
332348

333349
/*!
334350
* @brief unordered callback
@@ -344,9 +360,9 @@ typedef enum wsrep_status (*wsrep_commit_cb_t) (
344360
* @retval WSREP_OK
345361
* @retval WSREP_ERROR call failed
346362
*/
347-
typedef enum wsrep_status (*wsrep_unordered_cb_t) (void* recv_ctx,
348-
const void* data,
349-
size_t size);
363+
typedef enum wsrep_cb_status (*wsrep_unordered_cb_t) (void* recv_ctx,
364+
const void* data,
365+
size_t size);
350366

351367
/*!
352368
* @brief a callback to donate state snapshot
@@ -361,8 +377,7 @@ typedef enum wsrep_status (*wsrep_unordered_cb_t) (void* recv_ctx,
361377
* @param recv_ctx receiver context
362378
* @param msg state transfer request message
363379
* @param msg_len state transfer request message length
364-
* @param uuid current state uuid on this node
365-
* @param seqno current state seqno on this node
380+
* @param gtid current state ID on this node
366381
* @param state current wsrep internal state buffer
367382
* @param state_len current wsrep internal state buffer len
368383
* @param bypass bypass snapshot transfer, only transfer uuid:seqno pair
@@ -372,8 +387,7 @@ typedef int (*wsrep_sst_donate_cb_t) (void* app_ctx,
372387
void* recv_ctx,
373388
const void* msg,
374389
size_t msg_len,
375-
const wsrep_uuid_t* uuid,
376-
wsrep_seqno_t seqno,
390+
const wsrep_gtid_t* state_id,
377391
const char* state,
378392
size_t state_len,
379393
wsrep_bool_t bypass);
@@ -406,8 +420,7 @@ struct wsrep_init_args
406420
int proto_ver; //!< Max supported application protocol version
407421

408422
/* Application initial state information. */
409-
const wsrep_uuid_t* state_uuid; //!< Application state sequence UUID
410-
wsrep_seqno_t state_seqno; //!< Applicaiton state sequence number
423+
const wsrep_gtid_t* state_id; //!< Application state ID
411424
const char* state; //!< Initial state for wsrep implementation
412425
size_t state_len; //!< Length of state buffer
413426

@@ -840,29 +853,27 @@ struct wsrep_ {
840853
* @brief Signals to wsrep provider that state snapshot has been sent to
841854
* joiner.
842855
*
843-
* @param wsrep provider handle
844-
* @param uuid sequence UUID (group UUID)
845-
* @param seqno sequence number or negative error code of the operation
856+
* @param wsrep provider handle
857+
* @param state_id state ID
846858
*/
847859
wsrep_status_t (*sst_sent)(wsrep_t* wsrep,
848-
const wsrep_uuid_t* uuid,
849-
wsrep_seqno_t seqno);
860+
const wsrep_gtid_t* state_id);
850861

851862
/*!
852863
* @brief Signals to wsrep provider that new state snapshot has been received.
853864
* May deadlock if called from sst_prepare_cb.
854865
*
855866
* @param wsrep provider handle
856-
* @param uuid sequence UUID (group UUID)
857-
* @param seqno sequence number or negative error code of the operation
867+
* @param state_id state ID
858868
* @param state initial state provided by SST donor
859869
* @param state_len length of state buffer
870+
* @param rcode 0 or negative error code of the operation.
860871
*/
861872
wsrep_status_t (*sst_received)(wsrep_t* wsrep,
862-
const wsrep_uuid_t* uuid,
863-
wsrep_seqno_t seqno,
873+
const wsrep_gtid_t* state_id,
864874
const char* state,
865-
size_t state_len);
875+
size_t state_len,
876+
int rcode);
866877

867878

868879
/*!

wsrep_dummy.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,18 @@ static wsrep_status_t dummy_preordered(
220220

221221
static wsrep_status_t dummy_sst_sent(
222222
wsrep_t* w,
223-
const wsrep_uuid_t* uuid __attribute__((unused)),
224-
wsrep_seqno_t seqno __attribute__((unused)))
223+
const wsrep_gtid_t* state_id __attribute__((unused)))
225224
{
226225
WSREP_DBUG_ENTER(w);
227226
return WSREP_OK;
228227
}
229228

230229
static wsrep_status_t dummy_sst_received(
231230
wsrep_t* w,
232-
const wsrep_uuid_t* uuid __attribute__((unused)),
233-
const wsrep_seqno_t seqno __attribute__((unused)),
231+
const wsrep_gtid_t* state_id __attribute__((unused)),
234232
const char* state __attribute__((unused)),
235-
const size_t state_len __attribute__((unused)))
233+
const size_t state_len __attribute__((unused)),
234+
const int rcode __attribute__((unused)))
236235
{
237236
WSREP_DBUG_ENTER(w);
238237
return WSREP_OK;

wsrep_listener.c

+13-11
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ logger_cb (wsrep_log_level_t level __attribute__((unused)), const char* msg)
5050
* Each view change is the point where application may be pronounced out of
5151
* sync with the current cluster view and need state transfer.
5252
* It is guaranteed that no other callbacks are called concurrently with it. */
53-
static void
53+
static wsrep_cb_status_t
5454
view_cb (void* app_ctx __attribute__((unused)),
5555
void* recv_ctx __attribute__((unused)),
5656
const wsrep_view_info_t* view,
5757
const char* state __attribute__((unused)),
5858
size_t state_len __attribute__((unused)),
5959
void** sst_req,
60-
ssize_t* sst_req_len)
60+
int* sst_req_len)
6161
{
6262
printf ("New cluster membership view: %d nodes, my index is %d, "
6363
"global seqno: %lld\n",
64-
view->memb_num, view->my_idx, (long long)view->seqno);
64+
view->memb_num, view->my_idx, (long long)view->state_id.seqno);
6565

6666
if (view->state_gap) /* we need to receive new state from the cluster */
6767
{
@@ -76,12 +76,14 @@ view_cb (void* app_ctx __attribute__((unused)),
7676
else
7777
*sst_req_len = -ENOMEM;
7878
}
79+
80+
return WSREP_CB_SUCCESS;
7981
}
8082

8183
/*! This is called to "apply" writeset.
8284
* If writesets don't conflict on keys, it may be called concurrently to
8385
* utilize several CPU cores. */
84-
static wsrep_status_t
86+
static wsrep_cb_status_t
8587
apply_cb (void* recv_ctx,
8688
const void* ws_data __attribute__((unused)),
8789
size_t ws_size,
@@ -93,14 +95,14 @@ apply_cb (void* recv_ctx,
9395
"Got writeset %lld, size %zu", (long long)meta->gtid.seqno,
9496
ws_size);
9597

96-
return WSREP_OK;
98+
return WSREP_CB_SUCCESS;
9799
}
98100

99101
/*! This is called to "commit" or "rollback" previously applied writeset,
100102
* depending on commit parameter.
101103
* By default this callback is called synchronously in the order determined
102104
* by seqno. */
103-
static wsrep_status_t
105+
static wsrep_cb_status_t
104106
commit_cb (void* recv_ctx,
105107
const wsrep_trx_meta_t* meta __attribute__((unused)),
106108
wsrep_bool_t commit)
@@ -111,7 +113,7 @@ commit_cb (void* recv_ctx,
111113
* we don't need to worry about exclusive access to stdout. */
112114
if (commit) puts(ctx->msg);
113115

114-
return WSREP_OK;
116+
return WSREP_CB_SUCCESS;
115117
}
116118

117119
/* The following callbacks are stubs and not used in this example. */
@@ -120,8 +122,7 @@ sst_donate_cb (void* app_ctx __attribute__((unused)),
120122
void* recv_ctx __attribute__((unused)),
121123
const void* msg __attribute__((unused)),
122124
size_t msg_len __attribute__((unused)),
123-
const wsrep_uuid_t* uuid __attribute__((unused)),
124-
wsrep_seqno_t seqno __attribute__((unused)),
125+
const wsrep_gtid_t* state_id __attribute__((unused)),
125126
const char* state __attribute__((unused)),
126127
size_t state_len __attribute__((unused)),
127128
wsrep_bool_t bypass __attribute__((unused)))
@@ -176,6 +177,8 @@ int main (int argc, char* argv[])
176177
exit (EXIT_FAILURE);
177178
}
178179

180+
wsrep_gtid_t state_id = { WSREP_UUID_UNDEFINED, WSREP_SEQNO_UNDEFINED };
181+
179182
/* wsrep provider initialization arguments */
180183
struct wsrep_init_args wsrep_args =
181184
{
@@ -188,8 +191,7 @@ int main (int argc, char* argv[])
188191
.options = "",
189192
.proto_ver = 127, // maximum supported application event protocol
190193

191-
.state_uuid = &WSREP_UUID_UNDEFINED,
192-
.state_seqno = WSREP_SEQNO_UNDEFINED,
194+
.state_id = &state_id,
193195
.state = NULL,
194196
.state_len = 0,
195197

wsrep_uuid.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ wsrep_uuid_scan (const char* str, size_t str_len, wsrep_uuid_t* uuid)
4747

4848
if (isxdigit(str[uuid_len]) && isxdigit(str[uuid_len + 1])) {
4949
// got hex digit, scan another byte to uuid, increment uuid_offt
50-
sscanf (str + uuid_len, "%2hhx", uuid->uuid + uuid_offt);
50+
sscanf (str + uuid_len, "%2hhx", uuid->data + uuid_offt);
5151
uuid_len += 2;
5252
uuid_offt += 1;
53-
if (sizeof (uuid->uuid) == uuid_offt)
53+
if (sizeof (uuid->data) == uuid_offt)
5454
return uuid_len;
5555
}
5656
else {
@@ -71,7 +71,7 @@ int
7171
wsrep_uuid_print (const wsrep_uuid_t* uuid, char* str, size_t str_len)
7272
{
7373
if (str_len > 36) {
74-
const unsigned char* u = uuid->uuid;
74+
const unsigned char* u = uuid->data;
7575
return snprintf(str, str_len, "%02x%02x%02x%02x-%02x%02x-%02x%02x-"
7676
"%02x%02x-%02x%02x%02x%02x%02x%02x",
7777
u[ 0], u[ 1], u[ 2], u[ 3], u[ 4], u[ 5], u[ 6], u[ 7],
@@ -81,4 +81,3 @@ wsrep_uuid_print (const wsrep_uuid_t* uuid, char* str, size_t str_len)
8181
return -EMSGSIZE;
8282
}
8383
}
84-

0 commit comments

Comments
 (0)