-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathspd_sys_table.cc
More file actions
4588 lines (4371 loc) · 139 KB
/
spd_sys_table.cc
File metadata and controls
4588 lines (4371 loc) · 139 KB
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-2019 Kentoku Shiba
Copyright (C) 2019 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 "sql_class.h"
#include "key.h"
#include "sql_base.h"
#include "tztime.h"
#include "lock.h"
#endif
#include "sql_select.h"
#include "spd_err.h"
#include "spd_param.h"
#include "spd_db_include.h"
#include "spd_include.h"
#include "spd_sys_table.h"
#include "spd_malloc.h"
extern handlerton *spider_hton_ptr;
extern Time_zone *spd_tz_system;
#define SPIDER_XA_FORMAT_ID_POS 0
#define SPIDER_XA_GTRID_LENGTH_POS 1
#define SPIDER_XA_BQUAL_LENGTH_POS 2
#define SPIDER_XA_DATA_POS 3
#define SPIDER_XA_STATUS_POS 4
#define SPIDER_XA_MEMBER_FORMAT_ID_POS 0
#define SPIDER_XA_MEMBER_GTRID_LENGTH_POS 1
#define SPIDER_XA_MEMBER_BQUAL_LENGTH_POS 2
#define SPIDER_XA_MEMBER_DATA_POS 3
#define SPIDER_XA_MEMBER_SCHEME_POS 4
#define SPIDER_XA_MEMBER_HOST_POS 5
#define SPIDER_XA_MEMBER_PORT_POS 6
#define SPIDER_XA_MEMBER_SOCKET_POS 7
#define SPIDER_XA_MEMBER_USERNAME_POS 8
#define SPIDER_XA_MEMBER_PASSWORD_POS 9
#define SPIDER_XA_MEMBER_SSL_CA_POS 10
#define SPIDER_XA_MEMBER_SSL_CAPATH_POS 11
#define SPIDER_XA_MEMBER_SSL_CERT_POS 12
#define SPIDER_XA_MEMBER_SSL_CIPHER_POS 13
#define SPIDER_XA_MEMBER_SSL_KEY_POS 14
#define SPIDER_XA_MEMBER_SSL_VERIFY_SERVER_CERT_POS 15
#define SPIDER_XA_MEMBER_DEFAULT_FILE_POS 16
#define SPIDER_XA_MEMBER_DEFAULT_GROUP_POS 17
#define SPIDER_XA_MEMBER_DSN_POS 18
#define SPIDER_XA_MEMBER_FILEDSN_POS 19
#define SPIDER_XA_MEMBER_DRIVER_POS 20
#define SPIDER_XA_FAILED_LOG_THREAD_ID_POS 21
#define SPIDER_XA_FAILED_LOG_STATUS_POS 22
#define SPIDER_XA_FAILED_LOG_FAILED_TIME_POS 23
#define SPIDER_TABLES_DB_NAME_POS 0
#define SPIDER_TABLES_TABLE_NAME_POS 1
#define SPIDER_TABLES_LINK_ID_POS 2
#define SPIDER_TABLES_PRIORITY_POS 3
#define SPIDER_TABLES_SERVER_POS 4
#define SPIDER_TABLES_SCHEME_POS 5
#define SPIDER_TABLES_HOST_POS 6
#define SPIDER_TABLES_PORT_POS 7
#define SPIDER_TABLES_SOCKET_POS 8
#define SPIDER_TABLES_USERNAME_POS 9
#define SPIDER_TABLES_PASSWORD_POS 10
#define SPIDER_TABLES_SSL_CA_POS 11
#define SPIDER_TABLES_SSL_CAPATH_POS 12
#define SPIDER_TABLES_SSL_CERT_POS 13
#define SPIDER_TABLES_SSL_CIPHER_POS 14
#define SPIDER_TABLES_SSL_KEY_POS 15
#define SPIDER_TABLES_SSL_VERIFY_SERVER_CERT_POS 16
#define SPIDER_TABLES_MONITORING_BINLOG_POS_AT_FAILING_POS 17
#define SPIDER_TABLES_DEFAULT_FILE_POS 18
#define SPIDER_TABLES_DEFAULT_GROUP_POS 19
#define SPIDER_TABLES_DSN_POS 20
#define SPIDER_TABLES_FILEDSN_POS 21
#define SPIDER_TABLES_DRIVER_POS 22
#define SPIDER_TABLES_TGT_DB_NAME_POS 23
#define SPIDER_TABLES_TGT_TABLE_NAME_POS 24
#define SPIDER_TABLES_LINK_STATUS_POS 25
#define SPIDER_TABLES_BLOCK_STATUS_POS 26
#define SPIDER_TABLES_STATIC_LINK_ID_POS 27
#define SPIDER_LINK_MON_SERVERS_DB_NAME_POS 0
#define SPIDER_LINK_MON_SERVERS_TABLE_NAME_POS 1
#define SPIDER_LINK_MON_SERVERS_LINK_ID_POS 2
#define SPIDER_LINK_MON_SERVERS_SID_POS 3
#define SPIDER_LINK_MON_SERVERS_SERVER_POS 4
#define SPIDER_LINK_MON_SERVERS_SCHEME_POS 5
#define SPIDER_LINK_MON_SERVERS_HOST_POS 6
#define SPIDER_LINK_MON_SERVERS_PORT_POS 7
#define SPIDER_LINK_MON_SERVERS_SOCKET_POS 8
#define SPIDER_LINK_MON_SERVERS_USERNAME_POS 9
#define SPIDER_LINK_MON_SERVERS_PASSWORD_POS 10
#define SPIDER_LINK_MON_SERVERS_SSL_CA_POS 11
#define SPIDER_LINK_MON_SERVERS_SSL_CAPATH_POS 12
#define SPIDER_LINK_MON_SERVERS_SSL_CERT_POS 13
#define SPIDER_LINK_MON_SERVERS_SSL_CIPHER_POS 14
#define SPIDER_LINK_MON_SERVERS_SSL_KEY_POS 15
#define SPIDER_LINK_MON_SERVERS_SSL_VERIFY_SERVER_CERT_POS 16
#define SPIDER_LINK_MON_SERVERS_DEFAULT_FILE_POS 17
#define SPIDER_LINK_MON_SERVERS_DEFAULT_GROUP_POS 18
#define SPIDER_LINK_MON_SERVERS_DSN_POS 19
#define SPIDER_LINK_MON_SERVERS_FILEDSN_POS 20
#define SPIDER_LINK_MON_SERVERS_DRIVER_POS 21
#define SPIDER_LINK_FAILED_LOG_DB_NAME_POS 0
#define SPIDER_LINK_FAILED_LOG_TABLE_NAME_POS 1
#define SPIDER_LINK_FAILED_LOG_LINK_ID_POS 2
#define SPIDER_LINK_FAILED_LOG_FAILED_TIME_POS 3
#define SPIDER_TABLE_POSITION_FOR_RECOVERY_DB_NAME_POS 0
#define SPIDER_TABLE_POSITION_FOR_RECOVERY_TABLE_NAME_POS 1
#define SPIDER_TABLE_POSITION_FOR_RECOVERY_FAILED_LINK_ID_POS 2
#define SPIDER_TABLE_POSITION_FOR_RECOVERY_SOURCE_LINK_ID_POS 3
#define SPIDER_TABLE_POSITION_FOR_RECOVERY_FILE_POS 4
#define SPIDER_TABLE_POSITION_FOR_RECOVERY_POSITION_POS 5
#define SPIDER_TABLE_POSITION_FOR_RECOVERY_GTID_POS 6
#define SPIDER_TABLE_STS_DB_NAME_POS 0
#define SPIDER_TABLE_STS_TABLE_NAME_POS 1
#define SPIDER_TABLE_STS_DATA_FILE_LENGTH_POS 2
#define SPIDER_TABLE_STS_MAX_DATA_FILE_LENGTH_POS 3
#define SPIDER_TABLE_STS_INDEX_FILE_LENGTH_POS 4
#define SPIDER_TABLE_STS_RECORDS_POS 5
#define SPIDER_TABLE_STS_MEAN_REC_LENGTH_POS 6
#define SPIDER_TABLE_STS_CHECK_TIME_POS 7
#define SPIDER_TABLE_STS_CREATE_TIME_POS 8
#define SPIDER_TABLE_STS_UPDATE_TIME_POS 9
#define SPIDER_TABLE_STS_CHECKSUM_POS 10
#define SPIDER_TABLE_CRD_DB_NAME_POS 0
#define SPIDER_TABLE_CRD_TABLE_NAME_POS 1
#define SPIDER_TABLE_CRD_KEY_SEQ_POS 2
#define SPIDER_TABLE_CRD_CARDINALITY_POS 3
void spider_sys_init_one_table(
TABLE_LIST *table_list,
const char *db_nm,
uint db_nm_len,
const char *table_nm,
uint table_nm_len,
enum thr_lock_type lock_type
) {
DBUG_ENTER("spider_sys_init_one_table");
#ifdef SPIDER_use_LEX_CSTRING_for_database_tablename_alias
LEX_CSTRING db_name =
{
db_nm,
db_nm_len
};
LEX_CSTRING tbl_name =
{
table_nm,
table_nm_len
};
table_list->init_one_table(&db_name, &tbl_name, NULL, lock_type);
#else
table_list->init_one_table(db_nm, db_nm_len,
table_nm, table_nm_len, table_nm, lock_type);
#endif
DBUG_VOID_RETURN;
}
/**
Insert a Spider system table row.
@param table The spider system table.
@param do_handle_error TRUE if an error message should be printed
before returning.
@return Error code returned by the write.
*/
inline int spider_write_sys_table_row(TABLE *table, bool do_handle_error = TRUE)
{
int error_num;
THD *thd = table->in_use;
tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */
error_num = table->file->ha_write_row(table->record[0]);
reenable_binlog(thd);
if (error_num && do_handle_error)
table->file->print_error(error_num, MYF(0));
return error_num;
}
/**
Update a Spider system table row.
@param table The spider system table.
@param do_handle_error TRUE if an error message should be printed
before returning.
@return Error code returned by the update.
*/
inline int spider_update_sys_table_row(TABLE *table, bool do_handle_error = TRUE)
{
int error_num;
THD *thd = table->in_use;
tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */
error_num = table->file->ha_update_row(table->record[1], table->record[0]);
reenable_binlog(thd);
if (error_num && do_handle_error)
{
if (error_num == HA_ERR_RECORD_IS_THE_SAME)
error_num = 0;
else
table->file->print_error(error_num, MYF(0));
}
return error_num;
}
/**
Delete a Spider system table row.
@param table The spider system table.
@param record_number Location of the record: 0 or 1.
@param do_handle_error TRUE if an error message should be printed
before returning.
@return Error code returned by the delete.
*/
inline int spider_delete_sys_table_row(TABLE *table, int record_number = 0,
bool do_handle_error = TRUE)
{
int error_num;
THD *thd = table->in_use;
tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */
error_num = table->file->ha_delete_row(table->record[record_number]);
reenable_binlog(thd);
if (error_num && do_handle_error)
table->file->print_error(error_num, MYF(0));
return error_num;
}
#if MYSQL_VERSION_ID < 50500
TABLE *spider_open_sys_table(
THD *thd,
const char *table_name,
int table_name_length,
bool write,
Open_tables_state *open_tables_backup,
bool need_lock,
int *error_num
)
#else
TABLE *spider_open_sys_table(
THD *thd,
const char *table_name,
int table_name_length,
bool write,
Open_tables_backup *open_tables_backup,
bool need_lock,
int *error_num
)
#endif
{
TABLE *table;
TABLE_LIST tables;
#if MYSQL_VERSION_ID < 50500
TABLE_SHARE *table_share;
char table_key[MAX_DBKEY_LENGTH];
uint table_key_length;
#endif
DBUG_ENTER("spider_open_sys_table");
#if MYSQL_VERSION_ID < 50500
memset(&tables, 0, sizeof(TABLE_LIST));
SPIDER_TABLE_LIST_db_str(&tables) = (char*)"mysql";
SPIDER_TABLE_LIST_db_length(&tables) = sizeof("mysql") - 1;
SPIDER_TABLE_LIST_alias_str(&tables) =
SPIDER_TABLE_LIST_table_name_str(&tables) = (char *) table_name;
SPIDER_TABLE_LIST_table_name_length(&tables) = table_name_length;
tables.lock_type = (write ? TL_WRITE : TL_READ);
#else
#ifdef SPIDER_use_LEX_CSTRING_for_database_tablename_alias
LEX_CSTRING db_name =
{
"mysql",
sizeof("mysql") - 1
};
LEX_CSTRING tbl_name =
{
table_name,
(size_t) table_name_length
};
tables.init_one_table(&db_name, &tbl_name, 0, (write ? TL_WRITE : TL_READ));
#else
tables.init_one_table(
"mysql", sizeof("mysql") - 1, table_name, table_name_length, table_name,
(write ? TL_WRITE : TL_READ));
#endif
#endif
#if MYSQL_VERSION_ID < 50500
if (need_lock)
{
#endif
#if MYSQL_VERSION_ID < 50500
if (!(table = open_performance_schema_table(thd, &tables,
open_tables_backup)))
#else
if (!(table = spider_sys_open_table(thd, &tables, open_tables_backup)))
#endif
{
my_printf_error(ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM,
ER_SPIDER_CANT_OPEN_SYS_TABLE_STR, MYF(0),
"mysql", table_name);
*error_num = ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM;
DBUG_RETURN(NULL);
}
#if MYSQL_VERSION_ID < 50500
} else {
thd->reset_n_backup_open_tables_state(open_tables_backup);
if (!(table = (TABLE*) spider_malloc(spider_current_trx, 12,
sizeof(*table), MYF(MY_WME))))
{
my_error(HA_ERR_OUT_OF_MEM, MYF(0));
*error_num = HA_ERR_OUT_OF_MEM;
goto error_malloc;
}
table_key_length =
create_table_def_key(thd, table_key, &tables, FALSE);
if (!(table_share = get_table_share(thd,
&tables, table_key, table_key_length, 0, error_num)))
goto error;
if (open_table_from_share(thd, table_share, tables.alias,
(uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE | HA_GET_INDEX),
READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD,
(uint) HA_OPEN_IGNORE_IF_LOCKED | HA_OPEN_FROM_SQL_LAYER,
table, FALSE)
) {
release_table_share(table_share, RELEASE_NORMAL);
my_printf_error(ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM,
ER_SPIDER_CANT_OPEN_SYS_TABLE_STR, MYF(0),
"mysql", table_name);
*error_num = ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM;
goto error;
}
}
#endif
switch (table_name_length)
{
case 9:
if (!memcmp(table_name, SPIDER_SYS_XA_TABLE_NAME_STR,
SPIDER_SYS_XA_TABLE_NAME_LEN))
{
DBUG_PRINT("info",("spider checking for SYS_XA"));
if (table->s->fields != SPIDER_SYS_XA_COL_CNT)
{
spider_close_sys_table(thd, table, open_tables_backup, need_lock);
table = NULL;
my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
SPIDER_SYS_XA_TABLE_NAME_STR);
*error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
goto error_col_num_chk;
}
break;
}
DBUG_ASSERT(0);
break;
case 13:
if (!memcmp(table_name, SPIDER_SYS_TABLES_TABLE_NAME_STR,
SPIDER_SYS_TABLES_TABLE_NAME_LEN))
{
DBUG_PRINT("info",("spider checking for SYS_TABLES"));
if (table->s->fields != SPIDER_SYS_TABLES_COL_CNT)
{
spider_close_sys_table(thd, table, open_tables_backup, need_lock);
table = NULL;
my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
SPIDER_SYS_TABLES_TABLE_NAME_STR);
*error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
goto error_col_num_chk;
}
break;
}
DBUG_ASSERT(0);
break;
case 16:
if (!memcmp(table_name, SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR,
SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN))
{
DBUG_PRINT("info",("spider checking for SYS_XA_MEMBER"));
if (table->s->fields != SPIDER_SYS_XA_MEMBER_COL_CNT)
{
spider_close_sys_table(thd, table, open_tables_backup, need_lock);
table = NULL;
my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR);
*error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
goto error_col_num_chk;
}
break;
}
if (!memcmp(table_name, SPIDER_SYS_TABLE_STS_TABLE_NAME_STR,
SPIDER_SYS_TABLE_STS_TABLE_NAME_LEN))
{
DBUG_PRINT("info",("spider checking for SYS_TABLE_STS"));
if (table->s->fields != SPIDER_SYS_TABLE_STS_COL_CNT)
{
spider_close_sys_table(thd, table, open_tables_backup, need_lock);
table = NULL;
my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
SPIDER_SYS_TABLE_STS_TABLE_NAME_STR);
*error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
goto error_col_num_chk;
}
break;
}
if (!memcmp(table_name, SPIDER_SYS_TABLE_CRD_TABLE_NAME_STR,
SPIDER_SYS_TABLE_CRD_TABLE_NAME_LEN))
{
DBUG_PRINT("info",("spider checking for SYS_TABLE_CRD"));
if (table->s->fields != SPIDER_SYS_TABLE_CRD_COL_CNT)
{
spider_close_sys_table(thd, table, open_tables_backup, need_lock);
table = NULL;
my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
SPIDER_SYS_TABLE_CRD_TABLE_NAME_STR);
*error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
goto error_col_num_chk;
}
break;
}
DBUG_ASSERT(0);
break;
case 20:
if (!memcmp(table_name, SPIDER_SYS_XA_FAILED_TABLE_NAME_STR,
SPIDER_SYS_XA_FAILED_TABLE_NAME_LEN))
{
DBUG_PRINT("info",("spider checking for SYS_XA_FAILED"));
if (table->s->fields != SPIDER_SYS_XA_FAILED_TABLE_COL_CNT)
{
spider_close_sys_table(thd, table, open_tables_backup, need_lock);
table = NULL;
my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
SPIDER_SYS_XA_FAILED_TABLE_NAME_STR);
*error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
goto error_col_num_chk;
}
break;
}
DBUG_ASSERT(0);
break;
case 21:
if (!memcmp(table_name, SPIDER_SYS_RW_TBLS_TABLE_NAME_STR,
SPIDER_SYS_RW_TBLS_TABLE_NAME_LEN))
{
DBUG_PRINT("info",("spider checking for SYS_RW_TBLS"));
if (table->s->fields != SPIDER_SYS_RW_TBLS_COL_CNT)
{
spider_close_sys_table(thd, table, open_tables_backup, need_lock);
table = NULL;
my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
SPIDER_SYS_RW_TBLS_TABLE_NAME_STR);
*error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
goto error_col_num_chk;
}
}
DBUG_ASSERT(0);
break;
case 22:
if (!memcmp(table_name, SPIDER_SYS_LINK_FAILED_TABLE_NAME_STR,
SPIDER_SYS_LINK_FAILED_TABLE_NAME_LEN))
{
DBUG_PRINT("info",("spider checking for SYS_LINK_FAILED"));
if (table->s->fields != SPIDER_SYS_LINK_FAILED_TABLE_COL_CNT)
{
spider_close_sys_table(thd, table, open_tables_backup, need_lock);
table = NULL;
my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
SPIDER_SYS_LINK_FAILED_TABLE_NAME_STR);
*error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
goto error_col_num_chk;
}
break;
}
DBUG_ASSERT(0);
break;
case 23:
if (!memcmp(table_name, SPIDER_SYS_LINK_MON_TABLE_NAME_STR,
SPIDER_SYS_LINK_MON_TABLE_NAME_LEN))
{
DBUG_PRINT("info",("spider checking for SYS_LINK_MON"));
if (table->s->fields != SPIDER_SYS_LINK_MON_TABLE_COL_CNT)
{
spider_close_sys_table(thd, table, open_tables_backup, need_lock);
table = NULL;
my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
SPIDER_SYS_LINK_MON_TABLE_NAME_STR);
*error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
goto error_col_num_chk;
}
break;
}
if (!memcmp(table_name, SPIDER_SYS_RWN_TBLS_TABLE_NAME_STR,
SPIDER_SYS_RWN_TBLS_TABLE_NAME_LEN))
{
DBUG_PRINT("info",("spider checking for SYS_RWN_TBLS"));
if (table->s->fields != SPIDER_SYS_RWN_TBLS_COL_CNT)
{
spider_close_sys_table(thd, table, open_tables_backup, need_lock);
table = NULL;
my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
SPIDER_SYS_RWN_TBLS_TABLE_NAME_STR);
*error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
goto error_col_num_chk;
}
break;
}
DBUG_ASSERT(0);
break;
case 27:
if (!memcmp(table_name, SPIDER_SYS_RW_TBL_TBLS_TABLE_NAME_STR,
SPIDER_SYS_RW_TBL_TBLS_TABLE_NAME_LEN))
{
DBUG_PRINT("info",("spider checking for SYS_RW_TBL_TBLS"));
if (table->s->fields != SPIDER_SYS_RW_TBL_TBLS_COL_CNT)
{
spider_close_sys_table(thd, table, open_tables_backup, need_lock);
table = NULL;
my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
SPIDER_SYS_RW_TBL_TBLS_TABLE_NAME_STR);
*error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
goto error_col_num_chk;
}
break;
}
DBUG_ASSERT(0);
break;
case 31:
if (!memcmp(table_name, SPIDER_SYS_RW_TBL_PTTS_TABLE_NAME_STR,
SPIDER_SYS_RW_TBL_PTTS_TABLE_NAME_LEN))
{
DBUG_PRINT("info",("spider checking for SYS_RW_TBL_PTTS"));
if (table->s->fields != SPIDER_SYS_RW_TBL_PTTS_COL_CNT)
{
spider_close_sys_table(thd, table, open_tables_backup, need_lock);
table = NULL;
my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
SPIDER_SYS_RW_TBL_PTTS_TABLE_NAME_STR);
*error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
goto error_col_num_chk;
}
break;
}
DBUG_ASSERT(0);
break;
case 34:
if (!memcmp(table_name, SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_STR,
SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_LEN))
{
DBUG_PRINT("info",("spider checking for SYS_POS_FOR_RECOVERY"));
if (table->s->fields != SPIDER_SYS_POS_FOR_RECOVERY_TABLE_COL_CNT)
{
spider_close_sys_table(thd, table, open_tables_backup, need_lock);
table = NULL;
my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_STR);
*error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
goto error_col_num_chk;
}
break;
}
if (!memcmp(table_name, SPIDER_SYS_RW_TBL_SPTTS_TABLE_NAME_STR,
SPIDER_SYS_RW_TBL_SPTTS_TABLE_NAME_LEN))
{
DBUG_PRINT("info",("spider checking for SYS_RW_TBL_SPTTS"));
if (table->s->fields != SPIDER_SYS_RW_TBL_SPTTS_COL_CNT)
{
spider_close_sys_table(thd, table, open_tables_backup, need_lock);
table = NULL;
my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
SPIDER_SYS_RW_TBL_SPTTS_TABLE_NAME_STR);
*error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
goto error_col_num_chk;
}
break;
}
DBUG_ASSERT(0);
break;
default:
DBUG_ASSERT(0);
break;
}
DBUG_RETURN(table);
#if MYSQL_VERSION_ID < 50500
error:
spider_free(spider_current_trx, table, MYF(0));
error_malloc:
thd->restore_backup_open_tables_state(open_tables_backup);
#endif
error_col_num_chk:
DBUG_RETURN(NULL);
}
#if MYSQL_VERSION_ID < 50500
void spider_close_sys_table(
THD *thd,
TABLE *table,
Open_tables_state *open_tables_backup,
bool need_lock
)
#else
void spider_close_sys_table(
THD *thd,
TABLE *table,
Open_tables_backup *open_tables_backup,
bool need_lock
)
#endif
{
DBUG_ENTER("spider_close_sys_table");
#if MYSQL_VERSION_ID < 50500
if (need_lock)
{
close_performance_schema_table(thd, open_tables_backup);
} else {
table->file->ha_reset();
closefrm(table, TRUE);
spider_free(spider_current_trx, table, MYF(0));
thd->restore_backup_open_tables_state(open_tables_backup);
}
#else
spider_sys_close_table(thd, open_tables_backup);
#endif
DBUG_VOID_RETURN;
}
#if MYSQL_VERSION_ID < 50500
#else
bool spider_sys_open_tables(
THD *thd,
TABLE_LIST **tables,
uint *counter,
Open_tables_backup *open_tables_backup
) {
ulonglong utime_after_lock_backup = thd->utime_after_lock;
DBUG_ENTER("spider_sys_open_tables");
thd->reset_n_backup_open_tables_state(open_tables_backup);
if (open_tables(thd, tables, counter,
MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY |
MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT | MYSQL_LOCK_LOG_TABLE
)) {
thd->restore_backup_open_tables_state(open_tables_backup);
thd->utime_after_lock = utime_after_lock_backup;
DBUG_RETURN(TRUE);
}
thd->utime_after_lock = utime_after_lock_backup;
DBUG_RETURN(FALSE);
}
bool spider_sys_open_tables(
THD *thd,
TABLE_LIST **tables,
Open_tables_backup *open_tables_backup
) {
uint counter;
DBUG_ENTER("spider_sys_open_tables");
DBUG_RETURN(spider_sys_open_tables(thd, tables, &counter,
open_tables_backup));
}
TABLE *spider_sys_open_table(
THD *thd,
TABLE_LIST *tables,
Open_tables_backup *open_tables_backup
) {
TABLE *table;
ulonglong utime_after_lock_backup = thd->utime_after_lock;
DBUG_ENTER("spider_sys_open_table");
if (open_tables_backup)
thd->reset_n_backup_open_tables_state(open_tables_backup);
if ((table = open_ltable(thd, tables, tables->lock_type,
MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY |
MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT | MYSQL_LOCK_LOG_TABLE
))) {
table->use_all_columns();
table->s->no_replicate = 1;
} else if (open_tables_backup)
thd->restore_backup_open_tables_state(open_tables_backup);
thd->utime_after_lock = utime_after_lock_backup;
DBUG_RETURN(table);
}
void spider_sys_close_table(
THD *thd,
Open_tables_backup *open_tables_backup
) {
DBUG_ENTER("spider_sys_close_table");
close_thread_tables(thd);
thd->restore_backup_open_tables_state(open_tables_backup);
DBUG_VOID_RETURN;
}
MYSQL_LOCK *spider_sys_lock_tables(
THD *thd,
TABLE **table,
uint counter
) {
DBUG_ENTER("spider_sys_lock_tables");
DBUG_RETURN(mysql_lock_tables(thd, table, counter, 0));
}
void spider_sys_unlock_tables(
THD *thd,
MYSQL_LOCK *lock
) {
DBUG_ENTER("spider_sys_unlock_tables");
mysql_unlock_tables(thd, lock);
DBUG_VOID_RETURN;
}
#endif
int spider_sys_index_init(
TABLE *table,
uint idx,
bool sorted
) {
DBUG_ENTER("spider_sys_index_init");
DBUG_RETURN(table->file->ha_index_init(idx, sorted));
}
int spider_sys_index_end(
TABLE *table
) {
DBUG_ENTER("spider_sys_index_end");
DBUG_RETURN(table->file->ha_index_end());
}
int spider_sys_rnd_init(
TABLE *table,
bool scan
) {
DBUG_ENTER("spider_sys_rnd_init");
DBUG_RETURN(table->file->ha_rnd_init(scan));
}
int spider_sys_rnd_end(
TABLE *table
) {
DBUG_ENTER("spider_sys_rnd_end");
DBUG_RETURN(table->file->ha_rnd_end());
}
int spider_check_sys_table(
TABLE *table,
char *table_key
) {
DBUG_ENTER("spider_check_sys_table");
key_copy(
(uchar *) table_key,
table->record[0],
table->key_info,
table->key_info->key_length);
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
DBUG_RETURN(table->file->ha_index_read_idx_map(
table->record[0], 0, (uchar *) table_key,
HA_WHOLE_KEY, HA_READ_KEY_EXACT));
#else
DBUG_RETURN(table->file->index_read_idx_map(
table->record[0], 0, (uchar *) table_key,
HA_WHOLE_KEY, HA_READ_KEY_EXACT));
#endif
}
int spider_check_sys_table_with_find_flag(
TABLE *table,
char *table_key,
enum ha_rkey_function find_flag
) {
DBUG_ENTER("spider_check_sys_table");
key_copy(
(uchar *) table_key,
table->record[0],
table->key_info,
table->key_info->key_length);
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
DBUG_RETURN(table->file->ha_index_read_idx_map(
table->record[0], 0, (uchar *) table_key,
HA_WHOLE_KEY, find_flag));
#else
DBUG_RETURN(table->file->index_read_idx_map(
table->record[0], 0, (uchar *) table_key,
HA_WHOLE_KEY, find_flag));
#endif
}
int spider_check_sys_table_for_update_all_columns(
TABLE *table,
char *table_key
) {
DBUG_ENTER("spider_check_sys_table_for_update_all_columns");
key_copy(
(uchar *) table_key,
table->record[0],
table->key_info,
table->key_info->key_length);
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
DBUG_RETURN(table->file->ha_index_read_idx_map(
table->record[1], 0, (uchar *) table_key,
HA_WHOLE_KEY, HA_READ_KEY_EXACT));
#else
DBUG_RETURN(table->file->index_read_idx_map(
table->record[1], 0, (uchar *) table_key,
HA_WHOLE_KEY, HA_READ_KEY_EXACT));
#endif
}
int spider_get_sys_table_by_idx(
TABLE *table,
char *table_key,
const int idx,
const int col_count
) {
int error_num;
uint key_length;
KEY *key_info = table->key_info + idx;
DBUG_ENTER("spider_get_sys_table_by_idx");
if ((error_num = spider_sys_index_init(table, idx, FALSE)))
DBUG_RETURN(error_num);
if ((int) spider_user_defined_key_parts(key_info) == col_count)
{
key_length = key_info->key_length;
} else {
int roop_count;
key_length = 0;
for (roop_count = 0; roop_count < col_count; ++roop_count)
{
key_length += key_info->key_part[roop_count].store_length;
}
}
key_copy(
(uchar *) table_key,
table->record[0],
key_info,
key_length);
if (
/*
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
(error_num = table->file->ha_index_read_idx_map(
table->record[0], idx, (uchar *) table_key,
make_prev_keypart_map(col_count), HA_READ_KEY_EXACT))
#else
(error_num = table->file->index_read_idx_map(
table->record[0], idx, (uchar *) table_key,
make_prev_keypart_map(col_count), HA_READ_KEY_EXACT))
#endif
*/
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
(error_num = table->file->ha_index_read_map(
table->record[0], (uchar *) table_key,
make_prev_keypart_map(col_count), HA_READ_KEY_EXACT))
#else
(error_num = table->file->index_read_map(
table->record[0], (uchar *) table_key,
make_prev_keypart_map(col_count), HA_READ_KEY_EXACT))
#endif
) {
spider_sys_index_end(table);
DBUG_RETURN(error_num);
}
DBUG_RETURN(0);
}
int spider_sys_index_next_same(
TABLE *table,
char *table_key
) {
DBUG_ENTER("spider_sys_index_next_same");
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
DBUG_RETURN(table->file->ha_index_next_same(
table->record[0],
(const uchar*) table_key,
table->key_info->key_length));
#else
DBUG_RETURN(table->file->index_next_same(
table->record[0],
(const uchar*) table_key,
table->key_info->key_length));
#endif
}
int spider_sys_index_first(
TABLE *table,
const int idx
) {
int error_num;
DBUG_ENTER("spider_sys_index_first");
if ((error_num = spider_sys_index_init(table, idx, FALSE)))
DBUG_RETURN(error_num);
if (
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
(error_num = table->file->ha_index_first(table->record[0]))
#else
(error_num = table->file->index_first(table->record[0]))
#endif
) {
spider_sys_index_end(table);
DBUG_RETURN(error_num);
}
DBUG_RETURN(0);
}
int spider_sys_index_last(
TABLE *table,
const int idx
) {
int error_num;
DBUG_ENTER("spider_sys_index_last");
if ((error_num = spider_sys_index_init(table, idx, FALSE)))
DBUG_RETURN(error_num);
if (
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
(error_num = table->file->ha_index_last(table->record[0]))
#else
(error_num = table->file->index_last(table->record[0]))
#endif
) {
spider_sys_index_end(table);
DBUG_RETURN(error_num);
}
DBUG_RETURN(0);
}
int spider_sys_index_next(
TABLE *table
) {
DBUG_ENTER("spider_sys_index_next");
#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
DBUG_RETURN(table->file->ha_index_next(table->record[0]));
#else
DBUG_RETURN(table->file->index_next(table->record[0]));
#endif
}
void spider_store_xa_pk(
TABLE *table,
XID *xid