-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathspd_table.cc
11211 lines (10797 loc) · 367 KB
/
spd_table.cc
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 */
#define MYSQL_SERVER 1
#include <my_global.h>
#include "mysql_version.h"
#include "spd_environ.h"
#if MYSQL_VERSION_ID < 50500
#include "mysql_priv.h"
#include <mysql/plugin.h>
#else
#include "sql_priv.h"
#include "probes_mysql.h"
#include "my_getopt.h"
#include "sql_class.h"
#include "sql_partition.h"
#include "sql_servers.h"
#include "sql_select.h"
#include "tztime.h"
#include "sql_parse.h"
#endif
#include "spd_err.h"
#include "spd_param.h"
#include "spd_db_include.h"
#include "spd_include.h"
#include "spd_sys_table.h"
#include "ha_spider.h"
#include "spd_trx.h"
#include "spd_db_conn.h"
#include "spd_table.h"
#include "spd_conn.h"
#include "spd_ping_table.h"
#include "spd_direct_sql.h"
#include "spd_malloc.h"
#include "spd_group_by_handler.h"
#include "spd_init_query.h"
/* Background thread management */
#ifdef SPIDER_HAS_NEXT_THREAD_ID
#define SPIDER_set_next_thread_id(A)
MYSQL_THD create_thd();
void destroy_thd(MYSQL_THD thd);
#else
ulong *spd_db_att_thread_id;
inline void SPIDER_set_next_thread_id(THD *A)
{
pthread_mutex_lock(&LOCK_thread_count);
A->thread_id = (*spd_db_att_thread_id)++;
pthread_mutex_unlock(&LOCK_thread_count);
}
MYSQL_THD create_thd()
{
THD *thd = SPIDER_new_THD(next_thread_id());
if (thd)
{
thd->thread_stack = (char*) &thd;
thd->store_globals();
thd->set_command(COM_DAEMON);
thd->security_ctx->host_or_ip = "";
}
return thd;
}
void destroy_thd(MYSQL_THD thd)
{
delete thd;
}
#endif
inline MYSQL_THD spider_create_sys_thd(SPIDER_THREAD *thread)
{
THD *thd = create_thd();
if (thd)
{
SPIDER_set_next_thread_id(thd);
thd->mysys_var->current_cond = &thread->cond;
thd->mysys_var->current_mutex = &thread->mutex;
}
return thd;
}
inline void spider_destroy_sys_thd(MYSQL_THD thd)
{
destroy_thd(thd);
}
inline MYSQL_THD spider_create_thd()
{
THD *thd;
my_thread_init();
if (!(thd = new THD(next_thread_id())))
my_thread_end();
else
{
#ifdef HAVE_PSI_INTERFACE
mysql_thread_set_psi_id(thd->thread_id);
#endif
thd->thread_stack = (char *) &thd;
thd->store_globals();
}
return thd;
}
inline void spider_destroy_thd(MYSQL_THD thd)
{
delete thd;
}
#ifdef SPIDER_XID_USES_xid_cache_iterate
#else
#ifdef XID_CACHE_IS_SPLITTED
uint *spd_db_att_xid_cache_split_num;
#endif
pthread_mutex_t *spd_db_att_LOCK_xid_cache;
HASH *spd_db_att_xid_cache;
#endif
struct charset_info_st *spd_charset_utf8_bin;
const char **spd_defaults_extra_file;
const char **spd_defaults_file;
const char **spd_mysqld_unix_port;
uint *spd_mysqld_port;
bool volatile *spd_abort_loop;
Time_zone *spd_tz_system;
static int *spd_mysqld_server_started;
static pthread_mutex_t *spd_LOCK_server_started;
static pthread_cond_t *spd_COND_server_started;
extern long spider_conn_mutex_id;
handlerton *spider_hton_ptr;
SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE];
extern SPIDER_DBTON spider_dbton_mysql;
extern SPIDER_DBTON spider_dbton_mariadb;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
extern SPIDER_DBTON spider_dbton_handlersocket;
#endif
#ifdef HAVE_ORACLE_OCI
extern SPIDER_DBTON spider_dbton_oracle;
#endif
#ifndef WITHOUT_SPIDER_BG_SEARCH
SPIDER_THREAD *spider_table_sts_threads;
SPIDER_THREAD *spider_table_crd_threads;
#endif
#ifdef HAVE_PSI_INTERFACE
PSI_mutex_key spd_key_mutex_tbl;
PSI_mutex_key spd_key_mutex_init_error_tbl;
#ifdef WITH_PARTITION_STORAGE_ENGINE
PSI_mutex_key spd_key_mutex_wide_share;
#endif
PSI_mutex_key spd_key_mutex_lgtm_tblhnd_share;
PSI_mutex_key spd_key_mutex_conn;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
PSI_mutex_key spd_key_mutex_hs_r_conn;
PSI_mutex_key spd_key_mutex_hs_w_conn;
#endif
PSI_mutex_key spd_key_mutex_open_conn;
PSI_mutex_key spd_key_mutex_allocated_thds;
PSI_mutex_key spd_key_mutex_mon_table_cache;
PSI_mutex_key spd_key_mutex_udf_table_mon;
PSI_mutex_key spd_key_mutex_mta_conn;
#ifndef WITHOUT_SPIDER_BG_SEARCH
PSI_mutex_key spd_key_mutex_bg_conn_chain;
PSI_mutex_key spd_key_mutex_bg_conn_sync;
PSI_mutex_key spd_key_mutex_bg_conn;
PSI_mutex_key spd_key_mutex_bg_job_stack;
PSI_mutex_key spd_key_mutex_bg_mon;
PSI_mutex_key spd_key_mutex_bg_direct_sql;
#endif
PSI_mutex_key spd_key_mutex_mon_list_caller;
PSI_mutex_key spd_key_mutex_mon_list_receptor;
PSI_mutex_key spd_key_mutex_mon_list_monitor;
PSI_mutex_key spd_key_mutex_mon_list_update_status;
PSI_mutex_key spd_key_mutex_share;
PSI_mutex_key spd_key_mutex_share_sts;
PSI_mutex_key spd_key_mutex_share_crd;
PSI_mutex_key spd_key_mutex_share_auto_increment;
#ifdef WITH_PARTITION_STORAGE_ENGINE
PSI_mutex_key spd_key_mutex_wide_share_sts;
PSI_mutex_key spd_key_mutex_wide_share_crd;
PSI_mutex_key spd_key_mutex_pt_handler;
#endif
PSI_mutex_key spd_key_mutex_udf_table;
PSI_mutex_key spd_key_mutex_mem_calc;
PSI_mutex_key spd_key_thread_id;
PSI_mutex_key spd_key_conn_id;
PSI_mutex_key spd_key_mutex_ipport_count;
PSI_mutex_key spd_key_mutex_conn_i;
#ifndef WITHOUT_SPIDER_BG_SEARCH
PSI_mutex_key spd_key_mutex_bg_stss;
PSI_mutex_key spd_key_mutex_bg_crds;
#endif
PSI_mutex_key spd_key_mutex_conn_loop_check;
static PSI_mutex_info all_spider_mutexes[]=
{
{ &spd_key_mutex_tbl, "tbl", PSI_FLAG_GLOBAL},
{ &spd_key_mutex_init_error_tbl, "init_error_tbl", PSI_FLAG_GLOBAL},
#ifdef WITH_PARTITION_STORAGE_ENGINE
{ &spd_key_mutex_wide_share, "wide_share", PSI_FLAG_GLOBAL},
#endif
{ &spd_key_mutex_lgtm_tblhnd_share, "lgtm_tblhnd_share", PSI_FLAG_GLOBAL},
{ &spd_key_mutex_conn, "conn", PSI_FLAG_GLOBAL},
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
{ &spd_key_mutex_hs_r_conn, "hs_r_conn", PSI_FLAG_GLOBAL},
{ &spd_key_mutex_hs_w_conn, "hs_w_conn", PSI_FLAG_GLOBAL},
#endif
{ &spd_key_mutex_open_conn, "open_conn", PSI_FLAG_GLOBAL},
{ &spd_key_mutex_allocated_thds, "allocated_thds", PSI_FLAG_GLOBAL},
{ &spd_key_mutex_mon_table_cache, "mon_table_cache", PSI_FLAG_GLOBAL},
{ &spd_key_mutex_udf_table_mon, "udf_table_mon", PSI_FLAG_GLOBAL},
{ &spd_key_mutex_mem_calc, "mem_calc", PSI_FLAG_GLOBAL},
{ &spd_key_thread_id, "thread_id", PSI_FLAG_GLOBAL},
{ &spd_key_conn_id, "conn_id", PSI_FLAG_GLOBAL},
{ &spd_key_mutex_ipport_count, "ipport_count", PSI_FLAG_GLOBAL},
#ifndef WITHOUT_SPIDER_BG_SEARCH
{ &spd_key_mutex_bg_stss, "bg_stss", PSI_FLAG_GLOBAL},
{ &spd_key_mutex_bg_crds, "bg_crds", PSI_FLAG_GLOBAL},
#endif
{ &spd_key_mutex_conn_i, "conn_i", 0},
{ &spd_key_mutex_mta_conn, "mta_conn", 0},
#ifndef WITHOUT_SPIDER_BG_SEARCH
{ &spd_key_mutex_bg_conn_chain, "bg_conn_chain", 0},
{ &spd_key_mutex_bg_conn_sync, "bg_conn_sync", 0},
{ &spd_key_mutex_bg_conn, "bg_conn", 0},
{ &spd_key_mutex_bg_job_stack, "bg_job_stack", 0},
{ &spd_key_mutex_bg_mon, "bg_mon", 0},
{ &spd_key_mutex_bg_direct_sql, "bg_direct_sql", 0},
#endif
{ &spd_key_mutex_mon_list_caller, "mon_list_caller", 0},
{ &spd_key_mutex_mon_list_receptor, "mon_list_receptor", 0},
{ &spd_key_mutex_mon_list_monitor, "mon_list_monitor", 0},
{ &spd_key_mutex_mon_list_update_status, "mon_list_update_status", 0},
{ &spd_key_mutex_share, "share", 0},
{ &spd_key_mutex_share_sts, "share_sts", 0},
{ &spd_key_mutex_share_crd, "share_crd", 0},
{ &spd_key_mutex_share_auto_increment, "share_auto_increment", 0},
#ifdef WITH_PARTITION_STORAGE_ENGINE
{ &spd_key_mutex_wide_share_sts, "wide_share_sts", 0},
{ &spd_key_mutex_wide_share_crd, "wide_share_crd", 0},
{ &spd_key_mutex_pt_handler, "pt_handler", 0},
#endif
{ &spd_key_mutex_udf_table, "udf_table", 0},
{ &spd_key_mutex_conn_loop_check, "conn_loop_check", 0},
};
#ifndef WITHOUT_SPIDER_BG_SEARCH
PSI_cond_key spd_key_cond_bg_conn_sync;
PSI_cond_key spd_key_cond_bg_conn;
PSI_cond_key spd_key_cond_bg_sts;
PSI_cond_key spd_key_cond_bg_sts_sync;
PSI_cond_key spd_key_cond_bg_crd;
PSI_cond_key spd_key_cond_bg_crd_sync;
PSI_cond_key spd_key_cond_bg_mon;
PSI_cond_key spd_key_cond_bg_mon_sleep;
PSI_cond_key spd_key_cond_bg_direct_sql;
#endif
PSI_cond_key spd_key_cond_udf_table_mon;
PSI_cond_key spd_key_cond_conn_i;
#ifndef WITHOUT_SPIDER_BG_SEARCH
PSI_cond_key spd_key_cond_bg_stss;
PSI_cond_key spd_key_cond_bg_sts_syncs;
PSI_cond_key spd_key_cond_bg_crds;
PSI_cond_key spd_key_cond_bg_crd_syncs;
#endif
static PSI_cond_info all_spider_conds[] = {
#ifndef WITHOUT_SPIDER_BG_SEARCH
{&spd_key_cond_bg_conn_sync, "bg_conn_sync", 0},
{&spd_key_cond_bg_conn, "bg_conn", 0},
{&spd_key_cond_bg_sts, "bg_sts", 0},
{&spd_key_cond_bg_sts_sync, "bg_sts_sync", 0},
{&spd_key_cond_bg_crd, "bg_crd", 0},
{&spd_key_cond_bg_crd_sync, "bg_crd_sync", 0},
{&spd_key_cond_bg_mon, "bg_mon", 0},
{&spd_key_cond_bg_mon_sleep, "bg_mon_sleep", 0},
{&spd_key_cond_bg_direct_sql, "bg_direct_sql", 0},
#endif
{&spd_key_cond_udf_table_mon, "udf_table_mon", 0},
{&spd_key_cond_conn_i, "conn_i", 0},
#ifndef WITHOUT_SPIDER_BG_SEARCH
{&spd_key_cond_bg_stss, "bg_stss", 0},
{&spd_key_cond_bg_sts_syncs, "bg_sts_syncs", 0},
{&spd_key_cond_bg_crds, "bg_crds", 0},
{&spd_key_cond_bg_crd_syncs, "bg_crd_syncs", 0},
#endif
};
#ifndef WITHOUT_SPIDER_BG_SEARCH
PSI_thread_key spd_key_thd_bg;
PSI_thread_key spd_key_thd_bg_sts;
PSI_thread_key spd_key_thd_bg_crd;
PSI_thread_key spd_key_thd_bg_mon;
PSI_thread_key spd_key_thd_bg_stss;
PSI_thread_key spd_key_thd_bg_crds;
#endif
static PSI_thread_info all_spider_threads[] = {
#ifndef WITHOUT_SPIDER_BG_SEARCH
{&spd_key_thd_bg, "bg", 0},
{&spd_key_thd_bg_sts, "bg_sts", 0},
{&spd_key_thd_bg_crd, "bg_crd", 0},
{&spd_key_thd_bg_mon, "bg_mon", 0},
{&spd_key_thd_bg_stss, "bg_stss", 0},
{&spd_key_thd_bg_crds, "bg_crds", 0},
#endif
};
#endif
extern HASH spider_open_connections;
extern HASH spider_ipport_conns;
extern uint spider_open_connections_id;
extern const char *spider_open_connections_func_name;
extern const char *spider_open_connections_file_name;
extern ulong spider_open_connections_line_no;
extern pthread_mutex_t spider_conn_mutex;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
extern HASH spider_hs_r_conn_hash;
extern uint spider_hs_r_conn_hash_id;
extern const char *spider_hs_r_conn_hash_func_name;
extern const char *spider_hs_r_conn_hash_file_name;
extern ulong spider_hs_r_conn_hash_line_no;
extern pthread_mutex_t spider_hs_r_conn_mutex;
extern HASH spider_hs_w_conn_hash;
extern uint spider_hs_w_conn_hash_id;
extern const char *spider_hs_w_conn_hash_func_name;
extern const char *spider_hs_w_conn_hash_file_name;
extern ulong spider_hs_w_conn_hash_line_no;
extern pthread_mutex_t spider_hs_w_conn_mutex;
#endif
extern HASH *spider_udf_table_mon_list_hash;
extern uint spider_udf_table_mon_list_hash_id;
extern const char *spider_udf_table_mon_list_hash_func_name;
extern const char *spider_udf_table_mon_list_hash_file_name;
extern ulong spider_udf_table_mon_list_hash_line_no;
extern pthread_mutex_t *spider_udf_table_mon_mutexes;
extern pthread_cond_t *spider_udf_table_mon_conds;
extern pthread_mutex_t spider_open_conn_mutex;
extern pthread_mutex_t spider_mon_table_cache_mutex;
extern DYNAMIC_ARRAY spider_mon_table_cache;
extern uint spider_mon_table_cache_id;
extern const char *spider_mon_table_cache_func_name;
extern const char *spider_mon_table_cache_file_name;
extern ulong spider_mon_table_cache_line_no;
HASH spider_open_tables;
uint spider_open_tables_id;
const char *spider_open_tables_func_name;
const char *spider_open_tables_file_name;
ulong spider_open_tables_line_no;
pthread_mutex_t spider_tbl_mutex;
HASH spider_init_error_tables;
uint spider_init_error_tables_id;
const char *spider_init_error_tables_func_name;
const char *spider_init_error_tables_file_name;
ulong spider_init_error_tables_line_no;
pthread_mutex_t spider_init_error_tbl_mutex;
extern pthread_mutex_t spider_thread_id_mutex;
extern pthread_mutex_t spider_conn_id_mutex;
extern pthread_mutex_t spider_ipport_conn_mutex;
#ifdef WITH_PARTITION_STORAGE_ENGINE
HASH spider_open_wide_share;
uint spider_open_wide_share_id;
const char *spider_open_wide_share_func_name;
const char *spider_open_wide_share_file_name;
ulong spider_open_wide_share_line_no;
pthread_mutex_t spider_wide_share_mutex;
#endif
HASH spider_lgtm_tblhnd_share_hash;
uint spider_lgtm_tblhnd_share_hash_id;
const char *spider_lgtm_tblhnd_share_hash_func_name;
const char *spider_lgtm_tblhnd_share_hash_file_name;
ulong spider_lgtm_tblhnd_share_hash_line_no;
pthread_mutex_t spider_lgtm_tblhnd_share_mutex;
HASH spider_allocated_thds;
uint spider_allocated_thds_id;
const char *spider_allocated_thds_func_name;
const char *spider_allocated_thds_file_name;
ulong spider_allocated_thds_line_no;
pthread_mutex_t spider_allocated_thds_mutex;
#ifndef WITHOUT_SPIDER_BG_SEARCH
pthread_attr_t spider_pt_attr;
#endif
extern pthread_mutex_t spider_mem_calc_mutex;
extern const char *spider_alloc_func_name[SPIDER_MEM_CALC_LIST_NUM];
extern const char *spider_alloc_file_name[SPIDER_MEM_CALC_LIST_NUM];
extern ulong spider_alloc_line_no[SPIDER_MEM_CALC_LIST_NUM];
extern ulonglong spider_total_alloc_mem[SPIDER_MEM_CALC_LIST_NUM];
extern longlong spider_current_alloc_mem[SPIDER_MEM_CALC_LIST_NUM];
extern ulonglong spider_alloc_mem_count[SPIDER_MEM_CALC_LIST_NUM];
extern ulonglong spider_free_mem_count[SPIDER_MEM_CALC_LIST_NUM];
static char spider_wild_many = '%', spider_wild_one = '_',
spider_wild_prefix='\\';
static char spider_unique_id_buf[1 + 12 + 1 + 16 + 1 + 1];
LEX_CSTRING spider_unique_id;
// for spider_open_tables
uchar *spider_tbl_get_key(
SPIDER_SHARE *share,
size_t *length,
my_bool not_used __attribute__ ((unused))
) {
DBUG_ENTER("spider_tbl_get_key");
*length = share->table_name_length;
DBUG_RETURN((uchar*) share->table_name);
}
uchar *spider_wide_share_get_key(
SPIDER_WIDE_SHARE *share,
size_t *length,
my_bool not_used __attribute__ ((unused))
) {
DBUG_ENTER("spider_wide_share_get_key");
*length = share->table_name_length;
DBUG_RETURN((uchar*) share->table_name);
}
#ifdef WITH_PARTITION_STORAGE_ENGINE
uchar *spider_pt_handler_share_get_key(
SPIDER_PARTITION_HANDLER_SHARE *share,
size_t *length,
my_bool not_used __attribute__ ((unused))
) {
DBUG_ENTER("spider_pt_handler_share_get_key");
*length = sizeof(ha_spider *);
DBUG_RETURN((uchar*) share->owner);
}
#endif
uchar *spider_lgtm_tblhnd_share_hash_get_key(
SPIDER_LGTM_TBLHND_SHARE *share,
size_t *length,
my_bool not_used __attribute__ ((unused))
) {
DBUG_ENTER("spider_lgtm_tblhnd_share_hash_get_key");
*length = share->table_name_length;
DBUG_RETURN((uchar*) share->table_name);
}
uchar *spider_link_get_key(
SPIDER_LINK_FOR_HASH *link_for_hash,
size_t *length,
my_bool not_used __attribute__ ((unused))
) {
DBUG_ENTER("spider_link_get_key");
*length = link_for_hash->db_table_str->length();
DBUG_RETURN((uchar*) link_for_hash->db_table_str->ptr());
}
uchar *spider_ha_get_key(
ha_spider *spider,
size_t *length,
my_bool not_used __attribute__ ((unused))
) {
DBUG_ENTER("spider_ha_get_key");
*length = spider->share->table_name_length;
DBUG_RETURN((uchar*) spider->share->table_name);
}
uchar *spider_udf_tbl_mon_list_key(
SPIDER_TABLE_MON_LIST *table_mon_list,
size_t *length,
my_bool not_used __attribute__ ((unused))
) {
DBUG_ENTER("spider_udf_tbl_mon_list_key");
DBUG_PRINT("info",("spider hash key=%s", table_mon_list->key));
DBUG_PRINT("info",("spider hash key length=%u", table_mon_list->key_length));
*length = table_mon_list->key_length;
DBUG_RETURN((uchar*) table_mon_list->key);
}
uchar *spider_allocated_thds_get_key(
THD *thd,
size_t *length,
my_bool not_used __attribute__ ((unused))
) {
DBUG_ENTER("spider_allocated_thds_get_key");
*length = sizeof(THD *);
DBUG_RETURN((uchar*) thd);
}
#ifdef HAVE_PSI_INTERFACE
static void init_spider_psi_keys()
{
DBUG_ENTER("init_spider_psi_keys");
if (PSI_server == NULL)
DBUG_VOID_RETURN;
PSI_server->register_mutex("spider", all_spider_mutexes,
array_elements(all_spider_mutexes));
PSI_server->register_cond("spider", all_spider_conds,
array_elements(all_spider_conds));
PSI_server->register_thread("spider", all_spider_threads,
array_elements(all_spider_threads));
DBUG_VOID_RETURN;
}
#endif
int spider_get_server(
SPIDER_SHARE *share,
int link_idx
) {
MEM_ROOT mem_root;
int error_num, length;
FOREIGN_SERVER *server, server_buf;
DBUG_ENTER("spider_get_server");
SPD_INIT_ALLOC_ROOT(&mem_root, 128, 0, MYF(MY_WME));
if (!(server
= get_server_by_name(&mem_root, share->server_names[link_idx],
&server_buf)))
{
error_num = ER_FOREIGN_SERVER_DOESNT_EXIST;
goto error;
}
if (!share->tgt_wrappers[link_idx] && server->scheme)
{
share->tgt_wrappers_lengths[link_idx] = strlen(server->scheme);
if (!(share->tgt_wrappers[link_idx] =
spider_create_string(server->scheme,
share->tgt_wrappers_lengths[link_idx])))
{
error_num = HA_ERR_OUT_OF_MEM;
goto error;
}
DBUG_PRINT("info",("spider tgt_wrappers=%s",
share->tgt_wrappers[link_idx]));
}
if (!share->tgt_hosts[link_idx] && server->host)
{
share->tgt_hosts_lengths[link_idx] = strlen(server->host);
if (!(share->tgt_hosts[link_idx] =
spider_create_string(server->host, share->tgt_hosts_lengths[link_idx])))
{
error_num = HA_ERR_OUT_OF_MEM;
goto error;
}
DBUG_PRINT("info",("spider tgt_hosts=%s", share->tgt_hosts[link_idx]));
}
if (share->tgt_ports[link_idx] == -1)
{
share->tgt_ports[link_idx] = server->port;
DBUG_PRINT("info",("spider tgt_ports=%ld", share->tgt_ports[link_idx]));
}
if (!share->tgt_sockets[link_idx] && server->socket)
{
share->tgt_sockets_lengths[link_idx] = strlen(server->socket);
if (!(share->tgt_sockets[link_idx] =
spider_create_string(server->socket,
share->tgt_sockets_lengths[link_idx])))
{
error_num = HA_ERR_OUT_OF_MEM;
goto error;
}
DBUG_PRINT("info",("spider tgt_sockets=%s", share->tgt_sockets[link_idx]));
}
if (!share->tgt_dbs[link_idx] && server->db && (length = strlen(server->db)))
{
share->tgt_dbs_lengths[link_idx] = length;
if (!(share->tgt_dbs[link_idx] =
spider_create_string(server->db, length)))
{
error_num = HA_ERR_OUT_OF_MEM;
goto error;
}
DBUG_PRINT("info",("spider tgt_dbs=%s", share->tgt_dbs[link_idx]));
}
if (!share->tgt_usernames[link_idx] && server->username)
{
share->tgt_usernames_lengths[link_idx] = strlen(server->username);
if (!(share->tgt_usernames[link_idx] =
spider_create_string(server->username,
share->tgt_usernames_lengths[link_idx])))
{
error_num = HA_ERR_OUT_OF_MEM;
goto error;
}
DBUG_PRINT("info",("spider tgt_usernames=%s",
share->tgt_usernames[link_idx]));
}
if (!share->tgt_passwords[link_idx] && server->password)
{
share->tgt_passwords_lengths[link_idx] = strlen(server->password);
if (!(share->tgt_passwords[link_idx] =
spider_create_string(server->password,
share->tgt_passwords_lengths[link_idx])))
{
error_num = HA_ERR_OUT_OF_MEM;
goto error;
}
DBUG_PRINT("info",("spider tgt_passwords=%s",
share->tgt_passwords[link_idx]));
}
free_root(&mem_root, MYF(0));
DBUG_RETURN(0);
error:
free_root(&mem_root, MYF(0));
my_error(error_num, MYF(0), share->server_names[link_idx]);
DBUG_RETURN(error_num);
}
int spider_free_share_alloc(
SPIDER_SHARE *share
) {
int roop_count;
DBUG_ENTER("spider_free_share_alloc");
for (roop_count = SPIDER_DBTON_SIZE - 1; roop_count >= 0; roop_count--)
{
if (share->dbton_share[roop_count])
{
delete share->dbton_share[roop_count];
share->dbton_share[roop_count] = NULL;
}
}
if (share->server_names)
{
for (roop_count = 0; roop_count < (int) share->server_names_length;
roop_count++)
{
if (share->server_names[roop_count])
spider_free(spider_current_trx, share->server_names[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->server_names, MYF(0));
}
if (share->tgt_table_names)
{
for (roop_count = 0; roop_count < (int) share->tgt_table_names_length;
roop_count++)
{
if (share->tgt_table_names[roop_count])
spider_free(spider_current_trx, share->tgt_table_names[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->tgt_table_names, MYF(0));
}
if (share->tgt_dbs)
{
for (roop_count = 0; roop_count < (int) share->tgt_dbs_length;
roop_count++)
{
if (share->tgt_dbs[roop_count])
spider_free(spider_current_trx, share->tgt_dbs[roop_count], MYF(0));
}
spider_free(spider_current_trx, share->tgt_dbs, MYF(0));
}
if (share->tgt_hosts)
{
for (roop_count = 0; roop_count < (int) share->tgt_hosts_length;
roop_count++)
{
if (share->tgt_hosts[roop_count])
spider_free(spider_current_trx, share->tgt_hosts[roop_count], MYF(0));
}
spider_free(spider_current_trx, share->tgt_hosts, MYF(0));
}
if (share->tgt_usernames)
{
for (roop_count = 0; roop_count < (int) share->tgt_usernames_length;
roop_count++)
{
if (share->tgt_usernames[roop_count])
spider_free(spider_current_trx, share->tgt_usernames[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->tgt_usernames, MYF(0));
}
if (share->tgt_passwords)
{
for (roop_count = 0; roop_count < (int) share->tgt_passwords_length;
roop_count++)
{
if (share->tgt_passwords[roop_count])
spider_free(spider_current_trx, share->tgt_passwords[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->tgt_passwords, MYF(0));
}
if (share->tgt_sockets)
{
for (roop_count = 0; roop_count < (int) share->tgt_sockets_length;
roop_count++)
{
if (share->tgt_sockets[roop_count])
spider_free(spider_current_trx, share->tgt_sockets[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->tgt_sockets, MYF(0));
}
if (share->tgt_wrappers)
{
for (roop_count = 0; roop_count < (int) share->tgt_wrappers_length;
roop_count++)
{
if (share->tgt_wrappers[roop_count])
spider_free(spider_current_trx, share->tgt_wrappers[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->tgt_wrappers, MYF(0));
}
if (share->tgt_ssl_cas)
{
for (roop_count = 0; roop_count < (int) share->tgt_ssl_cas_length;
roop_count++)
{
if (share->tgt_ssl_cas[roop_count])
spider_free(spider_current_trx, share->tgt_ssl_cas[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->tgt_ssl_cas, MYF(0));
}
if (share->tgt_ssl_capaths)
{
for (roop_count = 0; roop_count < (int) share->tgt_ssl_capaths_length;
roop_count++)
{
if (share->tgt_ssl_capaths[roop_count])
spider_free(spider_current_trx, share->tgt_ssl_capaths[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->tgt_ssl_capaths, MYF(0));
}
if (share->tgt_ssl_certs)
{
for (roop_count = 0; roop_count < (int) share->tgt_ssl_certs_length;
roop_count++)
{
if (share->tgt_ssl_certs[roop_count])
spider_free(spider_current_trx, share->tgt_ssl_certs[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->tgt_ssl_certs, MYF(0));
}
if (share->tgt_ssl_ciphers)
{
for (roop_count = 0; roop_count < (int) share->tgt_ssl_ciphers_length;
roop_count++)
{
if (share->tgt_ssl_ciphers[roop_count])
spider_free(spider_current_trx, share->tgt_ssl_ciphers[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->tgt_ssl_ciphers, MYF(0));
}
if (share->tgt_ssl_keys)
{
for (roop_count = 0; roop_count < (int) share->tgt_ssl_keys_length;
roop_count++)
{
if (share->tgt_ssl_keys[roop_count])
spider_free(spider_current_trx, share->tgt_ssl_keys[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->tgt_ssl_keys, MYF(0));
}
if (share->tgt_default_files)
{
for (roop_count = 0; roop_count < (int) share->tgt_default_files_length;
roop_count++)
{
if (share->tgt_default_files[roop_count])
spider_free(spider_current_trx, share->tgt_default_files[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->tgt_default_files, MYF(0));
}
if (share->tgt_default_groups)
{
for (roop_count = 0; roop_count < (int) share->tgt_default_groups_length;
roop_count++)
{
if (share->tgt_default_groups[roop_count])
spider_free(spider_current_trx, share->tgt_default_groups[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->tgt_default_groups, MYF(0));
}
if (share->tgt_dsns)
{
for (roop_count = 0; roop_count < (int) share->tgt_dsns_length;
roop_count++)
{
if (share->tgt_dsns[roop_count])
spider_free(spider_current_trx, share->tgt_dsns[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->tgt_dsns, MYF(0));
}
if (share->tgt_filedsns)
{
for (roop_count = 0; roop_count < (int) share->tgt_filedsns_length;
roop_count++)
{
if (share->tgt_filedsns[roop_count])
spider_free(spider_current_trx, share->tgt_filedsns[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->tgt_filedsns, MYF(0));
}
if (share->tgt_drivers)
{
for (roop_count = 0; roop_count < (int) share->tgt_drivers_length;
roop_count++)
{
if (share->tgt_drivers[roop_count])
spider_free(spider_current_trx, share->tgt_drivers[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->tgt_drivers, MYF(0));
}
if (share->tgt_pk_names)
{
for (roop_count = 0; roop_count < (int) share->tgt_pk_names_length;
roop_count++)
{
if (share->tgt_pk_names[roop_count])
spider_free(spider_current_trx, share->tgt_pk_names[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->tgt_pk_names, MYF(0));
}
if (share->tgt_sequence_names)
{
for (roop_count = 0; roop_count < (int) share->tgt_sequence_names_length;
roop_count++)
{
if (share->tgt_sequence_names[roop_count])
spider_free(spider_current_trx, share->tgt_sequence_names[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->tgt_sequence_names, MYF(0));
}
if (share->static_link_ids)
{
for (roop_count = 0; roop_count < (int) share->static_link_ids_length;
roop_count++)
{
if (share->static_link_ids[roop_count])
spider_free(spider_current_trx, share->static_link_ids[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->static_link_ids, MYF(0));
}
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
if (share->hs_read_socks)
{
for (roop_count = 0; roop_count < (int) share->hs_read_socks_length;
roop_count++)
{
if (share->hs_read_socks[roop_count])
spider_free(spider_current_trx, share->hs_read_socks[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->hs_read_socks, MYF(0));
}
if (share->hs_write_socks)
{
for (roop_count = 0; roop_count < (int) share->hs_write_socks_length;
roop_count++)
{
if (share->hs_write_socks[roop_count])
spider_free(spider_current_trx, share->hs_write_socks[roop_count],
MYF(0));
}
spider_free(spider_current_trx, share->hs_write_socks, MYF(0));
}
#endif
if (share->bka_engine)
spider_free(spider_current_trx, share->bka_engine, MYF(0));
if (share->conn_keys)
spider_free(spider_current_trx, share->conn_keys, MYF(0));
if (share->tgt_ports)
spider_free(spider_current_trx, share->tgt_ports, MYF(0));
if (share->tgt_ssl_vscs)
spider_free(spider_current_trx, share->tgt_ssl_vscs, MYF(0));
if (share->link_statuses)
spider_free(spider_current_trx, share->link_statuses, MYF(0));
#ifndef WITHOUT_SPIDER_BG_SEARCH
if (share->monitoring_bg_flag)
spider_free(spider_current_trx, share->monitoring_bg_flag, MYF(0));
if (share->monitoring_bg_kind)
spider_free(spider_current_trx, share->monitoring_bg_kind, MYF(0));
#endif
if (share->monitoring_binlog_pos_at_failing)
spider_free(spider_current_trx, share->monitoring_binlog_pos_at_failing, MYF(0));
if (share->monitoring_flag)
spider_free(spider_current_trx, share->monitoring_flag, MYF(0));
if (share->monitoring_kind)
spider_free(spider_current_trx, share->monitoring_kind, MYF(0));
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
if (share->use_hs_reads)
spider_free(spider_current_trx, share->use_hs_reads, MYF(0));
if (share->use_hs_writes)
spider_free(spider_current_trx, share->use_hs_writes, MYF(0));
if (share->hs_read_ports)
spider_free(spider_current_trx, share->hs_read_ports, MYF(0));
if (share->hs_write_ports)
spider_free(spider_current_trx, share->hs_write_ports, MYF(0));
if (share->hs_write_to_reads)
spider_free(spider_current_trx, share->hs_write_to_reads, MYF(0));
#endif
if (share->use_handlers)
spider_free(spider_current_trx, share->use_handlers, MYF(0));
if (share->connect_timeouts)
spider_free(spider_current_trx, share->connect_timeouts, MYF(0));
if (share->net_read_timeouts)
spider_free(spider_current_trx, share->net_read_timeouts, MYF(0));
if (share->net_write_timeouts)
spider_free(spider_current_trx, share->net_write_timeouts, MYF(0));
if (share->access_balances)
spider_free(spider_current_trx, share->access_balances, MYF(0));
if (share->bka_table_name_types)
spider_free(spider_current_trx, share->bka_table_name_types, MYF(0));
if (share->strict_group_bys)
spider_free(spider_current_trx, share->strict_group_bys, MYF(0));
#ifndef WITHOUT_SPIDER_BG_SEARCH
if (share->monitoring_bg_interval)
spider_free(spider_current_trx, share->monitoring_bg_interval, MYF(0));
#endif
if (share->monitoring_limit)
spider_free(spider_current_trx, share->monitoring_limit, MYF(0));
if (share->monitoring_sid)
spider_free(spider_current_trx, share->monitoring_sid, MYF(0));
if (share->alter_table.tmp_server_names)
spider_free(spider_current_trx, share->alter_table.tmp_server_names,
MYF(0));
if (share->key_hint)
{
delete [] share->key_hint;
share->key_hint = NULL;
}
if (share->wide_share)
spider_free_wide_share(share->wide_share);
DBUG_RETURN(0);
}
void spider_free_tmp_share_alloc(
SPIDER_SHARE *share
) {
DBUG_ENTER("spider_free_tmp_share_alloc");
if (share->server_names && share->server_names[0])
{
spider_free(spider_current_trx, share->server_names[0], MYF(0));
share->server_names[0] = NULL;
}
if (share->tgt_table_names && share->tgt_table_names[0])
{
spider_free(spider_current_trx, share->tgt_table_names[0], MYF(0));
share->tgt_table_names[0] = NULL;
}
if (share->tgt_dbs && share->tgt_dbs[0])
{
spider_free(spider_current_trx, share->tgt_dbs[0], MYF(0));
share->tgt_dbs[0] = NULL;
}
if (share->tgt_hosts && share->tgt_hosts[0])
{
spider_free(spider_current_trx, share->tgt_hosts[0], MYF(0));
share->tgt_hosts[0] = NULL;
}
if (share->tgt_usernames && share->tgt_usernames[0])
{
spider_free(spider_current_trx, share->tgt_usernames[0], MYF(0));
share->tgt_usernames[0] = NULL;
}
if (share->tgt_passwords && share->tgt_passwords[0])
{
spider_free(spider_current_trx, share->tgt_passwords[0], MYF(0));
share->tgt_passwords[0] = NULL;
}
if (share->tgt_sockets && share->tgt_sockets[0])
{
spider_free(spider_current_trx, share->tgt_sockets[0], MYF(0));
share->tgt_sockets[0] = NULL;
}
if (share->tgt_wrappers && share->tgt_wrappers[0])