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_DETAIL_VERSION "3.3.13"
17#define SPIDER_HEX_VERSION 0x0303
18
19#if MYSQL_VERSION_ID < 50500
20#define spider_my_free(A,B) my_free(A,B)
21#else
22#define spider_my_free(A,B) my_free(A)
23#ifdef pthread_mutex_t
24#undef pthread_mutex_t
25#endif
26#define pthread_mutex_t mysql_mutex_t
27#ifdef pthread_mutex_lock
28#undef pthread_mutex_lock
29#endif
30#define pthread_mutex_lock mysql_mutex_lock
31#ifdef pthread_mutex_trylock
32#undef pthread_mutex_trylock
33#endif
34#define pthread_mutex_trylock mysql_mutex_trylock
35#ifdef pthread_mutex_unlock
36#undef pthread_mutex_unlock
37#endif
38#define pthread_mutex_unlock mysql_mutex_unlock
39#ifdef pthread_mutex_destroy
40#undef pthread_mutex_destroy
41#endif
42#define pthread_mutex_destroy mysql_mutex_destroy
43#ifdef pthread_cond_t
44#undef pthread_cond_t
45#endif
46#define pthread_cond_t mysql_cond_t
47#ifdef pthread_cond_wait
48#undef pthread_cond_wait
49#endif
50#define pthread_cond_wait mysql_cond_wait
51#ifdef pthread_cond_timedwait
52#undef pthread_cond_timedwait
53#endif
54#define pthread_cond_timedwait mysql_cond_timedwait
55#ifdef pthread_cond_signal
56#undef pthread_cond_signal
57#endif
58#define pthread_cond_signal mysql_cond_signal
59#ifdef pthread_cond_broadcast
60#undef pthread_cond_broadcast
61#endif
62#define pthread_cond_broadcast mysql_cond_broadcast
63#ifdef pthread_cond_destroy
64#undef pthread_cond_destroy
65#endif
66#define pthread_cond_destroy mysql_cond_destroy
67#define my_sprintf(A,B) sprintf B
68#endif
69
70
71#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100004
72#define spider_stmt_da_message(A) thd_get_error_message(A)
73#define spider_stmt_da_sql_errno(A) thd_get_error_number(A)
74#define spider_user_defined_key_parts(A) (A)->user_defined_key_parts
75#define spider_join_table_count(A) (A)->table_count
76#define SPIDER_CAN_BG_UPDATE (1LL << 39)
77#define SPIDER_ALTER_PARTITION_ADD ALTER_PARTITION_ADD
78#define SPIDER_ALTER_PARTITION_DROP ALTER_PARTITION_DROP
79#define SPIDER_ALTER_PARTITION_COALESCE ALTER_PARTITION_COALESCE
80#define SPIDER_ALTER_PARTITION_REORGANIZE ALTER_PARTITION_REORGANIZE
81#define SPIDER_ALTER_PARTITION_TABLE_REORG ALTER_PARTITION_TABLE_REORG
82#define SPIDER_ALTER_PARTITION_REBUILD ALTER_PARTITION_REBUILD
83#define SPIDER_WARN_LEVEL_WARN Sql_condition::WARN_LEVEL_WARN
84#define SPIDER_WARN_LEVEL_NOTE Sql_condition::WARN_LEVEL_NOTE
85#define SPIDER_THD_KILL_CONNECTION KILL_CONNECTION
86#else
87#if MYSQL_VERSION_ID < 50500
88#define spider_stmt_da_message(A) (A)->main_da.message()
89#define spider_stmt_da_sql_errno(A) (A)->main_da.sql_errno()
90#else
91#if MYSQL_VERSION_ID < 50600
92#define spider_stmt_da_message(A) (A)->stmt_da->message()
93#define spider_stmt_da_sql_errno(A) (A)->stmt_da->sql_errno()
94#else
95#define spider_stmt_da_message(A) (A)->get_stmt_da()->message()
96#define spider_stmt_da_sql_errno(A) (A)->get_stmt_da()->sql_errno()
97#endif
98#endif
99#define spider_user_defined_key_parts(A) (A)->key_parts
100#define spider_join_table_count(A) (A)->tables
101#define SPIDER_ALTER_PARTITION_ADD ALTER_PARTITION_ADD
102#define SPIDER_ALTER_PARTITION_DROP ALTER_PARTITION_DROP
103#define SPIDER_ALTER_PARTITION_COALESCE ALTER_PARTITION_COALESCE
104#define SPIDER_ALTER_PARTITION_REORGANIZE ALTER_PARTITION_REORGANIZE
105#define SPIDER_ALTER_PARTITION_TABLE_REORG ALTER_PARTITION_TABLE_REORG
106#define SPIDER_ALTER_PARTITION_REBUILD ALTER_PARTITION_REBUILD
107#define SPIDER_WARN_LEVEL_WARN MYSQL_ERROR::WARN_LEVEL_WARN
108#define SPIDER_WARN_LEVEL_NOTE MYSQL_ERROR::WARN_LEVEL_NOTE
109#define SPIDER_THD_KILL_CONNECTION THD::KILL_CONNECTION
110#endif
111
112#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100005
113#define SPIDER_HAS_EXPLAIN_QUERY
114#endif
115
116#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100009
117#define SPIDER_TEST(A) MY_TEST(A)
118#else
119#define SPIDER_TEST(A) test(A)
120#endif
121
122#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100100
123#define SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR
124#define SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON
125#define SPIDER_XID_USES_xid_cache_iterate
126#else
127#define SPIDER_XID_STATE_HAS_in_thd
128#endif
129
130#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100108
131#define SPIDER_Item_args_arg_count_IS_PROTECTED
132#endif
133
134#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100112
135#define SPIDER_Item_func_conv_charset_conv_charset collation.collation
136#else
137#define SPIDER_Item_func_conv_charset_conv_charset conv_charset
138#endif
139
140#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100200
141#define SPIDER_WITHOUT_HA_STATISTIC_INCREMENT
142#define SPIDER_init_read_record(A,B,C,D,E,F,G,H) init_read_record(A,B,C,D,E,F,G,H)
143#define SPIDER_HAS_NEXT_THREAD_ID
144#define SPIDER_new_THD(A) (new THD(A))
145#define SPIDER_order_direction_is_asc(A) (A->direction == ORDER::ORDER_ASC)
146#else
147#define SPIDER_init_read_record(A,B,C,D,E,F,G,H) init_read_record(A,B,C,D,F,G,H)
148#define SPIDER_new_THD(A) (new THD())
149#define SPIDER_order_direction_is_asc(A) (A->asc)
150#endif
151
152#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100201
153#define SPIDER_HAS_MY_CHARLEN
154#define SPIDER_find_temporary_table(A,B) A->find_temporary_table(B)
155#else
156#define SPIDER_find_temporary_table(A,B) find_temporary_table(A,B)
157#endif
158
159#if defined(MARIADB_BASE_VERSION)
160#if MYSQL_VERSION_ID >= 100209
161#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(A,B,C,E,F,G)
162#elif MYSQL_VERSION_ID >= 100200
163#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(A,B,C,D,E,F,G,H)
164#elif MYSQL_VERSION_ID >= 100007
165#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(B,C,D,E,F,G,H)
166#else
167#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(B,C,D,E,F,G)
168#endif
169#else
170#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H)
171#endif
172
173#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100209
174#define SPIDER_create_partition_name(A,B,C,D,E,F) create_partition_name(A,B,C,D,E,F)
175#define SPIDER_create_subpartition_name(A,B,C,D,E,F) create_subpartition_name(A,B,C,D,E,F)
176#define SPIDER_free_part_syntax(A,B)
177#else
178#define SPIDER_create_partition_name(A,B,C,D,E,F) create_partition_name(A,C,D,E,F)
179#define SPIDER_create_subpartition_name(A,B,C,D,E,F) create_subpartition_name(A,C,D,E,F)
180#define SPIDER_free_part_syntax(A,B) spider_my_free(A,B)
181#endif
182
183#if MYSQL_VERSION_ID >= 50500
184#define SPIDER_HAS_HASH_VALUE_TYPE
185#endif
186
187#define spider_bitmap_size(A) ((A + 7) / 8)
188#define spider_set_bit(BITMAP, BIT) \
189 ((BITMAP)[(BIT) / 8] |= (1 << ((BIT) & 7)))
190#define spider_clear_bit(BITMAP, BIT) \
191 ((BITMAP)[(BIT) / 8] &= ~(1 << ((BIT) & 7)))
192#define spider_bit_is_set(BITMAP, BIT) \
193 (uint) ((BITMAP)[(BIT) / 8] & (1 << ((BIT) & 7)))
194
195#define SPIDER_LINK_STATUS_NO_CHANGE 0
196#define SPIDER_LINK_STATUS_OK 1
197#define SPIDER_LINK_STATUS_RECOVERY 2
198#define SPIDER_LINK_STATUS_NG 3
199
200#define SPIDER_LINK_MON_OK 0
201#define SPIDER_LINK_MON_NG -1
202#define SPIDER_LINK_MON_DRAW_FEW_MON 1
203#define SPIDER_LINK_MON_DRAW 2
204
205#define SPIDER_TMP_SHARE_CHAR_PTR_COUNT 20
206#define SPIDER_TMP_SHARE_UINT_COUNT 17
207#define SPIDER_TMP_SHARE_LONG_COUNT 19
208#define SPIDER_TMP_SHARE_LONGLONG_COUNT 3
209
210#define SPIDER_MEM_CALC_LIST_NUM 257
211#define SPIDER_CONN_META_BUF_LEN 64
212
213#define SPIDER_BACKUP_DASTATUS \
214 bool da_status; if (thd) da_status = thd->is_error(); else da_status = FALSE;
215#define SPIDER_RESTORE_DASTATUS \
216 if (!da_status && thd->is_error()) thd->clear_error();
217#define SPIDER_CONN_RESTORE_DASTATUS \
218 if (thd && conn->error_mode) {SPIDER_RESTORE_DASTATUS;}
219#define SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM \
220 if (thd && conn->error_mode) {SPIDER_RESTORE_DASTATUS; error_num = 0;}
221#define SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_TMP_ERROR_NUM \
222 if (thd && conn->error_mode) {SPIDER_RESTORE_DASTATUS; tmp_error_num = 0;}
223
224#define SPIDER_SET_FILE_POS(A) \
225 {(A)->thd = current_thd; (A)->func_name = __func__; (A)->file_name = __FILE__; (A)->line_no = __LINE__;}
226#define SPIDER_CLEAR_FILE_POS(A) \
227 {DBUG_PRINT("info", ("spider thd=%p func_name=%s file_name=%s line_no=%lu", (A)->thd, (A)->func_name ? (A)->func_name : "NULL", (A)->file_name ? (A)->file_name : "NULL", (A)->line_no)); (A)->thd = NULL; (A)->func_name = NULL; (A)->file_name = NULL; (A)->line_no = 0;}
228
229class ha_spider;
230typedef struct st_spider_share SPIDER_SHARE;
231typedef struct st_spider_table_mon_list SPIDER_TABLE_MON_LIST;
232typedef struct st_spider_ip_port_conn SPIDER_IP_PORT_CONN;
233
234#ifndef WITHOUT_SPIDER_BG_SEARCH
235typedef struct st_spider_thread
236{
237 uint thread_idx;
238 THD *thd;
239 volatile bool killed;
240 volatile bool thd_wait;
241 volatile bool first_free_wait;
242 pthread_t thread;
243 pthread_cond_t cond;
244 pthread_mutex_t mutex;
245 pthread_cond_t sync_cond;
246 volatile SPIDER_SHARE *queue_first;
247 volatile SPIDER_SHARE *queue_last;
248} SPIDER_THREAD;
249#endif
250
251typedef struct st_spider_file_pos
252{
253 THD *thd;
254 const char *func_name;
255 const char *file_name;
256 ulong line_no;
257} SPIDER_FILE_POS;
258
259typedef struct st_spider_link_for_hash
260{
261 ha_spider *spider;
262 int link_idx;
263 spider_string *db_table_str;
264#ifdef SPIDER_HAS_HASH_VALUE_TYPE
265 my_hash_value_type db_table_str_hash_value;
266#endif
267} SPIDER_LINK_FOR_HASH;
268
269/* alter table */
270typedef struct st_spider_alter_table
271{
272 bool now_create;
273 char *table_name;
274 uint table_name_length;
275 char *tmp_char;
276#ifdef SPIDER_HAS_HASH_VALUE_TYPE
277 my_hash_value_type table_name_hash_value;
278#endif
279 longlong tmp_priority;
280 uint link_count;
281 uint all_link_count;
282
283 char **tmp_server_names;
284 char **tmp_tgt_table_names;
285 char **tmp_tgt_dbs;
286 char **tmp_tgt_hosts;
287 char **tmp_tgt_usernames;
288 char **tmp_tgt_passwords;
289 char **tmp_tgt_sockets;
290 char **tmp_tgt_wrappers;
291 char **tmp_tgt_ssl_cas;
292 char **tmp_tgt_ssl_capaths;
293 char **tmp_tgt_ssl_certs;
294 char **tmp_tgt_ssl_ciphers;
295 char **tmp_tgt_ssl_keys;
296 char **tmp_tgt_default_files;
297 char **tmp_tgt_default_groups;
298 char **tmp_static_link_ids;
299 long *tmp_tgt_ports;
300 long *tmp_tgt_ssl_vscs;
301 long *tmp_monitoring_binlog_pos_at_failing;
302 long *tmp_link_statuses;
303
304 uint *tmp_server_names_lengths;
305 uint *tmp_tgt_table_names_lengths;
306 uint *tmp_tgt_dbs_lengths;
307 uint *tmp_tgt_hosts_lengths;
308 uint *tmp_tgt_usernames_lengths;
309 uint *tmp_tgt_passwords_lengths;
310 uint *tmp_tgt_sockets_lengths;
311 uint *tmp_tgt_wrappers_lengths;
312 uint *tmp_tgt_ssl_cas_lengths;
313 uint *tmp_tgt_ssl_capaths_lengths;
314 uint *tmp_tgt_ssl_certs_lengths;
315 uint *tmp_tgt_ssl_ciphers_lengths;
316 uint *tmp_tgt_ssl_keys_lengths;
317 uint *tmp_tgt_default_files_lengths;
318 uint *tmp_tgt_default_groups_lengths;
319 uint *tmp_static_link_ids_lengths;
320
321 uint tmp_server_names_charlen;
322 uint tmp_tgt_table_names_charlen;
323 uint tmp_tgt_dbs_charlen;
324 uint tmp_tgt_hosts_charlen;
325 uint tmp_tgt_usernames_charlen;
326 uint tmp_tgt_passwords_charlen;
327 uint tmp_tgt_sockets_charlen;
328 uint tmp_tgt_wrappers_charlen;
329 uint tmp_tgt_ssl_cas_charlen;
330 uint tmp_tgt_ssl_capaths_charlen;
331 uint tmp_tgt_ssl_certs_charlen;
332 uint tmp_tgt_ssl_ciphers_charlen;
333 uint tmp_tgt_ssl_keys_charlen;
334 uint tmp_tgt_default_files_charlen;
335 uint tmp_tgt_default_groups_charlen;
336 uint tmp_static_link_ids_charlen;
337
338 uint tmp_server_names_length;
339 uint tmp_tgt_table_names_length;
340 uint tmp_tgt_dbs_length;
341 uint tmp_tgt_hosts_length;
342 uint tmp_tgt_usernames_length;
343 uint tmp_tgt_passwords_length;
344 uint tmp_tgt_sockets_length;
345 uint tmp_tgt_wrappers_length;
346 uint tmp_tgt_ssl_cas_length;
347 uint tmp_tgt_ssl_capaths_length;
348 uint tmp_tgt_ssl_certs_length;
349 uint tmp_tgt_ssl_ciphers_length;
350 uint tmp_tgt_ssl_keys_length;
351 uint tmp_tgt_default_files_length;
352 uint tmp_tgt_default_groups_length;
353 uint tmp_static_link_ids_length;
354 uint tmp_tgt_ports_length;
355 uint tmp_tgt_ssl_vscs_length;
356 uint tmp_monitoring_binlog_pos_at_failing_length;
357 uint tmp_link_statuses_length;
358} SPIDER_ALTER_TABLE;
359
360/* database connection */
361typedef struct st_spider_conn
362{
363 uint conn_kind;
364 char *conn_key;
365 uint conn_key_length;
366#ifdef SPIDER_HAS_HASH_VALUE_TYPE
367 my_hash_value_type conn_key_hash_value;
368#endif
369 int link_idx;
370 spider_db_conn *db_conn;
371#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
372 query_id_t hsc_query_id;
373 ulonglong hs_pre_age;
374 ulonglong hs_age;
375#endif
376 uint opened_handlers;
377 ulonglong conn_id;
378 ulonglong connection_id;
379 query_id_t casual_read_query_id;
380 uint casual_read_current_id;
381 st_spider_conn *casual_read_base_conn;
382 pthread_mutex_t mta_conn_mutex;
383 volatile bool mta_conn_mutex_lock_already;
384 volatile bool mta_conn_mutex_unlock_later;
385 SPIDER_FILE_POS mta_conn_mutex_file_pos;
386 uint join_trx;
387 int trx_isolation;
388 bool semi_trx_isolation_chk;
389 int semi_trx_isolation;
390 bool semi_trx_chk;
391 bool semi_trx;
392 bool trx_start;
393 bool table_locked;
394 int table_lock;
395 bool disable_xa;
396 bool disable_reconnect;
397 int autocommit;
398 int sql_log_off;
399 THD *thd;
400 void *another_ha_first;
401 void *another_ha_last;
402 st_spider_conn *p_small;
403 st_spider_conn *p_big;
404 st_spider_conn *c_small;
405 st_spider_conn *c_big;
406 longlong priority;
407 bool server_lost;
408 bool ignore_dup_key;
409 char *error_str;
410 int error_length;
411 time_t ping_time;
412 CHARSET_INFO *access_charset;
413 Time_zone *time_zone;
414 uint connect_timeout;
415 uint net_read_timeout;
416 uint net_write_timeout;
417 int error_mode;
418 spider_string default_database;
419
420 char *tgt_host;
421 char *tgt_username;
422 char *tgt_password;
423 char *tgt_socket;
424 char *tgt_wrapper;
425 char *tgt_ssl_ca;
426 char *tgt_ssl_capath;
427 char *tgt_ssl_cert;
428 char *tgt_ssl_cipher;
429 char *tgt_ssl_key;
430 char *tgt_default_file;
431 char *tgt_default_group;
432 long tgt_port;
433 long tgt_ssl_vsc;
434#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
435 char *hs_sock;
436 long hs_port;
437#endif
438
439 uint tgt_host_length;
440 uint tgt_username_length;
441 uint tgt_password_length;
442 uint tgt_socket_length;
443 uint tgt_wrapper_length;
444 uint tgt_ssl_ca_length;
445 uint tgt_ssl_capath_length;
446 uint tgt_ssl_cert_length;
447 uint tgt_ssl_cipher_length;
448 uint tgt_ssl_key_length;
449 uint tgt_default_file_length;
450 uint tgt_default_group_length;
451#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
452 uint hs_sock_length;
453#endif
454 uint dbton_id;
455
456#ifndef WITHOUT_SPIDER_BG_SEARCH
457 volatile
458#endif
459 void *quick_target;
460#ifndef WITHOUT_SPIDER_BG_SEARCH
461 volatile bool bg_init;
462 volatile bool bg_break;
463 volatile bool bg_kill;
464 volatile bool bg_caller_wait;
465 volatile bool bg_caller_sync_wait;
466 volatile bool bg_search;
467 volatile bool bg_discard_result;
468 volatile bool bg_direct_sql;
469 volatile bool bg_exec_sql;
470 volatile bool bg_get_job_stack;
471 volatile bool bg_get_job_stack_off;
472 volatile uint bg_simple_action;
473 THD *bg_thd;
474 pthread_t bg_thread;
475 pthread_cond_t bg_conn_cond;
476 pthread_mutex_t bg_conn_mutex;
477 pthread_cond_t bg_conn_sync_cond;
478 pthread_mutex_t bg_conn_sync_mutex;
479 pthread_mutex_t bg_conn_chain_mutex;
480 pthread_mutex_t *bg_conn_chain_mutex_ptr;
481 volatile void *bg_target;
482 volatile int *bg_error_num;
483 volatile ulong bg_sql_type;
484 pthread_mutex_t bg_job_stack_mutex;
485 DYNAMIC_ARRAY bg_job_stack;
486 uint bg_job_stack_id;
487 const char *bg_job_stack_func_name;
488 const char *bg_job_stack_file_name;
489 ulong bg_job_stack_line_no;
490 uint bg_job_stack_cur_pos;
491#endif
492#ifndef WITHOUT_SPIDER_BG_SEARCH
493 volatile
494#endif
495 int *need_mon;
496 int *conn_need_mon;
497
498 bool use_for_active_standby;
499 bool in_before_query;
500
501 bool queued_connect;
502 bool queued_ping;
503 bool queued_trx_isolation;
504 bool queued_semi_trx_isolation;
505 bool queued_autocommit;
506 bool queued_sql_log_off;
507 bool queued_time_zone;
508 bool queued_trx_start;
509 bool queued_xa_start;
510 bool queued_net_timeout;
511 SPIDER_SHARE *queued_connect_share;
512 int queued_connect_link_idx;
513 ha_spider *queued_ping_spider;
514 int queued_ping_link_idx;
515 int queued_trx_isolation_val;
516 int queued_semi_trx_isolation_val;
517 bool queued_autocommit_val;
518 bool queued_sql_log_off_val;
519 Time_zone *queued_time_zone_val;
520 XID *queued_xa_start_xid;
521
522#ifdef HA_CAN_BULK_ACCESS
523 uint bulk_access_requests;
524 uint bulk_access_sended;
525 int bulk_access_error_num;
526 st_spider_conn *bulk_access_next;
527#endif
528
529 bool disable_connect_retry; /* TRUE if it is unnecessary to
530 retry to connect after a
531 connection error */
532 bool connect_error_with_message;
533 char connect_error_msg[MYSQL_ERRMSG_SIZE];
534 int connect_error;
535 THD *connect_error_thd;
536 query_id_t connect_error_query_id;
537 time_t connect_error_time;
538
539#ifdef SPIDER_HAS_GROUP_BY_HANDLER
540 SPIDER_CONN_HOLDER *conn_holder_for_direct_join;
541 SPIDER_LINK_IDX_CHAIN *link_idx_chain;
542#endif
543 SPIDER_IP_PORT_CONN *ip_port_conn;
544} SPIDER_CONN;
545
546typedef struct st_spider_lgtm_tblhnd_share
547{
548 char *table_name;
549 uint table_name_length;
550#ifdef SPIDER_HAS_HASH_VALUE_TYPE
551 my_hash_value_type table_path_hash_value;
552#endif
553 pthread_mutex_t auto_increment_mutex;
554 volatile bool auto_increment_init;
555 volatile ulonglong auto_increment_lclval;
556 ulonglong auto_increment_value;
557} SPIDER_LGTM_TBLHND_SHARE;
558
559#ifdef WITH_PARTITION_STORAGE_ENGINE
560typedef struct st_spider_patition_handler_share
561{
562 uint use_count;
563 TABLE *table;
564#ifdef SPIDER_HAS_HASH_VALUE_TYPE
565 my_hash_value_type table_hash_value;
566#endif
567 void *creator;
568 void **handlers;
569 uchar *searched_bitmap;
570 uchar *ft_discard_bitmap;
571 uchar *idx_read_bitmap;
572 uchar *idx_write_bitmap;
573 uchar *rnd_read_bitmap;
574 uchar *rnd_write_bitmap;
575 bool between_flg;
576 bool idx_bitmap_is_set;
577 bool rnd_bitmap_is_set;
578 query_id_t parallel_search_query_id;
579} SPIDER_PARTITION_HANDLER_SHARE;
580
581typedef struct st_spider_patition_share
582{
583 char *table_name;
584 uint table_name_length;
585#ifdef SPIDER_HAS_HASH_VALUE_TYPE
586 my_hash_value_type table_path_hash_value;
587#endif
588 uint use_count;
589 pthread_mutex_t sts_mutex;
590 pthread_mutex_t crd_mutex;
591 pthread_mutex_t pt_handler_mutex;
592 HASH pt_handler_hash;
593 uint pt_handler_hash_id;
594 const char *pt_handler_hash_func_name;
595 const char *pt_handler_hash_file_name;
596 ulong pt_handler_hash_line_no;
597
598 volatile bool sts_init;
599 volatile bool crd_init;
600 volatile time_t sts_get_time;
601 volatile time_t crd_get_time;
602 ulonglong data_file_length;
603 ulonglong max_data_file_length;
604 ulonglong index_file_length;
605 ulonglong auto_increment_value;
606 ha_rows records;
607 ulong mean_rec_length;
608 time_t check_time;
609 time_t create_time;
610 time_t update_time;
611
612 longlong *cardinality;
613/*
614 volatile SPIDER_PARTITION_HANDLER_SHARE *partition_handler_share;
615*/
616} SPIDER_PARTITION_SHARE;
617#endif
618
619typedef struct st_spider_transaction
620{
621 bool trx_start;
622 bool trx_xa;
623 bool trx_consistent_snapshot;
624 bool trx_xa_prepared;
625
626 bool use_consistent_snapshot;
627 bool internal_xa;
628 uint internal_xa_snapshot;
629
630 query_id_t query_id;
631 bool tmp_flg;
632 bool registed_allocated_thds;
633
634 bool updated_in_this_trx;
635
636 THD *thd;
637#ifdef SPIDER_HAS_HASH_VALUE_TYPE
638 my_hash_value_type thd_hash_value;
639#endif
640 XID xid;
641 HASH trx_conn_hash;
642 uint trx_conn_hash_id;
643 const char *trx_conn_hash_func_name;
644 const char *trx_conn_hash_file_name;
645 ulong trx_conn_hash_line_no;
646 HASH trx_another_conn_hash;
647 uint trx_another_conn_hash_id;
648 const char *trx_another_conn_hash_func_name;
649 const char *trx_another_conn_hash_file_name;
650 ulong trx_another_conn_hash_line_no;
651#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
652 HASH trx_hs_r_conn_hash;
653 uint trx_hs_r_conn_hash_id;
654 const char *trx_hs_r_conn_hash_func_name;
655 const char *trx_hs_r_conn_hash_file_name;
656 ulong trx_hs_r_conn_hash_line_no;
657 HASH trx_hs_w_conn_hash;
658 uint trx_hs_w_conn_hash_id;
659 const char *trx_hs_w_conn_hash_func_name;
660 const char *trx_hs_w_conn_hash_file_name;
661 ulong trx_hs_w_conn_hash_line_no;
662#endif
663#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
664 HASH trx_direct_hs_r_conn_hash;
665 uint trx_direct_hs_r_conn_hash_id;
666 const char *trx_direct_hs_r_conn_hash_func_name;
667 const char *trx_direct_hs_r_conn_hash_file_name;
668 ulong trx_direct_hs_r_conn_hash_line_no;
669 HASH trx_direct_hs_w_conn_hash;
670 uint trx_direct_hs_w_conn_hash_id;
671 const char *trx_direct_hs_w_conn_hash_func_name;
672 const char *trx_direct_hs_w_conn_hash_file_name;
673 ulong trx_direct_hs_w_conn_hash_line_no;
674#endif
675 HASH trx_alter_table_hash;
676 uint trx_alter_table_hash_id;
677 const char *trx_alter_table_hash_func_name;
678 const char *trx_alter_table_hash_file_name;
679 ulong trx_alter_table_hash_line_no;
680 HASH trx_ha_hash;
681 uint trx_ha_hash_id;
682 const char *trx_ha_hash_func_name;
683 const char *trx_ha_hash_file_name;
684 ulong trx_ha_hash_line_no;
685 uint trx_ha_reuse_count;
686 XID_STATE internal_xid_state;
687 SPIDER_CONN *join_trx_top;
688 ulonglong spider_thread_id;
689 ulonglong trx_conn_adjustment;
690#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
691 ulonglong trx_hs_r_conn_adjustment;
692 ulonglong trx_hs_w_conn_adjustment;
693#endif
694 uint locked_connections;
695
696 ulonglong direct_update_count;
697 ulonglong direct_delete_count;
698 ulonglong direct_order_limit_count;
699 ulonglong direct_aggregate_count;
700 ulonglong parallel_search_count;
701#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
702 ulonglong hs_result_free_count;
703#endif
704
705#ifdef HA_CAN_BULK_ACCESS
706 SPIDER_CONN *bulk_access_conn_first;
707 SPIDER_CONN *bulk_access_conn_last;
708#endif
709
710 pthread_mutex_t *udf_table_mutexes;
711 CHARSET_INFO *udf_access_charset;
712 spider_string *udf_set_names;
713
714 time_t mem_calc_merge_time;
715 const char *alloc_func_name[SPIDER_MEM_CALC_LIST_NUM];
716 const char *alloc_file_name[SPIDER_MEM_CALC_LIST_NUM];
717 ulong alloc_line_no[SPIDER_MEM_CALC_LIST_NUM];
718 ulonglong total_alloc_mem[SPIDER_MEM_CALC_LIST_NUM];
719 longlong current_alloc_mem[SPIDER_MEM_CALC_LIST_NUM];
720 ulonglong alloc_mem_count[SPIDER_MEM_CALC_LIST_NUM];
721 ulonglong free_mem_count[SPIDER_MEM_CALC_LIST_NUM];
722 ulonglong total_alloc_mem_buffer[SPIDER_MEM_CALC_LIST_NUM];
723 longlong current_alloc_mem_buffer[SPIDER_MEM_CALC_LIST_NUM];
724 ulonglong alloc_mem_count_buffer[SPIDER_MEM_CALC_LIST_NUM];
725 ulonglong free_mem_count_buffer[SPIDER_MEM_CALC_LIST_NUM];
726
727 MEM_ROOT mem_root;
728
729 /* for transaction level query */
730 SPIDER_SHARE *tmp_share;
731 char *tmp_connect_info[SPIDER_TMP_SHARE_CHAR_PTR_COUNT];
732 uint tmp_connect_info_length[SPIDER_TMP_SHARE_UINT_COUNT];
733 long tmp_long[SPIDER_TMP_SHARE_LONG_COUNT];
734 longlong tmp_longlong[SPIDER_TMP_SHARE_LONGLONG_COUNT];
735 ha_spider *tmp_spider;
736 int tmp_need_mon;
737 spider_db_handler *tmp_dbton_handler[SPIDER_DBTON_SIZE];
738} SPIDER_TRX;
739
740typedef struct st_spider_share
741{
742 char *table_name;
743 uint table_name_length;
744 uint use_count;
745 uint link_count;
746 uint all_link_count;
747 uint link_bitmap_size;
748 pthread_mutex_t mutex;
749 pthread_mutex_t sts_mutex;
750 pthread_mutex_t crd_mutex;
751/*
752 pthread_mutex_t auto_increment_mutex;
753*/
754 THR_LOCK lock;
755 TABLE_SHARE *table_share;
756 SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share;
757#ifdef SPIDER_HAS_HASH_VALUE_TYPE
758 my_hash_value_type table_name_hash_value;
759#ifdef WITH_PARTITION_STORAGE_ENGINE
760 my_hash_value_type table_path_hash_value;
761#endif
762#endif
763
764 volatile bool init;
765 volatile bool init_error;
766 volatile time_t init_error_time;
767 volatile bool link_status_init;
768 uchar *table_mon_mutex_bitmap;
769 volatile bool sts_init;
770 volatile time_t sts_get_time;
771#ifndef WITHOUT_SPIDER_BG_SEARCH
772 volatile time_t bg_sts_try_time;
773 volatile double bg_sts_interval;
774 volatile int bg_sts_mode;
775#ifdef WITH_PARTITION_STORAGE_ENGINE
776 volatile int bg_sts_sync;
777#endif
778 volatile bool bg_sts_init;
779 volatile bool bg_sts_kill;
780 volatile bool bg_sts_thd_wait;
781 THD *bg_sts_thd;
782 pthread_t bg_sts_thread;
783 pthread_cond_t bg_sts_cond;
784 pthread_cond_t bg_sts_sync_cond;
785 volatile bool crd_init;
786#endif
787 volatile time_t crd_get_time;
788#ifndef WITHOUT_SPIDER_BG_SEARCH
789 volatile time_t bg_crd_try_time;
790 volatile double bg_crd_interval;
791 volatile int bg_crd_mode;
792#ifdef WITH_PARTITION_STORAGE_ENGINE
793 volatile int bg_crd_sync;
794#endif
795 volatile bool bg_crd_init;
796 volatile bool bg_crd_kill;
797 volatile bool bg_crd_thd_wait;
798 THD *bg_crd_thd;
799 pthread_t bg_crd_thread;
800 pthread_cond_t bg_crd_cond;
801 pthread_cond_t bg_crd_sync_cond;
802#endif
803#ifndef WITHOUT_SPIDER_BG_SEARCH
804 volatile bool bg_mon_init;
805 volatile bool bg_mon_kill;
806 THD **bg_mon_thds;
807 pthread_t *bg_mon_threads;
808 pthread_mutex_t *bg_mon_mutexes;
809 pthread_cond_t *bg_mon_conds;
810 pthread_cond_t *bg_mon_sleep_conds;
811#endif
812#ifndef WITHOUT_SPIDER_BG_SEARCH
813 /* static bg thread for sts and crd */
814 TABLE table;
815 ha_spider *sts_spider;
816 ha_spider *crd_spider;
817 SPIDER_THREAD *sts_thread;
818 SPIDER_THREAD *crd_thread;
819 volatile bool sts_spider_init;
820 volatile bool sts_working;
821 volatile bool sts_wait;
822 volatile bool crd_spider_init;
823 volatile bool crd_working;
824 volatile bool crd_wait;
825 volatile SPIDER_SHARE *sts_prev;
826 volatile SPIDER_SHARE *sts_next;
827 volatile SPIDER_SHARE *crd_prev;
828 volatile SPIDER_SHARE *crd_next;
829#endif
830
831 MEM_ROOT mem_root;
832
833/*
834 volatile bool auto_increment_init;
835 volatile ulonglong auto_increment_lclval;
836*/
837 ulonglong data_file_length;
838 ulonglong max_data_file_length;
839 ulonglong index_file_length;
840/*
841 ulonglong auto_increment_value;
842*/
843 ha_rows records;
844 ulong mean_rec_length;
845 time_t check_time;
846 time_t create_time;
847 time_t update_time;
848
849 longlong static_records_for_status;
850 longlong static_mean_rec_length;
851
852 int bitmap_size;
853 spider_string *key_hint;
854 CHARSET_INFO *access_charset;
855 longlong *static_key_cardinality;
856 longlong *cardinality;
857 uchar *cardinality_upd;
858 longlong additional_table_flags;
859 bool have_recovery_link;
860
861#ifndef WITHOUT_SPIDER_BG_SEARCH
862 int sts_bg_mode;
863#endif
864 double sts_interval;
865 int sts_mode;
866#ifdef WITH_PARTITION_STORAGE_ENGINE
867 int sts_sync;
868#endif
869 int store_last_sts;
870 int load_sts_at_startup;
871#ifndef WITHOUT_SPIDER_BG_SEARCH
872 int crd_bg_mode;
873#endif
874 double crd_interval;
875 int crd_mode;
876#ifdef WITH_PARTITION_STORAGE_ENGINE
877 int crd_sync;
878#endif
879 int store_last_crd;
880 int load_crd_at_startup;
881 int crd_type;
882 double crd_weight;
883 longlong internal_offset;
884 longlong internal_limit;
885 longlong split_read;
886 double semi_split_read;
887 longlong semi_split_read_limit;
888 int init_sql_alloc_size;
889 int reset_sql_alloc;
890 int multi_split_read;
891 int max_order;
892 int semi_table_lock;
893 int semi_table_lock_conn;
894 int selupd_lock_mode;
895 int query_cache;
896 int query_cache_sync;
897 int internal_delayed;
898 int bulk_size;
899 int bulk_update_mode;
900 int bulk_update_size;
901 int internal_optimize;
902 int internal_optimize_local;
903 double scan_rate;
904 double read_rate;
905 longlong priority;
906 int quick_mode;
907 longlong quick_page_size;
908 int low_mem_read;
909 int table_count_mode;
910 int select_column_mode;
911#ifndef WITHOUT_SPIDER_BG_SEARCH
912 int bgs_mode;
913 longlong bgs_first_read;
914 longlong bgs_second_read;
915#endif
916 longlong first_read;
917 longlong second_read;
918 int auto_increment_mode;
919 int use_table_charset;
920 int use_pushdown_udf;
921 int skip_default_condition;
922 int skip_parallel_search;
923 int direct_dup_insert;
924 longlong direct_order_limit;
925 int read_only_mode;
926 int error_read_mode;
927 int error_write_mode;
928 int active_link_count;
929#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
930 longlong hs_result_free_size;
931#endif
932#ifdef HA_CAN_BULK_ACCESS
933 int bulk_access_free;
934#endif
935#ifdef HA_CAN_FORCE_BULK_UPDATE
936 int force_bulk_update;
937#endif
938#ifdef HA_CAN_FORCE_BULK_DELETE
939 int force_bulk_delete;
940#endif
941 int casual_read;
942 int delete_all_rows_type;
943
944 int bka_mode;
945 char *bka_engine;
946 int bka_engine_length;
947
948#ifdef SPIDER_HAS_HASH_VALUE_TYPE
949 my_hash_value_type *conn_keys_hash_value;
950#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
951 my_hash_value_type *hs_read_conn_keys_hash_value;
952 my_hash_value_type *hs_write_conn_keys_hash_value;
953#endif
954#endif
955 char **server_names;
956 char **tgt_table_names;
957 char **tgt_dbs;
958 char **tgt_hosts;
959 char **tgt_usernames;
960 char **tgt_passwords;
961 char **tgt_sockets;
962 char **tgt_wrappers;
963 char **tgt_ssl_cas;
964 char **tgt_ssl_capaths;
965 char **tgt_ssl_certs;
966 char **tgt_ssl_ciphers;
967 char **tgt_ssl_keys;
968 char **tgt_default_files;
969 char **tgt_default_groups;
970 char **static_link_ids;
971 char **tgt_pk_names;
972 char **tgt_sequence_names;
973 char **conn_keys;
974#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
975 char **hs_read_socks;
976 char **hs_write_socks;
977 char **hs_read_conn_keys;
978 char **hs_write_conn_keys;
979#endif
980 long *tgt_ports;
981 long *tgt_ssl_vscs;
982 long *link_statuses;
983#ifndef WITHOUT_SPIDER_BG_SEARCH
984 long *monitoring_bg_flag;
985 long *monitoring_bg_kind;
986#endif
987 long *monitoring_binlog_pos_at_failing;
988 long *monitoring_flag;
989 long *monitoring_kind;
990#ifndef WITHOUT_SPIDER_BG_SEARCH
991 longlong *monitoring_bg_interval;
992#endif
993 longlong *monitoring_limit;
994 longlong *monitoring_sid;
995#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
996 long *use_hs_reads;
997 long *use_hs_writes;
998 long *hs_read_ports;
999 long *hs_write_ports;
1000 long *hs_write_to_reads;
1001#endif
1002 long *use_handlers;
1003 long *connect_timeouts;
1004 long *net_read_timeouts;
1005 long *net_write_timeouts;
1006 long *access_balances;
1007 long *bka_table_name_types;
1008
1009 uint *server_names_lengths;
1010 uint *tgt_table_names_lengths;
1011 uint *tgt_dbs_lengths;
1012 uint *tgt_hosts_lengths;
1013 uint *tgt_usernames_lengths;
1014 uint *tgt_passwords_lengths;
1015 uint *tgt_sockets_lengths;
1016 uint *tgt_wrappers_lengths;
1017 uint *tgt_ssl_cas_lengths;
1018 uint *tgt_ssl_capaths_lengths;
1019 uint *tgt_ssl_certs_lengths;
1020 uint *tgt_ssl_ciphers_lengths;
1021 uint *tgt_ssl_keys_lengths;
1022 uint *tgt_default_files_lengths;
1023 uint *tgt_default_groups_lengths;
1024 uint *static_link_ids_lengths;
1025 uint *tgt_pk_names_lengths;
1026 uint *tgt_sequence_names_lengths;
1027 uint *conn_keys_lengths;
1028#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1029 uint *hs_read_socks_lengths;
1030 uint *hs_write_socks_lengths;
1031 uint *hs_read_conn_keys_lengths;
1032 uint *hs_write_conn_keys_lengths;
1033#endif
1034 uint *sql_dbton_ids;
1035#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1036 uint *hs_dbton_ids;
1037#endif
1038
1039 uint server_names_charlen;
1040 uint tgt_table_names_charlen;
1041 uint tgt_dbs_charlen;
1042 uint tgt_hosts_charlen;
1043 uint tgt_usernames_charlen;
1044 uint tgt_passwords_charlen;
1045 uint tgt_sockets_charlen;
1046 uint tgt_wrappers_charlen;
1047 uint tgt_ssl_cas_charlen;
1048 uint tgt_ssl_capaths_charlen;
1049 uint tgt_ssl_certs_charlen;
1050 uint tgt_ssl_ciphers_charlen;
1051 uint tgt_ssl_keys_charlen;
1052 uint tgt_default_files_charlen;
1053 uint tgt_default_groups_charlen;
1054 uint static_link_ids_charlen;
1055 uint tgt_pk_names_charlen;
1056 uint tgt_sequence_names_charlen;
1057 uint conn_keys_charlen;
1058#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1059 uint hs_read_socks_charlen;
1060 uint hs_write_socks_charlen;
1061 uint hs_read_conn_keys_charlen;
1062 uint hs_write_conn_keys_charlen;
1063#endif
1064
1065 uint server_names_length;
1066 uint tgt_table_names_length;
1067 uint tgt_dbs_length;
1068 uint tgt_hosts_length;
1069 uint tgt_usernames_length;
1070 uint tgt_passwords_length;
1071 uint tgt_sockets_length;
1072 uint tgt_wrappers_length;
1073 uint tgt_ssl_cas_length;
1074 uint tgt_ssl_capaths_length;
1075 uint tgt_ssl_certs_length;
1076 uint tgt_ssl_ciphers_length;
1077 uint tgt_ssl_keys_length;
1078 uint tgt_default_files_length;
1079 uint tgt_default_groups_length;
1080 uint static_link_ids_length;
1081 uint tgt_pk_names_length;
1082 uint tgt_sequence_names_length;
1083 uint conn_keys_length;
1084#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1085 uint hs_read_socks_length;
1086 uint hs_write_socks_length;
1087 uint hs_read_conn_keys_length;
1088 uint hs_write_conn_keys_length;
1089#endif
1090 uint tgt_ports_length;
1091 uint tgt_ssl_vscs_length;
1092 uint link_statuses_length;
1093#ifndef WITHOUT_SPIDER_BG_SEARCH
1094 uint monitoring_bg_flag_length;
1095 uint monitoring_bg_kind_length;
1096#endif
1097 uint monitoring_binlog_pos_at_failing_length;
1098 uint monitoring_flag_length;
1099 uint monitoring_kind_length;
1100#ifndef WITHOUT_SPIDER_BG_SEARCH
1101 uint monitoring_bg_interval_length;
1102#endif
1103 uint monitoring_limit_length;
1104 uint monitoring_sid_length;
1105#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1106 uint use_hs_reads_length;
1107 uint use_hs_writes_length;
1108 uint hs_read_ports_length;
1109 uint hs_write_ports_length;
1110 uint hs_write_to_reads_length;
1111#endif
1112 uint use_handlers_length;
1113 uint connect_timeouts_length;
1114 uint net_read_timeouts_length;
1115 uint net_write_timeouts_length;
1116 uint access_balances_length;
1117 uint bka_table_name_types_length;
1118
1119 /* for dbton */
1120 uchar dbton_bitmap[spider_bitmap_size(SPIDER_DBTON_SIZE)];
1121 spider_db_share *dbton_share[SPIDER_DBTON_SIZE];
1122 uint use_dbton_count;
1123 uint use_dbton_ids[SPIDER_DBTON_SIZE];
1124 uint dbton_id_to_seq[SPIDER_DBTON_SIZE];
1125 uint use_sql_dbton_count;
1126 uint use_sql_dbton_ids[SPIDER_DBTON_SIZE];
1127 uint sql_dbton_id_to_seq[SPIDER_DBTON_SIZE];
1128#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1129 uint use_hs_dbton_count;
1130 uint use_hs_dbton_ids[SPIDER_DBTON_SIZE];
1131 uint hs_dbton_id_to_seq[SPIDER_DBTON_SIZE];
1132#endif
1133
1134 SPIDER_ALTER_TABLE alter_table;
1135#ifdef WITH_PARTITION_STORAGE_ENGINE
1136 SPIDER_PARTITION_SHARE *partition_share;
1137#endif
1138} SPIDER_SHARE;
1139
1140typedef struct st_spider_link_pack
1141{
1142 SPIDER_SHARE *share;
1143 int link_idx;
1144} SPIDER_LINK_PACK;
1145
1146typedef struct st_spider_init_error_table
1147{
1148 char *table_name;
1149 uint table_name_length;
1150#ifdef SPIDER_HAS_HASH_VALUE_TYPE
1151 my_hash_value_type table_name_hash_value;
1152#endif
1153 bool init_error_with_message;
1154 char init_error_msg[MYSQL_ERRMSG_SIZE];
1155 volatile int init_error;
1156 volatile time_t init_error_time;
1157} SPIDER_INIT_ERROR_TABLE;
1158
1159typedef struct st_spider_direct_sql
1160{
1161 int table_count;
1162 char **db_names;
1163 char **table_names;
1164 TABLE **tables;
1165 int *iop;
1166
1167#if MYSQL_VERSION_ID < 50500
1168#else
1169 /* for using real table */
1170 bool real_table_used;
1171 TABLE_LIST *table_list_first;
1172 TABLE_LIST *table_list;
1173 uchar *real_table_bitmap;
1174 Open_tables_backup open_tables_backup;
1175 THD *open_tables_thd;
1176#endif
1177
1178 char *sql;
1179 ulong sql_length;
1180
1181 SPIDER_TRX *trx;
1182 SPIDER_CONN *conn;
1183
1184 bool modified_non_trans_table;
1185
1186 int table_loop_mode;
1187 longlong priority;
1188 int connect_timeout;
1189 int net_read_timeout;
1190 int net_write_timeout;
1191 longlong bulk_insert_rows;
1192 int connection_channel;
1193#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1194 int access_mode;
1195#endif
1196#if MYSQL_VERSION_ID < 50500
1197#else
1198 int use_real_table;
1199#endif
1200 int error_rw_mode;
1201
1202 char *server_name;
1203 char *tgt_default_db_name;
1204 char *tgt_host;
1205 char *tgt_username;
1206 char *tgt_password;
1207 char *tgt_socket;
1208 char *tgt_wrapper;
1209 char *tgt_ssl_ca;
1210 char *tgt_ssl_capath;
1211 char *tgt_ssl_cert;
1212 char *tgt_ssl_cipher;
1213 char *tgt_ssl_key;
1214 char *tgt_default_file;
1215 char *tgt_default_group;
1216 char *conn_key;
1217 long tgt_port;
1218 long tgt_ssl_vsc;
1219
1220 uint server_name_length;
1221 uint tgt_default_db_name_length;
1222 uint tgt_host_length;
1223 uint tgt_username_length;
1224 uint tgt_password_length;
1225 uint tgt_socket_length;
1226 uint tgt_wrapper_length;
1227 uint tgt_ssl_ca_length;
1228 uint tgt_ssl_capath_length;
1229 uint tgt_ssl_cert_length;
1230 uint tgt_ssl_cipher_length;
1231 uint tgt_ssl_key_length;
1232 uint tgt_default_file_length;
1233 uint tgt_default_group_length;
1234 uint conn_key_length;
1235 uint dbton_id;
1236#ifdef SPIDER_HAS_HASH_VALUE_TYPE
1237 my_hash_value_type conn_key_hash_value;
1238#endif
1239
1240 pthread_mutex_t *bg_mutex;
1241 pthread_cond_t *bg_cond;
1242 volatile st_spider_direct_sql *prev;
1243 volatile st_spider_direct_sql *next;
1244 void *parent;
1245} SPIDER_DIRECT_SQL;
1246
1247typedef struct st_spider_bg_direct_sql
1248{
1249 longlong called_cnt;
1250 char bg_error_msg[MYSQL_ERRMSG_SIZE];
1251 volatile int bg_error;
1252 volatile bool modified_non_trans_table;
1253 pthread_mutex_t bg_mutex;
1254 pthread_cond_t bg_cond;
1255 volatile SPIDER_DIRECT_SQL *direct_sql;
1256} SPIDER_BG_DIRECT_SQL;
1257
1258typedef struct st_spider_mon_table_result
1259{
1260 int result_status;
1261 SPIDER_TRX *trx;
1262} SPIDER_MON_TABLE_RESULT;
1263
1264typedef struct st_spider_table_mon
1265{
1266 SPIDER_SHARE *share;
1267 uint32 server_id;
1268 st_spider_table_mon_list *parent;
1269 st_spider_table_mon *next;
1270} SPIDER_TABLE_MON;
1271
1272typedef struct st_spider_table_mon_list
1273{
1274 char *key;
1275 uint key_length;
1276#ifdef SPIDER_HAS_HASH_VALUE_TYPE
1277 my_hash_value_type key_hash_value;
1278#endif
1279
1280 uint use_count;
1281 uint mutex_hash;
1282 ulonglong mon_table_cache_version;
1283
1284 char *table_name;
1285 int link_id;
1286 uint table_name_length;
1287
1288 int list_size;
1289 SPIDER_TABLE_MON *first;
1290 SPIDER_TABLE_MON *current;
1291 volatile int mon_status;
1292
1293 SPIDER_SHARE *share;
1294
1295 pthread_mutex_t caller_mutex;
1296 pthread_mutex_t receptor_mutex;
1297 pthread_mutex_t monitor_mutex;
1298 pthread_mutex_t update_status_mutex;
1299 volatile int last_caller_result;
1300 volatile int last_receptor_result;
1301 volatile int last_mon_result;
1302} SPIDER_TABLE_MON_LIST;
1303
1304typedef struct st_spider_copy_table_conn
1305{
1306 SPIDER_SHARE *share;
1307 int link_idx;
1308 SPIDER_CONN *conn;
1309 spider_db_copy_table *copy_table;
1310 ha_spider *spider;
1311 int need_mon;
1312#ifndef WITHOUT_SPIDER_BG_SEARCH
1313 int bg_error_num;
1314#endif
1315 st_spider_copy_table_conn *next;
1316} SPIDER_COPY_TABLE_CONN;
1317
1318typedef struct st_spider_copy_tables
1319{
1320 SPIDER_TRX *trx;
1321 char *spider_db_name;
1322 int spider_db_name_length;
1323 char *spider_table_name;
1324 int spider_table_name_length;
1325 char *spider_real_table_name;
1326 int spider_real_table_name_length;
1327 TABLE_LIST spider_table_list;
1328 CHARSET_INFO *access_charset;
1329
1330 SPIDER_COPY_TABLE_CONN *table_conn[2];
1331 bool use_auto_mode[2];
1332 int link_idx_count[2];
1333 int *link_idxs[2];
1334
1335 int bulk_insert_interval;
1336 longlong bulk_insert_rows;
1337 int use_table_charset;
1338 int use_transaction;
1339#ifndef WITHOUT_SPIDER_BG_SEARCH
1340 int bg_mode;
1341#endif
1342
1343 char *database;
1344
1345 int database_length;
1346} SPIDER_COPY_TABLES;
1347
1348class SPIDER_SORT
1349{
1350public:
1351 ulong sort;
1352};
1353
1354typedef struct st_spider_trx_ha
1355{
1356 char *table_name;
1357 uint table_name_length;
1358 SPIDER_TRX *trx;
1359 SPIDER_SHARE *share;
1360 uint link_count;
1361 uint link_bitmap_size;
1362 uint *conn_link_idx;
1363 uchar *conn_can_fo;
1364 bool wait_for_reusing;
1365} SPIDER_TRX_HA;
1366
1367#ifdef HA_CAN_BULK_ACCESS
1368typedef struct st_spider_bulk_access_link
1369{
1370 ha_spider *spider;
1371 uint sequence_num;
1372 bool used;
1373 bool called;
1374 MEM_ROOT mem_root;
1375 st_spider_bulk_access_link *next;
1376} SPIDER_BULK_ACCESS_LINK;
1377#endif
1378
1379#define SPIDER_INT_HLD_TGT_SIZE 100
1380typedef struct st_spider_int_hld
1381{
1382 uint tgt_num;
1383 int tgt[SPIDER_INT_HLD_TGT_SIZE];
1384 st_spider_int_hld *next;
1385} SPIDER_INT_HLD;
1386
1387typedef struct st_spider_item_hld
1388{
1389 uint tgt_num;
1390 Item *item;
1391#ifdef SPIDER_ITEM_STRING_WITHOUT_SET_STR_WITH_COPY_AND_THDPTR
1392 bool init_mem_root;
1393 MEM_ROOT mem_root;
1394#endif
1395 st_spider_item_hld *next;
1396} SPIDER_ITEM_HLD;
1397
1398char *spider_create_string(
1399 const char *str,
1400 uint length
1401);
1402
1403
1404typedef struct st_spider_ip_port_conn {
1405 char *key;
1406 size_t key_len;
1407#ifdef SPIDER_HAS_HASH_VALUE_TYPE
1408 my_hash_value_type key_hash_value;
1409#endif
1410 char remote_ip_str[SPIDER_CONN_META_BUF_LEN];
1411 long remote_port;
1412 ulong ip_port_count;
1413 volatile ulong waiting_count;
1414 pthread_mutex_t mutex;
1415 pthread_cond_t cond;
1416 ulonglong conn_id; /* each conn has it's own conn_id */
1417} SPIDER_IP_PORT_CONN;
1418