1/* Copyright (C) 2008-2016 Kentoku Shiba
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
15
16#define SPIDER_SYS_XA_TABLE_NAME_STR "spider_xa"
17#define SPIDER_SYS_XA_TABLE_NAME_LEN (sizeof(SPIDER_SYS_XA_TABLE_NAME_STR) - 1)
18#define SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR "spider_xa_member"
19#define SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN (sizeof(SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR) - 1)
20#define SPIDER_SYS_TABLES_TABLE_NAME_STR "spider_tables"
21#define SPIDER_SYS_TABLES_TABLE_NAME_LEN (sizeof(SPIDER_SYS_TABLES_TABLE_NAME_STR) - 1)
22#define SPIDER_SYS_LINK_MON_TABLE_NAME_STR "spider_link_mon_servers"
23#define SPIDER_SYS_LINK_MON_TABLE_NAME_LEN (sizeof(SPIDER_SYS_LINK_MON_TABLE_NAME_STR) - 1)
24#define SPIDER_SYS_LINK_FAILED_TABLE_NAME_STR "spider_link_failed_log"
25#define SPIDER_SYS_LINK_FAILED_TABLE_NAME_LEN (sizeof(SPIDER_SYS_LINK_FAILED_TABLE_NAME_STR) - 1)
26#define SPIDER_SYS_XA_FAILED_TABLE_NAME_STR "spider_xa_failed_log"
27#define SPIDER_SYS_XA_FAILED_TABLE_NAME_LEN (sizeof(SPIDER_SYS_XA_FAILED_TABLE_NAME_STR) - 1)
28#define SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_STR "spider_table_position_for_recovery"
29#define SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_LEN (sizeof(SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_STR) - 1)
30#define SPIDER_SYS_TABLE_STS_TABLE_NAME_STR "spider_table_sts"
31#define SPIDER_SYS_TABLE_STS_TABLE_NAME_LEN (sizeof(SPIDER_SYS_TABLE_STS_TABLE_NAME_STR) - 1)
32#define SPIDER_SYS_TABLE_CRD_TABLE_NAME_STR "spider_table_crd"
33#define SPIDER_SYS_TABLE_CRD_TABLE_NAME_LEN (sizeof(SPIDER_SYS_TABLE_CRD_TABLE_NAME_STR) - 1)
34
35#define SPIDER_SYS_XA_PREPARED_STR "PREPARED"
36#define SPIDER_SYS_XA_NOT_YET_STR "NOT YET"
37#define SPIDER_SYS_XA_COMMIT_STR "COMMIT"
38#define SPIDER_SYS_XA_ROLLBACK_STR "ROLLBACK"
39
40#define SPIDER_SYS_XA_COL_CNT 5
41#define SPIDER_SYS_XA_PK_COL_CNT 3
42#define SPIDER_SYS_XA_IDX1_COL_CNT 1
43#define SPIDER_SYS_XA_MEMBER_COL_CNT 18
44#define SPIDER_SYS_XA_MEMBER_PK_COL_CNT 6
45#define SPIDER_SYS_TABLES_COL_CNT 25
46#define SPIDER_SYS_TABLES_PK_COL_CNT 3
47#define SPIDER_SYS_TABLES_IDX1_COL_CNT 1
48#define SPIDER_SYS_TABLES_UIDX1_COL_CNT 3
49#define SPIDER_SYS_LINK_MON_TABLE_COL_CNT 19
50#define SPIDER_SYS_POS_FOR_RECOVERY_TABLE_COL_CNT 7
51#define SPIDER_SYS_TABLE_STS_COL_CNT 10
52#define SPIDER_SYS_TABLE_STS_PK_COL_CNT 2
53#define SPIDER_SYS_TABLE_CRD_COL_CNT 4
54#define SPIDER_SYS_TABLE_CRD_PK_COL_CNT 3
55
56#define SPIDER_SYS_LINK_MON_TABLE_DB_NAME_SIZE 64
57#define SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE 64
58#define SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE 64
59
60class SPIDER_MON_KEY: public SPIDER_SORT
61{
62public:
63 char db_name[SPIDER_SYS_LINK_MON_TABLE_DB_NAME_SIZE + 1];
64 char table_name[SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE + 1];
65 char link_id[SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE + 1];
66 uint db_name_length;
67 uint table_name_length;
68 uint link_id_length;
69};
70
71#if MYSQL_VERSION_ID < 50500
72TABLE *spider_open_sys_table(
73 THD *thd,
74 const char *table_name,
75 int table_name_length,
76 bool write,
77 Open_tables_state *open_tables_backup,
78 bool need_lock,
79 int *error_num
80);
81
82void spider_close_sys_table(
83 THD *thd,
84 TABLE *table,
85 Open_tables_state *open_tables_backup,
86 bool need_lock
87);
88#else
89TABLE *spider_open_sys_table(
90 THD *thd,
91 const char *table_name,
92 int table_name_length,
93 bool write,
94 Open_tables_backup *open_tables_backup,
95 bool need_lock,
96 int *error_num
97);
98
99void spider_close_sys_table(
100 THD *thd,
101 TABLE *table,
102 Open_tables_backup *open_tables_backup,
103 bool need_lock
104);
105
106bool spider_sys_open_tables(
107 THD *thd,
108 TABLE_LIST **tables,
109 Open_tables_backup *open_tables_backup
110);
111
112TABLE *spider_sys_open_table(
113 THD *thd,
114 TABLE_LIST *tables,
115 Open_tables_backup *open_tables_backup
116);
117
118void spider_sys_close_table(
119 THD *thd,
120 Open_tables_backup *open_tables_backup
121);
122#endif
123
124int spider_sys_index_init(
125 TABLE *table,
126 uint idx,
127 bool sorted
128);
129
130int spider_sys_index_end(
131 TABLE *table
132);
133
134int spider_sys_rnd_init(
135 TABLE *table,
136 bool scan
137);
138
139int spider_sys_rnd_end(
140 TABLE *table
141);
142
143int spider_check_sys_table(
144 TABLE *table,
145 char *table_key
146);
147
148int spider_check_sys_table_with_find_flag(
149 TABLE *table,
150 char *table_key,
151 enum ha_rkey_function find_flag
152);
153
154int spider_check_sys_table_for_update_all_columns(
155 TABLE *table,
156 char *table_key
157);
158
159int spider_get_sys_table_by_idx(
160 TABLE *table,
161 char *table_key,
162 const int idx,
163 const int col_count
164);
165
166int spider_sys_index_next_same(
167 TABLE *table,
168 char *table_key
169);
170
171int spider_sys_index_first(
172 TABLE *table,
173 const int idx
174);
175
176int spider_sys_index_next(
177 TABLE *table
178);
179
180void spider_store_xa_pk(
181 TABLE *table,
182 XID *xid
183);
184
185void spider_store_xa_bqual_length(
186 TABLE *table,
187 XID *xid
188);
189
190void spider_store_xa_status(
191 TABLE *table,
192 const char *status
193);
194
195void spider_store_xa_member_pk(
196 TABLE *table,
197 XID *xid,
198 SPIDER_CONN *conn
199);
200
201void spider_store_xa_member_info(
202 TABLE *table,
203 XID *xid,
204 SPIDER_CONN *conn
205);
206
207void spider_store_tables_name(
208 TABLE *table,
209 const char *name,
210 const uint name_length
211);
212
213void spider_store_db_and_table_name(
214 TABLE *table,
215 const char *db_name,
216 const uint db_name_length,
217 const char *table_name,
218 const uint table_name_length
219);
220
221void spider_store_tables_link_idx(
222 TABLE *table,
223 int link_idx
224);
225
226void spider_store_tables_link_idx_str(
227 TABLE *table,
228 const char *link_idx,
229 const uint link_idx_length
230);
231
232void spider_store_tables_static_link_id(
233 TABLE *table,
234 const char *static_link_id,
235 const uint static_link_id_length
236);
237
238void spider_store_tables_priority(
239 TABLE *table,
240 longlong priority
241);
242
243void spider_store_tables_connect_info(
244 TABLE *table,
245 SPIDER_ALTER_TABLE *alter_table,
246 int link_idx
247);
248
249void spider_store_tables_link_status(
250 TABLE *table,
251 long link_status
252);
253
254void spider_store_link_chk_server_id(
255 TABLE *table,
256 uint32 server_id
257);
258
259void spider_store_binlog_pos_failed_link_idx(
260 TABLE *table,
261 int failed_link_idx
262);
263
264void spider_store_binlog_pos_source_link_idx(
265 TABLE *table,
266 int source_link_idx
267);
268
269void spider_store_binlog_pos_binlog_file(
270 TABLE *table,
271 const char *file_name,
272 int file_name_length,
273 const char *position,
274 int position_length,
275 CHARSET_INFO *binlog_pos_cs
276);
277
278void spider_store_binlog_pos_gtid(
279 TABLE *table,
280 const char *gtid,
281 int gtid_length,
282 CHARSET_INFO *binlog_pos_cs
283);
284
285void spider_store_table_sts_info(
286 TABLE *table,
287 ulonglong *data_file_length,
288 ulonglong *max_data_file_length,
289 ulonglong *index_file_length,
290 ha_rows *records,
291 ulong *mean_rec_length,
292 time_t *check_time,
293 time_t *create_time,
294 time_t *update_time
295);
296
297void spider_store_table_crd_info(
298 TABLE *table,
299 uint *seq,
300 longlong *cardinality
301);
302
303int spider_insert_xa(
304 TABLE *table,
305 XID *xid,
306 const char *status
307);
308
309int spider_insert_xa_member(
310 TABLE *table,
311 XID *xid,
312 SPIDER_CONN *conn
313);
314
315int spider_insert_tables(
316 TABLE *table,
317 SPIDER_SHARE *share
318);
319
320int spider_insert_sys_table(
321 TABLE *table
322);
323
324int spider_insert_or_update_table_sts(
325 TABLE *table,
326 const char *name,
327 uint name_length,
328 ulonglong *data_file_length,
329 ulonglong *max_data_file_length,
330 ulonglong *index_file_length,
331 ha_rows *records,
332 ulong *mean_rec_length,
333 time_t *check_time,
334 time_t *create_time,
335 time_t *update_time
336);
337
338int spider_insert_or_update_table_crd(
339 TABLE *table,
340 const char *name,
341 uint name_length,
342 longlong *cardinality,
343 uint number_of_keys
344);
345
346int spider_log_tables_link_failed(
347 TABLE *table,
348 char *name,
349 uint name_length,
350 int link_idx
351);
352
353int spider_log_xa_failed(
354 THD *thd,
355 TABLE *table,
356 XID *xid,
357 SPIDER_CONN *conn,
358 const char *status
359);
360
361int spider_update_xa(
362 TABLE *table,
363 XID *xid,
364 const char *status
365);
366
367int spider_update_tables_name(
368 TABLE *table,
369 const char *from,
370 const char *to,
371 int *old_link_count
372);
373
374int spider_update_tables_priority(
375 TABLE *table,
376 SPIDER_ALTER_TABLE *alter_table,
377 const char *name,
378 int *old_link_count
379);
380
381int spider_update_tables_link_status(
382 TABLE *table,
383 char *name,
384 uint name_length,
385 int link_idx,
386 long link_status
387);
388
389int spider_delete_xa(
390 TABLE *table,
391 XID *xid
392);
393
394int spider_delete_xa_member(
395 TABLE *table,
396 XID *xid
397);
398
399int spider_delete_tables(
400 TABLE *table,
401 const char *name,
402 int *old_link_count
403);
404
405int spider_delete_table_sts(
406 TABLE *table,
407 const char *name,
408 uint name_length
409);
410
411int spider_delete_table_crd(
412 TABLE *table,
413 const char *name,
414 uint name_length
415);
416
417int spider_get_sys_xid(
418 TABLE *table,
419 XID *xid,
420 MEM_ROOT *mem_root
421);
422
423int spider_get_sys_server_info(
424 TABLE *table,
425 SPIDER_SHARE *share,
426 int link_idx,
427 MEM_ROOT *mem_root
428);
429
430int spider_check_sys_xa_status(
431 TABLE *table,
432 const char *status1,
433 const char *status2,
434 const char *status3,
435 const int check_error_num,
436 MEM_ROOT *mem_root
437);
438
439int spider_get_sys_tables(
440 TABLE *table,
441 char **db_name,
442 char **table_name,
443 MEM_ROOT *mem_root
444);
445
446int spider_get_sys_tables_connect_info(
447 TABLE *table,
448 SPIDER_SHARE *share,
449 int link_idx,
450 MEM_ROOT *mem_root
451);
452
453int spider_get_sys_tables_monitoring_binlog_pos_at_failing(
454 TABLE *table,
455 long *monitoring_binlog_pos_at_failing,
456 MEM_ROOT *mem_root
457);
458
459int spider_get_sys_tables_link_status(
460 TABLE *table,
461 SPIDER_SHARE *share,
462 int link_idx,
463 MEM_ROOT *mem_root
464);
465
466int spider_get_sys_tables_link_status(
467 TABLE *table,
468 long *link_status,
469 MEM_ROOT *mem_root
470);
471
472int spider_get_sys_tables_link_idx(
473 TABLE *table,
474 int *link_idx,
475 MEM_ROOT *mem_root
476);
477
478int spider_get_sys_tables_static_link_id(
479 TABLE *table,
480 char **static_link_id,
481 uint *static_link_id_length,
482 MEM_ROOT *mem_root
483);
484
485void spider_get_sys_table_sts_info(
486 TABLE *table,
487 ulonglong *data_file_length,
488 ulonglong *max_data_file_length,
489 ulonglong *index_file_length,
490 ha_rows *records,
491 ulong *mean_rec_length,
492 time_t *check_time,
493 time_t *create_time,
494 time_t *update_time
495);
496
497void spider_get_sys_table_crd_info(
498 TABLE *table,
499 longlong *cardinality,
500 uint number_of_keys
501);
502
503int spider_sys_update_tables_link_status(
504 THD *thd,
505 char *name,
506 uint name_length,
507 int link_idx,
508 long link_status,
509 bool need_lock
510);
511
512int spider_sys_log_tables_link_failed(
513 THD *thd,
514 char *name,
515 uint name_length,
516 int link_idx,
517 bool need_lock
518);
519
520int spider_sys_log_xa_failed(
521 THD *thd,
522 XID *xid,
523 SPIDER_CONN *conn,
524 const char *status,
525 bool need_lock
526);
527
528int spider_get_sys_link_mon_key(
529 TABLE *table,
530 SPIDER_MON_KEY *mon_key,
531 MEM_ROOT *mem_root,
532 int *same
533);
534
535int spider_get_sys_link_mon_server_id(
536 TABLE *table,
537 uint32 *server_id,
538 MEM_ROOT *mem_root
539);
540
541int spider_get_sys_link_mon_connect_info(
542 TABLE *table,
543 SPIDER_SHARE *share,
544 int link_idx,
545 MEM_ROOT *mem_root
546);
547
548int spider_get_link_statuses(
549 TABLE *table,
550 SPIDER_SHARE *share,
551 MEM_ROOT *mem_root
552);
553
554int spider_sys_insert_or_update_table_sts(
555 THD *thd,
556 const char *name,
557 uint name_length,
558 ulonglong *data_file_length,
559 ulonglong *max_data_file_length,
560 ulonglong *index_file_length,
561 ha_rows *records,
562 ulong *mean_rec_length,
563 time_t *check_time,
564 time_t *create_time,
565 time_t *update_time,
566 bool need_lock
567);
568
569int spider_sys_insert_or_update_table_crd(
570 THD *thd,
571 const char *name,
572 uint name_length,
573 longlong *cardinality,
574 uint number_of_keys,
575 bool need_lock
576);
577
578int spider_sys_delete_table_sts(
579 THD *thd,
580 const char *name,
581 uint name_length,
582 bool need_lock
583);
584
585int spider_sys_delete_table_crd(
586 THD *thd,
587 const char *name,
588 uint name_length,
589 bool need_lock
590);
591
592int spider_sys_get_table_sts(
593 THD *thd,
594 const char *name,
595 uint name_length,
596 ulonglong *data_file_length,
597 ulonglong *max_data_file_length,
598 ulonglong *index_file_length,
599 ha_rows *records,
600 ulong *mean_rec_length,
601 time_t *check_time,
602 time_t *create_time,
603 time_t *update_time,
604 bool need_lock
605);
606
607int spider_sys_get_table_crd(
608 THD *thd,
609 const char *name,
610 uint name_length,
611 longlong *cardinality,
612 uint number_of_keys,
613 bool need_lock
614);
615
616int spider_sys_replace(
617 TABLE *table,
618 bool *modified_non_trans_table
619);
620
621TABLE *spider_mk_sys_tmp_table(
622 THD *thd,
623 TABLE *table,
624 TMP_TABLE_PARAM *tmp_tbl_prm,
625 const char *field_name,
626 CHARSET_INFO *cs
627);
628
629void spider_rm_sys_tmp_table(
630 THD *thd,
631 TABLE *tmp_table,
632 TMP_TABLE_PARAM *tmp_tbl_prm
633);
634
635TABLE *spider_mk_sys_tmp_table_for_result(
636 THD *thd,
637 TABLE *table,
638 TMP_TABLE_PARAM *tmp_tbl_prm,
639 const char *field_name1,
640 const char *field_name2,
641 const char *field_name3,
642 CHARSET_INFO *cs
643);
644
645void spider_rm_sys_tmp_table_for_result(
646 THD *thd,
647 TABLE *tmp_table,
648 TMP_TABLE_PARAM *tmp_tbl_prm
649);
650