1 /* Copyright (C) 2008-2019 Kentoku Shiba
2    Copyright (C) 2019 MariaDB corp
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 Street, Fifth Floor, Boston, MA 02110-1335 USA */
16 
17 #define SPIDER_LOCK_MODE_NO_LOCK             0
18 #define SPIDER_LOCK_MODE_SHARED              1
19 #define SPIDER_LOCK_MODE_EXCLUSIVE           2
20 
21 #define SPIDER_SIMPLE_NO_ACTION           0
22 #define SPIDER_SIMPLE_CONNECT             1
23 #define SPIDER_SIMPLE_DISCONNECT          2
24 #define SPIDER_SIMPLE_RECORDS             3
25 #ifdef HA_HAS_CHECKSUM_EXTENDED
26 #define SPIDER_SIMPLE_CHECKSUM_TABLE      4
27 #endif
28 
29 uchar *spider_conn_get_key(
30   SPIDER_CONN *conn,
31   size_t *length,
32   my_bool not_used __attribute__ ((unused))
33 );
34 
35 uchar *spider_ipport_conn_get_key(
36   SPIDER_IP_PORT_CONN *ip_port,
37   size_t *length,
38   my_bool not_used __attribute__ ((unused))
39 );
40 
41 int spider_reset_conn_setted_parameter(
42   SPIDER_CONN *conn,
43   THD *thd
44 );
45 
46 int spider_free_conn_alloc(
47   SPIDER_CONN *conn
48 );
49 
50 void spider_free_conn_from_trx(
51   SPIDER_TRX *trx,
52   SPIDER_CONN *conn,
53   bool another,
54   bool trx_free,
55   int *roop_count
56 );
57 
58 SPIDER_CONN *spider_create_conn(
59   SPIDER_SHARE *share,
60   ha_spider *spider,
61   int link_id,
62   int base_link_id,
63   uint conn_kind,
64   int *error_num
65 );
66 
67 SPIDER_CONN *spider_get_conn(
68   SPIDER_SHARE *share,
69   int link_idx,
70   char *conn_key,
71   SPIDER_TRX *trx,
72   ha_spider *spider,
73   bool another,
74   bool thd_chg,
75   uint conn_kind,
76   int *error_num
77 );
78 
79 int spider_free_conn(
80   SPIDER_CONN *conn
81 );
82 
83 int spider_check_and_get_casual_read_conn(
84   THD *thd,
85   ha_spider *spider,
86   int link_idx
87 );
88 
89 int spider_check_and_init_casual_read(
90   THD *thd,
91   ha_spider *spider,
92   int link_idx
93 );
94 
95 void spider_conn_queue_connect(
96   SPIDER_SHARE *share,
97   SPIDER_CONN *conn,
98   int link_idx
99 );
100 
101 void spider_conn_queue_connect_rewrite(
102   SPIDER_SHARE *share,
103   SPIDER_CONN *conn,
104   int link_idx
105 );
106 
107 void spider_conn_queue_ping(
108   ha_spider *spider,
109   SPIDER_CONN *conn,
110   int link_idx
111 );
112 
113 void spider_conn_queue_ping_rewrite(
114   ha_spider *spider,
115   SPIDER_CONN *conn,
116   int link_idx
117 );
118 
119 void spider_conn_queue_trx_isolation(
120   SPIDER_CONN *conn,
121   int trx_isolation
122 );
123 
124 void spider_conn_queue_semi_trx_isolation(
125   SPIDER_CONN *conn,
126   int trx_isolation
127 );
128 
129 void spider_conn_queue_autocommit(
130   SPIDER_CONN *conn,
131   bool autocommit
132 );
133 
134 void spider_conn_queue_sql_log_off(
135   SPIDER_CONN *conn,
136   bool sql_log_off
137 );
138 
139 void spider_conn_queue_wait_timeout(
140   SPIDER_CONN *conn,
141   int wait_timeout
142 );
143 
144 void spider_conn_queue_sql_mode(
145   SPIDER_CONN *conn,
146   sql_mode_t sql_mode
147 );
148 
149 void spider_conn_queue_time_zone(
150   SPIDER_CONN *conn,
151   Time_zone *time_zone
152 );
153 
154 void spider_conn_queue_UTC_time_zone(
155   SPIDER_CONN *conn
156 );
157 
158 void spider_conn_queue_start_transaction(
159   SPIDER_CONN *conn
160 );
161 
162 void spider_conn_queue_xa_start(
163   SPIDER_CONN *conn,
164   XID *xid
165 );
166 
167 void spider_conn_clear_queue(
168   SPIDER_CONN *conn
169 );
170 
171 void spider_conn_clear_queue_at_commit(
172   SPIDER_CONN *conn
173 );
174 
175 void spider_conn_set_timeout(
176   SPIDER_CONN *conn,
177   uint net_read_timeout,
178   uint net_write_timeout
179 );
180 
181 void spider_conn_set_timeout_from_share(
182   SPIDER_CONN *conn,
183   int link_idx,
184   THD *thd,
185   SPIDER_SHARE *share
186 );
187 
188 void spider_conn_set_timeout_from_direct_sql(
189   SPIDER_CONN *conn,
190   THD *thd,
191   SPIDER_DIRECT_SQL *direct_sql
192 );
193 
194 void spider_tree_insert(
195   SPIDER_CONN *top,
196   SPIDER_CONN *conn
197 );
198 
199 SPIDER_CONN *spider_tree_first(
200   SPIDER_CONN *top
201 );
202 
203 SPIDER_CONN *spider_tree_last(
204   SPIDER_CONN *top
205 );
206 
207 SPIDER_CONN *spider_tree_next(
208   SPIDER_CONN *current
209 );
210 
211 SPIDER_CONN *spider_tree_delete(
212   SPIDER_CONN *conn,
213   SPIDER_CONN *top
214 );
215 
216 #ifndef WITHOUT_SPIDER_BG_SEARCH
217 int spider_set_conn_bg_param(
218   ha_spider *spider
219 );
220 
221 int spider_create_conn_thread(
222   SPIDER_CONN *conn
223 );
224 
225 void spider_free_conn_thread(
226   SPIDER_CONN *conn
227 );
228 
229 void spider_bg_conn_wait(
230   SPIDER_CONN *conn
231 );
232 
233 void spider_bg_all_conn_wait(
234   ha_spider *spider
235 );
236 
237 int spider_bg_all_conn_pre_next(
238   ha_spider *spider,
239   int link_idx
240 );
241 
242 void spider_bg_conn_break(
243   SPIDER_CONN *conn,
244   ha_spider *spider
245 );
246 
247 void spider_bg_all_conn_break(
248   ha_spider *spider
249 );
250 
251 bool spider_bg_conn_get_job(
252   SPIDER_CONN *conn
253 );
254 
255 int spider_bg_conn_search(
256   ha_spider *spider,
257   int link_idx,
258   int first_link_idx,
259   bool first,
260   bool pre_next,
261   bool discard_result
262 );
263 
264 void spider_bg_conn_simple_action(
265   SPIDER_CONN *conn,
266   uint simple_action,
267   bool caller_wait,
268   void *target,
269   uint link_idx,
270   int *error_num
271 );
272 
273 void *spider_bg_conn_action(
274   void *arg
275 );
276 
277 int spider_create_sts_thread(
278   SPIDER_SHARE *share
279 );
280 
281 void spider_free_sts_thread(
282   SPIDER_SHARE *share
283 );
284 
285 void *spider_bg_sts_action(
286   void *arg
287 );
288 
289 int spider_create_crd_thread(
290   SPIDER_SHARE *share
291 );
292 
293 void spider_free_crd_thread(
294   SPIDER_SHARE *share
295 );
296 
297 void *spider_bg_crd_action(
298   void *arg
299 );
300 
301 int spider_create_mon_threads(
302   SPIDER_TRX *trx,
303   SPIDER_SHARE *share
304 );
305 
306 void spider_free_mon_threads(
307   SPIDER_SHARE *share
308 );
309 
310 void *spider_bg_mon_action(
311   void *arg
312 );
313 #endif
314 
315 int spider_conn_first_link_idx(
316   THD *thd,
317   long *link_statuses,
318   long *access_balances,
319   uint *conn_link_idx,
320   int link_count,
321   int link_status
322 );
323 
324 int spider_conn_next_link_idx(
325   THD *thd,
326   long *link_statuses,
327   long *access_balances,
328   uint *conn_link_idx,
329   int link_idx,
330   int link_count,
331   int link_status
332 );
333 
334 int spider_conn_link_idx_next(
335   long *link_statuses,
336   uint *conn_link_idx,
337   int link_idx,
338   int link_count,
339   int link_status
340 );
341 
342 int spider_conn_get_link_status(
343   long *link_statuses,
344   uint *conn_link_idx,
345   int link_idx
346 );
347 
348 int spider_conn_lock_mode(
349   ha_spider *spider
350 );
351 
352 bool spider_conn_check_recovery_link(
353   SPIDER_SHARE *share
354 );
355 
356 bool spider_conn_use_handler(
357   ha_spider *spider,
358   int lock_mode,
359   int link_idx
360 );
361 
362 bool spider_conn_need_open_handler(
363   ha_spider *spider,
364   uint idx,
365   int link_idx
366 );
367 
368 SPIDER_IP_PORT_CONN *spider_create_ipport_conn(SPIDER_CONN *conn);
369 SPIDER_CONN* spider_get_conn_from_idle_connection
370 (
371  SPIDER_SHARE *share,
372  int link_idx,
373  char *conn_key,
374  ha_spider *spider,
375  uint conn_kind,
376  int base_link_idx,
377  int *error_num
378  );
379 void spider_free_ipport_conn(void *info);
380