-
Notifications
You must be signed in to change notification settings - Fork 9
/
spd_include.h
1655 lines (1539 loc) · 57.3 KB
/
spd_include.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (C) 2008-2020 Kentoku Shiba
Copyright (C) 2019-2020 MariaDB corp
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifdef SPIDER_REWRITE_AVAILABLE
#define SPIDER_DETAIL_VERSION "3.4.2"
#define SPIDER_HEX_VERSION 0x0304
#else
#define SPIDER_DETAIL_VERSION "3.4.0"
#define SPIDER_HEX_VERSION 0x0304
#endif
#if MYSQL_VERSION_ID < 50500
#define spider_my_free(A,B) my_free(A,B)
#else
#define spider_my_free(A,B) my_free(A)
#ifdef pthread_mutex_t
#undef pthread_mutex_t
#endif
#define pthread_mutex_t mysql_mutex_t
#ifdef pthread_mutex_lock
#undef pthread_mutex_lock
#endif
#define pthread_mutex_lock mysql_mutex_lock
#ifdef pthread_mutex_trylock
#undef pthread_mutex_trylock
#endif
#define pthread_mutex_trylock mysql_mutex_trylock
#ifdef pthread_mutex_unlock
#undef pthread_mutex_unlock
#endif
#define pthread_mutex_unlock mysql_mutex_unlock
#ifdef pthread_mutex_destroy
#undef pthread_mutex_destroy
#endif
#define pthread_mutex_destroy mysql_mutex_destroy
#ifdef pthread_cond_t
#undef pthread_cond_t
#endif
#define pthread_cond_t mysql_cond_t
#ifdef pthread_cond_wait
#undef pthread_cond_wait
#endif
#define pthread_cond_wait mysql_cond_wait
#ifdef pthread_cond_timedwait
#undef pthread_cond_timedwait
#endif
#define pthread_cond_timedwait mysql_cond_timedwait
#ifdef pthread_cond_signal
#undef pthread_cond_signal
#endif
#define pthread_cond_signal mysql_cond_signal
#ifdef pthread_cond_broadcast
#undef pthread_cond_broadcast
#endif
#define pthread_cond_broadcast mysql_cond_broadcast
#ifdef pthread_cond_destroy
#undef pthread_cond_destroy
#endif
#define pthread_cond_destroy mysql_cond_destroy
#define my_sprintf(A,B) sprintf B
#endif
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100004
#define spider_stmt_da_message(A) thd_get_error_message(A)
#define spider_stmt_da_sql_errno(A) thd_get_error_number(A)
#define spider_user_defined_key_parts(A) (A)->user_defined_key_parts
#define spider_join_table_count(A) (A)->table_count
#define SPIDER_CAN_BG_UPDATE (1LL << 39)
#if MYSQL_VERSION_ID >= 100304
#define SPIDER_ALTER_PARTITION_ADD ALTER_PARTITION_ADD
#define SPIDER_ALTER_PARTITION_DROP ALTER_PARTITION_DROP
#define SPIDER_ALTER_PARTITION_COALESCE ALTER_PARTITION_COALESCE
#define SPIDER_ALTER_PARTITION_REORGANIZE ALTER_PARTITION_REORGANIZE
#define SPIDER_ALTER_PARTITION_TABLE_REORG ALTER_PARTITION_TABLE_REORG
#define SPIDER_ALTER_PARTITION_REBUILD ALTER_PARTITION_REBUILD
#else
#define SPIDER_ALTER_PARTITION_ADD Alter_info::ALTER_ADD_PARTITION
#define SPIDER_ALTER_PARTITION_DROP Alter_info::ALTER_DROP_PARTITION
#define SPIDER_ALTER_PARTITION_COALESCE Alter_info::ALTER_COALESCE_PARTITION
#define SPIDER_ALTER_PARTITION_REORGANIZE Alter_info::ALTER_REORGANIZE_PARTITION
#define SPIDER_ALTER_PARTITION_TABLE_REORG Alter_info::ALTER_TABLE_REORG
#define SPIDER_ALTER_PARTITION_REBUILD Alter_info::ALTER_REBUILD_PARTITION
#endif
#define SPIDER_WARN_LEVEL_WARN Sql_condition::WARN_LEVEL_WARN
#define SPIDER_WARN_LEVEL_NOTE Sql_condition::WARN_LEVEL_NOTE
#define SPIDER_THD_KILL_CONNECTION KILL_CONNECTION
#else
#if MYSQL_VERSION_ID < 50500
#define spider_stmt_da_message(A) (A)->main_da.message()
#define spider_stmt_da_sql_errno(A) (A)->main_da.sql_errno()
#else
#if MYSQL_VERSION_ID < 50600
#define spider_stmt_da_message(A) (A)->stmt_da->message()
#define spider_stmt_da_sql_errno(A) (A)->stmt_da->sql_errno()
#else
#define spider_stmt_da_message(A) (A)->get_stmt_da()->message()
#define spider_stmt_da_sql_errno(A) (A)->get_stmt_da()->sql_errno()
#endif
#endif
#define spider_user_defined_key_parts(A) (A)->key_parts
#define spider_join_table_count(A) (A)->tables
#define SPIDER_ALTER_PARTITION_ADD ALTER_ADD_PARTITION
#define SPIDER_ALTER_PARTITION_DROP ALTER_DROP_PARTITION
#define SPIDER_ALTER_PARTITION_COALESCE ALTER_COALESCE_PARTITION
#define SPIDER_ALTER_PARTITION_REORGANIZE ALTER_REORGANIZE_PARTITION
#define SPIDER_ALTER_PARTITION_TABLE_REORG ALTER_TABLE_REORG
#define SPIDER_ALTER_PARTITION_REBUILD ALTER_REBUILD_PARTITION
#define SPIDER_WARN_LEVEL_WARN MYSQL_ERROR::WARN_LEVEL_WARN
#define SPIDER_WARN_LEVEL_NOTE MYSQL_ERROR::WARN_LEVEL_NOTE
#define SPIDER_THD_KILL_CONNECTION THD::KILL_CONNECTION
#endif
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100005
#define SPIDER_HAS_EXPLAIN_QUERY
#endif
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100009
#define SPIDER_TEST(A) MY_TEST(A)
#else
#define SPIDER_TEST(A) test(A)
#endif
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100100
#define SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR
#define SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON
#define SPIDER_XID_USES_xid_cache_iterate
#else
#define SPIDER_XID_STATE_HAS_in_thd
#endif
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100108
#define SPIDER_Item_args_arg_count_IS_PROTECTED
#endif
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100112
#define SPIDER_Item_func_conv_charset_conv_charset collation.collation
#else
#define SPIDER_Item_func_conv_charset_conv_charset conv_charset
#endif
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100200
#define SPIDER_WITHOUT_HA_STATISTIC_INCREMENT
#define SPIDER_init_read_record(A,B,C,D,E,F,G,H) init_read_record(A,B,C,D,E,F,G,H)
#define SPIDER_HAS_NEXT_THREAD_ID
#define SPIDER_new_THD(A) (new THD(A))
#define SPIDER_order_direction_is_asc(A) (A->direction == ORDER::ORDER_ASC)
#else
#define SPIDER_init_read_record(A,B,C,D,E,F,G,H) init_read_record(A,B,C,D,F,G,H)
#define SPIDER_new_THD(A) (new THD())
#define SPIDER_order_direction_is_asc(A) (A->asc)
#endif
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100201
#define SPIDER_HAS_MY_CHARLEN
#define SPIDER_open_temporary_table
#endif
#if defined(MARIADB_BASE_VERSION)
#if MYSQL_VERSION_ID >= 100209
#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(A,B,C,E,F,G)
#elif MYSQL_VERSION_ID >= 100200
#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(A,B,C,D,E,F,G,H)
#elif MYSQL_VERSION_ID >= 100007
#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(B,C,D,E,F,G,H)
#else
#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H) generate_partition_syntax(B,C,D,E,F,G)
#endif
#else
#define SPIDER_generate_partition_syntax(A,B,C,D,E,F,G,H)
#endif
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100209
#define SPIDER_create_partition_name(A,B,C,D,E,F) create_partition_name(A,B,C,D,E,F)
#define SPIDER_create_subpartition_name(A,B,C,D,E,F) create_subpartition_name(A,B,C,D,E,F)
#define SPIDER_free_part_syntax(A,B)
#else
#define SPIDER_create_partition_name(A,B,C,D,E,F) create_partition_name(A,C,D,E,F)
#define SPIDER_create_subpartition_name(A,B,C,D,E,F) create_subpartition_name(A,C,D,E,F)
#define SPIDER_free_part_syntax(A,B) spider_my_free(A,B)
#endif
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100306
#define SPIDER_read_record_read_record(A) read_record()
#define SPIDER_has_Item_with_subquery
#define SPIDER_use_LEX_CSTRING_for_KEY_Field_name
#define SPIDER_use_LEX_CSTRING_for_Field_blob_constructor
#define SPIDER_use_LEX_CSTRING_for_database_tablename_alias
#define SPIDER_THD_db_str(A) (A)->db.str
#define SPIDER_THD_db_length(A) (A)->db.length
#define SPIDER_TABLE_LIST_db_str(A) (A)->db.str
#define SPIDER_TABLE_LIST_db_length(A) (A)->db.length
#define SPIDER_TABLE_LIST_table_name_str(A) (A)->table_name.str
#define SPIDER_TABLE_LIST_table_name_length(A) (A)->table_name.length
#define SPIDER_TABLE_LIST_alias_str(A) (A)->alias.str
#define SPIDER_TABLE_LIST_alias_length(A) (A)->alias.length
#define SPIDER_field_name_str(A) (A)->field_name.str
#define SPIDER_field_name_length(A) (A)->field_name.length
#define SPIDER_item_name_str(A) (A)->name.str
#define SPIDER_item_name_length(A) (A)->name.length
const LEX_CSTRING SPIDER_empty_string = {"", 0};
#else
#define SPIDER_read_record_read_record(A) read_record(A)
#define SPIDER_THD_db_str(A) (A)->db
#define SPIDER_THD_db_length(A) (A)->db_length
#define SPIDER_TABLE_LIST_db_str(A) (A)->db
#define SPIDER_TABLE_LIST_db_length(A) (A)->db_length
#define SPIDER_TABLE_LIST_table_name_str(A) (A)->table_name
#define SPIDER_TABLE_LIST_table_name_length(A) (A)->table_name_length
#define SPIDER_TABLE_LIST_alias_str(A) (A)->alias
#define SPIDER_TABLE_LIST_alias_length(A) strlen((A)->alias)
#define SPIDER_field_name_str(A) (A)->field_name
#define SPIDER_field_name_length(A) strlen((A)->field_name)
#define SPIDER_item_name_str(A) (A)->name
#define SPIDER_item_name_length(A) strlen((A)->name)
const char SPIDER_empty_string = "";
#endif
#if MYSQL_VERSION_ID >= 50500
#define SPIDER_HAS_HASH_VALUE_TYPE
#endif
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100400
#define SPIDER_date_mode_t(A) date_mode_t(A)
#define SPIDER_str_to_datetime(A,B,C,D,E) str_to_datetime_or_date(A,B,C,D,E)
#define SPIDER_get_linkage(A) A->get_linkage()
#else
#define SPIDER_date_mode_t(A) A
#define SPIDER_str_to_datetime(A,B,C,D,E) str_to_datetime(A,B,C,D,E)
#define SPIDER_get_linkage(A) A->linkage
#endif
#define spider_bitmap_size(A) ((A + 7) / 8)
#define spider_set_bit(BITMAP, BIT) \
((BITMAP)[(BIT) / 8] |= (1 << ((BIT) & 7)))
#define spider_clear_bit(BITMAP, BIT) \
((BITMAP)[(BIT) / 8] &= ~(1 << ((BIT) & 7)))
#define spider_bit_is_set(BITMAP, BIT) \
(uint) ((BITMAP)[(BIT) / 8] & (1 << ((BIT) & 7)))
#define SPIDER_LINK_STATUS_NO_CHANGE 0
#define SPIDER_LINK_STATUS_OK 1
#define SPIDER_LINK_STATUS_RECOVERY 2
#define SPIDER_LINK_STATUS_NG 3
#define SPIDER_LINK_MON_OK 0
#define SPIDER_LINK_MON_NG -1
#define SPIDER_LINK_MON_DRAW_FEW_MON 1
#define SPIDER_LINK_MON_DRAW 2
#define SPIDER_TMP_SHARE_CHAR_PTR_COUNT 23
#define SPIDER_TMP_SHARE_UINT_COUNT SPIDER_TMP_SHARE_CHAR_PTR_COUNT
#define SPIDER_TMP_SHARE_LONG_COUNT 20
#define SPIDER_TMP_SHARE_LONGLONG_COUNT 3
#define SPIDER_MEM_CALC_LIST_NUM 314
#define SPIDER_CONN_META_BUF_LEN 64
#define SPIDER_BACKUP_DASTATUS \
bool da_status; if (thd) da_status = thd->is_error(); else da_status = FALSE;
#define SPIDER_RESTORE_DASTATUS \
if (!da_status && thd->is_error()) thd->clear_error();
#define SPIDER_CONN_RESTORE_DASTATUS \
if (thd && conn->error_mode) {SPIDER_RESTORE_DASTATUS;}
#define SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM \
if (thd && conn->error_mode) {SPIDER_RESTORE_DASTATUS; error_num = 0;}
#define SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_TMP_ERROR_NUM \
if (thd && conn->error_mode) {SPIDER_RESTORE_DASTATUS; tmp_error_num = 0;}
#define SPIDER_SET_FILE_POS(A) \
{(A)->thd = current_thd; (A)->func_name = __func__; (A)->file_name = __FILE__; (A)->line_no = __LINE__;}
#define SPIDER_CLEAR_FILE_POS(A) \
{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;}
class ha_spider;
typedef struct st_spider_share SPIDER_SHARE;
typedef struct st_spider_table_mon_list SPIDER_TABLE_MON_LIST;
typedef struct st_spider_ip_port_conn SPIDER_IP_PORT_CONN;
#ifndef WITHOUT_SPIDER_BG_SEARCH
typedef struct st_spider_thread
{
uint thread_idx;
THD *thd;
volatile bool killed;
volatile bool thd_wait;
volatile bool first_free_wait;
volatile bool init_command;
pthread_t thread;
pthread_cond_t cond;
pthread_mutex_t mutex;
pthread_cond_t sync_cond;
volatile SPIDER_SHARE *queue_first;
volatile SPIDER_SHARE *queue_last;
} SPIDER_THREAD;
#endif
typedef struct st_spider_file_pos
{
THD *thd;
const char *func_name;
const char *file_name;
ulong line_no;
} SPIDER_FILE_POS;
typedef struct st_spider_link_for_hash
{
ha_spider *spider;
int link_idx;
spider_string *db_table_str;
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
my_hash_value_type db_table_str_hash_value;
#endif
} SPIDER_LINK_FOR_HASH;
/* alter table */
typedef struct st_spider_alter_table
{
bool now_create;
char *table_name;
uint table_name_length;
char *tmp_char;
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
my_hash_value_type table_name_hash_value;
#endif
longlong tmp_priority;
uint link_count;
uint all_link_count;
char **tmp_server_names;
char **tmp_tgt_table_names;
char **tmp_tgt_dbs;
char **tmp_tgt_hosts;
char **tmp_tgt_usernames;
char **tmp_tgt_passwords;
char **tmp_tgt_sockets;
char **tmp_tgt_wrappers;
char **tmp_tgt_ssl_cas;
char **tmp_tgt_ssl_capaths;
char **tmp_tgt_ssl_certs;
char **tmp_tgt_ssl_ciphers;
char **tmp_tgt_ssl_keys;
char **tmp_tgt_default_files;
char **tmp_tgt_default_groups;
char **tmp_tgt_dsns;
char **tmp_tgt_filedsns;
char **tmp_tgt_drivers;
char **tmp_static_link_ids;
long *tmp_tgt_ports;
long *tmp_tgt_ssl_vscs;
long *tmp_monitoring_binlog_pos_at_failing;
long *tmp_link_statuses;
uint *tmp_server_names_lengths;
uint *tmp_tgt_table_names_lengths;
uint *tmp_tgt_dbs_lengths;
uint *tmp_tgt_hosts_lengths;
uint *tmp_tgt_usernames_lengths;
uint *tmp_tgt_passwords_lengths;
uint *tmp_tgt_sockets_lengths;
uint *tmp_tgt_wrappers_lengths;
uint *tmp_tgt_ssl_cas_lengths;
uint *tmp_tgt_ssl_capaths_lengths;
uint *tmp_tgt_ssl_certs_lengths;
uint *tmp_tgt_ssl_ciphers_lengths;
uint *tmp_tgt_ssl_keys_lengths;
uint *tmp_tgt_default_files_lengths;
uint *tmp_tgt_default_groups_lengths;
uint *tmp_tgt_dsns_lengths;
uint *tmp_tgt_filedsns_lengths;
uint *tmp_tgt_drivers_lengths;
uint *tmp_static_link_ids_lengths;
uint tmp_server_names_charlen;
uint tmp_tgt_table_names_charlen;
uint tmp_tgt_dbs_charlen;
uint tmp_tgt_hosts_charlen;
uint tmp_tgt_usernames_charlen;
uint tmp_tgt_passwords_charlen;
uint tmp_tgt_sockets_charlen;
uint tmp_tgt_wrappers_charlen;
uint tmp_tgt_ssl_cas_charlen;
uint tmp_tgt_ssl_capaths_charlen;
uint tmp_tgt_ssl_certs_charlen;
uint tmp_tgt_ssl_ciphers_charlen;
uint tmp_tgt_ssl_keys_charlen;
uint tmp_tgt_default_files_charlen;
uint tmp_tgt_default_groups_charlen;
uint tmp_tgt_dsns_charlen;
uint tmp_tgt_filedsns_charlen;
uint tmp_tgt_drivers_charlen;
uint tmp_static_link_ids_charlen;
uint tmp_server_names_length;
uint tmp_tgt_table_names_length;
uint tmp_tgt_dbs_length;
uint tmp_tgt_hosts_length;
uint tmp_tgt_usernames_length;
uint tmp_tgt_passwords_length;
uint tmp_tgt_sockets_length;
uint tmp_tgt_wrappers_length;
uint tmp_tgt_ssl_cas_length;
uint tmp_tgt_ssl_capaths_length;
uint tmp_tgt_ssl_certs_length;
uint tmp_tgt_ssl_ciphers_length;
uint tmp_tgt_ssl_keys_length;
uint tmp_tgt_default_files_length;
uint tmp_tgt_default_groups_length;
uint tmp_tgt_dsns_length;
uint tmp_tgt_filedsns_length;
uint tmp_tgt_drivers_length;
uint tmp_static_link_ids_length;
uint tmp_tgt_ports_length;
uint tmp_tgt_ssl_vscs_length;
uint tmp_monitoring_binlog_pos_at_failing_length;
uint tmp_link_statuses_length;
} SPIDER_ALTER_TABLE;
typedef struct st_spider_conn_loop_check SPIDER_CONN_LOOP_CHECK;
/* database connection */
typedef struct st_spider_conn
{
uint conn_kind;
char *conn_key;
uint conn_key_length;
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
my_hash_value_type conn_key_hash_value;
#endif
int link_idx;
spider_db_conn *db_conn;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
query_id_t hsc_query_id;
ulonglong hs_pre_age;
ulonglong hs_age;
#endif
uint opened_handlers;
ulonglong conn_id;
ulonglong connection_id;
query_id_t casual_read_query_id;
uint casual_read_current_id;
st_spider_conn *casual_read_base_conn;
pthread_mutex_t mta_conn_mutex;
volatile bool mta_conn_mutex_lock_already;
volatile bool mta_conn_mutex_unlock_later;
SPIDER_FILE_POS mta_conn_mutex_file_pos;
uint join_trx;
int trx_isolation;
bool semi_trx_isolation_chk;
int semi_trx_isolation;
bool semi_trx_chk;
bool semi_trx;
bool trx_start;
bool table_locked;
int table_lock;
bool disable_xa;
bool disable_reconnect;
int autocommit;
int sql_log_off;
int wait_timeout;
sql_mode_t sql_mode;
THD *thd;
void *another_ha_first;
void *another_ha_last;
st_spider_conn *p_small;
st_spider_conn *p_big;
st_spider_conn *c_small;
st_spider_conn *c_big;
longlong priority;
bool server_lost;
bool ignore_dup_key;
char *error_str;
int error_length;
time_t ping_time;
CHARSET_INFO *access_charset;
Time_zone *time_zone;
uint connect_timeout;
uint net_read_timeout;
uint net_write_timeout;
int error_mode;
spider_string default_database;
char *tgt_host;
char *tgt_username;
char *tgt_password;
char *tgt_socket;
char *tgt_wrapper;
char *tgt_db; /* for not joinable tables on different db */
char *tgt_ssl_ca;
char *tgt_ssl_capath;
char *tgt_ssl_cert;
char *tgt_ssl_cipher;
char *tgt_ssl_key;
char *tgt_default_file;
char *tgt_default_group;
char *tgt_dsn;
char *tgt_filedsn;
char *tgt_driver;
long tgt_port;
long tgt_ssl_vsc;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
char *hs_sock;
long hs_port;
#endif
uint tgt_host_length;
uint tgt_username_length;
uint tgt_password_length;
uint tgt_socket_length;
uint tgt_wrapper_length;
uint tgt_db_length;
uint tgt_ssl_ca_length;
uint tgt_ssl_capath_length;
uint tgt_ssl_cert_length;
uint tgt_ssl_cipher_length;
uint tgt_ssl_key_length;
uint tgt_default_file_length;
uint tgt_default_group_length;
uint tgt_dsn_length;
uint tgt_filedsn_length;
uint tgt_driver_length;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
uint hs_sock_length;
#endif
uint dbton_id;
#ifndef WITHOUT_SPIDER_BG_SEARCH
volatile
#endif
void *quick_target;
#ifndef WITHOUT_SPIDER_BG_SEARCH
volatile bool bg_init;
volatile bool bg_break;
volatile bool bg_kill;
volatile bool bg_caller_wait;
volatile bool bg_caller_sync_wait;
volatile bool bg_search;
volatile bool bg_discard_result;
volatile bool bg_direct_sql;
volatile bool bg_exec_sql;
volatile bool bg_get_job_stack;
volatile bool bg_get_job_stack_off;
volatile uint bg_simple_action;
THD *bg_thd;
pthread_t bg_thread;
pthread_cond_t bg_conn_cond;
pthread_mutex_t bg_conn_mutex;
pthread_cond_t bg_conn_sync_cond;
pthread_mutex_t bg_conn_sync_mutex;
pthread_mutex_t bg_conn_chain_mutex;
pthread_mutex_t *bg_conn_chain_mutex_ptr;
volatile void *bg_target;
volatile int *bg_error_num;
volatile ulong bg_sql_type;
pthread_mutex_t bg_job_stack_mutex;
DYNAMIC_ARRAY bg_job_stack;
uint bg_job_stack_id;
const char *bg_job_stack_func_name;
const char *bg_job_stack_file_name;
ulong bg_job_stack_line_no;
uint bg_job_stack_cur_pos;
#endif
#ifndef WITHOUT_SPIDER_BG_SEARCH
volatile
#endif
int *need_mon;
int *conn_need_mon;
bool use_for_active_standby;
bool in_before_query;
bool queued_connect;
bool queued_ping;
bool queued_trx_isolation;
bool queued_semi_trx_isolation;
bool queued_wait_timeout;
bool queued_autocommit;
bool queued_sql_log_off;
bool queued_sql_mode;
bool queued_time_zone;
bool queued_trx_start;
bool queued_xa_start;
bool queued_net_timeout;
SPIDER_SHARE *queued_connect_share;
int queued_connect_link_idx;
ha_spider *queued_ping_spider;
int queued_ping_link_idx;
int queued_trx_isolation_val;
int queued_semi_trx_isolation_val;
int queued_wait_timeout_val;
bool queued_autocommit_val;
bool queued_sql_log_off_val;
sql_mode_t queued_sql_mode_val;
Time_zone *queued_time_zone_val;
XID *queued_xa_start_xid;
#ifdef HA_CAN_BULK_ACCESS
uint bulk_access_requests;
uint bulk_access_sended;
int bulk_access_error_num;
st_spider_conn *bulk_access_next;
#endif
bool disable_connect_retry; /* TRUE if it is unnecessary to
retry to connect after a
connection error */
bool connect_error_with_message;
char connect_error_msg[MYSQL_ERRMSG_SIZE];
int connect_error;
THD *connect_error_thd;
query_id_t connect_error_query_id;
time_t connect_error_time;
#ifdef SPIDER_HAS_GROUP_BY_HANDLER
SPIDER_CONN_HOLDER *conn_holder_for_direct_join;
SPIDER_LINK_IDX_CHAIN *link_idx_chain;
#endif
SPIDER_IP_PORT_CONN *ip_port_conn;
pthread_mutex_t loop_check_mutex;
HASH loop_checked;
uint loop_checked_id;
const char *loop_checked_func_name;
const char *loop_checked_file_name;
ulong loop_checked_line_no;
HASH loop_check_queue;
uint loop_check_queue_id;
const char *loop_check_queue_func_name;
const char *loop_check_queue_file_name;
ulong loop_check_queue_line_no;
SPIDER_CONN_LOOP_CHECK *loop_check_ignored_first;
SPIDER_CONN_LOOP_CHECK *loop_check_ignored_last;
SPIDER_CONN_LOOP_CHECK *loop_check_meraged_first;
SPIDER_CONN_LOOP_CHECK *loop_check_meraged_last;
} SPIDER_CONN;
typedef struct st_spider_lgtm_tblhnd_share
{
char *table_name;
uint table_name_length;
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
my_hash_value_type table_path_hash_value;
#endif
pthread_mutex_t auto_increment_mutex;
volatile bool auto_increment_init;
volatile ulonglong auto_increment_lclval;
ulonglong auto_increment_value;
} SPIDER_LGTM_TBLHND_SHARE;
#ifdef WITH_PARTITION_STORAGE_ENGINE
typedef struct st_spider_patition_handler_share
{
bool clone_bitmap_init;
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
my_hash_value_type table_hash_value;
#endif
query_id_t parallel_search_query_id;
uint no_parts;
TABLE *table;
ha_spider *owner;
ha_spider **handlers;
} SPIDER_PARTITION_HANDLER_SHARE;
#endif
typedef struct st_spider_wide_share
{
char *table_name;
uint table_name_length;
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
my_hash_value_type table_path_hash_value;
#endif
uint use_count;
THR_LOCK lock;
pthread_mutex_t sts_mutex;
pthread_mutex_t crd_mutex;
pthread_mutex_t pt_handler_mutex;
HASH pt_handler_hash;
uint pt_handler_hash_id;
const char *pt_handler_hash_func_name;
const char *pt_handler_hash_file_name;
ulong pt_handler_hash_line_no;
volatile bool sts_init;
volatile bool crd_init;
volatile time_t sts_get_time;
volatile time_t crd_get_time;
ha_statistics stat;
longlong *cardinality;
} SPIDER_WIDE_SHARE;
enum spider_hnd_stage {
SPD_HND_STAGE_NONE,
SPD_HND_STAGE_STORE_LOCK,
SPD_HND_STAGE_EXTERNAL_LOCK,
SPD_HND_STAGE_START_STMT,
SPD_HND_STAGE_EXTRA,
SPD_HND_STAGE_COND_PUSH,
SPD_HND_STAGE_COND_POP,
SPD_HND_STAGE_INFO_PUSH,
SPD_HND_STAGE_SET_TOP_TABLE_AND_FIELDS,
SPD_HND_STAGE_CLEAR_TOP_TABLE_FIELDS
};
typedef struct st_spider_wide_handler
{
spider_hnd_stage stage;
handler *stage_executor;
THR_LOCK_DATA lock;
SPIDER_TRX *trx;
uchar *searched_bitmap;
uchar *ft_discard_bitmap;
uchar *position_bitmap;
uchar *idx_read_bitmap;
uchar *idx_write_bitmap;
uchar *rnd_read_bitmap;
uchar *rnd_write_bitmap;
SPIDER_CONDITION *condition;
void *owner;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
uint32 *hs_pushed_ret_fields;
#endif
#endif
#ifdef WITH_PARTITION_STORAGE_ENGINE
SPIDER_PARTITION_HANDLER_SHARE *partition_handler_share;
#endif
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
List<Item> *direct_update_fields;
List<Item> *direct_update_values;
#endif
TABLE *top_table;
Field **top_table_field;
TABLE_SHARE *top_share;
enum thr_lock_type lock_type;
uchar lock_table_type;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
uint32 hs_pushed_strref_num;
#endif
#endif
int lock_mode;
int external_lock_type;
int cond_check_error;
uint sql_command;
uint top_table_fields;
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
#ifdef INFO_KIND_FORCE_LIMIT_BEGIN
longlong info_limit;
#endif
#endif
#ifdef HA_CAN_BULK_ACCESS
ulonglong external_lock_cnt;
#endif
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
size_t hs_pushed_ret_fields_num;
size_t hs_pushed_ret_fields_size;
size_t hs_pushed_lcl_fields_num;
#endif
#endif
bool between_flg;
bool idx_bitmap_is_set;
bool rnd_bitmap_is_set;
bool position_bitmap_init;
bool semi_trx_isolation_chk;
bool semi_trx_chk;
bool low_priority;
bool high_priority;
bool insert_delayed;
bool consistent_snapshot;
bool quick_mode;
bool keyread;
bool update_request;
bool ignore_dup_key;
bool write_can_replace;
bool insert_with_update;
bool cond_check;
bool set_top_table_fields;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
bool hs_increment;
bool hs_decrement;
#endif
#endif
bool semi_table_lock;
} SPIDER_WIDE_HANDLER;
typedef struct st_spider_transaction
{
bool trx_start;
bool trx_xa;
bool trx_consistent_snapshot;
bool trx_xa_prepared;
bool use_consistent_snapshot;
bool internal_xa;
uint internal_xa_snapshot;
query_id_t query_id;
bool tmp_flg;
bool registed_allocated_thds;
bool updated_in_this_trx;
THD *thd;
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
my_hash_value_type thd_hash_value;
#endif
XID xid;
HASH trx_conn_hash;
uint trx_conn_hash_id;
const char *trx_conn_hash_func_name;
const char *trx_conn_hash_file_name;
ulong trx_conn_hash_line_no;
HASH trx_another_conn_hash;
uint trx_another_conn_hash_id;
const char *trx_another_conn_hash_func_name;
const char *trx_another_conn_hash_file_name;
ulong trx_another_conn_hash_line_no;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
HASH trx_hs_r_conn_hash;
uint trx_hs_r_conn_hash_id;
const char *trx_hs_r_conn_hash_func_name;
const char *trx_hs_r_conn_hash_file_name;
ulong trx_hs_r_conn_hash_line_no;
HASH trx_hs_w_conn_hash;
uint trx_hs_w_conn_hash_id;
const char *trx_hs_w_conn_hash_func_name;
const char *trx_hs_w_conn_hash_file_name;
ulong trx_hs_w_conn_hash_line_no;
#endif
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
HASH trx_direct_hs_r_conn_hash;
uint trx_direct_hs_r_conn_hash_id;
const char *trx_direct_hs_r_conn_hash_func_name;
const char *trx_direct_hs_r_conn_hash_file_name;
ulong trx_direct_hs_r_conn_hash_line_no;
HASH trx_direct_hs_w_conn_hash;
uint trx_direct_hs_w_conn_hash_id;
const char *trx_direct_hs_w_conn_hash_func_name;
const char *trx_direct_hs_w_conn_hash_file_name;
ulong trx_direct_hs_w_conn_hash_line_no;
#endif
HASH trx_alter_table_hash;
uint trx_alter_table_hash_id;
const char *trx_alter_table_hash_func_name;
const char *trx_alter_table_hash_file_name;
ulong trx_alter_table_hash_line_no;
HASH trx_ha_hash;
uint trx_ha_hash_id;
const char *trx_ha_hash_func_name;
const char *trx_ha_hash_file_name;
ulong trx_ha_hash_line_no;
uint trx_ha_reuse_count;
XID_STATE internal_xid_state;
SPIDER_CONN *join_trx_top;
ulonglong spider_thread_id;
ulonglong trx_conn_adjustment;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
ulonglong trx_hs_r_conn_adjustment;
ulonglong trx_hs_w_conn_adjustment;
#endif
uint locked_connections;
ulonglong direct_update_count;
ulonglong direct_delete_count;
ulonglong direct_order_limit_count;
ulonglong direct_aggregate_count;
ulonglong parallel_search_count;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
ulonglong hs_result_free_count;
#endif
#ifdef HA_CAN_BULK_ACCESS
SPIDER_CONN *bulk_access_conn_first;
SPIDER_CONN *bulk_access_conn_last;
#endif
pthread_mutex_t *udf_table_mutexes;
CHARSET_INFO *udf_access_charset;
spider_string *udf_set_names;
time_t mem_calc_merge_time;
const char *alloc_func_name[SPIDER_MEM_CALC_LIST_NUM];
const char *alloc_file_name[SPIDER_MEM_CALC_LIST_NUM];
ulong alloc_line_no[SPIDER_MEM_CALC_LIST_NUM];
ulonglong total_alloc_mem[SPIDER_MEM_CALC_LIST_NUM];
longlong current_alloc_mem[SPIDER_MEM_CALC_LIST_NUM];
ulonglong alloc_mem_count[SPIDER_MEM_CALC_LIST_NUM];
ulonglong free_mem_count[SPIDER_MEM_CALC_LIST_NUM];
ulonglong total_alloc_mem_buffer[SPIDER_MEM_CALC_LIST_NUM];
longlong current_alloc_mem_buffer[SPIDER_MEM_CALC_LIST_NUM];
ulonglong alloc_mem_count_buffer[SPIDER_MEM_CALC_LIST_NUM];
ulonglong free_mem_count_buffer[SPIDER_MEM_CALC_LIST_NUM];
MEM_ROOT mem_root;
/* for transaction level query */
SPIDER_SHARE *tmp_share;
char *tmp_connect_info[SPIDER_TMP_SHARE_CHAR_PTR_COUNT];
uint tmp_connect_info_length[SPIDER_TMP_SHARE_UINT_COUNT];
long tmp_long[SPIDER_TMP_SHARE_LONG_COUNT];
longlong tmp_longlong[SPIDER_TMP_SHARE_LONGLONG_COUNT];
ha_spider *tmp_spider;
int tmp_need_mon;
spider_db_handler *tmp_dbton_handler[SPIDER_DBTON_SIZE];
} SPIDER_TRX;
typedef struct st_spider_share
{
char *table_name;
uint table_name_length;
uint use_count;
uint link_count;
uint all_link_count;
uint link_bitmap_size;
pthread_mutex_t mutex;
pthread_mutex_t sts_mutex;
pthread_mutex_t crd_mutex;
/*
pthread_mutex_t auto_increment_mutex;
*/
TABLE_SHARE *table_share;
SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share;
#ifdef SPIDER_HAS_HASH_VALUE_TYPE
my_hash_value_type table_name_hash_value;
#ifdef WITH_PARTITION_STORAGE_ENGINE
my_hash_value_type table_path_hash_value;
#endif
#endif
volatile bool init;
volatile bool init_error;
volatile time_t init_error_time;
volatile bool link_status_init;
uchar *table_mon_mutex_bitmap;
volatile bool sts_init;
volatile time_t sts_get_time;
#ifndef WITHOUT_SPIDER_BG_SEARCH
volatile time_t bg_sts_try_time;
volatile double bg_sts_interval;
volatile int bg_sts_mode;
#ifdef WITH_PARTITION_STORAGE_ENGINE
volatile int bg_sts_sync;
#endif
volatile bool bg_sts_init;
volatile bool bg_sts_kill;
volatile bool bg_sts_thd_wait;
THD *bg_sts_thd;
pthread_t bg_sts_thread;
pthread_cond_t bg_sts_cond;
pthread_cond_t bg_sts_sync_cond;
volatile bool crd_init;
#endif
volatile time_t crd_get_time;
#ifndef WITHOUT_SPIDER_BG_SEARCH
volatile time_t bg_crd_try_time;
volatile double bg_crd_interval;
volatile int bg_crd_mode;
#ifdef WITH_PARTITION_STORAGE_ENGINE
volatile int bg_crd_sync;
#endif
volatile bool bg_crd_init;
volatile bool bg_crd_kill;
volatile bool bg_crd_thd_wait;
THD *bg_crd_thd;
pthread_t bg_crd_thread;
pthread_cond_t bg_crd_cond;
pthread_cond_t bg_crd_sync_cond;
#endif
#ifndef WITHOUT_SPIDER_BG_SEARCH
volatile bool bg_mon_init;
volatile bool bg_mon_kill;
THD **bg_mon_thds;
pthread_t *bg_mon_threads;
pthread_mutex_t *bg_mon_mutexes;
pthread_cond_t *bg_mon_conds;
pthread_cond_t *bg_mon_sleep_conds;
#endif
#ifndef WITHOUT_SPIDER_BG_SEARCH
/* static bg thread for sts and crd */
TABLE table;
ha_spider *sts_spider;
ha_spider *crd_spider;
SPIDER_THREAD *sts_thread;
SPIDER_THREAD *crd_thread;