1#ifndef MYSQL_SERVICE_WSREP_INCLUDED
2/* Copyright (c) 2015 MariaDB Corporation Ab
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17/**
18 @file
19 wsrep service
20
21 Interface to WSREP functionality in the server.
22 For engines that want to support galera.
23*/
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29enum wsrep_conflict_state {
30 NO_CONFLICT,
31 MUST_ABORT,
32 ABORTING,
33 ABORTED,
34 MUST_REPLAY,
35 REPLAYING,
36 RETRY_AUTOCOMMIT,
37 CERT_FAILURE,
38};
39
40enum wsrep_exec_mode {
41 /* Transaction processing before replication. */
42 LOCAL_STATE,
43 /* Slave thread applying write sets from other nodes or replaying thread. */
44 REPL_RECV,
45 /* Total-order-isolation mode. */
46 TOTAL_ORDER,
47 /*
48 Transaction procession after it has been replicated in prepare stage and
49 has passed certification.
50 */
51 LOCAL_COMMIT
52};
53
54enum wsrep_query_state {
55 QUERY_IDLE,
56 QUERY_EXEC,
57 QUERY_COMMITTING,
58 QUERY_EXITING,
59 QUERY_ROLLINGBACK,
60};
61
62enum wsrep_trx_status {
63 WSREP_TRX_OK,
64 WSREP_TRX_CERT_FAIL, /* certification failure, must abort */
65 WSREP_TRX_SIZE_EXCEEDED, /* trx size exceeded */
66 WSREP_TRX_ERROR, /* native mysql error */
67};
68
69struct xid_t;
70struct wsrep;
71struct wsrep_ws_handle;
72struct wsrep_buf;
73
74extern struct wsrep_service_st {
75 struct wsrep * (*get_wsrep_func)();
76 my_bool (*get_wsrep_certify_nonPK_func)();
77 my_bool (*get_wsrep_debug_func)();
78 my_bool (*get_wsrep_drupal_282555_workaround_func)();
79 my_bool (*get_wsrep_recovery_func)();
80 my_bool (*get_wsrep_load_data_splitting_func)();
81 my_bool (*get_wsrep_log_conflicts_func)();
82 long (*get_wsrep_protocol_version_func)();
83 my_bool (*wsrep_aborting_thd_contains_func)(THD *thd);
84 void (*wsrep_aborting_thd_enqueue_func)(THD *thd);
85 bool (*wsrep_consistency_check_func)(THD *thd);
86 int (*wsrep_is_wsrep_xid_func)(const struct xid_t *xid);
87 long long (*wsrep_xid_seqno_func)(const struct xid_t *xid);
88 const unsigned char* (*wsrep_xid_uuid_func)(const struct xid_t *xid);
89 void (*wsrep_lock_rollback_func)();
90 int (*wsrep_on_func)(MYSQL_THD);
91 void (*wsrep_post_commit_func)(THD* thd, bool all);
92 bool (*wsrep_prepare_key_func)(const unsigned char*, size_t, const unsigned char*, size_t, struct wsrep_buf*, size_t*);
93 enum wsrep_trx_status (*wsrep_run_wsrep_commit_func)(THD *thd, bool all);
94 void (*wsrep_thd_LOCK_func)(THD *thd);
95 void (*wsrep_thd_UNLOCK_func)(THD *thd);
96 void (*wsrep_thd_awake_func)(THD *thd, my_bool signal);
97 enum wsrep_conflict_state (*wsrep_thd_conflict_state_func)(MYSQL_THD, my_bool);
98 const char * (*wsrep_thd_conflict_state_str_func)(THD *thd);
99 enum wsrep_exec_mode (*wsrep_thd_exec_mode_func)(THD *thd);
100 const char * (*wsrep_thd_exec_mode_str_func)(THD *thd);
101 enum wsrep_conflict_state (*wsrep_thd_get_conflict_state_func)(MYSQL_THD);
102 my_bool (*wsrep_thd_is_BF_func)(MYSQL_THD , my_bool);
103 my_bool (*wsrep_thd_is_wsrep_func)(MYSQL_THD thd);
104 char * (*wsrep_thd_query_func)(THD *thd);
105 enum wsrep_query_state (*wsrep_thd_query_state_func)(THD *thd);
106 const char * (*wsrep_thd_query_state_str_func)(THD *thd);
107 int (*wsrep_thd_retry_counter_func)(THD *thd);
108 void (*wsrep_thd_set_conflict_state_func)(THD *thd, enum wsrep_conflict_state state);
109 bool (*wsrep_thd_ignore_table_func)(THD *thd);
110 long long (*wsrep_thd_trx_seqno_func)(THD *thd);
111 struct wsrep_ws_handle * (*wsrep_thd_ws_handle_func)(THD *thd);
112 int (*wsrep_trx_is_aborting_func)(MYSQL_THD thd);
113 int (*wsrep_trx_order_before_func)(MYSQL_THD, MYSQL_THD);
114 void (*wsrep_unlock_rollback_func)();
115} *wsrep_service;
116
117#ifdef MYSQL_DYNAMIC_PLUGIN
118#define get_wsrep() wsrep_service->get_wsrep_func()
119#define get_wsrep_certify_nonPK() wsrep_service->get_wsrep_certify_nonPK_func()
120#define get_wsrep_debug() wsrep_service->get_wsrep_debug_func()
121#define get_wsrep_drupal_282555_workaround() wsrep_service->get_wsrep_drupal_282555_workaround_func()
122#define get_wsrep_recovery() wsrep_service->get_wsrep_recovery_func()
123#define get_wsrep_load_data_splitting() wsrep_service->get_wsrep_load_data_splitting_func()
124#define get_wsrep_log_conflicts() wsrep_service->get_wsrep_log_conflicts_func()
125#define get_wsrep_protocol_version() wsrep_service->get_wsrep_protocol_version_func()
126#define wsrep_aborting_thd_contains(T) wsrep_service->wsrep_aborting_thd_contains_func(T)
127#define wsrep_aborting_thd_enqueue(T) wsrep_service->wsrep_aborting_thd_enqueue_func(T)
128#define wsrep_consistency_check(T) wsrep_service->wsrep_consistency_check_func(T)
129#define wsrep_is_wsrep_xid(X) wsrep_service->wsrep_is_wsrep_xid_func(X)
130#define wsrep_xid_seqno(X) wsrep_service->wsrep_xid_seqno_func(X)
131#define wsrep_xid_uuid(X) wsrep_service->wsrep_xid_uuid_func(X)
132#define wsrep_lock_rollback() wsrep_service->wsrep_lock_rollback_func()
133#define wsrep_on(X) wsrep_service->wsrep_on_func(X)
134#define wsrep_post_commit(T,A) wsrep_service->wsrep_post_commit_func(T,A)
135#define wsrep_prepare_key(A,B,C,D,E,F) wsrep_service->wsrep_prepare_key_func(A,B,C,D,E,F)
136#define wsrep_run_wsrep_commit(T,A) wsrep_service->wsrep_run_wsrep_commit_func(T,A)
137#define wsrep_thd_LOCK(T) wsrep_service->wsrep_thd_LOCK_func(T)
138#define wsrep_thd_UNLOCK(T) wsrep_service->wsrep_thd_UNLOCK_func(T)
139#define wsrep_thd_awake(T,S) wsrep_service->wsrep_thd_awake_func(T,S)
140#define wsrep_thd_conflict_state(T,S) wsrep_service->wsrep_thd_conflict_state_func(T,S)
141#define wsrep_thd_conflict_state_str(T) wsrep_service->wsrep_thd_conflict_state_str_func(T)
142#define wsrep_thd_exec_mode(T) wsrep_service->wsrep_thd_exec_mode_func(T)
143#define wsrep_thd_exec_mode_str(T) wsrep_service->wsrep_thd_exec_mode_str_func(T)
144#define wsrep_thd_get_conflict_state(T) wsrep_service->wsrep_thd_get_conflict_state_func(T)
145#define wsrep_thd_is_BF(T,S) wsrep_service->wsrep_thd_is_BF_func(T,S)
146#define wsrep_thd_is_wsrep(T) wsrep_service->wsrep_thd_is_wsrep_func(T)
147#define wsrep_thd_query(T) wsrep_service->wsrep_thd_query_func(T)
148#define wsrep_thd_query_state(T) wsrep_service->wsrep_thd_query_state_func(T)
149#define wsrep_thd_query_state_str(T) wsrep_service->wsrep_thd_query_state_str_func(T)
150#define wsrep_thd_retry_counter(T) wsrep_service->wsrep_thd_retry_counter_func(T)
151#define wsrep_thd_set_conflict_state(T,S) wsrep_service->wsrep_thd_set_conflict_state_func(T,S)
152#define wsrep_thd_ignore_table(T) wsrep_service->wsrep_thd_ignore_table_func(T)
153#define wsrep_thd_trx_seqno(T) wsrep_service->wsrep_thd_trx_seqno_func(T)
154#define wsrep_thd_ws_handle(T) wsrep_service->wsrep_thd_ws_handle_func(T)
155#define wsrep_trx_is_aborting(T) wsrep_service->wsrep_trx_is_aborting_func(T)
156#define wsrep_trx_order_before(T1,T2) wsrep_service->wsrep_trx_order_before_func(T1,T2)
157#define wsrep_unlock_rollback() wsrep_service->wsrep_unlock_rollback_func()
158
159#define wsrep_debug get_wsrep_debug()
160#define wsrep_log_conflicts get_wsrep_log_conflicts()
161#define wsrep_certify_nonPK get_wsrep_certify_nonPK()
162#define wsrep_load_data_splitting get_wsrep_load_data_splitting()
163#define wsrep_drupal_282555_workaround get_wsrep_drupal_282555_workaround()
164#define wsrep_recovery get_wsrep_recovery()
165#define wsrep_protocol_version get_wsrep_protocol_version()
166
167#else
168
169extern my_bool wsrep_debug;
170extern my_bool wsrep_log_conflicts;
171extern my_bool wsrep_certify_nonPK;
172extern my_bool wsrep_load_data_splitting;
173extern my_bool wsrep_drupal_282555_workaround;
174extern my_bool wsrep_recovery;
175extern long wsrep_protocol_version;
176
177bool wsrep_consistency_check(THD *thd);
178bool wsrep_prepare_key(const unsigned char* cache_key, size_t cache_key_len, const unsigned char* row_id, size_t row_id_len, struct wsrep_buf* key, size_t* key_len);
179char *wsrep_thd_query(THD *thd);
180const char *wsrep_thd_conflict_state_str(THD *thd);
181const char *wsrep_thd_exec_mode_str(THD *thd);
182const char *wsrep_thd_query_state_str(THD *thd);
183enum wsrep_conflict_state wsrep_thd_conflict_state(MYSQL_THD thd, my_bool sync);
184enum wsrep_conflict_state wsrep_thd_get_conflict_state(MYSQL_THD thd);
185enum wsrep_exec_mode wsrep_thd_exec_mode(THD *thd);
186enum wsrep_query_state wsrep_thd_query_state(THD *thd);
187enum wsrep_trx_status wsrep_run_wsrep_commit(THD *thd, bool all);
188int wsrep_is_wsrep_xid(const struct xid_t* xid);
189long long wsrep_xid_seqno(const struct xid_t* xid);
190const unsigned char* wsrep_xid_uuid(const struct xid_t* xid);
191int wsrep_on(MYSQL_THD thd);
192int wsrep_thd_retry_counter(THD *thd);
193int wsrep_trx_is_aborting(MYSQL_THD thd);
194int wsrep_trx_order_before(MYSQL_THD thd1, MYSQL_THD thd2);
195long get_wsrep_protocol_version();
196long long wsrep_thd_trx_seqno(THD *thd);
197my_bool get_wsrep_certify_nonPK();
198my_bool get_wsrep_debug();
199my_bool get_wsrep_drupal_282555_workaround();
200my_bool get_wsrep_recovery();
201my_bool get_wsrep_load_data_splitting();
202my_bool get_wsrep_log_conflicts();
203my_bool wsrep_aborting_thd_contains(THD *thd);
204my_bool wsrep_thd_is_BF(MYSQL_THD thd, my_bool sync);
205my_bool wsrep_thd_is_wsrep(MYSQL_THD thd);
206struct wsrep *get_wsrep();
207struct wsrep_ws_handle *wsrep_thd_ws_handle(THD *thd);
208void wsrep_aborting_thd_enqueue(THD *thd);
209void wsrep_lock_rollback();
210void wsrep_post_commit(THD* thd, bool all);
211void wsrep_thd_LOCK(THD *thd);
212void wsrep_thd_UNLOCK(THD *thd);
213void wsrep_thd_awake(THD *thd, my_bool signal);
214void wsrep_thd_set_conflict_state(THD *thd, enum wsrep_conflict_state state);
215bool wsrep_thd_ignore_table(THD *thd);
216void wsrep_unlock_rollback();
217
218#endif
219
220#ifdef __cplusplus
221}
222#endif
223
224#define MYSQL_SERVICE_WSREP_INCLUDED
225#endif
226
227