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 | /* |
17 | Structure used to manage Spider parameter string parsing. Types of |
18 | parameters include: |
19 | - connection strings |
20 | - UDF parameters |
21 | |
22 | A parameter string consists of one or more parameter definitions using |
23 | the following syntax: |
24 | <parameter title> <parameter value> |
25 | A comma is the separator character between multiple parameter definitions. |
26 | Parameter titles must not be quoted. Parameter values must be quoted with |
27 | single or double quotes. |
28 | */ |
29 | |
30 | typedef struct st_spider_param_string_parse |
31 | { |
32 | char *start_ptr; /* Pointer to the start of the parameter string */ |
33 | char *end_ptr; /* Pointer to the end of the parameter string */ |
34 | char *start_title_ptr; /* Pointer to the start of the current parameter |
35 | title */ |
36 | char *end_title_ptr; /* Pointer to the end of the current parameter |
37 | title */ |
38 | char *start_value_ptr; /* Pointer to the start of the current parameter |
39 | value */ |
40 | char *end_value_ptr; /* Pointer to the end of the current parameter |
41 | value */ |
42 | int error_num; /* Error code of the error message to print when |
43 | an error is detected */ |
44 | uint delim_title_len; /* Length of the paramater title's delimiter */ |
45 | uint delim_value_len; /* Length of the paramater value's delimiter */ |
46 | char delim_title; /* Current parameter title's delimiter character */ |
47 | char delim_value; /* Current parameter value's delimiter character */ |
48 | |
49 | /** |
50 | Initialize the parameter string parse information. |
51 | |
52 | @param param_string Pointer to the parameter string being parsed. |
53 | @param error_code Error code of the error message to print when |
54 | an error is detected. |
55 | */ |
56 | |
57 | inline void init(char *param_string, int error_code) |
58 | { |
59 | start_ptr = param_string; |
60 | end_ptr = start_ptr + strlen(start_ptr); |
61 | |
62 | init_param_title(); |
63 | init_param_value(); |
64 | |
65 | error_num = error_code; |
66 | } |
67 | |
68 | /** |
69 | Initialize the current parameter title. |
70 | */ |
71 | |
72 | inline void init_param_title() |
73 | { |
74 | start_title_ptr = end_title_ptr = NULL; |
75 | delim_title_len = 0; |
76 | delim_title = '\0'; |
77 | } |
78 | |
79 | /** |
80 | Save pointers to the start and end positions of the current parameter |
81 | title in the parameter string. Also save the parameter title's |
82 | delimiter character. |
83 | |
84 | @param start_value Pointer to the start position of the current |
85 | parameter title. |
86 | @param end_value Pointer to the end position of the current |
87 | parameter title. |
88 | */ |
89 | |
90 | inline void set_param_title(char *start_title, char *end_title) |
91 | { |
92 | start_title_ptr = start_title; |
93 | end_title_ptr = end_title; |
94 | |
95 | if (*start_title == '"' || |
96 | *start_title == '\'') |
97 | { |
98 | delim_title = *start_title; |
99 | |
100 | if (start_title >= start_ptr && *--start_title == '\\') |
101 | delim_title_len = 2; |
102 | else |
103 | delim_title_len = 1; |
104 | } |
105 | } |
106 | |
107 | /** |
108 | Initialize the current parameter value. |
109 | */ |
110 | |
111 | inline void init_param_value() |
112 | { |
113 | start_value_ptr = end_value_ptr = NULL; |
114 | delim_value_len = 0; |
115 | delim_value = '\0'; |
116 | } |
117 | |
118 | /** |
119 | Save pointers to the start and end positions of the current parameter |
120 | value in the parameter string. Also save the parameter value's |
121 | delimiter character. |
122 | |
123 | @param start_value Pointer to the start position of the current |
124 | parameter value. |
125 | @param end_value Pointer to the end position of the current |
126 | parameter value. |
127 | */ |
128 | |
129 | inline void set_param_value(char *start_value, char *end_value) |
130 | { |
131 | start_value_ptr = start_value--; |
132 | end_value_ptr = end_value; |
133 | |
134 | if (*start_value == '"' || |
135 | *start_value == '\'') |
136 | { |
137 | delim_value = *start_value; |
138 | |
139 | if (*--start_value == '\\') |
140 | delim_value_len = 2; |
141 | else |
142 | delim_value_len = 1; |
143 | } |
144 | } |
145 | |
146 | /** |
147 | Determine whether the current parameter in the parameter string has |
148 | extra parameter values. |
149 | |
150 | @return 0 Current parameter value in the parameter string |
151 | does not have extra parameter values. |
152 | <> 0 Error code indicating that the current parameter |
153 | value in the parameter string has extra |
154 | parameter values. |
155 | */ |
156 | |
157 | inline int () |
158 | { |
159 | int error_num = 0; |
160 | DBUG_ENTER("has_extra_parameter_values" ); |
161 | |
162 | if (end_value_ptr) |
163 | { |
164 | /* There is a current parameter value */ |
165 | char *end_param_ptr = end_value_ptr; |
166 | |
167 | while (end_param_ptr < end_ptr && |
168 | (*end_param_ptr == ' ' || *end_param_ptr == '\r' || |
169 | *end_param_ptr == '\n' || *end_param_ptr == '\t')) |
170 | end_param_ptr++; |
171 | |
172 | if (end_param_ptr < end_ptr && *end_param_ptr != '\0') |
173 | { |
174 | /* Extra values in parameter definition */ |
175 | error_num = print_param_error(); |
176 | } |
177 | } |
178 | |
179 | DBUG_RETURN(error_num); |
180 | } |
181 | |
182 | /** |
183 | Restore the current parameter's input delimiter characters in the |
184 | parameter string. They were NULLed during parameter parsing. |
185 | */ |
186 | |
187 | inline void restore_delims() |
188 | { |
189 | char *end = end_title_ptr - 1; |
190 | |
191 | switch (delim_title_len) |
192 | { |
193 | case 2: |
194 | *end++ = '\\'; |
195 | /* Fall through */ |
196 | case 1: |
197 | *end = delim_title; |
198 | } |
199 | |
200 | end = end_value_ptr - 1; |
201 | switch (delim_value_len) |
202 | { |
203 | case 2: |
204 | *end++ = '\\'; |
205 | /* Fall through */ |
206 | case 1: |
207 | *end = delim_value; |
208 | } |
209 | } |
210 | |
211 | /** |
212 | Print a parameter string error message. |
213 | |
214 | @return Error code. |
215 | */ |
216 | |
217 | int print_param_error(); |
218 | } SPIDER_PARAM_STRING_PARSE; |
219 | |
220 | uchar *spider_tbl_get_key( |
221 | SPIDER_SHARE *share, |
222 | size_t *length, |
223 | my_bool not_used __attribute__ ((unused)) |
224 | ); |
225 | |
226 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
227 | uchar *spider_pt_share_get_key( |
228 | SPIDER_PARTITION_SHARE *share, |
229 | size_t *length, |
230 | my_bool not_used __attribute__ ((unused)) |
231 | ); |
232 | |
233 | uchar *spider_pt_handler_share_get_key( |
234 | SPIDER_PARTITION_HANDLER_SHARE *share, |
235 | size_t *length, |
236 | my_bool not_used __attribute__ ((unused)) |
237 | ); |
238 | #endif |
239 | |
240 | uchar *spider_link_get_key( |
241 | SPIDER_LINK_FOR_HASH *link_for_hash, |
242 | size_t *length, |
243 | my_bool not_used __attribute__ ((unused)) |
244 | ); |
245 | |
246 | uchar *spider_ha_get_key( |
247 | ha_spider *spider, |
248 | size_t *length, |
249 | my_bool not_used __attribute__ ((unused)) |
250 | ); |
251 | |
252 | int spider_get_server( |
253 | SPIDER_SHARE *share, |
254 | int link_idx |
255 | ); |
256 | |
257 | int spider_free_share_alloc( |
258 | SPIDER_SHARE *share |
259 | ); |
260 | |
261 | void spider_free_tmp_share_alloc( |
262 | SPIDER_SHARE *share |
263 | ); |
264 | |
265 | char *spider_get_string_between_quote( |
266 | char *ptr, |
267 | bool alloc, |
268 | SPIDER_PARAM_STRING_PARSE *param_string_parse = NULL |
269 | ); |
270 | |
271 | int spider_create_string_list( |
272 | char ***string_list, |
273 | uint **string_length_list, |
274 | uint *list_length, |
275 | char *str, |
276 | uint length, |
277 | SPIDER_PARAM_STRING_PARSE *param_string_parse |
278 | ); |
279 | |
280 | int spider_create_long_list( |
281 | long **long_list, |
282 | uint *list_length, |
283 | char *str, |
284 | uint length, |
285 | long min_val, |
286 | long max_val, |
287 | SPIDER_PARAM_STRING_PARSE *param_string_parse |
288 | ); |
289 | |
290 | int spider_create_longlong_list( |
291 | longlong **longlong_list, |
292 | uint *list_length, |
293 | char *str, |
294 | uint length, |
295 | longlong min_val, |
296 | longlong max_val, |
297 | SPIDER_PARAM_STRING_PARSE *param_string_parse |
298 | ); |
299 | |
300 | int spider_increase_string_list( |
301 | char ***string_list, |
302 | uint **string_length_list, |
303 | uint *list_length, |
304 | uint *list_charlen, |
305 | uint link_count |
306 | ); |
307 | |
308 | int spider_increase_long_list( |
309 | long **long_list, |
310 | uint *list_length, |
311 | uint link_count |
312 | ); |
313 | |
314 | int spider_increase_longlong_list( |
315 | longlong **longlong_list, |
316 | uint *list_length, |
317 | uint link_count |
318 | ); |
319 | |
320 | int spider_parse_connect_info( |
321 | SPIDER_SHARE *share, |
322 | TABLE_SHARE *table_share, |
323 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
324 | partition_info *part_info, |
325 | #endif |
326 | uint create_table |
327 | ); |
328 | |
329 | int spider_set_connect_info_default( |
330 | SPIDER_SHARE *share, |
331 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
332 | partition_element *part_elem, |
333 | partition_element *sub_elem, |
334 | #endif |
335 | TABLE_SHARE *table_share |
336 | ); |
337 | |
338 | int spider_set_connect_info_default_db_table( |
339 | SPIDER_SHARE *share, |
340 | const char *db_name, |
341 | uint db_name_length, |
342 | const char *table_name, |
343 | uint table_name_length |
344 | ); |
345 | |
346 | int spider_set_connect_info_default_dbtable( |
347 | SPIDER_SHARE *share, |
348 | const char *dbtable_name, |
349 | int dbtable_name_length |
350 | ); |
351 | |
352 | #ifndef DBUG_OFF |
353 | void spider_print_keys( |
354 | const char *key, |
355 | uint length |
356 | ); |
357 | #endif |
358 | |
359 | int spider_create_conn_keys( |
360 | SPIDER_SHARE *share |
361 | ); |
362 | |
363 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
364 | SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share( |
365 | const char *table_name, |
366 | uint table_name_length, |
367 | my_hash_value_type hash_value, |
368 | bool locked, |
369 | bool need_to_create, |
370 | int *error_num |
371 | ); |
372 | #else |
373 | SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share( |
374 | const char *table_name, |
375 | uint table_name_length, |
376 | bool locked, |
377 | bool need_to_create, |
378 | int *error_num |
379 | ); |
380 | #endif |
381 | |
382 | void spider_free_lgtm_tblhnd_share_alloc( |
383 | SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share, |
384 | bool locked |
385 | ); |
386 | |
387 | SPIDER_SHARE *spider_create_share( |
388 | const char *table_name, |
389 | TABLE_SHARE *table_share, |
390 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
391 | partition_info *part_info, |
392 | #endif |
393 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
394 | my_hash_value_type hash_value, |
395 | #endif |
396 | int *error_num |
397 | ); |
398 | |
399 | SPIDER_SHARE *spider_get_share( |
400 | const char *table_name, |
401 | TABLE *table, |
402 | THD *thd, |
403 | ha_spider *spider, |
404 | int *error_num |
405 | ); |
406 | |
407 | void spider_free_share_resource_only( |
408 | SPIDER_SHARE *share |
409 | ); |
410 | |
411 | int spider_free_share( |
412 | SPIDER_SHARE *share |
413 | ); |
414 | |
415 | void spider_update_link_status_for_share( |
416 | const char *table_name, |
417 | uint table_name_length, |
418 | int link_idx, |
419 | long link_status |
420 | ); |
421 | |
422 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
423 | SPIDER_PARTITION_SHARE *spider_get_pt_share( |
424 | SPIDER_SHARE *share, |
425 | TABLE_SHARE *table_share, |
426 | int *error_num |
427 | ); |
428 | |
429 | int spider_free_pt_share( |
430 | SPIDER_PARTITION_SHARE *partition_share |
431 | ); |
432 | |
433 | void spider_copy_sts_to_pt_share( |
434 | SPIDER_PARTITION_SHARE *partition_share, |
435 | SPIDER_SHARE *share |
436 | ); |
437 | |
438 | void spider_copy_sts_to_share( |
439 | SPIDER_SHARE *share, |
440 | SPIDER_PARTITION_SHARE *partition_share |
441 | ); |
442 | |
443 | void spider_copy_crd_to_pt_share( |
444 | SPIDER_PARTITION_SHARE *partition_share, |
445 | SPIDER_SHARE *share, |
446 | int fields |
447 | ); |
448 | |
449 | void spider_copy_crd_to_share( |
450 | SPIDER_SHARE *share, |
451 | SPIDER_PARTITION_SHARE *partition_share, |
452 | int fields |
453 | ); |
454 | #endif |
455 | |
456 | int spider_open_all_tables( |
457 | SPIDER_TRX *trx, |
458 | bool lock |
459 | ); |
460 | |
461 | bool spider_flush_logs( |
462 | handlerton *hton |
463 | ); |
464 | |
465 | handler* spider_create_handler( |
466 | handlerton *hton, |
467 | TABLE_SHARE *table, |
468 | MEM_ROOT *mem_root |
469 | ); |
470 | |
471 | int spider_close_connection( |
472 | handlerton* hton, |
473 | THD* thd |
474 | ); |
475 | |
476 | void spider_drop_database( |
477 | handlerton *hton, |
478 | char* path |
479 | ); |
480 | |
481 | bool spider_show_status( |
482 | handlerton *hton, |
483 | THD *thd, |
484 | stat_print_fn *stat_print, |
485 | enum ha_stat_type stat_type |
486 | ); |
487 | |
488 | int spider_db_done( |
489 | void *p |
490 | ); |
491 | |
492 | int spider_panic( |
493 | handlerton *hton, |
494 | ha_panic_function type |
495 | ); |
496 | |
497 | int spider_db_init( |
498 | void *p |
499 | ); |
500 | |
501 | char *spider_create_table_name_string( |
502 | const char *table_name, |
503 | const char *part_name, |
504 | const char *sub_name |
505 | ); |
506 | |
507 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
508 | void spider_get_partition_info( |
509 | const char *table_name, |
510 | uint table_name_length, |
511 | const TABLE_SHARE *table_share, |
512 | partition_info *part_info, |
513 | partition_element **part_elem, |
514 | partition_element **sub_elem |
515 | ); |
516 | #endif |
517 | |
518 | int spider_get_sts( |
519 | SPIDER_SHARE *share, |
520 | int link_idx, |
521 | time_t tmp_time, |
522 | ha_spider *spider, |
523 | double sts_interval, |
524 | int sts_mode, |
525 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
526 | int sts_sync, |
527 | #endif |
528 | int sts_sync_level, |
529 | uint flag |
530 | ); |
531 | |
532 | int spider_get_crd( |
533 | SPIDER_SHARE *share, |
534 | int link_idx, |
535 | time_t tmp_time, |
536 | ha_spider *spider, |
537 | TABLE *table, |
538 | double crd_interval, |
539 | int crd_mode, |
540 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
541 | int crd_sync, |
542 | #endif |
543 | int crd_sync_level |
544 | ); |
545 | |
546 | void spider_set_result_list_param( |
547 | ha_spider *spider |
548 | ); |
549 | |
550 | SPIDER_INIT_ERROR_TABLE *spider_get_init_error_table( |
551 | SPIDER_TRX *trx, |
552 | SPIDER_SHARE *share, |
553 | bool create |
554 | ); |
555 | |
556 | void spider_delete_init_error_table( |
557 | const char *name |
558 | ); |
559 | |
560 | bool spider_check_pk_update( |
561 | TABLE *table |
562 | ); |
563 | |
564 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
565 | #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS |
566 | bool spider_check_hs_pk_update( |
567 | ha_spider *spider, |
568 | key_range *key |
569 | ); |
570 | #endif |
571 | #endif |
572 | |
573 | void spider_set_tmp_share_pointer( |
574 | SPIDER_SHARE *tmp_share, |
575 | char **tmp_connect_info, |
576 | uint *tmp_connect_info_length, |
577 | long *tmp_long, |
578 | longlong *tmp_longlong |
579 | ); |
580 | |
581 | int spider_create_tmp_dbton_share( |
582 | SPIDER_SHARE *tmp_share |
583 | ); |
584 | |
585 | void spider_free_tmp_dbton_share( |
586 | SPIDER_SHARE *tmp_share |
587 | ); |
588 | |
589 | int spider_create_tmp_dbton_handler( |
590 | ha_spider *tmp_spider |
591 | ); |
592 | |
593 | void spider_free_tmp_dbton_handler( |
594 | ha_spider *tmp_spider |
595 | ); |
596 | |
597 | TABLE_LIST *spider_get_parent_table_list( |
598 | ha_spider *spider |
599 | ); |
600 | List<Index_hint> *spider_get_index_hints( |
601 | ha_spider *spider |
602 | ); |
603 | |
604 | st_select_lex *spider_get_select_lex( |
605 | ha_spider *spider |
606 | ); |
607 | |
608 | void spider_get_select_limit_from_select_lex( |
609 | st_select_lex *select_lex, |
610 | longlong *select_limit, |
611 | longlong *offset_limit |
612 | ); |
613 | |
614 | void spider_get_select_limit( |
615 | ha_spider *spider, |
616 | st_select_lex **select_lex, |
617 | longlong *select_limit, |
618 | longlong *offset_limit |
619 | ); |
620 | |
621 | longlong spider_split_read_param( |
622 | ha_spider *spider |
623 | ); |
624 | |
625 | longlong spider_bg_split_read_param( |
626 | ha_spider *spider |
627 | ); |
628 | |
629 | void spider_first_split_read_param( |
630 | ha_spider *spider |
631 | ); |
632 | |
633 | void spider_next_split_read_param( |
634 | ha_spider *spider |
635 | ); |
636 | |
637 | bool spider_check_direct_order_limit( |
638 | ha_spider *spider |
639 | ); |
640 | |
641 | int spider_set_direct_limit_offset( |
642 | ha_spider* spider |
643 | ); |
644 | |
645 | bool spider_check_index_merge( |
646 | TABLE *table, |
647 | st_select_lex *select_lex |
648 | ); |
649 | |
650 | int spider_compare_for_sort( |
651 | SPIDER_SORT *a, |
652 | SPIDER_SORT *b |
653 | ); |
654 | |
655 | ulong spider_calc_for_sort( |
656 | uint count, |
657 | ... |
658 | ); |
659 | |
660 | double spider_rand( |
661 | uint32 rand_source |
662 | ); |
663 | |
664 | #ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE |
665 | int spider_discover_table_structure_internal( |
666 | SPIDER_TRX *trx, |
667 | SPIDER_SHARE *spider_share, |
668 | spider_string *str |
669 | ); |
670 | |
671 | int spider_discover_table_structure( |
672 | handlerton *hton, |
673 | THD* thd, |
674 | TABLE_SHARE *share, |
675 | HA_CREATE_INFO *info |
676 | ); |
677 | #endif |
678 | |
679 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
680 | int spider_create_spider_object_for_share( |
681 | SPIDER_TRX *trx, |
682 | SPIDER_SHARE *share, |
683 | ha_spider **spider |
684 | ); |
685 | |
686 | void spider_free_spider_object_for_share( |
687 | ha_spider **spider |
688 | ); |
689 | |
690 | int spider_create_sts_threads( |
691 | SPIDER_THREAD *spider_thread |
692 | ); |
693 | |
694 | void spider_free_sts_threads( |
695 | SPIDER_THREAD *spider_thread |
696 | ); |
697 | |
698 | int spider_create_crd_threads( |
699 | SPIDER_THREAD *spider_thread |
700 | ); |
701 | |
702 | void spider_free_crd_threads( |
703 | SPIDER_THREAD *spider_thread |
704 | ); |
705 | |
706 | void *spider_table_bg_sts_action( |
707 | void *arg |
708 | ); |
709 | |
710 | void *spider_table_bg_crd_action( |
711 | void *arg |
712 | ); |
713 | |
714 | void spider_table_add_share_to_sts_thread( |
715 | SPIDER_SHARE *share |
716 | ); |
717 | |
718 | void spider_table_add_share_to_crd_thread( |
719 | SPIDER_SHARE *share |
720 | ); |
721 | |
722 | void spider_table_remove_share_from_sts_thread( |
723 | SPIDER_SHARE *share |
724 | ); |
725 | |
726 | void spider_table_remove_share_from_crd_thread( |
727 | SPIDER_SHARE *share |
728 | ); |
729 | #endif |
730 | |