72
/* The plugin_foreach() iterator requires that we
73
convert all the parameters of a plugin api entry point
74
into just one single void ptr, plus the session.
75
So we will take all the additional paramters of replicator_do1,
76
and marshall them into a struct of this type, and
77
then just pass in a pointer to it.
79
typedef struct replicator_do1_parms_st
83
} replicator_do1_parms_t;
85
73
/* This gets called by plugin_foreach once for each loaded replicator plugin */
86
static bool replicator_do1_iterate (Session *session, plugin_ref plugin, void *p)
74
static bool replicator_session_iterate (Session *session, plugin_ref plugin, void *)
88
replicator_t *l= plugin_data(plugin, replicator_t *);
89
replicator_do1_parms_t *parms= (replicator_do1_parms_t *) p;
76
replicator_t *repl= plugin_data(plugin, replicator_t *);
91
79
/* call this loaded replicator plugin's replicator_func1 function pointer */
92
if (l && l->replicator_func1)
80
if (repl && repl->session_init)
94
if (l->replicator_func1(session, parms->parm1, parms->parm2))
82
session_data= repl->session_init(session);
96
85
/* TRANSLATORS: The leading word "replicator" is the name
97
86
of the plugin api, and so should not be translated. */
98
sql_print_error(_("replicator plugin '%s' replicator_func1() failed"),
87
sql_print_error(_("replicator plugin '%s' replicator_session_init() failed"),
99
88
(char *)plugin_name(plugin));
93
session->setReplicationData(session_data);
106
/* This is the replicator_do1 entry point.
107
This gets called by the rest of the Drizzle server code */
108
bool replicator_do1 (Session *session, void *parm1, void *parm2)
99
This call is called once at the begining of each transaction.
101
bool replicator_session_init(Session *session)
110
replicator_do1_parms_t parms;
113
/* marshall the parameters so they will fit into the foreach */
117
/* call replicator_do1_iterate
118
once for each loaded replicator plugin */
119
foreach_rv= plugin_foreach(session,
120
replicator_do1_iterate,
121
DRIZZLE_REPLICATOR_PLUGIN,
106
call replicator_session_iterate
107
once for each loaded replicator plugin
109
foreach_rv= plugin_foreach(session, replicator_session_iterate,
110
DRIZZLE_REPLICATOR_PLUGIN, NULL);
123
111
return foreach_rv;
130
118
and marshall them into a struct of this type, and
131
119
then just pass in a pointer to it.
133
typedef struct replicator_do2_parms_st
121
enum repl_row_exec_t{
127
typedef struct replicator_row_parms_st
137
} replicator_do2_parms_t;
129
repl_row_exec_t type;
131
const unsigned char *before;
132
const unsigned char *after;
133
} replicator_row_parms_st;
139
136
/* This gets called by plugin_foreach once for each loaded replicator plugin */
140
static bool replicator_do2_iterate (Session *session, plugin_ref plugin, void *p)
137
static bool replicator_do_row_iterate (Session *session, plugin_ref plugin, void *p)
142
replicator_t *l= plugin_data(plugin, replicator_t *);
143
replicator_do2_parms_t *parms= (replicator_do2_parms_t *) p;
145
/* call this loaded replicator plugin's replicator_func1 function pointer */
146
if (l && l->replicator_func2)
148
if (l->replicator_func2(session, parms->parm3, parms->parm4))
150
/* TRANSLATORS: The leading word "replicator" is the name
151
of the plugin api, and so should not be translated. */
152
sql_print_error(_("replicator plugin '%s' replicator_func2() failed"),
153
(char *)plugin_name(plugin));
139
replicator_t *repl= plugin_data(plugin, replicator_t *);
140
replicator_row_parms_st *params= (replicator_row_parms_st *) p;
142
switch (params->type) {
144
if (repl && repl->row_insert)
146
if (repl->row_insert(session, params->table))
148
/* TRANSLATORS: The leading word "replicator" is the name
149
of the plugin api, and so should not be translated. */
150
sql_print_error(_("replicator plugin '%s' row_insert() failed"),
151
(char *)plugin_name(plugin));
158
if (repl && repl->row_update)
160
if (repl->row_update(session, params->table, params->before, params->after))
162
/* TRANSLATORS: The leading word "replicator" is the name
163
of the plugin api, and so should not be translated. */
164
sql_print_error(_("replicator plugin '%s' row_update() failed"),
165
(char *)plugin_name(plugin));
172
if (repl && repl->row_delete)
174
if (repl->row_delete(session, params->table))
176
/* TRANSLATORS: The leading word "replicator" is the name
177
of the plugin api, and so should not be translated. */
178
sql_print_error(_("replicator plugin '%s' row_delete() failed"),
179
(char *)plugin_name(plugin));
161
189
/* This is the replicator_do2 entry point.
162
190
This gets called by the rest of the Drizzle server code */
163
bool replicator_do2 (Session *session, void *parm3, void *parm4)
165
replicator_do2_parms_t parms;
168
/* marshall the parameters so they will fit into the foreach */
172
/* call replicator_do2_iterate
173
once for each loaded replicator plugin */
174
foreach_rv= plugin_foreach(session,
175
replicator_do2_iterate,
176
DRIZZLE_REPLICATOR_PLUGIN,
191
static bool replicator_do_row (Session *session, replicator_row_parms_st *params)
195
foreach_rv= plugin_foreach(session, replicator_do_row_iterate,
196
DRIZZLE_REPLICATOR_PLUGIN, (void *) ¶ms);
200
bool replicator_write_row(Session *session, Table *table)
202
replicator_row_parms_st param;
204
param.type= repl_insert;
209
return replicator_do_row(session, ¶m);
212
bool replicator_update_row(Session *session, Table *table,
213
const unsigned char *before,
214
const unsigned char *after)
216
replicator_row_parms_st param;
218
param.type= repl_update;
221
param.before= before;
223
return replicator_do_row(session, ¶m);
226
bool replicator_delete_row(Session *session, Table *table)
228
replicator_row_parms_st param;
230
param.type= repl_delete;
235
return replicator_do_row(session, ¶m);
241
Ok, not so much dragons, but this is where we handle either commits or rollbacks of
244
typedef struct replicator_row_end_st
248
} replicator_row_end_st;
250
/* We call this to end a statement (on each registered plugin) */
251
static bool replicator_do_row_end_iterate (Session *session, plugin_ref plugin, void *p)
253
replicator_t *repl= plugin_data(plugin, replicator_t *);
254
replicator_row_end_st *params= (replicator_row_end_st *)p;
256
/* call this loaded replicator plugin's replicator_func1 function pointer */
257
if (repl && repl->end_transaction)
259
if (repl->end_transaction(session, params->autocommit, params->commit))
261
/* TRANSLATORS: The leading word "replicator" is the name
262
of the plugin api, and so should not be translated. */
263
sql_print_error(_("replicator plugin '%s' end_transaction() failed"),
264
(char *)plugin_name(plugin));
272
bool replicator_end_transaction(Session *session, bool autocommit, bool commit)
275
replicator_row_end_st params;
277
params.autocommit= autocommit;
278
params.commit= commit;
280
/* We need to free any data we did an init of for the session */
281
foreach_rv= plugin_foreach(session, replicator_do_row_end_iterate,
282
DRIZZLE_REPLICATOR_PLUGIN, (void *) ¶ms);
288
For a ROLLBACK TO SAVEPOINT we make this call.
290
bool replicator_rollback_to_savepoint(Session *, void *)
296
If somene makes a call to create a savepoint.
298
bool replicator_savepoint_set(Session *, void *)
304
If you can do real 2PC this is your hook poing to know that the event is coming.
306
Always true for the moment.
309
bool replicator_prepare(Session *)