1 #ifndef MYSQL_SERVICE_WSREP_INCLUDED
2 #define MYSQL_SERVICE_WSREP_INCLUDED
3 
4 enum Wsrep_service_key_type
5 {
6     WSREP_SERVICE_KEY_SHARED,
7     WSREP_SERVICE_KEY_REFERENCE,
8     WSREP_SERVICE_KEY_UPDATE,
9     WSREP_SERVICE_KEY_EXCLUSIVE
10 };
11 
12 #if (defined (MYSQL_DYNAMIC_PLUGIN) && defined(MYSQL_SERVICE_WSREP_DYNAMIC_INCLUDED)) || (!defined(MYSQL_DYNAMIC_PLUGIN) && defined(MYSQL_SERVICE_WSREP_STATIC_INCLUDED))
13 
14 #else
15 
16 /* Copyright (c) 2015, 2020, MariaDB Corporation Ab
17                  2018 Codership Oy <info@codership.com>
18 
19    This program is free software; you can redistribute it and/or modify
20    it under the terms of the GNU General Public License as published by
21    the Free Software Foundation; version 2 of the License.
22 
23    This program is distributed in the hope that it will be useful,
24    but WITHOUT ANY WARRANTY; without even the implied warranty of
25    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26    GNU General Public License for more details.
27 
28    You should have received a copy of the GNU General Public License
29    along with this program; if not, write to the Free Software
30    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335  USA */
31 
32 /**
33   @file
34   wsrep service
35 
36   Interface to WSREP functionality in the server.
37   For engines that want to support galera.
38 */
39 #include <my_pthread.h>
40 #ifdef __cplusplus
41 #endif
42 
43 struct xid_t;
44 struct wsrep_ws_handle;
45 struct wsrep_buf;
46 
47 /* Must match to definition in sql/mysqld.h */
48 typedef int64 query_id_t;
49 
50 
51 extern struct wsrep_service_st {
52   my_bool                     (*get_wsrep_recovery_func)();
53   bool                        (*wsrep_consistency_check_func)(MYSQL_THD thd);
54   int                         (*wsrep_is_wsrep_xid_func)(const void *xid);
55   long long                   (*wsrep_xid_seqno_func)(const struct xid_t *xid);
56   const unsigned char*        (*wsrep_xid_uuid_func)(const struct xid_t *xid);
57   my_bool                     (*wsrep_on_func)(const MYSQL_THD thd);
58   bool                        (*wsrep_prepare_key_for_innodb_func)(MYSQL_THD thd, const unsigned char*, size_t, const unsigned char*, size_t, struct wsrep_buf*, size_t*);
59   void                        (*wsrep_thd_LOCK_func)(const MYSQL_THD thd);
60   void                        (*wsrep_thd_UNLOCK_func)(const MYSQL_THD thd);
61   const char *                (*wsrep_thd_query_func)(const MYSQL_THD thd);
62   int                         (*wsrep_thd_retry_counter_func)(const MYSQL_THD thd);
63   bool                        (*wsrep_thd_ignore_table_func)(MYSQL_THD thd);
64   long long                   (*wsrep_thd_trx_seqno_func)(const MYSQL_THD thd);
65   my_bool                     (*wsrep_thd_is_aborting_func)(const MYSQL_THD thd);
66   void                        (*wsrep_set_data_home_dir_func)(const char *data_dir);
67   my_bool                     (*wsrep_thd_is_BF_func)(const MYSQL_THD thd, my_bool sync);
68   my_bool                     (*wsrep_thd_is_local_func)(const MYSQL_THD thd);
69   void                        (*wsrep_thd_self_abort_func)(MYSQL_THD thd);
70   int                         (*wsrep_thd_append_key_func)(MYSQL_THD thd, const struct wsrep_key* key,
71                                                            int n_keys, enum Wsrep_service_key_type);
72   const char*                 (*wsrep_thd_client_state_str_func)(const MYSQL_THD thd);
73   const char*                 (*wsrep_thd_client_mode_str_func)(const MYSQL_THD thd);
74   const char*                 (*wsrep_thd_transaction_state_str_func)(const MYSQL_THD thd);
75   query_id_t                  (*wsrep_thd_transaction_id_func)(const MYSQL_THD thd);
76   my_bool                     (*wsrep_thd_bf_abort_func)(MYSQL_THD bf_thd,
77                                                          MYSQL_THD victim_thd,
78                                                          my_bool signal);
79   my_bool                     (*wsrep_thd_order_before_func)(const MYSQL_THD left, const MYSQL_THD right);
80   void                        (*wsrep_handle_SR_rollback_func)(MYSQL_THD BF_thd, MYSQL_THD victim_thd);
81   my_bool                     (*wsrep_thd_skip_locking_func)(const MYSQL_THD thd);
82   const char*                 (*wsrep_get_sr_table_name_func)();
83   my_bool                     (*wsrep_get_debug_func)();
84   void                        (*wsrep_commit_ordered_func)(MYSQL_THD thd);
85   my_bool                     (*wsrep_thd_is_applying_func)(const MYSQL_THD thd);
86   ulong                       (*wsrep_OSU_method_get_func)(const MYSQL_THD thd);
87   my_bool                     (*wsrep_thd_has_ignored_error_func)(const MYSQL_THD thd);
88   void                        (*wsrep_thd_set_ignored_error_func)(MYSQL_THD thd, my_bool val);
89   bool                        (*wsrep_thd_set_wsrep_aborter_func)(MYSQL_THD bf_thd, MYSQL_THD thd);
90   void                        (*wsrep_report_bf_lock_wait_func)(const MYSQL_THD thd,
91                                                                 unsigned long long trx_id);
92   void                        (*wsrep_thd_kill_LOCK_func)(const MYSQL_THD thd);
93   void                        (*wsrep_thd_kill_UNLOCK_func)(const MYSQL_THD thd);
94   void                        (*wsrep_thd_set_wsrep_PA_unsafe_func)(MYSQL_THD thd);
95 } *wsrep_service;
96 
97 #define MYSQL_SERVICE_WSREP_INCLUDED
98 #endif
99 
100 #ifdef MYSQL_DYNAMIC_PLUGIN
101 
102 #define MYSQL_SERVICE_WSREP_DYNAMIC_INCLUDED
103 #define get_wsrep_recovery() wsrep_service->get_wsrep_recovery_func()
104 #define wsrep_consistency_check(T) wsrep_service->wsrep_consistency_check_func(T)
105 #define wsrep_is_wsrep_xid(X) wsrep_service->wsrep_is_wsrep_xid_func(X)
106 #define wsrep_xid_seqno(X) wsrep_service->wsrep_xid_seqno_func(X)
107 #define wsrep_xid_uuid(X) wsrep_service->wsrep_xid_uuid_func(X)
108 #define wsrep_on(thd) (thd) && WSREP_ON && wsrep_service->wsrep_on_func(thd)
109 #define wsrep_prepare_key_for_innodb(A,B,C,D,E,F,G) wsrep_service->wsrep_prepare_key_for_innodb_func(A,B,C,D,E,F,G)
110 #define wsrep_thd_LOCK(T) wsrep_service->wsrep_thd_LOCK_func(T)
111 #define wsrep_thd_UNLOCK(T) wsrep_service->wsrep_thd_UNLOCK_func(T)
112 #define wsrep_thd_kill_LOCK(T) wsrep_service->wsrep_thd_kill_LOCK_func(T)
113 #define wsrep_thd_kill_UNLOCK(T) wsrep_service->wsrep_thd_kill_UNLOCK_func(T)
114 #define wsrep_thd_query(T) wsrep_service->wsrep_thd_query_func(T)
115 #define wsrep_thd_retry_counter(T) wsrep_service->wsrep_thd_retry_counter_func(T)
116 #define wsrep_thd_ignore_table(T) wsrep_service->wsrep_thd_ignore_table_func(T)
117 #define wsrep_thd_trx_seqno(T) wsrep_service->wsrep_thd_trx_seqno_func(T)
118 #define wsrep_set_data_home_dir(A) wsrep_service->wsrep_set_data_home_dir_func(A)
119 #define wsrep_thd_is_BF(T,S) wsrep_service->wsrep_thd_is_BF_func(T,S)
120 #define wsrep_thd_is_aborting(T) wsrep_service->wsrep_thd_is_aborting_func(T)
121 #define wsrep_thd_is_local(T) wsrep_service->wsrep_thd_is_local_func(T)
122 #define wsrep_thd_self_abort(T) wsrep_service->wsrep_thd_self_abort_func(T)
123 #define wsrep_thd_append_key(T,W,N,K) wsrep_service->wsrep_thd_append_key_func(T,W,N,K)
124 #define wsrep_thd_client_state_str(T) wsrep_service->wsrep_thd_client_state_str_func(T)
125 #define wsrep_thd_client_mode_str(T) wsrep_service->wsrep_thd_client_mode_str_func(T)
126 #define wsrep_thd_transaction_state_str(T) wsrep_service->wsrep_thd_transaction_state_str_func(T)
127 #define wsrep_thd_transaction_id(T) wsrep_service->wsrep_thd_transaction_id_func(T)
128 #define wsrep_thd_bf_abort(T,T2,S) wsrep_service->wsrep_thd_bf_abort_func(T,T2,S)
129 #define wsrep_thd_order_before(L,R) wsrep_service->wsrep_thd_order_before_func(L,R)
130 #define wsrep_handle_SR_rollback(B,V) wsrep_service->wsrep_handle_SR_rollback_func(B,V)
131 #define wsrep_thd_skip_locking(T) wsrep_service->wsrep_thd_skip_locking_func(T)
132 #define wsrep_get_sr_table_name() wsrep_service->wsrep_get_sr_table_name_func()
133 #define wsrep_get_debug() wsrep_service->wsrep_get_debug_func()
134 #define wsrep_commit_ordered(T) wsrep_service->wsrep_commit_ordered_func(T)
135 #define wsrep_thd_is_applying(T) wsrep_service->wsrep_thd_is_applying_func(T)
136 #define wsrep_OSU_method_get(T) wsrep_service->wsrep_OSU_method_get_func(T)
137 #define wsrep_thd_has_ignored_error(T) wsrep_service->wsrep_thd_has_ignored_error_func(T)
138 #define wsrep_thd_set_ignored_error(T,V) wsrep_service->wsrep_thd_set_ignored_error_func(T,V)
139 #define wsrep_thd_set_wsrep_aborter(T) wsrep_service->wsrep_thd_set_wsrep_aborter_func(T1, T2)
140 #define wsrep_report_bf_lock_wait(T,I) wsrep_service->wsrep_report_bf_lock_wait(T,I)
141 #define wsrep_thd_set_PA_unsafe(T) wsrep_service->wsrep_thd_set_PA_unsafe_func(T)
142 #else
143 
144 #define MYSQL_SERVICE_WSREP_STATIC_INCLUDED
145 extern ulong   wsrep_debug;
146 extern my_bool wsrep_log_conflicts;
147 extern my_bool wsrep_certify_nonPK;
148 extern my_bool wsrep_load_data_splitting;
149 extern my_bool wsrep_drupal_282555_workaround;
150 extern my_bool wsrep_recovery;
151 extern long wsrep_protocol_version;
152 
153 extern "C" bool wsrep_consistency_check(MYSQL_THD thd);
154 bool wsrep_prepare_key_for_innodb(MYSQL_THD thd, 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);
155 extern "C" const char *wsrep_thd_query(const MYSQL_THD thd);
156 extern "C" int wsrep_is_wsrep_xid(const void* xid);
157 extern "C" long long wsrep_xid_seqno(const struct xid_t* xid);
158 const unsigned char* wsrep_xid_uuid(const struct xid_t* xid);
159 extern "C" long long wsrep_thd_trx_seqno(const MYSQL_THD thd);
160 my_bool get_wsrep_recovery();
161 bool wsrep_thd_ignore_table(MYSQL_THD thd);
162 void wsrep_set_data_home_dir(const char *data_dir);
163 
164 /* from mysql wsrep-lib */
165 #include "my_global.h"
166 #include "my_pthread.h"
167 
168 /* Return true if wsrep is enabled for a thd. This means that
169    wsrep is enabled globally and the thd has wsrep on */
170 extern "C" my_bool wsrep_on(const MYSQL_THD thd);
171 /* Lock thd wsrep lock */
172 extern "C" void wsrep_thd_LOCK(const MYSQL_THD thd);
173 /* Unlock thd wsrep lock */
174 extern "C" void wsrep_thd_UNLOCK(const MYSQL_THD thd);
175 
176 extern "C" void wsrep_thd_kill_LOCK(const MYSQL_THD thd);
177 extern "C" void wsrep_thd_kill_UNLOCK(const MYSQL_THD thd);
178 
179 /* Return thd client state string */
180 extern "C" const char* wsrep_thd_client_state_str(const MYSQL_THD thd);
181 /* Return thd client mode string */
182 extern "C" const char* wsrep_thd_client_mode_str(const MYSQL_THD thd);
183 /* Return thd transaction state string */
184 extern "C" const char* wsrep_thd_transaction_state_str(const MYSQL_THD thd);
185 
186 /* Return current transaction id */
187 extern "C" query_id_t wsrep_thd_transaction_id(const MYSQL_THD thd);
188 /* Mark thd own transaction as aborted */
189 extern "C" void wsrep_thd_self_abort(MYSQL_THD thd);
190 /* Return true if thd is in replicating mode */
191 extern "C" my_bool wsrep_thd_is_local(const MYSQL_THD thd);
192 /* Return true if thd is in high priority mode */
193 /* todo: rename to is_high_priority() */
194 extern "C" my_bool wsrep_thd_is_applying(const MYSQL_THD thd);
195 /* set wsrep_aborter for the target THD */
196 extern "C" bool wsrep_thd_set_wsrep_aborter(MYSQL_THD bf_thd, MYSQL_THD victim_thd);
197 /* Return true if thd is in TOI mode */
198 extern "C" my_bool wsrep_thd_is_toi(const MYSQL_THD thd);
199 /* Return true if thd is in replicating TOI mode */
200 extern "C" my_bool wsrep_thd_is_local_toi(const MYSQL_THD thd);
201 /* Return true if thd is in RSU mode */
202 extern "C" my_bool wsrep_thd_is_in_rsu(const MYSQL_THD thd);
203 /* Return true if thd is in BF mode, either high_priority or TOI */
204 extern "C" my_bool wsrep_thd_is_BF(const MYSQL_THD thd, my_bool sync);
205 /* Return true if thd is streaming */
206 extern "C" my_bool wsrep_thd_is_SR(const MYSQL_THD thd);
207 extern "C" void wsrep_handle_SR_rollback(MYSQL_THD BF_thd, MYSQL_THD victim_thd);
208 /* Return thd retry counter */
209 extern "C" int wsrep_thd_retry_counter(const MYSQL_THD thd);
210 /* BF abort victim_thd */
211 extern "C" my_bool wsrep_thd_bf_abort(MYSQL_THD bf_thd,
212                                       MYSQL_THD victim_thd,
213                                       my_bool signal);
214 /* Return true if left thd is ordered before right thd */
215 extern "C" my_bool wsrep_thd_order_before(const MYSQL_THD left, const MYSQL_THD right);
216 /* Return true if thd should skip locking. This means that the thd
217    is operating on shared resource inside commit order critical section. */
218 extern "C" my_bool wsrep_thd_skip_locking(const MYSQL_THD thd);
219 /* Return true if thd is aborting */
220 extern "C" my_bool wsrep_thd_is_aborting(const MYSQL_THD thd);
221 
222 struct wsrep_key;
223 struct wsrep_key_array;
224 extern "C" int wsrep_thd_append_key(MYSQL_THD thd,
225                                     const struct wsrep_key* key,
226                                     int n_keys,
227                                     enum Wsrep_service_key_type);
228 
229 extern const char* wsrep_sr_table_name_full;
230 
231 extern "C" const char* wsrep_get_sr_table_name();
232 
233 extern "C" my_bool wsrep_get_debug();
234 
235 extern "C" void wsrep_commit_ordered(MYSQL_THD thd);
236 extern "C" my_bool wsrep_thd_is_applying(const MYSQL_THD thd);
237 extern "C" ulong wsrep_OSU_method_get(const MYSQL_THD thd);
238 extern "C" my_bool wsrep_thd_has_ignored_error(const MYSQL_THD thd);
239 extern "C" void wsrep_thd_set_ignored_error(MYSQL_THD thd, my_bool val);
240 extern "C" bool wsrep_thd_set_wsrep_aborter(MYSQL_THD bf_thd, MYSQL_THD victim_thd);
241 extern "C" void wsrep_report_bf_lock_wait(const THD *thd,
242                                           unsigned long long trx_id);
243 /* declare parallel applying unsafety for the THD */
244 extern "C" void wsrep_thd_set_PA_unsafe(MYSQL_THD thd);
245 #endif
246 #endif /* MYSQL_SERVICE_WSREP_INCLUDED */
247