1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
|
/* Copyright (C) 2009-2010 Codership Oy <info@codersihp.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
/*! @file Dummy wsrep API implementation. */
#include "wsrep_api.h"
#include <errno.h>
#include <string.h>
/*! Dummy backend context. */
typedef struct wsrep_dummy
{
wsrep_log_cb_t log_fn;
char* options;
} wsrep_dummy_t;
/* Get pointer to wsrep_dummy context from wsrep_t pointer */
#define WSREP_DUMMY(_p) ((wsrep_dummy_t *) (_p)->ctx)
/* Trace function usage a-la DBUG */
#define WSREP_DBUG_ENTER(_w) do { \
if (WSREP_DUMMY(_w)) { \
if (WSREP_DUMMY(_w)->log_fn) \
WSREP_DUMMY(_w)->log_fn(WSREP_LOG_DEBUG, __FUNCTION__); \
} \
} while (0)
static void dummy_free(wsrep_t *w)
{
WSREP_DBUG_ENTER(w);
if (WSREP_DUMMY(w)->options) {
free(WSREP_DUMMY(w)->options);
WSREP_DUMMY(w)->options = NULL;
}
free(w->ctx);
w->ctx = NULL;
}
static wsrep_status_t dummy_init (wsrep_t* w,
const struct wsrep_init_args* args)
{
WSREP_DUMMY(w)->log_fn = args->logger_cb;
WSREP_DBUG_ENTER(w);
if (args->options) {
WSREP_DUMMY(w)->options = strdup(args->options);
}
return WSREP_OK;
}
static uint64_t dummy_capabilities (wsrep_t* w __attribute__((unused)))
{
return 0;
}
static wsrep_status_t dummy_options_set(
wsrep_t* w,
const char* conf)
{
WSREP_DBUG_ENTER(w);
if (WSREP_DUMMY(w)->options) {
free(WSREP_DUMMY(w)->options);
WSREP_DUMMY(w)->options = NULL;
}
if (conf) {
WSREP_DUMMY(w)->options = strdup(conf);
}
return WSREP_OK;
}
static char* dummy_options_get (wsrep_t* w)
{
char *options;
WSREP_DBUG_ENTER(w);
options= WSREP_DUMMY(w)->options;
if (options)
options= strdup(WSREP_DUMMY(w)->options);
return options;
}
static wsrep_status_t dummy_connect(
wsrep_t* w,
const char* name __attribute__((unused)),
const char* url __attribute__((unused)),
const char* donor __attribute__((unused)),
wsrep_bool_t bootstrap __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_disconnect(wsrep_t* w)
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_recv(wsrep_t* w,
void* recv_ctx __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_pre_commit(
wsrep_t* w,
const wsrep_conn_id_t conn_id __attribute__((unused)),
wsrep_ws_handle_t* ws_handle __attribute__((unused)),
uint32_t flags __attribute__((unused)),
wsrep_trx_meta_t* meta __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_post_commit(
wsrep_t* w,
wsrep_ws_handle_t* ws_handle __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_post_rollback(
wsrep_t* w,
wsrep_ws_handle_t* ws_handle __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_replay_trx(
wsrep_t* w,
wsrep_ws_handle_t* ws_handle __attribute__((unused)),
void* trx_ctx __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_abort_pre_commit(
wsrep_t* w,
const wsrep_seqno_t bf_seqno __attribute__((unused)),
const wsrep_trx_id_t trx_id __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_append_key(
wsrep_t* w,
wsrep_ws_handle_t* ws_handle __attribute__((unused)),
const wsrep_key_t* key __attribute__((unused)),
const size_t key_num __attribute__((unused)),
const wsrep_key_type_t key_type __attribute__((unused)),
const wsrep_bool_t copy __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_append_data(
wsrep_t* w,
wsrep_ws_handle_t* ws_handle __attribute__((unused)),
const struct wsrep_buf* data __attribute__((unused)),
const size_t count __attribute__((unused)),
const wsrep_data_type_t type __attribute__((unused)),
const wsrep_bool_t copy __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_causal_read(
wsrep_t* w,
wsrep_gtid_t* gtid __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_free_connection(
wsrep_t* w,
const wsrep_conn_id_t conn_id __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_to_execute_start(
wsrep_t* w,
const wsrep_conn_id_t conn_id __attribute__((unused)),
const wsrep_key_t* key __attribute__((unused)),
const size_t key_num __attribute__((unused)),
const struct wsrep_buf* data __attribute__((unused)),
const size_t count __attribute__((unused)),
wsrep_trx_meta_t* meta __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_to_execute_end(
wsrep_t* w,
const wsrep_conn_id_t conn_id __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_preordered_collect(
wsrep_t* w,
wsrep_po_handle_t* handle __attribute__((unused)),
const struct wsrep_buf* data __attribute__((unused)),
size_t count __attribute__((unused)),
wsrep_bool_t copy __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_preordered_commit(
wsrep_t* w,
wsrep_po_handle_t* handle __attribute__((unused)),
const wsrep_uuid_t* source_id __attribute__((unused)),
uint32_t flags __attribute__((unused)),
int pa_range __attribute__((unused)),
wsrep_bool_t commit __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_sst_sent(
wsrep_t* w,
const wsrep_gtid_t* state_id __attribute__((unused)),
const int rcode __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_sst_received(
wsrep_t* w,
const wsrep_gtid_t* state_id __attribute__((unused)),
const void* state __attribute__((unused)),
const size_t state_len __attribute__((unused)),
const int rcode __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_snapshot(
wsrep_t* w,
const void* msg __attribute__((unused)),
const size_t msg_len __attribute__((unused)),
const char* donor_spec __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static struct wsrep_stats_var dummy_stats[] = {
{ NULL, WSREP_VAR_STRING, { 0 } }
};
static struct wsrep_stats_var* dummy_stats_get (wsrep_t* w)
{
WSREP_DBUG_ENTER(w);
return dummy_stats;
}
static void dummy_stats_free (
wsrep_t* w,
struct wsrep_stats_var* stats __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
}
static void dummy_stats_reset (wsrep_t* w)
{
WSREP_DBUG_ENTER(w);
}
static wsrep_seqno_t dummy_pause (wsrep_t* w)
{
WSREP_DBUG_ENTER(w);
return -ENOSYS;
}
static wsrep_status_t dummy_resume (wsrep_t* w)
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_desync (wsrep_t* w)
{
WSREP_DBUG_ENTER(w);
return WSREP_NOT_IMPLEMENTED;
}
static wsrep_status_t dummy_resync (wsrep_t* w)
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_status_t dummy_lock (wsrep_t* w,
const char* s __attribute__((unused)),
wsrep_bool_t r __attribute__((unused)),
uint64_t o __attribute__((unused)),
int64_t t __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_NOT_IMPLEMENTED;
}
static wsrep_status_t dummy_unlock (wsrep_t* w,
const char* s __attribute__((unused)),
uint64_t o __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return WSREP_OK;
}
static wsrep_bool_t dummy_is_locked (wsrep_t* w,
const char* s __attribute__((unused)),
uint64_t* o __attribute__((unused)),
wsrep_uuid_t* t __attribute__((unused)))
{
WSREP_DBUG_ENTER(w);
return 0;
}
static wsrep_t dummy_iface = {
WSREP_INTERFACE_VERSION,
&dummy_init,
&dummy_capabilities,
&dummy_options_set,
&dummy_options_get,
&dummy_connect,
&dummy_disconnect,
&dummy_recv,
&dummy_pre_commit,
&dummy_post_commit,
&dummy_post_rollback,
&dummy_replay_trx,
&dummy_abort_pre_commit,
&dummy_append_key,
&dummy_append_data,
&dummy_causal_read,
&dummy_free_connection,
&dummy_to_execute_start,
&dummy_to_execute_end,
&dummy_preordered_collect,
&dummy_preordered_commit,
&dummy_sst_sent,
&dummy_sst_received,
&dummy_snapshot,
&dummy_stats_get,
&dummy_stats_free,
&dummy_stats_reset,
&dummy_pause,
&dummy_resume,
&dummy_desync,
&dummy_resync,
&dummy_lock,
&dummy_unlock,
&dummy_is_locked,
WSREP_NONE,
WSREP_INTERFACE_VERSION,
"Codership Oy <info@codership.com>",
&dummy_free,
NULL,
NULL
};
int wsrep_dummy_loader(wsrep_t* w)
{
if (!w)
return EINVAL;
*w = dummy_iface;
// allocate private context
if (!(w->ctx = malloc(sizeof(wsrep_dummy_t))))
return ENOMEM;
// initialize private context
WSREP_DUMMY(w)->log_fn = NULL;
WSREP_DUMMY(w)->options = NULL;
return 0;
}
|