1/* Copyright (C) 2008-2017 Kentoku Shiba
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
15
16#define SPIDER_LOCK_MODE_NO_LOCK 0
17#define SPIDER_LOCK_MODE_SHARED 1
18#define SPIDER_LOCK_MODE_EXCLUSIVE 2
19
20#define SPIDER_BG_SIMPLE_NO_ACTION 0
21#define SPIDER_BG_SIMPLE_CONNECT 1
22#define SPIDER_BG_SIMPLE_DISCONNECT 2
23#define SPIDER_BG_SIMPLE_RECORDS 3
24
25uchar *spider_conn_get_key(
26 SPIDER_CONN *conn,
27 size_t *length,
28 my_bool not_used __attribute__ ((unused))
29);
30
31uchar *spider_ipport_conn_get_key(
32 SPIDER_IP_PORT_CONN *ip_port,
33 size_t *length,
34 my_bool not_used __attribute__ ((unused))
35);
36
37int spider_reset_conn_setted_parameter(
38 SPIDER_CONN *conn,
39 THD *thd
40);
41
42int spider_free_conn_alloc(
43 SPIDER_CONN *conn
44);
45
46void spider_free_conn_from_trx(
47 SPIDER_TRX *trx,
48 SPIDER_CONN *conn,
49 bool another,
50 bool trx_free,
51 int *roop_count
52);
53
54SPIDER_CONN *spider_create_conn(
55 SPIDER_SHARE *share,
56 ha_spider *spider,
57 int link_id,
58 int base_link_id,
59 uint conn_kind,
60 int *error_num
61);
62
63SPIDER_CONN *spider_get_conn(
64 SPIDER_SHARE *share,
65 int link_idx,
66 char *conn_key,
67 SPIDER_TRX *trx,
68 ha_spider *spider,
69 bool another,
70 bool thd_chg,
71 uint conn_kind,
72 int *error_num
73);
74
75int spider_free_conn(
76 SPIDER_CONN *conn
77);
78
79int spider_check_and_get_casual_read_conn(
80 THD *thd,
81 ha_spider *spider,
82 int link_idx
83);
84
85int spider_check_and_init_casual_read(
86 THD *thd,
87 ha_spider *spider,
88 int link_idx
89);
90
91void spider_conn_queue_connect(
92 SPIDER_SHARE *share,
93 SPIDER_CONN *conn,
94 int link_idx
95);
96
97void spider_conn_queue_connect_rewrite(
98 SPIDER_SHARE *share,
99 SPIDER_CONN *conn,
100 int link_idx
101);
102
103void spider_conn_queue_ping(
104 ha_spider *spider,
105 SPIDER_CONN *conn,
106 int link_idx
107);
108
109void spider_conn_queue_ping_rewrite(
110 ha_spider *spider,
111 SPIDER_CONN *conn,
112 int link_idx
113);
114
115void spider_conn_queue_trx_isolation(
116 SPIDER_CONN *conn,
117 int trx_isolation
118);
119
120void spider_conn_queue_semi_trx_isolation(
121 SPIDER_CONN *conn,
122 int trx_isolation
123);
124
125void spider_conn_queue_autocommit(
126 SPIDER_CONN *conn,
127 bool autocommit
128);
129
130void spider_conn_queue_sql_log_off(
131 SPIDER_CONN *conn,
132 bool sql_log_off
133);
134
135void spider_conn_queue_time_zone(
136 SPIDER_CONN *conn,
137 Time_zone *time_zone
138);
139
140void spider_conn_queue_start_transaction(
141 SPIDER_CONN *conn
142);
143
144void spider_conn_queue_xa_start(
145 SPIDER_CONN *conn,
146 XID *xid
147);
148
149void spider_conn_clear_queue(
150 SPIDER_CONN *conn
151);
152
153void spider_conn_clear_queue_at_commit(
154 SPIDER_CONN *conn
155);
156
157void spider_conn_set_timeout(
158 SPIDER_CONN *conn,
159 uint net_read_timeout,
160 uint net_write_timeout
161);
162
163void spider_conn_set_timeout_from_share(
164 SPIDER_CONN *conn,
165 int link_idx,
166 THD *thd,
167 SPIDER_SHARE *share
168);
169
170void spider_conn_set_timeout_from_direct_sql(
171 SPIDER_CONN *conn,
172 THD *thd,
173 SPIDER_DIRECT_SQL *direct_sql
174);
175
176void spider_tree_insert(
177 SPIDER_CONN *top,
178 SPIDER_CONN *conn
179);
180
181SPIDER_CONN *spider_tree_first(
182 SPIDER_CONN *top
183);
184
185SPIDER_CONN *spider_tree_last(
186 SPIDER_CONN *top
187);
188
189SPIDER_CONN *spider_tree_next(
190 SPIDER_CONN *current
191);
192
193SPIDER_CONN *spider_tree_delete(
194 SPIDER_CONN *conn,
195 SPIDER_CONN *top
196);
197
198#ifndef WITHOUT_SPIDER_BG_SEARCH
199int spider_set_conn_bg_param(
200 ha_spider *spider
201);
202
203int spider_create_conn_thread(
204 SPIDER_CONN *conn
205);
206
207void spider_free_conn_thread(
208 SPIDER_CONN *conn
209);
210
211void spider_bg_conn_wait(
212 SPIDER_CONN *conn
213);
214
215void spider_bg_all_conn_wait(
216 ha_spider *spider
217);
218
219int spider_bg_all_conn_pre_next(
220 ha_spider *spider,
221 int link_idx
222);
223
224void spider_bg_conn_break(
225 SPIDER_CONN *conn,
226 ha_spider *spider
227);
228
229void spider_bg_all_conn_break(
230 ha_spider *spider
231);
232
233bool spider_bg_conn_get_job(
234 SPIDER_CONN *conn
235);
236
237int spider_bg_conn_search(
238 ha_spider *spider,
239 int link_idx,
240 int first_link_idx,
241 bool first,
242 bool pre_next,
243 bool discard_result
244);
245
246void spider_bg_conn_simple_action(
247 SPIDER_CONN *conn,
248 uint simple_action,
249 bool caller_wait,
250 void *target,
251 uint link_idx,
252 int *error_num
253);
254
255void *spider_bg_conn_action(
256 void *arg
257);
258
259int spider_create_sts_thread(
260 SPIDER_SHARE *share
261);
262
263void spider_free_sts_thread(
264 SPIDER_SHARE *share
265);
266
267void *spider_bg_sts_action(
268 void *arg
269);
270
271int spider_create_crd_thread(
272 SPIDER_SHARE *share
273);
274
275void spider_free_crd_thread(
276 SPIDER_SHARE *share
277);
278
279void *spider_bg_crd_action(
280 void *arg
281);
282
283int spider_create_mon_threads(
284 SPIDER_TRX *trx,
285 SPIDER_SHARE *share
286);
287
288void spider_free_mon_threads(
289 SPIDER_SHARE *share
290);
291
292void *spider_bg_mon_action(
293 void *arg
294);
295#endif
296
297int spider_conn_first_link_idx(
298 THD *thd,
299 long *link_statuses,
300 long *access_balances,
301 uint *conn_link_idx,
302 int link_count,
303 int link_status
304);
305
306int spider_conn_next_link_idx(
307 THD *thd,
308 long *link_statuses,
309 long *access_balances,
310 uint *conn_link_idx,
311 int link_idx,
312 int link_count,
313 int link_status
314);
315
316int spider_conn_link_idx_next(
317 long *link_statuses,
318 uint *conn_link_idx,
319 int link_idx,
320 int link_count,
321 int link_status
322);
323
324int spider_conn_get_link_status(
325 long *link_statuses,
326 uint *conn_link_idx,
327 int link_idx
328);
329
330int spider_conn_lock_mode(
331 ha_spider *spider
332);
333
334bool spider_conn_check_recovery_link(
335 SPIDER_SHARE *share
336);
337
338bool spider_conn_use_handler(
339 ha_spider *spider,
340 int lock_mode,
341 int link_idx
342);
343
344bool spider_conn_need_open_handler(
345 ha_spider *spider,
346 uint idx,
347 int link_idx
348);
349
350SPIDER_IP_PORT_CONN *spider_create_ipport_conn(SPIDER_CONN *conn);
351SPIDER_CONN* spider_get_conn_from_idle_connection
352(
353 SPIDER_SHARE *share,
354 int link_idx,
355 char *conn_key,
356 ha_spider *spider,
357 uint conn_kind,
358 int base_link_idx,
359 int *error_num
360 );
361void spider_free_ipport_conn(void *info);
362