1/* Copyright (C) 2008-2017 Kentoku Shiba
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
15
16#define MYSQL_SERVER 1
17#include <my_global.h>
18#include "mysql_version.h"
19#include "spd_environ.h"
20#if MYSQL_VERSION_ID < 50500
21#include "mysql_priv.h"
22#include <mysql/plugin.h>
23#else
24#include "sql_priv.h"
25#include "probes_mysql.h"
26#include "sql_class.h"
27#include "key.h"
28#include "sql_base.h"
29#include "tztime.h"
30#endif
31#include "sql_select.h"
32#include "spd_err.h"
33#include "spd_param.h"
34#include "spd_db_include.h"
35#include "spd_include.h"
36#include "spd_sys_table.h"
37#include "spd_malloc.h"
38
39extern handlerton *spider_hton_ptr;
40extern Time_zone *spd_tz_system;
41static const LEX_CSTRING empty_clex_string= {"", 0};
42
43/**
44 Insert a Spider system table row.
45
46 @param table The spider system table.
47 @param do_handle_error TRUE if an error message should be printed
48 before returning.
49
50 @return Error code returned by the write.
51*/
52
53inline int spider_write_sys_table_row(TABLE *table, bool do_handle_error = TRUE)
54{
55 int error_num;
56 THD *thd = table->in_use;
57
58 tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */
59 error_num = table->file->ha_write_row(table->record[0]);
60 reenable_binlog(thd);
61
62 if (error_num && do_handle_error)
63 table->file->print_error(error_num, MYF(0));
64
65 return error_num;
66}
67
68/**
69 Update a Spider system table row.
70
71 @param table The spider system table.
72 @param do_handle_error TRUE if an error message should be printed
73 before returning.
74
75 @return Error code returned by the update.
76*/
77
78inline int spider_update_sys_table_row(TABLE *table, bool do_handle_error = TRUE)
79{
80 int error_num;
81 THD *thd = table->in_use;
82
83 tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */
84 error_num = table->file->ha_update_row(table->record[1], table->record[0]);
85 reenable_binlog(thd);
86
87 if (error_num && do_handle_error)
88 {
89 if (error_num == HA_ERR_RECORD_IS_THE_SAME)
90 error_num = 0;
91 else
92 table->file->print_error(error_num, MYF(0));
93 }
94
95 return error_num;
96}
97
98/**
99 Delete a Spider system table row.
100
101 @param table The spider system table.
102 @param record_number Location of the record: 0 or 1.
103 @param do_handle_error TRUE if an error message should be printed
104 before returning.
105
106 @return Error code returned by the delete.
107*/
108
109inline int spider_delete_sys_table_row(TABLE *table, int record_number = 0,
110 bool do_handle_error = TRUE)
111{
112 int error_num;
113 THD *thd = table->in_use;
114
115 tmp_disable_binlog(thd); /* Do not replicate the low-level changes. */
116 error_num = table->file->ha_delete_row(table->record[record_number]);
117 reenable_binlog(thd);
118
119 if (error_num && do_handle_error)
120 table->file->print_error(error_num, MYF(0));
121
122 return error_num;
123}
124
125#if MYSQL_VERSION_ID < 50500
126TABLE *spider_open_sys_table(
127 THD *thd,
128 const char *table_name,
129 int table_name_length,
130 bool write,
131 Open_tables_state *open_tables_backup,
132 bool need_lock,
133 int *error_num
134)
135#else
136TABLE *spider_open_sys_table(
137 THD *thd,
138 const char *table_name,
139 int table_name_length,
140 bool write,
141 Open_tables_backup *open_tables_backup,
142 bool need_lock,
143 int *error_num
144)
145#endif
146{
147 TABLE *table;
148 TABLE_LIST tables;
149#if MYSQL_VERSION_ID < 50500
150 TABLE_SHARE *table_share;
151 char table_key[MAX_DBKEY_LENGTH];
152 uint table_key_length;
153#endif
154 DBUG_ENTER("spider_open_sys_table");
155
156#if MYSQL_VERSION_ID < 50500
157 memset(&tables, 0, sizeof(TABLE_LIST));
158 tables.db = (char*)"mysql";
159 tables.db_length = sizeof("mysql") - 1;
160 tables.alias = tables.table_name = (char *) table_name;
161 tables.table_name_length = table_name_length;
162 tables.lock_type = (write ? TL_WRITE : TL_READ);
163#else
164 LEX_CSTRING db_name= { "mysql", sizeof("mysql") - 1 };
165 LEX_CSTRING tbl_name= { table_name, (size_t) table_name_length };
166 tables.init_one_table( &db_name, &tbl_name, 0, (write ? TL_WRITE : TL_READ));
167#endif
168
169#if MYSQL_VERSION_ID < 50500
170 if (need_lock)
171 {
172#endif
173#if MYSQL_VERSION_ID < 50500
174 if (!(table = open_performance_schema_table(thd, &tables,
175 open_tables_backup)))
176#else
177 if (!(table = spider_sys_open_table(thd, &tables, open_tables_backup)))
178#endif
179 {
180 my_printf_error(ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM,
181 ER_SPIDER_CANT_OPEN_SYS_TABLE_STR, MYF(0),
182 "mysql", table_name);
183 *error_num = ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM;
184 DBUG_RETURN(NULL);
185 }
186#if MYSQL_VERSION_ID < 50500
187 } else {
188 thd->reset_n_backup_open_tables_state(open_tables_backup);
189
190 if (!(table = (TABLE*) spider_malloc(spider_current_trx, 12,
191 sizeof(*table), MYF(MY_WME))))
192 {
193 *error_num = HA_ERR_OUT_OF_MEM;
194 goto error_malloc;
195 }
196
197 table_key_length =
198 create_table_def_key(thd, table_key, &tables, FALSE);
199
200 if (!(table_share = get_table_share(thd,
201 &tables, table_key, table_key_length, 0, error_num)))
202 goto error;
203 if (open_table_from_share(thd, table_share, tables.alias,
204 (uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE | HA_GET_INDEX),
205 READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD,
206 (uint) HA_OPEN_IGNORE_IF_LOCKED | HA_OPEN_FROM_SQL_LAYER,
207 table, FALSE)
208 ) {
209 release_table_share(table_share, RELEASE_NORMAL);
210 my_printf_error(ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM,
211 ER_SPIDER_CANT_OPEN_SYS_TABLE_STR, MYF(0),
212 "mysql", table_name);
213 *error_num = ER_SPIDER_CANT_OPEN_SYS_TABLE_NUM;
214 goto error;
215 }
216 }
217#endif
218 if (table_name_length == SPIDER_SYS_XA_TABLE_NAME_LEN)
219 {
220 if (
221 !memcmp(table_name,
222 SPIDER_SYS_XA_TABLE_NAME_STR, SPIDER_SYS_XA_TABLE_NAME_LEN) &&
223 table->s->fields != SPIDER_SYS_XA_COL_CNT
224 ) {
225 spider_close_sys_table(thd, table, open_tables_backup, need_lock);
226 table = NULL;
227 my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
228 ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
229 SPIDER_SYS_XA_TABLE_NAME_STR);
230 *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
231 goto error_col_num_chk;
232 }
233 } else if (table_name_length == SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN)
234 {
235 if (
236 !memcmp(table_name,
237 SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR,
238 SPIDER_SYS_XA_MEMBER_TABLE_NAME_LEN) &&
239 table->s->fields != SPIDER_SYS_XA_MEMBER_COL_CNT
240 ) {
241 spider_close_sys_table(thd, table, open_tables_backup, need_lock);
242 table = NULL;
243 my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
244 ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
245 SPIDER_SYS_XA_MEMBER_TABLE_NAME_STR);
246 *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
247 goto error_col_num_chk;
248 }
249 } else if (table_name_length == SPIDER_SYS_TABLES_TABLE_NAME_LEN)
250 {
251 if (
252 !memcmp(table_name,
253 SPIDER_SYS_TABLES_TABLE_NAME_STR,
254 SPIDER_SYS_TABLES_TABLE_NAME_LEN) &&
255 table->s->fields != SPIDER_SYS_TABLES_COL_CNT
256 ) {
257 spider_close_sys_table(thd, table, open_tables_backup, need_lock);
258 table = NULL;
259 my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
260 ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
261 SPIDER_SYS_TABLES_TABLE_NAME_STR);
262 *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
263 goto error_col_num_chk;
264 }
265 } else if (table_name_length == SPIDER_SYS_LINK_MON_TABLE_NAME_LEN)
266 {
267 if (
268 !memcmp(table_name,
269 SPIDER_SYS_LINK_MON_TABLE_NAME_STR,
270 SPIDER_SYS_LINK_MON_TABLE_NAME_LEN) &&
271 table->s->fields != SPIDER_SYS_LINK_MON_TABLE_COL_CNT
272 ) {
273 spider_close_sys_table(thd, table, open_tables_backup, need_lock);
274 table = NULL;
275 my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
276 ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
277 SPIDER_SYS_LINK_MON_TABLE_NAME_STR);
278 *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
279 goto error_col_num_chk;
280 }
281 } else if (table_name_length == SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_LEN)
282 {
283 if (
284 !memcmp(table_name,
285 SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_STR,
286 SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_LEN) &&
287 table->s->fields != SPIDER_SYS_POS_FOR_RECOVERY_TABLE_COL_CNT
288 ) {
289 spider_close_sys_table(thd, table, open_tables_backup, need_lock);
290 table = NULL;
291 my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
292 ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
293 SPIDER_SYS_POS_FOR_RECOVERY_TABLE_NAME_STR);
294 *error_num = ER_SPIDER_SYS_TABLE_VERSION_NUM;
295 goto error_col_num_chk;
296 }
297 }
298 DBUG_RETURN(table);
299
300#if MYSQL_VERSION_ID < 50500
301error:
302 spider_free(spider_current_trx, table, MYF(0));
303error_malloc:
304 thd->restore_backup_open_tables_state(open_tables_backup);
305#endif
306error_col_num_chk:
307 DBUG_RETURN(NULL);
308}
309
310#if MYSQL_VERSION_ID < 50500
311void spider_close_sys_table(
312 THD *thd,
313 TABLE *table,
314 Open_tables_state *open_tables_backup,
315 bool need_lock
316)
317#else
318void spider_close_sys_table(
319 THD *thd,
320 TABLE *table,
321 Open_tables_backup *open_tables_backup,
322 bool need_lock
323)
324#endif
325{
326 DBUG_ENTER("spider_close_sys_table");
327#if MYSQL_VERSION_ID < 50500
328 if (need_lock)
329 {
330 close_performance_schema_table(thd, open_tables_backup);
331 } else {
332 table->file->ha_reset();
333 closefrm(table, TRUE);
334 spider_free(spider_current_trx, table, MYF(0));
335 thd->restore_backup_open_tables_state(open_tables_backup);
336 }
337#else
338 spider_sys_close_table(thd, open_tables_backup);
339#endif
340 DBUG_VOID_RETURN;
341}
342
343#if MYSQL_VERSION_ID < 50500
344#else
345bool spider_sys_open_tables(
346 THD *thd,
347 TABLE_LIST **tables,
348 Open_tables_backup *open_tables_backup
349) {
350 uint counter;
351 ulonglong utime_after_lock_backup = thd->utime_after_lock;
352 DBUG_ENTER("spider_sys_open_tables");
353 thd->reset_n_backup_open_tables_state(open_tables_backup);
354 if (open_tables(thd, tables, &counter,
355 MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY |
356 MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT | MYSQL_LOCK_LOG_TABLE
357 )) {
358 thd->restore_backup_open_tables_state(open_tables_backup);
359 thd->utime_after_lock = utime_after_lock_backup;
360 DBUG_RETURN(TRUE);
361 }
362 thd->utime_after_lock = utime_after_lock_backup;
363 DBUG_RETURN(FALSE);
364}
365
366TABLE *spider_sys_open_table(
367 THD *thd,
368 TABLE_LIST *tables,
369 Open_tables_backup *open_tables_backup
370) {
371 TABLE *table;
372 ulonglong utime_after_lock_backup = thd->utime_after_lock;
373 DBUG_ENTER("spider_sys_open_table");
374 thd->reset_n_backup_open_tables_state(open_tables_backup);
375 if ((table = open_ltable(thd, tables, tables->lock_type,
376 MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK | MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY |
377 MYSQL_OPEN_IGNORE_FLUSH | MYSQL_LOCK_IGNORE_TIMEOUT | MYSQL_LOCK_LOG_TABLE
378 ))) {
379 table->use_all_columns();
380 table->s->no_replicate = 1;
381 } else
382 thd->restore_backup_open_tables_state(open_tables_backup);
383 thd->utime_after_lock = utime_after_lock_backup;
384 DBUG_RETURN(table);
385}
386
387void spider_sys_close_table(
388 THD *thd,
389 Open_tables_backup *open_tables_backup
390) {
391 DBUG_ENTER("spider_sys_close_table");
392 close_thread_tables(thd);
393 thd->restore_backup_open_tables_state(open_tables_backup);
394 DBUG_VOID_RETURN;
395}
396#endif
397
398int spider_sys_index_init(
399 TABLE *table,
400 uint idx,
401 bool sorted
402) {
403 DBUG_ENTER("spider_sys_index_init");
404 DBUG_RETURN(table->file->ha_index_init(idx, sorted));
405}
406
407int spider_sys_index_end(
408 TABLE *table
409) {
410 DBUG_ENTER("spider_sys_index_end");
411 DBUG_RETURN(table->file->ha_index_end());
412}
413
414int spider_sys_rnd_init(
415 TABLE *table,
416 bool scan
417) {
418 DBUG_ENTER("spider_sys_rnd_init");
419 DBUG_RETURN(table->file->ha_rnd_init(scan));
420}
421
422int spider_sys_rnd_end(
423 TABLE *table
424) {
425 DBUG_ENTER("spider_sys_rnd_end");
426 DBUG_RETURN(table->file->ha_rnd_end());
427}
428
429int spider_check_sys_table(
430 TABLE *table,
431 char *table_key
432) {
433 DBUG_ENTER("spider_check_sys_table");
434
435 key_copy(
436 (uchar *) table_key,
437 table->record[0],
438 table->key_info,
439 table->key_info->key_length);
440
441#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
442 DBUG_RETURN(table->file->ha_index_read_idx_map(
443 table->record[0], 0, (uchar *) table_key,
444 HA_WHOLE_KEY, HA_READ_KEY_EXACT));
445#else
446 DBUG_RETURN(table->file->index_read_idx_map(
447 table->record[0], 0, (uchar *) table_key,
448 HA_WHOLE_KEY, HA_READ_KEY_EXACT));
449#endif
450}
451
452int spider_check_sys_table_with_find_flag(
453 TABLE *table,
454 char *table_key,
455 enum ha_rkey_function find_flag
456) {
457 DBUG_ENTER("spider_check_sys_table");
458
459 key_copy(
460 (uchar *) table_key,
461 table->record[0],
462 table->key_info,
463 table->key_info->key_length);
464
465#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
466 DBUG_RETURN(table->file->ha_index_read_idx_map(
467 table->record[0], 0, (uchar *) table_key,
468 HA_WHOLE_KEY, find_flag));
469#else
470 DBUG_RETURN(table->file->index_read_idx_map(
471 table->record[0], 0, (uchar *) table_key,
472 HA_WHOLE_KEY, find_flag));
473#endif
474}
475
476int spider_check_sys_table_for_update_all_columns(
477 TABLE *table,
478 char *table_key
479) {
480 DBUG_ENTER("spider_check_sys_table_for_update_all_columns");
481
482 key_copy(
483 (uchar *) table_key,
484 table->record[0],
485 table->key_info,
486 table->key_info->key_length);
487
488#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
489 DBUG_RETURN(table->file->ha_index_read_idx_map(
490 table->record[1], 0, (uchar *) table_key,
491 HA_WHOLE_KEY, HA_READ_KEY_EXACT));
492#else
493 DBUG_RETURN(table->file->index_read_idx_map(
494 table->record[1], 0, (uchar *) table_key,
495 HA_WHOLE_KEY, HA_READ_KEY_EXACT));
496#endif
497}
498
499int spider_get_sys_table_by_idx(
500 TABLE *table,
501 char *table_key,
502 const int idx,
503 const int col_count
504) {
505 int error_num;
506 uint key_length;
507 KEY *key_info = table->key_info;
508 DBUG_ENTER("spider_get_sys_table_by_idx");
509 if ((error_num = spider_sys_index_init(table, idx, FALSE)))
510 DBUG_RETURN(error_num);
511
512 if ((int) spider_user_defined_key_parts(key_info) == col_count)
513 {
514 key_length = key_info->key_length;
515 } else {
516 int roop_count;
517 key_length = 0;
518 for (roop_count = 0; roop_count < col_count; ++roop_count)
519 {
520 key_length += key_info->key_part[roop_count].store_length;
521 }
522 }
523
524 key_copy(
525 (uchar *) table_key,
526 table->record[0],
527 key_info,
528 key_length);
529
530 if (
531/*
532#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
533 (error_num = table->file->ha_index_read_idx_map(
534 table->record[0], idx, (uchar *) table_key,
535 make_prev_keypart_map(col_count), HA_READ_KEY_EXACT))
536#else
537 (error_num = table->file->index_read_idx_map(
538 table->record[0], idx, (uchar *) table_key,
539 make_prev_keypart_map(col_count), HA_READ_KEY_EXACT))
540#endif
541*/
542#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
543 (error_num = table->file->ha_index_read_map(
544 table->record[0], (uchar *) table_key,
545 make_prev_keypart_map(col_count), HA_READ_KEY_EXACT))
546#else
547 (error_num = table->file->index_read_map(
548 table->record[0], (uchar *) table_key,
549 make_prev_keypart_map(col_count), HA_READ_KEY_EXACT))
550#endif
551 ) {
552 spider_sys_index_end(table);
553 DBUG_RETURN(error_num);
554 }
555 DBUG_RETURN(0);
556}
557
558int spider_sys_index_next_same(
559 TABLE *table,
560 char *table_key
561) {
562 DBUG_ENTER("spider_sys_index_next_same");
563#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
564 DBUG_RETURN(table->file->ha_index_next_same(
565 table->record[0],
566 (const uchar*) table_key,
567 table->key_info->key_length));
568#else
569 DBUG_RETURN(table->file->index_next_same(
570 table->record[0],
571 (const uchar*) table_key,
572 table->key_info->key_length));
573#endif
574}
575
576int spider_sys_index_first(
577 TABLE *table,
578 const int idx
579) {
580 int error_num;
581 DBUG_ENTER("spider_sys_index_first");
582 if ((error_num = spider_sys_index_init(table, idx, FALSE)))
583 DBUG_RETURN(error_num);
584
585 if (
586#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
587 (error_num = table->file->ha_index_first(table->record[0]))
588#else
589 (error_num = table->file->index_first(table->record[0]))
590#endif
591 ) {
592 spider_sys_index_end(table);
593 DBUG_RETURN(error_num);
594 }
595 DBUG_RETURN(0);
596}
597
598int spider_sys_index_next(
599 TABLE *table
600) {
601 DBUG_ENTER("spider_sys_index_next");
602#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
603 DBUG_RETURN(table->file->ha_index_next(table->record[0]));
604#else
605 DBUG_RETURN(table->file->index_next(table->record[0]));
606#endif
607}
608
609void spider_store_xa_pk(
610 TABLE *table,
611 XID *xid
612) {
613 DBUG_ENTER("spider_store_xa_pk");
614 table->field[0]->store(xid->formatID);
615 table->field[1]->store(xid->gtrid_length);
616 table->field[3]->store(
617 xid->data,
618 (uint) xid->gtrid_length + xid->bqual_length,
619 system_charset_info);
620 DBUG_VOID_RETURN;
621}
622
623void spider_store_xa_bqual_length(
624 TABLE *table,
625 XID *xid
626) {
627 DBUG_ENTER("spider_store_xa_bqual_length");
628 table->field[2]->store(xid->bqual_length);
629 DBUG_VOID_RETURN;
630}
631
632void spider_store_xa_status(
633 TABLE *table,
634 const char *status
635) {
636 DBUG_ENTER("spider_store_xa_status");
637 table->field[4]->store(
638 status,
639 (uint) strlen(status),
640 system_charset_info);
641 DBUG_VOID_RETURN;
642}
643
644void spider_store_xa_member_pk(
645 TABLE *table,
646 XID *xid,
647 SPIDER_CONN *conn
648) {
649 DBUG_ENTER("spider_store_xa_member_pk");
650 table->field[0]->store(xid->formatID);
651 table->field[1]->store(xid->gtrid_length);
652 table->field[3]->store(
653 xid->data,
654 (uint) xid->gtrid_length + xid->bqual_length,
655 system_charset_info);
656 table->field[5]->store(
657 conn->tgt_host,
658 (uint) conn->tgt_host_length,
659 system_charset_info);
660 table->field[6]->store(
661 conn->tgt_port);
662 table->field[7]->store(
663 conn->tgt_socket,
664 (uint) conn->tgt_socket_length,
665 system_charset_info);
666 DBUG_VOID_RETURN;
667}
668
669void spider_store_xa_member_info(
670 TABLE *table,
671 XID *xid,
672 SPIDER_CONN *conn
673) {
674 DBUG_ENTER("spider_store_xa_member_info");
675 table->field[2]->store(xid->bqual_length);
676 table->field[4]->store(
677 conn->tgt_wrapper,
678 (uint) conn->tgt_wrapper_length,
679 system_charset_info);
680 table->field[8]->store(
681 conn->tgt_username,
682 (uint) conn->tgt_username_length,
683 system_charset_info);
684 table->field[9]->store(
685 conn->tgt_password,
686 (uint) conn->tgt_password_length,
687 system_charset_info);
688 if (conn->tgt_ssl_ca)
689 {
690 table->field[10]->set_notnull();
691 table->field[10]->store(
692 conn->tgt_ssl_ca,
693 (uint) conn->tgt_ssl_ca_length,
694 system_charset_info);
695 } else {
696 table->field[10]->set_null();
697 table->field[10]->reset();
698 }
699 if (conn->tgt_ssl_capath)
700 {
701 table->field[11]->set_notnull();
702 table->field[11]->store(
703 conn->tgt_ssl_capath,
704 (uint) conn->tgt_ssl_capath_length,
705 system_charset_info);
706 } else {
707 table->field[11]->set_null();
708 table->field[11]->reset();
709 }
710 if (conn->tgt_ssl_cert)
711 {
712 table->field[12]->set_notnull();
713 table->field[12]->store(
714 conn->tgt_ssl_cert,
715 (uint) conn->tgt_ssl_cert_length,
716 system_charset_info);
717 } else {
718 table->field[12]->set_null();
719 table->field[12]->reset();
720 }
721 if (conn->tgt_ssl_cipher)
722 {
723 table->field[13]->set_notnull();
724 table->field[13]->store(
725 conn->tgt_ssl_cipher,
726 (uint) conn->tgt_ssl_cipher_length,
727 system_charset_info);
728 } else {
729 table->field[13]->set_null();
730 table->field[13]->reset();
731 }
732 if (conn->tgt_ssl_key)
733 {
734 table->field[14]->set_notnull();
735 table->field[14]->store(
736 conn->tgt_ssl_key,
737 (uint) conn->tgt_ssl_key_length,
738 system_charset_info);
739 } else {
740 table->field[14]->set_null();
741 table->field[14]->reset();
742 }
743 if (conn->tgt_ssl_vsc >= 0)
744 {
745 table->field[15]->set_notnull();
746 table->field[15]->store(
747 conn->tgt_ssl_vsc);
748 } else {
749 table->field[15]->set_null();
750 table->field[15]->reset();
751 }
752 if (conn->tgt_default_file)
753 {
754 table->field[16]->set_notnull();
755 table->field[16]->store(
756 conn->tgt_default_file,
757 (uint) conn->tgt_default_file_length,
758 system_charset_info);
759 } else {
760 table->field[16]->set_null();
761 table->field[16]->reset();
762 }
763 if (conn->tgt_default_group)
764 {
765 table->field[17]->set_notnull();
766 table->field[17]->store(
767 conn->tgt_default_group,
768 (uint) conn->tgt_default_group_length,
769 system_charset_info);
770 } else {
771 table->field[17]->set_null();
772 table->field[17]->reset();
773 }
774 DBUG_VOID_RETURN;
775}
776
777void spider_store_tables_name(
778 TABLE *table,
779 const char *name,
780 const uint name_length
781) {
782 const char *ptr_db, *ptr_table;
783 my_ptrdiff_t ptr_diff_db, ptr_diff_table;
784 DBUG_ENTER("spider_store_tables_name");
785 if (name[0] == FN_CURLIB && name[1] == FN_LIBCHAR)
786 {
787 ptr_db = strchr(name, FN_LIBCHAR);
788 ptr_db++;
789 ptr_diff_db = PTR_BYTE_DIFF(ptr_db, name);
790 DBUG_PRINT("info",("spider ptr_diff_db = %lld", (longlong) ptr_diff_db));
791 ptr_table = strchr(ptr_db, FN_LIBCHAR);
792 ptr_table++;
793 ptr_diff_table = PTR_BYTE_DIFF(ptr_table, ptr_db);
794 DBUG_PRINT("info",("spider ptr_diff_table = %lld",
795 (longlong) ptr_diff_table));
796 } else {
797 DBUG_PRINT("info",("spider temporary table"));
798 ptr_db = "";
799 ptr_diff_db = 1;
800 ptr_table = "";
801 ptr_diff_table = 1;
802 }
803 table->field[0]->store(
804 ptr_db,
805 (uint)(ptr_diff_table - 1),
806 system_charset_info);
807 DBUG_PRINT("info",("spider field[0]->null_bit = %d",
808 table->field[0]->null_bit));
809 table->field[1]->store(
810 ptr_table,
811 (uint) ((my_ptrdiff_t) name_length - ptr_diff_db - ptr_diff_table),
812 system_charset_info);
813 DBUG_PRINT("info",("spider field[1]->null_bit = %d",
814 table->field[1]->null_bit));
815 DBUG_VOID_RETURN;
816}
817
818void spider_store_db_and_table_name(
819 TABLE *table,
820 const char *db_name,
821 const uint db_name_length,
822 const char *table_name,
823 const uint table_name_length
824) {
825 DBUG_ENTER("spider_store_db_and_table_name");
826 table->field[0]->store(
827 db_name,
828 db_name_length,
829 system_charset_info);
830 DBUG_PRINT("info",("spider field[0]->null_bit = %d",
831 table->field[0]->null_bit));
832 table->field[1]->store(
833 table_name,
834 table_name_length,
835 system_charset_info);
836 DBUG_PRINT("info",("spider field[1]->null_bit = %d",
837 table->field[1]->null_bit));
838 DBUG_VOID_RETURN;
839}
840
841void spider_store_tables_link_idx(
842 TABLE *table,
843 int link_idx
844) {
845 DBUG_ENTER("spider_store_tables_link_idx");
846 table->field[2]->set_notnull();
847 table->field[2]->store(link_idx);
848 DBUG_VOID_RETURN;
849}
850
851void spider_store_tables_link_idx_str(
852 TABLE *table,
853 const char *link_idx,
854 const uint link_idx_length
855) {
856 DBUG_ENTER("spider_store_tables_link_idx_str");
857 table->field[2]->store(
858 link_idx,
859 link_idx_length,
860 system_charset_info);
861 DBUG_PRINT("info",("spider field[2]->null_bit = %d",
862 table->field[2]->null_bit));
863 DBUG_VOID_RETURN;
864}
865
866void spider_store_tables_static_link_id(
867 TABLE *table,
868 const char *static_link_id,
869 const uint static_link_id_length
870) {
871 DBUG_ENTER("spider_store_tables_static_link_id");
872 if (static_link_id)
873 {
874 table->field[24]->set_notnull();
875 table->field[24]->store(
876 static_link_id,
877 static_link_id_length,
878 system_charset_info);
879 } else {
880 table->field[24]->set_null();
881 table->field[24]->reset();
882 }
883 DBUG_VOID_RETURN;
884}
885
886void spider_store_tables_priority(
887 TABLE *table,
888 longlong priority
889) {
890 DBUG_ENTER("spider_store_tables_priority");
891 DBUG_PRINT("info",("spider priority = %lld", priority));
892 table->field[3]->store(priority, FALSE);
893 DBUG_VOID_RETURN;
894}
895
896void spider_store_tables_connect_info(
897 TABLE *table,
898 SPIDER_ALTER_TABLE *alter_table,
899 int link_idx
900) {
901 DBUG_ENTER("spider_store_tables_connect_info");
902 if (alter_table->tmp_server_names[link_idx])
903 {
904 table->field[4]->set_notnull();
905 table->field[4]->store(
906 alter_table->tmp_server_names[link_idx],
907 (uint) alter_table->tmp_server_names_lengths[link_idx],
908 system_charset_info);
909 } else {
910 table->field[4]->set_null();
911 table->field[4]->reset();
912 }
913 if (alter_table->tmp_tgt_wrappers[link_idx])
914 {
915 table->field[5]->set_notnull();
916 table->field[5]->store(
917 alter_table->tmp_tgt_wrappers[link_idx],
918 (uint) alter_table->tmp_tgt_wrappers_lengths[link_idx],
919 system_charset_info);
920 } else {
921 table->field[5]->set_null();
922 table->field[5]->reset();
923 }
924 if (alter_table->tmp_tgt_hosts[link_idx])
925 {
926 table->field[6]->set_notnull();
927 table->field[6]->store(
928 alter_table->tmp_tgt_hosts[link_idx],
929 (uint) alter_table->tmp_tgt_hosts_lengths[link_idx],
930 system_charset_info);
931 } else {
932 table->field[6]->set_null();
933 table->field[6]->reset();
934 }
935 if (alter_table->tmp_tgt_ports[link_idx] >= 0)
936 {
937 table->field[7]->set_notnull();
938 table->field[7]->store(
939 alter_table->tmp_tgt_ports[link_idx]);
940 } else {
941 table->field[7]->set_null();
942 table->field[7]->reset();
943 }
944 if (alter_table->tmp_tgt_sockets[link_idx])
945 {
946 table->field[8]->set_notnull();
947 table->field[8]->store(
948 alter_table->tmp_tgt_sockets[link_idx],
949 (uint) alter_table->tmp_tgt_sockets_lengths[link_idx],
950 system_charset_info);
951 } else {
952 table->field[8]->set_null();
953 table->field[8]->reset();
954 }
955 if (alter_table->tmp_tgt_usernames[link_idx])
956 {
957 table->field[9]->set_notnull();
958 table->field[9]->store(
959 alter_table->tmp_tgt_usernames[link_idx],
960 (uint) alter_table->tmp_tgt_usernames_lengths[link_idx],
961 system_charset_info);
962 } else {
963 table->field[9]->set_null();
964 table->field[9]->reset();
965 }
966 if (alter_table->tmp_tgt_passwords[link_idx])
967 {
968 table->field[10]->set_notnull();
969 table->field[10]->store(
970 alter_table->tmp_tgt_passwords[link_idx],
971 (uint) alter_table->tmp_tgt_passwords_lengths[link_idx],
972 system_charset_info);
973 } else {
974 table->field[10]->set_null();
975 table->field[10]->reset();
976 }
977 if (alter_table->tmp_tgt_ssl_cas[link_idx])
978 {
979 table->field[11]->set_notnull();
980 table->field[11]->store(
981 alter_table->tmp_tgt_ssl_cas[link_idx],
982 (uint) alter_table->tmp_tgt_ssl_cas_lengths[link_idx],
983 system_charset_info);
984 } else {
985 table->field[11]->set_null();
986 table->field[11]->reset();
987 }
988 if (alter_table->tmp_tgt_ssl_capaths[link_idx])
989 {
990 table->field[12]->set_notnull();
991 table->field[12]->store(
992 alter_table->tmp_tgt_ssl_capaths[link_idx],
993 (uint) alter_table->tmp_tgt_ssl_capaths_lengths[link_idx],
994 system_charset_info);
995 } else {
996 table->field[12]->set_null();
997 table->field[12]->reset();
998 }
999 if (alter_table->tmp_tgt_ssl_certs[link_idx])
1000 {
1001 table->field[13]->set_notnull();
1002 table->field[13]->store(
1003 alter_table->tmp_tgt_ssl_certs[link_idx],
1004 (uint) alter_table->tmp_tgt_ssl_certs_lengths[link_idx],
1005 system_charset_info);
1006 } else {
1007 table->field[13]->set_null();
1008 table->field[13]->reset();
1009 }
1010 if (alter_table->tmp_tgt_ssl_ciphers[link_idx])
1011 {
1012 table->field[14]->set_notnull();
1013 table->field[14]->store(
1014 alter_table->tmp_tgt_ssl_ciphers[link_idx],
1015 (uint) alter_table->tmp_tgt_ssl_ciphers_lengths[link_idx],
1016 system_charset_info);
1017 } else {
1018 table->field[14]->set_null();
1019 table->field[14]->reset();
1020 }
1021 if (alter_table->tmp_tgt_ssl_keys[link_idx])
1022 {
1023 table->field[15]->set_notnull();
1024 table->field[15]->store(
1025 alter_table->tmp_tgt_ssl_keys[link_idx],
1026 (uint) alter_table->tmp_tgt_ssl_keys_lengths[link_idx],
1027 system_charset_info);
1028 } else {
1029 table->field[15]->set_null();
1030 table->field[15]->reset();
1031 }
1032 if (alter_table->tmp_tgt_ssl_vscs[link_idx] >= 0)
1033 {
1034 table->field[16]->set_notnull();
1035 table->field[16]->store(
1036 alter_table->tmp_tgt_ssl_vscs[link_idx]);
1037 } else {
1038 table->field[16]->set_null();
1039 table->field[16]->reset();
1040 }
1041 table->field[17]->set_notnull();
1042 if (alter_table->tmp_monitoring_binlog_pos_at_failing[link_idx] >= 0)
1043 {
1044 table->field[17]->store(
1045 alter_table->tmp_monitoring_binlog_pos_at_failing[link_idx]);
1046 } else {
1047 table->field[17]->store(0);
1048 }
1049 if (alter_table->tmp_tgt_default_files[link_idx])
1050 {
1051 table->field[18]->set_notnull();
1052 table->field[18]->store(
1053 alter_table->tmp_tgt_default_files[link_idx],
1054 (uint) alter_table->tmp_tgt_default_files_lengths[link_idx],
1055 system_charset_info);
1056 } else {
1057 table->field[18]->set_null();
1058 table->field[18]->reset();
1059 }
1060 if (alter_table->tmp_tgt_default_groups[link_idx])
1061 {
1062 table->field[19]->set_notnull();
1063 table->field[19]->store(
1064 alter_table->tmp_tgt_default_groups[link_idx],
1065 (uint) alter_table->tmp_tgt_default_groups_lengths[link_idx],
1066 system_charset_info);
1067 } else {
1068 table->field[19]->set_null();
1069 table->field[19]->reset();
1070 }
1071 if (alter_table->tmp_tgt_dbs[link_idx])
1072 {
1073 table->field[20]->set_notnull();
1074 table->field[20]->store(
1075 alter_table->tmp_tgt_dbs[link_idx],
1076 (uint) alter_table->tmp_tgt_dbs_lengths[link_idx],
1077 system_charset_info);
1078 } else {
1079 table->field[20]->set_null();
1080 table->field[20]->reset();
1081 }
1082 if (alter_table->tmp_tgt_table_names[link_idx])
1083 {
1084 table->field[21]->set_notnull();
1085 table->field[21]->store(
1086 alter_table->tmp_tgt_table_names[link_idx],
1087 (uint) alter_table->tmp_tgt_table_names_lengths[link_idx],
1088 system_charset_info);
1089 } else {
1090 table->field[21]->set_null();
1091 table->field[21]->reset();
1092 }
1093 table->field[23]->store((longlong) 0, FALSE);
1094 if (alter_table->tmp_static_link_ids[link_idx])
1095 {
1096 DBUG_PRINT("info",("spider static_link_id[%d] = %s",
1097 link_idx, alter_table->tmp_static_link_ids[link_idx]));
1098 table->field[24]->set_notnull();
1099 table->field[24]->store(
1100 alter_table->tmp_static_link_ids[link_idx],
1101 (uint) alter_table->tmp_static_link_ids_lengths[link_idx],
1102 system_charset_info);
1103 } else {
1104 DBUG_PRINT("info",("spider static_link_id[%d] = NULL", link_idx));
1105 table->field[24]->set_null();
1106 table->field[24]->reset();
1107 }
1108 DBUG_VOID_RETURN;
1109}
1110
1111void spider_store_tables_link_status(
1112 TABLE *table,
1113 long link_status
1114) {
1115 DBUG_ENTER("spider_store_tables_link_status");
1116 DBUG_PRINT("info",("spider link_status = %ld", link_status));
1117 if (link_status > SPIDER_LINK_STATUS_NO_CHANGE)
1118 table->field[22]->store(link_status, FALSE);
1119 DBUG_VOID_RETURN;
1120}
1121
1122void spider_store_link_chk_server_id(
1123 TABLE *table,
1124 uint32 server_id
1125) {
1126 DBUG_ENTER("spider_store_link_chk_server_id");
1127 table->field[3]->set_notnull();
1128 table->field[3]->store(server_id);
1129 DBUG_VOID_RETURN;
1130}
1131
1132void spider_store_binlog_pos_failed_link_idx(
1133 TABLE *table,
1134 int failed_link_idx
1135) {
1136 DBUG_ENTER("spider_store_binlog_pos_failed_link_idx");
1137 table->field[2]->set_notnull();
1138 table->field[2]->store(failed_link_idx);
1139 DBUG_VOID_RETURN;
1140}
1141
1142void spider_store_binlog_pos_source_link_idx(
1143 TABLE *table,
1144 int source_link_idx
1145) {
1146 DBUG_ENTER("spider_store_binlog_pos_source_link_idx");
1147 table->field[3]->set_notnull();
1148 table->field[3]->store(source_link_idx);
1149 DBUG_VOID_RETURN;
1150}
1151
1152void spider_store_binlog_pos_binlog_file(
1153 TABLE *table,
1154 const char *file_name,
1155 int file_name_length,
1156 const char *position,
1157 int position_length,
1158 CHARSET_INFO *binlog_pos_cs
1159) {
1160 DBUG_ENTER("spider_store_binlog_pos_binlog_file");
1161 if (!file_name)
1162 {
1163 DBUG_PRINT("info",("spider file_name is NULL"));
1164 table->field[4]->set_null();
1165 table->field[4]->reset();
1166 } else {
1167 DBUG_PRINT("info",("spider file_name = %s", file_name));
1168 table->field[4]->set_notnull();
1169 table->field[4]->store(file_name, file_name_length, binlog_pos_cs);
1170 }
1171 if (!position)
1172 {
1173 DBUG_PRINT("info",("spider position is NULL"));
1174 table->field[5]->set_null();
1175 table->field[5]->reset();
1176 } else {
1177 DBUG_PRINT("info",("spider position = %s", position));
1178 table->field[5]->set_notnull();
1179 table->field[5]->store(position, position_length, binlog_pos_cs);
1180 }
1181 DBUG_VOID_RETURN;
1182}
1183
1184void spider_store_binlog_pos_gtid(
1185 TABLE *table,
1186 const char *gtid,
1187 int gtid_length,
1188 CHARSET_INFO *binlog_pos_cs
1189) {
1190 DBUG_ENTER("spider_store_binlog_pos_gtid");
1191 if (!gtid)
1192 {
1193 DBUG_PRINT("info",("spider gtid is NULL"));
1194 table->field[6]->set_null();
1195 table->field[6]->reset();
1196 } else {
1197 DBUG_PRINT("info",("spider gtid = %s", gtid));
1198 table->field[6]->set_notnull();
1199 table->field[6]->store(gtid, gtid_length, binlog_pos_cs);
1200 }
1201 DBUG_VOID_RETURN;
1202}
1203
1204void spider_store_table_sts_info(
1205 TABLE *table,
1206 ulonglong *data_file_length,
1207 ulonglong *max_data_file_length,
1208 ulonglong *index_file_length,
1209 ha_rows *records,
1210 ulong *mean_rec_length,
1211 time_t *check_time,
1212 time_t *create_time,
1213 time_t *update_time
1214) {
1215 MYSQL_TIME mysql_time;
1216 DBUG_ENTER("spider_store_table_sts_info");
1217 table->field[2]->store((longlong) *data_file_length, TRUE);
1218 table->field[3]->store((longlong) *max_data_file_length, TRUE);
1219 table->field[4]->store((longlong) *index_file_length, TRUE);
1220 table->field[5]->store((longlong) *records, TRUE);
1221 table->field[6]->store((longlong) *mean_rec_length, TRUE);
1222 spd_tz_system->gmt_sec_to_TIME(&mysql_time, (my_time_t) *check_time);
1223 table->field[7]->store_time(&mysql_time);
1224 spd_tz_system->gmt_sec_to_TIME(&mysql_time, (my_time_t) *create_time);
1225 table->field[8]->store_time(&mysql_time);
1226 spd_tz_system->gmt_sec_to_TIME(&mysql_time, (my_time_t) *update_time);
1227 table->field[9]->store_time(&mysql_time);
1228 DBUG_VOID_RETURN;
1229}
1230
1231void spider_store_table_crd_info(
1232 TABLE *table,
1233 uint *seq,
1234 longlong *cardinality
1235) {
1236 DBUG_ENTER("spider_store_table_crd_info");
1237 table->field[2]->store((longlong) *seq, TRUE);
1238 table->field[3]->store((longlong) *cardinality, FALSE);
1239 DBUG_VOID_RETURN;
1240}
1241
1242int spider_insert_xa(
1243 TABLE *table,
1244 XID *xid,
1245 const char *status
1246) {
1247 int error_num;
1248 char table_key[MAX_KEY_LENGTH];
1249 DBUG_ENTER("spider_insert_xa");
1250 table->use_all_columns();
1251 empty_record(table);
1252 spider_store_xa_pk(table, xid);
1253
1254 if ((error_num = spider_check_sys_table(table, table_key)))
1255 {
1256 if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
1257 {
1258 table->file->print_error(error_num, MYF(0));
1259 DBUG_RETURN(error_num);
1260 }
1261 table->use_all_columns();
1262 spider_store_xa_bqual_length(table, xid);
1263 spider_store_xa_status(table, status);
1264 if ((error_num = spider_write_sys_table_row(table)))
1265 DBUG_RETURN(error_num);
1266 } else {
1267 my_message(ER_SPIDER_XA_EXISTS_NUM, ER_SPIDER_XA_EXISTS_STR, MYF(0));
1268 DBUG_RETURN(ER_SPIDER_XA_EXISTS_NUM);
1269 }
1270
1271 DBUG_RETURN(0);
1272}
1273
1274int spider_insert_xa_member(
1275 TABLE *table,
1276 XID *xid,
1277 SPIDER_CONN *conn
1278) {
1279 int error_num;
1280 char table_key[MAX_KEY_LENGTH];
1281 DBUG_ENTER("spider_insert_xa_member");
1282 table->use_all_columns();
1283 empty_record(table);
1284 spider_store_xa_member_pk(table, xid, conn);
1285
1286 if ((error_num = spider_check_sys_table(table, table_key)))
1287 {
1288 if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
1289 {
1290 table->file->print_error(error_num, MYF(0));
1291 DBUG_RETURN(error_num);
1292 }
1293 table->use_all_columns();
1294 spider_store_xa_member_info(table, xid, conn);
1295 if ((error_num = spider_write_sys_table_row(table)))
1296 DBUG_RETURN(error_num);
1297 } else {
1298 my_message(ER_SPIDER_XA_MEMBER_EXISTS_NUM, ER_SPIDER_XA_MEMBER_EXISTS_STR,
1299 MYF(0));
1300 DBUG_RETURN(ER_SPIDER_XA_MEMBER_EXISTS_NUM);
1301 }
1302
1303 DBUG_RETURN(0);
1304}
1305
1306int spider_insert_tables(
1307 TABLE *table,
1308 SPIDER_SHARE *share
1309) {
1310 int error_num, roop_count;
1311 DBUG_ENTER("spider_insert_tables");
1312 table->use_all_columns();
1313 empty_record(table);
1314
1315 spider_store_tables_name(table, share->table_name, share->table_name_length);
1316 spider_store_tables_priority(table, share->priority);
1317 for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++)
1318 {
1319 spider_store_tables_link_idx(table, roop_count);
1320 spider_store_tables_connect_info(table, &share->alter_table, roop_count);
1321 spider_store_tables_link_status(table,
1322 share->alter_table.tmp_link_statuses[roop_count] >
1323 SPIDER_LINK_STATUS_NO_CHANGE ?
1324 share->alter_table.tmp_link_statuses[roop_count] :
1325 SPIDER_LINK_STATUS_OK);
1326 if ((error_num = spider_write_sys_table_row(table)))
1327 DBUG_RETURN(error_num);
1328 }
1329
1330 DBUG_RETURN(0);
1331}
1332
1333int spider_insert_sys_table(
1334 TABLE *table
1335) {
1336 int error_num;
1337 DBUG_ENTER("spider_insert_sys_table");
1338 if ((error_num = spider_write_sys_table_row(table)))
1339 DBUG_RETURN(error_num);
1340 DBUG_RETURN(0);
1341}
1342
1343int spider_insert_or_update_table_sts(
1344 TABLE *table,
1345 const char *name,
1346 uint name_length,
1347 ulonglong *data_file_length,
1348 ulonglong *max_data_file_length,
1349 ulonglong *index_file_length,
1350 ha_rows *records,
1351 ulong *mean_rec_length,
1352 time_t *check_time,
1353 time_t *create_time,
1354 time_t *update_time
1355) {
1356 int error_num;
1357 char table_key[MAX_KEY_LENGTH];
1358 DBUG_ENTER("spider_insert_or_update_table_sts");
1359 table->use_all_columns();
1360 spider_store_tables_name(table, name, name_length);
1361 spider_store_table_sts_info(
1362 table,
1363 data_file_length,
1364 max_data_file_length,
1365 index_file_length,
1366 records,
1367 mean_rec_length,
1368 check_time,
1369 create_time,
1370 update_time
1371 );
1372
1373 if ((error_num = spider_check_sys_table_for_update_all_columns(table, table_key)))
1374 {
1375 if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
1376 {
1377 table->file->print_error(error_num, MYF(0));
1378 DBUG_RETURN(error_num);
1379 }
1380 if ((error_num = spider_write_sys_table_row(table)))
1381 DBUG_RETURN(error_num);
1382 } else {
1383 if ((error_num = spider_update_sys_table_row(table, FALSE)))
1384 {
1385 table->file->print_error(error_num, MYF(0));
1386 DBUG_RETURN(error_num);
1387 }
1388 }
1389
1390 DBUG_RETURN(0);
1391}
1392
1393int spider_insert_or_update_table_crd(
1394 TABLE *table,
1395 const char *name,
1396 uint name_length,
1397 longlong *cardinality,
1398 uint number_of_keys
1399) {
1400 int error_num;
1401 uint roop_count;
1402 char table_key[MAX_KEY_LENGTH];
1403 DBUG_ENTER("spider_insert_or_update_table_crd");
1404 table->use_all_columns();
1405 spider_store_tables_name(table, name, name_length);
1406
1407 for (roop_count = 0; roop_count < number_of_keys; ++roop_count)
1408 {
1409 spider_store_table_crd_info(table, &roop_count, &cardinality[roop_count]);
1410 if ((error_num = spider_check_sys_table_for_update_all_columns(table, table_key)))
1411 {
1412 if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
1413 {
1414 table->file->print_error(error_num, MYF(0));
1415 DBUG_RETURN(error_num);
1416 }
1417 if ((error_num = spider_write_sys_table_row(table)))
1418 DBUG_RETURN(error_num);
1419 } else {
1420 if ((error_num = spider_update_sys_table_row(table, FALSE)))
1421 {
1422 table->file->print_error(error_num, MYF(0));
1423 DBUG_RETURN(error_num);
1424 }
1425 }
1426 }
1427 DBUG_RETURN(0);
1428}
1429
1430int spider_log_tables_link_failed(
1431 TABLE *table,
1432 char *name,
1433 uint name_length,
1434 int link_idx
1435) {
1436 int error_num;
1437 DBUG_ENTER("spider_log_tables_link_failed");
1438 table->use_all_columns();
1439 spider_store_tables_name(table, name, name_length);
1440 spider_store_tables_link_idx(table, link_idx);
1441#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
1442#else
1443 if (table->field[3] == table->timestamp_field)
1444 table->timestamp_field->set_time();
1445#endif
1446 if ((error_num = spider_write_sys_table_row(table)))
1447 DBUG_RETURN(error_num);
1448 DBUG_RETURN(0);
1449}
1450
1451int spider_log_xa_failed(
1452 THD *thd,
1453 TABLE *table,
1454 XID *xid,
1455 SPIDER_CONN *conn,
1456 const char *status
1457) {
1458 int error_num;
1459 DBUG_ENTER("spider_log_xa_failed");
1460 table->use_all_columns();
1461 spider_store_xa_member_pk(table, xid, conn);
1462 spider_store_xa_member_info(table, xid, conn);
1463 if (thd)
1464 {
1465 table->field[18]->set_notnull();
1466 table->field[18]->store(thd->thread_id, TRUE);
1467 } else {
1468 table->field[18]->set_null();
1469 table->field[18]->reset();
1470 }
1471 table->field[19]->store(
1472 status,
1473 (uint) strlen(status),
1474 system_charset_info);
1475
1476#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
1477#else
1478 if (table->field[20] == table->timestamp_field)
1479 table->timestamp_field->set_time();
1480#endif
1481 if ((error_num = spider_write_sys_table_row(table)))
1482 DBUG_RETURN(error_num);
1483 DBUG_RETURN(0);
1484}
1485
1486int spider_update_xa(
1487 TABLE *table,
1488 XID *xid,
1489 const char *status
1490) {
1491 int error_num;
1492 char table_key[MAX_KEY_LENGTH];
1493 DBUG_ENTER("spider_update_xa");
1494 table->use_all_columns();
1495 spider_store_xa_pk(table, xid);
1496
1497 if ((error_num = spider_check_sys_table(table, table_key)))
1498 {
1499 if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
1500 {
1501 table->file->print_error(error_num, MYF(0));
1502 DBUG_RETURN(error_num);
1503 }
1504 my_message(ER_SPIDER_XA_NOT_EXISTS_NUM, ER_SPIDER_XA_NOT_EXISTS_STR,
1505 MYF(0));
1506 DBUG_RETURN(ER_SPIDER_XA_NOT_EXISTS_NUM);
1507 } else {
1508 store_record(table, record[1]);
1509 table->use_all_columns();
1510 spider_store_xa_status(table, status);
1511 if ((error_num = spider_update_sys_table_row(table)))
1512 DBUG_RETURN(error_num);
1513 }
1514
1515 DBUG_RETURN(0);
1516}
1517
1518int spider_update_tables_name(
1519 TABLE *table,
1520 const char *from,
1521 const char *to,
1522 int *old_link_count
1523) {
1524 int error_num, roop_count = 0;
1525 char table_key[MAX_KEY_LENGTH];
1526 DBUG_ENTER("spider_update_tables_name");
1527 table->use_all_columns();
1528 while (TRUE)
1529 {
1530 spider_store_tables_name(table, from, strlen(from));
1531 spider_store_tables_link_idx(table, roop_count);
1532 if ((error_num = spider_check_sys_table(table, table_key)))
1533 {
1534 if (
1535 roop_count &&
1536 (error_num == HA_ERR_KEY_NOT_FOUND || error_num == HA_ERR_END_OF_FILE)
1537 )
1538 break;
1539 table->file->print_error(error_num, MYF(0));
1540 DBUG_RETURN(error_num);
1541 } else {
1542 store_record(table, record[1]);
1543 table->use_all_columns();
1544 spider_store_tables_name(table, to, strlen(to));
1545 if ((error_num = spider_update_sys_table_row(table)))
1546 DBUG_RETURN(error_num);
1547 }
1548 roop_count++;
1549 }
1550
1551 *old_link_count = roop_count;
1552 DBUG_RETURN(0);
1553}
1554
1555int spider_update_tables_priority(
1556 TABLE *table,
1557 SPIDER_ALTER_TABLE *alter_table,
1558 const char *name,
1559 int *old_link_count
1560) {
1561 int error_num, roop_count;
1562 char table_key[MAX_KEY_LENGTH];
1563 DBUG_ENTER("spider_update_tables_priority");
1564 table->use_all_columns();
1565 for (roop_count = 0; roop_count < (int) alter_table->all_link_count;
1566 roop_count++)
1567 {
1568 spider_store_tables_name(table, alter_table->table_name,
1569 alter_table->table_name_length);
1570 spider_store_tables_link_idx(table, roop_count);
1571 if ((error_num = spider_check_sys_table(table, table_key)))
1572 {
1573 if (
1574 roop_count &&
1575 (error_num == HA_ERR_KEY_NOT_FOUND || error_num == HA_ERR_END_OF_FILE)
1576 ) {
1577 *old_link_count = roop_count;
1578
1579 /* insert for adding link */
1580 spider_store_tables_name(table, name, strlen(name));
1581 spider_store_tables_priority(table, alter_table->tmp_priority);
1582 do {
1583 spider_store_tables_link_idx(table, roop_count);
1584 spider_store_tables_connect_info(table, alter_table, roop_count);
1585 spider_store_tables_link_status(table,
1586 alter_table->tmp_link_statuses[roop_count] !=
1587 SPIDER_LINK_STATUS_NO_CHANGE ?
1588 alter_table->tmp_link_statuses[roop_count] :
1589 SPIDER_LINK_STATUS_OK);
1590 if ((error_num = spider_write_sys_table_row(table)))
1591 DBUG_RETURN(error_num);
1592 roop_count++;
1593 } while (roop_count < (int) alter_table->all_link_count);
1594 DBUG_RETURN(0);
1595 } else {
1596 table->file->print_error(error_num, MYF(0));
1597 DBUG_RETURN(error_num);
1598 }
1599 } else {
1600 store_record(table, record[1]);
1601 table->use_all_columns();
1602 spider_store_tables_name(table, name, strlen(name));
1603 spider_store_tables_priority(table, alter_table->tmp_priority);
1604 spider_store_tables_connect_info(table, alter_table, roop_count);
1605 spider_store_tables_link_status(table,
1606 alter_table->tmp_link_statuses[roop_count]);
1607 if ((error_num = spider_update_sys_table_row(table)))
1608 DBUG_RETURN(error_num);
1609 }
1610 }
1611 while (TRUE)
1612 {
1613 /* delete for subtracting link */
1614 spider_store_tables_link_idx(table, roop_count);
1615 if ((error_num = spider_check_sys_table(table, table_key)))
1616 {
1617 if (
1618 roop_count &&
1619 (error_num == HA_ERR_KEY_NOT_FOUND || error_num == HA_ERR_END_OF_FILE)
1620 )
1621 break;
1622 else {
1623 table->file->print_error(error_num, MYF(0));
1624 DBUG_RETURN(error_num);
1625 }
1626 if ((error_num = spider_delete_sys_table_row(table)))
1627 DBUG_RETURN(error_num);
1628 }
1629 roop_count++;
1630 }
1631
1632 *old_link_count = roop_count;
1633 DBUG_RETURN(0);
1634}
1635
1636int spider_update_tables_link_status(
1637 TABLE *table,
1638 char *name,
1639 uint name_length,
1640 int link_idx,
1641 long link_status
1642) {
1643 int error_num;
1644 char table_key[MAX_KEY_LENGTH];
1645 DBUG_ENTER("spider_update_tables_link_status");
1646 table->use_all_columns();
1647 spider_store_tables_name(table, name, name_length);
1648 spider_store_tables_link_idx(table, link_idx);
1649 if ((error_num = spider_check_sys_table(table, table_key)))
1650 {
1651 if (
1652 (error_num == HA_ERR_KEY_NOT_FOUND || error_num == HA_ERR_END_OF_FILE)
1653 )
1654 DBUG_RETURN(0);
1655 else {
1656 table->file->print_error(error_num, MYF(0));
1657 DBUG_RETURN(error_num);
1658 }
1659 } else {
1660 store_record(table, record[1]);
1661 table->use_all_columns();
1662 spider_store_tables_link_status(table, link_status);
1663 if ((error_num = spider_update_sys_table_row(table)))
1664 DBUG_RETURN(error_num);
1665 }
1666
1667 DBUG_RETURN(0);
1668}
1669
1670int spider_delete_xa(
1671 TABLE *table,
1672 XID *xid
1673) {
1674 int error_num;
1675 char table_key[MAX_KEY_LENGTH];
1676 DBUG_ENTER("spider_delete_xa");
1677 table->use_all_columns();
1678 spider_store_xa_pk(table, xid);
1679
1680 if ((error_num = spider_check_sys_table(table, table_key)))
1681 {
1682 if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
1683 {
1684 table->file->print_error(error_num, MYF(0));
1685 DBUG_RETURN(error_num);
1686 }
1687 my_message(ER_SPIDER_XA_NOT_EXISTS_NUM, ER_SPIDER_XA_NOT_EXISTS_STR,
1688 MYF(0));
1689 DBUG_RETURN(ER_SPIDER_XA_NOT_EXISTS_NUM);
1690 } else {
1691 if ((error_num = spider_delete_sys_table_row(table)))
1692 DBUG_RETURN(error_num);
1693 }
1694
1695 DBUG_RETURN(0);
1696}
1697
1698int spider_delete_xa_member(
1699 TABLE *table,
1700 XID *xid
1701) {
1702 int error_num;
1703 char table_key[MAX_KEY_LENGTH];
1704 DBUG_ENTER("spider_delete_xa_member");
1705 table->use_all_columns();
1706 spider_store_xa_pk(table, xid);
1707
1708 if ((error_num = spider_get_sys_table_by_idx(table, table_key, 0,
1709 SPIDER_SYS_XA_PK_COL_CNT)))
1710 {
1711 if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
1712 {
1713 table->file->print_error(error_num, MYF(0));
1714 DBUG_RETURN(error_num);
1715 }
1716 DBUG_RETURN(0);
1717 } else {
1718 do {
1719 if ((error_num = spider_delete_sys_table_row(table, 0, FALSE)))
1720 {
1721 spider_sys_index_end(table);
1722 table->file->print_error(error_num, MYF(0));
1723 DBUG_RETURN(error_num);
1724 }
1725 error_num = spider_sys_index_next_same(table, table_key);
1726 } while (error_num == 0);
1727 }
1728 if ((error_num = spider_sys_index_end(table)))
1729 {
1730 table->file->print_error(error_num, MYF(0));
1731 DBUG_RETURN(error_num);
1732 }
1733
1734 DBUG_RETURN(0);
1735}
1736
1737int spider_delete_tables(
1738 TABLE *table,
1739 const char *name,
1740 int *old_link_count
1741) {
1742 int error_num, roop_count = 0;
1743 char table_key[MAX_KEY_LENGTH];
1744 DBUG_ENTER("spider_delete_tables");
1745 table->use_all_columns();
1746 spider_store_tables_name(table, name, strlen(name));
1747
1748 while (TRUE)
1749 {
1750 spider_store_tables_link_idx(table, roop_count);
1751 if ((error_num = spider_check_sys_table(table, table_key)))
1752 break;
1753 else {
1754 if ((error_num = spider_delete_sys_table_row(table)))
1755 DBUG_RETURN(error_num);
1756 }
1757 roop_count++;
1758 }
1759
1760 *old_link_count = roop_count;
1761 DBUG_RETURN(0);
1762}
1763
1764int spider_delete_table_sts(
1765 TABLE *table,
1766 const char *name,
1767 uint name_length
1768) {
1769 int error_num;
1770 char table_key[MAX_KEY_LENGTH];
1771 DBUG_ENTER("spider_delete_table_sts");
1772 table->use_all_columns();
1773 spider_store_tables_name(table, name, name_length);
1774
1775 if ((error_num = spider_check_sys_table(table, table_key)))
1776 {
1777 if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
1778 {
1779 table->file->print_error(error_num, MYF(0));
1780 DBUG_RETURN(error_num);
1781 }
1782 /* no record is ok */
1783 DBUG_RETURN(0);
1784 } else {
1785 if ((error_num = spider_delete_sys_table_row(table)))
1786 DBUG_RETURN(error_num);
1787 }
1788
1789 DBUG_RETURN(0);
1790}
1791
1792int spider_delete_table_crd(
1793 TABLE *table,
1794 const char *name,
1795 uint name_length
1796) {
1797 int error_num;
1798 char table_key[MAX_KEY_LENGTH];
1799 DBUG_ENTER("spider_delete_table_crd");
1800 table->use_all_columns();
1801 spider_store_tables_name(table, name, name_length);
1802
1803 if ((error_num = spider_get_sys_table_by_idx(table, table_key, 0,
1804 SPIDER_SYS_TABLE_CRD_PK_COL_CNT - 1)))
1805 {
1806 if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
1807 {
1808 table->file->print_error(error_num, MYF(0));
1809 DBUG_RETURN(error_num);
1810 }
1811 /* no record is ok */
1812 DBUG_RETURN(0);
1813 } else {
1814 do {
1815 if ((error_num = spider_delete_sys_table_row(table)))
1816 {
1817 spider_sys_index_end(table);
1818 DBUG_RETURN(error_num);
1819 }
1820 error_num = spider_sys_index_next_same(table, table_key);
1821 } while (error_num == 0);
1822 }
1823 if ((error_num = spider_sys_index_end(table)))
1824 {
1825 table->file->print_error(error_num, MYF(0));
1826 DBUG_RETURN(error_num);
1827 }
1828
1829 DBUG_RETURN(0);
1830}
1831
1832int spider_get_sys_xid(
1833 TABLE *table,
1834 XID *xid,
1835 MEM_ROOT *mem_root
1836) {
1837 char *ptr;
1838 DBUG_ENTER("spider_get_sys_xid");
1839 ptr = get_field(mem_root, table->field[0]);
1840 if (ptr)
1841 {
1842 xid->formatID = atoi(ptr);
1843 } else
1844 xid->formatID = 0;
1845 ptr = get_field(mem_root, table->field[1]);
1846 if (ptr)
1847 {
1848 xid->gtrid_length = atoi(ptr);
1849 } else
1850 xid->gtrid_length = 0;
1851 ptr = get_field(mem_root, table->field[2]);
1852 if (ptr)
1853 {
1854 xid->bqual_length = atoi(ptr);
1855 } else
1856 xid->bqual_length = 0;
1857 ptr = get_field(mem_root, table->field[3]);
1858 if (ptr)
1859 {
1860 strmov(xid->data, ptr);
1861 }
1862 DBUG_RETURN(0);
1863}
1864
1865int spider_get_sys_server_info(
1866 TABLE *table,
1867 SPIDER_SHARE *share,
1868 int link_idx,
1869 MEM_ROOT *mem_root
1870) {
1871 char *ptr;
1872 DBUG_ENTER("spider_get_sys_server_info");
1873 if ((ptr = get_field(mem_root, table->field[4])))
1874 {
1875 share->tgt_wrappers_lengths[link_idx] = strlen(ptr);
1876 share->tgt_wrappers[link_idx] = spider_create_string(ptr,
1877 share->tgt_wrappers_lengths[link_idx]);
1878 } else {
1879 share->tgt_wrappers_lengths[link_idx] = 0;
1880 share->tgt_wrappers[link_idx] = NULL;
1881 }
1882 if ((ptr = get_field(mem_root, table->field[5])))
1883 {
1884 share->tgt_hosts_lengths[link_idx] = strlen(ptr);
1885 share->tgt_hosts[link_idx] = spider_create_string(ptr,
1886 share->tgt_hosts_lengths[link_idx]);
1887 } else {
1888 share->tgt_hosts_lengths[link_idx] = 0;
1889 share->tgt_hosts[link_idx] = NULL;
1890 }
1891 if ((ptr = get_field(mem_root, table->field[6])))
1892 {
1893 share->tgt_ports[link_idx] = atol(ptr);
1894 } else
1895 share->tgt_ports[link_idx] = MYSQL_PORT;
1896 if ((ptr = get_field(mem_root, table->field[7])))
1897 {
1898 share->tgt_sockets_lengths[link_idx] = strlen(ptr);
1899 share->tgt_sockets[link_idx] = spider_create_string(ptr,
1900 share->tgt_sockets_lengths[link_idx]);
1901 } else {
1902 share->tgt_sockets_lengths[link_idx] = 0;
1903 share->tgt_sockets[link_idx] = NULL;
1904 }
1905 if ((ptr = get_field(mem_root, table->field[8])))
1906 {
1907 share->tgt_usernames_lengths[link_idx] = strlen(ptr);
1908 share->tgt_usernames[link_idx] =
1909 spider_create_string(ptr, share->tgt_usernames_lengths[link_idx]);
1910 } else {
1911 share->tgt_usernames_lengths[link_idx] = 0;
1912 share->tgt_usernames[link_idx] = NULL;
1913 }
1914 if ((ptr = get_field(mem_root, table->field[9])))
1915 {
1916 share->tgt_passwords_lengths[link_idx] = strlen(ptr);
1917 share->tgt_passwords[link_idx] =
1918 spider_create_string(ptr, share->tgt_passwords_lengths[link_idx]);
1919 } else {
1920 share->tgt_passwords_lengths[link_idx] = 0;
1921 share->tgt_passwords[link_idx] = NULL;
1922 }
1923 if (
1924 !table->field[10]->is_null() &&
1925 (ptr = get_field(mem_root, table->field[10]))
1926 ) {
1927 share->tgt_ssl_cas_lengths[link_idx] = strlen(ptr);
1928 share->tgt_ssl_cas[link_idx] =
1929 spider_create_string(ptr, share->tgt_ssl_cas_lengths[link_idx]);
1930 } else {
1931 share->tgt_ssl_cas_lengths[link_idx] = 0;
1932 share->tgt_ssl_cas[link_idx] = NULL;
1933 }
1934 if (
1935 !table->field[11]->is_null() &&
1936 (ptr = get_field(mem_root, table->field[11]))
1937 ) {
1938 share->tgt_ssl_capaths_lengths[link_idx] = strlen(ptr);
1939 share->tgt_ssl_capaths[link_idx] =
1940 spider_create_string(ptr, share->tgt_ssl_capaths_lengths[link_idx]);
1941 } else {
1942 share->tgt_ssl_capaths_lengths[link_idx] = 0;
1943 share->tgt_ssl_capaths[link_idx] = NULL;
1944 }
1945 if (
1946 !table->field[12]->is_null() &&
1947 (ptr = get_field(mem_root, table->field[12]))
1948 ) {
1949 share->tgt_ssl_certs_lengths[link_idx] = strlen(ptr);
1950 share->tgt_ssl_certs[link_idx] =
1951 spider_create_string(ptr, share->tgt_ssl_certs_lengths[link_idx]);
1952 } else {
1953 share->tgt_ssl_certs_lengths[link_idx] = 0;
1954 share->tgt_ssl_certs[link_idx] = NULL;
1955 }
1956 if (
1957 !table->field[13]->is_null() &&
1958 (ptr = get_field(mem_root, table->field[13]))
1959 ) {
1960 share->tgt_ssl_ciphers_lengths[link_idx] = strlen(ptr);
1961 share->tgt_ssl_ciphers[link_idx] =
1962 spider_create_string(ptr, share->tgt_ssl_ciphers_lengths[link_idx]);
1963 } else {
1964 share->tgt_ssl_ciphers_lengths[link_idx] = 0;
1965 share->tgt_ssl_ciphers[link_idx] = NULL;
1966 }
1967 if (
1968 !table->field[14]->is_null() &&
1969 (ptr = get_field(mem_root, table->field[14]))
1970 ) {
1971 share->tgt_ssl_keys_lengths[link_idx] = strlen(ptr);
1972 share->tgt_ssl_keys[link_idx] =
1973 spider_create_string(ptr, share->tgt_ssl_keys_lengths[link_idx]);
1974 } else {
1975 share->tgt_ssl_keys_lengths[link_idx] = 0;
1976 share->tgt_ssl_keys[link_idx] = NULL;
1977 }
1978 if (
1979 !table->field[15]->is_null() &&
1980 (ptr = get_field(mem_root, table->field[15]))
1981 ) {
1982 share->tgt_ssl_vscs[link_idx] = atol(ptr);
1983 } else
1984 share->tgt_ssl_vscs[link_idx] = 0;
1985 if (
1986 !table->field[16]->is_null() &&
1987 (ptr = get_field(mem_root, table->field[16]))
1988 ) {
1989 share->tgt_default_files_lengths[link_idx] = strlen(ptr);
1990 share->tgt_default_files[link_idx] =
1991 spider_create_string(ptr, share->tgt_default_files_lengths[link_idx]);
1992 } else {
1993 share->tgt_default_files_lengths[link_idx] = 0;
1994 share->tgt_default_files[link_idx] = NULL;
1995 }
1996 if (
1997 !table->field[17]->is_null() &&
1998 (ptr = get_field(mem_root, table->field[17]))
1999 ) {
2000 share->tgt_default_groups_lengths[link_idx] = strlen(ptr);
2001 share->tgt_default_groups[link_idx] =
2002 spider_create_string(ptr, share->tgt_default_groups_lengths[link_idx]);
2003 } else {
2004 share->tgt_default_groups_lengths[link_idx] = 0;
2005 share->tgt_default_groups[link_idx] = NULL;
2006 }
2007 DBUG_RETURN(0);
2008}
2009
2010int spider_check_sys_xa_status(
2011 TABLE *table,
2012 const char *status1,
2013 const char *status2,
2014 const char *status3,
2015 const int check_error_num,
2016 MEM_ROOT *mem_root
2017) {
2018 char *ptr;
2019 int error_num;
2020 DBUG_ENTER("spider_check_sys_xa_status");
2021 ptr = get_field(mem_root, table->field[4]);
2022 if (ptr)
2023 {
2024 if (
2025 strcmp(ptr, status1) &&
2026 (status2 == NULL || strcmp(ptr, status2)) &&
2027 (status3 == NULL || strcmp(ptr, status3))
2028 )
2029 error_num = check_error_num;
2030 else
2031 error_num = 0;
2032 } else
2033 error_num = check_error_num;
2034 DBUG_RETURN(error_num);
2035}
2036
2037int spider_get_sys_tables(
2038 TABLE *table,
2039 char **db_name,
2040 char **table_name,
2041 MEM_ROOT *mem_root
2042) {
2043 char *ptr;
2044 DBUG_ENTER("spider_get_sys_tables");
2045 if ((ptr = get_field(mem_root, table->field[0])))
2046 {
2047 *db_name = spider_create_string(ptr, strlen(ptr));
2048 } else {
2049 *db_name = NULL;
2050 }
2051 if ((ptr = get_field(mem_root, table->field[1])))
2052 {
2053 *table_name = spider_create_string(ptr, strlen(ptr));
2054 } else {
2055 *table_name = NULL;
2056 }
2057 DBUG_RETURN(0);
2058}
2059
2060int spider_get_sys_tables_connect_info(
2061 TABLE *table,
2062 SPIDER_SHARE *share,
2063 int link_idx,
2064 MEM_ROOT *mem_root
2065) {
2066 char *ptr;
2067 int error_num = 0;
2068 DBUG_ENTER("spider_get_sys_tables_connect_info");
2069 if ((ptr = get_field(mem_root, table->field[3])))
2070 {
2071 share->priority = my_strtoll10(ptr, (char**) NULL, &error_num);
2072 } else
2073 share->priority = 1000000;
2074 if (
2075 !table->field[4]->is_null() &&
2076 (ptr = get_field(mem_root, table->field[4]))
2077 ) {
2078 share->server_names_lengths[link_idx] = strlen(ptr);
2079 share->server_names[link_idx] =
2080 spider_create_string(ptr, share->server_names_lengths[link_idx]);
2081 } else {
2082 share->server_names_lengths[link_idx] = 0;
2083 share->server_names[link_idx] = NULL;
2084 }
2085 if (
2086 !table->field[5]->is_null() &&
2087 (ptr = get_field(mem_root, table->field[5]))
2088 ) {
2089 share->tgt_wrappers_lengths[link_idx] = strlen(ptr);
2090 share->tgt_wrappers[link_idx] =
2091 spider_create_string(ptr, share->tgt_wrappers_lengths[link_idx]);
2092 } else {
2093 share->tgt_wrappers_lengths[link_idx] = 0;
2094 share->tgt_wrappers[link_idx] = NULL;
2095 }
2096 if (
2097 !table->field[6]->is_null() &&
2098 (ptr = get_field(mem_root, table->field[6]))
2099 ) {
2100 share->tgt_hosts_lengths[link_idx] = strlen(ptr);
2101 share->tgt_hosts[link_idx] =
2102 spider_create_string(ptr, share->tgt_hosts_lengths[link_idx]);
2103 } else {
2104 share->tgt_hosts_lengths[link_idx] = 0;
2105 share->tgt_hosts[link_idx] = NULL;
2106 }
2107 if (
2108 !table->field[7]->is_null() &&
2109 (ptr = get_field(mem_root, table->field[7]))
2110 ) {
2111 share->tgt_ports[link_idx] = atol(ptr);
2112 } else {
2113 share->tgt_ports[link_idx] = -1;
2114 }
2115 if (
2116 !table->field[8]->is_null() &&
2117 (ptr = get_field(mem_root, table->field[8]))
2118 ) {
2119 share->tgt_sockets_lengths[link_idx] = strlen(ptr);
2120 share->tgt_sockets[link_idx] =
2121 spider_create_string(ptr, share->tgt_sockets_lengths[link_idx]);
2122 } else {
2123 share->tgt_sockets_lengths[link_idx] = 0;
2124 share->tgt_sockets[link_idx] = NULL;
2125 }
2126 if (
2127 !table->field[9]->is_null() &&
2128 (ptr = get_field(mem_root, table->field[9]))
2129 ) {
2130 share->tgt_usernames_lengths[link_idx] = strlen(ptr);
2131 share->tgt_usernames[link_idx] =
2132 spider_create_string(ptr, share->tgt_usernames_lengths[link_idx]);
2133 } else {
2134 share->tgt_usernames_lengths[link_idx] = 0;
2135 share->tgt_usernames[link_idx] = NULL;
2136 }
2137 if (
2138 !table->field[10]->is_null() &&
2139 (ptr = get_field(mem_root, table->field[10]))
2140 ) {
2141 share->tgt_passwords_lengths[link_idx] = strlen(ptr);
2142 share->tgt_passwords[link_idx] =
2143 spider_create_string(ptr, share->tgt_passwords_lengths[link_idx]);
2144 } else {
2145 share->tgt_passwords_lengths[link_idx] = 0;
2146 share->tgt_passwords[link_idx] = NULL;
2147 }
2148 if (
2149 !table->field[11]->is_null() &&
2150 (ptr = get_field(mem_root, table->field[11]))
2151 ) {
2152 share->tgt_ssl_cas_lengths[link_idx] = strlen(ptr);
2153 share->tgt_ssl_cas[link_idx] =
2154 spider_create_string(ptr, share->tgt_ssl_cas_lengths[link_idx]);
2155 } else {
2156 share->tgt_ssl_cas_lengths[link_idx] = 0;
2157 share->tgt_ssl_cas[link_idx] = NULL;
2158 }
2159 if (
2160 !table->field[12]->is_null() &&
2161 (ptr = get_field(mem_root, table->field[12]))
2162 ) {
2163 share->tgt_ssl_capaths_lengths[link_idx] = strlen(ptr);
2164 share->tgt_ssl_capaths[link_idx] =
2165 spider_create_string(ptr, share->tgt_ssl_capaths_lengths[link_idx]);
2166 } else {
2167 share->tgt_ssl_capaths_lengths[link_idx] = 0;
2168 share->tgt_ssl_capaths[link_idx] = NULL;
2169 }
2170 if (
2171 !table->field[13]->is_null() &&
2172 (ptr = get_field(mem_root, table->field[13]))
2173 ) {
2174 share->tgt_ssl_certs_lengths[link_idx] = strlen(ptr);
2175 share->tgt_ssl_certs[link_idx] =
2176 spider_create_string(ptr, share->tgt_ssl_certs_lengths[link_idx]);
2177 } else {
2178 share->tgt_ssl_certs_lengths[link_idx] = 0;
2179 share->tgt_ssl_certs[link_idx] = NULL;
2180 }
2181 if (
2182 !table->field[14]->is_null() &&
2183 (ptr = get_field(mem_root, table->field[14]))
2184 ) {
2185 share->tgt_ssl_ciphers_lengths[link_idx] = strlen(ptr);
2186 share->tgt_ssl_ciphers[link_idx] =
2187 spider_create_string(ptr, share->tgt_ssl_ciphers_lengths[link_idx]);
2188 } else {
2189 share->tgt_ssl_ciphers_lengths[link_idx] = 0;
2190 share->tgt_ssl_ciphers[link_idx] = NULL;
2191 }
2192 if (
2193 !table->field[15]->is_null() &&
2194 (ptr = get_field(mem_root, table->field[15]))
2195 ) {
2196 share->tgt_ssl_keys_lengths[link_idx] = strlen(ptr);
2197 share->tgt_ssl_keys[link_idx] =
2198 spider_create_string(ptr, share->tgt_ssl_keys_lengths[link_idx]);
2199 } else {
2200 share->tgt_ssl_keys_lengths[link_idx] = 0;
2201 share->tgt_ssl_keys[link_idx] = NULL;
2202 }
2203 if (
2204 !table->field[16]->is_null() &&
2205 (ptr = get_field(mem_root, table->field[16]))
2206 ) {
2207 share->tgt_ssl_vscs[link_idx] = atol(ptr);
2208 } else
2209 share->tgt_ssl_vscs[link_idx] = -1;
2210 if (
2211 !table->field[17]->is_null() &&
2212 (ptr = get_field(mem_root, table->field[17]))
2213 ) {
2214 share->monitoring_binlog_pos_at_failing[link_idx] = atol(ptr);
2215 } else
2216 share->monitoring_binlog_pos_at_failing[link_idx] = 0;
2217 if (
2218 !table->field[18]->is_null() &&
2219 (ptr = get_field(mem_root, table->field[18]))
2220 ) {
2221 share->tgt_default_files_lengths[link_idx] = strlen(ptr);
2222 share->tgt_default_files[link_idx] =
2223 spider_create_string(ptr, share->tgt_default_files_lengths[link_idx]);
2224 } else {
2225 share->tgt_default_files_lengths[link_idx] = 0;
2226 share->tgt_default_files[link_idx] = NULL;
2227 }
2228 if (
2229 !table->field[19]->is_null() &&
2230 (ptr = get_field(mem_root, table->field[19]))
2231 ) {
2232 share->tgt_default_groups_lengths[link_idx] = strlen(ptr);
2233 share->tgt_default_groups[link_idx] =
2234 spider_create_string(ptr, share->tgt_default_groups_lengths[link_idx]);
2235 } else {
2236 share->tgt_default_groups_lengths[link_idx] = 0;
2237 share->tgt_default_groups[link_idx] = NULL;
2238 }
2239 if (
2240 !table->field[20]->is_null() &&
2241 (ptr = get_field(mem_root, table->field[20]))
2242 ) {
2243 share->tgt_dbs_lengths[link_idx] = strlen(ptr);
2244 share->tgt_dbs[link_idx] =
2245 spider_create_string(ptr, share->tgt_dbs_lengths[link_idx]);
2246 } else {
2247 share->tgt_dbs_lengths[link_idx] = 0;
2248 share->tgt_dbs[link_idx] = NULL;
2249 }
2250 if (
2251 !table->field[21]->is_null() &&
2252 (ptr = get_field(mem_root, table->field[21]))
2253 ) {
2254 share->tgt_table_names_lengths[link_idx] = strlen(ptr);
2255 share->tgt_table_names[link_idx] =
2256 spider_create_string(ptr, share->tgt_table_names_lengths[link_idx]);
2257 } else {
2258 share->tgt_table_names_lengths[link_idx] = 0;
2259 share->tgt_table_names[link_idx] = NULL;
2260 }
2261 if (
2262 !table->field[24]->is_null() &&
2263 (ptr = get_field(mem_root, table->field[24]))
2264 ) {
2265 share->static_link_ids_lengths[link_idx] = strlen(ptr);
2266 share->static_link_ids[link_idx] =
2267 spider_create_string(ptr, share->static_link_ids_lengths[link_idx]);
2268 } else {
2269 share->static_link_ids_lengths[link_idx] = 0;
2270 share->static_link_ids[link_idx] = NULL;
2271 }
2272 DBUG_RETURN(error_num);
2273}
2274
2275int spider_get_sys_tables_monitoring_binlog_pos_at_failing(
2276 TABLE *table,
2277 long *monitoring_binlog_pos_at_failing,
2278 MEM_ROOT *mem_root
2279) {
2280 char *ptr;
2281 int error_num = 0;
2282 DBUG_ENTER("spider_get_sys_tables_monitoring_binlog_pos_at_failing");
2283 if ((ptr = get_field(mem_root, table->field[17])))
2284 *monitoring_binlog_pos_at_failing = (long) my_strtoll10(ptr, (char**) NULL,
2285 &error_num);
2286 else
2287 *monitoring_binlog_pos_at_failing = 1;
2288 DBUG_PRINT("info",("spider monitoring_binlog_pos_at_failing=%ld",
2289 *monitoring_binlog_pos_at_failing));
2290 DBUG_RETURN(error_num);
2291}
2292
2293int spider_get_sys_tables_link_status(
2294 TABLE *table,
2295 SPIDER_SHARE *share,
2296 int link_idx,
2297 MEM_ROOT *mem_root
2298) {
2299 char *ptr;
2300 int error_num = 0;
2301 DBUG_ENTER("spider_get_sys_tables_link_status");
2302 if ((ptr = get_field(mem_root, table->field[22])))
2303 {
2304 share->link_statuses[link_idx] =
2305 (long) my_strtoll10(ptr, (char**) NULL, &error_num);
2306 } else
2307 share->link_statuses[link_idx] = 1;
2308 DBUG_PRINT("info",("spider link_statuses[%d]=%ld",
2309 link_idx, share->link_statuses[link_idx]));
2310 DBUG_RETURN(error_num);
2311}
2312
2313int spider_get_sys_tables_link_status(
2314 TABLE *table,
2315 long *link_status,
2316 MEM_ROOT *mem_root
2317) {
2318 char *ptr;
2319 int error_num = 0;
2320 DBUG_ENTER("spider_get_sys_tables_link_status");
2321 if ((ptr = get_field(mem_root, table->field[22])))
2322 *link_status = (long) my_strtoll10(ptr, (char**) NULL, &error_num);
2323 else
2324 *link_status = 1;
2325 DBUG_PRINT("info",("spider link_statuses=%ld", *link_status));
2326 DBUG_RETURN(error_num);
2327}
2328
2329int spider_get_sys_tables_link_idx(
2330 TABLE *table,
2331 int *link_idx,
2332 MEM_ROOT *mem_root
2333) {
2334 char *ptr;
2335 int error_num = 0;
2336 DBUG_ENTER("spider_get_sys_tables_link_idx");
2337 if ((ptr = get_field(mem_root, table->field[2])))
2338 *link_idx = (int) my_strtoll10(ptr, (char**) NULL, &error_num);
2339 else
2340 *link_idx = 1;
2341 DBUG_PRINT("info",("spider link_idx=%d", *link_idx));
2342 DBUG_RETURN(error_num);
2343}
2344
2345int spider_get_sys_tables_static_link_id(
2346 TABLE *table,
2347 char **static_link_id,
2348 uint *static_link_id_length,
2349 MEM_ROOT *mem_root
2350) {
2351 int error_num = 0;
2352 DBUG_ENTER("spider_get_sys_tables_static_link_id");
2353 if (
2354 !table->field[24]->is_null() &&
2355 (*static_link_id = get_field(mem_root, table->field[24]))
2356 ) {
2357 *static_link_id_length = strlen(*static_link_id);
2358 } else {
2359 *static_link_id_length = 0;
2360 }
2361 DBUG_PRINT("info",("spider static_link_id=%s", *static_link_id ? *static_link_id : "NULL"));
2362 DBUG_RETURN(error_num);
2363}
2364
2365void spider_get_sys_table_sts_info(
2366 TABLE *table,
2367 ulonglong *data_file_length,
2368 ulonglong *max_data_file_length,
2369 ulonglong *index_file_length,
2370 ha_rows *records,
2371 ulong *mean_rec_length,
2372 time_t *check_time,
2373 time_t *create_time,
2374 time_t *update_time
2375) {
2376 MYSQL_TIME mysql_time;
2377#ifdef MARIADB_BASE_VERSION
2378 uint not_used_uint;
2379#else
2380 my_bool not_used_my_bool;
2381#endif
2382 long not_used_long;
2383 DBUG_ENTER("spider_get_sys_table_sts_info");
2384 *data_file_length = (ulonglong) table->field[2]->val_int();
2385 *max_data_file_length = (ulonglong) table->field[3]->val_int();
2386 *index_file_length = (ulonglong) table->field[4]->val_int();
2387 *records = (ha_rows) table->field[5]->val_int();
2388 *mean_rec_length = (ulong) table->field[6]->val_int();
2389 table->field[7]->get_date(&mysql_time, 0);
2390#ifdef MARIADB_BASE_VERSION
2391 *check_time = (time_t) my_system_gmt_sec(&mysql_time,
2392 &not_used_long, &not_used_uint);
2393#else
2394 *check_time = (time_t) my_system_gmt_sec(&mysql_time,
2395 &not_used_long, &not_used_my_bool);
2396#endif
2397 table->field[8]->get_date(&mysql_time, 0);
2398#ifdef MARIADB_BASE_VERSION
2399 *create_time = (time_t) my_system_gmt_sec(&mysql_time,
2400 &not_used_long, &not_used_uint);
2401#else
2402 *create_time = (time_t) my_system_gmt_sec(&mysql_time,
2403 &not_used_long, &not_used_my_bool);
2404#endif
2405 table->field[9]->get_date(&mysql_time, 0);
2406#ifdef MARIADB_BASE_VERSION
2407 *update_time = (time_t) my_system_gmt_sec(&mysql_time,
2408 &not_used_long, &not_used_uint);
2409#else
2410 *update_time = (time_t) my_system_gmt_sec(&mysql_time,
2411 &not_used_long, &not_used_my_bool);
2412#endif
2413 DBUG_VOID_RETURN;
2414}
2415
2416void spider_get_sys_table_crd_info(
2417 TABLE *table,
2418 longlong *cardinality,
2419 uint number_of_keys
2420) {
2421 uint seq;
2422 DBUG_ENTER("spider_get_sys_table_crd_info");
2423 seq = (uint) table->field[2]->val_int();
2424 if (seq < number_of_keys)
2425 {
2426 cardinality[seq] = (longlong) table->field[3]->val_int();
2427 }
2428 DBUG_VOID_RETURN;
2429}
2430
2431int spider_sys_update_tables_link_status(
2432 THD *thd,
2433 char *name,
2434 uint name_length,
2435 int link_idx,
2436 long link_status,
2437 bool need_lock
2438) {
2439 int error_num;
2440 TABLE *table_tables = NULL;
2441#if MYSQL_VERSION_ID < 50500
2442 Open_tables_state open_tables_backup;
2443#else
2444 Open_tables_backup open_tables_backup;
2445#endif
2446 DBUG_ENTER("spider_sys_update_tables_link_status");
2447 if (
2448 !(table_tables = spider_open_sys_table(
2449 thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
2450 SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, need_lock,
2451 &error_num))
2452 ) {
2453 goto error;
2454 }
2455 if ((error_num = spider_update_tables_link_status(table_tables,
2456 name, name_length, link_idx, link_status)))
2457 goto error;
2458 spider_close_sys_table(thd, table_tables,
2459 &open_tables_backup, need_lock);
2460 table_tables = NULL;
2461 DBUG_RETURN(0);
2462
2463error:
2464 if (table_tables)
2465 spider_close_sys_table(thd, table_tables,
2466 &open_tables_backup, need_lock);
2467 DBUG_RETURN(error_num);
2468}
2469
2470int spider_sys_log_tables_link_failed(
2471 THD *thd,
2472 char *name,
2473 uint name_length,
2474 int link_idx,
2475 bool need_lock
2476) {
2477 int error_num;
2478 TABLE *table_tables = NULL;
2479#if MYSQL_VERSION_ID < 50500
2480 Open_tables_state open_tables_backup;
2481#else
2482 Open_tables_backup open_tables_backup;
2483#endif
2484 DBUG_ENTER("spider_sys_log_tables_link_failed");
2485 if (
2486 !(table_tables = spider_open_sys_table(
2487 thd, SPIDER_SYS_LINK_FAILED_TABLE_NAME_STR,
2488 SPIDER_SYS_LINK_FAILED_TABLE_NAME_LEN, TRUE, &open_tables_backup,
2489 need_lock, &error_num))
2490 ) {
2491 goto error;
2492 }
2493 empty_record(table_tables);
2494 if ((error_num = spider_log_tables_link_failed(table_tables,
2495 name, name_length, link_idx)))
2496 goto error;
2497 spider_close_sys_table(thd, table_tables,
2498 &open_tables_backup, need_lock);
2499 table_tables = NULL;
2500 DBUG_RETURN(0);
2501
2502error:
2503 if (table_tables)
2504 spider_close_sys_table(thd, table_tables,
2505 &open_tables_backup, need_lock);
2506 DBUG_RETURN(error_num);
2507}
2508
2509int spider_sys_log_xa_failed(
2510 THD *thd,
2511 XID *xid,
2512 SPIDER_CONN *conn,
2513 const char *status,
2514 bool need_lock
2515) {
2516 int error_num;
2517 TABLE *table_tables = NULL;
2518#if MYSQL_VERSION_ID < 50500
2519 Open_tables_state open_tables_backup;
2520#else
2521 Open_tables_backup open_tables_backup;
2522#endif
2523 DBUG_ENTER("spider_sys_log_xa_failed");
2524 if (
2525 !(table_tables = spider_open_sys_table(
2526 thd, SPIDER_SYS_XA_FAILED_TABLE_NAME_STR,
2527 SPIDER_SYS_XA_FAILED_TABLE_NAME_LEN, TRUE, &open_tables_backup,
2528 need_lock, &error_num))
2529 ) {
2530 goto error;
2531 }
2532 empty_record(table_tables);
2533 if ((error_num = spider_log_xa_failed(thd, table_tables, xid, conn, status)))
2534 goto error;
2535 spider_close_sys_table(thd, table_tables, &open_tables_backup, need_lock);
2536 table_tables = NULL;
2537 DBUG_RETURN(0);
2538
2539error:
2540 if (table_tables)
2541 spider_close_sys_table(thd, table_tables, &open_tables_backup, need_lock);
2542 DBUG_RETURN(error_num);
2543}
2544
2545int spider_get_sys_link_mon_key(
2546 TABLE *table,
2547 SPIDER_MON_KEY *mon_key,
2548 MEM_ROOT *mem_root,
2549 int *same
2550) {
2551 char *db_name, *table_name, *link_id;
2552 uint db_name_length, table_name_length, link_id_length;
2553 DBUG_ENTER("spider_get_sys_link_mon_key");
2554 if (
2555 table->field[0]->is_null() ||
2556 table->field[1]->is_null() ||
2557 table->field[2]->is_null()
2558 ) {
2559 my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
2560 ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
2561 SPIDER_SYS_LINK_MON_TABLE_NAME_STR);
2562 DBUG_RETURN(ER_SPIDER_SYS_TABLE_VERSION_NUM);
2563 }
2564
2565 if (
2566 !(db_name = get_field(mem_root, table->field[0])) ||
2567 !(table_name = get_field(mem_root, table->field[1])) ||
2568 !(link_id = get_field(mem_root, table->field[2]))
2569 )
2570 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
2571
2572 db_name_length = strlen(db_name);
2573 table_name_length = strlen(table_name);
2574 link_id_length = strlen(link_id);
2575
2576 if (
2577 db_name_length > SPIDER_SYS_LINK_MON_TABLE_DB_NAME_SIZE ||
2578 table_name_length > SPIDER_SYS_LINK_MON_TABLE_TABLE_NAME_SIZE ||
2579 link_id_length > SPIDER_SYS_LINK_MON_TABLE_LINK_ID_SIZE
2580 ) {
2581 my_printf_error(ER_SPIDER_SYS_TABLE_VERSION_NUM,
2582 ER_SPIDER_SYS_TABLE_VERSION_STR, MYF(0),
2583 SPIDER_SYS_LINK_MON_TABLE_NAME_STR);
2584 DBUG_RETURN(ER_SPIDER_SYS_TABLE_VERSION_NUM);
2585 }
2586
2587 if (
2588 db_name_length == mon_key->db_name_length &&
2589 table_name_length == mon_key->table_name_length &&
2590 link_id_length == mon_key->link_id_length &&
2591 !memcmp(db_name, mon_key->db_name, db_name_length) &&
2592 !memcmp(table_name, mon_key->table_name, table_name_length) &&
2593 !memcmp(link_id, mon_key->link_id, link_id_length)
2594 ) {
2595 /* same key */
2596 *same = 1;
2597 DBUG_RETURN(0);
2598 }
2599
2600 *same = 0;
2601 mon_key->db_name_length = db_name_length;
2602 memcpy(mon_key->db_name, db_name, db_name_length + 1);
2603 mon_key->table_name_length = table_name_length;
2604 memcpy(mon_key->table_name, table_name, table_name_length + 1);
2605 mon_key->link_id_length = link_id_length;
2606 memcpy(mon_key->link_id, link_id, link_id_length + 1);
2607 DBUG_RETURN(0);
2608}
2609
2610int spider_get_sys_link_mon_server_id(
2611 TABLE *table,
2612 uint32 *server_id,
2613 MEM_ROOT *mem_root
2614) {
2615 char *ptr;
2616 int error_num = 0;
2617 DBUG_ENTER("spider_get_sys_link_mon_server_id");
2618 if ((ptr = get_field(mem_root, table->field[3])))
2619 *server_id = (uint32) my_strtoll10(ptr, (char**) NULL, &error_num);
2620 else
2621 *server_id = ~(uint32) 0;
2622 DBUG_RETURN(error_num);
2623}
2624
2625int spider_get_sys_link_mon_connect_info(
2626 TABLE *table,
2627 SPIDER_SHARE *share,
2628 int link_idx,
2629 MEM_ROOT *mem_root
2630) {
2631 char *ptr;
2632 int error_num = 0;
2633 DBUG_ENTER("spider_get_sys_link_mon_connect_info");
2634 if (
2635 !table->field[4]->is_null() &&
2636 (ptr = get_field(mem_root, table->field[4]))
2637 ) {
2638 share->server_names_lengths[link_idx] = strlen(ptr);
2639 share->server_names[link_idx] =
2640 spider_create_string(ptr, share->server_names_lengths[link_idx]);
2641 } else {
2642 share->server_names_lengths[link_idx] = 0;
2643 share->server_names[link_idx] = NULL;
2644 }
2645 if (
2646 !table->field[5]->is_null() &&
2647 (ptr = get_field(mem_root, table->field[5]))
2648 ) {
2649 share->tgt_wrappers_lengths[link_idx] = strlen(ptr);
2650 share->tgt_wrappers[link_idx] =
2651 spider_create_string(ptr, share->tgt_wrappers_lengths[link_idx]);
2652 } else {
2653 share->tgt_wrappers_lengths[link_idx] = 0;
2654 share->tgt_wrappers[link_idx] = NULL;
2655 }
2656 if (
2657 !table->field[6]->is_null() &&
2658 (ptr = get_field(mem_root, table->field[6]))
2659 ) {
2660 share->tgt_hosts_lengths[link_idx] = strlen(ptr);
2661 share->tgt_hosts[link_idx] =
2662 spider_create_string(ptr, share->tgt_hosts_lengths[link_idx]);
2663 } else {
2664 share->tgt_hosts_lengths[link_idx] = 0;
2665 share->tgt_hosts[link_idx] = NULL;
2666 }
2667 if (
2668 !table->field[7]->is_null() &&
2669 (ptr = get_field(mem_root, table->field[7]))
2670 ) {
2671 share->tgt_ports[link_idx] = atol(ptr);
2672 } else {
2673 share->tgt_ports[link_idx] = -1;
2674 }
2675 if (
2676 !table->field[8]->is_null() &&
2677 (ptr = get_field(mem_root, table->field[8]))
2678 ) {
2679 share->tgt_sockets_lengths[link_idx] = strlen(ptr);
2680 share->tgt_sockets[link_idx] =
2681 spider_create_string(ptr, share->tgt_sockets_lengths[link_idx]);
2682 } else {
2683 share->tgt_sockets_lengths[link_idx] = 0;
2684 share->tgt_sockets[link_idx] = NULL;
2685 }
2686 if (
2687 !table->field[9]->is_null() &&
2688 (ptr = get_field(mem_root, table->field[9]))
2689 ) {
2690 share->tgt_usernames_lengths[link_idx] = strlen(ptr);
2691 share->tgt_usernames[link_idx] =
2692 spider_create_string(ptr, share->tgt_usernames_lengths[link_idx]);
2693 } else {
2694 share->tgt_usernames_lengths[link_idx] = 0;
2695 share->tgt_usernames[link_idx] = NULL;
2696 }
2697 if (
2698 !table->field[10]->is_null() &&
2699 (ptr = get_field(mem_root, table->field[10]))
2700 ) {
2701 share->tgt_passwords_lengths[link_idx] = strlen(ptr);
2702 share->tgt_passwords[link_idx] =
2703 spider_create_string(ptr, share->tgt_passwords_lengths[link_idx]);
2704 } else {
2705 share->tgt_passwords_lengths[link_idx] = 0;
2706 share->tgt_passwords[link_idx] = NULL;
2707 }
2708 if (
2709 !table->field[11]->is_null() &&
2710 (ptr = get_field(mem_root, table->field[11]))
2711 ) {
2712 share->tgt_ssl_cas_lengths[link_idx] = strlen(ptr);
2713 share->tgt_ssl_cas[link_idx] =
2714 spider_create_string(ptr, share->tgt_ssl_cas_lengths[link_idx]);
2715 } else {
2716 share->tgt_ssl_cas_lengths[link_idx] = 0;
2717 share->tgt_ssl_cas[link_idx] = NULL;
2718 }
2719 if (
2720 !table->field[12]->is_null() &&
2721 (ptr = get_field(mem_root, table->field[12]))
2722 ) {
2723 share->tgt_ssl_capaths_lengths[link_idx] = strlen(ptr);
2724 share->tgt_ssl_capaths[link_idx] =
2725 spider_create_string(ptr, share->tgt_ssl_capaths_lengths[link_idx]);
2726 } else {
2727 share->tgt_ssl_capaths_lengths[link_idx] = 0;
2728 share->tgt_ssl_capaths[link_idx] = NULL;
2729 }
2730 if (
2731 !table->field[13]->is_null() &&
2732 (ptr = get_field(mem_root, table->field[13]))
2733 ) {
2734 share->tgt_ssl_certs_lengths[link_idx] = strlen(ptr);
2735 share->tgt_ssl_certs[link_idx] =
2736 spider_create_string(ptr, share->tgt_ssl_certs_lengths[link_idx]);
2737 } else {
2738 share->tgt_ssl_certs_lengths[link_idx] = 0;
2739 share->tgt_ssl_certs[link_idx] = NULL;
2740 }
2741 if (
2742 !table->field[14]->is_null() &&
2743 (ptr = get_field(mem_root, table->field[14]))
2744 ) {
2745 share->tgt_ssl_ciphers_lengths[link_idx] = strlen(ptr);
2746 share->tgt_ssl_ciphers[link_idx] =
2747 spider_create_string(ptr, share->tgt_ssl_ciphers_lengths[link_idx]);
2748 } else {
2749 share->tgt_ssl_ciphers_lengths[link_idx] = 0;
2750 share->tgt_ssl_ciphers[link_idx] = NULL;
2751 }
2752 if (
2753 !table->field[15]->is_null() &&
2754 (ptr = get_field(mem_root, table->field[15]))
2755 ) {
2756 share->tgt_ssl_keys_lengths[link_idx] = strlen(ptr);
2757 share->tgt_ssl_keys[link_idx] =
2758 spider_create_string(ptr, share->tgt_ssl_keys_lengths[link_idx]);
2759 } else {
2760 share->tgt_ssl_keys_lengths[link_idx] = 0;
2761 share->tgt_ssl_keys[link_idx] = NULL;
2762 }
2763 if (
2764 !table->field[16]->is_null() &&
2765 (ptr = get_field(mem_root, table->field[16]))
2766 ) {
2767 share->tgt_ssl_vscs[link_idx] = atol(ptr);
2768 } else
2769 share->tgt_ssl_vscs[link_idx] = -1;
2770 if (
2771 !table->field[17]->is_null() &&
2772 (ptr = get_field(mem_root, table->field[17]))
2773 ) {
2774 share->tgt_default_files_lengths[link_idx] = strlen(ptr);
2775 share->tgt_default_files[link_idx] =
2776 spider_create_string(ptr, share->tgt_default_files_lengths[link_idx]);
2777 } else {
2778 share->tgt_default_files_lengths[link_idx] = 0;
2779 share->tgt_default_files[link_idx] = NULL;
2780 }
2781 if (
2782 !table->field[18]->is_null() &&
2783 (ptr = get_field(mem_root, table->field[18]))
2784 ) {
2785 share->tgt_default_groups_lengths[link_idx] = strlen(ptr);
2786 share->tgt_default_groups[link_idx] =
2787 spider_create_string(ptr, share->tgt_default_groups_lengths[link_idx]);
2788 } else {
2789 share->tgt_default_groups_lengths[link_idx] = 0;
2790 share->tgt_default_groups[link_idx] = NULL;
2791 }
2792 DBUG_RETURN(error_num);
2793}
2794
2795int spider_get_link_statuses(
2796 TABLE *table,
2797 SPIDER_SHARE *share,
2798 MEM_ROOT *mem_root
2799) {
2800 int error_num, roop_count;
2801 char table_key[MAX_KEY_LENGTH];
2802 DBUG_ENTER("spider_get_link_statuses");
2803 table->use_all_columns();
2804 spider_store_tables_name(table, share->table_name,
2805 share->table_name_length);
2806 for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
2807 {
2808 spider_store_tables_link_idx(table, roop_count);
2809 if ((error_num = spider_check_sys_table(table, table_key)))
2810 {
2811 if (
2812 (error_num == HA_ERR_KEY_NOT_FOUND || error_num == HA_ERR_END_OF_FILE)
2813 ) {
2814/*
2815 table->file->print_error(error_num, MYF(0));
2816*/
2817 DBUG_RETURN(error_num);
2818 }
2819 } else if ((error_num =
2820 spider_get_sys_tables_link_status(table, share, roop_count, mem_root)))
2821 {
2822 table->file->print_error(error_num, MYF(0));
2823 DBUG_RETURN(error_num);
2824 }
2825 }
2826 DBUG_RETURN(0);
2827}
2828
2829int spider_sys_insert_or_update_table_sts(
2830 THD *thd,
2831 const char *name,
2832 uint name_length,
2833 ulonglong *data_file_length,
2834 ulonglong *max_data_file_length,
2835 ulonglong *index_file_length,
2836 ha_rows *records,
2837 ulong *mean_rec_length,
2838 time_t *check_time,
2839 time_t *create_time,
2840 time_t *update_time,
2841 bool need_lock
2842) {
2843 int error_num;
2844 TABLE *table_sts = NULL;
2845#if MYSQL_VERSION_ID < 50500
2846 Open_tables_state open_tables_backup;
2847#else
2848 Open_tables_backup open_tables_backup;
2849#endif
2850 DBUG_ENTER("spider_sys_insert_or_update_table_sts");
2851 if (
2852 !(table_sts = spider_open_sys_table(
2853 thd, SPIDER_SYS_TABLE_STS_TABLE_NAME_STR,
2854 SPIDER_SYS_TABLE_STS_TABLE_NAME_LEN, TRUE,
2855 &open_tables_backup, need_lock, &error_num))
2856 ) {
2857 goto error;
2858 }
2859 if ((error_num = spider_insert_or_update_table_sts(
2860 table_sts,
2861 name,
2862 name_length,
2863 data_file_length,
2864 max_data_file_length,
2865 index_file_length,
2866 records,
2867 mean_rec_length,
2868 check_time,
2869 create_time,
2870 update_time
2871 )))
2872 goto error;
2873 spider_close_sys_table(thd, table_sts, &open_tables_backup, need_lock);
2874 table_sts = NULL;
2875 DBUG_RETURN(0);
2876
2877error:
2878 if (table_sts)
2879 spider_close_sys_table(thd, table_sts, &open_tables_backup, need_lock);
2880 DBUG_RETURN(error_num);
2881}
2882
2883int spider_sys_insert_or_update_table_crd(
2884 THD *thd,
2885 const char *name,
2886 uint name_length,
2887 longlong *cardinality,
2888 uint number_of_keys,
2889 bool need_lock
2890) {
2891 int error_num;
2892 TABLE *table_crd = NULL;
2893#if MYSQL_VERSION_ID < 50500
2894 Open_tables_state open_tables_backup;
2895#else
2896 Open_tables_backup open_tables_backup;
2897#endif
2898 DBUG_ENTER("spider_sys_insert_or_update_table_crd");
2899 if (
2900 !(table_crd = spider_open_sys_table(
2901 thd, SPIDER_SYS_TABLE_CRD_TABLE_NAME_STR,
2902 SPIDER_SYS_TABLE_CRD_TABLE_NAME_LEN, TRUE,
2903 &open_tables_backup, need_lock, &error_num))
2904 ) {
2905 goto error;
2906 }
2907 if ((error_num = spider_insert_or_update_table_crd(
2908 table_crd,
2909 name,
2910 name_length,
2911 cardinality,
2912 number_of_keys
2913 )))
2914 goto error;
2915 spider_close_sys_table(thd, table_crd, &open_tables_backup, need_lock);
2916 table_crd = NULL;
2917 DBUG_RETURN(0);
2918
2919error:
2920 if (table_crd)
2921 spider_close_sys_table(thd, table_crd, &open_tables_backup, need_lock);
2922 DBUG_RETURN(error_num);
2923}
2924
2925int spider_sys_delete_table_sts(
2926 THD *thd,
2927 const char *name,
2928 uint name_length,
2929 bool need_lock
2930) {
2931 int error_num;
2932 TABLE *table_sts = NULL;
2933#if MYSQL_VERSION_ID < 50500
2934 Open_tables_state open_tables_backup;
2935#else
2936 Open_tables_backup open_tables_backup;
2937#endif
2938 DBUG_ENTER("spider_sys_delete_table_sts");
2939 if (
2940 !(table_sts = spider_open_sys_table(
2941 thd, SPIDER_SYS_TABLE_STS_TABLE_NAME_STR,
2942 SPIDER_SYS_TABLE_STS_TABLE_NAME_LEN, TRUE,
2943 &open_tables_backup, need_lock, &error_num))
2944 ) {
2945 goto error;
2946 }
2947 if ((error_num = spider_delete_table_sts(
2948 table_sts,
2949 name,
2950 name_length
2951 )))
2952 goto error;
2953 spider_close_sys_table(thd, table_sts, &open_tables_backup, need_lock);
2954 table_sts = NULL;
2955 DBUG_RETURN(0);
2956
2957error:
2958 if (table_sts)
2959 spider_close_sys_table(thd, table_sts, &open_tables_backup, need_lock);
2960 DBUG_RETURN(error_num);
2961}
2962
2963int spider_sys_delete_table_crd(
2964 THD *thd,
2965 const char *name,
2966 uint name_length,
2967 bool need_lock
2968) {
2969 int error_num;
2970 TABLE *table_crd = NULL;
2971#if MYSQL_VERSION_ID < 50500
2972 Open_tables_state open_tables_backup;
2973#else
2974 Open_tables_backup open_tables_backup;
2975#endif
2976 DBUG_ENTER("spider_sys_delete_table_crd");
2977 if (
2978 !(table_crd = spider_open_sys_table(
2979 thd, SPIDER_SYS_TABLE_CRD_TABLE_NAME_STR,
2980 SPIDER_SYS_TABLE_CRD_TABLE_NAME_LEN, TRUE,
2981 &open_tables_backup, need_lock, &error_num))
2982 ) {
2983 goto error;
2984 }
2985 if ((error_num = spider_delete_table_crd(
2986 table_crd,
2987 name,
2988 name_length
2989 )))
2990 goto error;
2991 spider_close_sys_table(thd, table_crd, &open_tables_backup, need_lock);
2992 table_crd = NULL;
2993 DBUG_RETURN(0);
2994
2995error:
2996 if (table_crd)
2997 spider_close_sys_table(thd, table_crd, &open_tables_backup, need_lock);
2998 DBUG_RETURN(error_num);
2999}
3000
3001int spider_sys_get_table_sts(
3002 THD *thd,
3003 const char *name,
3004 uint name_length,
3005 ulonglong *data_file_length,
3006 ulonglong *max_data_file_length,
3007 ulonglong *index_file_length,
3008 ha_rows *records,
3009 ulong *mean_rec_length,
3010 time_t *check_time,
3011 time_t *create_time,
3012 time_t *update_time,
3013 bool need_lock
3014) {
3015 int error_num;
3016 char table_key[MAX_KEY_LENGTH];
3017 TABLE *table_sts = NULL;
3018#if MYSQL_VERSION_ID < 50500
3019 Open_tables_state open_tables_backup;
3020#else
3021 Open_tables_backup open_tables_backup;
3022#endif
3023 DBUG_ENTER("spider_sys_get_table_sts");
3024 if (
3025 !(table_sts = spider_open_sys_table(
3026 thd, SPIDER_SYS_TABLE_STS_TABLE_NAME_STR,
3027 SPIDER_SYS_TABLE_STS_TABLE_NAME_LEN, TRUE,
3028 &open_tables_backup, need_lock, &error_num))
3029 ) {
3030 goto error;
3031 }
3032
3033 table_sts->use_all_columns();
3034 spider_store_tables_name(table_sts, name, name_length);
3035 if ((error_num = spider_check_sys_table(table_sts, table_key)))
3036 {
3037 if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
3038 {
3039 table_sts->file->print_error(error_num, MYF(0));
3040 }
3041 goto error;
3042 } else {
3043 spider_get_sys_table_sts_info(
3044 table_sts,
3045 data_file_length,
3046 max_data_file_length,
3047 index_file_length,
3048 records,
3049 mean_rec_length,
3050 check_time,
3051 create_time,
3052 update_time
3053 );
3054 }
3055
3056 spider_close_sys_table(thd, table_sts, &open_tables_backup, need_lock);
3057 table_sts = NULL;
3058 DBUG_RETURN(0);
3059
3060error:
3061 if (table_sts)
3062 spider_close_sys_table(thd, table_sts, &open_tables_backup, need_lock);
3063 DBUG_RETURN(error_num);
3064}
3065
3066int spider_sys_get_table_crd(
3067 THD *thd,
3068 const char *name,
3069 uint name_length,
3070 longlong *cardinality,
3071 uint number_of_keys,
3072 bool need_lock
3073) {
3074 int error_num;
3075 char table_key[MAX_KEY_LENGTH];
3076 bool index_inited = FALSE;
3077 TABLE *table_crd = NULL;
3078#if MYSQL_VERSION_ID < 50500
3079 Open_tables_state open_tables_backup;
3080#else
3081 Open_tables_backup open_tables_backup;
3082#endif
3083 DBUG_ENTER("spider_sys_get_table_crd");
3084 if (
3085 !(table_crd = spider_open_sys_table(
3086 thd, SPIDER_SYS_TABLE_CRD_TABLE_NAME_STR,
3087 SPIDER_SYS_TABLE_CRD_TABLE_NAME_LEN, TRUE,
3088 &open_tables_backup, need_lock, &error_num))
3089 ) {
3090 goto error;
3091 }
3092
3093 table_crd->use_all_columns();
3094 spider_store_tables_name(table_crd, name, name_length);
3095 if ((error_num = spider_get_sys_table_by_idx(table_crd, table_key, 0,
3096 SPIDER_SYS_TABLE_CRD_PK_COL_CNT - 1)))
3097 {
3098 if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
3099 {
3100 table_crd->file->print_error(error_num, MYF(0));
3101 }
3102 goto error;
3103 } else {
3104 index_inited = TRUE;
3105 do {
3106 spider_get_sys_table_crd_info(
3107 table_crd,
3108 cardinality,
3109 number_of_keys
3110 );
3111 error_num = spider_sys_index_next_same(table_crd, table_key);
3112 } while (error_num == 0);
3113 }
3114 index_inited = FALSE;
3115 if ((error_num = spider_sys_index_end(table_crd)))
3116 {
3117 table_crd->file->print_error(error_num, MYF(0));
3118 goto error;
3119 }
3120
3121 spider_close_sys_table(thd, table_crd, &open_tables_backup, need_lock);
3122 table_crd = NULL;
3123 DBUG_RETURN(0);
3124
3125error:
3126 if (index_inited)
3127 spider_sys_index_end(table_crd);
3128 if (table_crd)
3129 spider_close_sys_table(thd, table_crd, &open_tables_backup, need_lock);
3130 DBUG_RETURN(error_num);
3131}
3132
3133int spider_sys_replace(
3134 TABLE *table,
3135 bool *modified_non_trans_table
3136) {
3137 int error_num, key_num;
3138 bool last_uniq_key;
3139 char table_key[MAX_KEY_LENGTH];
3140 DBUG_ENTER("spider_sys_replace");
3141
3142 while ((error_num = spider_write_sys_table_row(table, FALSE)))
3143 {
3144 if (
3145 table->file->is_fatal_error(error_num, HA_CHECK_DUP) ||
3146 (key_num = table->file->get_dup_key(error_num)) < 0
3147 )
3148 goto error;
3149
3150 if (table->file->ha_table_flags() & HA_DUPLICATE_POS)
3151 {
3152#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
3153 error_num = table->file->ha_rnd_pos(table->record[1],
3154 table->file->dup_ref);
3155#else
3156 error_num = table->file->rnd_pos(table->record[1], table->file->dup_ref);
3157#endif
3158 if (error_num)
3159 {
3160 if (error_num == HA_ERR_RECORD_DELETED)
3161 error_num = HA_ERR_KEY_NOT_FOUND;
3162 goto error;
3163 }
3164 } else {
3165 if ((error_num = table->file->extra(HA_EXTRA_FLUSH_CACHE)))
3166 goto error;
3167
3168 key_copy((uchar*)table_key, table->record[0],
3169 table->key_info + key_num, 0);
3170#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 50200
3171 error_num = table->file->ha_index_read_idx_map(table->record[1], key_num,
3172 (const uchar*)table_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT);
3173#else
3174 error_num = table->file->index_read_idx_map(table->record[1], key_num,
3175 (const uchar*)table_key, HA_WHOLE_KEY, HA_READ_KEY_EXACT);
3176#endif
3177 if (error_num)
3178 {
3179 if (error_num == HA_ERR_RECORD_DELETED)
3180 error_num = HA_ERR_KEY_NOT_FOUND;
3181 goto error;
3182 }
3183 }
3184
3185 last_uniq_key = TRUE;
3186 while (++key_num < (int) table->s->keys)
3187 if (table->key_info[key_num].flags & HA_NOSAME)
3188 last_uniq_key = FALSE;
3189
3190 if (
3191 last_uniq_key &&
3192 !table->file->referenced_by_foreign_key()
3193 ) {
3194 if ((error_num = spider_update_sys_table_row(table)))
3195 goto error;
3196 DBUG_RETURN(0);
3197 } else {
3198 if ((error_num = spider_delete_sys_table_row(table, 1, FALSE)))
3199 goto error;
3200 *modified_non_trans_table = TRUE;
3201 }
3202 }
3203
3204 DBUG_RETURN(0);
3205
3206error:
3207 DBUG_RETURN(error_num);
3208}
3209
3210TABLE *spider_mk_sys_tmp_table(
3211 THD *thd,
3212 TABLE *table,
3213 TMP_TABLE_PARAM *tmp_tbl_prm,
3214 const char *field_name,
3215 CHARSET_INFO *cs
3216) {
3217 Field_blob *field;
3218 Item_field *i_field;
3219 List<Item> i_list;
3220 TABLE *tmp_table;
3221 LEX_CSTRING name= { field_name, strlen(field_name) };
3222 DBUG_ENTER("spider_mk_sys_tmp_table");
3223
3224#ifdef SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR
3225 if (!(field = new (thd->mem_root) Field_blob(
3226 (uint32) 4294967295U, FALSE, &name, cs, TRUE)))
3227 goto error_alloc_field;
3228#else
3229 if (!(field = new Field_blob(
3230 4294967295U, FALSE, &name, cs, TRUE)))
3231 goto error_alloc_field;
3232#endif
3233 field->init(table);
3234
3235#ifdef SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR
3236 if (!(i_field = new (thd->mem_root) Item_field(thd, (Field *) field)))
3237 goto error_alloc_item_field;
3238#else
3239 if (!(i_field = new Item_field((Field *) field)))
3240 goto error_alloc_item_field;
3241#endif
3242
3243 if (i_list.push_back(i_field))
3244 goto error_push_item;
3245
3246 if (!(tmp_table = create_tmp_table(thd, tmp_tbl_prm,
3247 i_list, (ORDER*) NULL, FALSE, FALSE, TMP_TABLE_FORCE_MYISAM,
3248 HA_POS_ERROR, &empty_clex_string)))
3249 goto error_create_tmp_table;
3250 DBUG_RETURN(tmp_table);
3251
3252error_create_tmp_table:
3253error_push_item:
3254 delete i_field;
3255error_alloc_item_field:
3256 delete field;
3257error_alloc_field:
3258 DBUG_RETURN(NULL);
3259}
3260
3261void spider_rm_sys_tmp_table(
3262 THD *thd,
3263 TABLE *tmp_table,
3264 TMP_TABLE_PARAM *tmp_tbl_prm
3265) {
3266 DBUG_ENTER("spider_rm_sys_tmp_table");
3267 free_tmp_table(thd, tmp_table);
3268 tmp_tbl_prm->cleanup();
3269 tmp_tbl_prm->field_count = 1;
3270 DBUG_VOID_RETURN;
3271}
3272
3273TABLE *spider_mk_sys_tmp_table_for_result(
3274 THD *thd,
3275 TABLE *table,
3276 TMP_TABLE_PARAM *tmp_tbl_prm,
3277 const char *field_name1,
3278 const char *field_name2,
3279 const char *field_name3,
3280 CHARSET_INFO *cs
3281) {
3282 Field_blob *field1, *field2, *field3;
3283 Item_field *i_field1, *i_field2, *i_field3;
3284 List<Item> i_list;
3285 TABLE *tmp_table;
3286 LEX_CSTRING name1= { field_name1, strlen(field_name1) };
3287 LEX_CSTRING name2= { field_name2, strlen(field_name2) };
3288 LEX_CSTRING name3= { field_name3, strlen(field_name3) };
3289 DBUG_ENTER("spider_mk_sys_tmp_table_for_result");
3290
3291#ifdef SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR
3292 if (!(field1 = new (thd->mem_root) Field_blob(
3293 (uint32) 4294967295U, FALSE, &name1, cs, TRUE)))
3294 goto error_alloc_field1;
3295#else
3296 if (!(field1 = new Field_blob(
3297 4294967295U, FALSE, &name1, cs, TRUE)))
3298 goto error_alloc_field1;
3299#endif
3300 field1->init(table);
3301
3302#ifdef SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR
3303 if (!(i_field1 = new (thd->mem_root) Item_field(thd, (Field *) field1)))
3304 goto error_alloc_item_field1;
3305#else
3306 if (!(i_field1 = new Item_field((Field *) field1)))
3307 goto error_alloc_item_field1;
3308#endif
3309
3310 if (i_list.push_back(i_field1))
3311 goto error_push_item1;
3312
3313#ifdef SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR
3314 if (!(field2 = new (thd->mem_root) Field_blob(
3315 4294967295U, FALSE, &name2, cs, TRUE)))
3316 goto error_alloc_field2;
3317#else
3318 if (!(field2 = new Field_blob(
3319 4294967295U, FALSE, &name2, cs, TRUE)))
3320 goto error_alloc_field2;
3321#endif
3322 field2->init(table);
3323
3324#ifdef SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR
3325 if (!(i_field2 = new (thd->mem_root) Item_field(thd, (Field *) field2)))
3326 goto error_alloc_item_field2;
3327#else
3328 if (!(i_field2 = new Item_field((Field *) field2)))
3329 goto error_alloc_item_field2;
3330#endif
3331
3332 if (i_list.push_back(i_field2))
3333 goto error_push_item2;
3334
3335#ifdef SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR
3336 if (!(field3 = new (thd->mem_root) Field_blob(
3337 4294967295U, FALSE, &name3, cs, TRUE)))
3338 goto error_alloc_field3;
3339#else
3340 if (!(field3 = new Field_blob(
3341 4294967295U, FALSE, field_name3, cs, TRUE)))
3342 goto error_alloc_field3;
3343#endif
3344 field3->init(table);
3345
3346#ifdef SPIDER_FIELD_FIELDPTR_REQUIRES_THDPTR
3347 if (!(i_field3 = new (thd->mem_root) Item_field(thd, (Field *) field3)))
3348 goto error_alloc_item_field3;
3349#else
3350 if (!(i_field3 = new Item_field((Field *) field3)))
3351 goto error_alloc_item_field3;
3352#endif
3353
3354 if (i_list.push_back(i_field3))
3355 goto error_push_item3;
3356
3357 if (!(tmp_table = create_tmp_table(thd, tmp_tbl_prm,
3358 i_list, (ORDER*) NULL, FALSE, FALSE, TMP_TABLE_FORCE_MYISAM,
3359 HA_POS_ERROR, &empty_clex_string)))
3360 goto error_create_tmp_table;
3361 DBUG_RETURN(tmp_table);
3362
3363error_create_tmp_table:
3364error_push_item3:
3365 delete i_field3;
3366error_alloc_item_field3:
3367 delete field3;
3368error_alloc_field3:
3369error_push_item2:
3370 delete i_field2;
3371error_alloc_item_field2:
3372 delete field2;
3373error_alloc_field2:
3374error_push_item1:
3375 delete i_field1;
3376error_alloc_item_field1:
3377 delete field1;
3378error_alloc_field1:
3379 DBUG_RETURN(NULL);
3380}
3381
3382void spider_rm_sys_tmp_table_for_result(
3383 THD *thd,
3384 TABLE *tmp_table,
3385 TMP_TABLE_PARAM *tmp_tbl_prm
3386) {
3387 DBUG_ENTER("spider_rm_sys_tmp_table_for_result");
3388 free_tmp_table(thd, tmp_table);
3389 tmp_tbl_prm->cleanup();
3390 tmp_tbl_prm->field_count = 3;
3391 DBUG_VOID_RETURN;
3392}
3393