1 /* Copyright (C) 2008-2020 Kentoku Shiba
2 Copyright (C) 2019-2022 MariaDB corp
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
16
17 #define MYSQL_SERVER 1
18 #include <my_global.h>
19 #include "mysql_version.h"
20 #include "spd_environ.h"
21 #if MYSQL_VERSION_ID < 50500
22 #include "mysql_priv.h"
23 #include <mysql/plugin.h>
24 #else
25 #include "sql_priv.h"
26 #include "probes_mysql.h"
27 #include "my_getopt.h"
28 #include "sql_class.h"
29 #include "sql_partition.h"
30 #include "sql_servers.h"
31 #include "sql_select.h"
32 #include "tztime.h"
33 #include "sql_parse.h"
34 #endif
35 #include "spd_err.h"
36 #include "spd_param.h"
37 #include "spd_db_include.h"
38 #include "spd_include.h"
39 #include "spd_sys_table.h"
40 #include "ha_spider.h"
41 #include "spd_trx.h"
42 #include "spd_db_conn.h"
43 #include "spd_table.h"
44 #include "spd_conn.h"
45 #include "spd_ping_table.h"
46 #include "spd_direct_sql.h"
47 #include "spd_malloc.h"
48 #include "spd_group_by_handler.h"
49 #include "spd_init_query.h"
50
51 /* Background thread management */
52 #ifdef SPIDER_HAS_NEXT_THREAD_ID
53 #define SPIDER_set_next_thread_id(A)
54 MYSQL_THD create_thd();
55 void destroy_thd(MYSQL_THD thd);
56 #else
57 ulong *spd_db_att_thread_id;
SPIDER_set_next_thread_id(THD * A)58 inline void SPIDER_set_next_thread_id(THD *A)
59 {
60 pthread_mutex_lock(&LOCK_thread_count);
61 A->thread_id = (*spd_db_att_thread_id)++;
62 pthread_mutex_unlock(&LOCK_thread_count);
63 }
create_thd()64 MYSQL_THD create_thd()
65 {
66 THD *thd = SPIDER_new_THD(next_thread_id());
67 if (thd)
68 {
69 thd->thread_stack = (char*) &thd;
70 thd->store_globals();
71 thd->set_command(COM_DAEMON);
72 thd->security_ctx->host_or_ip = "";
73 }
74 return thd;
75 }
destroy_thd(MYSQL_THD thd)76 void destroy_thd(MYSQL_THD thd)
77 {
78 delete thd;
79 }
80 #endif
spider_create_sys_thd(SPIDER_THREAD * thread)81 inline MYSQL_THD spider_create_sys_thd(SPIDER_THREAD *thread)
82 {
83 THD *thd = create_thd();
84 if (thd)
85 {
86 SPIDER_set_next_thread_id(thd);
87 thd->mysys_var->current_cond = &thread->cond;
88 thd->mysys_var->current_mutex = &thread->mutex;
89 }
90 return thd;
91 }
spider_destroy_sys_thd(MYSQL_THD thd)92 inline void spider_destroy_sys_thd(MYSQL_THD thd)
93 {
94 destroy_thd(thd);
95 }
spider_create_thd()96 inline MYSQL_THD spider_create_thd()
97 {
98 THD *thd;
99 my_thread_init();
100 if (!(thd = new THD(next_thread_id())))
101 my_thread_end();
102 else
103 {
104 #ifdef HAVE_PSI_INTERFACE
105 mysql_thread_set_psi_id(thd->thread_id);
106 #endif
107 thd->thread_stack = (char *) &thd;
108 thd->store_globals();
109 }
110 return thd;
111 }
spider_destroy_thd(MYSQL_THD thd)112 inline void spider_destroy_thd(MYSQL_THD thd)
113 {
114 delete thd;
115 }
116
117 #ifdef SPIDER_XID_USES_xid_cache_iterate
118 #else
119 #ifdef XID_CACHE_IS_SPLITTED
120 uint *spd_db_att_xid_cache_split_num;
121 #endif
122 pthread_mutex_t *spd_db_att_LOCK_xid_cache;
123 HASH *spd_db_att_xid_cache;
124 #endif
125 struct charset_info_st *spd_charset_utf8mb3_bin;
126 const char **spd_defaults_extra_file;
127 const char **spd_defaults_file;
128 const char **spd_mysqld_unix_port;
129 uint *spd_mysqld_port;
130 bool volatile *spd_abort_loop;
131 Time_zone *spd_tz_system;
132 static int *spd_mysqld_server_started;
133 static pthread_mutex_t *spd_LOCK_server_started;
134 static pthread_cond_t *spd_COND_server_started;
135 extern long spider_conn_mutex_id;
136 handlerton *spider_hton_ptr;
137 SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE];
138 extern SPIDER_DBTON spider_dbton_mysql;
139 extern SPIDER_DBTON spider_dbton_mariadb;
140 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
141 extern SPIDER_DBTON spider_dbton_handlersocket;
142 #endif
143 #ifdef HAVE_ORACLE_OCI
144 extern SPIDER_DBTON spider_dbton_oracle;
145 #endif
146 #ifndef WITHOUT_SPIDER_BG_SEARCH
147 SPIDER_THREAD *spider_table_sts_threads;
148 SPIDER_THREAD *spider_table_crd_threads;
149 #endif
150
151 #ifdef HAVE_PSI_INTERFACE
152 PSI_mutex_key spd_key_mutex_tbl;
153 PSI_mutex_key spd_key_mutex_init_error_tbl;
154 #ifdef WITH_PARTITION_STORAGE_ENGINE
155 PSI_mutex_key spd_key_mutex_wide_share;
156 #endif
157 PSI_mutex_key spd_key_mutex_lgtm_tblhnd_share;
158 PSI_mutex_key spd_key_mutex_conn;
159 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
160 PSI_mutex_key spd_key_mutex_hs_r_conn;
161 PSI_mutex_key spd_key_mutex_hs_w_conn;
162 #endif
163 PSI_mutex_key spd_key_mutex_open_conn;
164 PSI_mutex_key spd_key_mutex_allocated_thds;
165 PSI_mutex_key spd_key_mutex_mon_table_cache;
166 PSI_mutex_key spd_key_mutex_udf_table_mon;
167 PSI_mutex_key spd_key_mutex_mta_conn;
168 #ifndef WITHOUT_SPIDER_BG_SEARCH
169 PSI_mutex_key spd_key_mutex_bg_conn_chain;
170 PSI_mutex_key spd_key_mutex_bg_conn_sync;
171 PSI_mutex_key spd_key_mutex_bg_conn;
172 PSI_mutex_key spd_key_mutex_bg_job_stack;
173 PSI_mutex_key spd_key_mutex_bg_mon;
174 PSI_mutex_key spd_key_mutex_bg_direct_sql;
175 #endif
176 PSI_mutex_key spd_key_mutex_mon_list_caller;
177 PSI_mutex_key spd_key_mutex_mon_list_receptor;
178 PSI_mutex_key spd_key_mutex_mon_list_monitor;
179 PSI_mutex_key spd_key_mutex_mon_list_update_status;
180 PSI_mutex_key spd_key_mutex_share;
181 PSI_mutex_key spd_key_mutex_share_sts;
182 PSI_mutex_key spd_key_mutex_share_crd;
183 PSI_mutex_key spd_key_mutex_share_auto_increment;
184 #ifdef WITH_PARTITION_STORAGE_ENGINE
185 PSI_mutex_key spd_key_mutex_wide_share_sts;
186 PSI_mutex_key spd_key_mutex_wide_share_crd;
187 #endif
188 PSI_mutex_key spd_key_mutex_udf_table;
189 PSI_mutex_key spd_key_mutex_mem_calc;
190 PSI_mutex_key spd_key_thread_id;
191 PSI_mutex_key spd_key_conn_id;
192 PSI_mutex_key spd_key_mutex_ipport_count;
193 PSI_mutex_key spd_key_mutex_conn_i;
194 #ifndef WITHOUT_SPIDER_BG_SEARCH
195 PSI_mutex_key spd_key_mutex_bg_stss;
196 PSI_mutex_key spd_key_mutex_bg_crds;
197 #endif
198 PSI_mutex_key spd_key_mutex_conn_loop_check;
199
200 static PSI_mutex_info all_spider_mutexes[]=
201 {
202 { &spd_key_mutex_tbl, "tbl", PSI_FLAG_GLOBAL},
203 { &spd_key_mutex_init_error_tbl, "init_error_tbl", PSI_FLAG_GLOBAL},
204 #ifdef WITH_PARTITION_STORAGE_ENGINE
205 { &spd_key_mutex_wide_share, "wide_share", PSI_FLAG_GLOBAL},
206 #endif
207 { &spd_key_mutex_lgtm_tblhnd_share, "lgtm_tblhnd_share", PSI_FLAG_GLOBAL},
208 { &spd_key_mutex_conn, "conn", PSI_FLAG_GLOBAL},
209 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
210 { &spd_key_mutex_hs_r_conn, "hs_r_conn", PSI_FLAG_GLOBAL},
211 { &spd_key_mutex_hs_w_conn, "hs_w_conn", PSI_FLAG_GLOBAL},
212 #endif
213 { &spd_key_mutex_open_conn, "open_conn", PSI_FLAG_GLOBAL},
214 { &spd_key_mutex_allocated_thds, "allocated_thds", PSI_FLAG_GLOBAL},
215 { &spd_key_mutex_mon_table_cache, "mon_table_cache", PSI_FLAG_GLOBAL},
216 { &spd_key_mutex_udf_table_mon, "udf_table_mon", PSI_FLAG_GLOBAL},
217 { &spd_key_mutex_mem_calc, "mem_calc", PSI_FLAG_GLOBAL},
218 { &spd_key_thread_id, "thread_id", PSI_FLAG_GLOBAL},
219 { &spd_key_conn_id, "conn_id", PSI_FLAG_GLOBAL},
220 { &spd_key_mutex_ipport_count, "ipport_count", PSI_FLAG_GLOBAL},
221 #ifndef WITHOUT_SPIDER_BG_SEARCH
222 { &spd_key_mutex_bg_stss, "bg_stss", PSI_FLAG_GLOBAL},
223 { &spd_key_mutex_bg_crds, "bg_crds", PSI_FLAG_GLOBAL},
224 #endif
225 { &spd_key_mutex_conn_i, "conn_i", 0},
226 { &spd_key_mutex_mta_conn, "mta_conn", 0},
227 #ifndef WITHOUT_SPIDER_BG_SEARCH
228 { &spd_key_mutex_bg_conn_chain, "bg_conn_chain", 0},
229 { &spd_key_mutex_bg_conn_sync, "bg_conn_sync", 0},
230 { &spd_key_mutex_bg_conn, "bg_conn", 0},
231 { &spd_key_mutex_bg_job_stack, "bg_job_stack", 0},
232 { &spd_key_mutex_bg_mon, "bg_mon", 0},
233 { &spd_key_mutex_bg_direct_sql, "bg_direct_sql", 0},
234 #endif
235 { &spd_key_mutex_mon_list_caller, "mon_list_caller", 0},
236 { &spd_key_mutex_mon_list_receptor, "mon_list_receptor", 0},
237 { &spd_key_mutex_mon_list_monitor, "mon_list_monitor", 0},
238 { &spd_key_mutex_mon_list_update_status, "mon_list_update_status", 0},
239 { &spd_key_mutex_share, "share", 0},
240 { &spd_key_mutex_share_sts, "share_sts", 0},
241 { &spd_key_mutex_share_crd, "share_crd", 0},
242 { &spd_key_mutex_share_auto_increment, "share_auto_increment", 0},
243 #ifdef WITH_PARTITION_STORAGE_ENGINE
244 { &spd_key_mutex_wide_share_sts, "wide_share_sts", 0},
245 { &spd_key_mutex_wide_share_crd, "wide_share_crd", 0},
246 #endif
247 { &spd_key_mutex_udf_table, "udf_table", 0},
248 { &spd_key_mutex_conn_loop_check, "conn_loop_check", 0},
249 };
250
251 #ifndef WITHOUT_SPIDER_BG_SEARCH
252 PSI_cond_key spd_key_cond_bg_conn_sync;
253 PSI_cond_key spd_key_cond_bg_conn;
254 PSI_cond_key spd_key_cond_bg_sts;
255 PSI_cond_key spd_key_cond_bg_sts_sync;
256 PSI_cond_key spd_key_cond_bg_crd;
257 PSI_cond_key spd_key_cond_bg_crd_sync;
258 PSI_cond_key spd_key_cond_bg_mon;
259 PSI_cond_key spd_key_cond_bg_mon_sleep;
260 PSI_cond_key spd_key_cond_bg_direct_sql;
261 #endif
262 PSI_cond_key spd_key_cond_udf_table_mon;
263 PSI_cond_key spd_key_cond_conn_i;
264 #ifndef WITHOUT_SPIDER_BG_SEARCH
265 PSI_cond_key spd_key_cond_bg_stss;
266 PSI_cond_key spd_key_cond_bg_sts_syncs;
267 PSI_cond_key spd_key_cond_bg_crds;
268 PSI_cond_key spd_key_cond_bg_crd_syncs;
269 #endif
270
271 static PSI_cond_info all_spider_conds[] = {
272 #ifndef WITHOUT_SPIDER_BG_SEARCH
273 {&spd_key_cond_bg_conn_sync, "bg_conn_sync", 0},
274 {&spd_key_cond_bg_conn, "bg_conn", 0},
275 {&spd_key_cond_bg_sts, "bg_sts", 0},
276 {&spd_key_cond_bg_sts_sync, "bg_sts_sync", 0},
277 {&spd_key_cond_bg_crd, "bg_crd", 0},
278 {&spd_key_cond_bg_crd_sync, "bg_crd_sync", 0},
279 {&spd_key_cond_bg_mon, "bg_mon", 0},
280 {&spd_key_cond_bg_mon_sleep, "bg_mon_sleep", 0},
281 {&spd_key_cond_bg_direct_sql, "bg_direct_sql", 0},
282 #endif
283 {&spd_key_cond_udf_table_mon, "udf_table_mon", 0},
284 {&spd_key_cond_conn_i, "conn_i", 0},
285 #ifndef WITHOUT_SPIDER_BG_SEARCH
286 {&spd_key_cond_bg_stss, "bg_stss", 0},
287 {&spd_key_cond_bg_sts_syncs, "bg_sts_syncs", 0},
288 {&spd_key_cond_bg_crds, "bg_crds", 0},
289 {&spd_key_cond_bg_crd_syncs, "bg_crd_syncs", 0},
290 #endif
291 };
292
293 #ifndef WITHOUT_SPIDER_BG_SEARCH
294 PSI_thread_key spd_key_thd_bg;
295 PSI_thread_key spd_key_thd_bg_sts;
296 PSI_thread_key spd_key_thd_bg_crd;
297 PSI_thread_key spd_key_thd_bg_mon;
298 PSI_thread_key spd_key_thd_bg_stss;
299 PSI_thread_key spd_key_thd_bg_crds;
300 #endif
301
302 static PSI_thread_info all_spider_threads[] = {
303 #ifndef WITHOUT_SPIDER_BG_SEARCH
304 {&spd_key_thd_bg, "bg", 0},
305 {&spd_key_thd_bg_sts, "bg_sts", 0},
306 {&spd_key_thd_bg_crd, "bg_crd", 0},
307 {&spd_key_thd_bg_mon, "bg_mon", 0},
308 {&spd_key_thd_bg_stss, "bg_stss", 0},
309 {&spd_key_thd_bg_crds, "bg_crds", 0},
310 #endif
311 };
312 #endif
313
314 extern HASH spider_open_connections;
315 extern HASH spider_ipport_conns;
316 extern uint spider_open_connections_id;
317 extern const char *spider_open_connections_func_name;
318 extern const char *spider_open_connections_file_name;
319 extern ulong spider_open_connections_line_no;
320 extern pthread_mutex_t spider_conn_mutex;
321 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
322 extern HASH spider_hs_r_conn_hash;
323 extern uint spider_hs_r_conn_hash_id;
324 extern const char *spider_hs_r_conn_hash_func_name;
325 extern const char *spider_hs_r_conn_hash_file_name;
326 extern ulong spider_hs_r_conn_hash_line_no;
327 extern pthread_mutex_t spider_hs_r_conn_mutex;
328 extern HASH spider_hs_w_conn_hash;
329 extern uint spider_hs_w_conn_hash_id;
330 extern const char *spider_hs_w_conn_hash_func_name;
331 extern const char *spider_hs_w_conn_hash_file_name;
332 extern ulong spider_hs_w_conn_hash_line_no;
333 extern pthread_mutex_t spider_hs_w_conn_mutex;
334 #endif
335 extern HASH *spider_udf_table_mon_list_hash;
336 extern uint spider_udf_table_mon_list_hash_id;
337 extern const char *spider_udf_table_mon_list_hash_func_name;
338 extern const char *spider_udf_table_mon_list_hash_file_name;
339 extern ulong spider_udf_table_mon_list_hash_line_no;
340 extern pthread_mutex_t *spider_udf_table_mon_mutexes;
341 extern pthread_cond_t *spider_udf_table_mon_conds;
342 extern pthread_mutex_t spider_open_conn_mutex;
343 extern pthread_mutex_t spider_mon_table_cache_mutex;
344 extern DYNAMIC_ARRAY spider_mon_table_cache;
345 extern uint spider_mon_table_cache_id;
346 extern const char *spider_mon_table_cache_func_name;
347 extern const char *spider_mon_table_cache_file_name;
348 extern ulong spider_mon_table_cache_line_no;
349
350 HASH spider_open_tables;
351 uint spider_open_tables_id;
352 const char *spider_open_tables_func_name;
353 const char *spider_open_tables_file_name;
354 ulong spider_open_tables_line_no;
355 pthread_mutex_t spider_tbl_mutex;
356 HASH spider_init_error_tables;
357 uint spider_init_error_tables_id;
358 const char *spider_init_error_tables_func_name;
359 const char *spider_init_error_tables_file_name;
360 ulong spider_init_error_tables_line_no;
361 pthread_mutex_t spider_init_error_tbl_mutex;
362
363 extern pthread_mutex_t spider_thread_id_mutex;
364 extern pthread_mutex_t spider_conn_id_mutex;
365 extern pthread_mutex_t spider_ipport_conn_mutex;
366
367 #ifdef WITH_PARTITION_STORAGE_ENGINE
368 HASH spider_open_wide_share;
369 uint spider_open_wide_share_id;
370 const char *spider_open_wide_share_func_name;
371 const char *spider_open_wide_share_file_name;
372 ulong spider_open_wide_share_line_no;
373 pthread_mutex_t spider_wide_share_mutex;
374 #endif
375
376 HASH spider_lgtm_tblhnd_share_hash;
377 uint spider_lgtm_tblhnd_share_hash_id;
378 const char *spider_lgtm_tblhnd_share_hash_func_name;
379 const char *spider_lgtm_tblhnd_share_hash_file_name;
380 ulong spider_lgtm_tblhnd_share_hash_line_no;
381 pthread_mutex_t spider_lgtm_tblhnd_share_mutex;
382
383 HASH spider_allocated_thds;
384 uint spider_allocated_thds_id;
385 const char *spider_allocated_thds_func_name;
386 const char *spider_allocated_thds_file_name;
387 ulong spider_allocated_thds_line_no;
388 pthread_mutex_t spider_allocated_thds_mutex;
389
390 #ifndef WITHOUT_SPIDER_BG_SEARCH
391 pthread_attr_t spider_pt_attr;
392 #endif
393
394 extern pthread_mutex_t spider_mem_calc_mutex;
395
396 extern const char *spider_alloc_func_name[SPIDER_MEM_CALC_LIST_NUM];
397 extern const char *spider_alloc_file_name[SPIDER_MEM_CALC_LIST_NUM];
398 extern ulong spider_alloc_line_no[SPIDER_MEM_CALC_LIST_NUM];
399 extern ulonglong spider_total_alloc_mem[SPIDER_MEM_CALC_LIST_NUM];
400 extern longlong spider_current_alloc_mem[SPIDER_MEM_CALC_LIST_NUM];
401 extern ulonglong spider_alloc_mem_count[SPIDER_MEM_CALC_LIST_NUM];
402 extern ulonglong spider_free_mem_count[SPIDER_MEM_CALC_LIST_NUM];
403
404 static char spider_wild_many = '%', spider_wild_one = '_',
405 spider_wild_prefix='\\';
406
407 static char spider_unique_id_buf[1 + 12 + 1 + (16 * 2) + 1 + 1];
408 LEX_CSTRING spider_unique_id;
409
410 // for spider_open_tables
spider_tbl_get_key(SPIDER_SHARE * share,size_t * length,my_bool not_used)411 uchar *spider_tbl_get_key(
412 SPIDER_SHARE *share,
413 size_t *length,
414 my_bool not_used __attribute__ ((unused))
415 ) {
416 DBUG_ENTER("spider_tbl_get_key");
417 *length = share->table_name_length;
418 DBUG_RETURN((uchar*) share->table_name);
419 }
420
spider_wide_share_get_key(SPIDER_WIDE_SHARE * share,size_t * length,my_bool not_used)421 uchar *spider_wide_share_get_key(
422 SPIDER_WIDE_SHARE *share,
423 size_t *length,
424 my_bool not_used __attribute__ ((unused))
425 ) {
426 DBUG_ENTER("spider_wide_share_get_key");
427 *length = share->table_name_length;
428 DBUG_RETURN((uchar*) share->table_name);
429 }
430
spider_lgtm_tblhnd_share_hash_get_key(SPIDER_LGTM_TBLHND_SHARE * share,size_t * length,my_bool not_used)431 uchar *spider_lgtm_tblhnd_share_hash_get_key(
432 SPIDER_LGTM_TBLHND_SHARE *share,
433 size_t *length,
434 my_bool not_used __attribute__ ((unused))
435 ) {
436 DBUG_ENTER("spider_lgtm_tblhnd_share_hash_get_key");
437 *length = share->table_name_length;
438 DBUG_RETURN((uchar*) share->table_name);
439 }
440
spider_link_get_key(SPIDER_LINK_FOR_HASH * link_for_hash,size_t * length,my_bool not_used)441 uchar *spider_link_get_key(
442 SPIDER_LINK_FOR_HASH *link_for_hash,
443 size_t *length,
444 my_bool not_used __attribute__ ((unused))
445 ) {
446 DBUG_ENTER("spider_link_get_key");
447 *length = link_for_hash->db_table_str->length();
448 DBUG_RETURN((uchar*) link_for_hash->db_table_str->ptr());
449 }
450
spider_ha_get_key(ha_spider * spider,size_t * length,my_bool not_used)451 uchar *spider_ha_get_key(
452 ha_spider *spider,
453 size_t *length,
454 my_bool not_used __attribute__ ((unused))
455 ) {
456 DBUG_ENTER("spider_ha_get_key");
457 *length = spider->share->table_name_length;
458 DBUG_RETURN((uchar*) spider->share->table_name);
459 }
460
spider_udf_tbl_mon_list_key(SPIDER_TABLE_MON_LIST * table_mon_list,size_t * length,my_bool not_used)461 uchar *spider_udf_tbl_mon_list_key(
462 SPIDER_TABLE_MON_LIST *table_mon_list,
463 size_t *length,
464 my_bool not_used __attribute__ ((unused))
465 ) {
466 DBUG_ENTER("spider_udf_tbl_mon_list_key");
467 DBUG_PRINT("info",("spider hash key=%s", table_mon_list->key));
468 DBUG_PRINT("info",("spider hash key length=%u", table_mon_list->key_length));
469 *length = table_mon_list->key_length;
470 DBUG_RETURN((uchar*) table_mon_list->key);
471 }
472
spider_allocated_thds_get_key(THD * thd,size_t * length,my_bool not_used)473 uchar *spider_allocated_thds_get_key(
474 THD *thd,
475 size_t *length,
476 my_bool not_used __attribute__ ((unused))
477 ) {
478 DBUG_ENTER("spider_allocated_thds_get_key");
479 *length = sizeof(THD *);
480 DBUG_RETURN((uchar*) thd);
481 }
482
483 #ifdef HAVE_PSI_INTERFACE
init_spider_psi_keys()484 static void init_spider_psi_keys()
485 {
486 DBUG_ENTER("init_spider_psi_keys");
487 if (PSI_server == NULL)
488 DBUG_VOID_RETURN;
489
490 PSI_server->register_mutex("spider", all_spider_mutexes,
491 array_elements(all_spider_mutexes));
492 PSI_server->register_cond("spider", all_spider_conds,
493 array_elements(all_spider_conds));
494 PSI_server->register_thread("spider", all_spider_threads,
495 array_elements(all_spider_threads));
496 DBUG_VOID_RETURN;
497 }
498 #endif
499
spider_get_server(SPIDER_SHARE * share,int link_idx)500 int spider_get_server(
501 SPIDER_SHARE *share,
502 int link_idx
503 ) {
504 MEM_ROOT mem_root;
505 int error_num, length;
506 FOREIGN_SERVER *server, server_buf;
507 DBUG_ENTER("spider_get_server");
508 SPD_INIT_ALLOC_ROOT(&mem_root, 128, 0, MYF(MY_WME));
509
510 if (!(server
511 = get_server_by_name(&mem_root, share->server_names[link_idx],
512 &server_buf)))
513 {
514 error_num = ER_FOREIGN_SERVER_DOESNT_EXIST;
515 goto error;
516 }
517
518 if (!share->tgt_wrappers[link_idx] && server->scheme)
519 {
520 share->tgt_wrappers_lengths[link_idx] = strlen(server->scheme);
521 if (!(share->tgt_wrappers[link_idx] =
522 spider_create_string(server->scheme,
523 share->tgt_wrappers_lengths[link_idx])))
524 {
525 error_num = HA_ERR_OUT_OF_MEM;
526 goto error;
527 }
528 DBUG_PRINT("info",("spider tgt_wrappers=%s",
529 share->tgt_wrappers[link_idx]));
530 }
531
532 if (!share->tgt_hosts[link_idx] && server->host)
533 {
534 share->tgt_hosts_lengths[link_idx] = strlen(server->host);
535 if (!(share->tgt_hosts[link_idx] =
536 spider_create_string(server->host, share->tgt_hosts_lengths[link_idx])))
537 {
538 error_num = HA_ERR_OUT_OF_MEM;
539 goto error;
540 }
541 DBUG_PRINT("info",("spider tgt_hosts=%s", share->tgt_hosts[link_idx]));
542 }
543
544 if (share->tgt_ports[link_idx] == -1)
545 {
546 share->tgt_ports[link_idx] = server->port;
547 DBUG_PRINT("info",("spider tgt_ports=%ld", share->tgt_ports[link_idx]));
548 }
549
550 if (!share->tgt_sockets[link_idx] && server->socket)
551 {
552 share->tgt_sockets_lengths[link_idx] = strlen(server->socket);
553 if (!(share->tgt_sockets[link_idx] =
554 spider_create_string(server->socket,
555 share->tgt_sockets_lengths[link_idx])))
556 {
557 error_num = HA_ERR_OUT_OF_MEM;
558 goto error;
559 }
560 DBUG_PRINT("info",("spider tgt_sockets=%s", share->tgt_sockets[link_idx]));
561 }
562
563 if (!share->tgt_dbs[link_idx] && server->db && (length = strlen(server->db)))
564 {
565 share->tgt_dbs_lengths[link_idx] = length;
566 if (!(share->tgt_dbs[link_idx] =
567 spider_create_string(server->db, length)))
568 {
569 error_num = HA_ERR_OUT_OF_MEM;
570 goto error;
571 }
572 DBUG_PRINT("info",("spider tgt_dbs=%s", share->tgt_dbs[link_idx]));
573 }
574
575 if (!share->tgt_usernames[link_idx] && server->username)
576 {
577 share->tgt_usernames_lengths[link_idx] = strlen(server->username);
578 if (!(share->tgt_usernames[link_idx] =
579 spider_create_string(server->username,
580 share->tgt_usernames_lengths[link_idx])))
581 {
582 error_num = HA_ERR_OUT_OF_MEM;
583 goto error;
584 }
585 DBUG_PRINT("info",("spider tgt_usernames=%s",
586 share->tgt_usernames[link_idx]));
587 }
588
589 if (!share->tgt_passwords[link_idx] && server->password)
590 {
591 share->tgt_passwords_lengths[link_idx] = strlen(server->password);
592 if (!(share->tgt_passwords[link_idx] =
593 spider_create_string(server->password,
594 share->tgt_passwords_lengths[link_idx])))
595 {
596 error_num = HA_ERR_OUT_OF_MEM;
597 goto error;
598 }
599 DBUG_PRINT("info",("spider tgt_passwords=%s",
600 share->tgt_passwords[link_idx]));
601 }
602
603 free_root(&mem_root, MYF(0));
604 DBUG_RETURN(0);
605
606 error:
607 free_root(&mem_root, MYF(0));
608 my_error(error_num, MYF(0), share->server_names[link_idx]);
609 DBUG_RETURN(error_num);
610 }
611
spider_free_share_alloc(SPIDER_SHARE * share)612 int spider_free_share_alloc(
613 SPIDER_SHARE *share
614 ) {
615 int roop_count;
616 DBUG_ENTER("spider_free_share_alloc");
617 for (roop_count = SPIDER_DBTON_SIZE - 1; roop_count >= 0; roop_count--)
618 {
619 if (share->dbton_share[roop_count])
620 {
621 delete share->dbton_share[roop_count];
622 share->dbton_share[roop_count] = NULL;
623 }
624 }
625 if (share->server_names)
626 {
627 for (roop_count = 0; roop_count < (int) share->server_names_length;
628 roop_count++)
629 {
630 if (share->server_names[roop_count])
631 spider_free(spider_current_trx, share->server_names[roop_count],
632 MYF(0));
633 }
634 spider_free(spider_current_trx, share->server_names, MYF(0));
635 }
636 if (share->tgt_table_names)
637 {
638 for (roop_count = 0; roop_count < (int) share->tgt_table_names_length;
639 roop_count++)
640 {
641 if (share->tgt_table_names[roop_count])
642 spider_free(spider_current_trx, share->tgt_table_names[roop_count],
643 MYF(0));
644 }
645 spider_free(spider_current_trx, share->tgt_table_names, MYF(0));
646 }
647 if (share->tgt_dbs)
648 {
649 for (roop_count = 0; roop_count < (int) share->tgt_dbs_length;
650 roop_count++)
651 {
652 if (share->tgt_dbs[roop_count])
653 spider_free(spider_current_trx, share->tgt_dbs[roop_count], MYF(0));
654 }
655 spider_free(spider_current_trx, share->tgt_dbs, MYF(0));
656 }
657 if (share->tgt_hosts)
658 {
659 for (roop_count = 0; roop_count < (int) share->tgt_hosts_length;
660 roop_count++)
661 {
662 if (share->tgt_hosts[roop_count])
663 spider_free(spider_current_trx, share->tgt_hosts[roop_count], MYF(0));
664 }
665 spider_free(spider_current_trx, share->tgt_hosts, MYF(0));
666 }
667 if (share->tgt_usernames)
668 {
669 for (roop_count = 0; roop_count < (int) share->tgt_usernames_length;
670 roop_count++)
671 {
672 if (share->tgt_usernames[roop_count])
673 spider_free(spider_current_trx, share->tgt_usernames[roop_count],
674 MYF(0));
675 }
676 spider_free(spider_current_trx, share->tgt_usernames, MYF(0));
677 }
678 if (share->tgt_passwords)
679 {
680 for (roop_count = 0; roop_count < (int) share->tgt_passwords_length;
681 roop_count++)
682 {
683 if (share->tgt_passwords[roop_count])
684 spider_free(spider_current_trx, share->tgt_passwords[roop_count],
685 MYF(0));
686 }
687 spider_free(spider_current_trx, share->tgt_passwords, MYF(0));
688 }
689 if (share->tgt_sockets)
690 {
691 for (roop_count = 0; roop_count < (int) share->tgt_sockets_length;
692 roop_count++)
693 {
694 if (share->tgt_sockets[roop_count])
695 spider_free(spider_current_trx, share->tgt_sockets[roop_count],
696 MYF(0));
697 }
698 spider_free(spider_current_trx, share->tgt_sockets, MYF(0));
699 }
700 if (share->tgt_wrappers)
701 {
702 for (roop_count = 0; roop_count < (int) share->tgt_wrappers_length;
703 roop_count++)
704 {
705 if (share->tgt_wrappers[roop_count])
706 spider_free(spider_current_trx, share->tgt_wrappers[roop_count],
707 MYF(0));
708 }
709 spider_free(spider_current_trx, share->tgt_wrappers, MYF(0));
710 }
711 if (share->tgt_ssl_cas)
712 {
713 for (roop_count = 0; roop_count < (int) share->tgt_ssl_cas_length;
714 roop_count++)
715 {
716 if (share->tgt_ssl_cas[roop_count])
717 spider_free(spider_current_trx, share->tgt_ssl_cas[roop_count],
718 MYF(0));
719 }
720 spider_free(spider_current_trx, share->tgt_ssl_cas, MYF(0));
721 }
722 if (share->tgt_ssl_capaths)
723 {
724 for (roop_count = 0; roop_count < (int) share->tgt_ssl_capaths_length;
725 roop_count++)
726 {
727 if (share->tgt_ssl_capaths[roop_count])
728 spider_free(spider_current_trx, share->tgt_ssl_capaths[roop_count],
729 MYF(0));
730 }
731 spider_free(spider_current_trx, share->tgt_ssl_capaths, MYF(0));
732 }
733 if (share->tgt_ssl_certs)
734 {
735 for (roop_count = 0; roop_count < (int) share->tgt_ssl_certs_length;
736 roop_count++)
737 {
738 if (share->tgt_ssl_certs[roop_count])
739 spider_free(spider_current_trx, share->tgt_ssl_certs[roop_count],
740 MYF(0));
741 }
742 spider_free(spider_current_trx, share->tgt_ssl_certs, MYF(0));
743 }
744 if (share->tgt_ssl_ciphers)
745 {
746 for (roop_count = 0; roop_count < (int) share->tgt_ssl_ciphers_length;
747 roop_count++)
748 {
749 if (share->tgt_ssl_ciphers[roop_count])
750 spider_free(spider_current_trx, share->tgt_ssl_ciphers[roop_count],
751 MYF(0));
752 }
753 spider_free(spider_current_trx, share->tgt_ssl_ciphers, MYF(0));
754 }
755 if (share->tgt_ssl_keys)
756 {
757 for (roop_count = 0; roop_count < (int) share->tgt_ssl_keys_length;
758 roop_count++)
759 {
760 if (share->tgt_ssl_keys[roop_count])
761 spider_free(spider_current_trx, share->tgt_ssl_keys[roop_count],
762 MYF(0));
763 }
764 spider_free(spider_current_trx, share->tgt_ssl_keys, MYF(0));
765 }
766 if (share->tgt_default_files)
767 {
768 for (roop_count = 0; roop_count < (int) share->tgt_default_files_length;
769 roop_count++)
770 {
771 if (share->tgt_default_files[roop_count])
772 spider_free(spider_current_trx, share->tgt_default_files[roop_count],
773 MYF(0));
774 }
775 spider_free(spider_current_trx, share->tgt_default_files, MYF(0));
776 }
777 if (share->tgt_default_groups)
778 {
779 for (roop_count = 0; roop_count < (int) share->tgt_default_groups_length;
780 roop_count++)
781 {
782 if (share->tgt_default_groups[roop_count])
783 spider_free(spider_current_trx, share->tgt_default_groups[roop_count],
784 MYF(0));
785 }
786 spider_free(spider_current_trx, share->tgt_default_groups, MYF(0));
787 }
788 if (share->tgt_dsns)
789 {
790 for (roop_count = 0; roop_count < (int) share->tgt_dsns_length;
791 roop_count++)
792 {
793 if (share->tgt_dsns[roop_count])
794 spider_free(spider_current_trx, share->tgt_dsns[roop_count],
795 MYF(0));
796 }
797 spider_free(spider_current_trx, share->tgt_dsns, MYF(0));
798 }
799 if (share->tgt_pk_names)
800 {
801 for (roop_count = 0; roop_count < (int) share->tgt_pk_names_length;
802 roop_count++)
803 {
804 if (share->tgt_pk_names[roop_count])
805 spider_free(spider_current_trx, share->tgt_pk_names[roop_count],
806 MYF(0));
807 }
808 spider_free(spider_current_trx, share->tgt_pk_names, MYF(0));
809 }
810 if (share->tgt_sequence_names)
811 {
812 for (roop_count = 0; roop_count < (int) share->tgt_sequence_names_length;
813 roop_count++)
814 {
815 if (share->tgt_sequence_names[roop_count])
816 spider_free(spider_current_trx, share->tgt_sequence_names[roop_count],
817 MYF(0));
818 }
819 spider_free(spider_current_trx, share->tgt_sequence_names, MYF(0));
820 }
821 if (share->static_link_ids)
822 {
823 for (roop_count = 0; roop_count < (int) share->static_link_ids_length;
824 roop_count++)
825 {
826 if (share->static_link_ids[roop_count])
827 spider_free(spider_current_trx, share->static_link_ids[roop_count],
828 MYF(0));
829 }
830 spider_free(spider_current_trx, share->static_link_ids, MYF(0));
831 }
832 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
833 if (share->hs_read_socks)
834 {
835 for (roop_count = 0; roop_count < (int) share->hs_read_socks_length;
836 roop_count++)
837 {
838 if (share->hs_read_socks[roop_count])
839 spider_free(spider_current_trx, share->hs_read_socks[roop_count],
840 MYF(0));
841 }
842 spider_free(spider_current_trx, share->hs_read_socks, MYF(0));
843 }
844 if (share->hs_write_socks)
845 {
846 for (roop_count = 0; roop_count < (int) share->hs_write_socks_length;
847 roop_count++)
848 {
849 if (share->hs_write_socks[roop_count])
850 spider_free(spider_current_trx, share->hs_write_socks[roop_count],
851 MYF(0));
852 }
853 spider_free(spider_current_trx, share->hs_write_socks, MYF(0));
854 }
855 #endif
856 if (share->bka_engine)
857 spider_free(spider_current_trx, share->bka_engine, MYF(0));
858 if (share->conn_keys)
859 spider_free(spider_current_trx, share->conn_keys, MYF(0));
860 if (share->tgt_ports)
861 spider_free(spider_current_trx, share->tgt_ports, MYF(0));
862 if (share->tgt_ssl_vscs)
863 spider_free(spider_current_trx, share->tgt_ssl_vscs, MYF(0));
864 if (share->link_statuses)
865 spider_free(spider_current_trx, share->link_statuses, MYF(0));
866 #ifndef WITHOUT_SPIDER_BG_SEARCH
867 if (share->monitoring_bg_flag)
868 spider_free(spider_current_trx, share->monitoring_bg_flag, MYF(0));
869 if (share->monitoring_bg_kind)
870 spider_free(spider_current_trx, share->monitoring_bg_kind, MYF(0));
871 #endif
872 if (share->monitoring_binlog_pos_at_failing)
873 spider_free(spider_current_trx, share->monitoring_binlog_pos_at_failing, MYF(0));
874 if (share->monitoring_flag)
875 spider_free(spider_current_trx, share->monitoring_flag, MYF(0));
876 if (share->monitoring_kind)
877 spider_free(spider_current_trx, share->monitoring_kind, MYF(0));
878 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
879 if (share->use_hs_reads)
880 spider_free(spider_current_trx, share->use_hs_reads, MYF(0));
881 if (share->use_hs_writes)
882 spider_free(spider_current_trx, share->use_hs_writes, MYF(0));
883 if (share->hs_read_ports)
884 spider_free(spider_current_trx, share->hs_read_ports, MYF(0));
885 if (share->hs_write_ports)
886 spider_free(spider_current_trx, share->hs_write_ports, MYF(0));
887 if (share->hs_write_to_reads)
888 spider_free(spider_current_trx, share->hs_write_to_reads, MYF(0));
889 #endif
890 if (share->use_handlers)
891 spider_free(spider_current_trx, share->use_handlers, MYF(0));
892 if (share->connect_timeouts)
893 spider_free(spider_current_trx, share->connect_timeouts, MYF(0));
894 if (share->net_read_timeouts)
895 spider_free(spider_current_trx, share->net_read_timeouts, MYF(0));
896 if (share->net_write_timeouts)
897 spider_free(spider_current_trx, share->net_write_timeouts, MYF(0));
898 if (share->access_balances)
899 spider_free(spider_current_trx, share->access_balances, MYF(0));
900 if (share->bka_table_name_types)
901 spider_free(spider_current_trx, share->bka_table_name_types, MYF(0));
902 if (share->strict_group_bys)
903 spider_free(spider_current_trx, share->strict_group_bys, MYF(0));
904 #ifndef WITHOUT_SPIDER_BG_SEARCH
905 if (share->monitoring_bg_interval)
906 spider_free(spider_current_trx, share->monitoring_bg_interval, MYF(0));
907 #endif
908 if (share->monitoring_limit)
909 spider_free(spider_current_trx, share->monitoring_limit, MYF(0));
910 if (share->monitoring_sid)
911 spider_free(spider_current_trx, share->monitoring_sid, MYF(0));
912 if (share->alter_table.tmp_server_names)
913 spider_free(spider_current_trx, share->alter_table.tmp_server_names,
914 MYF(0));
915 if (share->key_hint)
916 {
917 delete [] share->key_hint;
918 share->key_hint = NULL;
919 }
920 if (share->wide_share)
921 spider_free_wide_share(share->wide_share);
922 DBUG_RETURN(0);
923 }
924
spider_free_tmp_share_alloc(SPIDER_SHARE * share)925 void spider_free_tmp_share_alloc(
926 SPIDER_SHARE *share
927 ) {
928 DBUG_ENTER("spider_free_tmp_share_alloc");
929 if (share->server_names && share->server_names[0])
930 {
931 spider_free(spider_current_trx, share->server_names[0], MYF(0));
932 share->server_names[0] = NULL;
933 }
934 if (share->tgt_table_names && share->tgt_table_names[0])
935 {
936 spider_free(spider_current_trx, share->tgt_table_names[0], MYF(0));
937 share->tgt_table_names[0] = NULL;
938 }
939 if (share->tgt_dbs && share->tgt_dbs[0])
940 {
941 spider_free(spider_current_trx, share->tgt_dbs[0], MYF(0));
942 share->tgt_dbs[0] = NULL;
943 }
944 if (share->tgt_hosts && share->tgt_hosts[0])
945 {
946 spider_free(spider_current_trx, share->tgt_hosts[0], MYF(0));
947 share->tgt_hosts[0] = NULL;
948 }
949 if (share->tgt_usernames && share->tgt_usernames[0])
950 {
951 spider_free(spider_current_trx, share->tgt_usernames[0], MYF(0));
952 share->tgt_usernames[0] = NULL;
953 }
954 if (share->tgt_passwords && share->tgt_passwords[0])
955 {
956 spider_free(spider_current_trx, share->tgt_passwords[0], MYF(0));
957 share->tgt_passwords[0] = NULL;
958 }
959 if (share->tgt_sockets && share->tgt_sockets[0])
960 {
961 spider_free(spider_current_trx, share->tgt_sockets[0], MYF(0));
962 share->tgt_sockets[0] = NULL;
963 }
964 if (share->tgt_wrappers && share->tgt_wrappers[0])
965 {
966 spider_free(spider_current_trx, share->tgt_wrappers[0], MYF(0));
967 share->tgt_wrappers[0] = NULL;
968 }
969 if (share->tgt_ssl_cas && share->tgt_ssl_cas[0])
970 {
971 spider_free(spider_current_trx, share->tgt_ssl_cas[0], MYF(0));
972 share->tgt_ssl_cas[0] = NULL;
973 }
974 if (share->tgt_ssl_capaths && share->tgt_ssl_capaths[0])
975 {
976 spider_free(spider_current_trx, share->tgt_ssl_capaths[0], MYF(0));
977 share->tgt_ssl_capaths[0] = NULL;
978 }
979 if (share->tgt_ssl_certs && share->tgt_ssl_certs[0])
980 {
981 spider_free(spider_current_trx, share->tgt_ssl_certs[0], MYF(0));
982 share->tgt_ssl_certs[0] = NULL;
983 }
984 if (share->tgt_ssl_ciphers && share->tgt_ssl_ciphers[0])
985 {
986 spider_free(spider_current_trx, share->tgt_ssl_ciphers[0], MYF(0));
987 share->tgt_ssl_ciphers[0] = NULL;
988 }
989 if (share->tgt_ssl_keys && share->tgt_ssl_keys[0])
990 {
991 spider_free(spider_current_trx, share->tgt_ssl_keys[0], MYF(0));
992 share->tgt_ssl_keys[0] = NULL;
993 }
994 if (share->tgt_default_files && share->tgt_default_files[0])
995 {
996 spider_free(spider_current_trx, share->tgt_default_files[0], MYF(0));
997 share->tgt_default_files[0] = NULL;
998 }
999 if (share->tgt_default_groups && share->tgt_default_groups[0])
1000 {
1001 spider_free(spider_current_trx, share->tgt_default_groups[0], MYF(0));
1002 share->tgt_default_groups[0] = NULL;
1003 }
1004 if (share->tgt_dsns && share->tgt_dsns[0])
1005 {
1006 spider_free(spider_current_trx, share->tgt_dsns[0], MYF(0));
1007 share->tgt_dsns[0] = NULL;
1008 }
1009 if (share->tgt_pk_names && share->tgt_pk_names[0])
1010 {
1011 spider_free(spider_current_trx, share->tgt_pk_names[0], MYF(0));
1012 share->tgt_pk_names[0] = NULL;
1013 }
1014 if (share->tgt_sequence_names && share->tgt_sequence_names[0])
1015 {
1016 spider_free(spider_current_trx, share->tgt_sequence_names[0], MYF(0));
1017 share->tgt_sequence_names[0] = NULL;
1018 }
1019 if (share->static_link_ids && share->static_link_ids[0])
1020 {
1021 spider_free(spider_current_trx, share->static_link_ids[0], MYF(0));
1022 share->static_link_ids[0] = NULL;
1023 }
1024 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1025 if (share->hs_read_socks && share->hs_read_socks[0])
1026 {
1027 spider_free(spider_current_trx, share->hs_read_socks[0], MYF(0));
1028 share->hs_read_socks[0] = NULL;
1029 }
1030 if (share->hs_write_socks && share->hs_write_socks[0])
1031 {
1032 spider_free(spider_current_trx, share->hs_write_socks[0], MYF(0));
1033 share->hs_write_socks[0] = NULL;
1034 }
1035 #endif
1036 if (share->bka_engine)
1037 {
1038 spider_free(spider_current_trx, share->bka_engine, MYF(0));
1039 share->bka_engine = NULL;
1040 }
1041 if (share->conn_keys)
1042 {
1043 spider_free(spider_current_trx, share->conn_keys, MYF(0));
1044 share->conn_keys = NULL;
1045 }
1046 if (share->static_key_cardinality)
1047 spider_free(spider_current_trx, share->static_key_cardinality, MYF(0));
1048 if (share->key_hint)
1049 {
1050 delete [] share->key_hint;
1051 share->key_hint = NULL;
1052 }
1053 DBUG_VOID_RETURN;
1054 }
1055
spider_get_string_between_quote(char * ptr,bool alloc,SPIDER_PARAM_STRING_PARSE * param_string_parse)1056 char *spider_get_string_between_quote(
1057 char *ptr,
1058 bool alloc,
1059 SPIDER_PARAM_STRING_PARSE *param_string_parse
1060 ) {
1061 char *start_ptr, *end_ptr, *tmp_ptr, *esc_ptr;
1062 bool find_flg = FALSE;
1063 DBUG_ENTER("spider_get_string_between_quote");
1064
1065 start_ptr = strchr(ptr, '\'');
1066 end_ptr = strchr(ptr, '"');
1067 if (start_ptr && (!end_ptr || start_ptr < end_ptr))
1068 {
1069 tmp_ptr = ++start_ptr;
1070 while (!find_flg)
1071 {
1072 if (!(end_ptr = strchr(tmp_ptr, '\'')))
1073 DBUG_RETURN(NULL);
1074 esc_ptr = tmp_ptr;
1075 while (!find_flg)
1076 {
1077 esc_ptr = strchr(esc_ptr, '\\');
1078 if (!esc_ptr || esc_ptr > end_ptr)
1079 find_flg = TRUE;
1080 else if (esc_ptr == end_ptr - 1)
1081 {
1082 tmp_ptr = end_ptr + 1;
1083 break;
1084 } else {
1085 esc_ptr += 2;
1086 }
1087 }
1088 }
1089 } else if (end_ptr)
1090 {
1091 start_ptr = end_ptr;
1092 tmp_ptr = ++start_ptr;
1093 while (!find_flg)
1094 {
1095 if (!(end_ptr = strchr(tmp_ptr, '"')))
1096 DBUG_RETURN(NULL);
1097 esc_ptr = tmp_ptr;
1098 while (!find_flg)
1099 {
1100 esc_ptr = strchr(esc_ptr, '\\');
1101 if (!esc_ptr || esc_ptr > end_ptr)
1102 find_flg = TRUE;
1103 else if (esc_ptr == end_ptr - 1)
1104 {
1105 tmp_ptr = end_ptr + 1;
1106 break;
1107 } else {
1108 esc_ptr += 2;
1109 }
1110 }
1111 }
1112 } else
1113 DBUG_RETURN(NULL);
1114
1115 *end_ptr = '\0';
1116
1117 if (param_string_parse)
1118 param_string_parse->set_param_value(start_ptr, start_ptr + strlen(start_ptr) + 1);
1119
1120 if (alloc)
1121 {
1122 DBUG_RETURN(
1123 spider_create_string(
1124 start_ptr,
1125 strlen(start_ptr))
1126 );
1127 } else {
1128 DBUG_RETURN(start_ptr);
1129 }
1130 }
1131
spider_create_string_list(char *** string_list,uint ** string_length_list,uint * list_length,char * str,uint length,SPIDER_PARAM_STRING_PARSE * param_string_parse)1132 int spider_create_string_list(
1133 char ***string_list,
1134 uint **string_length_list,
1135 uint *list_length,
1136 char *str,
1137 uint length,
1138 SPIDER_PARAM_STRING_PARSE *param_string_parse
1139 ) {
1140 int roop_count;
1141 char *tmp_ptr, *tmp_ptr2, *tmp_ptr3, *tmp_ptr4, *esc_ptr;
1142 bool find_flg = FALSE;
1143 DBUG_ENTER("spider_create_string_list");
1144
1145 *list_length = 0;
1146 param_string_parse->init_param_value();
1147 if (!str)
1148 {
1149 *string_list = NULL;
1150 DBUG_RETURN(0);
1151 }
1152
1153 tmp_ptr = str;
1154 while (*tmp_ptr == ' ')
1155 tmp_ptr++;
1156 if (*tmp_ptr)
1157 *list_length = 1;
1158 else {
1159 *string_list = NULL;
1160 DBUG_RETURN(0);
1161 }
1162
1163 bool last_esc_flg = FALSE;
1164 while (TRUE)
1165 {
1166 if ((tmp_ptr2 = strchr(tmp_ptr, ' ')))
1167 {
1168 find_flg = FALSE;
1169 last_esc_flg = FALSE;
1170 esc_ptr = tmp_ptr;
1171 while (!find_flg)
1172 {
1173 esc_ptr = strchr(esc_ptr, '\\');
1174 if (!esc_ptr || esc_ptr > tmp_ptr2)
1175 {
1176 find_flg = TRUE;
1177 }
1178 else if (esc_ptr == tmp_ptr2 - 1)
1179 {
1180 last_esc_flg = TRUE;
1181 tmp_ptr = tmp_ptr2 + 1;
1182 break;
1183 } else {
1184 last_esc_flg = TRUE;
1185 esc_ptr += 2;
1186 }
1187 }
1188 if (find_flg)
1189 {
1190 (*list_length)++;
1191 tmp_ptr = tmp_ptr2 + 1;
1192 while (*tmp_ptr == ' ')
1193 tmp_ptr++;
1194 }
1195 } else
1196 break;
1197 }
1198
1199 if (!(*string_list = (char**)
1200 spider_bulk_malloc(spider_current_trx, 37, MYF(MY_WME | MY_ZEROFILL),
1201 string_list, (uint) (sizeof(char*) * (*list_length)),
1202 string_length_list, (uint) (sizeof(int) * (*list_length)),
1203 NullS))
1204 ) {
1205 my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
1206 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
1207 }
1208
1209 tmp_ptr = str;
1210 while (*tmp_ptr == ' ')
1211 {
1212 *tmp_ptr = '\0';
1213 tmp_ptr++;
1214 }
1215 tmp_ptr3 = tmp_ptr;
1216
1217 for (roop_count = 0; roop_count < (int) *list_length - 1; roop_count++)
1218 {
1219 bool esc_flg = FALSE;
1220 find_flg = FALSE;
1221 while (TRUE)
1222 {
1223 tmp_ptr2 = strchr(tmp_ptr, ' ');
1224
1225 esc_ptr = tmp_ptr;
1226 while (!find_flg)
1227 {
1228 esc_ptr = strchr(esc_ptr, '\\');
1229 if (!esc_ptr || esc_ptr > tmp_ptr2)
1230 {
1231 find_flg = TRUE;
1232 }
1233 else if (esc_ptr == tmp_ptr2 - 1)
1234 {
1235 esc_flg = TRUE;
1236 tmp_ptr = tmp_ptr2 + 1;
1237 break;
1238 } else {
1239 esc_flg = TRUE;
1240 esc_ptr += 2;
1241 }
1242 }
1243 if (find_flg)
1244 break;
1245 }
1246 tmp_ptr = tmp_ptr2;
1247
1248 while (*tmp_ptr == ' ')
1249 {
1250 *tmp_ptr = '\0';
1251 tmp_ptr++;
1252 }
1253
1254 (*string_length_list)[roop_count] = strlen(tmp_ptr3);
1255 if (!((*string_list)[roop_count] = spider_create_string(
1256 tmp_ptr3, (*string_length_list)[roop_count]))
1257 ) {
1258 my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
1259 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
1260 }
1261
1262 if (esc_flg)
1263 {
1264 esc_ptr = (*string_list)[roop_count];
1265 while (TRUE)
1266 {
1267 esc_ptr = strchr(esc_ptr, '\\');
1268 if (!esc_ptr)
1269 break;
1270 switch(*(esc_ptr + 1))
1271 {
1272 case 'b':
1273 *esc_ptr = '\b';
1274 break;
1275 case 'n':
1276 *esc_ptr = '\n';
1277 break;
1278 case 'r':
1279 *esc_ptr = '\r';
1280 break;
1281 case 't':
1282 *esc_ptr = '\t';
1283 break;
1284 default:
1285 *esc_ptr = *(esc_ptr + 1);
1286 break;
1287 }
1288 esc_ptr++;
1289 tmp_ptr4 = esc_ptr;
1290 do
1291 {
1292 *tmp_ptr4 = *(tmp_ptr4 + 1);
1293 tmp_ptr4++;
1294 } while (*tmp_ptr4);
1295 (*string_length_list)[roop_count] -= 1;
1296 }
1297 }
1298 DBUG_PRINT("info",("spider string_list[%d]=%s", roop_count,
1299 (*string_list)[roop_count]));
1300 tmp_ptr3 = tmp_ptr;
1301 }
1302 (*string_length_list)[roop_count] = strlen(tmp_ptr3);
1303 if (!((*string_list)[roop_count] = spider_create_string(
1304 tmp_ptr3, (*string_length_list)[roop_count]))
1305 ) {
1306 my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
1307 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
1308 }
1309 if (last_esc_flg)
1310 {
1311 esc_ptr = (*string_list)[roop_count];
1312 while (TRUE)
1313 {
1314 esc_ptr = strchr(esc_ptr, '\\');
1315 if (!esc_ptr)
1316 break;
1317 switch(*(esc_ptr + 1))
1318 {
1319 case 'b':
1320 *esc_ptr = '\b';
1321 break;
1322 case 'n':
1323 *esc_ptr = '\n';
1324 break;
1325 case 'r':
1326 *esc_ptr = '\r';
1327 break;
1328 case 't':
1329 *esc_ptr = '\t';
1330 break;
1331 default:
1332 *esc_ptr = *(esc_ptr + 1);
1333 break;
1334 }
1335 esc_ptr++;
1336 tmp_ptr4 = esc_ptr;
1337 do
1338 {
1339 *tmp_ptr4 = *(tmp_ptr4 + 1);
1340 tmp_ptr4++;
1341 } while (*tmp_ptr4);
1342 (*string_length_list)[roop_count] -= 1;
1343 }
1344 }
1345
1346 param_string_parse->set_param_value(tmp_ptr3,
1347 tmp_ptr3 + strlen(tmp_ptr3) + 1);
1348
1349 DBUG_PRINT("info",("spider string_list[%d]=%s", roop_count,
1350 (*string_list)[roop_count]));
1351
1352 DBUG_RETURN(0);
1353 }
1354
spider_create_long_list(long ** long_list,uint * list_length,char * str,uint length,long min_val,long max_val,SPIDER_PARAM_STRING_PARSE * param_string_parse)1355 int spider_create_long_list(
1356 long **long_list,
1357 uint *list_length,
1358 char *str,
1359 uint length,
1360 long min_val,
1361 long max_val,
1362 SPIDER_PARAM_STRING_PARSE *param_string_parse
1363 ) {
1364 int roop_count;
1365 char *tmp_ptr;
1366 DBUG_ENTER("spider_create_long_list");
1367
1368 *list_length = 0;
1369 param_string_parse->init_param_value();
1370 if (!str)
1371 {
1372 *long_list = NULL;
1373 DBUG_RETURN(0);
1374 }
1375
1376 tmp_ptr = str;
1377 while (*tmp_ptr == ' ')
1378 tmp_ptr++;
1379 if (*tmp_ptr)
1380 *list_length = 1;
1381 else {
1382 *long_list = NULL;
1383 DBUG_RETURN(0);
1384 }
1385
1386 while (TRUE)
1387 {
1388 if ((tmp_ptr = strchr(tmp_ptr, ' ')))
1389 {
1390 (*list_length)++;
1391 tmp_ptr = tmp_ptr + 1;
1392 while (*tmp_ptr == ' ')
1393 tmp_ptr++;
1394 } else
1395 break;
1396 }
1397
1398 if (!(*long_list = (long*)
1399 spider_bulk_malloc(spider_current_trx, 38, MYF(MY_WME | MY_ZEROFILL),
1400 long_list, (uint) (sizeof(long) * (*list_length)),
1401 NullS))
1402 ) {
1403 my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
1404 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
1405 }
1406
1407 tmp_ptr = str;
1408 for (roop_count = 0; roop_count < (int) *list_length; roop_count++)
1409 {
1410 if (roop_count != 0)
1411 tmp_ptr = strchr(tmp_ptr, ' ');
1412
1413 while (*tmp_ptr == ' ')
1414 {
1415 *tmp_ptr = '\0';
1416 tmp_ptr++;
1417 }
1418 (*long_list)[roop_count] = atol(tmp_ptr);
1419 if ((*long_list)[roop_count] < min_val)
1420 (*long_list)[roop_count] = min_val;
1421 else if ((*long_list)[roop_count] > max_val)
1422 (*long_list)[roop_count] = max_val;
1423 }
1424
1425 param_string_parse->set_param_value(tmp_ptr,
1426 tmp_ptr + strlen(tmp_ptr) + 1);
1427
1428 #ifndef DBUG_OFF
1429 for (roop_count = 0; roop_count < (int) *list_length; roop_count++)
1430 {
1431 DBUG_PRINT("info",("spider long_list[%d]=%ld", roop_count,
1432 (*long_list)[roop_count]));
1433 }
1434 #endif
1435
1436 DBUG_RETURN(0);
1437 }
1438
spider_create_longlong_list(longlong ** longlong_list,uint * list_length,char * str,uint length,longlong min_val,longlong max_val,SPIDER_PARAM_STRING_PARSE * param_string_parse)1439 int spider_create_longlong_list(
1440 longlong **longlong_list,
1441 uint *list_length,
1442 char *str,
1443 uint length,
1444 longlong min_val,
1445 longlong max_val,
1446 SPIDER_PARAM_STRING_PARSE *param_string_parse
1447 ) {
1448 int error_num, roop_count;
1449 char *tmp_ptr;
1450 DBUG_ENTER("spider_create_longlong_list");
1451
1452 *list_length = 0;
1453 param_string_parse->init_param_value();
1454 if (!str)
1455 {
1456 *longlong_list = NULL;
1457 DBUG_RETURN(0);
1458 }
1459
1460 tmp_ptr = str;
1461 while (*tmp_ptr == ' ')
1462 tmp_ptr++;
1463 if (*tmp_ptr)
1464 *list_length = 1;
1465 else {
1466 *longlong_list = NULL;
1467 DBUG_RETURN(0);
1468 }
1469
1470 while (TRUE)
1471 {
1472 if ((tmp_ptr = strchr(tmp_ptr, ' ')))
1473 {
1474 (*list_length)++;
1475 tmp_ptr = tmp_ptr + 1;
1476 while (*tmp_ptr == ' ')
1477 tmp_ptr++;
1478 } else
1479 break;
1480 }
1481
1482 if (!(*longlong_list = (longlong *)
1483 spider_bulk_malloc(spider_current_trx, 39, MYF(MY_WME | MY_ZEROFILL),
1484 longlong_list, (uint) (sizeof(longlong) * (*list_length)),
1485 NullS))
1486 ) {
1487 my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
1488 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
1489 }
1490
1491 tmp_ptr = str;
1492 for (roop_count = 0; roop_count < (int) *list_length; roop_count++)
1493 {
1494 if (roop_count != 0)
1495 tmp_ptr = strchr(tmp_ptr, ' ');
1496
1497 while (*tmp_ptr == ' ')
1498 {
1499 *tmp_ptr = '\0';
1500 tmp_ptr++;
1501 }
1502 (*longlong_list)[roop_count] = my_strtoll10(tmp_ptr, (char**) NULL,
1503 &error_num);
1504 if ((*longlong_list)[roop_count] < min_val)
1505 (*longlong_list)[roop_count] = min_val;
1506 else if ((*longlong_list)[roop_count] > max_val)
1507 (*longlong_list)[roop_count] = max_val;
1508 }
1509
1510 param_string_parse->set_param_value(tmp_ptr,
1511 tmp_ptr + strlen(tmp_ptr) + 1);
1512
1513 #ifndef DBUG_OFF
1514 for (roop_count = 0; roop_count < (int) *list_length; roop_count++)
1515 {
1516 DBUG_PRINT("info",("spider longlong_list[%d]=%lld", roop_count,
1517 (*longlong_list)[roop_count]));
1518 }
1519 #endif
1520
1521 DBUG_RETURN(0);
1522 }
1523
spider_increase_string_list(char *** string_list,uint ** string_length_list,uint * list_length,uint * list_charlen,uint link_count)1524 int spider_increase_string_list(
1525 char ***string_list,
1526 uint **string_length_list,
1527 uint *list_length,
1528 uint *list_charlen,
1529 uint link_count
1530 ) {
1531 int roop_count;
1532 char **tmp_str_list, *tmp_str;
1533 uint *tmp_length_list, tmp_length;
1534 DBUG_ENTER("spider_increase_string_list");
1535 if (*list_length == link_count)
1536 DBUG_RETURN(0);
1537 if (*list_length > 1)
1538 {
1539 my_printf_error(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM,
1540 ER_SPIDER_DIFFERENT_LINK_COUNT_STR, MYF(0));
1541 DBUG_RETURN(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM);
1542 }
1543
1544 if (*string_list)
1545 {
1546 tmp_str = (*string_list)[0];
1547 tmp_length = (*string_length_list)[0];
1548 } else {
1549 tmp_str = NULL;
1550 tmp_length = 0;
1551 }
1552
1553 if (!(tmp_str_list = (char**)
1554 spider_bulk_malloc(spider_current_trx, 40, MYF(MY_WME | MY_ZEROFILL),
1555 &tmp_str_list, (uint) (sizeof(char*) * link_count),
1556 &tmp_length_list, (uint) (sizeof(uint) * link_count),
1557 NullS))
1558 ) {
1559 my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
1560 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
1561 }
1562
1563 for (roop_count = 0; roop_count < (int) link_count; roop_count++)
1564 {
1565 tmp_length_list[roop_count] = tmp_length;
1566 if (tmp_str)
1567 {
1568 if (!(tmp_str_list[roop_count] = spider_create_string(
1569 tmp_str, tmp_length))
1570 )
1571 goto error;
1572 DBUG_PRINT("info",("spider string_list[%d]=%s", roop_count,
1573 tmp_str_list[roop_count]));
1574 } else
1575 tmp_str_list[roop_count] = NULL;
1576 }
1577 if (*string_list)
1578 {
1579 if ((*string_list)[0])
1580 spider_free(spider_current_trx, (*string_list)[0], MYF(0));
1581 spider_free(spider_current_trx, *string_list, MYF(0));
1582 }
1583 *list_charlen = (tmp_length + 1) * link_count - 1;
1584 *list_length = link_count;
1585 *string_list = tmp_str_list;
1586 *string_length_list = tmp_length_list;
1587
1588 DBUG_RETURN(0);
1589
1590 error:
1591 for (roop_count = 0; roop_count < (int) link_count; roop_count++)
1592 {
1593 if (tmp_str_list[roop_count])
1594 spider_free(spider_current_trx, tmp_str_list[roop_count], MYF(0));
1595 }
1596 if (tmp_str_list)
1597 spider_free(spider_current_trx, tmp_str_list, MYF(0));
1598 my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
1599 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
1600 }
1601
spider_increase_null_string_list(char *** string_list,uint ** string_length_list,uint * list_length,uint * list_charlen,uint link_count)1602 int spider_increase_null_string_list(
1603 char ***string_list,
1604 uint **string_length_list,
1605 uint *list_length,
1606 uint *list_charlen,
1607 uint link_count
1608 ) {
1609 int roop_count;
1610 char **tmp_str_list;
1611 uint *tmp_length_list;
1612 DBUG_ENTER("spider_increase_null_string_list");
1613 if (*list_length == link_count)
1614 DBUG_RETURN(0);
1615
1616 if (!(tmp_str_list = (char**)
1617 spider_bulk_malloc(spider_current_trx, 247, MYF(MY_WME | MY_ZEROFILL),
1618 &tmp_str_list, (uint) (sizeof(char*) * link_count),
1619 &tmp_length_list, (uint) (sizeof(uint) * link_count),
1620 NullS))
1621 ) {
1622 my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
1623 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
1624 }
1625
1626 for (roop_count = 0; roop_count < (int) *list_length; roop_count++)
1627 {
1628 tmp_str_list[roop_count] = (*string_list)[roop_count];
1629 tmp_length_list[roop_count] = (*string_length_list)[roop_count];
1630 }
1631 if (*string_list)
1632 {
1633 spider_free(spider_current_trx, *string_list, MYF(0));
1634 }
1635 *list_length = link_count;
1636 *string_list = tmp_str_list;
1637 *string_length_list = tmp_length_list;
1638 #ifndef DBUG_OFF
1639 DBUG_PRINT("info",("spider list_length=%u", *list_length));
1640 for (roop_count = 0; roop_count < (int) *list_length; roop_count++)
1641 {
1642 DBUG_PRINT("info",("spider string_list[%d]=%s", roop_count,
1643 (*string_list)[roop_count] ? (*string_list)[roop_count] : "NULL"));
1644 DBUG_PRINT("info",("spider string_length_list[%d]=%u", roop_count,
1645 (*string_length_list)[roop_count]));
1646 }
1647 #endif
1648
1649 DBUG_RETURN(0);
1650 }
1651
spider_increase_long_list(long ** long_list,uint * list_length,uint link_count)1652 int spider_increase_long_list(
1653 long **long_list,
1654 uint *list_length,
1655 uint link_count
1656 ) {
1657 int roop_count;
1658 long *tmp_long_list, tmp_long;
1659 DBUG_ENTER("spider_increase_long_list");
1660 if (*list_length == link_count)
1661 DBUG_RETURN(0);
1662 if (*list_length > 1)
1663 {
1664 my_printf_error(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM,
1665 ER_SPIDER_DIFFERENT_LINK_COUNT_STR, MYF(0));
1666 DBUG_RETURN(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM);
1667 }
1668
1669 if (*long_list)
1670 tmp_long = (*long_list)[0];
1671 else
1672 tmp_long = -1;
1673
1674 if (!(tmp_long_list = (long*)
1675 spider_bulk_malloc(spider_current_trx, 41, MYF(MY_WME | MY_ZEROFILL),
1676 &tmp_long_list, (uint) (sizeof(long) * link_count),
1677 NullS))
1678 ) {
1679 my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
1680 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
1681 }
1682
1683 for (roop_count = 0; roop_count < (int) link_count; roop_count++)
1684 {
1685 tmp_long_list[roop_count] = tmp_long;
1686 DBUG_PRINT("info",("spider long_list[%d]=%ld", roop_count,
1687 tmp_long));
1688 }
1689 if (*long_list)
1690 spider_free(spider_current_trx, *long_list, MYF(0));
1691 *list_length = link_count;
1692 *long_list = tmp_long_list;
1693
1694 DBUG_RETURN(0);
1695 }
1696
spider_increase_longlong_list(longlong ** longlong_list,uint * list_length,uint link_count)1697 int spider_increase_longlong_list(
1698 longlong **longlong_list,
1699 uint *list_length,
1700 uint link_count
1701 ) {
1702 int roop_count;
1703 longlong *tmp_longlong_list, tmp_longlong;
1704 DBUG_ENTER("spider_increase_longlong_list");
1705 if (*list_length == link_count)
1706 DBUG_RETURN(0);
1707 if (*list_length > 1)
1708 {
1709 my_printf_error(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM,
1710 ER_SPIDER_DIFFERENT_LINK_COUNT_STR, MYF(0));
1711 DBUG_RETURN(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM);
1712 }
1713
1714 if (*longlong_list)
1715 tmp_longlong = (*longlong_list)[0];
1716 else
1717 tmp_longlong = -1;
1718
1719 if (!(tmp_longlong_list = (longlong*)
1720 spider_bulk_malloc(spider_current_trx, 42, MYF(MY_WME | MY_ZEROFILL),
1721 &tmp_longlong_list, (uint) (sizeof(longlong) * link_count),
1722 NullS))
1723 ) {
1724 my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
1725 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
1726 }
1727
1728 for (roop_count = 0; roop_count < (int) link_count; roop_count++)
1729 {
1730 tmp_longlong_list[roop_count] = tmp_longlong;
1731 DBUG_PRINT("info",("spider longlong_list[%d]=%lld", roop_count,
1732 tmp_longlong));
1733 }
1734 if (*longlong_list)
1735 spider_free(spider_current_trx, *longlong_list, MYF(0));
1736 *list_length = link_count;
1737 *longlong_list = tmp_longlong_list;
1738
1739 DBUG_RETURN(0);
1740 }
1741
spider_set_ll_value(longlong * value,char * str)1742 static int spider_set_ll_value(
1743 longlong *value,
1744 char *str
1745 ) {
1746 int error_num = 0;
1747 DBUG_ENTER("spider_set_ll_value");
1748 *value = my_strtoll10(str, (char**) NULL, &error_num);
1749 DBUG_RETURN(error_num);
1750 }
1751
1752 /**
1753 Print a parameter string error message.
1754
1755 @return Error code.
1756 */
1757
print_param_error()1758 int st_spider_param_string_parse::print_param_error()
1759 {
1760 if (start_title_ptr)
1761 {
1762 /* Restore the input delimiter characters */
1763 restore_delims();
1764
1765 /* Print the error message */
1766 switch (error_num)
1767 {
1768 case ER_SPIDER_INVALID_UDF_PARAM_NUM:
1769 my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR,
1770 MYF(0), start_title_ptr);
1771 break;
1772 case ER_SPIDER_INVALID_CONNECT_INFO_NUM:
1773 default:
1774 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
1775 MYF(0), start_title_ptr);
1776 }
1777
1778 return error_num;
1779 }
1780 else
1781 return 0;
1782 }
1783
1784 #define SPIDER_PARAM_STR_LEN(name) name ## _length
1785 #define SPIDER_PARAM_STR(title_name, param_name) \
1786 if (!strncasecmp(tmp_ptr, title_name, title_length)) \
1787 { \
1788 DBUG_PRINT("info",("spider " title_name " start")); \
1789 if (!share->param_name) \
1790 { \
1791 if ((share->param_name = spider_get_string_between_quote( \
1792 start_ptr, TRUE, &connect_string_parse))) \
1793 share->SPIDER_PARAM_STR_LEN(param_name) = strlen(share->param_name); \
1794 else { \
1795 error_num = connect_string_parse.print_param_error(); \
1796 goto error; \
1797 } \
1798 DBUG_PRINT("info",("spider " title_name "=%s", share->param_name)); \
1799 } \
1800 break; \
1801 }
1802 #define SPIDER_PARAM_STR_LENS(name) name ## _lengths
1803 #define SPIDER_PARAM_STR_CHARLEN(name) name ## _charlen
1804 #define SPIDER_PARAM_STR_LIST(title_name, param_name) \
1805 if (!strncasecmp(tmp_ptr, title_name, title_length)) \
1806 { \
1807 DBUG_PRINT("info",("spider " title_name " start")); \
1808 if (!share->param_name) \
1809 { \
1810 if ((tmp_ptr2 = spider_get_string_between_quote( \
1811 start_ptr, FALSE))) \
1812 { \
1813 share->SPIDER_PARAM_STR_CHARLEN(param_name) = strlen(tmp_ptr2); \
1814 if ((error_num = spider_create_string_list( \
1815 &share->param_name, \
1816 &share->SPIDER_PARAM_STR_LENS(param_name), \
1817 &share->SPIDER_PARAM_STR_LEN(param_name), \
1818 tmp_ptr2, \
1819 share->SPIDER_PARAM_STR_CHARLEN(param_name), \
1820 &connect_string_parse))) \
1821 goto error; \
1822 } else { \
1823 error_num = connect_string_parse.print_param_error(); \
1824 goto error; \
1825 } \
1826 } \
1827 break; \
1828 }
1829 #define SPIDER_PARAM_HINT(title_name, param_name, check_length, max_size, append_method) \
1830 if (!strncasecmp(tmp_ptr, title_name, check_length)) \
1831 { \
1832 DBUG_PRINT("info",("spider " title_name " start")); \
1833 DBUG_PRINT("info",("spider max_size=%d", max_size)); \
1834 int hint_num = atoi(tmp_ptr + check_length); \
1835 DBUG_PRINT("info",("spider hint_num=%d", hint_num)); \
1836 DBUG_PRINT("info",("spider share->param_name=%p", share->param_name)); \
1837 if (share->param_name) \
1838 { \
1839 if (hint_num < 0 || hint_num >= max_size) \
1840 { \
1841 error_num = connect_string_parse.print_param_error(); \
1842 goto error; \
1843 } else if (share->param_name[hint_num].length() > 0) \
1844 break; \
1845 char *hint_str = spider_get_string_between_quote(start_ptr, FALSE); \
1846 if ((error_num = \
1847 append_method(&share->param_name[hint_num], hint_str))) \
1848 goto error; \
1849 DBUG_PRINT("info",("spider " title_name "[%d]=%s", hint_num, \
1850 share->param_name[hint_num].ptr())); \
1851 } else { \
1852 error_num = connect_string_parse.print_param_error(); \
1853 goto error; \
1854 } \
1855 break; \
1856 }
1857 #define SPIDER_PARAM_NUMHINT(title_name, param_name, check_length, max_size, append_method) \
1858 if (!strncasecmp(tmp_ptr, title_name, check_length)) \
1859 { \
1860 DBUG_PRINT("info",("spider " title_name " start")); \
1861 DBUG_PRINT("info",("spider max_size=%d", max_size)); \
1862 int hint_num = atoi(tmp_ptr + check_length); \
1863 DBUG_PRINT("info",("spider hint_num=%d", hint_num)); \
1864 DBUG_PRINT("info",("spider share->param_name=%p", share->param_name)); \
1865 if (share->param_name) \
1866 { \
1867 if (hint_num < 0 || hint_num >= max_size) \
1868 { \
1869 error_num = connect_string_parse.print_param_error(); \
1870 goto error; \
1871 } else if (share->param_name[hint_num] != -1) \
1872 break; \
1873 char *hint_str = spider_get_string_between_quote(start_ptr, FALSE); \
1874 if ((error_num = \
1875 append_method(&share->param_name[hint_num], hint_str))) \
1876 goto error; \
1877 DBUG_PRINT("info",("spider " title_name "[%d]=%lld", hint_num, \
1878 share->param_name[hint_num])); \
1879 } else { \
1880 error_num = connect_string_parse.print_param_error(); \
1881 goto error; \
1882 } \
1883 break; \
1884 }
1885 #define SPIDER_PARAM_LONG_LEN(name) name ## _length
1886 #define SPIDER_PARAM_LONG_LIST_WITH_MAX(title_name, param_name, \
1887 min_val, max_val) \
1888 if (!strncasecmp(tmp_ptr, title_name, title_length)) \
1889 { \
1890 DBUG_PRINT("info",("spider " title_name " start")); \
1891 if (!share->param_name) \
1892 { \
1893 if ((tmp_ptr2 = spider_get_string_between_quote( \
1894 start_ptr, FALSE))) \
1895 { \
1896 if ((error_num = spider_create_long_list( \
1897 &share->param_name, \
1898 &share->SPIDER_PARAM_LONG_LEN(param_name), \
1899 tmp_ptr2, \
1900 strlen(tmp_ptr2), \
1901 min_val, max_val, \
1902 &connect_string_parse))) \
1903 goto error; \
1904 } else { \
1905 error_num = connect_string_parse.print_param_error(); \
1906 goto error; \
1907 } \
1908 } \
1909 break; \
1910 }
1911 #define SPIDER_PARAM_LONGLONG_LEN(name) name ## _length
1912 #define SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(title_name, param_name, \
1913 min_val, max_val) \
1914 if (!strncasecmp(tmp_ptr, title_name, title_length)) \
1915 { \
1916 DBUG_PRINT("info",("spider " title_name " start")); \
1917 if (!share->param_name) \
1918 { \
1919 if ((tmp_ptr2 = spider_get_string_between_quote( \
1920 start_ptr, FALSE))) \
1921 { \
1922 if ((error_num = spider_create_longlong_list( \
1923 &share->param_name, \
1924 &share->SPIDER_PARAM_LONGLONG_LEN(param_name), \
1925 tmp_ptr2, \
1926 strlen(tmp_ptr2), \
1927 min_val, max_val, \
1928 &connect_string_parse))) \
1929 goto error; \
1930 } else { \
1931 error_num = connect_string_parse.print_param_error(); \
1932 goto error; \
1933 } \
1934 } \
1935 break; \
1936 }
1937 #define SPIDER_PARAM_INT_WITH_MAX(title_name, param_name, min_val, max_val) \
1938 if (!strncasecmp(tmp_ptr, title_name, title_length)) \
1939 { \
1940 DBUG_PRINT("info",("spider " title_name " start")); \
1941 if (share->param_name == -1) \
1942 { \
1943 if ((tmp_ptr2 = spider_get_string_between_quote( \
1944 start_ptr, FALSE))) \
1945 { \
1946 share->param_name = atoi(tmp_ptr2); \
1947 if (share->param_name < min_val) \
1948 share->param_name = min_val; \
1949 else if (share->param_name > max_val) \
1950 share->param_name = max_val; \
1951 connect_string_parse.set_param_value(tmp_ptr2, \
1952 tmp_ptr2 + \
1953 strlen(tmp_ptr2) + 1); \
1954 } else { \
1955 error_num = connect_string_parse.print_param_error(); \
1956 goto error; \
1957 } \
1958 DBUG_PRINT("info",("spider " title_name "=%d", share->param_name)); \
1959 } \
1960 break; \
1961 }
1962 #define SPIDER_PARAM_INT(title_name, param_name, min_val) \
1963 if (!strncasecmp(tmp_ptr, title_name, title_length)) \
1964 { \
1965 DBUG_PRINT("info",("spider " title_name " start")); \
1966 if (share->param_name == -1) \
1967 { \
1968 if ((tmp_ptr2 = spider_get_string_between_quote( \
1969 start_ptr, FALSE))) \
1970 { \
1971 share->param_name = atoi(tmp_ptr2); \
1972 if (share->param_name < min_val) \
1973 share->param_name = min_val; \
1974 connect_string_parse.set_param_value(tmp_ptr2, \
1975 tmp_ptr2 + \
1976 strlen(tmp_ptr2) + 1); \
1977 } else { \
1978 error_num = connect_string_parse.print_param_error(); \
1979 goto error; \
1980 } \
1981 DBUG_PRINT("info",("spider " title_name "=%d", share->param_name)); \
1982 } \
1983 break; \
1984 }
1985 #define SPIDER_PARAM_DOUBLE(title_name, param_name, min_val) \
1986 if (!strncasecmp(tmp_ptr, title_name, title_length)) \
1987 { \
1988 DBUG_PRINT("info",("spider " title_name " start")); \
1989 if (share->param_name == -1) \
1990 { \
1991 if ((tmp_ptr2 = spider_get_string_between_quote( \
1992 start_ptr, FALSE))) \
1993 { \
1994 share->param_name = my_atof(tmp_ptr2); \
1995 if (share->param_name < min_val) \
1996 share->param_name = min_val; \
1997 connect_string_parse.set_param_value(tmp_ptr2, \
1998 tmp_ptr2 + \
1999 strlen(tmp_ptr2) + 1); \
2000 } else { \
2001 error_num = connect_string_parse.print_param_error(); \
2002 goto error; \
2003 } \
2004 DBUG_PRINT("info",("spider " title_name "=%f", share->param_name)); \
2005 } \
2006 break; \
2007 }
2008 #define SPIDER_PARAM_LONGLONG(title_name, param_name, min_val) \
2009 if (!strncasecmp(tmp_ptr, title_name, title_length)) \
2010 { \
2011 DBUG_PRINT("info",("spider " title_name " start")); \
2012 if (share->param_name == -1) \
2013 { \
2014 if ((tmp_ptr2 = spider_get_string_between_quote( \
2015 start_ptr, FALSE))) \
2016 { \
2017 share->param_name = my_strtoll10(tmp_ptr2, (char**) NULL, &error_num); \
2018 if (share->param_name < min_val) \
2019 share->param_name = min_val; \
2020 connect_string_parse.set_param_value(tmp_ptr2, \
2021 tmp_ptr2 + \
2022 strlen(tmp_ptr2) + 1); \
2023 } else { \
2024 error_num = connect_string_parse.print_param_error(); \
2025 goto error; \
2026 } \
2027 DBUG_PRINT("info",("spider " title_name "=%lld", share->param_name)); \
2028 } \
2029 break; \
2030 }
2031
spider_parse_connect_info(SPIDER_SHARE * share,TABLE_SHARE * table_share,partition_info * part_info,uint create_table)2032 int spider_parse_connect_info(
2033 SPIDER_SHARE *share,
2034 TABLE_SHARE *table_share,
2035 #ifdef WITH_PARTITION_STORAGE_ENGINE
2036 partition_info *part_info,
2037 #endif
2038 uint create_table
2039 ) {
2040 int error_num = 0;
2041 char *connect_string = NULL;
2042 char *sprit_ptr;
2043 char *tmp_ptr, *tmp_ptr2, *start_ptr;
2044 int roop_count;
2045 int title_length;
2046 SPIDER_PARAM_STRING_PARSE connect_string_parse;
2047 SPIDER_ALTER_TABLE *share_alter;
2048 #ifdef WITH_PARTITION_STORAGE_ENGINE
2049 partition_element *part_elem;
2050 partition_element *sub_elem;
2051 #endif
2052 DBUG_ENTER("spider_parse_connect_info");
2053 #ifdef WITH_PARTITION_STORAGE_ENGINE
2054 #if MYSQL_VERSION_ID < 50500
2055 DBUG_PRINT("info",("spider partition_info=%s", table_share->partition_info));
2056 #else
2057 DBUG_PRINT("info",("spider partition_info=%s",
2058 table_share->partition_info_str));
2059 #endif
2060 DBUG_PRINT("info",("spider part_info=%p", part_info));
2061 #endif
2062 DBUG_PRINT("info",("spider s->db=%s", table_share->db.str));
2063 DBUG_PRINT("info",("spider s->table_name=%s", table_share->table_name.str));
2064 DBUG_PRINT("info",("spider s->path=%s", table_share->path.str));
2065 DBUG_PRINT("info",
2066 ("spider s->normalized_path=%s", table_share->normalized_path.str));
2067 #ifdef WITH_PARTITION_STORAGE_ENGINE
2068 spider_get_partition_info(share->table_name, share->table_name_length,
2069 table_share, part_info, &part_elem, &sub_elem);
2070 #endif
2071 #ifndef WITHOUT_SPIDER_BG_SEARCH
2072 share->sts_bg_mode = -1;
2073 #endif
2074 share->sts_interval = -1;
2075 share->sts_mode = -1;
2076 #ifdef WITH_PARTITION_STORAGE_ENGINE
2077 share->sts_sync = -1;
2078 #endif
2079 share->store_last_sts = -1;
2080 share->load_sts_at_startup = -1;
2081 #ifndef WITHOUT_SPIDER_BG_SEARCH
2082 share->crd_bg_mode = -1;
2083 #endif
2084 share->crd_interval = -1;
2085 share->crd_mode = -1;
2086 #ifdef WITH_PARTITION_STORAGE_ENGINE
2087 share->crd_sync = -1;
2088 #endif
2089 share->store_last_crd = -1;
2090 share->load_crd_at_startup = -1;
2091 share->crd_type = -1;
2092 share->crd_weight = -1;
2093 share->internal_offset = -1;
2094 share->internal_limit = -1;
2095 share->split_read = -1;
2096 share->semi_split_read = -1;
2097 share->semi_split_read_limit = -1;
2098 share->init_sql_alloc_size = -1;
2099 share->reset_sql_alloc = -1;
2100 share->multi_split_read = -1;
2101 share->max_order = -1;
2102 share->semi_table_lock = -1;
2103 share->semi_table_lock_conn = -1;
2104 share->selupd_lock_mode = -1;
2105 share->query_cache = -1;
2106 share->query_cache_sync = -1;
2107 share->internal_delayed = -1;
2108 share->bulk_size = -1;
2109 share->bulk_update_mode = -1;
2110 share->bulk_update_size = -1;
2111 share->buffer_size = -1;
2112 share->internal_optimize = -1;
2113 share->internal_optimize_local = -1;
2114 share->scan_rate = -1;
2115 share->read_rate = -1;
2116 share->priority = -1;
2117 share->quick_mode = -1;
2118 share->quick_page_size = -1;
2119 share->quick_page_byte = -1;
2120 share->low_mem_read = -1;
2121 share->table_count_mode = -1;
2122 share->select_column_mode = -1;
2123 #ifndef WITHOUT_SPIDER_BG_SEARCH
2124 share->bgs_mode = -1;
2125 share->bgs_first_read = -1;
2126 share->bgs_second_read = -1;
2127 #endif
2128 share->first_read = -1;
2129 share->second_read = -1;
2130 share->auto_increment_mode = -1;
2131 share->use_table_charset = -1;
2132 share->use_pushdown_udf = -1;
2133 share->skip_default_condition = -1;
2134 share->skip_parallel_search = -1;
2135 share->direct_dup_insert = -1;
2136 share->direct_order_limit = -1;
2137 share->bka_mode = -1;
2138 share->read_only_mode = -1;
2139 share->error_read_mode = -1;
2140 share->error_write_mode = -1;
2141 share->active_link_count = -1;
2142 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2143 share->hs_result_free_size = -1;
2144 #endif
2145 #ifdef HA_CAN_BULK_ACCESS
2146 share->bulk_access_free = -1;
2147 #endif
2148 #ifdef HA_CAN_FORCE_BULK_UPDATE
2149 share->force_bulk_update = -1;
2150 #endif
2151 #ifdef HA_CAN_FORCE_BULK_DELETE
2152 share->force_bulk_delete = -1;
2153 #endif
2154 share->casual_read = -1;
2155 share->delete_all_rows_type = -1;
2156 share->static_records_for_status = -1;
2157 share->static_mean_rec_length = -1;
2158 for (roop_count = 0; roop_count < (int) table_share->keys; roop_count++)
2159 {
2160 share->static_key_cardinality[roop_count] = -1;
2161 }
2162
2163 #ifdef WITH_PARTITION_STORAGE_ENGINE
2164 for (roop_count = 4; roop_count > 0; roop_count--)
2165 #else
2166 for (roop_count = 2; roop_count > 0; roop_count--)
2167 #endif
2168 {
2169 if (connect_string)
2170 {
2171 spider_free(spider_current_trx, connect_string, MYF(0));
2172 connect_string = NULL;
2173 }
2174 switch (roop_count)
2175 {
2176 #ifdef WITH_PARTITION_STORAGE_ENGINE
2177 case 4:
2178 if (!sub_elem || !sub_elem->part_comment)
2179 continue;
2180 DBUG_PRINT("info",("spider create sub comment string"));
2181 if (
2182 !(connect_string = spider_create_string(
2183 sub_elem->part_comment,
2184 strlen(sub_elem->part_comment)))
2185 ) {
2186 error_num = HA_ERR_OUT_OF_MEM;
2187 goto error_alloc_conn_string;
2188 }
2189 DBUG_PRINT("info",("spider sub comment string=%s", connect_string));
2190 break;
2191 case 3:
2192 if (!part_elem || !part_elem->part_comment)
2193 continue;
2194 DBUG_PRINT("info",("spider create part comment string"));
2195 if (
2196 !(connect_string = spider_create_string(
2197 part_elem->part_comment,
2198 strlen(part_elem->part_comment)))
2199 ) {
2200 error_num = HA_ERR_OUT_OF_MEM;
2201 goto error_alloc_conn_string;
2202 }
2203 DBUG_PRINT("info",("spider part comment string=%s", connect_string));
2204 break;
2205 #endif
2206 case 2:
2207 if (table_share->comment.length == 0)
2208 continue;
2209 DBUG_PRINT("info",("spider create comment string"));
2210 if (
2211 !(connect_string = spider_create_string(
2212 table_share->comment.str,
2213 table_share->comment.length))
2214 ) {
2215 error_num = HA_ERR_OUT_OF_MEM;
2216 goto error_alloc_conn_string;
2217 }
2218 DBUG_PRINT("info",("spider comment string=%s", connect_string));
2219 break;
2220 default:
2221 if (table_share->connect_string.length == 0)
2222 continue;
2223 DBUG_PRINT("info",("spider create connect_string string"));
2224 if (
2225 !(connect_string = spider_create_string(
2226 table_share->connect_string.str,
2227 table_share->connect_string.length))
2228 ) {
2229 error_num = HA_ERR_OUT_OF_MEM;
2230 goto error_alloc_conn_string;
2231 }
2232 DBUG_PRINT("info",("spider connect_string=%s", connect_string));
2233 break;
2234 }
2235
2236 sprit_ptr = connect_string;
2237 connect_string_parse.init(connect_string, ER_SPIDER_INVALID_CONNECT_INFO_NUM);
2238 while (sprit_ptr)
2239 {
2240 tmp_ptr = sprit_ptr;
2241 while (*tmp_ptr == ' ' || *tmp_ptr == '\r' ||
2242 *tmp_ptr == '\n' || *tmp_ptr == '\t')
2243 tmp_ptr++;
2244
2245 if (*tmp_ptr == '\0')
2246 break;
2247
2248 title_length = 0;
2249 start_ptr = tmp_ptr;
2250 while (*start_ptr != ' ' && *start_ptr != '\'' &&
2251 *start_ptr != '"' && *start_ptr != '\0' &&
2252 *start_ptr != '\r' && *start_ptr != '\n' &&
2253 *start_ptr != '\t')
2254 {
2255 title_length++;
2256 start_ptr++;
2257 }
2258 connect_string_parse.set_param_title(tmp_ptr, tmp_ptr + title_length);
2259 if ((error_num = connect_string_parse.get_next_parameter_head(
2260 start_ptr, &sprit_ptr)))
2261 {
2262 goto error;
2263 }
2264
2265 switch (title_length)
2266 {
2267 case 0:
2268 error_num = connect_string_parse.print_param_error();
2269 if (error_num)
2270 goto error;
2271 continue;
2272 case 3:
2273 SPIDER_PARAM_LONG_LIST_WITH_MAX("abl", access_balances, 0,
2274 2147483647);
2275 SPIDER_PARAM_INT_WITH_MAX("aim", auto_increment_mode, 0, 3);
2276 SPIDER_PARAM_INT("alc", active_link_count, 1);
2277 #ifdef HA_CAN_BULK_ACCESS
2278 SPIDER_PARAM_INT_WITH_MAX("baf", bulk_access_free, 0, 1);
2279 #endif
2280 SPIDER_PARAM_INT("bfz", buffer_size, 0);
2281 #ifndef WITHOUT_SPIDER_BG_SEARCH
2282 SPIDER_PARAM_LONGLONG("bfr", bgs_first_read, 0);
2283 SPIDER_PARAM_INT("bmd", bgs_mode, 0);
2284 SPIDER_PARAM_LONGLONG("bsr", bgs_second_read, 0);
2285 #endif
2286 SPIDER_PARAM_STR("bke", bka_engine);
2287 SPIDER_PARAM_INT_WITH_MAX("bkm", bka_mode, 0, 2);
2288 SPIDER_PARAM_INT("bsz", bulk_size, 0);
2289 SPIDER_PARAM_LONG_LIST_WITH_MAX("btt", bka_table_name_types,
2290 0, 1);
2291 SPIDER_PARAM_INT_WITH_MAX("bum", bulk_update_mode, 0, 2);
2292 SPIDER_PARAM_INT("bus", bulk_update_size, 0);
2293 #ifndef WITHOUT_SPIDER_BG_SEARCH
2294 SPIDER_PARAM_INT_WITH_MAX("cbm", crd_bg_mode, 0, 2);
2295 #endif
2296 SPIDER_PARAM_DOUBLE("civ", crd_interval, 0);
2297 SPIDER_PARAM_INT_WITH_MAX("cmd", crd_mode, 0, 3);
2298 SPIDER_PARAM_INT_WITH_MAX("csr", casual_read, 0, 63);
2299 #ifdef WITH_PARTITION_STORAGE_ENGINE
2300 SPIDER_PARAM_INT_WITH_MAX("csy", crd_sync, 0, 2);
2301 #endif
2302 SPIDER_PARAM_LONG_LIST_WITH_MAX("cto", connect_timeouts, 0,
2303 2147483647);
2304 SPIDER_PARAM_INT_WITH_MAX("ctp", crd_type, 0, 2);
2305 SPIDER_PARAM_DOUBLE("cwg", crd_weight, 1);
2306 SPIDER_PARAM_INT_WITH_MAX("dat", delete_all_rows_type, 0, 1);
2307 SPIDER_PARAM_INT_WITH_MAX("ddi", direct_dup_insert, 0, 1);
2308 SPIDER_PARAM_STR_LIST("dff", tgt_default_files);
2309 SPIDER_PARAM_STR_LIST("dfg", tgt_default_groups);
2310 SPIDER_PARAM_LONGLONG("dol", direct_order_limit, 0);
2311 SPIDER_PARAM_STR_LIST("dsn", tgt_dsns);
2312 SPIDER_PARAM_INT_WITH_MAX("erm", error_read_mode, 0, 1);
2313 SPIDER_PARAM_INT_WITH_MAX("ewm", error_write_mode, 0, 1);
2314 #ifdef HA_CAN_FORCE_BULK_DELETE
2315 SPIDER_PARAM_INT_WITH_MAX("fbd", force_bulk_delete, 0, 1);
2316 #endif
2317 #ifdef HA_CAN_FORCE_BULK_UPDATE
2318 SPIDER_PARAM_INT_WITH_MAX("fbu", force_bulk_update, 0, 1);
2319 #endif
2320 SPIDER_PARAM_LONGLONG("frd", first_read, 0);
2321 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2322 SPIDER_PARAM_LONGLONG("hrf", hs_result_free_size, 0);
2323 SPIDER_PARAM_LONG_LIST_WITH_MAX(
2324 "hrp", hs_read_ports, 0, 65535);
2325 SPIDER_PARAM_STR_LIST("hrs", hs_read_socks);
2326 SPIDER_PARAM_LONG_LIST_WITH_MAX(
2327 "hwp", hs_write_ports, 0, 65535);
2328 SPIDER_PARAM_LONG_LIST_WITH_MAX(
2329 "hwr", hs_write_to_reads, 0, 1);
2330 SPIDER_PARAM_STR_LIST("hws", hs_write_socks);
2331 #endif
2332 SPIDER_PARAM_INT("isa", init_sql_alloc_size, 0);
2333 SPIDER_PARAM_INT_WITH_MAX("idl", internal_delayed, 0, 1);
2334 SPIDER_PARAM_LONGLONG("ilm", internal_limit, 0);
2335 SPIDER_PARAM_LONGLONG("ios", internal_offset, 0);
2336 SPIDER_PARAM_INT_WITH_MAX("iom", internal_optimize, 0, 1);
2337 SPIDER_PARAM_INT_WITH_MAX("iol", internal_optimize_local, 0, 1);
2338 SPIDER_PARAM_INT_WITH_MAX("lmr", low_mem_read, 0, 1);
2339 SPIDER_PARAM_INT_WITH_MAX("lcs", load_crd_at_startup, 0, 1);
2340 SPIDER_PARAM_INT_WITH_MAX("lss", load_sts_at_startup, 0, 1);
2341 SPIDER_PARAM_LONG_LIST_WITH_MAX("lst", link_statuses, 0, 3);
2342 #ifndef WITHOUT_SPIDER_BG_SEARCH
2343 SPIDER_PARAM_LONG_LIST_WITH_MAX("mbf", monitoring_bg_flag, 0, 1);
2344 SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(
2345 "mbi", monitoring_bg_interval, 0, 4294967295LL);
2346 SPIDER_PARAM_LONG_LIST_WITH_MAX("mbk", monitoring_bg_kind, 0, 3);
2347 #endif
2348 SPIDER_PARAM_LONG_LIST_WITH_MAX("mbp", monitoring_binlog_pos_at_failing, 0, 2);
2349 SPIDER_PARAM_LONG_LIST_WITH_MAX("mfg", monitoring_flag, 0, 1);
2350 SPIDER_PARAM_LONG_LIST_WITH_MAX("mkd", monitoring_kind, 0, 3);
2351 SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(
2352 "mlt", monitoring_limit, 0, 9223372036854775807LL);
2353 SPIDER_PARAM_INT("mod", max_order, 0);
2354 SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(
2355 "msi", monitoring_sid, 0, 4294967295LL);
2356 SPIDER_PARAM_INT_WITH_MAX("msr", multi_split_read, 0, 2147483647);
2357 SPIDER_PARAM_LONG_LIST_WITH_MAX("nrt", net_read_timeouts, 0,
2358 2147483647);
2359 SPIDER_PARAM_LONG_LIST_WITH_MAX("nwt", net_write_timeouts, 0,
2360 2147483647);
2361 SPIDER_PARAM_STR_LIST("pkn", tgt_pk_names);
2362 SPIDER_PARAM_LONGLONG("prt", priority, 0);
2363 SPIDER_PARAM_INT_WITH_MAX("qch", query_cache, 0, 2);
2364 SPIDER_PARAM_INT_WITH_MAX("qcs", query_cache_sync, 0, 3);
2365 SPIDER_PARAM_INT_WITH_MAX("qmd", quick_mode, 0, 3);
2366 SPIDER_PARAM_LONGLONG("qpb", quick_page_byte, 0);
2367 SPIDER_PARAM_LONGLONG("qps", quick_page_size, 0);
2368 SPIDER_PARAM_INT_WITH_MAX("rom", read_only_mode, 0, 1);
2369 SPIDER_PARAM_DOUBLE("rrt", read_rate, 0);
2370 SPIDER_PARAM_INT_WITH_MAX("rsa", reset_sql_alloc, 0, 1);
2371 #ifndef WITHOUT_SPIDER_BG_SEARCH
2372 SPIDER_PARAM_INT_WITH_MAX("sbm", sts_bg_mode, 0, 2);
2373 #endif
2374 SPIDER_PARAM_STR_LIST("sca", tgt_ssl_cas);
2375 SPIDER_PARAM_STR_LIST("sch", tgt_ssl_ciphers);
2376 SPIDER_PARAM_INT_WITH_MAX("scm", select_column_mode, 0, 1);
2377 SPIDER_PARAM_STR_LIST("scp", tgt_ssl_capaths);
2378 SPIDER_PARAM_STR_LIST("scr", tgt_ssl_certs);
2379 SPIDER_PARAM_INT_WITH_MAX("sdc", skip_default_condition, 0, 1);
2380 SPIDER_PARAM_LONG_LIST_WITH_MAX("sgb", strict_group_bys, 0, 1);
2381 SPIDER_PARAM_DOUBLE("siv", sts_interval, 0);
2382 SPIDER_PARAM_STR_LIST("sky", tgt_ssl_keys);
2383 SPIDER_PARAM_STR_LIST("sli", static_link_ids);
2384 SPIDER_PARAM_INT_WITH_MAX("slc", store_last_crd, 0, 1);
2385 SPIDER_PARAM_INT_WITH_MAX("slm", selupd_lock_mode, 0, 2);
2386 SPIDER_PARAM_INT_WITH_MAX("sls", store_last_sts, 0, 1);
2387 SPIDER_PARAM_INT_WITH_MAX("smd", sts_mode, 1, 2);
2388 SPIDER_PARAM_LONGLONG("smr", static_mean_rec_length, 0);
2389 SPIDER_PARAM_LONGLONG("spr", split_read, 0);
2390 SPIDER_PARAM_INT_WITH_MAX("sps", skip_parallel_search, 0, 3);
2391 SPIDER_PARAM_STR_LIST("sqn", tgt_sequence_names);
2392 SPIDER_PARAM_LONGLONG("srd", second_read, 0);
2393 SPIDER_PARAM_DOUBLE("srt", scan_rate, 0);
2394 SPIDER_PARAM_STR_LIST("srv", server_names);
2395 SPIDER_PARAM_DOUBLE("ssr", semi_split_read, 0);
2396 SPIDER_PARAM_LONGLONG("ssl", semi_split_read_limit, 0);
2397 #ifdef WITH_PARTITION_STORAGE_ENGINE
2398 SPIDER_PARAM_INT_WITH_MAX("ssy", sts_sync, 0, 2);
2399 #endif
2400 SPIDER_PARAM_INT_WITH_MAX("stc", semi_table_lock_conn, 0, 1);
2401 SPIDER_PARAM_INT_WITH_MAX("stl", semi_table_lock, 0, 1);
2402 SPIDER_PARAM_LONGLONG("srs", static_records_for_status, 0);
2403 SPIDER_PARAM_LONG_LIST_WITH_MAX("svc", tgt_ssl_vscs, 0, 1);
2404 SPIDER_PARAM_STR_LIST("tbl", tgt_table_names);
2405 SPIDER_PARAM_INT_WITH_MAX("tcm", table_count_mode, 0, 3);
2406 SPIDER_PARAM_LONG_LIST_WITH_MAX("uhd", use_handlers, 0, 3);
2407 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2408 SPIDER_PARAM_LONG_LIST_WITH_MAX(
2409 "uhr", use_hs_reads, 0, 1);
2410 SPIDER_PARAM_LONG_LIST_WITH_MAX(
2411 "uhw", use_hs_writes, 0, 1);
2412 #endif
2413 SPIDER_PARAM_INT_WITH_MAX("upu", use_pushdown_udf, 0, 1);
2414 SPIDER_PARAM_INT_WITH_MAX("utc", use_table_charset, 0, 1);
2415 error_num = connect_string_parse.print_param_error();
2416 goto error;
2417 case 4:
2418 SPIDER_PARAM_STR_LIST("host", tgt_hosts);
2419 SPIDER_PARAM_STR_LIST("user", tgt_usernames);
2420 SPIDER_PARAM_LONG_LIST_WITH_MAX("port", tgt_ports, 0, 65535);
2421 error_num = connect_string_parse.print_param_error();
2422 goto error;
2423 case 5:
2424 SPIDER_PARAM_STR_LIST("table", tgt_table_names);
2425 error_num = connect_string_parse.print_param_error();
2426 goto error;
2427 case 6:
2428 SPIDER_PARAM_STR_LIST("server", server_names);
2429 SPIDER_PARAM_STR_LIST("socket", tgt_sockets);
2430 SPIDER_PARAM_HINT("idx", key_hint, 3, (int) table_share->keys,
2431 spider_db_append_key_hint);
2432 SPIDER_PARAM_STR_LIST("ssl_ca", tgt_ssl_cas);
2433 SPIDER_PARAM_NUMHINT("skc", static_key_cardinality, 3,
2434 (int) table_share->keys, spider_set_ll_value);
2435 error_num = connect_string_parse.print_param_error();
2436 goto error;
2437 case 7:
2438 SPIDER_PARAM_STR_LIST("wrapper", tgt_wrappers);
2439 SPIDER_PARAM_STR_LIST("ssl_key", tgt_ssl_keys);
2440 SPIDER_PARAM_STR_LIST("pk_name", tgt_pk_names);
2441 error_num = connect_string_parse.print_param_error();
2442 goto error;
2443 case 8:
2444 SPIDER_PARAM_STR_LIST("database", tgt_dbs);
2445 SPIDER_PARAM_STR_LIST("password", tgt_passwords);
2446 SPIDER_PARAM_INT_WITH_MAX("sts_mode", sts_mode, 1, 2);
2447 #ifdef WITH_PARTITION_STORAGE_ENGINE
2448 SPIDER_PARAM_INT_WITH_MAX("sts_sync", sts_sync, 0, 2);
2449 #endif
2450 SPIDER_PARAM_INT_WITH_MAX("crd_mode", crd_mode, 0, 3);
2451 #ifdef WITH_PARTITION_STORAGE_ENGINE
2452 SPIDER_PARAM_INT_WITH_MAX("crd_sync", crd_sync, 0, 2);
2453 #endif
2454 SPIDER_PARAM_INT_WITH_MAX("crd_type", crd_type, 0, 2);
2455 SPIDER_PARAM_LONGLONG("priority", priority, 0);
2456 #ifndef WITHOUT_SPIDER_BG_SEARCH
2457 SPIDER_PARAM_INT("bgs_mode", bgs_mode, 0);
2458 #endif
2459 SPIDER_PARAM_STR_LIST("ssl_cert", tgt_ssl_certs);
2460 SPIDER_PARAM_INT_WITH_MAX("bka_mode", bka_mode, 0, 2);
2461 error_num = connect_string_parse.print_param_error();
2462 goto error;
2463 case 9:
2464 SPIDER_PARAM_INT("max_order", max_order, 0);
2465 SPIDER_PARAM_INT("bulk_size", bulk_size, 0);
2466 SPIDER_PARAM_DOUBLE("scan_rate", scan_rate, 0);
2467 SPIDER_PARAM_DOUBLE("read_rate", read_rate, 0);
2468 error_num = connect_string_parse.print_param_error();
2469 goto error;
2470 case 10:
2471 SPIDER_PARAM_DOUBLE("crd_weight", crd_weight, 1);
2472 SPIDER_PARAM_LONGLONG("split_read", split_read, 0);
2473 SPIDER_PARAM_INT_WITH_MAX("quick_mode", quick_mode, 0, 3);
2474 SPIDER_PARAM_STR_LIST("ssl_cipher", tgt_ssl_ciphers);
2475 SPIDER_PARAM_STR_LIST("ssl_capath", tgt_ssl_capaths);
2476 SPIDER_PARAM_STR("bka_engine", bka_engine);
2477 SPIDER_PARAM_LONGLONG("first_read", first_read, 0);
2478 error_num = connect_string_parse.print_param_error();
2479 goto error;
2480 case 11:
2481 SPIDER_PARAM_INT_WITH_MAX("query_cache", query_cache, 0, 2);
2482 #ifndef WITHOUT_SPIDER_BG_SEARCH
2483 SPIDER_PARAM_INT_WITH_MAX("crd_bg_mode", crd_bg_mode, 0, 2);
2484 SPIDER_PARAM_INT_WITH_MAX("sts_bg_mode", sts_bg_mode, 0, 2);
2485 #endif
2486 SPIDER_PARAM_LONG_LIST_WITH_MAX("link_status", link_statuses, 0, 3);
2487 SPIDER_PARAM_LONG_LIST_WITH_MAX("use_handler", use_handlers, 0, 3);
2488 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2489 SPIDER_PARAM_LONG_LIST_WITH_MAX("use_hs_read", use_hs_reads, 0, 1);
2490 #endif
2491 SPIDER_PARAM_INT_WITH_MAX("casual_read", casual_read, 0, 63);
2492 SPIDER_PARAM_INT("buffer_size", buffer_size, 0);
2493 error_num = connect_string_parse.print_param_error();
2494 goto error;
2495 case 12:
2496 SPIDER_PARAM_DOUBLE("sts_interval", sts_interval, 0);
2497 SPIDER_PARAM_DOUBLE("crd_interval", crd_interval, 0);
2498 SPIDER_PARAM_INT_WITH_MAX("low_mem_read", low_mem_read, 0, 1);
2499 SPIDER_PARAM_STR_LIST("default_file", tgt_default_files);
2500 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2501 SPIDER_PARAM_LONG_LIST_WITH_MAX(
2502 "use_hs_write", use_hs_writes, 0, 1);
2503 SPIDER_PARAM_LONG_LIST_WITH_MAX(
2504 "hs_read_port", hs_read_ports, 0, 65535);
2505 #endif
2506 error_num = connect_string_parse.print_param_error();
2507 goto error;
2508 case 13:
2509 SPIDER_PARAM_STR_LIST("default_group", tgt_default_groups);
2510 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2511 SPIDER_PARAM_LONG_LIST_WITH_MAX(
2512 "hs_write_port", hs_write_ports, 0, 65535);
2513 #endif
2514 SPIDER_PARAM_STR_LIST("sequence_name", tgt_sequence_names);
2515 error_num = connect_string_parse.print_param_error();
2516 goto error;
2517 case 14:
2518 SPIDER_PARAM_LONGLONG("internal_limit", internal_limit, 0);
2519 #ifndef WITHOUT_SPIDER_BG_SEARCH
2520 SPIDER_PARAM_LONGLONG("bgs_first_read", bgs_first_read, 0);
2521 #endif
2522 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2523 SPIDER_PARAM_STR_LIST(
2524 "hs_read_socket", hs_read_socks);
2525 #endif
2526 SPIDER_PARAM_INT_WITH_MAX("read_only_mode", read_only_mode, 0, 1);
2527 SPIDER_PARAM_LONG_LIST_WITH_MAX("access_balance", access_balances, 0,
2528 2147483647);
2529 SPIDER_PARAM_STR_LIST("static_link_id", static_link_ids);
2530 SPIDER_PARAM_INT_WITH_MAX("store_last_crd", store_last_crd, 0, 1);
2531 SPIDER_PARAM_INT_WITH_MAX("store_last_sts", store_last_sts, 0, 1);
2532 error_num = connect_string_parse.print_param_error();
2533 goto error;
2534 case 15:
2535 SPIDER_PARAM_LONGLONG("internal_offset", internal_offset, 0);
2536 SPIDER_PARAM_INT_WITH_MAX("reset_sql_alloc", reset_sql_alloc, 0, 1);
2537 SPIDER_PARAM_INT_WITH_MAX("semi_table_lock", semi_table_lock, 0, 1);
2538 SPIDER_PARAM_LONGLONG("quick_page_byte", quick_page_byte, 0);
2539 SPIDER_PARAM_LONGLONG("quick_page_size", quick_page_size, 0);
2540 #ifndef WITHOUT_SPIDER_BG_SEARCH
2541 SPIDER_PARAM_LONGLONG("bgs_second_read", bgs_second_read, 0);
2542 #endif
2543 SPIDER_PARAM_LONG_LIST_WITH_MAX("monitoring_flag", monitoring_flag, 0, 1);
2544 SPIDER_PARAM_LONG_LIST_WITH_MAX("monitoring_kind", monitoring_kind, 0, 3);
2545 SPIDER_PARAM_DOUBLE("semi_split_read", semi_split_read, 0);
2546 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2547 SPIDER_PARAM_STR_LIST(
2548 "hs_write_socket", hs_write_socks);
2549 #endif
2550 SPIDER_PARAM_LONG_LIST_WITH_MAX("connect_timeout", connect_timeouts,
2551 0, 2147483647);
2552 SPIDER_PARAM_LONG_LIST_WITH_MAX("strict_group_by",
2553 strict_group_bys, 0, 1);
2554 SPIDER_PARAM_INT_WITH_MAX("error_read_mode", error_read_mode, 0, 1);
2555 error_num = connect_string_parse.print_param_error();
2556 goto error;
2557 case 16:
2558 SPIDER_PARAM_INT_WITH_MAX(
2559 "multi_split_read", multi_split_read, 0, 2147483647);
2560 SPIDER_PARAM_INT_WITH_MAX(
2561 "selupd_lock_mode", selupd_lock_mode, 0, 2);
2562 SPIDER_PARAM_INT_WITH_MAX(
2563 "internal_delayed", internal_delayed, 0, 1);
2564 SPIDER_PARAM_INT_WITH_MAX(
2565 "table_count_mode", table_count_mode, 0, 3);
2566 SPIDER_PARAM_INT_WITH_MAX(
2567 "use_pushdown_udf", use_pushdown_udf, 0, 1);
2568 SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(
2569 "monitoring_limit", monitoring_limit, 0, 9223372036854775807LL);
2570 SPIDER_PARAM_INT_WITH_MAX(
2571 "bulk_update_mode", bulk_update_mode, 0, 2);
2572 SPIDER_PARAM_INT("bulk_update_size", bulk_update_size, 0);
2573 SPIDER_PARAM_LONG_LIST_WITH_MAX("net_read_timeout",
2574 net_read_timeouts, 0, 2147483647);
2575 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2576 SPIDER_PARAM_LONG_LIST_WITH_MAX(
2577 "hs_write_to_read", hs_write_to_reads, 0, 1);
2578 #endif
2579 SPIDER_PARAM_INT_WITH_MAX(
2580 "error_write_mode", error_write_mode, 0, 1);
2581 #ifdef HA_CAN_BULK_ACCESS
2582 SPIDER_PARAM_INT_WITH_MAX(
2583 "bulk_access_free", bulk_access_free, 0, 1);
2584 #endif
2585 SPIDER_PARAM_INT_WITH_MAX(
2586 "query_cache_sync", query_cache_sync, 0, 3);
2587 error_num = connect_string_parse.print_param_error();
2588 goto error;
2589 case 17:
2590 SPIDER_PARAM_INT_WITH_MAX(
2591 "internal_optimize", internal_optimize, 0, 1);
2592 SPIDER_PARAM_INT_WITH_MAX(
2593 "use_table_charset", use_table_charset, 0, 1);
2594 SPIDER_PARAM_INT_WITH_MAX(
2595 "direct_dup_insert", direct_dup_insert, 0, 1);
2596 SPIDER_PARAM_INT("active_link_count", active_link_count, 1);
2597 SPIDER_PARAM_LONG_LIST_WITH_MAX("net_write_timeout",
2598 net_write_timeouts, 0, 2147483647);
2599 #ifdef HA_CAN_FORCE_BULK_DELETE
2600 SPIDER_PARAM_INT_WITH_MAX(
2601 "force_bulk_delete", force_bulk_delete, 0, 1);
2602 #endif
2603 #ifdef HA_CAN_FORCE_BULK_UPDATE
2604 SPIDER_PARAM_INT_WITH_MAX(
2605 "force_bulk_update", force_bulk_update, 0, 1);
2606 #endif
2607 error_num = connect_string_parse.print_param_error();
2608 goto error;
2609 case 18:
2610 SPIDER_PARAM_INT_WITH_MAX(
2611 "select_column_mode", select_column_mode, 0, 1);
2612 #ifndef WITHOUT_SPIDER_BG_SEARCH
2613 SPIDER_PARAM_LONG_LIST_WITH_MAX(
2614 "monitoring_bg_flag", monitoring_bg_flag, 0, 1);
2615 SPIDER_PARAM_LONG_LIST_WITH_MAX(
2616 "monitoring_bg_kind", monitoring_bg_kind, 0, 3);
2617 #endif
2618 SPIDER_PARAM_LONGLONG(
2619 "direct_order_limit", direct_order_limit, 0);
2620 error_num = connect_string_parse.print_param_error();
2621 goto error;
2622 case 19:
2623 SPIDER_PARAM_INT("init_sql_alloc_size", init_sql_alloc_size, 0);
2624 SPIDER_PARAM_INT_WITH_MAX(
2625 "auto_increment_mode", auto_increment_mode, 0, 3);
2626 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2627 SPIDER_PARAM_LONGLONG("hs_result_free_size", hs_result_free_size, 0);
2628 #endif
2629 SPIDER_PARAM_LONG_LIST_WITH_MAX("bka_table_name_type",
2630 bka_table_name_types, 0, 1);
2631 SPIDER_PARAM_INT_WITH_MAX(
2632 "load_crd_at_startup", load_crd_at_startup, 0, 1);
2633 SPIDER_PARAM_INT_WITH_MAX(
2634 "load_sts_at_startup", load_sts_at_startup, 0, 1);
2635 error_num = connect_string_parse.print_param_error();
2636 goto error;
2637 case 20:
2638 SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(
2639 "monitoring_server_id", monitoring_sid, 0, 4294967295LL);
2640 SPIDER_PARAM_INT_WITH_MAX(
2641 "delete_all_rows_type", delete_all_rows_type, 0, 1);
2642 SPIDER_PARAM_INT_WITH_MAX(
2643 "skip_parallel_search", skip_parallel_search, 0, 3);
2644 error_num = connect_string_parse.print_param_error();
2645 goto error;
2646 case 21:
2647 SPIDER_PARAM_LONGLONG(
2648 "semi_split_read_limit", semi_split_read_limit, 0);
2649 error_num = connect_string_parse.print_param_error();
2650 goto error;
2651 case 22:
2652 SPIDER_PARAM_LONG_LIST_WITH_MAX(
2653 "ssl_verify_server_cert", tgt_ssl_vscs, 0, 1);
2654 #ifndef WITHOUT_SPIDER_BG_SEARCH
2655 SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(
2656 "monitoring_bg_interval", monitoring_bg_interval, 0, 4294967295LL);
2657 #endif
2658 SPIDER_PARAM_INT_WITH_MAX(
2659 "skip_default_condition", skip_default_condition, 0, 1);
2660 SPIDER_PARAM_LONGLONG(
2661 "static_mean_rec_length", static_mean_rec_length, 0);
2662 error_num = connect_string_parse.print_param_error();
2663 goto error;
2664 case 23:
2665 SPIDER_PARAM_INT_WITH_MAX(
2666 "internal_optimize_local", internal_optimize_local, 0, 1);
2667 error_num = connect_string_parse.print_param_error();
2668 goto error;
2669 case 25:
2670 SPIDER_PARAM_LONGLONG("static_records_for_status",
2671 static_records_for_status, 0);
2672 SPIDER_PARAM_NUMHINT("static_key_cardinality", static_key_cardinality,
2673 3, (int) table_share->keys, spider_set_ll_value);
2674 error_num = connect_string_parse.print_param_error();
2675 goto error;
2676 case 26:
2677 SPIDER_PARAM_INT_WITH_MAX(
2678 "semi_table_lock_connection", semi_table_lock_conn, 0, 1);
2679 error_num = connect_string_parse.print_param_error();
2680 goto error;
2681 case 32:
2682 SPIDER_PARAM_LONG_LIST_WITH_MAX("monitoring_binlog_pos_at_failing",
2683 monitoring_binlog_pos_at_failing, 0, 2);
2684 error_num = connect_string_parse.print_param_error();
2685 goto error;
2686 default:
2687 error_num = connect_string_parse.print_param_error();
2688 goto error;
2689 }
2690
2691 /* Verify that the remainder of the parameter value is whitespace */
2692 if ((error_num = connect_string_parse.has_extra_parameter_values()))
2693 goto error;
2694 }
2695 }
2696
2697 /* check all_link_count */
2698 share->all_link_count = 1;
2699 if (share->all_link_count < share->server_names_length)
2700 share->all_link_count = share->server_names_length;
2701 if (share->all_link_count < share->tgt_table_names_length)
2702 share->all_link_count = share->tgt_table_names_length;
2703 if (share->all_link_count < share->tgt_dbs_length)
2704 share->all_link_count = share->tgt_dbs_length;
2705 if (share->all_link_count < share->tgt_hosts_length)
2706 share->all_link_count = share->tgt_hosts_length;
2707 if (share->all_link_count < share->tgt_usernames_length)
2708 share->all_link_count = share->tgt_usernames_length;
2709 if (share->all_link_count < share->tgt_passwords_length)
2710 share->all_link_count = share->tgt_passwords_length;
2711 if (share->all_link_count < share->tgt_sockets_length)
2712 share->all_link_count = share->tgt_sockets_length;
2713 if (share->all_link_count < share->tgt_wrappers_length)
2714 share->all_link_count = share->tgt_wrappers_length;
2715 if (share->all_link_count < share->tgt_ssl_cas_length)
2716 share->all_link_count = share->tgt_ssl_cas_length;
2717 if (share->all_link_count < share->tgt_ssl_capaths_length)
2718 share->all_link_count = share->tgt_ssl_capaths_length;
2719 if (share->all_link_count < share->tgt_ssl_certs_length)
2720 share->all_link_count = share->tgt_ssl_certs_length;
2721 if (share->all_link_count < share->tgt_ssl_ciphers_length)
2722 share->all_link_count = share->tgt_ssl_ciphers_length;
2723 if (share->all_link_count < share->tgt_ssl_keys_length)
2724 share->all_link_count = share->tgt_ssl_keys_length;
2725 if (share->all_link_count < share->tgt_default_files_length)
2726 share->all_link_count = share->tgt_default_files_length;
2727 if (share->all_link_count < share->tgt_default_groups_length)
2728 share->all_link_count = share->tgt_default_groups_length;
2729 if (share->all_link_count < share->tgt_dsns_length)
2730 share->all_link_count = share->tgt_dsns_length;
2731 if (share->all_link_count < share->tgt_pk_names_length)
2732 share->all_link_count = share->tgt_pk_names_length;
2733 if (share->all_link_count < share->tgt_sequence_names_length)
2734 share->all_link_count = share->tgt_sequence_names_length;
2735 if (share->all_link_count < share->static_link_ids_length)
2736 share->all_link_count = share->static_link_ids_length;
2737 if (share->all_link_count < share->tgt_ports_length)
2738 share->all_link_count = share->tgt_ports_length;
2739 if (share->all_link_count < share->tgt_ssl_vscs_length)
2740 share->all_link_count = share->tgt_ssl_vscs_length;
2741 if (share->all_link_count < share->link_statuses_length)
2742 share->all_link_count = share->link_statuses_length;
2743 if (share->all_link_count < share->monitoring_binlog_pos_at_failing_length)
2744 share->all_link_count = share->monitoring_binlog_pos_at_failing_length;
2745 if (share->all_link_count < share->monitoring_flag_length)
2746 share->all_link_count = share->monitoring_flag_length;
2747 if (share->all_link_count < share->monitoring_kind_length)
2748 share->all_link_count = share->monitoring_kind_length;
2749 if (share->all_link_count < share->monitoring_limit_length)
2750 share->all_link_count = share->monitoring_limit_length;
2751 if (share->all_link_count < share->monitoring_sid_length)
2752 share->all_link_count = share->monitoring_sid_length;
2753 #ifndef WITHOUT_SPIDER_BG_SEARCH
2754 if (share->all_link_count < share->monitoring_bg_flag_length)
2755 share->all_link_count = share->monitoring_bg_flag_length;
2756 if (share->all_link_count < share->monitoring_bg_kind_length)
2757 share->all_link_count = share->monitoring_bg_kind_length;
2758 if (share->all_link_count < share->monitoring_bg_interval_length)
2759 share->all_link_count = share->monitoring_bg_interval_length;
2760 #endif
2761 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2762 if (share->all_link_count < share->use_hs_reads_length)
2763 share->all_link_count = share->use_hs_reads_length;
2764 if (share->all_link_count < share->use_hs_writes_length)
2765 share->all_link_count = share->use_hs_writes_length;
2766 if (share->all_link_count < share->hs_read_ports_length)
2767 share->all_link_count = share->hs_read_ports_length;
2768 if (share->all_link_count < share->hs_write_ports_length)
2769 share->all_link_count = share->hs_write_ports_length;
2770 if (share->all_link_count < share->hs_read_socks_length)
2771 share->all_link_count = share->hs_read_socks_length;
2772 if (share->all_link_count < share->hs_write_socks_length)
2773 share->all_link_count = share->hs_write_socks_length;
2774 if (share->all_link_count < share->hs_write_to_reads_length)
2775 share->all_link_count = share->hs_write_to_reads_length;
2776 #endif
2777 if (share->all_link_count < share->use_handlers_length)
2778 share->all_link_count = share->use_handlers_length;
2779 if (share->all_link_count < share->connect_timeouts_length)
2780 share->all_link_count = share->connect_timeouts_length;
2781 if (share->all_link_count < share->net_read_timeouts_length)
2782 share->all_link_count = share->net_read_timeouts_length;
2783 if (share->all_link_count < share->net_write_timeouts_length)
2784 share->all_link_count = share->net_write_timeouts_length;
2785 if (share->all_link_count < share->access_balances_length)
2786 share->all_link_count = share->access_balances_length;
2787 if (share->all_link_count < share->bka_table_name_types_length)
2788 share->all_link_count = share->bka_table_name_types_length;
2789 if (share->all_link_count < share->strict_group_bys_length)
2790 share->all_link_count = share->strict_group_bys_length;
2791 if ((error_num = spider_increase_string_list(
2792 &share->server_names,
2793 &share->server_names_lengths,
2794 &share->server_names_length,
2795 &share->server_names_charlen,
2796 share->all_link_count)))
2797 goto error;
2798 if ((error_num = spider_increase_string_list(
2799 &share->tgt_table_names,
2800 &share->tgt_table_names_lengths,
2801 &share->tgt_table_names_length,
2802 &share->tgt_table_names_charlen,
2803 share->all_link_count)))
2804 goto error;
2805 if ((error_num = spider_increase_string_list(
2806 &share->tgt_dbs,
2807 &share->tgt_dbs_lengths,
2808 &share->tgt_dbs_length,
2809 &share->tgt_dbs_charlen,
2810 share->all_link_count)))
2811 goto error;
2812 if ((error_num = spider_increase_string_list(
2813 &share->tgt_hosts,
2814 &share->tgt_hosts_lengths,
2815 &share->tgt_hosts_length,
2816 &share->tgt_hosts_charlen,
2817 share->all_link_count)))
2818 goto error;
2819 if ((error_num = spider_increase_string_list(
2820 &share->tgt_usernames,
2821 &share->tgt_usernames_lengths,
2822 &share->tgt_usernames_length,
2823 &share->tgt_usernames_charlen,
2824 share->all_link_count)))
2825 goto error;
2826 if ((error_num = spider_increase_string_list(
2827 &share->tgt_passwords,
2828 &share->tgt_passwords_lengths,
2829 &share->tgt_passwords_length,
2830 &share->tgt_passwords_charlen,
2831 share->all_link_count)))
2832 goto error;
2833 if ((error_num = spider_increase_string_list(
2834 &share->tgt_sockets,
2835 &share->tgt_sockets_lengths,
2836 &share->tgt_sockets_length,
2837 &share->tgt_sockets_charlen,
2838 share->all_link_count)))
2839 goto error;
2840 if ((error_num = spider_increase_string_list(
2841 &share->tgt_wrappers,
2842 &share->tgt_wrappers_lengths,
2843 &share->tgt_wrappers_length,
2844 &share->tgt_wrappers_charlen,
2845 share->all_link_count)))
2846 goto error;
2847 if ((error_num = spider_increase_string_list(
2848 &share->tgt_ssl_cas,
2849 &share->tgt_ssl_cas_lengths,
2850 &share->tgt_ssl_cas_length,
2851 &share->tgt_ssl_cas_charlen,
2852 share->all_link_count)))
2853 goto error;
2854 if ((error_num = spider_increase_string_list(
2855 &share->tgt_ssl_capaths,
2856 &share->tgt_ssl_capaths_lengths,
2857 &share->tgt_ssl_capaths_length,
2858 &share->tgt_ssl_capaths_charlen,
2859 share->all_link_count)))
2860 goto error;
2861 if ((error_num = spider_increase_string_list(
2862 &share->tgt_ssl_certs,
2863 &share->tgt_ssl_certs_lengths,
2864 &share->tgt_ssl_certs_length,
2865 &share->tgt_ssl_certs_charlen,
2866 share->all_link_count)))
2867 goto error;
2868 if ((error_num = spider_increase_string_list(
2869 &share->tgt_ssl_ciphers,
2870 &share->tgt_ssl_ciphers_lengths,
2871 &share->tgt_ssl_ciphers_length,
2872 &share->tgt_ssl_ciphers_charlen,
2873 share->all_link_count)))
2874 goto error;
2875 if ((error_num = spider_increase_string_list(
2876 &share->tgt_ssl_keys,
2877 &share->tgt_ssl_keys_lengths,
2878 &share->tgt_ssl_keys_length,
2879 &share->tgt_ssl_keys_charlen,
2880 share->all_link_count)))
2881 goto error;
2882 if ((error_num = spider_increase_string_list(
2883 &share->tgt_default_files,
2884 &share->tgt_default_files_lengths,
2885 &share->tgt_default_files_length,
2886 &share->tgt_default_files_charlen,
2887 share->all_link_count)))
2888 goto error;
2889 if ((error_num = spider_increase_string_list(
2890 &share->tgt_default_groups,
2891 &share->tgt_default_groups_lengths,
2892 &share->tgt_default_groups_length,
2893 &share->tgt_default_groups_charlen,
2894 share->all_link_count)))
2895 goto error;
2896 if ((error_num = spider_increase_string_list(
2897 &share->tgt_dsns,
2898 &share->tgt_dsns_lengths,
2899 &share->tgt_dsns_length,
2900 &share->tgt_dsns_charlen,
2901 share->all_link_count)))
2902 goto error;
2903 if ((error_num = spider_increase_string_list(
2904 &share->tgt_pk_names,
2905 &share->tgt_pk_names_lengths,
2906 &share->tgt_pk_names_length,
2907 &share->tgt_pk_names_charlen,
2908 share->all_link_count)))
2909 goto error;
2910 if ((error_num = spider_increase_string_list(
2911 &share->tgt_sequence_names,
2912 &share->tgt_sequence_names_lengths,
2913 &share->tgt_sequence_names_length,
2914 &share->tgt_sequence_names_charlen,
2915 share->all_link_count)))
2916 goto error;
2917 if ((error_num = spider_increase_null_string_list(
2918 &share->static_link_ids,
2919 &share->static_link_ids_lengths,
2920 &share->static_link_ids_length,
2921 &share->static_link_ids_charlen,
2922 share->all_link_count)))
2923 goto error;
2924 if ((error_num = spider_increase_long_list(
2925 &share->tgt_ports,
2926 &share->tgt_ports_length,
2927 share->all_link_count)))
2928 goto error;
2929 if ((error_num = spider_increase_long_list(
2930 &share->tgt_ssl_vscs,
2931 &share->tgt_ssl_vscs_length,
2932 share->all_link_count)))
2933 goto error;
2934 if ((error_num = spider_increase_long_list(
2935 &share->link_statuses,
2936 &share->link_statuses_length,
2937 share->all_link_count)))
2938 goto error;
2939 #ifndef WITHOUT_SPIDER_BG_SEARCH
2940 if ((error_num = spider_increase_long_list(
2941 &share->monitoring_bg_flag,
2942 &share->monitoring_bg_flag_length,
2943 share->all_link_count)))
2944 goto error;
2945 if ((error_num = spider_increase_long_list(
2946 &share->monitoring_bg_kind,
2947 &share->monitoring_bg_kind_length,
2948 share->all_link_count)))
2949 goto error;
2950 #endif
2951 if ((error_num = spider_increase_long_list(
2952 &share->monitoring_binlog_pos_at_failing,
2953 &share->monitoring_binlog_pos_at_failing_length,
2954 share->all_link_count)))
2955 goto error;
2956 if ((error_num = spider_increase_long_list(
2957 &share->monitoring_flag,
2958 &share->monitoring_flag_length,
2959 share->all_link_count)))
2960 goto error;
2961 if ((error_num = spider_increase_long_list(
2962 &share->monitoring_kind,
2963 &share->monitoring_kind_length,
2964 share->all_link_count)))
2965 goto error;
2966 #ifndef WITHOUT_SPIDER_BG_SEARCH
2967 if ((error_num = spider_increase_longlong_list(
2968 &share->monitoring_bg_interval,
2969 &share->monitoring_bg_interval_length,
2970 share->all_link_count)))
2971 goto error;
2972 #endif
2973 if ((error_num = spider_increase_longlong_list(
2974 &share->monitoring_limit,
2975 &share->monitoring_limit_length,
2976 share->all_link_count)))
2977 goto error;
2978 if ((error_num = spider_increase_longlong_list(
2979 &share->monitoring_sid,
2980 &share->monitoring_sid_length,
2981 share->all_link_count)))
2982 goto error;
2983 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
2984 if ((error_num = spider_increase_long_list(
2985 &share->use_hs_reads,
2986 &share->use_hs_reads_length,
2987 share->all_link_count)))
2988 goto error;
2989 if ((error_num = spider_increase_long_list(
2990 &share->use_hs_writes,
2991 &share->use_hs_writes_length,
2992 share->all_link_count)))
2993 goto error;
2994 if ((error_num = spider_increase_long_list(
2995 &share->hs_read_ports,
2996 &share->hs_read_ports_length,
2997 share->all_link_count)))
2998 goto error;
2999 if ((error_num = spider_increase_long_list(
3000 &share->hs_write_ports,
3001 &share->hs_write_ports_length,
3002 share->all_link_count)))
3003 goto error;
3004 if ((error_num = spider_increase_string_list(
3005 &share->hs_read_socks,
3006 &share->hs_read_socks_lengths,
3007 &share->hs_read_socks_length,
3008 &share->hs_read_socks_charlen,
3009 share->all_link_count)))
3010 goto error;
3011 if ((error_num = spider_increase_string_list(
3012 &share->hs_write_socks,
3013 &share->hs_write_socks_lengths,
3014 &share->hs_write_socks_length,
3015 &share->hs_write_socks_charlen,
3016 share->all_link_count)))
3017 goto error;
3018 if ((error_num = spider_increase_long_list(
3019 &share->hs_write_to_reads,
3020 &share->hs_write_to_reads_length,
3021 share->all_link_count)))
3022 goto error;
3023 #endif
3024 if ((error_num = spider_increase_long_list(
3025 &share->use_handlers,
3026 &share->use_handlers_length,
3027 share->all_link_count)))
3028 goto error;
3029 if ((error_num = spider_increase_long_list(
3030 &share->connect_timeouts,
3031 &share->connect_timeouts_length,
3032 share->all_link_count)))
3033 goto error;
3034 if ((error_num = spider_increase_long_list(
3035 &share->net_read_timeouts,
3036 &share->net_read_timeouts_length,
3037 share->all_link_count)))
3038 goto error;
3039 if ((error_num = spider_increase_long_list(
3040 &share->net_write_timeouts,
3041 &share->net_write_timeouts_length,
3042 share->all_link_count)))
3043 goto error;
3044 if ((error_num = spider_increase_long_list(
3045 &share->access_balances,
3046 &share->access_balances_length,
3047 share->all_link_count)))
3048 goto error;
3049 if ((error_num = spider_increase_long_list(
3050 &share->bka_table_name_types,
3051 &share->bka_table_name_types_length,
3052 share->all_link_count)))
3053 goto error;
3054 if ((error_num = spider_increase_long_list(
3055 &share->strict_group_bys,
3056 &share->strict_group_bys_length,
3057 share->all_link_count)))
3058 goto error;
3059
3060 /* copy for tables start */
3061 share_alter = &share->alter_table;
3062 share_alter->all_link_count = share->all_link_count;
3063 if (!(share_alter->tmp_server_names = (char **)
3064 spider_bulk_malloc(spider_current_trx, 43, MYF(MY_WME | MY_ZEROFILL),
3065 &share_alter->tmp_server_names,
3066 (uint) (sizeof(char *) * share->all_link_count),
3067 &share_alter->tmp_tgt_table_names,
3068 (uint) (sizeof(char *) * share->all_link_count),
3069 &share_alter->tmp_tgt_dbs,
3070 (uint) (sizeof(char *) * share->all_link_count),
3071 &share_alter->tmp_tgt_hosts,
3072 (uint) (sizeof(char *) * share->all_link_count),
3073 &share_alter->tmp_tgt_usernames,
3074 (uint) (sizeof(char *) * share->all_link_count),
3075 &share_alter->tmp_tgt_passwords,
3076 (uint) (sizeof(char *) * share->all_link_count),
3077 &share_alter->tmp_tgt_sockets,
3078 (uint) (sizeof(char *) * share->all_link_count),
3079 &share_alter->tmp_tgt_wrappers,
3080 (uint) (sizeof(char *) * share->all_link_count),
3081 &share_alter->tmp_tgt_ssl_cas,
3082 (uint) (sizeof(char *) * share->all_link_count),
3083 &share_alter->tmp_tgt_ssl_capaths,
3084 (uint) (sizeof(char *) * share->all_link_count),
3085 &share_alter->tmp_tgt_ssl_certs,
3086 (uint) (sizeof(char *) * share->all_link_count),
3087 &share_alter->tmp_tgt_ssl_ciphers,
3088 (uint) (sizeof(char *) * share->all_link_count),
3089 &share_alter->tmp_tgt_ssl_keys,
3090 (uint) (sizeof(char *) * share->all_link_count),
3091 &share_alter->tmp_tgt_default_files,
3092 (uint) (sizeof(char *) * share->all_link_count),
3093 &share_alter->tmp_tgt_default_groups,
3094 (uint) (sizeof(char *) * share->all_link_count),
3095 &share_alter->tmp_tgt_dsns,
3096 (uint) (sizeof(char *) * share->all_link_count),
3097 &share_alter->tmp_static_link_ids,
3098 (uint) (sizeof(char *) * share->all_link_count),
3099 &share_alter->tmp_server_names_lengths,
3100 (uint) (sizeof(uint *) * share->all_link_count),
3101 &share_alter->tmp_tgt_table_names_lengths,
3102 (uint) (sizeof(uint *) * share->all_link_count),
3103 &share_alter->tmp_tgt_dbs_lengths,
3104 (uint) (sizeof(uint *) * share->all_link_count),
3105 &share_alter->tmp_tgt_hosts_lengths,
3106 (uint) (sizeof(uint *) * share->all_link_count),
3107 &share_alter->tmp_tgt_usernames_lengths,
3108 (uint) (sizeof(uint *) * share->all_link_count),
3109 &share_alter->tmp_tgt_passwords_lengths,
3110 (uint) (sizeof(uint *) * share->all_link_count),
3111 &share_alter->tmp_tgt_sockets_lengths,
3112 (uint) (sizeof(uint *) * share->all_link_count),
3113 &share_alter->tmp_tgt_wrappers_lengths,
3114 (uint) (sizeof(uint *) * share->all_link_count),
3115 &share_alter->tmp_tgt_ssl_cas_lengths,
3116 (uint) (sizeof(uint *) * share->all_link_count),
3117 &share_alter->tmp_tgt_ssl_capaths_lengths,
3118 (uint) (sizeof(uint *) * share->all_link_count),
3119 &share_alter->tmp_tgt_ssl_certs_lengths,
3120 (uint) (sizeof(uint *) * share->all_link_count),
3121 &share_alter->tmp_tgt_ssl_ciphers_lengths,
3122 (uint) (sizeof(uint *) * share->all_link_count),
3123 &share_alter->tmp_tgt_ssl_keys_lengths,
3124 (uint) (sizeof(uint *) * share->all_link_count),
3125 &share_alter->tmp_tgt_default_files_lengths,
3126 (uint) (sizeof(uint *) * share->all_link_count),
3127 &share_alter->tmp_tgt_default_groups_lengths,
3128 (uint) (sizeof(uint *) * share->all_link_count),
3129 &share_alter->tmp_tgt_dsns_lengths,
3130 (uint) (sizeof(uint *) * share->all_link_count),
3131 &share_alter->tmp_static_link_ids_lengths,
3132 (uint) (sizeof(uint *) * share->all_link_count),
3133 &share_alter->tmp_tgt_ports,
3134 (uint) (sizeof(long) * share->all_link_count),
3135 &share_alter->tmp_tgt_ssl_vscs,
3136 (uint) (sizeof(long) * share->all_link_count),
3137 &share_alter->tmp_monitoring_binlog_pos_at_failing,
3138 (uint) (sizeof(long) * share->all_link_count),
3139 &share_alter->tmp_link_statuses,
3140 (uint) (sizeof(long) * share->all_link_count),
3141 NullS))
3142 ) {
3143 error_num = HA_ERR_OUT_OF_MEM;
3144 goto error;
3145 }
3146
3147
3148 memcpy(share_alter->tmp_server_names, share->server_names,
3149 sizeof(char *) * share->all_link_count);
3150 memcpy(share_alter->tmp_tgt_table_names, share->tgt_table_names,
3151 sizeof(char *) * share->all_link_count);
3152 memcpy(share_alter->tmp_tgt_dbs, share->tgt_dbs,
3153 sizeof(char *) * share->all_link_count);
3154 memcpy(share_alter->tmp_tgt_hosts, share->tgt_hosts,
3155 sizeof(char *) * share->all_link_count);
3156 memcpy(share_alter->tmp_tgt_usernames, share->tgt_usernames,
3157 sizeof(char *) * share->all_link_count);
3158 memcpy(share_alter->tmp_tgt_passwords, share->tgt_passwords,
3159 sizeof(char *) * share->all_link_count);
3160 memcpy(share_alter->tmp_tgt_sockets, share->tgt_sockets,
3161 sizeof(char *) * share->all_link_count);
3162 memcpy(share_alter->tmp_tgt_wrappers, share->tgt_wrappers,
3163 sizeof(char *) * share->all_link_count);
3164 memcpy(share_alter->tmp_tgt_ssl_cas, share->tgt_ssl_cas,
3165 sizeof(char *) * share->all_link_count);
3166 memcpy(share_alter->tmp_tgt_ssl_capaths, share->tgt_ssl_capaths,
3167 sizeof(char *) * share->all_link_count);
3168 memcpy(share_alter->tmp_tgt_ssl_certs, share->tgt_ssl_certs,
3169 sizeof(char *) * share->all_link_count);
3170 memcpy(share_alter->tmp_tgt_ssl_ciphers, share->tgt_ssl_ciphers,
3171 sizeof(char *) * share->all_link_count);
3172 memcpy(share_alter->tmp_tgt_ssl_keys, share->tgt_ssl_keys,
3173 sizeof(char *) * share->all_link_count);
3174 memcpy(share_alter->tmp_tgt_default_files, share->tgt_default_files,
3175 sizeof(char *) * share->all_link_count);
3176 memcpy(share_alter->tmp_tgt_default_groups, share->tgt_default_groups,
3177 sizeof(char *) * share->all_link_count);
3178 memcpy(share_alter->tmp_tgt_dsns, share->tgt_dsns,
3179 sizeof(char *) * share->all_link_count);
3180 memcpy(share_alter->tmp_static_link_ids, share->static_link_ids,
3181 sizeof(char *) * share->all_link_count);
3182
3183 memcpy(share_alter->tmp_tgt_ports, share->tgt_ports,
3184 sizeof(long) * share->all_link_count);
3185 memcpy(share_alter->tmp_tgt_ssl_vscs, share->tgt_ssl_vscs,
3186 sizeof(long) * share->all_link_count);
3187 memcpy(share_alter->tmp_monitoring_binlog_pos_at_failing,
3188 share->monitoring_binlog_pos_at_failing,
3189 sizeof(long) * share->all_link_count);
3190 memcpy(share_alter->tmp_link_statuses, share->link_statuses,
3191 sizeof(long) * share->all_link_count);
3192
3193 memcpy(share_alter->tmp_server_names_lengths,
3194 share->server_names_lengths,
3195 sizeof(uint) * share->all_link_count);
3196 memcpy(share_alter->tmp_tgt_table_names_lengths,
3197 share->tgt_table_names_lengths,
3198 sizeof(uint) * share->all_link_count);
3199 memcpy(share_alter->tmp_tgt_dbs_lengths, share->tgt_dbs_lengths,
3200 sizeof(uint) * share->all_link_count);
3201 memcpy(share_alter->tmp_tgt_hosts_lengths, share->tgt_hosts_lengths,
3202 sizeof(uint) * share->all_link_count);
3203 memcpy(share_alter->tmp_tgt_usernames_lengths,
3204 share->tgt_usernames_lengths,
3205 sizeof(uint) * share->all_link_count);
3206 memcpy(share_alter->tmp_tgt_passwords_lengths,
3207 share->tgt_passwords_lengths,
3208 sizeof(uint) * share->all_link_count);
3209 memcpy(share_alter->tmp_tgt_sockets_lengths, share->tgt_sockets_lengths,
3210 sizeof(uint) * share->all_link_count);
3211 memcpy(share_alter->tmp_tgt_wrappers_lengths,
3212 share->tgt_wrappers_lengths,
3213 sizeof(uint) * share->all_link_count);
3214 memcpy(share_alter->tmp_tgt_ssl_cas_lengths,
3215 share->tgt_ssl_cas_lengths,
3216 sizeof(uint) * share->all_link_count);
3217 memcpy(share_alter->tmp_tgt_ssl_capaths_lengths,
3218 share->tgt_ssl_capaths_lengths,
3219 sizeof(uint) * share->all_link_count);
3220 memcpy(share_alter->tmp_tgt_ssl_certs_lengths,
3221 share->tgt_ssl_certs_lengths,
3222 sizeof(uint) * share->all_link_count);
3223 memcpy(share_alter->tmp_tgt_ssl_ciphers_lengths,
3224 share->tgt_ssl_ciphers_lengths,
3225 sizeof(uint) * share->all_link_count);
3226 memcpy(share_alter->tmp_tgt_ssl_keys_lengths,
3227 share->tgt_ssl_keys_lengths,
3228 sizeof(uint) * share->all_link_count);
3229 memcpy(share_alter->tmp_tgt_default_files_lengths,
3230 share->tgt_default_files_lengths,
3231 sizeof(uint) * share->all_link_count);
3232 memcpy(share_alter->tmp_tgt_default_groups_lengths,
3233 share->tgt_default_groups_lengths,
3234 sizeof(uint) * share->all_link_count);
3235 memcpy(share_alter->tmp_tgt_dsns_lengths,
3236 share->tgt_dsns_lengths,
3237 sizeof(uint) * share->all_link_count);
3238 memcpy(share_alter->tmp_static_link_ids_lengths,
3239 share->static_link_ids_lengths,
3240 sizeof(uint) * share->all_link_count);
3241
3242 share_alter->tmp_server_names_charlen = share->server_names_charlen;
3243 share_alter->tmp_tgt_table_names_charlen = share->tgt_table_names_charlen;
3244 share_alter->tmp_tgt_dbs_charlen = share->tgt_dbs_charlen;
3245 share_alter->tmp_tgt_hosts_charlen = share->tgt_hosts_charlen;
3246 share_alter->tmp_tgt_usernames_charlen = share->tgt_usernames_charlen;
3247 share_alter->tmp_tgt_passwords_charlen = share->tgt_passwords_charlen;
3248 share_alter->tmp_tgt_sockets_charlen = share->tgt_sockets_charlen;
3249 share_alter->tmp_tgt_wrappers_charlen = share->tgt_wrappers_charlen;
3250 share_alter->tmp_tgt_ssl_cas_charlen = share->tgt_ssl_cas_charlen;
3251 share_alter->tmp_tgt_ssl_capaths_charlen = share->tgt_ssl_capaths_charlen;
3252 share_alter->tmp_tgt_ssl_certs_charlen = share->tgt_ssl_certs_charlen;
3253 share_alter->tmp_tgt_ssl_ciphers_charlen = share->tgt_ssl_ciphers_charlen;
3254 share_alter->tmp_tgt_ssl_keys_charlen = share->tgt_ssl_keys_charlen;
3255 share_alter->tmp_tgt_default_files_charlen =
3256 share->tgt_default_files_charlen;
3257 share_alter->tmp_tgt_default_groups_charlen =
3258 share->tgt_default_groups_charlen;
3259 share_alter->tmp_tgt_dsns_charlen =
3260 share->tgt_dsns_charlen;
3261 share_alter->tmp_static_link_ids_charlen =
3262 share->static_link_ids_charlen;
3263
3264 share_alter->tmp_server_names_length = share->server_names_length;
3265 share_alter->tmp_tgt_table_names_length = share->tgt_table_names_length;
3266 share_alter->tmp_tgt_dbs_length = share->tgt_dbs_length;
3267 share_alter->tmp_tgt_hosts_length = share->tgt_hosts_length;
3268 share_alter->tmp_tgt_usernames_length = share->tgt_usernames_length;
3269 share_alter->tmp_tgt_passwords_length = share->tgt_passwords_length;
3270 share_alter->tmp_tgt_sockets_length = share->tgt_sockets_length;
3271 share_alter->tmp_tgt_wrappers_length = share->tgt_wrappers_length;
3272 share_alter->tmp_tgt_ssl_cas_length = share->tgt_ssl_cas_length;
3273 share_alter->tmp_tgt_ssl_capaths_length = share->tgt_ssl_capaths_length;
3274 share_alter->tmp_tgt_ssl_certs_length = share->tgt_ssl_certs_length;
3275 share_alter->tmp_tgt_ssl_ciphers_length = share->tgt_ssl_ciphers_length;
3276 share_alter->tmp_tgt_ssl_keys_length = share->tgt_ssl_keys_length;
3277 share_alter->tmp_tgt_default_files_length = share->tgt_default_files_length;
3278 share_alter->tmp_tgt_default_groups_length =
3279 share->tgt_default_groups_length;
3280 share_alter->tmp_tgt_dsns_length =
3281 share->tgt_dsns_length;
3282 share_alter->tmp_static_link_ids_length =
3283 share->static_link_ids_length;
3284 share_alter->tmp_tgt_ports_length = share->tgt_ports_length;
3285 share_alter->tmp_tgt_ssl_vscs_length = share->tgt_ssl_vscs_length;
3286 share_alter->tmp_monitoring_binlog_pos_at_failing_length =
3287 share->monitoring_binlog_pos_at_failing_length;
3288 share_alter->tmp_link_statuses_length = share->link_statuses_length;
3289 /* copy for tables end */
3290
3291 if ((error_num = spider_set_connect_info_default(
3292 share,
3293 #ifdef WITH_PARTITION_STORAGE_ENGINE
3294 part_elem,
3295 sub_elem,
3296 #endif
3297 table_share
3298 )))
3299 goto error;
3300
3301 if (create_table)
3302 {
3303 for (roop_count = 0; roop_count < (int) share->all_link_count;
3304 roop_count++)
3305 {
3306 int roop_count2;
3307 for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++)
3308 {
3309 if (
3310 spider_dbton[roop_count2].wrapper &&
3311 !strcmp(share->tgt_wrappers[roop_count],
3312 spider_dbton[roop_count2].wrapper)
3313 ) {
3314 break;
3315 }
3316 }
3317 if (roop_count2 == SPIDER_DBTON_SIZE)
3318 {
3319 DBUG_PRINT("info",("spider err tgt_wrappers[%d]=%s", roop_count,
3320 share->tgt_wrappers[roop_count]));
3321 error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
3322 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
3323 MYF(0), share->tgt_wrappers[roop_count]);
3324 goto error;
3325 }
3326
3327 DBUG_PRINT("info",
3328 ("spider server_names_lengths[%d] = %u", roop_count,
3329 share->server_names_lengths[roop_count]));
3330 if (share->server_names_lengths[roop_count] > SPIDER_CONNECT_INFO_MAX_LEN)
3331 {
3332 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3333 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3334 MYF(0), share->server_names[roop_count], "server");
3335 goto error;
3336 }
3337
3338 DBUG_PRINT("info",
3339 ("spider tgt_table_names_lengths[%d] = %u", roop_count,
3340 share->tgt_table_names_lengths[roop_count]));
3341 if (share->tgt_table_names_lengths[roop_count] >
3342 SPIDER_CONNECT_INFO_MAX_LEN)
3343 {
3344 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3345 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3346 MYF(0), share->tgt_table_names[roop_count], "table");
3347 goto error;
3348 }
3349
3350 DBUG_PRINT("info",
3351 ("spider tgt_dbs_lengths[%d] = %u", roop_count,
3352 share->tgt_dbs_lengths[roop_count]));
3353 if (share->tgt_dbs_lengths[roop_count] > SPIDER_CONNECT_INFO_MAX_LEN)
3354 {
3355 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3356 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3357 MYF(0), share->tgt_dbs[roop_count], "database");
3358 goto error;
3359 }
3360
3361 DBUG_PRINT("info",
3362 ("spider tgt_hosts_lengths[%d] = %u", roop_count,
3363 share->tgt_hosts_lengths[roop_count]));
3364 if (share->tgt_hosts_lengths[roop_count] > SPIDER_CONNECT_INFO_MAX_LEN)
3365 {
3366 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3367 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3368 MYF(0), share->tgt_hosts[roop_count], "host");
3369 goto error;
3370 }
3371
3372 DBUG_PRINT("info",
3373 ("spider tgt_usernames_lengths[%d] = %u", roop_count,
3374 share->tgt_usernames_lengths[roop_count]));
3375 if (share->tgt_usernames_lengths[roop_count] >
3376 SPIDER_CONNECT_INFO_MAX_LEN)
3377 {
3378 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3379 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3380 MYF(0), share->tgt_usernames[roop_count], "user");
3381 goto error;
3382 }
3383
3384 DBUG_PRINT("info",
3385 ("spider tgt_passwords_lengths[%d] = %u", roop_count,
3386 share->tgt_passwords_lengths[roop_count]));
3387 if (share->tgt_passwords_lengths[roop_count] >
3388 SPIDER_CONNECT_INFO_MAX_LEN)
3389 {
3390 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3391 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3392 MYF(0), share->tgt_passwords[roop_count], "password");
3393 goto error;
3394 }
3395
3396 DBUG_PRINT("info",
3397 ("spider tgt_sockets_lengths[%d] = %u", roop_count,
3398 share->tgt_sockets_lengths[roop_count]));
3399 if (share->tgt_sockets_lengths[roop_count] >
3400 SPIDER_CONNECT_INFO_PATH_MAX_LEN)
3401 {
3402 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3403 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3404 MYF(0), share->tgt_sockets[roop_count], "socket");
3405 goto error;
3406 }
3407
3408 DBUG_PRINT("info",
3409 ("spider tgt_wrappers_lengths[%d] = %u", roop_count,
3410 share->tgt_wrappers_lengths[roop_count]));
3411 if (share->tgt_wrappers_lengths[roop_count] >
3412 SPIDER_CONNECT_INFO_MAX_LEN)
3413 {
3414 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3415 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3416 MYF(0), share->tgt_wrappers[roop_count], "wrapper");
3417 goto error;
3418 }
3419
3420 DBUG_PRINT("info",
3421 ("spider tgt_ssl_cas_lengths[%d] = %u", roop_count,
3422 share->tgt_ssl_cas_lengths[roop_count]));
3423 if (share->tgt_ssl_cas_lengths[roop_count] >
3424 SPIDER_CONNECT_INFO_PATH_MAX_LEN)
3425 {
3426 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3427 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3428 MYF(0), share->tgt_ssl_cas[roop_count], "ssl_ca");
3429 goto error;
3430 }
3431
3432 DBUG_PRINT("info",
3433 ("spider tgt_ssl_capaths_lengths[%d] = %u", roop_count,
3434 share->tgt_ssl_capaths_lengths[roop_count]));
3435 if (share->tgt_ssl_capaths_lengths[roop_count] >
3436 SPIDER_CONNECT_INFO_PATH_MAX_LEN)
3437 {
3438 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3439 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3440 MYF(0), share->tgt_ssl_capaths[roop_count], "ssl_capath");
3441 goto error;
3442 }
3443
3444 DBUG_PRINT("info",
3445 ("spider tgt_ssl_certs_lengths[%d] = %u", roop_count,
3446 share->tgt_ssl_certs_lengths[roop_count]));
3447 if (share->tgt_ssl_certs_lengths[roop_count] >
3448 SPIDER_CONNECT_INFO_PATH_MAX_LEN)
3449 {
3450 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3451 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3452 MYF(0), share->tgt_ssl_certs[roop_count], "ssl_cert");
3453 goto error;
3454 }
3455
3456 DBUG_PRINT("info",
3457 ("spider tgt_ssl_ciphers_lengths[%d] = %u", roop_count,
3458 share->tgt_ssl_ciphers_lengths[roop_count]));
3459 if (share->tgt_ssl_ciphers_lengths[roop_count] >
3460 SPIDER_CONNECT_INFO_MAX_LEN)
3461 {
3462 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3463 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3464 MYF(0), share->tgt_ssl_ciphers[roop_count], "ssl_cipher");
3465 goto error;
3466 }
3467
3468 DBUG_PRINT("info",
3469 ("spider tgt_ssl_keys_lengths[%d] = %u", roop_count,
3470 share->tgt_ssl_keys_lengths[roop_count]));
3471 if (share->tgt_ssl_keys_lengths[roop_count] >
3472 SPIDER_CONNECT_INFO_PATH_MAX_LEN)
3473 {
3474 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3475 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3476 MYF(0), share->tgt_ssl_keys[roop_count], "ssl_key");
3477 goto error;
3478 }
3479
3480 DBUG_PRINT("info",
3481 ("spider tgt_default_files_lengths[%d] = %u", roop_count,
3482 share->tgt_default_files_lengths[roop_count]));
3483 if (share->tgt_default_files_lengths[roop_count] >
3484 SPIDER_CONNECT_INFO_PATH_MAX_LEN)
3485 {
3486 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3487 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3488 MYF(0), share->tgt_default_files[roop_count], "default_file");
3489 goto error;
3490 }
3491
3492 DBUG_PRINT("info",
3493 ("spider tgt_default_groups_lengths[%d] = %u", roop_count,
3494 share->tgt_default_groups_lengths[roop_count]));
3495 if (share->tgt_default_groups_lengths[roop_count] >
3496 SPIDER_CONNECT_INFO_MAX_LEN)
3497 {
3498 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3499 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3500 MYF(0), share->tgt_default_groups[roop_count], "default_group");
3501 goto error;
3502 }
3503
3504 DBUG_PRINT("info",
3505 ("spider tgt_dsns_lengths[%d] = %u", roop_count,
3506 share->tgt_dsns_lengths[roop_count]));
3507 if (share->tgt_dsns_lengths[roop_count] >
3508 SPIDER_CONNECT_INFO_MAX_LEN)
3509 {
3510 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3511 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3512 MYF(0), share->tgt_dsns[roop_count], "default_group");
3513 goto error;
3514 }
3515
3516 DBUG_PRINT("info",
3517 ("spider tgt_pk_names_lengths[%d] = %u", roop_count,
3518 share->tgt_pk_names_lengths[roop_count]));
3519 if (share->tgt_pk_names_lengths[roop_count] >
3520 SPIDER_CONNECT_INFO_MAX_LEN)
3521 {
3522 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3523 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3524 MYF(0), share->tgt_pk_names[roop_count], "pk_name");
3525 goto error;
3526 }
3527
3528 DBUG_PRINT("info",
3529 ("spider tgt_sequence_names_lengths[%d] = %u", roop_count,
3530 share->tgt_sequence_names_lengths[roop_count]));
3531 if (share->tgt_sequence_names_lengths[roop_count] >
3532 SPIDER_CONNECT_INFO_MAX_LEN)
3533 {
3534 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3535 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3536 MYF(0), share->tgt_sequence_names[roop_count], "sequence_name");
3537 goto error;
3538 }
3539
3540 DBUG_PRINT("info",
3541 ("spider static_link_ids_lengths[%d] = %u", roop_count,
3542 share->static_link_ids_lengths[roop_count]));
3543 if (share->static_link_ids_lengths[roop_count] >
3544 SPIDER_CONNECT_INFO_MAX_LEN)
3545 {
3546 error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
3547 my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
3548 MYF(0), share->static_link_ids[roop_count], "static_link_id");
3549 goto error;
3550 }
3551 if (share->static_link_ids[roop_count])
3552 {
3553 if (
3554 share->static_link_ids_lengths[roop_count] > 0 &&
3555 share->static_link_ids[roop_count][0] >= '0' &&
3556 share->static_link_ids[roop_count][0] <= '9'
3557 ) {
3558 error_num = ER_SPIDER_INVALID_CONNECT_INFO_START_WITH_NUM_NUM;
3559 my_printf_error(error_num,
3560 ER_SPIDER_INVALID_CONNECT_INFO_START_WITH_NUM_STR,
3561 MYF(0), share->static_link_ids[roop_count], "static_link_id");
3562 goto error;
3563 }
3564 for (roop_count2 = roop_count + 1;
3565 roop_count2 < (int) share->all_link_count;
3566 roop_count2++)
3567 {
3568 if (
3569 share->static_link_ids_lengths[roop_count] ==
3570 share->static_link_ids_lengths[roop_count2] &&
3571 !memcmp(share->static_link_ids[roop_count],
3572 share->static_link_ids[roop_count2],
3573 share->static_link_ids_lengths[roop_count])
3574 ) {
3575 error_num = ER_SPIDER_INVALID_CONNECT_INFO_SAME_NUM;
3576 my_printf_error(error_num,
3577 ER_SPIDER_INVALID_CONNECT_INFO_SAME_STR,
3578 MYF(0), share->static_link_ids[roop_count],
3579 "static_link_id");
3580 goto error;
3581 }
3582 }
3583 }
3584 }
3585 }
3586
3587 DBUG_PRINT("info", ("spider share->active_link_count = %d",
3588 share->active_link_count));
3589 share->link_count = (uint) share->active_link_count;
3590 share_alter->link_count = share->link_count;
3591 share->link_bitmap_size = (share->link_count + 7) / 8;
3592
3593 if (connect_string)
3594 spider_free(spider_current_trx, connect_string, MYF(0));
3595 DBUG_RETURN(0);
3596
3597 error:
3598 if (connect_string)
3599 spider_free(spider_current_trx, connect_string, MYF(0));
3600 error_alloc_conn_string:
3601 DBUG_RETURN(error_num);
3602 }
3603
spider_set_connect_info_default(SPIDER_SHARE * share,partition_element * part_elem,partition_element * sub_elem,TABLE_SHARE * table_share)3604 int spider_set_connect_info_default(
3605 SPIDER_SHARE *share,
3606 #ifdef WITH_PARTITION_STORAGE_ENGINE
3607 partition_element *part_elem,
3608 partition_element *sub_elem,
3609 #endif
3610 TABLE_SHARE *table_share
3611 ) {
3612 bool check_socket;
3613 bool check_database;
3614 bool socket_has_default_value;
3615 bool database_has_default_value;
3616 int error_num, roop_count, roop_count2;
3617 DBUG_ENTER("spider_set_connect_info_default");
3618 for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++)
3619 {
3620 if (share->server_names[roop_count])
3621 {
3622 if ((error_num = spider_get_server(share, roop_count)))
3623 DBUG_RETURN(error_num);
3624 }
3625
3626 if (
3627 !share->tgt_sockets[roop_count] &&
3628 (
3629 !share->tgt_hosts[roop_count] ||
3630 !strcmp(share->tgt_hosts[roop_count], my_localhost)
3631 )
3632 ) {
3633 check_socket = TRUE;
3634 } else {
3635 check_socket = FALSE;
3636 }
3637 if (!share->tgt_dbs[roop_count] && table_share)
3638 {
3639 check_database = TRUE;
3640 } else {
3641 check_database = FALSE;
3642 }
3643 if (check_socket || check_database)
3644 {
3645 socket_has_default_value = check_socket;
3646 database_has_default_value = check_database;
3647 if (share->tgt_wrappers[roop_count])
3648 {
3649 for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++)
3650 {
3651 DBUG_PRINT("info",("spider share->tgt_wrappers[%d]=%s", roop_count,
3652 share->tgt_wrappers[roop_count]));
3653 DBUG_PRINT("info",("spider spider_dbton[%d].wrapper=%s", roop_count2,
3654 spider_dbton[roop_count2].wrapper ?
3655 spider_dbton[roop_count2].wrapper : "NULL"));
3656 if (
3657 spider_dbton[roop_count2].wrapper &&
3658 !strcmp(share->tgt_wrappers[roop_count],
3659 spider_dbton[roop_count2].wrapper)
3660 ) {
3661 if (spider_dbton[roop_count2].db_access_type ==
3662 SPIDER_DB_ACCESS_TYPE_SQL)
3663 {
3664 if (check_socket)
3665 {
3666 socket_has_default_value = spider_dbton[roop_count2].
3667 db_util->socket_has_default_value();
3668 }
3669 if (check_database)
3670 {
3671 database_has_default_value = spider_dbton[roop_count2].
3672 db_util->database_has_default_value();
3673 }
3674 break;
3675 }
3676 }
3677 }
3678 }
3679 } else {
3680 socket_has_default_value = FALSE;
3681 database_has_default_value = FALSE;
3682 }
3683
3684 if (!share->tgt_wrappers[roop_count])
3685 {
3686 DBUG_PRINT("info",("spider create default tgt_wrappers"));
3687 share->tgt_wrappers_lengths[roop_count] = SPIDER_DB_WRAPPER_LEN;
3688 if (
3689 !(share->tgt_wrappers[roop_count] = spider_create_string(
3690 SPIDER_DB_WRAPPER_STR,
3691 share->tgt_wrappers_lengths[roop_count]))
3692 ) {
3693 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
3694 }
3695 }
3696
3697 if (!share->tgt_hosts[roop_count])
3698 {
3699 DBUG_PRINT("info",("spider create default tgt_hosts"));
3700 share->tgt_hosts_lengths[roop_count] = strlen(my_localhost);
3701 if (
3702 !(share->tgt_hosts[roop_count] = spider_create_string(
3703 my_localhost,
3704 share->tgt_hosts_lengths[roop_count]))
3705 ) {
3706 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
3707 }
3708 }
3709
3710 if (database_has_default_value)
3711 {
3712 DBUG_PRINT("info",("spider create default tgt_dbs"));
3713 share->tgt_dbs_lengths[roop_count] = table_share->db.length;
3714 if (
3715 !(share->tgt_dbs[roop_count] = spider_create_string(
3716 table_share->db.str,
3717 table_share->db.length))
3718 ) {
3719 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
3720 }
3721 }
3722
3723 if (!share->tgt_table_names[roop_count] && table_share)
3724 {
3725 DBUG_PRINT("info",("spider create default tgt_table_names"));
3726 share->tgt_table_names_lengths[roop_count] =
3727 table_share->table_name.length;
3728 if (
3729 !(share->tgt_table_names[roop_count] = spider_create_table_name_string(
3730 table_share->table_name.str,
3731 #ifdef WITH_PARTITION_STORAGE_ENGINE
3732 (part_elem ? part_elem->partition_name : NULL),
3733 (sub_elem ? sub_elem->partition_name : NULL)
3734 #else
3735 NULL,
3736 NULL
3737 #endif
3738 ))
3739 ) {
3740 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
3741 }
3742 }
3743
3744 if (
3745 !share->tgt_default_files[roop_count] &&
3746 share->tgt_default_groups[roop_count] &&
3747 (*spd_defaults_file || *spd_defaults_extra_file)
3748 ) {
3749 DBUG_PRINT("info",("spider create default tgt_default_files"));
3750 if (*spd_defaults_extra_file)
3751 {
3752 share->tgt_default_files_lengths[roop_count] =
3753 strlen(*spd_defaults_extra_file);
3754 if (
3755 !(share->tgt_default_files[roop_count] = spider_create_string(
3756 *spd_defaults_extra_file,
3757 share->tgt_default_files_lengths[roop_count]))
3758 ) {
3759 my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
3760 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
3761 }
3762 } else {
3763 share->tgt_default_files_lengths[roop_count] =
3764 strlen(*spd_defaults_file);
3765 if (
3766 !(share->tgt_default_files[roop_count] = spider_create_string(
3767 *spd_defaults_file,
3768 share->tgt_default_files_lengths[roop_count]))
3769 ) {
3770 my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
3771 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
3772 }
3773 }
3774 }
3775
3776 if (!share->tgt_pk_names[roop_count])
3777 {
3778 DBUG_PRINT("info",("spider create default tgt_pk_names"));
3779 share->tgt_pk_names_lengths[roop_count] = SPIDER_DB_PK_NAME_LEN;
3780 if (
3781 !(share->tgt_pk_names[roop_count] = spider_create_string(
3782 SPIDER_DB_PK_NAME_STR,
3783 share->tgt_pk_names_lengths[roop_count]))
3784 ) {
3785 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
3786 }
3787 }
3788
3789 if (!share->tgt_sequence_names[roop_count])
3790 {
3791 DBUG_PRINT("info",("spider create default tgt_sequence_names"));
3792 share->tgt_sequence_names_lengths[roop_count] =
3793 SPIDER_DB_SEQUENCE_NAME_LEN;
3794 if (
3795 !(share->tgt_sequence_names[roop_count] = spider_create_string(
3796 SPIDER_DB_SEQUENCE_NAME_STR,
3797 share->tgt_sequence_names_lengths[roop_count]))
3798 ) {
3799 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
3800 }
3801 }
3802
3803 /*
3804 if (!share->static_link_ids[roop_count])
3805 {
3806 DBUG_PRINT("info",("spider create default static_link_ids"));
3807 share->static_link_ids_lengths[roop_count] =
3808 SPIDER_DB_STATIC_LINK_ID_LEN;
3809 if (
3810 !(share->static_link_ids[roop_count] = spider_create_string(
3811 SPIDER_DB_STATIC_LINK_ID_STR,
3812 share->static_link_ids_lengths[roop_count]))
3813 ) {
3814 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
3815 }
3816 }
3817 */
3818
3819 if (share->tgt_ports[roop_count] == -1)
3820 {
3821 share->tgt_ports[roop_count] = MYSQL_PORT;
3822 } else if (share->tgt_ports[roop_count] < 0)
3823 {
3824 share->tgt_ports[roop_count] = 0;
3825 } else if (share->tgt_ports[roop_count] > 65535)
3826 {
3827 share->tgt_ports[roop_count] = 65535;
3828 }
3829
3830 if (share->tgt_ssl_vscs[roop_count] == -1)
3831 share->tgt_ssl_vscs[roop_count] = 0;
3832
3833 if (socket_has_default_value)
3834 {
3835 DBUG_PRINT("info",("spider create default tgt_sockets"));
3836 share->tgt_sockets_lengths[roop_count] =
3837 strlen((char *) MYSQL_UNIX_ADDR);
3838 if (
3839 !(share->tgt_sockets[roop_count] = spider_create_string(
3840 (char *) MYSQL_UNIX_ADDR,
3841 share->tgt_sockets_lengths[roop_count]))
3842 ) {
3843 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
3844 }
3845 }
3846
3847 if (share->link_statuses[roop_count] == -1)
3848 share->link_statuses[roop_count] = SPIDER_LINK_STATUS_NO_CHANGE;
3849
3850 #ifndef WITHOUT_SPIDER_BG_SEARCH
3851 if (share->monitoring_bg_flag[roop_count] == -1)
3852 share->monitoring_bg_flag[roop_count] = 0;
3853 if (share->monitoring_bg_kind[roop_count] == -1)
3854 share->monitoring_bg_kind[roop_count] = 0;
3855 #endif
3856 if (share->monitoring_binlog_pos_at_failing[roop_count] == -1)
3857 share->monitoring_binlog_pos_at_failing[roop_count] = 0;
3858 if (share->monitoring_flag[roop_count] == -1)
3859 share->monitoring_flag[roop_count] = 0;
3860 if (share->monitoring_kind[roop_count] == -1)
3861 share->monitoring_kind[roop_count] = 0;
3862 #ifndef WITHOUT_SPIDER_BG_SEARCH
3863 if (share->monitoring_bg_interval[roop_count] == -1)
3864 share->monitoring_bg_interval[roop_count] = 10000000;
3865 #endif
3866 if (share->monitoring_limit[roop_count] == -1)
3867 share->monitoring_limit[roop_count] = 1;
3868 if (share->monitoring_sid[roop_count] == -1)
3869 #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002
3870 share->monitoring_sid[roop_count] = global_system_variables.server_id;
3871 #else
3872 share->monitoring_sid[roop_count] = current_thd->server_id;
3873 #endif
3874
3875 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
3876 if (share->use_hs_reads[roop_count] == -1)
3877 share->use_hs_reads[roop_count] = 0;
3878 if (share->use_hs_writes[roop_count] == -1)
3879 share->use_hs_writes[roop_count] = 0;
3880 if (share->hs_read_ports[roop_count] == -1)
3881 {
3882 share->hs_read_ports[roop_count] = 9998;
3883 } else if (share->hs_read_ports[roop_count] < 0)
3884 {
3885 share->hs_read_ports[roop_count] = 0;
3886 } else if (share->hs_read_ports[roop_count] > 65535)
3887 {
3888 share->hs_read_ports[roop_count] = 65535;
3889 }
3890 if (share->hs_write_ports[roop_count] == -1)
3891 {
3892 share->hs_write_ports[roop_count] = 9999;
3893 } else if (share->hs_write_ports[roop_count] < 0)
3894 {
3895 share->hs_write_ports[roop_count] = 0;
3896 } else if (share->hs_write_ports[roop_count] > 65535)
3897 {
3898 share->hs_write_ports[roop_count] = 65535;
3899 }
3900 if (share->hs_write_to_reads[roop_count] == -1)
3901 {
3902 share->hs_write_to_reads[roop_count] = 1;
3903 } else if (share->hs_write_to_reads[roop_count] < 0)
3904 {
3905 share->hs_write_to_reads[roop_count] = 0;
3906 } else if (share->hs_write_to_reads[roop_count] > 1)
3907 {
3908 share->hs_write_to_reads[roop_count] = 1;
3909 }
3910 #endif
3911 if (share->use_handlers[roop_count] == -1)
3912 share->use_handlers[roop_count] = 0;
3913 if (share->connect_timeouts[roop_count] == -1)
3914 share->connect_timeouts[roop_count] = 6;
3915 if (share->net_read_timeouts[roop_count] == -1)
3916 share->net_read_timeouts[roop_count] = 600;
3917 if (share->net_write_timeouts[roop_count] == -1)
3918 share->net_write_timeouts[roop_count] = 600;
3919 if (share->access_balances[roop_count] == -1)
3920 share->access_balances[roop_count] = 100;
3921 if (share->bka_table_name_types[roop_count] == -1)
3922 share->bka_table_name_types[roop_count] = 0;
3923 if (share->strict_group_bys[roop_count] == -1)
3924 share->strict_group_bys[roop_count] = 1;
3925 }
3926
3927 #ifndef WITHOUT_SPIDER_BG_SEARCH
3928 if (share->sts_bg_mode == -1)
3929 share->sts_bg_mode = 2;
3930 #endif
3931 if (share->sts_interval == -1)
3932 share->sts_interval = 10;
3933 if (share->sts_mode == -1)
3934 share->sts_mode = 1;
3935 #ifdef WITH_PARTITION_STORAGE_ENGINE
3936 if (share->sts_sync == -1)
3937 share->sts_sync = 0;
3938 #endif
3939 if (share->store_last_sts == -1)
3940 share->store_last_sts = 1;
3941 if (share->load_sts_at_startup == -1)
3942 share->load_sts_at_startup = 1;
3943 #ifndef WITHOUT_SPIDER_BG_SEARCH
3944 if (share->crd_bg_mode == -1)
3945 share->crd_bg_mode = 2;
3946 #endif
3947 if (share->crd_interval == -1)
3948 share->crd_interval = 51;
3949 if (share->crd_mode == -1)
3950 share->crd_mode = 1;
3951 #ifdef WITH_PARTITION_STORAGE_ENGINE
3952 if (share->crd_sync == -1)
3953 share->crd_sync = 0;
3954 #endif
3955 if (share->store_last_crd == -1)
3956 share->store_last_crd = 1;
3957 if (share->load_crd_at_startup == -1)
3958 share->load_crd_at_startup = 1;
3959 if (share->crd_type == -1)
3960 share->crd_type = 2;
3961 if (share->crd_weight == -1)
3962 share->crd_weight = 2;
3963 if (share->internal_offset == -1)
3964 share->internal_offset = 0;
3965 if (share->internal_limit == -1)
3966 share->internal_limit = 9223372036854775807LL;
3967 if (share->split_read == -1)
3968 share->split_read = 9223372036854775807LL;
3969 if (share->semi_split_read == -1)
3970 share->semi_split_read = 2;
3971 if (share->semi_split_read_limit == -1)
3972 share->semi_split_read_limit = 9223372036854775807LL;
3973 if (share->init_sql_alloc_size == -1)
3974 share->init_sql_alloc_size = 1024;
3975 if (share->reset_sql_alloc == -1)
3976 share->reset_sql_alloc = 1;
3977 if (share->multi_split_read == -1)
3978 share->multi_split_read = 100;
3979 if (share->max_order == -1)
3980 share->max_order = 32767;
3981 if (share->semi_table_lock == -1)
3982 share->semi_table_lock = 0;
3983 if (share->semi_table_lock_conn == -1)
3984 share->semi_table_lock_conn = 1;
3985 if (share->selupd_lock_mode == -1)
3986 share->selupd_lock_mode = 1;
3987 if (share->query_cache == -1)
3988 share->query_cache = 0;
3989 if (share->query_cache_sync == -1)
3990 share->query_cache_sync = 0;
3991 if (share->internal_delayed == -1)
3992 share->internal_delayed = 0;
3993 if (share->bulk_size == -1)
3994 share->bulk_size = 16000;
3995 if (share->bulk_update_mode == -1)
3996 share->bulk_update_mode = 0;
3997 if (share->bulk_update_size == -1)
3998 share->bulk_update_size = 16000;
3999 if (share->buffer_size == -1)
4000 share->buffer_size = 16000;
4001 if (share->internal_optimize == -1)
4002 share->internal_optimize = 0;
4003 if (share->internal_optimize_local == -1)
4004 share->internal_optimize_local = 0;
4005 if (share->scan_rate == -1)
4006 share->scan_rate = 1;
4007 if (share->read_rate == -1)
4008 share->read_rate = 0.0002;
4009 if (share->priority == -1)
4010 share->priority = 1000000;
4011 if (share->quick_mode == -1)
4012 share->quick_mode = 3;
4013 if (share->quick_page_size == -1)
4014 share->quick_page_size = 1024;
4015 if (share->quick_page_byte == -1)
4016 share->quick_page_byte = 10485760;
4017 if (share->low_mem_read == -1)
4018 share->low_mem_read = 1;
4019 if (share->table_count_mode == -1)
4020 share->table_count_mode = 0;
4021 if (share->select_column_mode == -1)
4022 share->select_column_mode = 1;
4023 #ifndef WITHOUT_SPIDER_BG_SEARCH
4024 if (share->bgs_mode == -1)
4025 share->bgs_mode = 0;
4026 if (share->bgs_first_read == -1)
4027 share->bgs_first_read = 2;
4028 if (share->bgs_second_read == -1)
4029 share->bgs_second_read = 100;
4030 #endif
4031 if (share->first_read == -1)
4032 share->first_read = 0;
4033 if (share->second_read == -1)
4034 share->second_read = 0;
4035 if (share->auto_increment_mode == -1)
4036 share->auto_increment_mode = 0;
4037 if (share->use_table_charset == -1)
4038 share->use_table_charset = 1;
4039 if (share->use_pushdown_udf == -1)
4040 share->use_pushdown_udf = 1;
4041 if (share->skip_default_condition == -1)
4042 share->skip_default_condition = 0;
4043 if (share->skip_parallel_search == -1)
4044 share->skip_parallel_search = 0;
4045 if (share->direct_dup_insert == -1)
4046 share->direct_dup_insert = 0;
4047 if (share->direct_order_limit == -1)
4048 share->direct_order_limit = 9223372036854775807LL;
4049 if (share->read_only_mode == -1)
4050 share->read_only_mode = 0;
4051 if (share->error_read_mode == -1)
4052 share->error_read_mode = 0;
4053 if (share->error_write_mode == -1)
4054 share->error_write_mode = 0;
4055 if (share->active_link_count == -1)
4056 share->active_link_count = share->all_link_count;
4057 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4058 if (share->hs_result_free_size == -1)
4059 share->hs_result_free_size = 1048576;
4060 #endif
4061 #ifdef HA_CAN_BULK_ACCESS
4062 if (share->bulk_access_free == -1)
4063 share->bulk_access_free = 0;
4064 #endif
4065 #ifdef HA_CAN_FORCE_BULK_UPDATE
4066 if (share->force_bulk_update == -1)
4067 share->force_bulk_update = 0;
4068 #endif
4069 #ifdef HA_CAN_FORCE_BULK_DELETE
4070 if (share->force_bulk_delete == -1)
4071 share->force_bulk_delete = 0;
4072 #endif
4073 if (share->casual_read == -1)
4074 share->casual_read = 0;
4075 if (share->delete_all_rows_type == -1)
4076 {
4077 #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
4078 share->delete_all_rows_type = 1;
4079 #else
4080 share->delete_all_rows_type = 0;
4081 #endif
4082 }
4083 if (share->bka_mode == -1)
4084 share->bka_mode = 1;
4085 if (!share->bka_engine)
4086 {
4087 DBUG_PRINT("info",("spider create default bka_engine"));
4088 share->bka_engine_length = SPIDER_SQL_TMP_BKA_ENGINE_LEN;
4089 if (
4090 !(share->bka_engine = spider_create_string(
4091 SPIDER_SQL_TMP_BKA_ENGINE_STR,
4092 SPIDER_SQL_TMP_BKA_ENGINE_LEN))
4093 ) {
4094 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
4095 }
4096 }
4097 DBUG_RETURN(0);
4098 }
4099
spider_set_connect_info_default_db_table(SPIDER_SHARE * share,const char * db_name,uint db_name_length,const char * table_name,uint table_name_length)4100 int spider_set_connect_info_default_db_table(
4101 SPIDER_SHARE *share,
4102 const char *db_name,
4103 uint db_name_length,
4104 const char *table_name,
4105 uint table_name_length
4106 ) {
4107 uint roop_count, roop_count2;
4108 bool check_database;
4109 bool database_has_default_value;
4110 DBUG_ENTER("spider_set_connect_info_default_db_table");
4111 for (roop_count = 0; roop_count < share->link_count; roop_count++)
4112 {
4113 if (!share->tgt_dbs[roop_count] && db_name)
4114 {
4115 check_database = TRUE;
4116 } else {
4117 check_database = FALSE;
4118 }
4119 if (check_database)
4120 {
4121 database_has_default_value = check_database;
4122 if (share->tgt_wrappers[roop_count])
4123 {
4124 for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++)
4125 {
4126 DBUG_PRINT("info",("spider share->tgt_wrappers[%d]=%s", roop_count,
4127 share->tgt_wrappers[roop_count]));
4128 DBUG_PRINT("info",("spider spider_dbton[%d].wrapper=%s", roop_count2,
4129 spider_dbton[roop_count2].wrapper ?
4130 spider_dbton[roop_count2].wrapper : "NULL"));
4131 if (
4132 spider_dbton[roop_count2].wrapper &&
4133 !strcmp(share->tgt_wrappers[roop_count],
4134 spider_dbton[roop_count2].wrapper)
4135 ) {
4136 if (spider_dbton[roop_count2].db_access_type ==
4137 SPIDER_DB_ACCESS_TYPE_SQL)
4138 {
4139 if (check_database)
4140 {
4141 database_has_default_value = spider_dbton[roop_count2].
4142 db_util->database_has_default_value();
4143 }
4144 break;
4145 }
4146 }
4147 }
4148 }
4149 } else {
4150 database_has_default_value = FALSE;
4151 }
4152
4153 if (database_has_default_value)
4154 {
4155 DBUG_PRINT("info",("spider create default tgt_dbs"));
4156 share->tgt_dbs_lengths[roop_count] = db_name_length;
4157 if (
4158 !(share->tgt_dbs[roop_count] = spider_create_string(
4159 db_name,
4160 db_name_length))
4161 ) {
4162 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
4163 }
4164 }
4165
4166 if (!share->tgt_table_names[roop_count] && table_name)
4167 {
4168 const char *tmp_ptr;
4169 DBUG_PRINT("info",("spider create default tgt_table_names"));
4170 if ((tmp_ptr = strstr(table_name, "#P#")))
4171 table_name_length = (uint) PTR_BYTE_DIFF(tmp_ptr, table_name);
4172 share->tgt_table_names_lengths[roop_count] = table_name_length;
4173 if (
4174 !(share->tgt_table_names[roop_count] = spider_create_string(
4175 table_name,
4176 table_name_length))
4177 ) {
4178 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
4179 }
4180 }
4181 }
4182 DBUG_RETURN(0);
4183 }
4184
spider_set_connect_info_default_dbtable(SPIDER_SHARE * share,const char * dbtable_name,int dbtable_name_length)4185 int spider_set_connect_info_default_dbtable(
4186 SPIDER_SHARE *share,
4187 const char *dbtable_name,
4188 int dbtable_name_length
4189 ) {
4190 const char *ptr_db, *ptr_table;
4191 my_ptrdiff_t ptr_diff_db, ptr_diff_table;
4192 DBUG_ENTER("spider_set_connect_info_default_dbtable");
4193 ptr_db = strchr(dbtable_name, FN_LIBCHAR);
4194 ptr_db++;
4195 ptr_diff_db = PTR_BYTE_DIFF(ptr_db, dbtable_name);
4196 DBUG_PRINT("info",("spider ptr_diff_db = %lld", (longlong) ptr_diff_db));
4197 ptr_table = strchr(ptr_db, FN_LIBCHAR);
4198 ptr_table++;
4199 ptr_diff_table = PTR_BYTE_DIFF(ptr_table, ptr_db);
4200 DBUG_PRINT("info",("spider ptr_diff_table = %lld", (longlong) ptr_diff_table));
4201 DBUG_RETURN(spider_set_connect_info_default_db_table(
4202 share,
4203 ptr_db,
4204 (uint)(ptr_diff_table - 1),
4205 ptr_table,
4206 (uint)(dbtable_name_length - ptr_diff_db - ptr_diff_table)
4207 ));
4208 }
4209
4210 #ifndef DBUG_OFF
spider_print_keys(const char * key,uint length)4211 void spider_print_keys(
4212 const char *key,
4213 uint length
4214 ) {
4215 const char *end_ptr;
4216 uint roop_count = 1;
4217 DBUG_ENTER("spider_print_keys");
4218 DBUG_PRINT("info",("spider key_length=%u", length));
4219 end_ptr = key + length;
4220 while (key < end_ptr)
4221 {
4222 DBUG_PRINT("info",("spider key[%u]=%s", roop_count, key));
4223 key = strchr(key, '\0') + 1;
4224 roop_count++;
4225 }
4226 DBUG_VOID_RETURN;
4227 }
4228 #endif
4229
spider_create_conn_keys(SPIDER_SHARE * share)4230 int spider_create_conn_keys(
4231 SPIDER_SHARE *share
4232 ) {
4233 int roop_count, roop_count2;
4234 char *tmp_name, port_str[6];
4235 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4236 char *tmp_hs_r_name, *tmp_hs_w_name;
4237 #endif
4238 uint length_base = sizeof(uint) * share->all_link_count;
4239 uint *conn_keys_lengths;
4240 uint *sql_dbton_ids;
4241 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4242 uint *hs_dbton_ids;
4243 uint *hs_r_conn_keys_lengths;
4244 uint *hs_w_conn_keys_lengths;
4245 #endif
4246 DBUG_ENTER("spider_create_conn_keys");
4247 char *ptr;
4248 uint length = length_base * 2;
4249 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4250 length += length_base * 3;
4251 #endif
4252 ptr = (char *) my_alloca(length);
4253 if (!ptr)
4254 {
4255 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
4256 }
4257 conn_keys_lengths = (uint *) ptr;
4258 ptr += length_base;
4259 sql_dbton_ids = (uint *) ptr;
4260 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4261 ptr += length_base;
4262 hs_dbton_ids = (uint *) ptr;
4263 ptr += length_base;
4264 hs_r_conn_keys_lengths = (uint *) ptr;
4265 ptr += length_base;
4266 hs_w_conn_keys_lengths = (uint *) ptr;
4267 #endif
4268
4269 share->conn_keys_charlen = 0;
4270 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4271 share->hs_read_conn_keys_charlen = 0;
4272 share->hs_write_conn_keys_charlen = 0;
4273 #endif
4274 for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++)
4275 {
4276 bool get_sql_id = FALSE;
4277 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4278 bool get_nosql_id = FALSE;
4279 #endif
4280 for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++)
4281 {
4282 DBUG_PRINT("info",("spider share->tgt_wrappers[%d]=%s", roop_count,
4283 share->tgt_wrappers[roop_count]));
4284 DBUG_PRINT("info",("spider spider_dbton[%d].wrapper=%s", roop_count2,
4285 spider_dbton[roop_count2].wrapper ?
4286 spider_dbton[roop_count2].wrapper : "NULL"));
4287 if (
4288 spider_dbton[roop_count2].wrapper &&
4289 !strcmp(share->tgt_wrappers[roop_count],
4290 spider_dbton[roop_count2].wrapper)
4291 ) {
4292 spider_set_bit(share->dbton_bitmap, roop_count2);
4293 if (
4294 !get_sql_id &&
4295 spider_dbton[roop_count2].db_access_type == SPIDER_DB_ACCESS_TYPE_SQL
4296 ) {
4297 sql_dbton_ids[roop_count] = roop_count2;
4298 get_sql_id = TRUE;
4299 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4300 if (get_nosql_id)
4301 #endif
4302 break;
4303 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4304 else
4305 continue;
4306 #endif
4307 }
4308 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4309 if (
4310 !get_nosql_id &&
4311 spider_dbton[roop_count2].db_access_type ==
4312 SPIDER_DB_ACCESS_TYPE_NOSQL
4313 ) {
4314 hs_dbton_ids[roop_count] = roop_count2;
4315 get_nosql_id = TRUE;
4316 if (get_sql_id)
4317 break;
4318 }
4319 #endif
4320 }
4321 }
4322 if (!get_sql_id)
4323 sql_dbton_ids[roop_count] = SPIDER_DBTON_SIZE;
4324 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4325 if (!get_nosql_id)
4326 hs_dbton_ids[roop_count] = SPIDER_DBTON_SIZE;
4327 #endif
4328
4329 bool tables_on_different_db_are_joinable;
4330 if (get_sql_id)
4331 {
4332 tables_on_different_db_are_joinable =
4333 spider_dbton[sql_dbton_ids[roop_count]].db_util->
4334 tables_on_different_db_are_joinable();
4335 } else {
4336 tables_on_different_db_are_joinable = TRUE;
4337 }
4338 conn_keys_lengths[roop_count]
4339 = 1
4340 + share->tgt_wrappers_lengths[roop_count] + 1
4341 + share->tgt_hosts_lengths[roop_count] + 1
4342 + 5 + 1
4343 + share->tgt_sockets_lengths[roop_count] + 1
4344 + (tables_on_different_db_are_joinable ?
4345 0 : share->tgt_dbs_lengths[roop_count] + 1)
4346 + share->tgt_usernames_lengths[roop_count] + 1
4347 + share->tgt_passwords_lengths[roop_count] + 1
4348 + share->tgt_ssl_cas_lengths[roop_count] + 1
4349 + share->tgt_ssl_capaths_lengths[roop_count] + 1
4350 + share->tgt_ssl_certs_lengths[roop_count] + 1
4351 + share->tgt_ssl_ciphers_lengths[roop_count] + 1
4352 + share->tgt_ssl_keys_lengths[roop_count] + 1
4353 + 1 + 1
4354 + share->tgt_default_files_lengths[roop_count] + 1
4355 + share->tgt_default_groups_lengths[roop_count] + 1
4356 + share->tgt_dsns_lengths[roop_count];
4357 share->conn_keys_charlen += conn_keys_lengths[roop_count] + 2;
4358 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4359 hs_r_conn_keys_lengths[roop_count]
4360 = 1
4361 + share->tgt_wrappers_lengths[roop_count] + 1
4362 + share->tgt_hosts_lengths[roop_count] + 1
4363 + 5 + 1
4364 + share->hs_read_socks_lengths[roop_count];
4365 share->hs_read_conn_keys_charlen +=
4366 hs_r_conn_keys_lengths[roop_count] + 2;
4367 hs_w_conn_keys_lengths[roop_count]
4368 = 1
4369 + share->tgt_wrappers_lengths[roop_count] + 1
4370 + share->tgt_hosts_lengths[roop_count] + 1
4371 + 5 + 1
4372 + share->hs_write_socks_lengths[roop_count];
4373 share->hs_write_conn_keys_charlen +=
4374 hs_w_conn_keys_lengths[roop_count] + 2;
4375 #endif
4376 }
4377 if (!(share->conn_keys = (char **)
4378 spider_bulk_alloc_mem(spider_current_trx, 45,
4379 __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL),
4380 &share->conn_keys, sizeof(char *) * share->all_link_count,
4381 &share->conn_keys_lengths, length_base,
4382 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
4383 &share->conn_keys_hash_value,
4384 sizeof(my_hash_value_type) * share->all_link_count,
4385 #endif
4386 &tmp_name, sizeof(char) * share->conn_keys_charlen,
4387 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4388 &share->hs_read_conn_keys, sizeof(char *) * share->all_link_count,
4389 &share->hs_read_conn_keys_lengths, length_base,
4390 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
4391 &share->hs_read_conn_keys_hash_value,
4392 sizeof(my_hash_value_type) * share->all_link_count,
4393 #endif
4394 &tmp_hs_r_name, sizeof(char) * share->hs_read_conn_keys_charlen,
4395 &share->hs_write_conn_keys, sizeof(char *) * share->all_link_count,
4396 &share->hs_write_conn_keys_lengths, length_base,
4397 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
4398 &share->hs_write_conn_keys_hash_value,
4399 sizeof(my_hash_value_type) * share->all_link_count,
4400 #endif
4401 &tmp_hs_w_name, sizeof(char) * share->hs_write_conn_keys_charlen,
4402 #endif
4403 &share->sql_dbton_ids, length_base,
4404 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4405 &share->hs_dbton_ids, length_base,
4406 #endif
4407 NullS))
4408 ) {
4409 my_afree(conn_keys_lengths);
4410 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
4411 }
4412 share->conn_keys_length = share->all_link_count;
4413 memcpy(share->conn_keys_lengths, conn_keys_lengths,
4414 length_base);
4415 memcpy(share->sql_dbton_ids, sql_dbton_ids, length_base);
4416 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4417 share->hs_read_conn_keys_length = share->all_link_count;
4418 share->hs_write_conn_keys_length = share->all_link_count;
4419 memcpy(share->hs_read_conn_keys_lengths, hs_r_conn_keys_lengths,
4420 length_base);
4421 memcpy(share->hs_write_conn_keys_lengths, hs_w_conn_keys_lengths,
4422 length_base);
4423 memcpy(share->hs_dbton_ids, hs_dbton_ids, length_base);
4424 #endif
4425
4426 my_afree(conn_keys_lengths);
4427
4428 for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++)
4429 {
4430 bool tables_on_different_db_are_joinable;
4431 if (share->sql_dbton_ids[roop_count] != SPIDER_DBTON_SIZE)
4432 {
4433 tables_on_different_db_are_joinable =
4434 spider_dbton[share->sql_dbton_ids[roop_count]].db_util->
4435 tables_on_different_db_are_joinable();
4436 } else {
4437 tables_on_different_db_are_joinable = TRUE;
4438 }
4439
4440 share->conn_keys[roop_count] = tmp_name;
4441 *tmp_name = '0';
4442 DBUG_PRINT("info",("spider tgt_wrappers[%d]=%s", roop_count,
4443 share->tgt_wrappers[roop_count]));
4444 tmp_name = strmov(tmp_name + 1, share->tgt_wrappers[roop_count]);
4445 DBUG_PRINT("info",("spider tgt_hosts[%d]=%s", roop_count,
4446 share->tgt_hosts[roop_count]));
4447 tmp_name = strmov(tmp_name + 1, share->tgt_hosts[roop_count]);
4448 my_sprintf(port_str, (port_str, "%05ld", share->tgt_ports[roop_count]));
4449 DBUG_PRINT("info",("spider port_str=%s", port_str));
4450 tmp_name = strmov(tmp_name + 1, port_str);
4451 if (share->tgt_sockets[roop_count])
4452 {
4453 DBUG_PRINT("info",("spider tgt_sockets[%d]=%s", roop_count,
4454 share->tgt_sockets[roop_count]));
4455 tmp_name = strmov(tmp_name + 1, share->tgt_sockets[roop_count]);
4456 } else
4457 tmp_name++;
4458 if (!tables_on_different_db_are_joinable)
4459 {
4460 if (share->tgt_dbs[roop_count])
4461 {
4462 DBUG_PRINT("info",("spider tgt_dbs[%d]=%s", roop_count,
4463 share->tgt_dbs[roop_count]));
4464 tmp_name = strmov(tmp_name + 1, share->tgt_dbs[roop_count]);
4465 } else
4466 tmp_name++;
4467 }
4468 if (share->tgt_usernames[roop_count])
4469 {
4470 DBUG_PRINT("info",("spider tgt_usernames[%d]=%s", roop_count,
4471 share->tgt_usernames[roop_count]));
4472 tmp_name = strmov(tmp_name + 1, share->tgt_usernames[roop_count]);
4473 } else
4474 tmp_name++;
4475 if (share->tgt_passwords[roop_count])
4476 {
4477 DBUG_PRINT("info",("spider tgt_passwords[%d]=%s", roop_count,
4478 share->tgt_passwords[roop_count]));
4479 tmp_name = strmov(tmp_name + 1, share->tgt_passwords[roop_count]);
4480 } else
4481 tmp_name++;
4482 if (share->tgt_ssl_cas[roop_count])
4483 {
4484 DBUG_PRINT("info",("spider tgt_ssl_cas[%d]=%s", roop_count,
4485 share->tgt_ssl_cas[roop_count]));
4486 tmp_name = strmov(tmp_name + 1, share->tgt_ssl_cas[roop_count]);
4487 } else
4488 tmp_name++;
4489 if (share->tgt_ssl_capaths[roop_count])
4490 {
4491 DBUG_PRINT("info",("spider tgt_ssl_capaths[%d]=%s", roop_count,
4492 share->tgt_ssl_capaths[roop_count]));
4493 tmp_name = strmov(tmp_name + 1, share->tgt_ssl_capaths[roop_count]);
4494 } else
4495 tmp_name++;
4496 if (share->tgt_ssl_certs[roop_count])
4497 {
4498 DBUG_PRINT("info",("spider tgt_ssl_certs[%d]=%s", roop_count,
4499 share->tgt_ssl_certs[roop_count]));
4500 tmp_name = strmov(tmp_name + 1, share->tgt_ssl_certs[roop_count]);
4501 } else
4502 tmp_name++;
4503 if (share->tgt_ssl_ciphers[roop_count])
4504 {
4505 DBUG_PRINT("info",("spider tgt_ssl_ciphers[%d]=%s", roop_count,
4506 share->tgt_ssl_ciphers[roop_count]));
4507 tmp_name = strmov(tmp_name + 1, share->tgt_ssl_ciphers[roop_count]);
4508 } else
4509 tmp_name++;
4510 if (share->tgt_ssl_keys[roop_count])
4511 {
4512 DBUG_PRINT("info",("spider tgt_ssl_keys[%d]=%s", roop_count,
4513 share->tgt_ssl_keys[roop_count]));
4514 tmp_name = strmov(tmp_name + 1, share->tgt_ssl_keys[roop_count]);
4515 } else
4516 tmp_name++;
4517 tmp_name++;
4518 *tmp_name = '0' + ((char) share->tgt_ssl_vscs[roop_count]);
4519 if (share->tgt_default_files[roop_count])
4520 {
4521 DBUG_PRINT("info",("spider tgt_default_files[%d]=%s", roop_count,
4522 share->tgt_default_files[roop_count]));
4523 tmp_name = strmov(tmp_name + 1, share->tgt_default_files[roop_count]);
4524 } else
4525 tmp_name++;
4526 if (share->tgt_default_groups[roop_count])
4527 {
4528 DBUG_PRINT("info",("spider tgt_default_groups[%d]=%s", roop_count,
4529 share->tgt_default_groups[roop_count]));
4530 tmp_name = strmov(tmp_name + 1, share->tgt_default_groups[roop_count]);
4531 } else
4532 tmp_name++;
4533 if (share->tgt_dsns[roop_count])
4534 {
4535 DBUG_PRINT("info",("spider tgt_dsns[%d]=%s", roop_count,
4536 share->tgt_dsns[roop_count]));
4537 tmp_name = strmov(tmp_name + 1, share->tgt_dsns[roop_count]);
4538 } else
4539 tmp_name++;
4540 tmp_name++;
4541 tmp_name++;
4542 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
4543 share->conn_keys_hash_value[roop_count] = my_calc_hash(
4544 &spider_open_connections, (uchar*) share->conn_keys[roop_count],
4545 share->conn_keys_lengths[roop_count]);
4546 #endif
4547 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4548 share->hs_read_conn_keys[roop_count] = tmp_hs_r_name;
4549 *tmp_hs_r_name = '0';
4550 DBUG_PRINT("info",("spider tgt_wrappers[%d]=%s", roop_count,
4551 share->tgt_wrappers[roop_count]));
4552 tmp_hs_r_name = strmov(tmp_hs_r_name + 1, share->tgt_wrappers[roop_count]);
4553 DBUG_PRINT("info",("spider tgt_hosts[%d]=%s", roop_count,
4554 share->tgt_hosts[roop_count]));
4555 tmp_hs_r_name = strmov(tmp_hs_r_name + 1, share->tgt_hosts[roop_count]);
4556 my_sprintf(port_str, (port_str, "%05ld",
4557 share->hs_read_ports[roop_count]));
4558 DBUG_PRINT("info",("spider port_str=%s", port_str));
4559 tmp_hs_r_name = strmov(tmp_hs_r_name + 1, port_str);
4560 if (share->hs_read_socks[roop_count])
4561 {
4562 DBUG_PRINT("info",("spider hs_read_socks[%d]=%s", roop_count,
4563 share->hs_read_socks[roop_count]));
4564 tmp_hs_r_name = strmov(tmp_hs_r_name + 1,
4565 share->hs_read_socks[roop_count]);
4566 } else
4567 tmp_hs_r_name++;
4568 tmp_hs_r_name++;
4569 tmp_hs_r_name++;
4570 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
4571 share->hs_read_conn_keys_hash_value[roop_count] = my_calc_hash(
4572 &spider_open_connections, (uchar*) share->hs_read_conn_keys[roop_count],
4573 share->hs_read_conn_keys_lengths[roop_count]);
4574 #endif
4575 share->hs_write_conn_keys[roop_count] = tmp_hs_w_name;
4576 *tmp_hs_w_name = '0';
4577 DBUG_PRINT("info",("spider tgt_wrappers[%d]=%s", roop_count,
4578 share->tgt_wrappers[roop_count]));
4579 tmp_hs_w_name = strmov(tmp_hs_w_name + 1, share->tgt_wrappers[roop_count]);
4580 DBUG_PRINT("info",("spider tgt_hosts[%d]=%s", roop_count,
4581 share->tgt_hosts[roop_count]));
4582 tmp_hs_w_name = strmov(tmp_hs_w_name + 1, share->tgt_hosts[roop_count]);
4583 my_sprintf(port_str, (port_str, "%05ld",
4584 share->hs_write_ports[roop_count]));
4585 DBUG_PRINT("info",("spider port_str=%s", port_str));
4586 tmp_hs_w_name = strmov(tmp_hs_w_name + 1, port_str);
4587 if (share->hs_write_socks[roop_count])
4588 {
4589 DBUG_PRINT("info",("spider hs_write_socks[%d]=%s", roop_count,
4590 share->hs_write_socks[roop_count]));
4591 tmp_hs_w_name = strmov(tmp_hs_w_name + 1,
4592 share->hs_write_socks[roop_count]);
4593 } else
4594 tmp_hs_w_name++;
4595 tmp_hs_w_name++;
4596 tmp_hs_w_name++;
4597 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
4598 share->hs_write_conn_keys_hash_value[roop_count] = my_calc_hash(
4599 &spider_open_connections, (uchar*) share->hs_write_conn_keys[roop_count],
4600 share->hs_write_conn_keys_lengths[roop_count]);
4601 #endif
4602 #endif
4603 }
4604 for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++)
4605 {
4606 if (spider_bit_is_set(share->dbton_bitmap, roop_count2))
4607 {
4608 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4609 if (spider_dbton[roop_count2].db_access_type ==
4610 SPIDER_DB_ACCESS_TYPE_SQL)
4611 {
4612 #endif
4613 share->use_sql_dbton_ids[share->use_dbton_count] = roop_count2;
4614 share->sql_dbton_id_to_seq[roop_count2] = share->use_dbton_count;
4615 share->use_sql_dbton_count++;
4616 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4617 } else {
4618 share->use_hs_dbton_ids[share->use_hs_dbton_count] = roop_count2;
4619 share->hs_dbton_id_to_seq[roop_count2] = share->use_hs_dbton_count;
4620 share->use_hs_dbton_count++;
4621 }
4622 #endif
4623 share->use_dbton_ids[share->use_dbton_count] = roop_count2;
4624 share->dbton_id_to_seq[roop_count2] = share->use_dbton_count;
4625 share->use_dbton_count++;
4626 }
4627 }
4628 DBUG_RETURN(0);
4629 }
4630
spider_create_share(const char * table_name,TABLE_SHARE * table_share,partition_info * part_info,my_hash_value_type hash_value,int * error_num)4631 SPIDER_SHARE *spider_create_share(
4632 const char *table_name,
4633 TABLE_SHARE *table_share,
4634 #ifdef WITH_PARTITION_STORAGE_ENGINE
4635 partition_info *part_info,
4636 #endif
4637 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
4638 my_hash_value_type hash_value,
4639 #endif
4640 int *error_num
4641 ) {
4642 int bitmap_size, roop_count;
4643 uint length;
4644 int use_table_charset;
4645 SPIDER_SHARE *share;
4646 char *tmp_name;
4647 longlong *tmp_cardinality, *tmp_static_key_cardinality;
4648 uchar *tmp_cardinality_upd, *tmp_table_mon_mutex_bitmap;
4649 char buf[MAX_FIELD_WIDTH], *buf_pos;
4650 char link_idx_str[SPIDER_SQL_INT_LEN];
4651 #ifdef HA_HAS_CHECKSUM_EXTENDED
4652 bool checksum_support = TRUE;
4653 #endif
4654 DBUG_ENTER("spider_create_share");
4655 length = (uint) strlen(table_name);
4656 bitmap_size = spider_bitmap_size(table_share->fields);
4657 if (!(share = (SPIDER_SHARE *)
4658 spider_bulk_malloc(spider_current_trx, 46, MYF(MY_WME | MY_ZEROFILL),
4659 &share, (uint) (sizeof(*share)),
4660 &tmp_name, (uint) (length + 1),
4661 &tmp_static_key_cardinality,
4662 (uint) (sizeof(*tmp_static_key_cardinality) * table_share->keys),
4663 &tmp_cardinality,
4664 (uint) (sizeof(*tmp_cardinality) * table_share->fields),
4665 &tmp_cardinality_upd,
4666 (uint) (sizeof(*tmp_cardinality_upd) * bitmap_size),
4667 &tmp_table_mon_mutex_bitmap,
4668 (uint) (sizeof(*tmp_table_mon_mutex_bitmap) *
4669 ((spider_param_udf_table_mon_mutex_count() + 7) / 8)),
4670 NullS))
4671 ) {
4672 *error_num = HA_ERR_OUT_OF_MEM;
4673 goto error_alloc_share;
4674 }
4675
4676 SPD_INIT_ALLOC_ROOT(&share->mem_root, 4096, 0, MYF(MY_WME));
4677 share->use_count = 0;
4678 share->use_dbton_count = 0;
4679 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4680 share->use_hs_dbton_count = 0;
4681 #endif
4682 share->table_name_length = length;
4683 share->table_name = tmp_name;
4684 strmov(share->table_name, table_name);
4685 share->static_key_cardinality = tmp_static_key_cardinality;
4686 share->cardinality = tmp_cardinality;
4687 share->cardinality_upd = tmp_cardinality_upd;
4688 share->table_mon_mutex_bitmap = tmp_table_mon_mutex_bitmap;
4689 share->bitmap_size = bitmap_size;
4690 share->table_share = table_share;
4691 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
4692 share->table_name_hash_value = hash_value;
4693 #ifdef WITH_PARTITION_STORAGE_ENGINE
4694 share->table_path_hash_value = my_calc_hash(&spider_open_tables,
4695 (uchar*) table_share->path.str, table_share->path.length);
4696 #endif
4697 #endif
4698 #ifndef WITHOUT_SPIDER_BG_SEARCH
4699 share->table.s = table_share;
4700 share->table.field = table_share->field;
4701 share->table.key_info = table_share->key_info;
4702 share->table.read_set = &table_share->all_set;
4703 #endif
4704
4705 if (table_share->keys > 0 &&
4706 !(share->key_hint = new spider_string[table_share->keys])
4707 ) {
4708 *error_num = HA_ERR_OUT_OF_MEM;
4709 goto error_init_hint_string;
4710 }
4711 for (roop_count = 0; roop_count < (int) table_share->keys; roop_count++)
4712 share->key_hint[roop_count].init_calc_mem(95);
4713 DBUG_PRINT("info",("spider share->key_hint=%p", share->key_hint));
4714
4715 if ((*error_num = spider_parse_connect_info(share, table_share,
4716 #ifdef WITH_PARTITION_STORAGE_ENGINE
4717 part_info,
4718 #endif
4719 0)))
4720 goto error_parse_connect_string;
4721
4722 for (roop_count = 0; roop_count < (int) share->all_link_count;
4723 roop_count++)
4724 {
4725 my_sprintf(link_idx_str, (link_idx_str, "%010d", roop_count));
4726 buf_pos = strmov(buf, share->table_name);
4727 buf_pos = strmov(buf_pos, link_idx_str);
4728 *buf_pos = '\0';
4729 spider_set_bit(tmp_table_mon_mutex_bitmap,
4730 spider_udf_calc_hash(buf, spider_param_udf_table_mon_mutex_count())
4731 );
4732 }
4733
4734 use_table_charset = spider_param_use_table_charset(
4735 share->use_table_charset);
4736 if (table_share->table_charset && use_table_charset)
4737 share->access_charset = table_share->table_charset;
4738 else
4739 share->access_charset = system_charset_info;
4740
4741 if ((*error_num = spider_create_conn_keys(share)))
4742 goto error_create_conn_keys;
4743
4744 if (share->table_count_mode & 1)
4745 share->additional_table_flags |= HA_STATS_RECORDS_IS_EXACT;
4746 if (share->table_count_mode & 2)
4747 share->additional_table_flags |= HA_HAS_RECORDS;
4748
4749 #if MYSQL_VERSION_ID < 50500
4750 if (pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST))
4751 #else
4752 if (mysql_mutex_init(spd_key_mutex_share,
4753 &share->mutex, MY_MUTEX_INIT_FAST))
4754 #endif
4755 {
4756 *error_num = HA_ERR_OUT_OF_MEM;
4757 goto error_init_mutex;
4758 }
4759
4760 #if MYSQL_VERSION_ID < 50500
4761 if (pthread_mutex_init(&share->sts_mutex, MY_MUTEX_INIT_FAST))
4762 #else
4763 if (mysql_mutex_init(spd_key_mutex_share_sts,
4764 &share->sts_mutex, MY_MUTEX_INIT_FAST))
4765 #endif
4766 {
4767 *error_num = HA_ERR_OUT_OF_MEM;
4768 goto error_init_sts_mutex;
4769 }
4770
4771 #if MYSQL_VERSION_ID < 50500
4772 if (pthread_mutex_init(&share->crd_mutex, MY_MUTEX_INIT_FAST))
4773 #else
4774 if (mysql_mutex_init(spd_key_mutex_share_crd,
4775 &share->crd_mutex, MY_MUTEX_INIT_FAST))
4776 #endif
4777 {
4778 *error_num = HA_ERR_OUT_OF_MEM;
4779 goto error_init_crd_mutex;
4780 }
4781
4782 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
4783 if (!(share->lgtm_tblhnd_share =
4784 spider_get_lgtm_tblhnd_share(tmp_name, length, hash_value, FALSE, TRUE,
4785 error_num)))
4786 #else
4787 if (!(share->lgtm_tblhnd_share =
4788 spider_get_lgtm_tblhnd_share(tmp_name, length, FALSE, TRUE, error_num)))
4789 #endif
4790 {
4791 goto error_get_lgtm_tblhnd_share;
4792 }
4793
4794 if (!(share->wide_share =
4795 spider_get_wide_share(share, table_share, error_num)))
4796 goto error_get_wide_share;
4797
4798 for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++)
4799 {
4800 if (spider_bit_is_set(share->dbton_bitmap, roop_count))
4801 {
4802 if (!(share->dbton_share[roop_count] =
4803 spider_dbton[roop_count].create_db_share(share)))
4804 {
4805 *error_num = HA_ERR_OUT_OF_MEM;
4806 goto error_init_dbton;
4807 }
4808 if ((*error_num = share->dbton_share[roop_count]->init()))
4809 {
4810 goto error_init_dbton;
4811 }
4812 #ifdef HA_HAS_CHECKSUM_EXTENDED
4813 if (
4814 spider_dbton[roop_count].db_access_type == SPIDER_DB_ACCESS_TYPE_SQL &&
4815 !share->dbton_share[roop_count]->checksum_support()
4816 ) {
4817 checksum_support = FALSE;
4818 }
4819 #endif
4820 }
4821 }
4822 #ifdef HA_HAS_CHECKSUM_EXTENDED
4823 if (checksum_support)
4824 {
4825 share->additional_table_flags |=
4826 HA_HAS_OLD_CHECKSUM |
4827 HA_HAS_NEW_CHECKSUM;
4828 }
4829 #endif
4830 DBUG_RETURN(share);
4831
4832 /*
4833 roop_count = SPIDER_DBTON_SIZE - 1;
4834 */
4835 error_init_dbton:
4836 for (; roop_count >= 0; roop_count--)
4837 {
4838 if (share->dbton_share[roop_count])
4839 {
4840 delete share->dbton_share[roop_count];
4841 share->dbton_share[roop_count] = NULL;
4842 }
4843 }
4844 spider_free_wide_share(share->wide_share);
4845 error_get_wide_share:
4846 error_get_lgtm_tblhnd_share:
4847 pthread_mutex_destroy(&share->crd_mutex);
4848 error_init_crd_mutex:
4849 pthread_mutex_destroy(&share->sts_mutex);
4850 error_init_sts_mutex:
4851 pthread_mutex_destroy(&share->mutex);
4852 error_init_mutex:
4853 error_create_conn_keys:
4854 error_parse_connect_string:
4855 error_init_hint_string:
4856 spider_free_share_alloc(share);
4857 spider_free(spider_current_trx, share, MYF(0));
4858 error_alloc_share:
4859 DBUG_RETURN(NULL);
4860 }
4861
spider_get_share(const char * table_name,TABLE * table,THD * thd,ha_spider * spider,int * error_num)4862 SPIDER_SHARE *spider_get_share(
4863 const char *table_name,
4864 TABLE *table,
4865 THD *thd,
4866 ha_spider *spider,
4867 int *error_num
4868 ) {
4869 SPIDER_SHARE *share;
4870 TABLE_SHARE *table_share = table->s;
4871 SPIDER_RESULT_LIST *result_list = &spider->result_list;
4872 uint length, tmp_conn_link_idx = 0, buf_sz;
4873 char *tmp_name, *tmp_cid;
4874 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
4875 char *tmp_hs_r_name, *tmp_hs_w_name;
4876 #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
4877 uint32 *tmp_hs_r_ret_fields, *tmp_hs_w_ret_fields;
4878 #endif
4879 #endif
4880 int roop_count;
4881 double sts_interval;
4882 int sts_mode;
4883 #ifdef WITH_PARTITION_STORAGE_ENGINE
4884 int sts_sync;
4885 int auto_increment_mode;
4886 #endif
4887 double crd_interval;
4888 int crd_mode;
4889 #ifdef WITH_PARTITION_STORAGE_ENGINE
4890 int crd_sync;
4891 #endif
4892 char first_byte;
4893 int semi_table_lock_conn;
4894 int search_link_idx;
4895 uint sql_command = thd_sql_command(thd);
4896 SPIDER_Open_tables_backup open_tables_backup;
4897 MEM_ROOT mem_root;
4898 TABLE *table_tables = NULL;
4899 bool init_mem_root = FALSE;
4900 bool same_server_link;
4901 int load_sts_at_startup;
4902 int load_crd_at_startup;
4903 user_var_entry *loop_check;
4904 char *loop_check_buf;
4905 TABLE_SHARE *top_share;
4906 LEX_CSTRING lex_str;
4907 DBUG_ENTER("spider_get_share");
4908 top_share = spider->wide_handler->top_share;
4909 length = (uint) strlen(table_name);
4910 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
4911 my_hash_value_type hash_value = my_calc_hash(&spider_open_tables,
4912 (uchar*) table_name, length);
4913 #endif
4914 if (top_share)
4915 {
4916 lex_str.length = top_share->path.length + SPIDER_SQL_LOP_CHK_PRM_PRF_LEN;
4917 buf_sz = spider_unique_id.length > SPIDER_SQL_LOP_CHK_PRM_PRF_LEN ?
4918 top_share->path.length + spider_unique_id.length + 2 :
4919 lex_str.length + 2;
4920 loop_check_buf = (char *) my_alloca(buf_sz);
4921 if (unlikely(!loop_check_buf))
4922 {
4923 *error_num = HA_ERR_OUT_OF_MEM;
4924 DBUG_RETURN(NULL);
4925 }
4926 lex_str.str = loop_check_buf + buf_sz - lex_str.length - 2;
4927 memcpy((void *) lex_str.str,
4928 SPIDER_SQL_LOP_CHK_PRM_PRF_STR, SPIDER_SQL_LOP_CHK_PRM_PRF_LEN);
4929 memcpy((void *) (lex_str.str + SPIDER_SQL_LOP_CHK_PRM_PRF_LEN),
4930 top_share->path.str, top_share->path.length);
4931 ((char *) lex_str.str)[lex_str.length] = '\0';
4932 DBUG_PRINT("info",("spider loop check param name=%s", lex_str.str));
4933 loop_check = get_variable(&thd->user_vars, &lex_str, FALSE);
4934 if (loop_check && loop_check->type == STRING_RESULT)
4935 {
4936 lex_str.length = top_share->path.length + spider_unique_id.length + 1;
4937 lex_str.str = loop_check_buf + buf_sz - top_share->path.length -
4938 spider_unique_id.length - 2;
4939 memcpy((void *) lex_str.str, spider_unique_id.str,
4940 spider_unique_id.length);
4941 ((char *) lex_str.str)[lex_str.length - 1] = '-';
4942 ((char *) lex_str.str)[lex_str.length] = '\0';
4943 DBUG_PRINT("info",("spider loop check key=%s", lex_str.str));
4944 DBUG_PRINT("info",("spider loop check param value=%s",
4945 loop_check->value));
4946 if (unlikely(strstr(loop_check->value, lex_str.str)))
4947 {
4948 *error_num = ER_SPIDER_INFINITE_LOOP_NUM;
4949 my_printf_error(*error_num, ER_SPIDER_INFINITE_LOOP_STR, MYF(0),
4950 top_share->db.str, top_share->table_name.str);
4951 my_afree(loop_check_buf);
4952 DBUG_RETURN(NULL);
4953 }
4954 }
4955 my_afree(loop_check_buf);
4956 }
4957 pthread_mutex_lock(&spider_tbl_mutex);
4958 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
4959 if (!(share = (SPIDER_SHARE*) my_hash_search_using_hash_value(
4960 &spider_open_tables, hash_value, (uchar*) table_name, length)))
4961 #else
4962 if (!(share = (SPIDER_SHARE*) my_hash_search(&spider_open_tables,
4963 (uchar*) table_name, length)))
4964 #endif
4965 {
4966 if (!(share = spider_create_share(
4967 table_name, table_share,
4968 #ifdef WITH_PARTITION_STORAGE_ENGINE
4969 table->part_info,
4970 #endif
4971 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
4972 hash_value,
4973 #endif
4974 error_num
4975 ))) {
4976 goto error_alloc_share;
4977 }
4978
4979 uint old_elements = spider_open_tables.array.max_element;
4980 #ifdef HASH_UPDATE_WITH_HASH_VALUE
4981 if (my_hash_insert_with_hash_value(&spider_open_tables, hash_value,
4982 (uchar*) share))
4983 #else
4984 if (my_hash_insert(&spider_open_tables, (uchar*) share))
4985 #endif
4986 {
4987 *error_num = HA_ERR_OUT_OF_MEM;
4988 goto error_hash_insert;
4989 }
4990 if (spider_open_tables.array.max_element > old_elements)
4991 {
4992 spider_alloc_calc_mem(spider_current_trx,
4993 spider_open_tables,
4994 (spider_open_tables.array.max_element - old_elements) *
4995 spider_open_tables.array.size_of_element);
4996 }
4997
4998 spider->share = share;
4999 spider->conn_link_idx = &tmp_conn_link_idx;
5000
5001 share->use_count++;
5002 pthread_mutex_unlock(&spider_tbl_mutex);
5003
5004 if (!share->link_status_init)
5005 {
5006 pthread_mutex_lock(&share->mutex);
5007 for (roop_count = 0;
5008 roop_count < (int) spider_param_udf_table_mon_mutex_count();
5009 roop_count++
5010 ) {
5011 if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count))
5012 pthread_mutex_lock(&spider_udf_table_mon_mutexes[roop_count]);
5013 }
5014 if (!share->link_status_init)
5015 {
5016 /*
5017 The link statuses need to be refreshed from the spider_tables table
5018 if the operation:
5019 - Is not a DROP TABLE on a permanent table; or
5020 - Is an ALTER TABLE.
5021
5022 Note that SHOW CREATE TABLE is not excluded, because the commands
5023 that follow it require up-to-date link statuses.
5024 */
5025 if ((table_share->tmp_table == NO_TMP_TABLE &&
5026 sql_command != SQLCOM_DROP_TABLE) ||
5027 /* for alter change link status */
5028 sql_command == SQLCOM_ALTER_TABLE)
5029 {
5030 SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME));
5031 init_mem_root = TRUE;
5032
5033 if (
5034 !(table_tables = spider_open_sys_table(
5035 thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
5036 SPIDER_SYS_TABLES_TABLE_NAME_LEN, FALSE, &open_tables_backup,
5037 FALSE, error_num))
5038 ) {
5039 for (roop_count = 0;
5040 roop_count < (int) spider_param_udf_table_mon_mutex_count();
5041 roop_count++
5042 ) {
5043 if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count))
5044 pthread_mutex_unlock(&spider_udf_table_mon_mutexes[roop_count]);
5045 }
5046 pthread_mutex_unlock(&share->mutex);
5047 share->init_error = TRUE;
5048 share->init_error_time = (time_t) time((time_t*) 0);
5049 share->init = TRUE;
5050 spider_free_share(share);
5051 goto error_open_sys_table;
5052 }
5053 *error_num = spider_get_link_statuses(table_tables, share,
5054 &mem_root);
5055 if (*error_num)
5056 {
5057 if (
5058 *error_num != HA_ERR_KEY_NOT_FOUND &&
5059 *error_num != HA_ERR_END_OF_FILE
5060 ) {
5061 for (roop_count = 0;
5062 roop_count < (int) spider_param_udf_table_mon_mutex_count();
5063 roop_count++
5064 ) {
5065 if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count))
5066 pthread_mutex_unlock(&spider_udf_table_mon_mutexes[roop_count]);
5067 }
5068 pthread_mutex_unlock(&share->mutex);
5069 share->init_error = TRUE;
5070 share->init_error_time = (time_t) time((time_t*) 0);
5071 share->init = TRUE;
5072 spider_free_share(share);
5073 spider_close_sys_table(thd, table_tables,
5074 &open_tables_backup, FALSE);
5075 table_tables = NULL;
5076 goto error_open_sys_table;
5077 }
5078 } else {
5079 memcpy(share->alter_table.tmp_link_statuses, share->link_statuses,
5080 sizeof(long) * share->all_link_count);
5081 share->link_status_init = TRUE;
5082 }
5083 spider_close_sys_table(thd, table_tables,
5084 &open_tables_backup, FALSE);
5085 table_tables = NULL;
5086 }
5087 share->have_recovery_link = spider_conn_check_recovery_link(share);
5088 if (init_mem_root)
5089 {
5090 free_root(&mem_root, MYF(0));
5091 init_mem_root = FALSE;
5092 }
5093 }
5094 for (roop_count = 0;
5095 roop_count < (int) spider_param_udf_table_mon_mutex_count();
5096 roop_count++
5097 ) {
5098 if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count))
5099 pthread_mutex_unlock(&spider_udf_table_mon_mutexes[roop_count]);
5100 }
5101 pthread_mutex_unlock(&share->mutex);
5102 }
5103
5104 semi_table_lock_conn = spider_param_semi_table_lock_connection(thd,
5105 share->semi_table_lock_conn);
5106 if (semi_table_lock_conn)
5107 first_byte = '0' +
5108 spider_param_semi_table_lock(thd, share->semi_table_lock);
5109 else
5110 first_byte = '0';
5111
5112 if (!(spider->wide_handler->trx = spider_get_trx(thd, TRUE, error_num)))
5113 {
5114 share->init_error = TRUE;
5115 share->init_error_time = (time_t) time((time_t*) 0);
5116 share->init = TRUE;
5117 spider_free_share(share);
5118 goto error_but_no_delete;
5119 }
5120 spider->set_error_mode();
5121
5122 #ifndef WITHOUT_SPIDER_BG_SEARCH
5123 if (!share->sts_spider_init)
5124 {
5125 pthread_mutex_lock(&share->mutex);
5126 if (!share->sts_spider_init)
5127 {
5128 if ((*error_num = spider_create_spider_object_for_share(
5129 spider->wide_handler->trx, share, &share->sts_spider)))
5130 {
5131 pthread_mutex_unlock(&share->mutex);
5132 share->init_error = TRUE;
5133 share->init_error_time = (time_t) time((time_t*) 0);
5134 share->init = TRUE;
5135 spider_free_share(share);
5136 goto error_sts_spider_init;
5137 }
5138 #ifdef HASH_UPDATE_WITH_HASH_VALUE
5139 share->sts_thread = &spider_table_sts_threads[
5140 hash_value % spider_param_table_sts_thread_count()];
5141 #else
5142 share->sts_thread = &spider_table_sts_threads[
5143 my_calc_hash(&spider_open_tables, (uchar*) table_name, length) %
5144 spider_param_table_sts_thread_count()];
5145 #endif
5146 share->sts_spider_init = TRUE;
5147 }
5148 pthread_mutex_unlock(&share->mutex);
5149 }
5150
5151 if (!share->crd_spider_init)
5152 {
5153 pthread_mutex_lock(&share->mutex);
5154 if (!share->crd_spider_init)
5155 {
5156 if ((*error_num = spider_create_spider_object_for_share(
5157 spider->wide_handler->trx, share, &share->crd_spider)))
5158 {
5159 pthread_mutex_unlock(&share->mutex);
5160 share->init_error = TRUE;
5161 share->init_error_time = (time_t) time((time_t*) 0);
5162 share->init = TRUE;
5163 spider_free_share(share);
5164 goto error_crd_spider_init;
5165 }
5166 #ifdef HASH_UPDATE_WITH_HASH_VALUE
5167 share->crd_thread = &spider_table_crd_threads[
5168 hash_value % spider_param_table_crd_thread_count()];
5169 #else
5170 share->crd_thread = &spider_table_crd_threads[
5171 my_calc_hash(&spider_open_tables, (uchar*) table_name, length) %
5172 spider_param_table_crd_thread_count()];
5173 #endif
5174 share->crd_spider_init = TRUE;
5175 }
5176 pthread_mutex_unlock(&share->mutex);
5177 }
5178 #endif
5179
5180 #ifndef WITHOUT_SPIDER_BG_SEARCH
5181 if (
5182 sql_command != SQLCOM_DROP_TABLE &&
5183 sql_command != SQLCOM_ALTER_TABLE &&
5184 sql_command != SQLCOM_SHOW_CREATE &&
5185 (*error_num = spider_create_mon_threads(spider->wide_handler->trx,
5186 share))
5187 ) {
5188 share->init_error = TRUE;
5189 share->init_error_time = (time_t) time((time_t*) 0);
5190 share->init = TRUE;
5191 spider_free_share(share);
5192 goto error_but_no_delete;
5193 }
5194 #endif
5195
5196 if (!(spider->conn_keys = (char **)
5197 spider_bulk_alloc_mem(spider_current_trx, 47,
5198 __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL),
5199 &spider->conn_keys, sizeof(char *) * share->link_count,
5200 &tmp_name, sizeof(char) * share->conn_keys_charlen,
5201 &spider->conns, sizeof(SPIDER_CONN *) * share->link_count,
5202 &spider->conn_link_idx, sizeof(uint) * share->link_count,
5203 &spider->conn_can_fo, sizeof(uchar) * share->link_bitmap_size,
5204 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
5205 &spider->hs_r_conn_keys, sizeof(char *) * share->link_count,
5206 &tmp_hs_r_name, sizeof(char) * share->hs_read_conn_keys_charlen,
5207 &spider->hs_r_conns, sizeof(SPIDER_CONN *) * share->link_count,
5208 &spider->hs_r_conn_ages, sizeof(ulonglong) * share->link_count,
5209 &spider->hs_w_conn_keys, sizeof(char *) * share->link_count,
5210 &tmp_hs_w_name, sizeof(char) * share->hs_write_conn_keys_charlen,
5211 &spider->hs_w_conns, sizeof(SPIDER_CONN *) * share->link_count,
5212 &spider->hs_w_conn_ages, sizeof(ulonglong) * share->link_count,
5213 #endif
5214 &spider->sql_kind, sizeof(uint) * share->link_count,
5215 &spider->connection_ids, sizeof(ulonglong) * share->link_count,
5216 &spider->conn_kind, sizeof(uint) * share->link_count,
5217 &spider->db_request_id, sizeof(ulonglong) * share->link_count,
5218 &spider->db_request_phase, sizeof(uchar) * share->link_bitmap_size,
5219 &spider->m_handler_opened, sizeof(uchar) * share->link_bitmap_size,
5220 &spider->m_handler_id, sizeof(uint) * share->link_count,
5221 &spider->m_handler_cid, sizeof(char *) * share->link_count,
5222 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
5223 &spider->r_handler_opened, sizeof(uchar) * share->link_bitmap_size,
5224 &spider->r_handler_id, sizeof(uint) * share->link_count,
5225 &spider->r_handler_index, sizeof(uint) * share->link_count,
5226 &spider->w_handler_opened, sizeof(uchar) * share->link_bitmap_size,
5227 &spider->w_handler_id, sizeof(uint) * share->link_count,
5228 &spider->w_handler_index, sizeof(uint) * share->link_count,
5229 #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
5230 &spider->do_hs_direct_update, sizeof(uchar) * share->link_bitmap_size,
5231 &spider->hs_r_ret_fields, sizeof(uint32 *) * share->link_count,
5232 &spider->hs_w_ret_fields, sizeof(uint32 *) * share->link_count,
5233 &spider->hs_r_ret_fields_num, sizeof(size_t) * share->link_count,
5234 &spider->hs_w_ret_fields_num, sizeof(size_t) * share->link_count,
5235 &tmp_hs_r_ret_fields,
5236 sizeof(uint32) * share->link_count * table_share->fields,
5237 &tmp_hs_w_ret_fields,
5238 sizeof(uint32) * share->link_count * table_share->fields,
5239 &spider->tmp_column_bitmap, sizeof(uchar) * share->bitmap_size,
5240 #endif
5241 #endif
5242 &tmp_cid, sizeof(char) * (SPIDER_SQL_HANDLER_CID_LEN + 1) *
5243 share->link_count,
5244 &spider->need_mons, sizeof(int) * share->link_count,
5245 &spider->quick_targets, sizeof(void *) * share->link_count,
5246 &result_list->upd_tmp_tbls, sizeof(TABLE *) * share->link_count,
5247 &result_list->upd_tmp_tbl_prms,
5248 sizeof(TMP_TABLE_PARAM) * share->link_count,
5249 &result_list->tmp_table_join_first,
5250 sizeof(uchar) * share->link_bitmap_size,
5251 &result_list->tmp_table_created,
5252 sizeof(uchar) * share->link_bitmap_size,
5253 #ifdef HA_CAN_BULK_ACCESS
5254 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
5255 &result_list->hs_r_bulk_open_index,
5256 sizeof(uchar) * share->link_bitmap_size,
5257 &result_list->hs_w_bulk_open_index,
5258 sizeof(uchar) * share->link_bitmap_size,
5259 #endif
5260 #endif
5261 &result_list->sql_kind_backup, sizeof(uint) * share->link_count,
5262 &result_list->casual_read, sizeof(int) * share->link_count,
5263 &spider->dbton_handler,
5264 sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE,
5265 NullS))
5266 ) {
5267 share->init_error = TRUE;
5268 share->init_error_time = (time_t) time((time_t*) 0);
5269 share->init = TRUE;
5270 spider_free_share(share);
5271 goto error_but_no_delete;
5272 }
5273 memcpy(tmp_name, share->conn_keys[0], share->conn_keys_charlen);
5274 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
5275 memcpy(tmp_hs_r_name, share->hs_read_conn_keys[0],
5276 share->hs_read_conn_keys_charlen);
5277 memcpy(tmp_hs_w_name, share->hs_write_conn_keys[0],
5278 share->hs_write_conn_keys_charlen);
5279 #endif
5280
5281 spider->conn_keys_first_ptr = tmp_name;
5282 for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
5283 {
5284 spider->conn_keys[roop_count] = tmp_name;
5285 *tmp_name = first_byte;
5286 tmp_name += share->conn_keys_lengths[roop_count] + 1;
5287 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
5288 spider->hs_r_conn_keys[roop_count] = tmp_hs_r_name;
5289 tmp_hs_r_name += share->hs_read_conn_keys_lengths[roop_count] + 1;
5290 spider->hs_w_conn_keys[roop_count] = tmp_hs_w_name;
5291 tmp_hs_w_name += share->hs_write_conn_keys_lengths[roop_count] + 1;
5292 #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
5293 spider->hs_r_ret_fields[roop_count] = tmp_hs_r_ret_fields;
5294 tmp_hs_r_ret_fields += table_share->fields;
5295 spider->hs_w_ret_fields[roop_count] = tmp_hs_w_ret_fields;
5296 tmp_hs_w_ret_fields += table_share->fields;
5297 #endif
5298 #endif
5299 spider->m_handler_cid[roop_count] = tmp_cid;
5300 tmp_cid += SPIDER_SQL_HANDLER_CID_LEN + 1;
5301 result_list->upd_tmp_tbl_prms[roop_count].init();
5302 result_list->upd_tmp_tbl_prms[roop_count].field_count = 1;
5303 spider->conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL;
5304 }
5305 spider_trx_set_link_idx_for_all(spider);
5306
5307 for (roop_count = 0; roop_count < (int) share->use_dbton_count;
5308 roop_count++)
5309 {
5310 uint dbton_id = share->use_dbton_ids[roop_count];
5311 if (!(spider->dbton_handler[dbton_id] =
5312 spider_dbton[dbton_id].create_db_handler(spider,
5313 share->dbton_share[dbton_id])))
5314 {
5315 *error_num = HA_ERR_OUT_OF_MEM;
5316 break;
5317 }
5318 if ((*error_num = spider->dbton_handler[dbton_id]->init()))
5319 {
5320 break;
5321 }
5322 }
5323 if (roop_count < (int) share->use_dbton_count)
5324 {
5325 for (; roop_count >= 0; roop_count--)
5326 {
5327 uint dbton_id = share->use_dbton_ids[roop_count];
5328 if (spider->dbton_handler[dbton_id])
5329 {
5330 delete spider->dbton_handler[dbton_id];
5331 spider->dbton_handler[dbton_id] = NULL;
5332 }
5333 }
5334 share->init_error = TRUE;
5335 share->init_error_time = (time_t) time((time_t*) 0);
5336 share->init = TRUE;
5337 goto error_after_alloc_conn_keys;
5338 }
5339
5340 if (
5341 sql_command != SQLCOM_DROP_TABLE &&
5342 sql_command != SQLCOM_ALTER_TABLE &&
5343 sql_command != SQLCOM_SHOW_CREATE
5344 ) {
5345 for (
5346 roop_count = spider_conn_link_idx_next(share->link_statuses,
5347 spider->conn_link_idx, -1, share->link_count,
5348 SPIDER_LINK_STATUS_RECOVERY);
5349 roop_count < (int) share->link_count;
5350 roop_count = spider_conn_link_idx_next(share->link_statuses,
5351 spider->conn_link_idx, roop_count, share->link_count,
5352 SPIDER_LINK_STATUS_RECOVERY)
5353 ) {
5354 if (
5355 !(spider->conns[roop_count] =
5356 spider_get_conn(share, roop_count, spider->conn_keys[roop_count],
5357 spider->wide_handler->trx, spider, FALSE, TRUE,
5358 SPIDER_CONN_KIND_MYSQL,
5359 error_num))
5360 ) {
5361 if (
5362 share->monitoring_kind[roop_count] &&
5363 spider->need_mons[roop_count]
5364 ) {
5365 *error_num = spider_ping_table_mon_from_table(
5366 spider->wide_handler->trx,
5367 spider->wide_handler->trx->thd,
5368 share,
5369 roop_count,
5370 (uint32) share->monitoring_sid[roop_count],
5371 share->table_name,
5372 share->table_name_length,
5373 spider->conn_link_idx[roop_count],
5374 NULL,
5375 0,
5376 share->monitoring_kind[roop_count],
5377 share->monitoring_limit[roop_count],
5378 share->monitoring_flag[roop_count],
5379 FALSE
5380 );
5381 }
5382 share->init_error = TRUE;
5383 share->init_error_time = (time_t) time((time_t*) 0);
5384 share->init = TRUE;
5385 goto error_after_alloc_dbton_handler;
5386 }
5387 spider->conns[roop_count]->error_mode &= spider->error_mode;
5388 }
5389 }
5390 search_link_idx = spider_conn_first_link_idx(thd,
5391 share->link_statuses, share->access_balances, spider->conn_link_idx,
5392 share->link_count, SPIDER_LINK_STATUS_OK);
5393 if (search_link_idx == -1)
5394 {
5395 char *db = (char *) my_alloca(
5396 table_share->db.length + 1 + table_share->table_name.length + 1);
5397 if (!db)
5398 {
5399 *error_num = HA_ERR_OUT_OF_MEM;
5400 share->init_error = TRUE;
5401 share->init_error_time = (time_t) time((time_t*) 0);
5402 share->init = TRUE;
5403 goto error_after_alloc_dbton_handler;
5404 }
5405 char *table_name = db + table_share->db.length + 1;
5406 memcpy(db, table_share->db.str, table_share->db.length);
5407 db[table_share->db.length] = '\0';
5408 memcpy(table_name, table_share->table_name.str,
5409 table_share->table_name.length);
5410 table_name[table_share->table_name.length] = '\0';
5411 my_printf_error(ER_SPIDER_ALL_LINKS_FAILED_NUM,
5412 ER_SPIDER_ALL_LINKS_FAILED_STR, MYF(0), db, table_name);
5413 my_afree(db);
5414 *error_num = ER_SPIDER_ALL_LINKS_FAILED_NUM;
5415 share->init_error = TRUE;
5416 share->init_error_time = (time_t) time((time_t*) 0);
5417 share->init = TRUE;
5418 goto error_after_alloc_dbton_handler;
5419 } else if (search_link_idx == -2)
5420 {
5421 *error_num = HA_ERR_OUT_OF_MEM;
5422 share->init_error = TRUE;
5423 share->init_error_time = (time_t) time((time_t*) 0);
5424 share->init = TRUE;
5425 goto error_after_alloc_dbton_handler;
5426 }
5427 spider->search_link_idx = search_link_idx;
5428
5429 same_server_link = spider_param_same_server_link(thd);
5430 load_sts_at_startup =
5431 spider_param_load_sts_at_startup(share->load_sts_at_startup);
5432 load_crd_at_startup =
5433 spider_param_load_crd_at_startup(share->load_crd_at_startup);
5434 if (
5435 sql_command != SQLCOM_DROP_TABLE &&
5436 sql_command != SQLCOM_ALTER_TABLE &&
5437 sql_command != SQLCOM_SHOW_CREATE &&
5438 !spider->error_mode &&
5439 (
5440 !same_server_link ||
5441 load_sts_at_startup ||
5442 load_crd_at_startup
5443 )
5444 ) {
5445 SPIDER_INIT_ERROR_TABLE *spider_init_error_table;
5446 sts_interval = spider_param_sts_interval(thd, share->sts_interval);
5447 sts_mode = spider_param_sts_mode(thd, share->sts_mode);
5448 #ifdef WITH_PARTITION_STORAGE_ENGINE
5449 sts_sync = spider_param_sts_sync(thd, share->sts_sync);
5450 auto_increment_mode = spider_param_auto_increment_mode(thd,
5451 share->auto_increment_mode);
5452 if (auto_increment_mode == 1)
5453 sts_sync = 0;
5454 #endif
5455 crd_interval = spider_param_crd_interval(thd, share->crd_interval);
5456 crd_mode = spider_param_crd_mode(thd, share->crd_mode);
5457 if (crd_mode == 3)
5458 crd_mode = 1;
5459 #ifdef WITH_PARTITION_STORAGE_ENGINE
5460 crd_sync = spider_param_crd_sync(thd, share->crd_sync);
5461 #endif
5462 time_t tmp_time = (time_t) time((time_t*) 0);
5463 pthread_mutex_lock(&share->sts_mutex);
5464 pthread_mutex_lock(&share->crd_mutex);
5465 if ((spider_init_error_table =
5466 spider_get_init_error_table(spider->wide_handler->trx, share, FALSE)))
5467 {
5468 DBUG_PRINT("info",("spider diff1=%f",
5469 difftime(tmp_time, spider_init_error_table->init_error_time)));
5470 if (difftime(tmp_time,
5471 spider_init_error_table->init_error_time) <
5472 spider_param_table_init_error_interval())
5473 {
5474 *error_num = spider_init_error_table->init_error;
5475 if (spider_init_error_table->init_error_with_message)
5476 my_message(spider_init_error_table->init_error,
5477 spider_init_error_table->init_error_msg, MYF(0));
5478 share->init_error = TRUE;
5479 share->init = TRUE;
5480 pthread_mutex_unlock(&share->crd_mutex);
5481 pthread_mutex_unlock(&share->sts_mutex);
5482 goto error_after_alloc_dbton_handler;
5483 }
5484 }
5485
5486 if (
5487 (
5488 !same_server_link ||
5489 load_sts_at_startup
5490 ) &&
5491 (*error_num = spider_get_sts(share, spider->search_link_idx, tmp_time,
5492 spider, sts_interval, sts_mode,
5493 #ifdef WITH_PARTITION_STORAGE_ENGINE
5494 sts_sync,
5495 #endif
5496 1, HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_AUTO))
5497 ) {
5498 if (*error_num != ER_SPIDER_SYS_TABLE_VERSION_NUM)
5499 {
5500 thd->clear_error();
5501 } else {
5502 pthread_mutex_unlock(&share->crd_mutex);
5503 pthread_mutex_unlock(&share->sts_mutex);
5504 share->init_error = TRUE;
5505 share->init_error_time = (time_t) time((time_t*) 0);
5506 share->init = TRUE;
5507 goto error_after_alloc_dbton_handler;
5508 }
5509 }
5510 if (
5511 (
5512 !same_server_link ||
5513 load_crd_at_startup
5514 ) &&
5515 (*error_num = spider_get_crd(share, spider->search_link_idx, tmp_time,
5516 spider, table, crd_interval, crd_mode,
5517 #ifdef WITH_PARTITION_STORAGE_ENGINE
5518 crd_sync,
5519 #endif
5520 1))
5521 ) {
5522 if (*error_num != ER_SPIDER_SYS_TABLE_VERSION_NUM)
5523 {
5524 thd->clear_error();
5525 } else {
5526 pthread_mutex_unlock(&share->crd_mutex);
5527 pthread_mutex_unlock(&share->sts_mutex);
5528 share->init_error = TRUE;
5529 share->init_error_time = (time_t) time((time_t*) 0);
5530 share->init = TRUE;
5531 goto error_after_alloc_dbton_handler;
5532 }
5533 }
5534 pthread_mutex_unlock(&share->crd_mutex);
5535 pthread_mutex_unlock(&share->sts_mutex);
5536 }
5537
5538 share->init = TRUE;
5539 } else {
5540 share->use_count++;
5541 pthread_mutex_unlock(&spider_tbl_mutex);
5542
5543 int sleep_cnt = 0;
5544 while (!share->init)
5545 {
5546 // avoid for dead loop
5547 if (sleep_cnt++ > 1000)
5548 {
5549 fprintf(stderr, " [WARN SPIDER RESULT] "
5550 "Wait share->init too long, table_name %s %s %ld\n",
5551 share->table_name, share->tgt_hosts[0], share->tgt_ports[0]);
5552 *error_num = ER_SPIDER_TABLE_OPEN_TIMEOUT_NUM;
5553 my_printf_error(ER_SPIDER_TABLE_OPEN_TIMEOUT_NUM,
5554 ER_SPIDER_TABLE_OPEN_TIMEOUT_STR, MYF(0),
5555 table_share->db.str, table_share->table_name.str);
5556 spider_free_share(share);
5557 goto error_but_no_delete;
5558 }
5559 my_sleep(10000); // wait 10 ms
5560 }
5561
5562 if (!share->link_status_init)
5563 {
5564 pthread_mutex_lock(&share->mutex);
5565 for (roop_count = 0;
5566 roop_count < (int) spider_param_udf_table_mon_mutex_count();
5567 roop_count++
5568 ) {
5569 if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count))
5570 pthread_mutex_lock(&spider_udf_table_mon_mutexes[roop_count]);
5571 }
5572 if (!share->link_status_init)
5573 {
5574 DBUG_ASSERT(!table_tables);
5575 /*
5576 The link statuses need to be refreshed from the spider_tables table
5577 if the operation:
5578 - Is not a DROP TABLE on a permanent table; or
5579 - Is an ALTER TABLE.
5580
5581 Note that SHOW CREATE TABLE is not excluded, because the commands
5582 that follow it require up-to-date link statuses.
5583 */
5584 if ((table_share->tmp_table == NO_TMP_TABLE &&
5585 sql_command != SQLCOM_DROP_TABLE) ||
5586 /* for alter change link status */
5587 sql_command == SQLCOM_ALTER_TABLE)
5588 {
5589 SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME));
5590 init_mem_root = TRUE;
5591
5592 if (
5593 !(table_tables = spider_open_sys_table(
5594 thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
5595 SPIDER_SYS_TABLES_TABLE_NAME_LEN, FALSE, &open_tables_backup,
5596 FALSE, error_num))
5597 ) {
5598 for (roop_count = 0;
5599 roop_count < (int) spider_param_udf_table_mon_mutex_count();
5600 roop_count++
5601 ) {
5602 if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count))
5603 pthread_mutex_unlock(&spider_udf_table_mon_mutexes[roop_count]);
5604 }
5605 pthread_mutex_unlock(&share->mutex);
5606 spider_free_share(share);
5607 goto error_open_sys_table;
5608 }
5609 *error_num = spider_get_link_statuses(table_tables, share,
5610 &mem_root);
5611 if (*error_num)
5612 {
5613 if (
5614 *error_num != HA_ERR_KEY_NOT_FOUND &&
5615 *error_num != HA_ERR_END_OF_FILE
5616 ) {
5617 for (roop_count = 0;
5618 roop_count < (int) spider_param_udf_table_mon_mutex_count();
5619 roop_count++
5620 ) {
5621 if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count))
5622 pthread_mutex_unlock(&spider_udf_table_mon_mutexes[roop_count]);
5623 }
5624 pthread_mutex_unlock(&share->mutex);
5625 spider_free_share(share);
5626 spider_close_sys_table(thd, table_tables,
5627 &open_tables_backup, FALSE);
5628 table_tables = NULL;
5629 goto error_open_sys_table;
5630 }
5631 } else {
5632 memcpy(share->alter_table.tmp_link_statuses, share->link_statuses,
5633 sizeof(long) * share->all_link_count);
5634 share->link_status_init = TRUE;
5635 }
5636 spider_close_sys_table(thd, table_tables,
5637 &open_tables_backup, FALSE);
5638 table_tables = NULL;
5639 }
5640 share->have_recovery_link = spider_conn_check_recovery_link(share);
5641 if (init_mem_root)
5642 {
5643 free_root(&mem_root, MYF(0));
5644 init_mem_root = FALSE;
5645 }
5646 }
5647 for (roop_count = 0;
5648 roop_count < (int) spider_param_udf_table_mon_mutex_count();
5649 roop_count++
5650 ) {
5651 if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count))
5652 pthread_mutex_unlock(&spider_udf_table_mon_mutexes[roop_count]);
5653 }
5654 pthread_mutex_unlock(&share->mutex);
5655 }
5656
5657 semi_table_lock_conn = spider_param_semi_table_lock_connection(thd,
5658 share->semi_table_lock_conn);
5659 if (semi_table_lock_conn)
5660 first_byte = '0' +
5661 spider_param_semi_table_lock(thd, share->semi_table_lock);
5662 else
5663 first_byte = '0';
5664
5665 spider->share = share;
5666 if (!(spider->wide_handler->trx = spider_get_trx(thd, TRUE, error_num)))
5667 {
5668 spider_free_share(share);
5669 goto error_but_no_delete;
5670 }
5671 spider->set_error_mode();
5672
5673 #ifndef WITHOUT_SPIDER_BG_SEARCH
5674 if (!share->sts_spider_init)
5675 {
5676 pthread_mutex_lock(&share->mutex);
5677 if (!share->sts_spider_init)
5678 {
5679 if ((*error_num = spider_create_spider_object_for_share(
5680 spider->wide_handler->trx, share, &share->sts_spider)))
5681 {
5682 pthread_mutex_unlock(&share->mutex);
5683 spider_free_share(share);
5684 goto error_sts_spider_init;
5685 }
5686 #ifdef HASH_UPDATE_WITH_HASH_VALUE
5687 share->sts_thread = &spider_table_sts_threads[
5688 hash_value % spider_param_table_sts_thread_count()];
5689 #else
5690 share->sts_thread = &spider_table_sts_threads[
5691 my_calc_hash(&spider_open_tables, (uchar*) table_name, length) %
5692 spider_param_table_sts_thread_count()];
5693 #endif
5694 share->sts_spider_init = TRUE;
5695 }
5696 pthread_mutex_unlock(&share->mutex);
5697 }
5698
5699 if (!share->crd_spider_init)
5700 {
5701 pthread_mutex_lock(&share->mutex);
5702 if (!share->crd_spider_init)
5703 {
5704 if ((*error_num = spider_create_spider_object_for_share(
5705 spider->wide_handler->trx, share, &share->crd_spider)))
5706 {
5707 pthread_mutex_unlock(&share->mutex);
5708 spider_free_share(share);
5709 goto error_crd_spider_init;
5710 }
5711 #ifdef HASH_UPDATE_WITH_HASH_VALUE
5712 share->crd_thread = &spider_table_crd_threads[
5713 hash_value % spider_param_table_crd_thread_count()];
5714 #else
5715 share->crd_thread = &spider_table_crd_threads[
5716 my_calc_hash(&spider_open_tables, (uchar*) table_name, length) %
5717 spider_param_table_crd_thread_count()];
5718 #endif
5719 share->crd_spider_init = TRUE;
5720 }
5721 pthread_mutex_unlock(&share->mutex);
5722 }
5723 #endif
5724
5725 #ifndef WITHOUT_SPIDER_BG_SEARCH
5726 if (
5727 sql_command != SQLCOM_DROP_TABLE &&
5728 sql_command != SQLCOM_ALTER_TABLE &&
5729 sql_command != SQLCOM_SHOW_CREATE &&
5730 (*error_num = spider_create_mon_threads(spider->wide_handler->trx,
5731 share))
5732 ) {
5733 spider_free_share(share);
5734 goto error_but_no_delete;
5735 }
5736 #endif
5737
5738 if (!(spider->conn_keys = (char **)
5739 spider_bulk_alloc_mem(spider_current_trx, 49,
5740 __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL),
5741 &spider->conn_keys, sizeof(char *) * share->link_count,
5742 &tmp_name, sizeof(char) * share->conn_keys_charlen,
5743 &spider->conns, sizeof(SPIDER_CONN *) * share->link_count,
5744 &spider->conn_link_idx, sizeof(uint) * share->link_count,
5745 &spider->conn_can_fo, sizeof(uchar) * share->link_bitmap_size,
5746 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
5747 &spider->hs_r_conn_keys, sizeof(char *) * share->link_count,
5748 &tmp_hs_r_name, sizeof(char) * share->hs_read_conn_keys_charlen,
5749 &spider->hs_r_conns, sizeof(SPIDER_CONN *) * share->link_count,
5750 &spider->hs_r_conn_ages, sizeof(ulonglong) * share->link_count,
5751 &spider->hs_w_conn_keys, sizeof(char *) * share->link_count,
5752 &tmp_hs_w_name, sizeof(char) * share->hs_write_conn_keys_charlen,
5753 &spider->hs_w_conns, sizeof(SPIDER_CONN *) * share->link_count,
5754 &spider->hs_w_conn_ages, sizeof(ulonglong) * share->link_count,
5755 #endif
5756 &spider->sql_kind, sizeof(uint) * share->link_count,
5757 &spider->connection_ids, sizeof(ulonglong) * share->link_count,
5758 &spider->conn_kind, sizeof(uint) * share->link_count,
5759 &spider->db_request_id, sizeof(ulonglong) * share->link_count,
5760 &spider->db_request_phase, sizeof(uchar) * share->link_bitmap_size,
5761 &spider->m_handler_opened, sizeof(uchar) * share->link_bitmap_size,
5762 &spider->m_handler_id, sizeof(uint) * share->link_count,
5763 &spider->m_handler_cid, sizeof(char *) * share->link_count,
5764 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
5765 &spider->r_handler_opened, sizeof(uchar) * share->link_bitmap_size,
5766 &spider->r_handler_id, sizeof(uint) * share->link_count,
5767 &spider->r_handler_index, sizeof(uint) * share->link_count,
5768 &spider->w_handler_opened, sizeof(uchar) * share->link_bitmap_size,
5769 &spider->w_handler_id, sizeof(uint) * share->link_count,
5770 &spider->w_handler_index, sizeof(uint) * share->link_count,
5771 #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
5772 &spider->do_hs_direct_update, sizeof(uchar) * share->link_bitmap_size,
5773 &spider->hs_r_ret_fields, sizeof(uint32 *) * share->link_count,
5774 &spider->hs_w_ret_fields, sizeof(uint32 *) * share->link_count,
5775 &spider->hs_r_ret_fields_num, sizeof(size_t) * share->link_count,
5776 &spider->hs_w_ret_fields_num, sizeof(size_t) * share->link_count,
5777 &tmp_hs_r_ret_fields,
5778 sizeof(uint32) * share->link_count * table_share->fields,
5779 &tmp_hs_w_ret_fields,
5780 sizeof(uint32) * share->link_count * table_share->fields,
5781 &spider->tmp_column_bitmap, sizeof(uchar) * share->bitmap_size,
5782 #endif
5783 #endif
5784 &tmp_cid, sizeof(char) * (SPIDER_SQL_HANDLER_CID_LEN + 1) *
5785 share->link_count,
5786 &spider->need_mons, sizeof(int) * share->link_count,
5787 &spider->quick_targets, sizeof(void *) * share->link_count,
5788 &result_list->upd_tmp_tbls, sizeof(TABLE *) * share->link_count,
5789 &result_list->upd_tmp_tbl_prms,
5790 sizeof(TMP_TABLE_PARAM) * share->link_count,
5791 &result_list->tmp_table_join_first,
5792 sizeof(uchar) * share->link_bitmap_size,
5793 &result_list->tmp_table_created,
5794 sizeof(uchar) * share->link_bitmap_size,
5795 #ifdef HA_CAN_BULK_ACCESS
5796 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
5797 &result_list->hs_r_bulk_open_index,
5798 sizeof(uchar) * share->link_bitmap_size,
5799 &result_list->hs_w_bulk_open_index,
5800 sizeof(uchar) * share->link_bitmap_size,
5801 #endif
5802 #endif
5803 &result_list->sql_kind_backup, sizeof(uint) * share->link_count,
5804 &result_list->casual_read, sizeof(int) * share->link_count,
5805 &spider->dbton_handler,
5806 sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE,
5807 NullS))
5808 ) {
5809 spider_free_share(share);
5810 goto error_but_no_delete;
5811 }
5812 memcpy(tmp_name, share->conn_keys[0], share->conn_keys_charlen);
5813 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
5814 memcpy(tmp_hs_r_name, share->hs_read_conn_keys[0],
5815 share->hs_read_conn_keys_charlen);
5816 memcpy(tmp_hs_w_name, share->hs_write_conn_keys[0],
5817 share->hs_write_conn_keys_charlen);
5818 #endif
5819
5820 spider->conn_keys_first_ptr = tmp_name;
5821 for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
5822 {
5823 spider->conn_keys[roop_count] = tmp_name;
5824 *tmp_name = first_byte;
5825 tmp_name += share->conn_keys_lengths[roop_count] + 1;
5826 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
5827 spider->hs_r_conn_keys[roop_count] = tmp_hs_r_name;
5828 tmp_hs_r_name += share->hs_read_conn_keys_lengths[roop_count] + 1;
5829 spider->hs_w_conn_keys[roop_count] = tmp_hs_w_name;
5830 tmp_hs_w_name += share->hs_write_conn_keys_lengths[roop_count] + 1;
5831 #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
5832 spider->hs_r_ret_fields[roop_count] = tmp_hs_r_ret_fields;
5833 tmp_hs_r_ret_fields += table_share->fields;
5834 spider->hs_w_ret_fields[roop_count] = tmp_hs_w_ret_fields;
5835 tmp_hs_w_ret_fields += table_share->fields;
5836 #endif
5837 #endif
5838 spider->m_handler_cid[roop_count] = tmp_cid;
5839 tmp_cid += SPIDER_SQL_HANDLER_CID_LEN + 1;
5840 result_list->upd_tmp_tbl_prms[roop_count].init();
5841 result_list->upd_tmp_tbl_prms[roop_count].field_count = 1;
5842 spider->conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL;
5843 }
5844 spider_trx_set_link_idx_for_all(spider);
5845
5846 for (roop_count = 0; roop_count < (int) share->use_dbton_count;
5847 roop_count++)
5848 {
5849 uint dbton_id = share->use_dbton_ids[roop_count];
5850 if (!(spider->dbton_handler[dbton_id] =
5851 spider_dbton[dbton_id].create_db_handler(spider,
5852 share->dbton_share[dbton_id])))
5853 {
5854 *error_num = HA_ERR_OUT_OF_MEM;
5855 break;
5856 }
5857 if ((*error_num = spider->dbton_handler[dbton_id]->init()))
5858 {
5859 break;
5860 }
5861 }
5862 if (roop_count < (int) share->use_dbton_count)
5863 {
5864 for (; roop_count >= 0; roop_count--)
5865 {
5866 uint dbton_id = share->use_dbton_ids[roop_count];
5867 if (spider->dbton_handler[dbton_id])
5868 {
5869 delete spider->dbton_handler[dbton_id];
5870 spider->dbton_handler[dbton_id] = NULL;
5871 }
5872 }
5873 goto error_after_alloc_conn_keys;
5874 }
5875
5876 if (
5877 sql_command != SQLCOM_DROP_TABLE &&
5878 sql_command != SQLCOM_ALTER_TABLE &&
5879 sql_command != SQLCOM_SHOW_CREATE
5880 ) {
5881 for (
5882 roop_count = spider_conn_link_idx_next(share->link_statuses,
5883 spider->conn_link_idx, -1, share->link_count,
5884 SPIDER_LINK_STATUS_RECOVERY);
5885 roop_count < (int) share->link_count;
5886 roop_count = spider_conn_link_idx_next(share->link_statuses,
5887 spider->conn_link_idx, roop_count, share->link_count,
5888 SPIDER_LINK_STATUS_RECOVERY)
5889 ) {
5890 if (
5891 !(spider->conns[roop_count] =
5892 spider_get_conn(share, roop_count, spider->conn_keys[roop_count],
5893 spider->wide_handler->trx, spider, FALSE, TRUE,
5894 SPIDER_CONN_KIND_MYSQL,
5895 error_num))
5896 ) {
5897 if (
5898 share->monitoring_kind[roop_count] &&
5899 spider->need_mons[roop_count]
5900 ) {
5901 *error_num = spider_ping_table_mon_from_table(
5902 spider->wide_handler->trx,
5903 spider->wide_handler->trx->thd,
5904 share,
5905 roop_count,
5906 (uint32) share->monitoring_sid[roop_count],
5907 share->table_name,
5908 share->table_name_length,
5909 spider->conn_link_idx[roop_count],
5910 NULL,
5911 0,
5912 share->monitoring_kind[roop_count],
5913 share->monitoring_limit[roop_count],
5914 share->monitoring_flag[roop_count],
5915 FALSE
5916 );
5917 }
5918 goto error_after_alloc_dbton_handler;
5919 }
5920 spider->conns[roop_count]->error_mode &= spider->error_mode;
5921 }
5922 }
5923 search_link_idx = spider_conn_first_link_idx(thd,
5924 share->link_statuses, share->access_balances, spider->conn_link_idx,
5925 share->link_count, SPIDER_LINK_STATUS_OK);
5926 if (search_link_idx == -1)
5927 {
5928 char *db = (char *) my_alloca(
5929 table_share->db.length + 1 + table_share->table_name.length + 1);
5930 if (!db)
5931 {
5932 *error_num = HA_ERR_OUT_OF_MEM;
5933 goto error_after_alloc_dbton_handler;
5934 }
5935 char *table_name = db + table_share->db.length + 1;
5936 memcpy(db, table_share->db.str, table_share->db.length);
5937 db[table_share->db.length] = '\0';
5938 memcpy(table_name, table_share->table_name.str,
5939 table_share->table_name.length);
5940 table_name[table_share->table_name.length] = '\0';
5941 my_printf_error(ER_SPIDER_ALL_LINKS_FAILED_NUM,
5942 ER_SPIDER_ALL_LINKS_FAILED_STR, MYF(0), db, table_name);
5943 my_afree(db);
5944 *error_num = ER_SPIDER_ALL_LINKS_FAILED_NUM;
5945 goto error_after_alloc_dbton_handler;
5946 } else if (search_link_idx == -2)
5947 {
5948 *error_num = HA_ERR_OUT_OF_MEM;
5949 goto error_after_alloc_dbton_handler;
5950 }
5951 spider->search_link_idx = search_link_idx;
5952
5953 if (share->init_error)
5954 {
5955 pthread_mutex_lock(&share->sts_mutex);
5956 pthread_mutex_lock(&share->crd_mutex);
5957 if (share->init_error)
5958 {
5959 same_server_link = spider_param_same_server_link(thd);
5960 load_sts_at_startup =
5961 spider_param_load_sts_at_startup(share->load_sts_at_startup);
5962 load_crd_at_startup =
5963 spider_param_load_crd_at_startup(share->load_crd_at_startup);
5964 if (
5965 sql_command != SQLCOM_DROP_TABLE &&
5966 sql_command != SQLCOM_ALTER_TABLE &&
5967 sql_command != SQLCOM_SHOW_CREATE &&
5968 !spider->error_mode &&
5969 (
5970 !same_server_link ||
5971 load_sts_at_startup ||
5972 load_crd_at_startup
5973 )
5974 ) {
5975 SPIDER_INIT_ERROR_TABLE *spider_init_error_table;
5976 sts_interval = spider_param_sts_interval(thd, share->sts_interval);
5977 sts_mode = spider_param_sts_mode(thd, share->sts_mode);
5978 #ifdef WITH_PARTITION_STORAGE_ENGINE
5979 sts_sync = spider_param_sts_sync(thd, share->sts_sync);
5980 auto_increment_mode = spider_param_auto_increment_mode(thd,
5981 share->auto_increment_mode);
5982 if (auto_increment_mode == 1)
5983 sts_sync = 0;
5984 #endif
5985 crd_interval = spider_param_crd_interval(thd, share->crd_interval);
5986 crd_mode = spider_param_crd_mode(thd, share->crd_mode);
5987 if (crd_mode == 3)
5988 crd_mode = 1;
5989 #ifdef WITH_PARTITION_STORAGE_ENGINE
5990 crd_sync = spider_param_crd_sync(thd, share->crd_sync);
5991 #endif
5992 time_t tmp_time = (time_t) time((time_t*) 0);
5993 if ((spider_init_error_table =
5994 spider_get_init_error_table(spider->wide_handler->trx, share,
5995 FALSE)))
5996 {
5997 DBUG_PRINT("info",("spider diff2=%f",
5998 difftime(tmp_time, spider_init_error_table->init_error_time)));
5999 if (difftime(tmp_time,
6000 spider_init_error_table->init_error_time) <
6001 spider_param_table_init_error_interval())
6002 {
6003 *error_num = spider_init_error_table->init_error;
6004 if (spider_init_error_table->init_error_with_message)
6005 my_message(spider_init_error_table->init_error,
6006 spider_init_error_table->init_error_msg, MYF(0));
6007 pthread_mutex_unlock(&share->crd_mutex);
6008 pthread_mutex_unlock(&share->sts_mutex);
6009 goto error_after_alloc_dbton_handler;
6010 }
6011 }
6012
6013 if (
6014 (
6015 !same_server_link ||
6016 load_sts_at_startup
6017 ) &&
6018 (*error_num = spider_get_sts(share, spider->search_link_idx,
6019 tmp_time, spider, sts_interval, sts_mode,
6020 #ifdef WITH_PARTITION_STORAGE_ENGINE
6021 sts_sync,
6022 #endif
6023 1, HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_AUTO))
6024 ) {
6025 if (*error_num != ER_SPIDER_SYS_TABLE_VERSION_NUM)
6026 {
6027 thd->clear_error();
6028 } else {
6029 pthread_mutex_unlock(&share->crd_mutex);
6030 pthread_mutex_unlock(&share->sts_mutex);
6031 goto error_after_alloc_dbton_handler;
6032 }
6033 }
6034 if (
6035 (
6036 !same_server_link ||
6037 load_crd_at_startup
6038 ) &&
6039 (*error_num = spider_get_crd(share, spider->search_link_idx,
6040 tmp_time, spider, table, crd_interval, crd_mode,
6041 #ifdef WITH_PARTITION_STORAGE_ENGINE
6042 crd_sync,
6043 #endif
6044 1))
6045 ) {
6046 if (*error_num != ER_SPIDER_SYS_TABLE_VERSION_NUM)
6047 {
6048 thd->clear_error();
6049 } else {
6050 pthread_mutex_unlock(&share->crd_mutex);
6051 pthread_mutex_unlock(&share->sts_mutex);
6052 goto error_after_alloc_dbton_handler;
6053 }
6054 }
6055 }
6056 share->init_error = FALSE;
6057 }
6058 pthread_mutex_unlock(&share->crd_mutex);
6059 pthread_mutex_unlock(&share->sts_mutex);
6060 }
6061 }
6062
6063 DBUG_PRINT("info",("spider share=%p", share));
6064 DBUG_RETURN(share);
6065
6066 error_after_alloc_dbton_handler:
6067 for (roop_count = 0; roop_count < (int) share->use_dbton_count; ++roop_count)
6068 {
6069 uint dbton_id = share->use_dbton_ids[roop_count];
6070 if (spider->dbton_handler[dbton_id])
6071 {
6072 delete spider->dbton_handler[dbton_id];
6073 spider->dbton_handler[dbton_id] = NULL;
6074 }
6075 }
6076 error_after_alloc_conn_keys:
6077 spider_free(spider_current_trx, spider->conn_keys, MYF(0));
6078 spider->conn_keys = NULL;
6079 spider_free_share(share);
6080 goto error_but_no_delete;
6081
6082 error_hash_insert:
6083 spider_free_share_resource_only(share);
6084 error_alloc_share:
6085 pthread_mutex_unlock(&spider_tbl_mutex);
6086 error_open_sys_table:
6087 #ifndef WITHOUT_SPIDER_BG_SEARCH
6088 error_crd_spider_init:
6089 error_sts_spider_init:
6090 #endif
6091 if (init_mem_root)
6092 {
6093 free_root(&mem_root, MYF(0));
6094 init_mem_root = FALSE;
6095 }
6096 error_but_no_delete:
6097 DBUG_RETURN(NULL);
6098 }
6099
spider_free_share_resource_only(SPIDER_SHARE * share)6100 void spider_free_share_resource_only(
6101 SPIDER_SHARE *share
6102 ) {
6103 DBUG_ENTER("spider_free_share_resource_only");
6104 spider_free_share_alloc(share);
6105 pthread_mutex_destroy(&share->crd_mutex);
6106 pthread_mutex_destroy(&share->sts_mutex);
6107 pthread_mutex_destroy(&share->mutex);
6108 spider_free(spider_current_trx, share, MYF(0));
6109 DBUG_VOID_RETURN;
6110 }
6111
spider_free_share(SPIDER_SHARE * share)6112 int spider_free_share(
6113 SPIDER_SHARE *share
6114 ) {
6115 DBUG_ENTER("spider_free_share");
6116 pthread_mutex_lock(&spider_tbl_mutex);
6117 bool do_delete_thd = false;
6118 THD *thd = current_thd;
6119 if (!--share->use_count)
6120 {
6121 #ifndef WITHOUT_SPIDER_BG_SEARCH
6122 spider_free_sts_thread(share);
6123 spider_free_crd_thread(share);
6124 spider_free_mon_threads(share);
6125 if (share->sts_spider_init)
6126 {
6127 spider_table_remove_share_from_sts_thread(share);
6128 spider_free_spider_object_for_share(&share->sts_spider);
6129 }
6130 if (share->crd_spider_init)
6131 {
6132 spider_table_remove_share_from_crd_thread(share);
6133 spider_free_spider_object_for_share(&share->crd_spider);
6134 }
6135 #endif
6136 if (
6137 share->sts_init &&
6138 spider_param_store_last_sts(share->store_last_sts)
6139 ) {
6140 if (!thd)
6141 {
6142 /* Create a thread for Spider system table update */
6143 thd = spider_create_thd();
6144 if (!thd)
6145 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
6146 do_delete_thd = TRUE;
6147 }
6148 spider_sys_insert_or_update_table_sts(
6149 thd,
6150 share->lgtm_tblhnd_share->table_name,
6151 share->lgtm_tblhnd_share->table_name_length,
6152 &share->stat,
6153 FALSE
6154 );
6155 }
6156 if (
6157 share->crd_init &&
6158 spider_param_store_last_crd(share->store_last_crd)
6159 ) {
6160 if (!thd)
6161 {
6162 /* Create a thread for Spider system table update */
6163 thd = spider_create_thd();
6164 if (!thd)
6165 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
6166 do_delete_thd = TRUE;
6167 }
6168 spider_sys_insert_or_update_table_crd(
6169 thd,
6170 share->lgtm_tblhnd_share->table_name,
6171 share->lgtm_tblhnd_share->table_name_length,
6172 share->cardinality,
6173 share->table_share->fields,
6174 FALSE
6175 );
6176 }
6177 spider_free_share_alloc(share);
6178 #ifdef HASH_UPDATE_WITH_HASH_VALUE
6179 my_hash_delete_with_hash_value(&spider_open_tables,
6180 share->table_name_hash_value, (uchar*) share);
6181 #else
6182 my_hash_delete(&spider_open_tables, (uchar*) share);
6183 #endif
6184 pthread_mutex_destroy(&share->crd_mutex);
6185 pthread_mutex_destroy(&share->sts_mutex);
6186 pthread_mutex_destroy(&share->mutex);
6187 free_root(&share->mem_root, MYF(0));
6188 spider_free(spider_current_trx, share, MYF(0));
6189 }
6190 if (do_delete_thd)
6191 spider_destroy_thd(thd);
6192 pthread_mutex_unlock(&spider_tbl_mutex);
6193 DBUG_RETURN(0);
6194 }
6195
spider_update_link_status_for_share(const char * table_name,uint table_name_length,int link_idx,long link_status)6196 void spider_update_link_status_for_share(
6197 const char *table_name,
6198 uint table_name_length,
6199 int link_idx,
6200 long link_status
6201 ) {
6202 SPIDER_SHARE *share;
6203 DBUG_ENTER("spider_update_link_status_for_share");
6204
6205 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
6206 my_hash_value_type hash_value = my_calc_hash(&spider_open_tables,
6207 (uchar*) table_name, table_name_length);
6208 #endif
6209 pthread_mutex_lock(&spider_tbl_mutex);
6210 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
6211 if ((share = (SPIDER_SHARE*) my_hash_search_using_hash_value(
6212 &spider_open_tables, hash_value, (uchar*) table_name,
6213 table_name_length)))
6214 #else
6215 if ((share = (SPIDER_SHARE*) my_hash_search(&spider_open_tables,
6216 (uchar*) table_name, table_name_length)))
6217 #endif
6218 {
6219 DBUG_PRINT("info", ("spider share->link_status_init=%s",
6220 share->link_status_init ? "TRUE" : "FALSE"));
6221 if (share->link_status_init)
6222 {
6223 DBUG_PRINT("info", ("spider share->link_statuses[%d]=%ld",
6224 link_idx, link_status));
6225 share->link_statuses[link_idx] = link_status;
6226 }
6227 }
6228 pthread_mutex_unlock(&spider_tbl_mutex);
6229 DBUG_VOID_RETURN;
6230 }
6231
6232 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
spider_get_lgtm_tblhnd_share(const char * table_name,uint table_name_length,my_hash_value_type hash_value,bool locked,bool need_to_create,int * error_num)6233 SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share(
6234 const char *table_name,
6235 uint table_name_length,
6236 my_hash_value_type hash_value,
6237 bool locked,
6238 bool need_to_create,
6239 int *error_num
6240 )
6241 #else
6242 SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share(
6243 const char *table_name,
6244 uint table_name_length,
6245 bool locked,
6246 bool need_to_create,
6247 int *error_num
6248 )
6249 #endif
6250 {
6251 SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share;
6252 char *tmp_name;
6253 DBUG_ENTER("spider_get_lgtm_tblhnd_share");
6254
6255 if (!locked)
6256 pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex);
6257 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
6258 if (!(lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE*)
6259 my_hash_search_using_hash_value(
6260 &spider_lgtm_tblhnd_share_hash, hash_value,
6261 (uchar*) table_name, table_name_length)))
6262 #else
6263 if (!(lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE*) my_hash_search(
6264 &spider_lgtm_tblhnd_share_hash,
6265 (uchar*) table_name, table_name_length)))
6266 #endif
6267 {
6268 DBUG_PRINT("info",("spider create new lgtm tblhnd share"));
6269 if (!(lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE *)
6270 spider_bulk_malloc(spider_current_trx, 244, MYF(MY_WME | MY_ZEROFILL),
6271 &lgtm_tblhnd_share, (uint) (sizeof(*lgtm_tblhnd_share)),
6272 &tmp_name, (uint) (table_name_length + 1),
6273 NullS))
6274 ) {
6275 *error_num = HA_ERR_OUT_OF_MEM;
6276 goto error_alloc_share;
6277 }
6278
6279 lgtm_tblhnd_share->table_name_length = table_name_length;
6280 lgtm_tblhnd_share->table_name = tmp_name;
6281 memcpy(lgtm_tblhnd_share->table_name, table_name,
6282 lgtm_tblhnd_share->table_name_length);
6283 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
6284 lgtm_tblhnd_share->table_path_hash_value = hash_value;
6285 #endif
6286
6287 #if MYSQL_VERSION_ID < 50500
6288 if (pthread_mutex_init(&lgtm_tblhnd_share->auto_increment_mutex,
6289 MY_MUTEX_INIT_FAST))
6290 #else
6291 if (mysql_mutex_init(spd_key_mutex_share_auto_increment,
6292 &lgtm_tblhnd_share->auto_increment_mutex, MY_MUTEX_INIT_FAST))
6293 #endif
6294 {
6295 *error_num = HA_ERR_OUT_OF_MEM;
6296 goto error_init_auto_increment_mutex;
6297 }
6298
6299 uint old_elements = spider_lgtm_tblhnd_share_hash.array.max_element;
6300 #ifdef HASH_UPDATE_WITH_HASH_VALUE
6301 if (my_hash_insert_with_hash_value(&spider_lgtm_tblhnd_share_hash,
6302 hash_value, (uchar*) lgtm_tblhnd_share))
6303 #else
6304 if (my_hash_insert(&spider_lgtm_tblhnd_share_hash,
6305 (uchar*) lgtm_tblhnd_share))
6306 #endif
6307 {
6308 *error_num = HA_ERR_OUT_OF_MEM;
6309 goto error_hash_insert;
6310 }
6311 if (spider_lgtm_tblhnd_share_hash.array.max_element > old_elements)
6312 {
6313 spider_alloc_calc_mem(spider_current_trx,
6314 spider_lgtm_tblhnd_share_hash,
6315 (spider_lgtm_tblhnd_share_hash.array.max_element - old_elements) *
6316 spider_lgtm_tblhnd_share_hash.array.size_of_element);
6317 }
6318 }
6319 if (!locked)
6320 pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
6321
6322 DBUG_PRINT("info",("spider lgtm_tblhnd_share=%p", lgtm_tblhnd_share));
6323 DBUG_RETURN(lgtm_tblhnd_share);
6324
6325 error_hash_insert:
6326 pthread_mutex_destroy(&lgtm_tblhnd_share->auto_increment_mutex);
6327 error_init_auto_increment_mutex:
6328 spider_free(spider_current_trx, lgtm_tblhnd_share, MYF(0));
6329 error_alloc_share:
6330 if (!locked)
6331 pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
6332 DBUG_RETURN(NULL);
6333 }
6334
spider_free_lgtm_tblhnd_share_alloc(SPIDER_LGTM_TBLHND_SHARE * lgtm_tblhnd_share,bool locked)6335 void spider_free_lgtm_tblhnd_share_alloc(
6336 SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share,
6337 bool locked
6338 ) {
6339 DBUG_ENTER("spider_free_lgtm_tblhnd_share");
6340 if (!locked)
6341 pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex);
6342 #ifdef HASH_UPDATE_WITH_HASH_VALUE
6343 my_hash_delete_with_hash_value(&spider_lgtm_tblhnd_share_hash,
6344 lgtm_tblhnd_share->table_path_hash_value, (uchar*) lgtm_tblhnd_share);
6345 #else
6346 my_hash_delete(&spider_lgtm_tblhnd_share_hash, (uchar*) lgtm_tblhnd_share);
6347 #endif
6348 pthread_mutex_destroy(&lgtm_tblhnd_share->auto_increment_mutex);
6349 spider_free(spider_current_trx, lgtm_tblhnd_share, MYF(0));
6350 if (!locked)
6351 pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
6352 DBUG_VOID_RETURN;
6353 }
6354
spider_get_wide_share(SPIDER_SHARE * share,TABLE_SHARE * table_share,int * error_num)6355 SPIDER_WIDE_SHARE *spider_get_wide_share(
6356 SPIDER_SHARE *share,
6357 TABLE_SHARE *table_share,
6358 int *error_num
6359 ) {
6360 SPIDER_WIDE_SHARE *wide_share;
6361 char *tmp_name;
6362 longlong *tmp_cardinality;
6363 DBUG_ENTER("spider_get_wide_share");
6364
6365 pthread_mutex_lock(&spider_wide_share_mutex);
6366 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
6367 if (!(wide_share = (SPIDER_WIDE_SHARE*)
6368 my_hash_search_using_hash_value(
6369 &spider_open_wide_share, share->table_path_hash_value,
6370 (uchar*) table_share->path.str, table_share->path.length)))
6371 #else
6372 if (!(wide_share = (SPIDER_WIDE_SHARE*) my_hash_search(
6373 &spider_open_wide_share,
6374 (uchar*) table_share->path.str, table_share->path.length)))
6375 #endif
6376 {
6377 DBUG_PRINT("info",("spider create new wide share"));
6378 if (!(wide_share = (SPIDER_WIDE_SHARE *)
6379 spider_bulk_malloc(spider_current_trx, 51, MYF(MY_WME | MY_ZEROFILL),
6380 &wide_share, sizeof(SPIDER_WIDE_SHARE),
6381 &tmp_name, (uint) (table_share->path.length + 1),
6382 &tmp_cardinality,
6383 (uint) (sizeof(*tmp_cardinality) * table_share->fields),
6384 NullS))
6385 ) {
6386 *error_num = HA_ERR_OUT_OF_MEM;
6387 goto error_alloc_share;
6388 }
6389
6390 wide_share->use_count = 0;
6391 wide_share->table_name_length = table_share->path.length;
6392 wide_share->table_name = tmp_name;
6393 memcpy(wide_share->table_name, table_share->path.str,
6394 wide_share->table_name_length);
6395 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
6396 wide_share->table_path_hash_value = share->table_path_hash_value;
6397 #endif
6398 wide_share->cardinality = tmp_cardinality;
6399
6400 wide_share->crd_get_time = wide_share->sts_get_time =
6401 share->crd_get_time;
6402
6403 #if MYSQL_VERSION_ID < 50500
6404 if (pthread_mutex_init(&wide_share->sts_mutex, MY_MUTEX_INIT_FAST))
6405 #else
6406 if (mysql_mutex_init(spd_key_mutex_wide_share_sts,
6407 &wide_share->sts_mutex, MY_MUTEX_INIT_FAST))
6408 #endif
6409 {
6410 *error_num = HA_ERR_OUT_OF_MEM;
6411 goto error_init_sts_mutex;
6412 }
6413
6414 #if MYSQL_VERSION_ID < 50500
6415 if (pthread_mutex_init(&wide_share->crd_mutex, MY_MUTEX_INIT_FAST))
6416 #else
6417 if (mysql_mutex_init(spd_key_mutex_wide_share_crd,
6418 &wide_share->crd_mutex, MY_MUTEX_INIT_FAST))
6419 #endif
6420 {
6421 *error_num = HA_ERR_OUT_OF_MEM;
6422 goto error_init_crd_mutex;
6423 }
6424
6425 thr_lock_init(&wide_share->lock);
6426
6427 uint old_elements = spider_open_wide_share.array.max_element;
6428 #ifdef HASH_UPDATE_WITH_HASH_VALUE
6429 if (my_hash_insert_with_hash_value(&spider_open_wide_share,
6430 share->table_path_hash_value,
6431 (uchar*) wide_share))
6432 #else
6433 if (my_hash_insert(&spider_open_wide_share, (uchar*) wide_share))
6434 #endif
6435 {
6436 *error_num = HA_ERR_OUT_OF_MEM;
6437 goto error_hash_insert;
6438 }
6439 if (spider_open_wide_share.array.max_element > old_elements)
6440 {
6441 spider_alloc_calc_mem(spider_current_trx,
6442 spider_open_wide_share,
6443 (spider_open_wide_share.array.max_element - old_elements) *
6444 spider_open_wide_share.array.size_of_element);
6445 }
6446 }
6447 wide_share->use_count++;
6448 pthread_mutex_unlock(&spider_wide_share_mutex);
6449
6450 DBUG_PRINT("info",("spider wide_share=%p", wide_share));
6451 DBUG_RETURN(wide_share);
6452
6453 error_hash_insert:
6454 pthread_mutex_destroy(&wide_share->crd_mutex);
6455 error_init_crd_mutex:
6456 pthread_mutex_destroy(&wide_share->sts_mutex);
6457 error_init_sts_mutex:
6458 spider_free(spider_current_trx, wide_share, MYF(0));
6459 error_alloc_share:
6460 pthread_mutex_unlock(&spider_wide_share_mutex);
6461 DBUG_RETURN(NULL);
6462 }
6463
spider_free_wide_share(SPIDER_WIDE_SHARE * wide_share)6464 int spider_free_wide_share(
6465 SPIDER_WIDE_SHARE *wide_share
6466 ) {
6467 DBUG_ENTER("spider_free_wide_share");
6468 pthread_mutex_lock(&spider_wide_share_mutex);
6469 if (!--wide_share->use_count)
6470 {
6471 thr_lock_delete(&wide_share->lock);
6472 #ifdef HASH_UPDATE_WITH_HASH_VALUE
6473 my_hash_delete_with_hash_value(&spider_open_wide_share,
6474 wide_share->table_path_hash_value, (uchar*) wide_share);
6475 #else
6476 my_hash_delete(&spider_open_wide_share, (uchar*) wide_share);
6477 #endif
6478 pthread_mutex_destroy(&wide_share->crd_mutex);
6479 pthread_mutex_destroy(&wide_share->sts_mutex);
6480 spider_free(spider_current_trx, wide_share, MYF(0));
6481 }
6482 pthread_mutex_unlock(&spider_wide_share_mutex);
6483 DBUG_RETURN(0);
6484 }
6485
spider_copy_sts_to_wide_share(SPIDER_WIDE_SHARE * wide_share,SPIDER_SHARE * share)6486 void spider_copy_sts_to_wide_share(
6487 SPIDER_WIDE_SHARE *wide_share,
6488 SPIDER_SHARE *share
6489 ) {
6490 DBUG_ENTER("spider_copy_sts_to_pt_share");
6491 wide_share->stat = share->stat;
6492 DBUG_VOID_RETURN;
6493 }
6494
spider_copy_sts_to_share(SPIDER_SHARE * share,SPIDER_WIDE_SHARE * wide_share)6495 void spider_copy_sts_to_share(
6496 SPIDER_SHARE *share,
6497 SPIDER_WIDE_SHARE *wide_share
6498 ) {
6499 DBUG_ENTER("spider_copy_sts_to_share");
6500 share->stat = wide_share->stat;
6501 DBUG_VOID_RETURN;
6502 }
6503
spider_copy_crd_to_wide_share(SPIDER_WIDE_SHARE * wide_share,SPIDER_SHARE * share,int fields)6504 void spider_copy_crd_to_wide_share(
6505 SPIDER_WIDE_SHARE *wide_share,
6506 SPIDER_SHARE *share,
6507 int fields
6508 ) {
6509 DBUG_ENTER("spider_copy_crd_to_wide_share");
6510 memcpy(wide_share->cardinality, share->cardinality,
6511 sizeof(longlong) * fields);
6512 DBUG_VOID_RETURN;
6513 }
6514
spider_copy_crd_to_share(SPIDER_SHARE * share,SPIDER_WIDE_SHARE * wide_share,int fields)6515 void spider_copy_crd_to_share(
6516 SPIDER_SHARE *share,
6517 SPIDER_WIDE_SHARE *wide_share,
6518 int fields
6519 ) {
6520 DBUG_ENTER("spider_copy_crd_to_share");
6521 memcpy(share->cardinality, wide_share->cardinality,
6522 sizeof(longlong) * fields);
6523 DBUG_VOID_RETURN;
6524 }
6525
spider_open_all_tables(SPIDER_TRX * trx,bool lock)6526 int spider_open_all_tables(
6527 SPIDER_TRX *trx,
6528 bool lock
6529 ) {
6530 THD *thd = trx->thd;
6531 TABLE *table_tables;
6532 int error_num, *need_mon, mon_val;
6533 SPIDER_SHARE tmp_share;
6534 char *db_name, *table_name;
6535 uint db_name_length, table_name_length;
6536 char *tmp_connect_info[SPIDER_TMP_SHARE_CHAR_PTR_COUNT];
6537 uint tmp_connect_info_length[SPIDER_TMP_SHARE_UINT_COUNT];
6538 long tmp_long[SPIDER_TMP_SHARE_LONG_COUNT];
6539 longlong tmp_longlong[SPIDER_TMP_SHARE_LONGLONG_COUNT];
6540 SPIDER_CONN *conn, **conns;
6541 ha_spider *spider;
6542 SPIDER_SHARE *share;
6543 char **connect_info;
6544 uint *connect_info_length;
6545 long *long_info;
6546 longlong *longlong_info;
6547 MEM_ROOT mem_root;
6548 SPIDER_Open_tables_backup open_tables_backup;
6549 DBUG_ENTER("spider_open_all_tables");
6550 if (
6551 !(table_tables = spider_open_sys_table(
6552 thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
6553 SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, TRUE,
6554 &error_num))
6555 )
6556 DBUG_RETURN(error_num);
6557 if (
6558 (error_num = spider_sys_index_first(table_tables, 1))
6559 ) {
6560 if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
6561 {
6562 table_tables->file->print_error(error_num, MYF(0));
6563 spider_close_sys_table(thd, table_tables,
6564 &open_tables_backup, TRUE);
6565 DBUG_RETURN(error_num);
6566 } else {
6567 spider_close_sys_table(thd, table_tables,
6568 &open_tables_backup, TRUE);
6569 DBUG_RETURN(0);
6570 }
6571 }
6572
6573 SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME));
6574 memset((void*)&tmp_share, 0, sizeof(SPIDER_SHARE));
6575 memset(&tmp_connect_info, 0,
6576 sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT);
6577 memset(tmp_connect_info_length, 0,
6578 sizeof(uint) * SPIDER_TMP_SHARE_UINT_COUNT);
6579 memset(tmp_long, 0, sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT);
6580 memset(tmp_longlong, 0, sizeof(longlong) * SPIDER_TMP_SHARE_LONGLONG_COUNT);
6581 spider_set_tmp_share_pointer(&tmp_share, (char **) &tmp_connect_info,
6582 tmp_connect_info_length, tmp_long, tmp_longlong);
6583 tmp_share.link_statuses[0] = -1;
6584
6585 do {
6586 if (
6587 (error_num = spider_get_sys_tables(
6588 table_tables, &db_name, &table_name, &mem_root)) ||
6589 (error_num = spider_get_sys_tables_connect_info(
6590 table_tables, &tmp_share, 0, &mem_root)) ||
6591 (error_num = spider_set_connect_info_default(
6592 &tmp_share,
6593 #ifdef WITH_PARTITION_STORAGE_ENGINE
6594 NULL,
6595 NULL,
6596 #endif
6597 NULL
6598 ))
6599 ) {
6600 spider_sys_index_end(table_tables);
6601 spider_close_sys_table(thd, table_tables,
6602 &open_tables_backup, TRUE);
6603 spider_free_tmp_share_alloc(&tmp_share);
6604 free_root(&mem_root, MYF(0));
6605 DBUG_RETURN(error_num);
6606 }
6607 db_name_length = strlen(db_name);
6608 table_name_length = strlen(table_name);
6609
6610 if (
6611 (error_num = spider_set_connect_info_default_db_table(
6612 &tmp_share,
6613 db_name,
6614 db_name_length,
6615 table_name,
6616 table_name_length
6617 )) ||
6618 (error_num = spider_create_conn_keys(&tmp_share)) ||
6619 /*
6620 (error_num = spider_db_create_table_names_str(&tmp_share)) ||
6621 */
6622 (error_num = spider_create_tmp_dbton_share(&tmp_share))
6623 ) {
6624 spider_sys_index_end(table_tables);
6625 spider_close_sys_table(thd, table_tables,
6626 &open_tables_backup, TRUE);
6627 spider_free_tmp_share_alloc(&tmp_share);
6628 free_root(&mem_root, MYF(0));
6629 DBUG_RETURN(error_num);
6630 }
6631
6632 /* create conn */
6633 if (
6634 !(conn = spider_get_conn(
6635 &tmp_share, 0, tmp_share.conn_keys[0], trx, NULL, FALSE, FALSE,
6636 SPIDER_CONN_KIND_MYSQL, &error_num))
6637 ) {
6638 spider_sys_index_end(table_tables);
6639 spider_close_sys_table(thd, table_tables,
6640 &open_tables_backup, TRUE);
6641 spider_free_tmp_dbton_share(&tmp_share);
6642 spider_free_tmp_share_alloc(&tmp_share);
6643 free_root(&mem_root, MYF(0));
6644 DBUG_RETURN(error_num);
6645 }
6646 conn->error_mode &= spider_param_error_read_mode(thd, 0);
6647 conn->error_mode &= spider_param_error_write_mode(thd, 0);
6648 pthread_mutex_assert_not_owner(&conn->mta_conn_mutex);
6649 pthread_mutex_lock(&conn->mta_conn_mutex);
6650 SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
6651 conn->need_mon = &mon_val;
6652 DBUG_ASSERT(!conn->mta_conn_mutex_lock_already);
6653 DBUG_ASSERT(!conn->mta_conn_mutex_unlock_later);
6654 conn->mta_conn_mutex_lock_already = TRUE;
6655 conn->mta_conn_mutex_unlock_later = TRUE;
6656 if ((error_num = spider_db_before_query(conn, &mon_val)))
6657 {
6658 DBUG_ASSERT(conn->mta_conn_mutex_lock_already);
6659 DBUG_ASSERT(conn->mta_conn_mutex_unlock_later);
6660 conn->mta_conn_mutex_lock_already = FALSE;
6661 conn->mta_conn_mutex_unlock_later = FALSE;
6662 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
6663 pthread_mutex_unlock(&conn->mta_conn_mutex);
6664 spider_sys_index_end(table_tables);
6665 spider_close_sys_table(thd, table_tables,
6666 &open_tables_backup, TRUE);
6667 spider_free_tmp_dbton_share(&tmp_share);
6668 spider_free_tmp_share_alloc(&tmp_share);
6669 free_root(&mem_root, MYF(0));
6670 DBUG_RETURN(error_num);
6671 }
6672 DBUG_ASSERT(conn->mta_conn_mutex_lock_already);
6673 DBUG_ASSERT(conn->mta_conn_mutex_unlock_later);
6674 conn->mta_conn_mutex_lock_already = FALSE;
6675 conn->mta_conn_mutex_unlock_later = FALSE;
6676 SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
6677 pthread_mutex_unlock(&conn->mta_conn_mutex);
6678
6679 if (lock && spider_param_use_snapshot_with_flush_tables(thd) == 2)
6680 {
6681 if (!(spider = new ha_spider()))
6682 {
6683 spider_sys_index_end(table_tables);
6684 spider_close_sys_table(thd, table_tables,
6685 &open_tables_backup, TRUE);
6686 spider_free_tmp_dbton_share(&tmp_share);
6687 spider_free_tmp_share_alloc(&tmp_share);
6688 free_root(&mem_root, MYF(0));
6689 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
6690 }
6691 spider->wide_handler->lock_type = TL_READ_NO_INSERT;
6692
6693 if (!(share = (SPIDER_SHARE *)
6694 spider_bulk_malloc(spider_current_trx, 52, MYF(MY_WME | MY_ZEROFILL),
6695 &share, (uint) (sizeof(*share)),
6696 &connect_info,
6697 (uint) (sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT),
6698 &connect_info_length,
6699 (uint) (sizeof(uint) * SPIDER_TMP_SHARE_UINT_COUNT),
6700 &long_info, (uint) (sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT),
6701 &longlong_info,
6702 (uint) (sizeof(longlong) * SPIDER_TMP_SHARE_LONGLONG_COUNT),
6703 &conns, (uint) (sizeof(SPIDER_CONN *)),
6704 &need_mon, (uint) (sizeof(int)),
6705 &spider->conn_link_idx, (uint) (sizeof(uint)),
6706 &spider->conn_can_fo, (uint) (sizeof(uchar)),
6707 NullS))
6708 ) {
6709 delete spider;
6710 spider_sys_index_end(table_tables);
6711 spider_close_sys_table(thd, table_tables,
6712 &open_tables_backup, TRUE);
6713 spider_free_tmp_dbton_share(&tmp_share);
6714 spider_free_tmp_share_alloc(&tmp_share);
6715 free_root(&mem_root, MYF(0));
6716 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
6717 }
6718 memcpy((void*)share, &tmp_share, sizeof(*share));
6719 spider_set_tmp_share_pointer(share, connect_info,
6720 connect_info_length, long_info, longlong_info);
6721 memcpy(connect_info, &tmp_connect_info, sizeof(char *) *
6722 SPIDER_TMP_SHARE_CHAR_PTR_COUNT);
6723 memcpy(connect_info_length, &tmp_connect_info_length, sizeof(uint) *
6724 SPIDER_TMP_SHARE_UINT_COUNT);
6725 memcpy(long_info, &tmp_long, sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT);
6726 memcpy(longlong_info, &tmp_longlong, sizeof(longlong) *
6727 SPIDER_TMP_SHARE_LONGLONG_COUNT);
6728 spider->share = share;
6729 spider->wide_handler->trx = trx;
6730 spider->conns = conns;
6731 spider->need_mons = need_mon;
6732 spider->conn_link_idx[0] = 0;
6733 spider->conn_can_fo[0] = 0;
6734 if ((error_num = spider_create_tmp_dbton_handler(spider)))
6735 {
6736 spider_free(trx, share, MYF(0));
6737 delete spider;
6738 spider_sys_index_end(table_tables);
6739 spider_close_sys_table(thd, table_tables,
6740 &open_tables_backup, TRUE);
6741 spider_free_tmp_dbton_share(&tmp_share);
6742 spider_free_tmp_share_alloc(&tmp_share);
6743 free_root(&mem_root, MYF(0));
6744 DBUG_RETURN(error_num);
6745 }
6746
6747 /* create another conn */
6748 if (
6749 (!(conn = spider_get_conn(
6750 &tmp_share, 0, tmp_share.conn_keys[0], trx, spider, TRUE, FALSE,
6751 SPIDER_CONN_KIND_MYSQL, &error_num)))
6752 ) {
6753 spider_free_tmp_dbton_handler(spider);
6754 spider_free(trx, share, MYF(0));
6755 delete spider;
6756 spider_sys_index_end(table_tables);
6757 spider_close_sys_table(thd, table_tables,
6758 &open_tables_backup, TRUE);
6759 spider_free_tmp_dbton_share(&tmp_share);
6760 spider_free_tmp_share_alloc(&tmp_share);
6761 free_root(&mem_root, MYF(0));
6762 DBUG_RETURN(error_num);
6763 }
6764 conn->error_mode &= spider_param_error_read_mode(thd, 0);
6765 conn->error_mode &= spider_param_error_write_mode(thd, 0);
6766
6767 spider->next = NULL;
6768 if (conn->another_ha_last)
6769 {
6770 ((ha_spider*) conn->another_ha_last)->next = spider;
6771 } else {
6772 conn->another_ha_first = (void*) spider;
6773 }
6774 conn->another_ha_last = (void*) spider;
6775
6776 int appended = 0;
6777 if ((error_num = spider->dbton_handler[conn->dbton_id]->
6778 append_lock_tables_list(conn, 0, &appended)))
6779 {
6780 spider_free_tmp_dbton_handler(spider);
6781 spider_free(trx, share, MYF(0));
6782 delete spider;
6783 spider_sys_index_end(table_tables);
6784 spider_close_sys_table(thd, table_tables,
6785 &open_tables_backup, TRUE);
6786 spider_free_tmp_dbton_share(&tmp_share);
6787 spider_free_tmp_share_alloc(&tmp_share);
6788 free_root(&mem_root, MYF(0));
6789 DBUG_RETURN(error_num);
6790 }
6791 } else {
6792 spider_free_tmp_dbton_share(&tmp_share);
6793 spider_free_tmp_share_alloc(&tmp_share);
6794 }
6795 error_num = spider_sys_index_next(table_tables);
6796 } while (error_num == 0);
6797 free_root(&mem_root, MYF(0));
6798
6799 spider_sys_index_end(table_tables);
6800 spider_close_sys_table(thd, table_tables,
6801 &open_tables_backup, TRUE);
6802 DBUG_RETURN(0);
6803 }
6804
spider_flush_logs(handlerton * hton)6805 bool spider_flush_logs(
6806 handlerton *hton
6807 ) {
6808 int error_num;
6809 THD* thd = current_thd;
6810 SPIDER_TRX *trx;
6811 DBUG_ENTER("spider_flush_logs");
6812
6813 if (!(trx = spider_get_trx(thd, TRUE, &error_num)))
6814 {
6815 my_errno = error_num;
6816 DBUG_RETURN(TRUE);
6817 }
6818 if (
6819 spider_param_use_flash_logs(trx->thd) &&
6820 (
6821 !trx->trx_consistent_snapshot ||
6822 !spider_param_use_all_conns_snapshot(trx->thd) ||
6823 !spider_param_use_snapshot_with_flush_tables(trx->thd)
6824 )
6825 ) {
6826 if (
6827 (error_num = spider_open_all_tables(trx, FALSE)) ||
6828 (error_num = spider_trx_all_flush_logs(trx))
6829 ) {
6830 my_errno = error_num;
6831 DBUG_RETURN(TRUE);
6832 }
6833 }
6834
6835 DBUG_RETURN(FALSE);
6836 }
6837
spider_create_handler(handlerton * hton,TABLE_SHARE * table,MEM_ROOT * mem_root)6838 handler* spider_create_handler(
6839 handlerton *hton,
6840 TABLE_SHARE *table,
6841 MEM_ROOT *mem_root
6842 ) {
6843 DBUG_ENTER("spider_create_handler");
6844 #ifndef WITHOUT_SPIDER_BG_SEARCH
6845 SPIDER_THREAD *thread = &spider_table_sts_threads[0];
6846 if (unlikely(thread->init_command))
6847 {
6848 THD *thd = current_thd;
6849 pthread_cond_t *cond = thd->mysys_var->current_cond;
6850 pthread_mutex_t *mutex = thd->mysys_var->current_mutex;
6851 /* wait for finishing init_command */
6852 pthread_mutex_lock(&thread->mutex);
6853 if (unlikely(thread->init_command))
6854 {
6855 thd->mysys_var->current_cond = &thread->sync_cond;
6856 thd->mysys_var->current_mutex = &thread->mutex;
6857 pthread_cond_wait(&thread->sync_cond, &thread->mutex);
6858 }
6859 pthread_mutex_unlock(&thread->mutex);
6860 thd->mysys_var->current_cond = cond;
6861 thd->mysys_var->current_mutex = mutex;
6862 if (thd->killed)
6863 {
6864 DBUG_RETURN(NULL);
6865 }
6866 }
6867 #endif
6868 DBUG_RETURN(new (mem_root) ha_spider(hton, table));
6869 }
6870
spider_close_connection(handlerton * hton,THD * thd)6871 int spider_close_connection(
6872 handlerton* hton,
6873 THD* thd
6874 ) {
6875 int roop_count = 0;
6876 SPIDER_CONN *conn;
6877 SPIDER_TRX *trx;
6878 DBUG_ENTER("spider_close_connection");
6879 if (!(trx = (SPIDER_TRX*) thd_get_ha_data(thd, spider_hton_ptr)))
6880 DBUG_RETURN(0); /* transaction is not started */
6881
6882 trx->tmp_spider->conns = &conn;
6883 while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_conn_hash,
6884 roop_count)))
6885 {
6886 SPIDER_BACKUP_DASTATUS;
6887 DBUG_PRINT("info",("spider conn->table_lock=%d", conn->table_lock));
6888 if (conn->table_lock > 0)
6889 {
6890 if (!conn->trx_start)
6891 conn->disable_reconnect = FALSE;
6892 if (conn->table_lock != 2)
6893 {
6894 spider_db_unlock_tables(trx->tmp_spider, 0);
6895 }
6896 conn->table_lock = 0;
6897 }
6898 roop_count++;
6899 SPIDER_CONN_RESTORE_DASTATUS;
6900 }
6901
6902 spider_rollback(spider_hton_ptr, thd, TRUE);
6903 spider_free_trx(trx, TRUE, false);
6904
6905 DBUG_RETURN(0);
6906 }
6907
spider_drop_database(handlerton * hton,char * path)6908 void spider_drop_database(
6909 handlerton *hton,
6910 char* path
6911 ) {
6912 DBUG_ENTER("spider_drop_database");
6913 DBUG_VOID_RETURN;
6914 }
6915
spider_show_status(handlerton * hton,THD * thd,stat_print_fn * stat_print,enum ha_stat_type stat_type)6916 bool spider_show_status(
6917 handlerton *hton,
6918 THD *thd,
6919 stat_print_fn *stat_print,
6920 enum ha_stat_type stat_type
6921 ) {
6922 DBUG_ENTER("spider_show_status");
6923 switch (stat_type) {
6924 case HA_ENGINE_STATUS:
6925 default:
6926 DBUG_RETURN(FALSE);
6927 }
6928 }
6929
spider_db_done(void * p)6930 int spider_db_done(
6931 void *p
6932 ) {
6933 int roop_count;
6934 bool do_delete_thd;
6935 THD *thd = current_thd, *tmp_thd;
6936 SPIDER_CONN *conn;
6937 SPIDER_INIT_ERROR_TABLE *spider_init_error_table;
6938 SPIDER_TABLE_MON_LIST *table_mon_list;
6939 SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share;
6940 DBUG_ENTER("spider_db_done");
6941
6942 /* Begin Spider plugin deinit */
6943 if (thd)
6944 do_delete_thd = FALSE;
6945 else
6946 {
6947 /* Create a thread for Spider plugin deinit */
6948 thd = spider_create_thd();
6949 if (!thd)
6950 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
6951 do_delete_thd = TRUE;
6952 }
6953
6954 for (roop_count = SPIDER_DBTON_SIZE - 1; roop_count >= 0; roop_count--)
6955 {
6956 if (spider_dbton[roop_count].deinit)
6957 {
6958 spider_dbton[roop_count].deinit();
6959 }
6960 }
6961
6962 #ifndef WITHOUT_SPIDER_BG_SEARCH
6963 for (roop_count = spider_param_table_crd_thread_count() - 1;
6964 roop_count >= 0; roop_count--)
6965 {
6966 spider_free_crd_threads(&spider_table_crd_threads[roop_count]);
6967 }
6968 for (roop_count = spider_param_table_sts_thread_count() - 1;
6969 roop_count >= 0; roop_count--)
6970 {
6971 spider_free_sts_threads(&spider_table_sts_threads[roop_count]);
6972 }
6973 spider_free(NULL, spider_table_sts_threads, MYF(0));
6974 #endif
6975
6976 for (roop_count = spider_param_udf_table_mon_mutex_count() - 1;
6977 roop_count >= 0; roop_count--)
6978 {
6979 while ((table_mon_list = (SPIDER_TABLE_MON_LIST *) my_hash_element(
6980 &spider_udf_table_mon_list_hash[roop_count], 0)))
6981 {
6982 #ifdef HASH_UPDATE_WITH_HASH_VALUE
6983 my_hash_delete_with_hash_value(
6984 &spider_udf_table_mon_list_hash[roop_count],
6985 table_mon_list->key_hash_value, (uchar*) table_mon_list);
6986 #else
6987 my_hash_delete(&spider_udf_table_mon_list_hash[roop_count],
6988 (uchar*) table_mon_list);
6989 #endif
6990 spider_ping_table_free_mon_list(table_mon_list);
6991 }
6992 spider_free_mem_calc(spider_current_trx,
6993 spider_udf_table_mon_list_hash_id,
6994 spider_udf_table_mon_list_hash[roop_count].array.max_element *
6995 spider_udf_table_mon_list_hash[roop_count].array.size_of_element);
6996 my_hash_free(&spider_udf_table_mon_list_hash[roop_count]);
6997 }
6998 for (roop_count = spider_param_udf_table_mon_mutex_count() - 1;
6999 roop_count >= 0; roop_count--)
7000 pthread_cond_destroy(&spider_udf_table_mon_conds[roop_count]);
7001 for (roop_count = spider_param_udf_table_mon_mutex_count() - 1;
7002 roop_count >= 0; roop_count--)
7003 pthread_mutex_destroy(&spider_udf_table_mon_mutexes[roop_count]);
7004 spider_free(NULL, spider_udf_table_mon_mutexes, MYF(0));
7005
7006 pthread_mutex_lock(&spider_allocated_thds_mutex);
7007 while ((tmp_thd = (THD *) my_hash_element(&spider_allocated_thds, 0)))
7008 {
7009 SPIDER_TRX *trx = (SPIDER_TRX *)
7010 thd_get_ha_data(tmp_thd, spider_hton_ptr);
7011 if (trx)
7012 {
7013 DBUG_ASSERT(tmp_thd == trx->thd);
7014 spider_free_trx(trx, FALSE);
7015 thd_set_ha_data(tmp_thd, spider_hton_ptr, NULL);
7016 }
7017 else
7018 my_hash_delete(&spider_allocated_thds, (uchar *) tmp_thd);
7019 }
7020 pthread_mutex_unlock(&spider_allocated_thds_mutex);
7021
7022 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
7023 pthread_mutex_lock(&spider_hs_w_conn_mutex);
7024 while ((conn = (SPIDER_CONN*) my_hash_element(&spider_hs_w_conn_hash, 0)))
7025 {
7026 #ifdef HASH_UPDATE_WITH_HASH_VALUE
7027 my_hash_delete_with_hash_value(&spider_hs_w_conn_hash,
7028 conn->conn_key_hash_value, (uchar*) conn);
7029 #else
7030 my_hash_delete(&spider_hs_w_conn_hash, (uchar*) conn);
7031 #endif
7032 spider_free_conn(conn);
7033 }
7034 pthread_mutex_unlock(&spider_hs_w_conn_mutex);
7035 pthread_mutex_lock(&spider_hs_r_conn_mutex);
7036 while ((conn = (SPIDER_CONN*) my_hash_element(&spider_hs_r_conn_hash, 0)))
7037 {
7038 #ifdef HASH_UPDATE_WITH_HASH_VALUE
7039 my_hash_delete_with_hash_value(&spider_hs_r_conn_hash,
7040 conn->conn_key_hash_value, (uchar*) conn);
7041 #else
7042 my_hash_delete(&spider_hs_r_conn_hash, (uchar*) conn);
7043 #endif
7044 spider_free_conn(conn);
7045 }
7046 pthread_mutex_unlock(&spider_hs_r_conn_mutex);
7047 #endif
7048 pthread_mutex_lock(&spider_conn_mutex);
7049 while ((conn = (SPIDER_CONN*) my_hash_element(&spider_open_connections, 0)))
7050 {
7051 #ifdef HASH_UPDATE_WITH_HASH_VALUE
7052 my_hash_delete_with_hash_value(&spider_open_connections,
7053 conn->conn_key_hash_value, (uchar*) conn);
7054 #else
7055 my_hash_delete(&spider_open_connections, (uchar*) conn);
7056 #endif
7057 spider_free_conn(conn);
7058 }
7059 pthread_mutex_unlock(&spider_conn_mutex);
7060 pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex);
7061 while ((lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE*) my_hash_element(
7062 &spider_lgtm_tblhnd_share_hash, 0)))
7063 {
7064 spider_free_lgtm_tblhnd_share_alloc(lgtm_tblhnd_share, TRUE);
7065 }
7066 pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
7067 spider_free_mem_calc(spider_current_trx,
7068 spider_mon_table_cache_id,
7069 spider_mon_table_cache.max_element *
7070 spider_mon_table_cache.size_of_element);
7071 delete_dynamic(&spider_mon_table_cache);
7072 spider_free_mem_calc(spider_current_trx,
7073 spider_allocated_thds_id,
7074 spider_allocated_thds.array.max_element *
7075 spider_allocated_thds.array.size_of_element);
7076 my_hash_free(&spider_allocated_thds);
7077 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
7078 spider_free_mem_calc(spider_current_trx,
7079 spider_hs_w_conn_hash_id,
7080 spider_hs_w_conn_hash.array.max_element *
7081 spider_hs_w_conn_hash.array.size_of_element);
7082 my_hash_free(&spider_hs_w_conn_hash);
7083 spider_free_mem_calc(spider_current_trx,
7084 spider_hs_r_conn_hash_id,
7085 spider_hs_r_conn_hash.array.max_element *
7086 spider_hs_r_conn_hash.array.size_of_element);
7087 my_hash_free(&spider_hs_r_conn_hash);
7088 #endif
7089 spider_free_mem_calc(spider_current_trx,
7090 spider_open_connections_id,
7091 spider_open_connections.array.max_element *
7092 spider_open_connections.array.size_of_element);
7093 my_hash_free(&spider_open_connections);
7094 my_hash_free(&spider_ipport_conns);
7095 spider_free_mem_calc(spider_current_trx,
7096 spider_lgtm_tblhnd_share_hash_id,
7097 spider_lgtm_tblhnd_share_hash.array.max_element *
7098 spider_lgtm_tblhnd_share_hash.array.size_of_element);
7099 my_hash_free(&spider_lgtm_tblhnd_share_hash);
7100 #ifdef WITH_PARTITION_STORAGE_ENGINE
7101 spider_free_mem_calc(spider_current_trx,
7102 spider_open_wide_share_id,
7103 spider_open_wide_share.array.max_element *
7104 spider_open_wide_share.array.size_of_element);
7105 my_hash_free(&spider_open_wide_share);
7106 #endif
7107 pthread_mutex_lock(&spider_init_error_tbl_mutex);
7108 while ((spider_init_error_table = (SPIDER_INIT_ERROR_TABLE*)
7109 my_hash_element(&spider_init_error_tables, 0)))
7110 {
7111 #ifdef HASH_UPDATE_WITH_HASH_VALUE
7112 my_hash_delete_with_hash_value(&spider_init_error_tables,
7113 spider_init_error_table->table_name_hash_value,
7114 (uchar*) spider_init_error_table);
7115 #else
7116 my_hash_delete(&spider_init_error_tables,
7117 (uchar*) spider_init_error_table);
7118 #endif
7119 spider_free(NULL, spider_init_error_table, MYF(0));
7120 }
7121 pthread_mutex_unlock(&spider_init_error_tbl_mutex);
7122 spider_free_mem_calc(spider_current_trx,
7123 spider_init_error_tables_id,
7124 spider_init_error_tables.array.max_element *
7125 spider_init_error_tables.array.size_of_element);
7126 my_hash_free(&spider_init_error_tables);
7127 spider_free_mem_calc(spider_current_trx,
7128 spider_open_tables_id,
7129 spider_open_tables.array.max_element *
7130 spider_open_tables.array.size_of_element);
7131 my_hash_free(&spider_open_tables);
7132 pthread_mutex_destroy(&spider_mem_calc_mutex);
7133 pthread_mutex_destroy(&spider_mon_table_cache_mutex);
7134 pthread_mutex_destroy(&spider_allocated_thds_mutex);
7135 pthread_mutex_destroy(&spider_open_conn_mutex);
7136 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
7137 pthread_mutex_destroy(&spider_hs_w_conn_mutex);
7138 pthread_mutex_destroy(&spider_hs_r_conn_mutex);
7139 #endif
7140 pthread_mutex_destroy(&spider_conn_mutex);
7141 pthread_mutex_destroy(&spider_lgtm_tblhnd_share_mutex);
7142 #ifdef WITH_PARTITION_STORAGE_ENGINE
7143 pthread_mutex_destroy(&spider_wide_share_mutex);
7144 #endif
7145 pthread_mutex_destroy(&spider_init_error_tbl_mutex);
7146 pthread_mutex_destroy(&spider_conn_id_mutex);
7147 pthread_mutex_destroy(&spider_ipport_conn_mutex);
7148 pthread_mutex_destroy(&spider_thread_id_mutex);
7149 pthread_mutex_destroy(&spider_tbl_mutex);
7150 #ifndef WITHOUT_SPIDER_BG_SEARCH
7151 pthread_attr_destroy(&spider_pt_attr);
7152 #endif
7153
7154 for (roop_count = 0; roop_count < SPIDER_MEM_CALC_LIST_NUM; roop_count++)
7155 {
7156 if (spider_alloc_func_name[roop_count])
7157 DBUG_PRINT("info",("spider %d %s %s %lu %llu %lld %llu %llu %s",
7158 roop_count,
7159 spider_alloc_func_name[roop_count],
7160 spider_alloc_file_name[roop_count],
7161 spider_alloc_line_no[roop_count],
7162 spider_total_alloc_mem[roop_count],
7163 spider_current_alloc_mem[roop_count],
7164 spider_alloc_mem_count[roop_count],
7165 spider_free_mem_count[roop_count],
7166 spider_current_alloc_mem[roop_count] ? "NG" : "OK"
7167 ));
7168 }
7169
7170 /* End Spider plugin deinit */
7171 if (do_delete_thd)
7172 spider_destroy_thd(thd);
7173
7174 /*
7175 DBUG_ASSERT(0);
7176 */
7177 DBUG_RETURN(0);
7178 }
7179
spider_panic(handlerton * hton,ha_panic_function type)7180 int spider_panic(
7181 handlerton *hton,
7182 ha_panic_function type
7183 ) {
7184 DBUG_ENTER("spider_panic");
7185 DBUG_RETURN(0);
7186 }
7187
spider_db_init(void * p)7188 int spider_db_init(
7189 void *p
7190 ) {
7191 int error_num = HA_ERR_OUT_OF_MEM, roop_count;
7192 uint dbton_id = 0;
7193 uchar addr[6];
7194 handlerton *spider_hton = (handlerton *)p;
7195 DBUG_ENTER("spider_db_init");
7196 spider_hton_ptr = spider_hton;
7197
7198 spider_hton->flags = HTON_NO_FLAGS;
7199 #ifdef HTON_CAN_READ_CONNECT_STRING_IN_PARTITION
7200 spider_hton->flags |= HTON_CAN_READ_CONNECT_STRING_IN_PARTITION;
7201 #endif
7202 /* spider_hton->db_type = DB_TYPE_SPIDER; */
7203 /*
7204 spider_hton->savepoint_offset;
7205 spider_hton->savepoint_set = spider_savepoint_set;
7206 spider_hton->savepoint_rollback = spider_savepoint_rollback;
7207 spider_hton->savepoint_release = spider_savepoint_release;
7208 spider_hton->create_cursor_read_view = spider_create_cursor_read_view;
7209 spider_hton->set_cursor_read_view = spider_set_cursor_read_view;
7210 spider_hton->close_cursor_read_view = spider_close_cursor_read_view;
7211 */
7212 spider_hton->panic = spider_panic;
7213 spider_hton->close_connection = spider_close_connection;
7214 spider_hton->start_consistent_snapshot = spider_start_consistent_snapshot;
7215 spider_hton->flush_logs = spider_flush_logs;
7216 spider_hton->commit = spider_commit;
7217 spider_hton->rollback = spider_rollback;
7218 #ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE
7219 spider_hton->discover_table_structure = spider_discover_table_structure;
7220 #endif
7221 if (spider_param_support_xa())
7222 {
7223 spider_hton->prepare = spider_xa_prepare;
7224 spider_hton->recover = spider_xa_recover;
7225 spider_hton->commit_by_xid = spider_xa_commit_by_xid;
7226 spider_hton->rollback_by_xid = spider_xa_rollback_by_xid;
7227 }
7228 spider_hton->create = spider_create_handler;
7229 spider_hton->drop_database = spider_drop_database;
7230 spider_hton->show_status = spider_show_status;
7231 #ifdef SPIDER_HAS_GROUP_BY_HANDLER
7232 spider_hton->create_group_by = spider_create_group_by_handler;
7233 #endif
7234
7235 if (my_gethwaddr((uchar *) addr))
7236 {
7237 my_printf_error(ER_SPIDER_CANT_NUM, ER_SPIDER_CANT_STR1, MYF(0),
7238 "get hardware address with error ", errno);
7239 }
7240 spider_unique_id.str = spider_unique_id_buf;
7241 spider_unique_id.length = my_sprintf(spider_unique_id_buf,
7242 (spider_unique_id_buf, "-%02x%02x%02x%02x%02x%02x-%lx-",
7243 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], (ulong) getpid()));
7244
7245 memset(&spider_alloc_func_name, 0, sizeof(spider_alloc_func_name));
7246 memset(&spider_alloc_file_name, 0, sizeof(spider_alloc_file_name));
7247 memset(&spider_alloc_line_no, 0, sizeof(spider_alloc_line_no));
7248 memset(&spider_total_alloc_mem, 0, sizeof(spider_total_alloc_mem));
7249 memset(&spider_current_alloc_mem, 0, sizeof(spider_current_alloc_mem));
7250 memset(&spider_alloc_mem_count, 0, sizeof(spider_alloc_mem_count));
7251 memset(&spider_free_mem_count, 0, sizeof(spider_free_mem_count));
7252
7253 #ifndef SPIDER_HAS_NEXT_THREAD_ID
7254 spd_db_att_thread_id = &thread_id;
7255 #endif
7256 #ifdef SPIDER_XID_USES_xid_cache_iterate
7257 #else
7258 #ifdef XID_CACHE_IS_SPLITTED
7259 spd_db_att_xid_cache_split_num = &opt_xid_cache_split_num;
7260 spd_db_att_LOCK_xid_cache = LOCK_xid_cache;
7261 spd_db_att_xid_cache = xid_cache;
7262 #else
7263 spd_db_att_LOCK_xid_cache = &LOCK_xid_cache;
7264 spd_db_att_xid_cache = &xid_cache;
7265 #endif
7266 #endif
7267 spd_charset_utf8mb3_bin = &my_charset_utf8mb3_bin;
7268 spd_defaults_extra_file = &my_defaults_extra_file;
7269 spd_defaults_file = &my_defaults_file;
7270 spd_mysqld_unix_port = (const char **) &mysqld_unix_port;
7271 spd_mysqld_port = &mysqld_port;
7272 spd_abort_loop = &abort_loop;
7273 spd_tz_system = my_tz_SYSTEM;
7274 spd_mysqld_server_started = &mysqld_server_started;
7275 spd_LOCK_server_started = &LOCK_server_started;
7276 spd_COND_server_started = &COND_server_started;
7277
7278 #ifdef HAVE_PSI_INTERFACE
7279 init_spider_psi_keys();
7280 #endif
7281
7282 #ifndef WITHOUT_SPIDER_BG_SEARCH
7283 if (pthread_attr_init(&spider_pt_attr))
7284 goto error_pt_attr_init;
7285 /*
7286 if (pthread_attr_setdetachstate(&spider_pt_attr, PTHREAD_CREATE_DETACHED))
7287 goto error_pt_attr_setstate;
7288 */
7289 #endif
7290
7291 #if MYSQL_VERSION_ID < 50500
7292 if (pthread_mutex_init(&spider_tbl_mutex, MY_MUTEX_INIT_FAST))
7293 #else
7294 if (mysql_mutex_init(spd_key_mutex_tbl,
7295 &spider_tbl_mutex, MY_MUTEX_INIT_FAST))
7296 #endif
7297 goto error_tbl_mutex_init;
7298 #if MYSQL_VERSION_ID < 50500
7299 if (pthread_mutex_init(&spider_thread_id_mutex, MY_MUTEX_INIT_FAST))
7300 #else
7301 if (mysql_mutex_init(spd_key_thread_id,
7302 &spider_thread_id_mutex, MY_MUTEX_INIT_FAST))
7303 #endif
7304 goto error_thread_id_mutex_init;
7305 #if MYSQL_VERSION_ID < 50500
7306 if (pthread_mutex_init(&spider_conn_id_mutex, MY_MUTEX_INIT_FAST))
7307 #else
7308 if (mysql_mutex_init(spd_key_conn_id,
7309 &spider_conn_id_mutex, MY_MUTEX_INIT_FAST))
7310 #endif
7311 goto error_conn_id_mutex_init;
7312 #if MYSQL_VERSION_ID < 50500
7313 if (pthread_mutex_init(&spider_ipport_conn_mutex, MY_MUTEX_INIT_FAST))
7314 #else
7315 if (mysql_mutex_init(spd_key_mutex_ipport_count,
7316 &spider_ipport_conn_mutex, MY_MUTEX_INIT_FAST))
7317 #endif
7318 goto error_ipport_count_mutex_init;
7319
7320 #if MYSQL_VERSION_ID < 50500
7321 if (pthread_mutex_init(&spider_init_error_tbl_mutex, MY_MUTEX_INIT_FAST))
7322 #else
7323 if (mysql_mutex_init(spd_key_mutex_init_error_tbl,
7324 &spider_init_error_tbl_mutex, MY_MUTEX_INIT_FAST))
7325 #endif
7326 goto error_init_error_tbl_mutex_init;
7327
7328 #ifdef WITH_PARTITION_STORAGE_ENGINE
7329 #if MYSQL_VERSION_ID < 50500
7330 if (pthread_mutex_init(&spider_wide_share_mutex, MY_MUTEX_INIT_FAST))
7331 #else
7332 if (mysql_mutex_init(spd_key_mutex_wide_share,
7333 &spider_wide_share_mutex, MY_MUTEX_INIT_FAST))
7334 #endif
7335 goto error_wide_share_mutex_init;
7336
7337 #endif
7338 #if MYSQL_VERSION_ID < 50500
7339 if (pthread_mutex_init(&spider_lgtm_tblhnd_share_mutex, MY_MUTEX_INIT_FAST))
7340 #else
7341 if (mysql_mutex_init(spd_key_mutex_lgtm_tblhnd_share,
7342 &spider_lgtm_tblhnd_share_mutex, MY_MUTEX_INIT_FAST))
7343 #endif
7344 goto error_lgtm_tblhnd_share_mutex_init;
7345
7346 #if MYSQL_VERSION_ID < 50500
7347 if (pthread_mutex_init(&spider_conn_mutex, MY_MUTEX_INIT_FAST))
7348 #else
7349 if (mysql_mutex_init(spd_key_mutex_conn,
7350 &spider_conn_mutex, MY_MUTEX_INIT_FAST))
7351 #endif
7352 goto error_conn_mutex_init;
7353
7354 #if MYSQL_VERSION_ID < 50500
7355 if (pthread_mutex_init(&spider_open_conn_mutex, MY_MUTEX_INIT_FAST))
7356 #else
7357 if (mysql_mutex_init(spd_key_mutex_open_conn,
7358 &spider_open_conn_mutex, MY_MUTEX_INIT_FAST))
7359 #endif
7360 goto error_open_conn_mutex_init;
7361
7362 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
7363 #if MYSQL_VERSION_ID < 50500
7364 if (pthread_mutex_init(&spider_hs_r_conn_mutex, MY_MUTEX_INIT_FAST))
7365 #else
7366 if (mysql_mutex_init(spd_key_mutex_hs_r_conn,
7367 &spider_hs_r_conn_mutex, MY_MUTEX_INIT_FAST))
7368 #endif
7369 goto error_hs_r_conn_mutex_init;
7370
7371 #if MYSQL_VERSION_ID < 50500
7372 if (pthread_mutex_init(&spider_hs_w_conn_mutex, MY_MUTEX_INIT_FAST))
7373 #else
7374 if (mysql_mutex_init(spd_key_mutex_hs_w_conn,
7375 &spider_hs_w_conn_mutex, MY_MUTEX_INIT_FAST))
7376 #endif
7377 goto error_hs_w_conn_mutex_init;
7378
7379 #endif
7380 #if MYSQL_VERSION_ID < 50500
7381 if (pthread_mutex_init(&spider_allocated_thds_mutex, MY_MUTEX_INIT_FAST))
7382 #else
7383 if (mysql_mutex_init(spd_key_mutex_allocated_thds,
7384 &spider_allocated_thds_mutex, MY_MUTEX_INIT_FAST))
7385 #endif
7386 goto error_allocated_thds_mutex_init;
7387
7388 #if MYSQL_VERSION_ID < 50500
7389 if (pthread_mutex_init(&spider_mon_table_cache_mutex, MY_MUTEX_INIT_FAST))
7390 #else
7391 if (mysql_mutex_init(spd_key_mutex_mon_table_cache,
7392 &spider_mon_table_cache_mutex, MY_MUTEX_INIT_FAST))
7393 #endif
7394 goto error_mon_table_cache_mutex_init;
7395
7396 #if MYSQL_VERSION_ID < 50500
7397 if (pthread_mutex_init(&spider_mem_calc_mutex, MY_MUTEX_INIT_FAST))
7398 #else
7399 if (mysql_mutex_init(spd_key_mutex_mem_calc,
7400 &spider_mem_calc_mutex, MY_MUTEX_INIT_FAST))
7401 #endif
7402 goto error_mem_calc_mutex_init;
7403
7404 if (my_hash_init(PSI_INSTRUMENT_ME, &spider_open_tables, spd_charset_utf8mb3_bin, 32, 0, 0,
7405 (my_hash_get_key) spider_tbl_get_key, 0, 0))
7406 goto error_open_tables_hash_init;
7407
7408 spider_alloc_calc_mem_init(spider_open_tables, 143);
7409 spider_alloc_calc_mem(NULL,
7410 spider_open_tables,
7411 spider_open_tables.array.max_element *
7412 spider_open_tables.array.size_of_element);
7413 if (my_hash_init(PSI_INSTRUMENT_ME, &spider_init_error_tables, spd_charset_utf8mb3_bin, 32, 0, 0,
7414 (my_hash_get_key) spider_tbl_get_key, 0, 0))
7415 goto error_init_error_tables_hash_init;
7416
7417 spider_alloc_calc_mem_init(spider_init_error_tables, 144);
7418 spider_alloc_calc_mem(NULL,
7419 spider_init_error_tables,
7420 spider_init_error_tables.array.max_element *
7421 spider_init_error_tables.array.size_of_element);
7422 #ifdef WITH_PARTITION_STORAGE_ENGINE
7423 if(
7424 my_hash_init(PSI_INSTRUMENT_ME, &spider_open_wide_share, spd_charset_utf8mb3_bin, 32, 0, 0,
7425 (my_hash_get_key) spider_wide_share_get_key, 0, 0)
7426 )
7427 goto error_open_wide_share_hash_init;
7428
7429 spider_alloc_calc_mem_init(spider_open_wide_share, 145);
7430 spider_alloc_calc_mem(NULL,
7431 spider_open_wide_share,
7432 spider_open_wide_share.array.max_element *
7433 spider_open_wide_share.array.size_of_element);
7434 #endif
7435 if (my_hash_init(PSI_INSTRUMENT_ME, &spider_lgtm_tblhnd_share_hash,
7436 spd_charset_utf8mb3_bin, 32, 0, 0,
7437 (my_hash_get_key) spider_lgtm_tblhnd_share_hash_get_key, 0, 0))
7438 goto error_lgtm_tblhnd_share_hash_init;
7439
7440 spider_alloc_calc_mem_init(spider_lgtm_tblhnd_share_hash, 245);
7441 spider_alloc_calc_mem(NULL,
7442 spider_lgtm_tblhnd_share_hash,
7443 spider_lgtm_tblhnd_share_hash.array.max_element *
7444 spider_lgtm_tblhnd_share_hash.array.size_of_element);
7445 if (my_hash_init(PSI_INSTRUMENT_ME, &spider_open_connections, spd_charset_utf8mb3_bin, 32, 0, 0,
7446 (my_hash_get_key) spider_conn_get_key, 0, 0))
7447 goto error_open_connections_hash_init;
7448
7449 if (my_hash_init(PSI_INSTRUMENT_ME, &spider_ipport_conns, spd_charset_utf8mb3_bin, 32, 0, 0,
7450 (my_hash_get_key) spider_ipport_conn_get_key,
7451 spider_free_ipport_conn, 0))
7452 goto error_ipport_conn__hash_init;
7453
7454 spider_alloc_calc_mem_init(spider_open_connections, 146);
7455 spider_alloc_calc_mem(NULL,
7456 spider_open_connections,
7457 spider_open_connections.array.max_element *
7458 spider_open_connections.array.size_of_element);
7459 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
7460 if (my_hash_init(PSI_INSTRUMENT_ME, &spider_hs_r_conn_hash, spd_charset_utf8mb3_bin, 32, 0, 0,
7461 (my_hash_get_key) spider_conn_get_key, 0, 0))
7462 goto error_hs_r_conn_hash_init;
7463
7464 spider_alloc_calc_mem_init(spider_hs_r_conn_hash, 147);
7465 spider_alloc_calc_mem(NULL,
7466 spider_hs_r_conn_hash,
7467 spider_hs_r_conn_hash.array.max_element *
7468 spider_hs_r_conn_hash.array.size_of_element);
7469 if (my_hash_init(PSI_INSTRUMENT_ME, &spider_hs_w_conn_hash, spd_charset_utf8mb3_bin, 32, 0, 0,
7470 (my_hash_get_key) spider_conn_get_key, 0, 0))
7471 goto error_hs_w_conn_hash_init;
7472
7473 spider_alloc_calc_mem_init(spider_hs_w_conn_hash, 148);
7474 spider_alloc_calc_mem(NULL,
7475 spider_hs_w_conn_hash,
7476 spider_hs_w_conn_hash.array.max_element *
7477 spider_hs_w_conn_hash.array.size_of_element);
7478 #endif
7479 if (my_hash_init(PSI_INSTRUMENT_ME, &spider_allocated_thds, spd_charset_utf8mb3_bin, 32, 0, 0,
7480 (my_hash_get_key) spider_allocated_thds_get_key, 0, 0))
7481 goto error_allocated_thds_hash_init;
7482
7483 spider_alloc_calc_mem_init(spider_allocated_thds, 149);
7484 spider_alloc_calc_mem(NULL,
7485 spider_allocated_thds,
7486 spider_allocated_thds.array.max_element *
7487 spider_allocated_thds.array.size_of_element);
7488
7489 if (SPD_INIT_DYNAMIC_ARRAY2(&spider_mon_table_cache, sizeof(SPIDER_MON_KEY),
7490 NULL, 64, 64, MYF(MY_WME)))
7491 goto error_mon_table_cache_array_init;
7492
7493 spider_alloc_calc_mem_init(spider_mon_table_cache, 165);
7494 spider_alloc_calc_mem(NULL,
7495 spider_mon_table_cache,
7496 spider_mon_table_cache.max_element *
7497 spider_mon_table_cache.size_of_element);
7498
7499 if (!(spider_udf_table_mon_mutexes = (pthread_mutex_t *)
7500 spider_bulk_malloc(NULL, 53, MYF(MY_WME | MY_ZEROFILL),
7501 &spider_udf_table_mon_mutexes, (uint) (sizeof(pthread_mutex_t) *
7502 spider_param_udf_table_mon_mutex_count()),
7503 &spider_udf_table_mon_conds, (uint) (sizeof(pthread_cond_t) *
7504 spider_param_udf_table_mon_mutex_count()),
7505 &spider_udf_table_mon_list_hash, (uint) (sizeof(HASH) *
7506 spider_param_udf_table_mon_mutex_count()),
7507 NullS))
7508 )
7509 goto error_alloc_mon_mutxes;
7510
7511 for (roop_count = 0;
7512 roop_count < (int) spider_param_udf_table_mon_mutex_count();
7513 roop_count++)
7514 {
7515 #if MYSQL_VERSION_ID < 50500
7516 if (pthread_mutex_init(&spider_udf_table_mon_mutexes[roop_count],
7517 MY_MUTEX_INIT_FAST))
7518 #else
7519 if (mysql_mutex_init(spd_key_mutex_udf_table_mon,
7520 &spider_udf_table_mon_mutexes[roop_count], MY_MUTEX_INIT_FAST))
7521 #endif
7522 goto error_init_udf_table_mon_mutex;
7523 }
7524 for (roop_count = 0;
7525 roop_count < (int) spider_param_udf_table_mon_mutex_count();
7526 roop_count++)
7527 {
7528 #if MYSQL_VERSION_ID < 50500
7529 if (pthread_cond_init(&spider_udf_table_mon_conds[roop_count], NULL))
7530 #else
7531 if (mysql_cond_init(spd_key_cond_udf_table_mon,
7532 &spider_udf_table_mon_conds[roop_count], NULL))
7533 #endif
7534 goto error_init_udf_table_mon_cond;
7535 }
7536 for (roop_count = 0;
7537 roop_count < (int) spider_param_udf_table_mon_mutex_count();
7538 roop_count++)
7539 {
7540 if (my_hash_init(PSI_INSTRUMENT_ME, &spider_udf_table_mon_list_hash[roop_count],
7541 spd_charset_utf8mb3_bin, 32, 0, 0,
7542 (my_hash_get_key) spider_udf_tbl_mon_list_key, 0, 0))
7543 goto error_init_udf_table_mon_list_hash;
7544
7545 spider_alloc_calc_mem_init(spider_udf_table_mon_list_hash, 150);
7546 spider_alloc_calc_mem(NULL,
7547 spider_udf_table_mon_list_hash,
7548 spider_udf_table_mon_list_hash[roop_count].array.max_element *
7549 spider_udf_table_mon_list_hash[roop_count].array.size_of_element);
7550 }
7551
7552 #ifndef WITHOUT_SPIDER_BG_SEARCH
7553 if (!(spider_table_sts_threads = (SPIDER_THREAD *)
7554 spider_bulk_malloc(NULL, 256, MYF(MY_WME | MY_ZEROFILL),
7555 &spider_table_sts_threads, (uint) (sizeof(SPIDER_THREAD) *
7556 spider_param_table_sts_thread_count()),
7557 &spider_table_crd_threads, (uint) (sizeof(SPIDER_THREAD) *
7558 spider_param_table_crd_thread_count()),
7559 NullS))
7560 )
7561 goto error_alloc_mon_mutxes;
7562 spider_table_sts_threads[0].init_command = TRUE;
7563
7564 for (roop_count = 0;
7565 roop_count < (int) spider_param_table_sts_thread_count();
7566 roop_count++)
7567 {
7568 if ((error_num = spider_create_sts_threads(&spider_table_sts_threads[roop_count])))
7569 {
7570 goto error_init_table_sts_threads;
7571 }
7572 }
7573 for (roop_count = 0;
7574 roop_count < (int) spider_param_table_crd_thread_count();
7575 roop_count++)
7576 {
7577 if ((error_num = spider_create_crd_threads(&spider_table_crd_threads[roop_count])))
7578 {
7579 goto error_init_table_crd_threads;
7580 }
7581 }
7582 #endif
7583
7584 spider_dbton_mysql.dbton_id = dbton_id;
7585 spider_dbton_mysql.db_util->dbton_id = dbton_id;
7586 spider_dbton[dbton_id] = spider_dbton_mysql;
7587 ++dbton_id;
7588 spider_dbton_mariadb.dbton_id = dbton_id;
7589 spider_dbton_mariadb.db_util->dbton_id = dbton_id;
7590 spider_dbton[dbton_id] = spider_dbton_mariadb;
7591 ++dbton_id;
7592 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
7593 spider_dbton_handlersocket.dbton_id = dbton_id;
7594 spider_dbton_handlersocket.db_util->dbton_id = dbton_id;
7595 spider_dbton[dbton_id] = spider_dbton_handlersocket;
7596 ++dbton_id;
7597 #endif
7598 #ifdef HAVE_ORACLE_OCI
7599 spider_dbton_oracle.dbton_id = dbton_id;
7600 spider_dbton_oracle.db_util->dbton_id = dbton_id;
7601 spider_dbton[dbton_id] = spider_dbton_oracle;
7602 ++dbton_id;
7603 #endif
7604 for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++)
7605 {
7606 if (spider_dbton[roop_count].init)
7607 {
7608 if ((error_num = spider_dbton[roop_count].init()))
7609 {
7610 goto error_init_dbton;
7611 }
7612 }
7613 }
7614 DBUG_RETURN(0);
7615
7616 #ifndef WITHOUT_SPIDER_BG_SEARCH
7617 error_init_dbton:
7618 for (roop_count--; roop_count >= 0; roop_count--)
7619 {
7620 if (spider_dbton[roop_count].deinit)
7621 {
7622 spider_dbton[roop_count].deinit();
7623 }
7624 }
7625 roop_count = spider_param_table_crd_thread_count() - 1;
7626 error_init_table_crd_threads:
7627 for (; roop_count >= 0; roop_count--)
7628 {
7629 spider_free_crd_threads(&spider_table_crd_threads[roop_count]);
7630 }
7631 roop_count = spider_param_table_sts_thread_count() - 1;
7632 error_init_table_sts_threads:
7633 for (; roop_count >= 0; roop_count--)
7634 {
7635 spider_free_sts_threads(&spider_table_sts_threads[roop_count]);
7636 }
7637 spider_free(NULL, spider_table_sts_threads, MYF(0));
7638 roop_count = spider_param_udf_table_mon_mutex_count() - 1;
7639 #endif
7640 error_init_udf_table_mon_list_hash:
7641 for (; roop_count >= 0; roop_count--)
7642 {
7643 spider_free_mem_calc(NULL,
7644 spider_udf_table_mon_list_hash_id,
7645 spider_udf_table_mon_list_hash[roop_count].array.max_element *
7646 spider_udf_table_mon_list_hash[roop_count].array.size_of_element);
7647 my_hash_free(&spider_udf_table_mon_list_hash[roop_count]);
7648 }
7649 roop_count = spider_param_udf_table_mon_mutex_count() - 1;
7650 error_init_udf_table_mon_cond:
7651 for (; roop_count >= 0; roop_count--)
7652 pthread_cond_destroy(&spider_udf_table_mon_conds[roop_count]);
7653 roop_count = spider_param_udf_table_mon_mutex_count() - 1;
7654 error_init_udf_table_mon_mutex:
7655 for (; roop_count >= 0; roop_count--)
7656 pthread_mutex_destroy(&spider_udf_table_mon_mutexes[roop_count]);
7657 spider_free(NULL, spider_udf_table_mon_mutexes, MYF(0));
7658 error_alloc_mon_mutxes:
7659 spider_free_mem_calc(NULL,
7660 spider_mon_table_cache_id,
7661 spider_mon_table_cache.max_element *
7662 spider_mon_table_cache.size_of_element);
7663 delete_dynamic(&spider_mon_table_cache);
7664 error_mon_table_cache_array_init:
7665 spider_free_mem_calc(NULL,
7666 spider_allocated_thds_id,
7667 spider_allocated_thds.array.max_element *
7668 spider_allocated_thds.array.size_of_element);
7669 my_hash_free(&spider_allocated_thds);
7670 error_allocated_thds_hash_init:
7671 my_hash_free(&spider_ipport_conns);
7672 error_ipport_conn__hash_init:
7673 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
7674 spider_free_mem_calc(NULL,
7675 spider_hs_w_conn_hash_id,
7676 spider_hs_w_conn_hash.array.max_element *
7677 spider_hs_w_conn_hash.array.size_of_element);
7678 my_hash_free(&spider_hs_w_conn_hash);
7679 error_hs_w_conn_hash_init:
7680 spider_free_mem_calc(NULL,
7681 spider_hs_r_conn_hash_id,
7682 spider_hs_r_conn_hash.array.max_element *
7683 spider_hs_r_conn_hash.array.size_of_element);
7684 my_hash_free(&spider_hs_r_conn_hash);
7685 error_hs_r_conn_hash_init:
7686 #endif
7687 spider_free_mem_calc(NULL,
7688 spider_open_connections_id,
7689 spider_open_connections.array.max_element *
7690 spider_open_connections.array.size_of_element);
7691 my_hash_free(&spider_open_connections);
7692 error_open_connections_hash_init:
7693 spider_free_mem_calc(NULL,
7694 spider_lgtm_tblhnd_share_hash_id,
7695 spider_lgtm_tblhnd_share_hash.array.max_element *
7696 spider_lgtm_tblhnd_share_hash.array.size_of_element);
7697 my_hash_free(&spider_lgtm_tblhnd_share_hash);
7698 error_lgtm_tblhnd_share_hash_init:
7699 #ifdef WITH_PARTITION_STORAGE_ENGINE
7700 spider_free_mem_calc(NULL,
7701 spider_open_wide_share_id,
7702 spider_open_wide_share.array.max_element *
7703 spider_open_wide_share.array.size_of_element);
7704 my_hash_free(&spider_open_wide_share);
7705 error_open_wide_share_hash_init:
7706 #endif
7707 spider_free_mem_calc(NULL,
7708 spider_init_error_tables_id,
7709 spider_init_error_tables.array.max_element *
7710 spider_init_error_tables.array.size_of_element);
7711 my_hash_free(&spider_init_error_tables);
7712 error_init_error_tables_hash_init:
7713 spider_free_mem_calc(NULL,
7714 spider_open_tables_id,
7715 spider_open_tables.array.max_element *
7716 spider_open_tables.array.size_of_element);
7717 my_hash_free(&spider_open_tables);
7718 error_open_tables_hash_init:
7719 pthread_mutex_destroy(&spider_mem_calc_mutex);
7720 error_mem_calc_mutex_init:
7721 pthread_mutex_destroy(&spider_mon_table_cache_mutex);
7722 error_mon_table_cache_mutex_init:
7723 pthread_mutex_destroy(&spider_allocated_thds_mutex);
7724 error_allocated_thds_mutex_init:
7725 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
7726 pthread_mutex_destroy(&spider_hs_w_conn_mutex);
7727 error_hs_w_conn_mutex_init:
7728 pthread_mutex_destroy(&spider_hs_r_conn_mutex);
7729 error_hs_r_conn_mutex_init:
7730 #endif
7731 pthread_mutex_destroy(&spider_open_conn_mutex);
7732 error_open_conn_mutex_init:
7733 pthread_mutex_destroy(&spider_conn_mutex);
7734 error_conn_mutex_init:
7735 pthread_mutex_destroy(&spider_lgtm_tblhnd_share_mutex);
7736 error_lgtm_tblhnd_share_mutex_init:
7737 #ifdef WITH_PARTITION_STORAGE_ENGINE
7738 pthread_mutex_destroy(&spider_wide_share_mutex);
7739 error_wide_share_mutex_init:
7740 #endif
7741 pthread_mutex_destroy(&spider_init_error_tbl_mutex);
7742 error_init_error_tbl_mutex_init:
7743 pthread_mutex_destroy(&spider_ipport_conn_mutex);
7744 error_ipport_count_mutex_init:
7745 pthread_mutex_destroy(&spider_conn_id_mutex);
7746 error_conn_id_mutex_init:
7747 pthread_mutex_destroy(&spider_thread_id_mutex);
7748 error_thread_id_mutex_init:
7749 pthread_mutex_destroy(&spider_tbl_mutex);
7750 error_tbl_mutex_init:
7751 #ifndef WITHOUT_SPIDER_BG_SEARCH
7752 /*
7753 error_pt_attr_setstate:
7754 */
7755 pthread_attr_destroy(&spider_pt_attr);
7756 error_pt_attr_init:
7757 #endif
7758 DBUG_RETURN(error_num);
7759 }
7760
spider_create_string(const char * str,uint length)7761 char *spider_create_string(
7762 const char *str,
7763 uint length
7764 ) {
7765 char *res;
7766 DBUG_ENTER("spider_create_string");
7767 if (!(res = (char*) spider_malloc(spider_current_trx, 13, length + 1,
7768 MYF(MY_WME))))
7769 DBUG_RETURN(NULL);
7770 memcpy(res, str, length);
7771 res[length] = '\0';
7772 DBUG_RETURN(res);
7773 }
7774
spider_create_table_name_string(const char * table_name,const char * part_name,const char * sub_name)7775 char *spider_create_table_name_string(
7776 const char *table_name,
7777 const char *part_name,
7778 const char *sub_name
7779 ) {
7780 char *res, *tmp;
7781 uint length = strlen(table_name);
7782 DBUG_ENTER("spider_create_table_name_string");
7783 if (part_name)
7784 {
7785 length += sizeof("#P#") - 1 + strlen(part_name);
7786 if (sub_name)
7787 length += sizeof("#SP#") - 1 + strlen(sub_name);
7788 }
7789 if (!(res = (char*) spider_malloc(spider_current_trx, 14, length + 1,
7790 MYF(MY_WME))))
7791 DBUG_RETURN(NULL);
7792 tmp = strmov(res, table_name);
7793 if (part_name)
7794 {
7795 tmp = strmov(tmp, "#P#");
7796 tmp = strmov(tmp, part_name);
7797 if (sub_name)
7798 {
7799 tmp = strmov(tmp, "#SP#");
7800 tmp = strmov(tmp, sub_name);
7801 }
7802 }
7803 DBUG_RETURN(res);
7804 }
7805
7806 #ifdef WITH_PARTITION_STORAGE_ENGINE
spider_get_partition_info(const char * table_name,uint table_name_length,const TABLE_SHARE * table_share,partition_info * part_info,partition_element ** part_elem,partition_element ** sub_elem)7807 void spider_get_partition_info(
7808 const char *table_name,
7809 uint table_name_length,
7810 const TABLE_SHARE *table_share,
7811 partition_info *part_info,
7812 partition_element **part_elem,
7813 partition_element **sub_elem
7814 ) {
7815 char tmp_name[FN_REFLEN + 1];
7816 partition_element *tmp_part_elem = NULL, *tmp_sub_elem = NULL;
7817 bool tmp_flg = FALSE, tmp_find_flg = FALSE;
7818 DBUG_ENTER("spider_get_partition_info");
7819 *part_elem = NULL;
7820 *sub_elem = NULL;
7821 if (!part_info)
7822 DBUG_VOID_RETURN;
7823
7824 if (!memcmp(table_name + table_name_length - 5, "#TMP#", 5))
7825 tmp_flg = TRUE;
7826
7827 DBUG_PRINT("info",("spider table_name=%s", table_name));
7828 List_iterator<partition_element> part_it(part_info->partitions);
7829 while ((*part_elem = part_it++))
7830 {
7831 if ((*part_elem)->subpartitions.elements)
7832 {
7833 List_iterator<partition_element> sub_it((*part_elem)->subpartitions);
7834 while ((*sub_elem = sub_it++))
7835 {
7836 if (SPIDER_create_subpartition_name(
7837 tmp_name, FN_REFLEN + 1, table_share->path.str,
7838 (*part_elem)->partition_name, (*sub_elem)->partition_name,
7839 NORMAL_PART_NAME))
7840 {
7841 DBUG_VOID_RETURN;
7842 }
7843 DBUG_PRINT("info",("spider tmp_name=%s", tmp_name));
7844 if (!memcmp(table_name, tmp_name, table_name_length + 1))
7845 DBUG_VOID_RETURN;
7846 if (
7847 tmp_flg &&
7848 *(tmp_name + table_name_length - 5) == '\0' &&
7849 !memcmp(table_name, tmp_name, table_name_length - 5)
7850 ) {
7851 tmp_part_elem = *part_elem;
7852 tmp_sub_elem = *sub_elem;
7853 tmp_flg = FALSE;
7854 tmp_find_flg = TRUE;
7855 }
7856 }
7857 } else {
7858 if (SPIDER_create_partition_name(
7859 tmp_name, FN_REFLEN + 1, table_share->path.str,
7860 (*part_elem)->partition_name, NORMAL_PART_NAME, TRUE))
7861 {
7862 DBUG_VOID_RETURN;
7863 }
7864 DBUG_PRINT("info",("spider tmp_name=%s", tmp_name));
7865 if (!memcmp(table_name, tmp_name, table_name_length + 1))
7866 DBUG_VOID_RETURN;
7867 if (
7868 tmp_flg &&
7869 *(tmp_name + table_name_length - 5) == '\0' &&
7870 !memcmp(table_name, tmp_name, table_name_length - 5)
7871 ) {
7872 tmp_part_elem = *part_elem;
7873 tmp_flg = FALSE;
7874 tmp_find_flg = TRUE;
7875 }
7876 }
7877 }
7878 if (tmp_find_flg)
7879 {
7880 *part_elem = tmp_part_elem;
7881 *sub_elem = tmp_sub_elem;
7882 DBUG_PRINT("info",("spider tmp find"));
7883 DBUG_VOID_RETURN;
7884 }
7885 *part_elem = NULL;
7886 *sub_elem = NULL;
7887 DBUG_PRINT("info",("spider no hit"));
7888 DBUG_VOID_RETURN;
7889 }
7890 #endif
7891
spider_get_sts(SPIDER_SHARE * share,int link_idx,time_t tmp_time,ha_spider * spider,double sts_interval,int sts_mode,int sts_sync,int sts_sync_level,uint flag)7892 int spider_get_sts(
7893 SPIDER_SHARE *share,
7894 int link_idx,
7895 time_t tmp_time,
7896 ha_spider *spider,
7897 double sts_interval,
7898 int sts_mode,
7899 #ifdef WITH_PARTITION_STORAGE_ENGINE
7900 int sts_sync,
7901 #endif
7902 int sts_sync_level,
7903 uint flag
7904 ) {
7905 #ifdef WITH_PARTITION_STORAGE_ENGINE
7906 int get_type;
7907 #endif
7908 int error_num = 0;
7909 bool need_to_get = TRUE;
7910 DBUG_ENTER("spider_get_sts");
7911
7912 #ifdef WITH_PARTITION_STORAGE_ENGINE
7913 if (
7914 sts_sync == 0
7915 ) {
7916 /* get */
7917 get_type = 1;
7918 } else if (
7919 !share->wide_share->sts_init
7920 ) {
7921 pthread_mutex_lock(&share->wide_share->sts_mutex);
7922 if (!share->wide_share->sts_init)
7923 {
7924 /* get after mutex_lock */
7925 get_type = 2;
7926 } else {
7927 pthread_mutex_unlock(&share->wide_share->sts_mutex);
7928 /* copy */
7929 get_type = 0;
7930 }
7931 } else if (
7932 difftime(share->sts_get_time, share->wide_share->sts_get_time) <
7933 sts_interval
7934 ) {
7935 /* copy */
7936 get_type = 0;
7937 } else if (
7938 !pthread_mutex_trylock(&share->wide_share->sts_mutex)
7939 ) {
7940 /* get after mutex_trylock */
7941 get_type = 3;
7942 } else {
7943 /* copy */
7944 get_type = 0;
7945 }
7946 #endif
7947 if (
7948 !share->sts_init &&
7949 spider_param_load_sts_at_startup(share->load_sts_at_startup) &&
7950 (!share->init || share->init_error)
7951 ) {
7952 error_num = spider_sys_get_table_sts(
7953 current_thd,
7954 share->lgtm_tblhnd_share->table_name,
7955 share->lgtm_tblhnd_share->table_name_length,
7956 &share->stat,
7957 FALSE
7958 );
7959 if (
7960 !error_num ||
7961 (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
7962 )
7963 need_to_get = FALSE;
7964 }
7965
7966 if (need_to_get)
7967 {
7968 #ifdef WITH_PARTITION_STORAGE_ENGINE
7969 if (get_type == 0)
7970 spider_copy_sts_to_share(share, share->wide_share);
7971 else {
7972 #endif
7973 error_num = spider_db_show_table_status(spider, link_idx, sts_mode, flag);
7974 #ifdef WITH_PARTITION_STORAGE_ENGINE
7975 }
7976 #endif
7977 }
7978 #ifdef WITH_PARTITION_STORAGE_ENGINE
7979 if (get_type >= 2)
7980 pthread_mutex_unlock(&share->wide_share->sts_mutex);
7981 #endif
7982 if (error_num)
7983 {
7984 #ifdef WITH_PARTITION_STORAGE_ENGINE
7985 SPIDER_PARTITION_HANDLER *partition_handler =
7986 spider->partition_handler;
7987 if (
7988 !share->wide_share->sts_init &&
7989 sts_sync >= sts_sync_level &&
7990 get_type > 1 &&
7991 partition_handler &&
7992 partition_handler->handlers &&
7993 partition_handler->handlers[0] == spider
7994 ) {
7995 int roop_count;
7996 ha_spider *tmp_spider;
7997 SPIDER_SHARE *tmp_share;
7998 double tmp_sts_interval;
7999 int tmp_sts_mode;
8000 int tmp_sts_sync;
8001 THD *thd = spider->wide_handler->trx->thd;
8002 for (roop_count = 1;
8003 roop_count < (int) partition_handler->no_parts;
8004 roop_count++)
8005 {
8006 tmp_spider =
8007 (ha_spider *) partition_handler->handlers[roop_count];
8008 tmp_share = tmp_spider->share;
8009 tmp_sts_interval = spider_param_sts_interval(thd, share->sts_interval);
8010 tmp_sts_mode = spider_param_sts_mode(thd, share->sts_mode);
8011 tmp_sts_sync = spider_param_sts_sync(thd, share->sts_sync);
8012 spider_get_sts(tmp_share, tmp_spider->search_link_idx,
8013 tmp_time, tmp_spider, tmp_sts_interval, tmp_sts_mode, tmp_sts_sync,
8014 1, flag);
8015 if (share->wide_share->sts_init)
8016 {
8017 error_num = 0;
8018 thd->clear_error();
8019 get_type = 0;
8020 spider_copy_sts_to_share(share, share->wide_share);
8021 break;
8022 }
8023 }
8024 }
8025 if (error_num)
8026 #endif
8027 DBUG_RETURN(error_num);
8028 }
8029 #ifdef WITH_PARTITION_STORAGE_ENGINE
8030 if (sts_sync >= sts_sync_level && get_type > 0)
8031 {
8032 spider_copy_sts_to_wide_share(share->wide_share, share);
8033 share->wide_share->sts_get_time = tmp_time;
8034 share->wide_share->sts_init = TRUE;
8035 }
8036 #endif
8037 share->sts_get_time = tmp_time;
8038 share->sts_init = TRUE;
8039 DBUG_RETURN(0);
8040 }
8041
spider_get_crd(SPIDER_SHARE * share,int link_idx,time_t tmp_time,ha_spider * spider,TABLE * table,double crd_interval,int crd_mode,int crd_sync,int crd_sync_level)8042 int spider_get_crd(
8043 SPIDER_SHARE *share,
8044 int link_idx,
8045 time_t tmp_time,
8046 ha_spider *spider,
8047 TABLE *table,
8048 double crd_interval,
8049 int crd_mode,
8050 #ifdef WITH_PARTITION_STORAGE_ENGINE
8051 int crd_sync,
8052 #endif
8053 int crd_sync_level
8054 ) {
8055 #ifdef WITH_PARTITION_STORAGE_ENGINE
8056 int get_type;
8057 #endif
8058 int error_num = 0;
8059 bool need_to_get = TRUE;
8060 DBUG_ENTER("spider_get_crd");
8061
8062 #ifdef WITH_PARTITION_STORAGE_ENGINE
8063 if (
8064 crd_sync == 0
8065 ) {
8066 /* get */
8067 get_type = 1;
8068 } else if (
8069 !share->wide_share->crd_init
8070 ) {
8071 pthread_mutex_lock(&share->wide_share->crd_mutex);
8072 if (!share->wide_share->crd_init)
8073 {
8074 /* get after mutex_lock */
8075 get_type = 2;
8076 } else {
8077 pthread_mutex_unlock(&share->wide_share->crd_mutex);
8078 /* copy */
8079 get_type = 0;
8080 }
8081 } else if (
8082 difftime(share->crd_get_time, share->wide_share->crd_get_time) <
8083 crd_interval
8084 ) {
8085 /* copy */
8086 get_type = 0;
8087 } else if (
8088 !pthread_mutex_trylock(&share->wide_share->crd_mutex)
8089 ) {
8090 /* get after mutex_trylock */
8091 get_type = 3;
8092 } else {
8093 /* copy */
8094 get_type = 0;
8095 }
8096 #endif
8097 if (
8098 !share->crd_init &&
8099 spider_param_load_sts_at_startup(share->load_crd_at_startup)
8100 ) {
8101 error_num = spider_sys_get_table_crd(
8102 current_thd,
8103 share->lgtm_tblhnd_share->table_name,
8104 share->lgtm_tblhnd_share->table_name_length,
8105 share->cardinality,
8106 table->s->fields,
8107 FALSE
8108 );
8109 if (
8110 !error_num ||
8111 (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
8112 )
8113 need_to_get = FALSE;
8114 }
8115
8116 if (need_to_get)
8117 {
8118 #ifdef WITH_PARTITION_STORAGE_ENGINE
8119 if (get_type == 0)
8120 spider_copy_crd_to_share(share, share->wide_share,
8121 table->s->fields);
8122 else {
8123 #endif
8124 error_num = spider_db_show_index(spider, link_idx, table, crd_mode);
8125 #ifdef WITH_PARTITION_STORAGE_ENGINE
8126 }
8127 #endif
8128 }
8129 #ifdef WITH_PARTITION_STORAGE_ENGINE
8130 if (get_type >= 2)
8131 pthread_mutex_unlock(&share->wide_share->crd_mutex);
8132 #endif
8133 if (error_num)
8134 {
8135 #ifdef WITH_PARTITION_STORAGE_ENGINE
8136 SPIDER_PARTITION_HANDLER *partition_handler =
8137 spider->partition_handler;
8138 if (
8139 !share->wide_share->crd_init &&
8140 crd_sync >= crd_sync_level &&
8141 get_type > 1 &&
8142 partition_handler &&
8143 partition_handler->handlers &&
8144 partition_handler->handlers[0] == spider
8145 ) {
8146 int roop_count;
8147 ha_spider *tmp_spider;
8148 SPIDER_SHARE *tmp_share;
8149 double tmp_crd_interval;
8150 int tmp_crd_mode;
8151 int tmp_crd_sync;
8152 THD *thd = spider->wide_handler->trx->thd;
8153 for (roop_count = 1;
8154 roop_count < (int) partition_handler->no_parts;
8155 roop_count++)
8156 {
8157 tmp_spider =
8158 (ha_spider *) partition_handler->handlers[roop_count];
8159 tmp_share = tmp_spider->share;
8160 tmp_crd_interval = spider_param_crd_interval(thd, share->crd_interval);
8161 tmp_crd_mode = spider_param_crd_mode(thd, share->crd_mode);
8162 tmp_crd_sync = spider_param_crd_sync(thd, share->crd_sync);
8163 spider_get_crd(tmp_share, tmp_spider->search_link_idx,
8164 tmp_time, tmp_spider, table, tmp_crd_interval, tmp_crd_mode,
8165 tmp_crd_sync, 1);
8166 if (share->wide_share->crd_init)
8167 {
8168 error_num = 0;
8169 thd->clear_error();
8170 get_type = 0;
8171 spider_copy_crd_to_share(share, share->wide_share,
8172 table->s->fields);
8173 break;
8174 }
8175 }
8176 }
8177 if (error_num)
8178 #endif
8179 DBUG_RETURN(error_num);
8180 }
8181 #ifdef WITH_PARTITION_STORAGE_ENGINE
8182 if (crd_sync >= crd_sync_level && get_type > 0)
8183 {
8184 spider_copy_crd_to_wide_share(share->wide_share, share,
8185 table->s->fields);
8186 share->wide_share->crd_get_time = tmp_time;
8187 share->wide_share->crd_init = TRUE;
8188 }
8189 #endif
8190 share->crd_get_time = tmp_time;
8191 share->crd_init = TRUE;
8192 DBUG_RETURN(0);
8193 }
8194
spider_set_result_list_param(ha_spider * spider)8195 void spider_set_result_list_param(
8196 ha_spider *spider
8197 ) {
8198 SPIDER_RESULT_LIST *result_list = &spider->result_list;
8199 SPIDER_SHARE *share = spider->share;
8200 THD *thd = spider->wide_handler->trx->thd;
8201 DBUG_ENTER("spider_set_result_list_param");
8202 result_list->internal_offset =
8203 spider_param_internal_offset(thd, share->internal_offset);
8204 result_list->internal_limit =
8205 #ifdef INFO_KIND_FORCE_LIMIT_BEGIN
8206 spider->wide_handler->info_limit < 9223372036854775807LL ?
8207 spider->wide_handler->info_limit :
8208 #endif
8209 spider_param_internal_limit(thd, share->internal_limit);
8210 result_list->split_read = spider_split_read_param(spider);
8211 if (spider->support_multi_split_read_sql())
8212 {
8213 result_list->multi_split_read =
8214 spider_param_multi_split_read(thd, share->multi_split_read);
8215 } else {
8216 result_list->multi_split_read = 1;
8217 }
8218 result_list->max_order =
8219 spider_param_max_order(thd, share->max_order);
8220 result_list->quick_mode =
8221 spider_param_quick_mode(thd, share->quick_mode);
8222 result_list->quick_page_size =
8223 spider_param_quick_page_size(thd, share->quick_page_size);
8224 result_list->quick_page_byte =
8225 spider_param_quick_page_byte(thd, share->quick_page_byte);
8226 result_list->low_mem_read =
8227 spider_param_low_mem_read(thd, share->low_mem_read);
8228 DBUG_VOID_RETURN;
8229 }
8230
spider_get_init_error_table(SPIDER_TRX * trx,SPIDER_SHARE * share,bool create)8231 SPIDER_INIT_ERROR_TABLE *spider_get_init_error_table(
8232 SPIDER_TRX *trx,
8233 SPIDER_SHARE *share,
8234 bool create
8235 ) {
8236 SPIDER_INIT_ERROR_TABLE *spider_init_error_table;
8237 char *tmp_name;
8238 DBUG_ENTER("spider_get_init_error_table");
8239 pthread_mutex_lock(&spider_init_error_tbl_mutex);
8240 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
8241 if (!(spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *)
8242 my_hash_search_using_hash_value(
8243 &spider_init_error_tables, share->table_name_hash_value,
8244 (uchar*) share->table_name, share->table_name_length)))
8245 #else
8246 if (!(spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *) my_hash_search(
8247 &spider_init_error_tables,
8248 (uchar*) share->table_name, share->table_name_length)))
8249 #endif
8250 {
8251 if (!create)
8252 {
8253 pthread_mutex_unlock(&spider_init_error_tbl_mutex);
8254 DBUG_RETURN(NULL);
8255 }
8256 if (!(spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *)
8257 spider_bulk_malloc(spider_current_trx, 54, MYF(MY_WME | MY_ZEROFILL),
8258 &spider_init_error_table, (uint) (sizeof(*spider_init_error_table)),
8259 &tmp_name, (uint) (share->table_name_length + 1),
8260 NullS))
8261 ) {
8262 pthread_mutex_unlock(&spider_init_error_tbl_mutex);
8263 DBUG_RETURN(NULL);
8264 }
8265 memcpy(tmp_name, share->table_name, share->table_name_length);
8266 spider_init_error_table->table_name = tmp_name;
8267 spider_init_error_table->table_name_length = share->table_name_length;
8268 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
8269 spider_init_error_table->table_name_hash_value =
8270 share->table_name_hash_value;
8271 #endif
8272 uint old_elements = spider_init_error_tables.array.max_element;
8273 #ifdef HASH_UPDATE_WITH_HASH_VALUE
8274 if (my_hash_insert_with_hash_value(&spider_init_error_tables,
8275 share->table_name_hash_value, (uchar*) spider_init_error_table))
8276 #else
8277 if (my_hash_insert(&spider_init_error_tables,
8278 (uchar*) spider_init_error_table))
8279 #endif
8280 {
8281 spider_free(trx, spider_init_error_table, MYF(0));
8282 pthread_mutex_unlock(&spider_init_error_tbl_mutex);
8283 DBUG_RETURN(NULL);
8284 }
8285 if (spider_init_error_tables.array.max_element > old_elements)
8286 {
8287 spider_alloc_calc_mem(spider_current_trx,
8288 spider_init_error_tables,
8289 (spider_init_error_tables.array.max_element - old_elements) *
8290 spider_init_error_tables.array.size_of_element);
8291 }
8292 }
8293 pthread_mutex_unlock(&spider_init_error_tbl_mutex);
8294 DBUG_RETURN(spider_init_error_table);
8295 }
8296
spider_delete_init_error_table(const char * name)8297 void spider_delete_init_error_table(
8298 const char *name
8299 ) {
8300 SPIDER_INIT_ERROR_TABLE *spider_init_error_table;
8301 uint length = strlen(name);
8302 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
8303 my_hash_value_type hash_value = my_calc_hash(&spider_open_tables,
8304 (uchar*) name, length);
8305 #endif
8306 DBUG_ENTER("spider_delete_init_error_table");
8307 pthread_mutex_lock(&spider_init_error_tbl_mutex);
8308 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
8309 if ((spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *)
8310 my_hash_search_using_hash_value(&spider_init_error_tables, hash_value,
8311 (uchar*) name, length)))
8312 #else
8313 if ((spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *) my_hash_search(
8314 &spider_init_error_tables, (uchar*) name, length)))
8315 #endif
8316 {
8317 #ifdef HASH_UPDATE_WITH_HASH_VALUE
8318 my_hash_delete_with_hash_value(&spider_init_error_tables,
8319 spider_init_error_table->table_name_hash_value,
8320 (uchar*) spider_init_error_table);
8321 #else
8322 my_hash_delete(&spider_init_error_tables,
8323 (uchar*) spider_init_error_table);
8324 #endif
8325 spider_free(spider_current_trx, spider_init_error_table, MYF(0));
8326 }
8327 pthread_mutex_unlock(&spider_init_error_tbl_mutex);
8328 DBUG_VOID_RETURN;
8329 }
8330
spider_check_pk_update(TABLE * table)8331 bool spider_check_pk_update(
8332 TABLE *table
8333 ) {
8334 int roop_count;
8335 TABLE_SHARE *table_share = table->s;
8336 KEY *key_info;
8337 KEY_PART_INFO *key_part;
8338 DBUG_ENTER("spider_check_pk_update");
8339 if (table_share->primary_key == MAX_KEY)
8340 DBUG_RETURN(FALSE);
8341
8342 key_info = &table_share->key_info[table_share->primary_key];
8343 key_part = key_info->key_part;
8344 for (roop_count = 0;
8345 roop_count < (int) spider_user_defined_key_parts(key_info); roop_count++)
8346 {
8347 if (bitmap_is_set(table->write_set,
8348 key_part[roop_count].field->field_index))
8349 DBUG_RETURN(TRUE);
8350 }
8351 DBUG_RETURN(FALSE);
8352 }
8353
8354 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
8355 #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
spider_check_hs_pk_update(ha_spider * spider,key_range * key)8356 bool spider_check_hs_pk_update(
8357 ha_spider *spider,
8358 key_range *key
8359 ) {
8360 uint roop_count, field_index, set_count = 0;
8361 TABLE *table = spider->get_table();
8362 TABLE_SHARE *table_share = table->s;
8363 SPIDER_SHARE *share = spider->share;
8364 KEY *key_info;
8365 KEY_PART_INFO *key_part;
8366 char buf[MAX_FIELD_WIDTH], buf2[MAX_FIELD_WIDTH];
8367 spider_string tmp_str(buf, MAX_FIELD_WIDTH, &my_charset_bin),
8368 tmp_str2(buf2, MAX_FIELD_WIDTH, &my_charset_bin);
8369 String *str, *str2;
8370 DBUG_ENTER("spider_check_hs_pk_update");
8371 tmp_str.init_calc_mem(137);
8372
8373 if (table_share->primary_key == MAX_KEY)
8374 DBUG_RETURN(FALSE);
8375 memset(spider->tmp_column_bitmap, 0, sizeof(uchar) * share->bitmap_size);
8376 key_info = &table->key_info[table_share->primary_key];
8377 key_part = key_info->key_part;
8378 for (roop_count = 0; roop_count < spider_user_defined_key_parts(key_info);
8379 roop_count++)
8380 {
8381 field_index = key_part[roop_count].field->field_index;
8382 if (bitmap_is_set(table->write_set, field_index))
8383 {
8384 DBUG_PRINT("info", ("spider set key_part=%u field_index=%u",
8385 roop_count, field_index));
8386 spider_set_bit(spider->tmp_column_bitmap, field_index);
8387 set_count++;
8388 }
8389 }
8390 DBUG_PRINT("info", ("spider set_count=%u", set_count));
8391
8392 Field *field;
8393 uint store_length, length, var_len;
8394 const uchar *ptr;
8395 bool key_eq;
8396 key_part_map tgt_key_part_map = key->keypart_map;
8397 key_info = &table->key_info[spider->active_index];
8398 for (
8399 key_part = key_info->key_part,
8400 length = 0;
8401 tgt_key_part_map;
8402 length += store_length,
8403 tgt_key_part_map >>= 1,
8404 key_part++
8405 ) {
8406 store_length = key_part->store_length;
8407 field = key_part->field;
8408 field_index = field->field_index;
8409 if (spider_bit_is_set(spider->tmp_column_bitmap, field_index))
8410 {
8411 ptr = key->key + length;
8412 key_eq = (tgt_key_part_map > 1);
8413 if (key_part->null_bit && *ptr++)
8414 {
8415 if (key->flag != HA_READ_KEY_EXACT || !field->is_null())
8416 {
8417 DBUG_PRINT("info", ("spider flag=%u is_null=%s",
8418 key->flag, field->is_null() ? "TRUE" : "FALSE"));
8419 DBUG_RETURN(TRUE);
8420 }
8421 } else {
8422 if (
8423 field->type() == MYSQL_TYPE_BLOB ||
8424 field->real_type() == MYSQL_TYPE_VARCHAR ||
8425 field->type() == MYSQL_TYPE_GEOMETRY
8426 ) {
8427 var_len = uint2korr(ptr);
8428 tmp_str.set_quick((char *) ptr + HA_KEY_BLOB_LENGTH, var_len,
8429 &my_charset_bin);
8430 str = tmp_str.get_str();
8431 } else {
8432 str = field->val_str(tmp_str.get_str(), ptr);
8433 tmp_str.mem_calc();
8434 }
8435 str2 = field->val_str(tmp_str2.get_str());
8436 tmp_str2.mem_calc();
8437 if (
8438 str->length() != str2->length() ||
8439 memcmp(str->ptr(), str2->ptr(), str->length())
8440 ) {
8441 DBUG_PRINT("info", ("spider length=%u %u",
8442 str->length(), str2->length()));
8443 DBUG_PRINT("info", ("spider length=%s %s",
8444 str->c_ptr_safe(), str2->c_ptr_safe()));
8445 DBUG_RETURN(TRUE);
8446 }
8447 }
8448 set_count--;
8449 }
8450 }
8451 DBUG_PRINT("info", ("spider set_count=%u", set_count));
8452 if (set_count)
8453 {
8454 DBUG_RETURN(TRUE);
8455 }
8456 DBUG_RETURN(FALSE);
8457 }
8458 #endif
8459 #endif
8460
spider_set_tmp_share_pointer(SPIDER_SHARE * tmp_share,char ** tmp_connect_info,uint * tmp_connect_info_length,long * tmp_long,longlong * tmp_longlong)8461 void spider_set_tmp_share_pointer(
8462 SPIDER_SHARE *tmp_share,
8463 char **tmp_connect_info,
8464 uint *tmp_connect_info_length,
8465 long *tmp_long,
8466 longlong *tmp_longlong
8467 ) {
8468 DBUG_ENTER("spider_set_tmp_share_pointer");
8469 tmp_share->link_count = 1;
8470 tmp_share->all_link_count = 1;
8471 tmp_share->server_names = &tmp_connect_info[0];
8472 tmp_share->tgt_table_names = &tmp_connect_info[1];
8473 tmp_share->tgt_dbs = &tmp_connect_info[2];
8474 tmp_share->tgt_hosts = &tmp_connect_info[3];
8475 tmp_share->tgt_usernames = &tmp_connect_info[4];
8476 tmp_share->tgt_passwords = &tmp_connect_info[5];
8477 tmp_share->tgt_sockets = &tmp_connect_info[6];
8478 tmp_share->tgt_wrappers = &tmp_connect_info[7];
8479 tmp_share->tgt_ssl_cas = &tmp_connect_info[8];
8480 tmp_share->tgt_ssl_capaths = &tmp_connect_info[9];
8481 tmp_share->tgt_ssl_certs = &tmp_connect_info[10];
8482 tmp_share->tgt_ssl_ciphers = &tmp_connect_info[11];
8483 tmp_share->tgt_ssl_keys = &tmp_connect_info[12];
8484 tmp_share->tgt_default_files = &tmp_connect_info[13];
8485 tmp_share->tgt_default_groups = &tmp_connect_info[14];
8486 tmp_share->tgt_dsns = &tmp_connect_info[15];
8487 tmp_share->tgt_pk_names = &tmp_connect_info[16];
8488 tmp_share->tgt_sequence_names = &tmp_connect_info[17];
8489 tmp_share->static_link_ids = &tmp_connect_info[18];
8490 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
8491 tmp_share->hs_read_socks = &tmp_connect_info[19];
8492 tmp_share->hs_write_socks = &tmp_connect_info[20];
8493 #endif
8494 tmp_share->tgt_ports = &tmp_long[0];
8495 tmp_share->tgt_ssl_vscs = &tmp_long[1];
8496 tmp_share->link_statuses = &tmp_long[2];
8497 tmp_share->monitoring_binlog_pos_at_failing = &tmp_long[3];
8498 tmp_share->monitoring_flag = &tmp_long[4];
8499 tmp_share->monitoring_kind = &tmp_long[5];
8500 #ifndef WITHOUT_SPIDER_BG_SEARCH
8501 tmp_share->monitoring_bg_flag = &tmp_long[6];
8502 tmp_share->monitoring_bg_kind = &tmp_long[7];
8503 #endif
8504 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
8505 tmp_share->use_hs_reads = &tmp_long[8];
8506 tmp_share->use_hs_writes = &tmp_long[9];
8507 tmp_share->hs_read_ports = &tmp_long[10];
8508 tmp_share->hs_write_ports = &tmp_long[11];
8509 tmp_share->hs_write_to_reads = &tmp_long[12];
8510 #endif
8511 tmp_share->use_handlers = &tmp_long[13];
8512 tmp_share->connect_timeouts = &tmp_long[14];
8513 tmp_long[13] = -1;
8514 tmp_share->net_read_timeouts = &tmp_long[15];
8515 tmp_long[14] = -1;
8516 tmp_share->net_write_timeouts = &tmp_long[16];
8517 tmp_long[15] = -1;
8518 tmp_share->access_balances = &tmp_long[17];
8519 tmp_share->bka_table_name_types = &tmp_long[18];
8520 tmp_share->strict_group_bys = &tmp_long[19];
8521 tmp_share->monitoring_limit = &tmp_longlong[0];
8522 tmp_share->monitoring_sid = &tmp_longlong[1];
8523 #ifndef WITHOUT_SPIDER_BG_SEARCH
8524 tmp_share->monitoring_bg_interval = &tmp_longlong[2];
8525 #endif
8526 tmp_share->server_names_lengths = &tmp_connect_info_length[0];
8527 tmp_share->tgt_table_names_lengths = &tmp_connect_info_length[1];
8528 tmp_share->tgt_dbs_lengths = &tmp_connect_info_length[2];
8529 tmp_share->tgt_hosts_lengths = &tmp_connect_info_length[3];
8530 tmp_share->tgt_usernames_lengths = &tmp_connect_info_length[4];
8531 tmp_share->tgt_passwords_lengths = &tmp_connect_info_length[5];
8532 tmp_share->tgt_sockets_lengths = &tmp_connect_info_length[6];
8533 tmp_share->tgt_wrappers_lengths = &tmp_connect_info_length[7];
8534 tmp_share->tgt_ssl_cas_lengths = &tmp_connect_info_length[8];
8535 tmp_share->tgt_ssl_capaths_lengths = &tmp_connect_info_length[9];
8536 tmp_share->tgt_ssl_certs_lengths = &tmp_connect_info_length[10];
8537 tmp_share->tgt_ssl_ciphers_lengths = &tmp_connect_info_length[11];
8538 tmp_share->tgt_ssl_keys_lengths = &tmp_connect_info_length[12];
8539 tmp_share->tgt_default_files_lengths = &tmp_connect_info_length[13];
8540 tmp_share->tgt_default_groups_lengths = &tmp_connect_info_length[14];
8541 tmp_share->tgt_dsns_lengths = &tmp_connect_info_length[15];
8542 tmp_share->tgt_pk_names_lengths = &tmp_connect_info_length[16];
8543 tmp_share->tgt_sequence_names_lengths = &tmp_connect_info_length[17];
8544 tmp_share->static_link_ids_lengths = &tmp_connect_info_length[18];
8545 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
8546 tmp_share->hs_read_socks_lengths = &tmp_connect_info_length[19];
8547 tmp_share->hs_write_socks_lengths = &tmp_connect_info_length[20];
8548 #endif
8549 tmp_share->server_names_length = 1;
8550 tmp_share->tgt_table_names_length = 1;
8551 tmp_share->tgt_dbs_length = 1;
8552 tmp_share->tgt_hosts_length = 1;
8553 tmp_share->tgt_usernames_length = 1;
8554 tmp_share->tgt_passwords_length = 1;
8555 tmp_share->tgt_sockets_length = 1;
8556 tmp_share->tgt_wrappers_length = 1;
8557 tmp_share->tgt_ssl_cas_length = 1;
8558 tmp_share->tgt_ssl_capaths_length = 1;
8559 tmp_share->tgt_ssl_certs_length = 1;
8560 tmp_share->tgt_ssl_ciphers_length = 1;
8561 tmp_share->tgt_ssl_keys_length = 1;
8562 tmp_share->tgt_default_files_length = 1;
8563 tmp_share->tgt_default_groups_length = 1;
8564 tmp_share->tgt_dsns_length = 1;
8565 tmp_share->tgt_pk_names_length = 1;
8566 tmp_share->tgt_sequence_names_length = 1;
8567 tmp_share->static_link_ids_length = 1;
8568 tmp_share->tgt_ports_length = 1;
8569 tmp_share->tgt_ssl_vscs_length = 1;
8570 tmp_share->link_statuses_length = 1;
8571 tmp_share->monitoring_binlog_pos_at_failing_length = 1;
8572 tmp_share->monitoring_flag_length = 1;
8573 tmp_share->monitoring_kind_length = 1;
8574 #ifndef WITHOUT_SPIDER_BG_SEARCH
8575 tmp_share->monitoring_bg_flag_length = 1;
8576 tmp_share->monitoring_bg_kind_length = 1;
8577 #endif
8578 tmp_share->monitoring_limit_length = 1;
8579 tmp_share->monitoring_sid_length = 1;
8580 #ifndef WITHOUT_SPIDER_BG_SEARCH
8581 tmp_share->monitoring_bg_interval_length = 1;
8582 #endif
8583 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
8584 tmp_share->hs_read_socks_length = 1;
8585 tmp_share->hs_write_socks_length = 1;
8586 tmp_share->use_hs_reads_length = 1;
8587 tmp_share->use_hs_writes_length = 1;
8588 tmp_share->hs_read_ports_length = 1;
8589 tmp_share->hs_write_ports_length = 1;
8590 tmp_share->hs_write_to_reads_length = 1;
8591 #endif
8592 tmp_share->use_handlers_length = 1;
8593 tmp_share->connect_timeouts_length = 1;
8594 tmp_share->net_read_timeouts_length = 1;
8595 tmp_share->net_write_timeouts_length = 1;
8596 tmp_share->access_balances_length = 1;
8597 tmp_share->bka_table_name_types_length = 1;
8598 tmp_share->strict_group_bys_length = 1;
8599
8600 #ifndef WITHOUT_SPIDER_BG_SEARCH
8601 tmp_share->monitoring_bg_flag[0] = -1;
8602 tmp_share->monitoring_bg_kind[0] = -1;
8603 #endif
8604 tmp_share->monitoring_binlog_pos_at_failing[0] = -1;
8605 tmp_share->monitoring_flag[0] = -1;
8606 tmp_share->monitoring_kind[0] = -1;
8607 #ifndef WITHOUT_SPIDER_BG_SEARCH
8608 tmp_share->monitoring_bg_interval[0] = -1;
8609 #endif
8610 tmp_share->monitoring_limit[0] = -1;
8611 tmp_share->monitoring_sid[0] = -1;
8612 tmp_share->bka_engine = NULL;
8613 tmp_share->use_dbton_count = 0;
8614 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
8615 tmp_share->use_hs_dbton_count = 0;
8616 #endif
8617 DBUG_VOID_RETURN;
8618 }
8619
spider_create_tmp_dbton_share(SPIDER_SHARE * tmp_share)8620 int spider_create_tmp_dbton_share(
8621 SPIDER_SHARE *tmp_share
8622 ) {
8623 int error_num;
8624 uint dbton_id = tmp_share->use_dbton_ids[0];
8625 DBUG_ENTER("spider_create_tmp_dbton_share");
8626 if (!(tmp_share->dbton_share[dbton_id] =
8627 spider_dbton[dbton_id].create_db_share(tmp_share)))
8628 {
8629 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
8630 }
8631 if ((error_num = tmp_share->dbton_share[dbton_id]->init()))
8632 {
8633 delete tmp_share->dbton_share[dbton_id];
8634 tmp_share->dbton_share[dbton_id] = NULL;
8635 DBUG_RETURN(error_num);
8636 }
8637 DBUG_RETURN(0);
8638 }
8639
spider_free_tmp_dbton_share(SPIDER_SHARE * tmp_share)8640 void spider_free_tmp_dbton_share(
8641 SPIDER_SHARE *tmp_share
8642 ) {
8643 uint dbton_id = tmp_share->use_dbton_ids[0];
8644 DBUG_ENTER("spider_free_tmp_dbton_share");
8645 if (tmp_share->dbton_share[dbton_id])
8646 {
8647 delete tmp_share->dbton_share[dbton_id];
8648 tmp_share->dbton_share[dbton_id] = NULL;
8649 }
8650 DBUG_VOID_RETURN;
8651 }
8652
spider_create_tmp_dbton_handler(ha_spider * tmp_spider)8653 int spider_create_tmp_dbton_handler(
8654 ha_spider *tmp_spider
8655 ) {
8656 int error_num;
8657 SPIDER_SHARE *tmp_share = tmp_spider->share;
8658 uint dbton_id = tmp_share->use_dbton_ids[0];
8659 DBUG_ENTER("spider_create_tmp_dbton_handler");
8660 if (!(tmp_spider->dbton_handler[dbton_id] =
8661 spider_dbton[dbton_id].create_db_handler(tmp_spider,
8662 tmp_share->dbton_share[dbton_id])))
8663 {
8664 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
8665 }
8666 if ((error_num = tmp_spider->dbton_handler[dbton_id]->init()))
8667 {
8668 delete tmp_spider->dbton_handler[dbton_id];
8669 tmp_spider->dbton_handler[dbton_id] = NULL;
8670 DBUG_RETURN(error_num);
8671 }
8672 DBUG_RETURN(0);
8673 }
8674
spider_free_tmp_dbton_handler(ha_spider * tmp_spider)8675 void spider_free_tmp_dbton_handler(
8676 ha_spider *tmp_spider
8677 ) {
8678 SPIDER_SHARE *tmp_share = tmp_spider->share;
8679 uint dbton_id = tmp_share->use_dbton_ids[0];
8680 DBUG_ENTER("spider_create_tmp_dbton_handler");
8681 if (tmp_spider->dbton_handler[dbton_id])
8682 {
8683 delete tmp_spider->dbton_handler[dbton_id];
8684 tmp_spider->dbton_handler[dbton_id] = NULL;
8685 }
8686 DBUG_VOID_RETURN;
8687 }
8688
spider_get_parent_table_list(ha_spider * spider)8689 TABLE_LIST *spider_get_parent_table_list(
8690 ha_spider *spider
8691 ) {
8692 TABLE *table = spider->get_table();
8693 DBUG_ENTER("spider_get_parent_table_list");
8694 DBUG_RETURN(table->pos_in_table_list);
8695 }
8696
spider_get_index_hints(ha_spider * spider)8697 List<Index_hint> *spider_get_index_hints(
8698 ha_spider *spider
8699 ) {
8700 TABLE_LIST *table_list = spider_get_parent_table_list(spider);
8701 DBUG_ENTER("spider_get_index_hint");
8702 if (table_list)
8703 {
8704 DBUG_RETURN(table_list->index_hints);
8705 }
8706 DBUG_RETURN(NULL);
8707 }
8708
8709
spider_get_select_lex(ha_spider * spider)8710 st_select_lex *spider_get_select_lex(
8711 ha_spider *spider
8712 ) {
8713 TABLE_LIST *table_list = spider_get_parent_table_list(spider);
8714 DBUG_ENTER("spider_get_select_lex");
8715 if (table_list)
8716 {
8717 DBUG_RETURN(table_list->select_lex);
8718 }
8719 DBUG_RETURN(NULL);
8720 }
8721
spider_get_select_limit_from_select_lex(st_select_lex * select_lex,longlong * select_limit,longlong * offset_limit)8722 void spider_get_select_limit_from_select_lex(
8723 st_select_lex *select_lex,
8724 longlong *select_limit,
8725 longlong *offset_limit
8726 ) {
8727 DBUG_ENTER("spider_get_select_limit_from_select_lex");
8728 *select_limit = 9223372036854775807LL;
8729 *offset_limit = 0;
8730 if (select_lex && select_lex->explicit_limit)
8731 {
8732 *select_limit = select_lex->select_limit ?
8733 select_lex->select_limit->val_int() : 0;
8734 *offset_limit = select_lex->offset_limit ?
8735 select_lex->offset_limit->val_int() : 0;
8736 }
8737 DBUG_VOID_RETURN;
8738 }
8739
spider_get_select_limit(ha_spider * spider,st_select_lex ** select_lex,longlong * select_limit,longlong * offset_limit)8740 void spider_get_select_limit(
8741 ha_spider *spider,
8742 st_select_lex **select_lex,
8743 longlong *select_limit,
8744 longlong *offset_limit
8745 ) {
8746 DBUG_ENTER("spider_get_select_limit");
8747 *select_lex = spider_get_select_lex(spider);
8748 spider_get_select_limit_from_select_lex(
8749 *select_lex, select_limit, offset_limit);
8750 DBUG_VOID_RETURN;
8751 }
8752
spider_split_read_param(ha_spider * spider)8753 longlong spider_split_read_param(
8754 ha_spider *spider
8755 ) {
8756 SPIDER_SHARE *share = spider->share;
8757 SPIDER_RESULT_LIST *result_list = &spider->result_list;
8758 THD *thd = spider->wide_handler->trx->thd;
8759 st_select_lex *select_lex;
8760 longlong select_limit;
8761 longlong offset_limit;
8762 double semi_split_read;
8763 longlong split_read;
8764 DBUG_ENTER("spider_split_read_param");
8765 result_list->set_split_read_count = 1;
8766 #ifdef INFO_KIND_FORCE_LIMIT_BEGIN
8767 if (spider->wide_handler->info_limit < 9223372036854775807LL)
8768 {
8769 DBUG_PRINT("info",("spider info_limit=%lld",
8770 spider->wide_handler->info_limit));
8771 longlong info_limit = spider->wide_handler->info_limit;
8772 result_list->split_read_base = info_limit;
8773 result_list->semi_split_read = 0;
8774 result_list->first_read = info_limit;
8775 result_list->second_read = info_limit;
8776 result_list->semi_split_read_base = 0;
8777 result_list->set_split_read = FALSE;
8778 DBUG_RETURN(info_limit);
8779 }
8780 #endif
8781 if (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER)
8782 {
8783 DBUG_RETURN(result_list->semi_split_read_base);
8784 }
8785 spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit);
8786 DBUG_PRINT("info",("spider result_list->set_split_read=%s", result_list->set_split_read ? "TRUE" : "FALSE"));
8787 if (!result_list->set_split_read)
8788 {
8789 int bulk_update_mode = spider_param_bulk_update_mode(thd,
8790 share->bulk_update_mode);
8791 DBUG_PRINT("info",("spider sql_command=%u",
8792 spider->wide_handler->sql_command));
8793 DBUG_PRINT("info",("spider bulk_update_mode=%d", bulk_update_mode));
8794 DBUG_PRINT("info",("spider support_bulk_update_sql=%s",
8795 spider->support_bulk_update_sql() ? "TRUE" : "FALSE"));
8796 #ifdef SPIDER_HAS_GROUP_BY_HANDLER
8797 bool inserting =
8798 (
8799 #ifdef HS_HAS_SQLCOM
8800 spider->wide_handler->sql_command == SQLCOM_HS_INSERT ||
8801 #endif
8802 spider->wide_handler->sql_command == SQLCOM_INSERT ||
8803 spider->wide_handler->sql_command == SQLCOM_INSERT_SELECT
8804 );
8805 #endif
8806 bool updating =
8807 (
8808 #ifdef HS_HAS_SQLCOM
8809 spider->wide_handler->sql_command == SQLCOM_HS_UPDATE ||
8810 #endif
8811 spider->wide_handler->sql_command == SQLCOM_UPDATE ||
8812 spider->wide_handler->sql_command == SQLCOM_UPDATE_MULTI
8813 );
8814 bool deleting =
8815 (
8816 #ifdef HS_HAS_SQLCOM
8817 spider->wide_handler->sql_command == SQLCOM_HS_DELETE ||
8818 #endif
8819 spider->wide_handler->sql_command == SQLCOM_DELETE ||
8820 spider->wide_handler->sql_command == SQLCOM_DELETE_MULTI
8821 );
8822 bool replacing =
8823 (
8824 spider->wide_handler->sql_command == SQLCOM_REPLACE ||
8825 spider->wide_handler->sql_command == SQLCOM_REPLACE_SELECT
8826 );
8827 DBUG_PRINT("info",("spider updating=%s", updating ? "TRUE" : "FALSE"));
8828 DBUG_PRINT("info",("spider deleting=%s", deleting ? "TRUE" : "FALSE"));
8829 DBUG_PRINT("info",("spider replacing=%s", replacing ? "TRUE" : "FALSE"));
8830 TABLE *table = spider->get_table();
8831 if (
8832 #ifdef SPIDER_HAS_GROUP_BY_HANDLER
8833 (
8834 inserting &&
8835 spider->use_fields
8836 ) ||
8837 #endif
8838 replacing ||
8839 (
8840 (
8841 updating ||
8842 deleting
8843 ) &&
8844 (
8845 bulk_update_mode != 2 ||
8846 !spider->support_bulk_update_sql() ||
8847 (
8848 updating &&
8849 table->triggers &&
8850 #ifdef HA_CAN_FORCE_BULK_UPDATE
8851 !(table->file->ha_table_flags() & HA_CAN_FORCE_BULK_UPDATE) &&
8852 #endif
8853 table->triggers->has_triggers(TRG_EVENT_UPDATE, TRG_ACTION_AFTER)
8854 ) ||
8855 (
8856 deleting &&
8857 table->triggers &&
8858 #ifdef HA_CAN_FORCE_BULK_DELETE
8859 !(table->file->ha_table_flags() & HA_CAN_FORCE_BULK_DELETE) &&
8860 #endif
8861 table->triggers->has_triggers(TRG_EVENT_DELETE, TRG_ACTION_AFTER)
8862 )
8863 )
8864 )
8865 ) {
8866 /* This case must select by one shot */
8867 DBUG_PRINT("info",("spider cancel split read"));
8868 result_list->split_read_base = 9223372036854775807LL;
8869 result_list->semi_split_read = 0;
8870 result_list->semi_split_read_limit = 9223372036854775807LL;
8871 result_list->first_read = 9223372036854775807LL;
8872 result_list->second_read = 9223372036854775807LL;
8873 result_list->semi_split_read_base = 0;
8874 result_list->set_split_read = TRUE;
8875 DBUG_RETURN(9223372036854775807LL);
8876 }
8877 #ifdef SPIDER_HAS_EXPLAIN_QUERY
8878 Explain_query *explain = thd->lex->explain;
8879 bool filesort = FALSE;
8880 if (explain)
8881 {
8882 DBUG_PRINT("info",("spider explain=%p", explain));
8883 Explain_select *explain_select = NULL;
8884 if (select_lex)
8885 {
8886 DBUG_PRINT("info",("spider select_lex=%p", select_lex));
8887 DBUG_PRINT("info",("spider select_number=%u",
8888 select_lex->select_number));
8889 explain_select =
8890 explain->get_select(select_lex->select_number);
8891 }
8892 if (explain_select)
8893 {
8894 DBUG_PRINT("info",("spider explain_select=%p", explain_select));
8895 if (explain_select->using_filesort)
8896 {
8897 DBUG_PRINT("info",("spider using filesort"));
8898 filesort = TRUE;
8899 }
8900 }
8901 }
8902 #endif
8903 result_list->split_read_base =
8904 spider_param_split_read(thd, share->split_read);
8905 #ifdef SPIDER_HAS_EXPLAIN_QUERY
8906 if (filesort)
8907 {
8908 result_list->semi_split_read = 0;
8909 result_list->semi_split_read_limit = 9223372036854775807LL;
8910 } else {
8911 #endif
8912 result_list->semi_split_read =
8913 spider_param_semi_split_read(thd, share->semi_split_read);
8914 result_list->semi_split_read_limit =
8915 spider_param_semi_split_read_limit(thd, share->semi_split_read_limit);
8916 #ifdef SPIDER_HAS_EXPLAIN_QUERY
8917 }
8918 #endif
8919 result_list->first_read =
8920 spider_param_first_read(thd, share->first_read);
8921 result_list->second_read =
8922 spider_param_second_read(thd, share->second_read);
8923 result_list->semi_split_read_base = 0;
8924 result_list->set_split_read = TRUE;
8925 }
8926 DBUG_PRINT("info",("spider result_list->semi_split_read=%f", result_list->semi_split_read));
8927 DBUG_PRINT("info",("spider select_lex->explicit_limit=%d", select_lex ? select_lex->explicit_limit : 0));
8928 DBUG_PRINT("info",("spider OPTION_FOUND_ROWS=%s", select_lex && (select_lex->options & OPTION_FOUND_ROWS) ? "TRUE" : "FALSE"));
8929 DBUG_PRINT("info",("spider select_lex->group_list.elements=%u", select_lex ? select_lex->group_list.elements : 0));
8930 DBUG_PRINT("info",("spider select_lex->with_sum_func=%s", select_lex && select_lex->with_sum_func ? "TRUE" : "FALSE"));
8931 if (
8932 result_list->semi_split_read > 0 &&
8933 select_lex && select_lex->explicit_limit &&
8934 !(select_lex->options & OPTION_FOUND_ROWS) &&
8935 !select_lex->group_list.elements &&
8936 !select_lex->with_sum_func
8937 ) {
8938 semi_split_read = result_list->semi_split_read *
8939 (select_limit + offset_limit);
8940 DBUG_PRINT("info",("spider semi_split_read=%f", semi_split_read));
8941 if (semi_split_read >= result_list->semi_split_read_limit)
8942 {
8943 result_list->semi_split_read_base = result_list->semi_split_read_limit;
8944 DBUG_RETURN(result_list->semi_split_read_limit);
8945 } else {
8946 split_read = (longlong) semi_split_read;
8947 if (split_read < 0)
8948 {
8949 result_list->semi_split_read_base = result_list->semi_split_read_limit;
8950 DBUG_RETURN(result_list->semi_split_read_limit);
8951 } else if (split_read == 0)
8952 {
8953 result_list->semi_split_read_base = 1;
8954 DBUG_RETURN(1);
8955 } else {
8956 result_list->semi_split_read_base = split_read;
8957 DBUG_RETURN(split_read);
8958 }
8959 }
8960 } else if (result_list->first_read > 0)
8961 DBUG_RETURN(result_list->first_read);
8962 DBUG_RETURN(result_list->split_read_base);
8963 }
8964
spider_bg_split_read_param(ha_spider * spider)8965 longlong spider_bg_split_read_param(
8966 ha_spider *spider
8967 ) {
8968 SPIDER_RESULT_LIST *result_list = &spider->result_list;
8969 DBUG_ENTER("spider_bg_split_read_param");
8970 if (result_list->semi_split_read_base)
8971 DBUG_RETURN(result_list->semi_split_read_base);
8972 DBUG_RETURN(result_list->split_read_base);
8973 }
8974
spider_first_split_read_param(ha_spider * spider)8975 void spider_first_split_read_param(
8976 ha_spider *spider
8977 ) {
8978 SPIDER_RESULT_LIST *result_list = &spider->result_list;
8979 DBUG_ENTER("spider_first_split_read_param");
8980 if (result_list->semi_split_read_base)
8981 result_list->split_read = result_list->semi_split_read_base;
8982 else if (result_list->second_read > 0)
8983 result_list->split_read = result_list->first_read;
8984 else
8985 result_list->split_read = result_list->split_read_base;
8986 result_list->set_split_read_count = 1;
8987 DBUG_VOID_RETURN;
8988 }
8989
spider_next_split_read_param(ha_spider * spider)8990 void spider_next_split_read_param(
8991 ha_spider *spider
8992 ) {
8993 SPIDER_RESULT_LIST *result_list = &spider->result_list;
8994 DBUG_ENTER("spider_next_split_read_param");
8995 if (result_list->semi_split_read_base)
8996 result_list->split_read = result_list->semi_split_read_base;
8997 else if (
8998 result_list->set_split_read_count == 1 &&
8999 result_list->second_read > 0
9000 )
9001 result_list->split_read = result_list->second_read;
9002 else
9003 result_list->split_read = result_list->split_read_base;
9004 result_list->set_split_read_count++;
9005 DBUG_VOID_RETURN;
9006 }
9007
spider_check_direct_order_limit(ha_spider * spider)9008 bool spider_check_direct_order_limit(
9009 ha_spider *spider
9010 ) {
9011 THD *thd = spider->wide_handler->trx->thd;
9012 SPIDER_SHARE *share = spider->share;
9013 st_select_lex *select_lex;
9014 longlong select_limit;
9015 longlong offset_limit;
9016 DBUG_ENTER("spider_check_direct_order_limit");
9017 if (spider_check_index_merge(spider->get_table(),
9018 spider_get_select_lex(spider)))
9019 {
9020 DBUG_PRINT("info",("spider set use_index_merge"));
9021 spider->use_index_merge = TRUE;
9022 }
9023 DBUG_PRINT("info",("spider SQLCOM_HA_READ=%s",
9024 (spider->wide_handler->sql_command == SQLCOM_HA_READ) ? "TRUE" : "FALSE"));
9025 DBUG_PRINT("info",("spider sql_kinds with SPIDER_SQL_KIND_HANDLER=%s",
9026 (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER) ? "TRUE" : "FALSE"));
9027 DBUG_PRINT("info",("spider use_index_merge=%s",
9028 spider->use_index_merge ? "TRUE" : "FALSE"));
9029 DBUG_PRINT("info",("spider is_clone=%s",
9030 spider->is_clone ? "TRUE" : "FALSE"));
9031 #ifdef HA_CAN_BULK_ACCESS
9032 DBUG_PRINT("info",("spider is_bulk_access_clone=%s",
9033 spider->is_bulk_access_clone ? "TRUE" : "FALSE"));
9034 #endif
9035 if (
9036 spider->wide_handler->sql_command != SQLCOM_HA_READ &&
9037 !spider->use_index_merge &&
9038 #ifdef HA_CAN_BULK_ACCESS
9039 (!spider->is_clone || spider->is_bulk_access_clone)
9040 #else
9041 !spider->is_clone
9042 #endif
9043 ) {
9044 spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit);
9045 bool first_check = TRUE;
9046 DBUG_PRINT("info",("spider select_lex=%p", select_lex));
9047 #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
9048 DBUG_PRINT("info",("spider leaf_tables.elements=%u",
9049 select_lex ? select_lex->leaf_tables.elements : 0));
9050 #endif
9051
9052 if (select_lex && (select_lex->options & SELECT_DISTINCT))
9053 {
9054 DBUG_PRINT("info",("spider with distinct"));
9055 spider->result_list.direct_distinct = TRUE;
9056 }
9057 #ifdef HANDLER_HAS_DIRECT_AGGREGATE
9058 spider->result_list.direct_aggregate = TRUE;
9059 #endif
9060 DBUG_PRINT("info",("spider select_limit=%lld", select_limit));
9061 DBUG_PRINT("info",("spider offset_limit=%lld", offset_limit));
9062 if (
9063 #if MYSQL_VERSION_ID < 50500
9064 !thd->variables.engine_condition_pushdown ||
9065 #else
9066 #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON
9067 #else
9068 !(thd->variables.optimizer_switch &
9069 OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) ||
9070 #endif
9071 #endif
9072 #ifdef SPIDER_NEED_CHECK_CONDITION_AT_CHECKING_DIRECT_ORDER_LIMIT
9073 !spider->condition ||
9074 #endif
9075 !select_lex ||
9076 #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
9077 select_lex->leaf_tables.elements != 1 ||
9078 #endif
9079 select_lex->table_list.elements != 1
9080 ) {
9081 DBUG_PRINT("info",("spider first_check is FALSE"));
9082 first_check = FALSE;
9083 spider->result_list.direct_distinct = FALSE;
9084 #ifdef HANDLER_HAS_DIRECT_AGGREGATE
9085 spider->result_list.direct_aggregate = FALSE;
9086 #endif
9087 } else if (spider_db_append_condition(spider, NULL, 0, TRUE))
9088 {
9089 DBUG_PRINT("info",("spider FALSE by condition"));
9090 first_check = FALSE;
9091 spider->result_list.direct_distinct = FALSE;
9092 #ifdef HANDLER_HAS_DIRECT_AGGREGATE
9093 spider->result_list.direct_aggregate = FALSE;
9094 #endif
9095 } else if (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER)
9096 {
9097 DBUG_PRINT("info",("spider sql_kinds with SPIDER_SQL_KIND_HANDLER"));
9098 spider->result_list.direct_distinct = FALSE;
9099 #ifdef HANDLER_HAS_DIRECT_AGGREGATE
9100 spider->result_list.direct_aggregate = FALSE;
9101 } else if (
9102 !select_lex->group_list.elements &&
9103 !select_lex->with_sum_func
9104 ) {
9105 DBUG_PRINT("info",("spider this SQL is not aggregate SQL"));
9106 spider->result_list.direct_aggregate = FALSE;
9107 } else {
9108 ORDER *group;
9109 for (group = (ORDER *) select_lex->group_list.first; group;
9110 group = group->next)
9111 {
9112 if (spider->print_item_type((*group->item), NULL, NULL, 0))
9113 {
9114 DBUG_PRINT("info",("spider aggregate FALSE by group"));
9115 spider->result_list.direct_aggregate = FALSE;
9116 break;
9117 }
9118 }
9119 JOIN *join = select_lex->join;
9120 Item_sum **item_sum_ptr;
9121 for (item_sum_ptr = join->sum_funcs; *item_sum_ptr; ++item_sum_ptr)
9122 {
9123 if (spider->print_item_type(*item_sum_ptr, NULL, NULL, 0))
9124 {
9125 DBUG_PRINT("info",("spider aggregate FALSE by not supported"));
9126 spider->result_list.direct_aggregate = FALSE;
9127 break;
9128 }
9129 }
9130 if (!spider_all_part_in_order((ORDER *) select_lex->group_list.first,
9131 spider->get_table()))
9132 {
9133 DBUG_PRINT("info",("spider FALSE by group condition"));
9134 first_check = FALSE;
9135 spider->result_list.direct_distinct = FALSE;
9136 }
9137 #endif
9138 }
9139
9140 longlong direct_order_limit = spider_param_direct_order_limit(thd,
9141 share->direct_order_limit);
9142 DBUG_PRINT("info",("spider direct_order_limit=%lld", direct_order_limit));
9143 if (direct_order_limit)
9144 {
9145 DBUG_PRINT("info",("spider first_check=%s",
9146 first_check ? "TRUE" : "FALSE"));
9147 DBUG_PRINT("info",("spider (select_lex->options & OPTION_FOUND_ROWS)=%s",
9148 select_lex && (select_lex->options & OPTION_FOUND_ROWS) ? "TRUE" : "FALSE"));
9149 #ifdef HANDLER_HAS_DIRECT_AGGREGATE
9150 DBUG_PRINT("info",("spider direct_aggregate=%s",
9151 spider->result_list.direct_aggregate ? "TRUE" : "FALSE"));
9152 #endif
9153 DBUG_PRINT("info",("spider select_lex->group_list.elements=%u",
9154 select_lex ? select_lex->group_list.elements : 0));
9155 DBUG_PRINT("info",("spider select_lex->with_sum_func=%s",
9156 select_lex && select_lex->with_sum_func ? "TRUE" : "FALSE"));
9157 DBUG_PRINT("info",("spider select_lex->having=%s",
9158 select_lex && select_lex->having ? "TRUE" : "FALSE"));
9159 DBUG_PRINT("info",("spider select_lex->order_list.elements=%u",
9160 select_lex ? select_lex->order_list.elements : 0));
9161 if (
9162 !first_check ||
9163 !select_lex->explicit_limit ||
9164 (select_lex->options & OPTION_FOUND_ROWS) ||
9165 (
9166 #ifdef HANDLER_HAS_DIRECT_AGGREGATE
9167 !spider->result_list.direct_aggregate &&
9168 #endif
9169 (
9170 select_lex->group_list.elements ||
9171 select_lex->with_sum_func
9172 )
9173 ) ||
9174 select_lex->having ||
9175 !select_lex->order_list.elements ||
9176 select_limit > direct_order_limit - offset_limit
9177 ) {
9178 DBUG_PRINT("info",("spider FALSE by select_lex"));
9179 DBUG_RETURN(FALSE);
9180 }
9181 ORDER *order;
9182 for (order = (ORDER *) select_lex->order_list.first; order;
9183 order = order->next)
9184 {
9185 if (spider->print_item_type((*order->item), NULL, NULL, 0))
9186 {
9187 DBUG_PRINT("info",("spider FALSE by order"));
9188 DBUG_RETURN(FALSE);
9189 }
9190 }
9191 DBUG_PRINT("info",("spider TRUE"));
9192 spider->result_list.internal_limit = select_limit + offset_limit;
9193 spider->result_list.split_read = select_limit + offset_limit;
9194 spider->wide_handler->trx->direct_order_limit_count++;
9195 DBUG_RETURN(TRUE);
9196 }
9197 }
9198 DBUG_PRINT("info",("spider FALSE by parameter"));
9199 DBUG_RETURN(FALSE);
9200 }
9201
9202 #ifdef HANDLER_HAS_DIRECT_AGGREGATE
spider_all_part_in_order(ORDER * order,TABLE * table)9203 bool spider_all_part_in_order(
9204 ORDER *order,
9205 TABLE *table
9206 ) {
9207 TABLE_LIST *parent;
9208 partition_info *part_info;
9209 Field **part_fields;
9210 ORDER *ptr;
9211 Item *item;
9212 Item_field *item_field;
9213 DBUG_ENTER("spider_all_part_in_order");
9214 while (TRUE)
9215 {
9216 DBUG_PRINT("info", ("spider table_name = %s", table->s->db.str));
9217 DBUG_PRINT("info",("spider part_info=%p", table->part_info));
9218 if ((part_info = table->part_info))
9219 {
9220 for (part_fields = part_info->full_part_field_array;
9221 *part_fields; ++part_fields)
9222 {
9223 DBUG_PRINT("info", ("spider part_field = %s",
9224 SPIDER_field_name_str(*part_fields)));
9225 for (ptr = order; ptr; ptr = ptr->next)
9226 {
9227 item = *ptr->item;
9228 if (item->type() != Item::FIELD_ITEM)
9229 {
9230 continue;
9231 }
9232 item_field = (Item_field *) item;
9233 Field *field = item_field->field;
9234 if (!field)
9235 {
9236 continue;
9237 }
9238 DBUG_PRINT("info", ("spider field_name = %s.%s",
9239 field->table->s->db.str, SPIDER_field_name_str(field)));
9240 if (*part_fields == spider_field_exchange(table->file, field))
9241 {
9242 break;
9243 }
9244 }
9245 if (!ptr)
9246 {
9247 DBUG_RETURN(FALSE);
9248 }
9249 }
9250 }
9251 if (!(parent = table->pos_in_table_list->parent_l))
9252 {
9253 break;
9254 }
9255 table = parent->table;
9256 }
9257 DBUG_RETURN(TRUE);
9258 }
9259
spider_field_exchange(handler * handler,Field * field)9260 Field *spider_field_exchange(
9261 handler *handler,
9262 Field *field
9263 ) {
9264 DBUG_ENTER("spider_field_exchange");
9265 #ifdef HA_CAN_BULK_ACCESS
9266 if (handler->is_bulk_access_clone)
9267 {
9268 handler = handler->pt_clone_source_handler;
9269 }
9270 #endif
9271 DBUG_PRINT("info",("spider in field=%p", field));
9272 DBUG_PRINT("info",("spider in field->table=%p", field->table));
9273 DBUG_PRINT("info",("spider table=%p", handler->get_table()));
9274 if (field->table != handler->get_table())
9275 DBUG_RETURN(NULL);
9276 DBUG_PRINT("info",("spider out field=%p", field));
9277 DBUG_RETURN(field);
9278 }
9279 #endif
9280
spider_set_direct_limit_offset(ha_spider * spider)9281 int spider_set_direct_limit_offset(
9282 ha_spider *spider
9283 ) {
9284 #ifndef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON
9285 THD *thd = spider->wide_handler->trx->thd;
9286 #endif
9287 st_select_lex *select_lex;
9288 longlong select_limit;
9289 longlong offset_limit;
9290 TABLE_LIST *table_list;
9291 DBUG_ENTER("spider_set_direct_limit_offset");
9292
9293 if (spider->result_list.direct_limit_offset)
9294 DBUG_RETURN(TRUE);
9295
9296 if (
9297 spider->partition_handler &&
9298 !spider->wide_handler_owner
9299 ) {
9300 if (spider->partition_handler->owner->
9301 result_list.direct_limit_offset == TRUE)
9302 {
9303 spider->result_list.direct_limit_offset = TRUE;
9304 DBUG_RETURN(TRUE);
9305 } else {
9306 DBUG_RETURN(FALSE);
9307 }
9308 }
9309
9310 if (
9311 spider->wide_handler->sql_command != SQLCOM_SELECT ||
9312 #ifdef HANDLER_HAS_DIRECT_AGGREGATE
9313 spider->result_list.direct_aggregate ||
9314 #endif
9315 spider->result_list.direct_order_limit ||
9316 spider->prev_index_rnd_init != SPD_RND // must be RND_INIT and not be INDEX_INIT
9317 )
9318 DBUG_RETURN(FALSE);
9319
9320 spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit);
9321
9322 // limit and offset is non-zero
9323 if (!(select_limit && offset_limit))
9324 DBUG_RETURN(FALSE);
9325
9326 // more than one table
9327 if (
9328 !select_lex ||
9329 select_lex->table_list.elements != 1
9330 )
9331 DBUG_RETURN(FALSE);
9332
9333 table_list = (TABLE_LIST *) select_lex->table_list.first;
9334 if (table_list->table->file->partition_ht() != spider_hton_ptr)
9335 {
9336 DBUG_PRINT("info",("spider ht1=%u ht2=%u",
9337 table_list->table->file->partition_ht()->slot,
9338 spider_hton_ptr->slot
9339 ));
9340 DBUG_RETURN(FALSE);
9341 }
9342
9343 // contain where
9344 if (
9345 #if MYSQL_VERSION_ID < 50500
9346 !thd->variables.engine_condition_pushdown ||
9347 #else
9348 #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON
9349 #else
9350 !(thd->variables.optimizer_switch &
9351 OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) ||
9352 #endif
9353 #endif
9354 // conditions is null may be no where condition in rand_init
9355 spider->wide_handler->condition
9356 )
9357 DBUG_RETURN(FALSE);
9358
9359 // ignore condition like 1=1
9360 #ifdef SPIDER_has_Item_with_subquery
9361 if (select_lex->where && select_lex->where->with_subquery())
9362 #else
9363 if (select_lex->where && select_lex->where->with_subselect)
9364 #endif
9365 DBUG_RETURN(FALSE);
9366
9367 if (
9368 select_lex->group_list.elements ||
9369 select_lex->with_sum_func ||
9370 select_lex->having ||
9371 select_lex->order_list.elements
9372 )
9373 DBUG_RETURN(FALSE);
9374
9375 // must not be derived table
9376 if (SPIDER_get_linkage(select_lex) == DERIVED_TABLE_TYPE)
9377 DBUG_RETURN(FALSE);
9378
9379 spider->direct_select_offset = offset_limit;
9380 spider->direct_current_offset = offset_limit;
9381 spider->direct_select_limit = select_limit;
9382 spider->result_list.direct_limit_offset = TRUE;
9383 DBUG_RETURN(TRUE);
9384 }
9385
9386
spider_check_index_merge(TABLE * table,st_select_lex * select_lex)9387 bool spider_check_index_merge(
9388 TABLE *table,
9389 st_select_lex *select_lex
9390 ) {
9391 uint roop_count;
9392 JOIN *join;
9393 DBUG_ENTER("spider_check_index_merge");
9394 if (!select_lex)
9395 {
9396 DBUG_PRINT("info",("spider select_lex is null"));
9397 DBUG_RETURN(FALSE);
9398 }
9399 join = select_lex->join;
9400 if (!join)
9401 {
9402 DBUG_PRINT("info",("spider join is null"));
9403 DBUG_RETURN(FALSE);
9404 }
9405 if (!join->join_tab)
9406 {
9407 DBUG_PRINT("info",("spider join->join_tab is null"));
9408 DBUG_RETURN(FALSE);
9409 }
9410 for (roop_count = 0; roop_count < spider_join_table_count(join); ++roop_count)
9411 {
9412 JOIN_TAB *join_tab = &join->join_tab[roop_count];
9413 if (join_tab->table == table)
9414 {
9415 DBUG_PRINT("info",("spider join_tab->type=%u", join_tab->type));
9416 if (
9417 #ifdef SPIDER_HAS_JT_HASH_INDEX_MERGE
9418 join_tab->type == JT_HASH_INDEX_MERGE ||
9419 #endif
9420 join_tab->type == JT_INDEX_MERGE
9421 ) {
9422 DBUG_RETURN(TRUE);
9423 }
9424 /*
9425 DBUG_PRINT("info",("spider join_tab->quick->get_type()=%u",
9426 join_tab->quick ? join_tab->quick->get_type() : 0));
9427 if (
9428 join_tab->quick &&
9429 join_tab->quick->get_type() == QUICK_SELECT_I::QS_TYPE_INDEX_MERGE
9430 ) {
9431 DBUG_RETURN(TRUE);
9432 }
9433 */
9434 DBUG_PRINT("info",("spider join_tab->select->quick->get_type()=%u",
9435 join_tab->select && join_tab->select->quick ? join_tab->select->quick->get_type() : 0));
9436 if (
9437 join_tab->select &&
9438 join_tab->select->quick &&
9439 join_tab->select->quick->get_type() == QUICK_SELECT_I::QS_TYPE_INDEX_MERGE
9440 ) {
9441 DBUG_RETURN(TRUE);
9442 }
9443 break;
9444 }
9445 }
9446 DBUG_RETURN(FALSE);
9447 }
9448
spider_compare_for_sort(SPIDER_SORT * a,SPIDER_SORT * b)9449 int spider_compare_for_sort(
9450 SPIDER_SORT *a,
9451 SPIDER_SORT *b
9452 ) {
9453 DBUG_ENTER("spider_compare_for_sort");
9454 if (a->sort > b->sort)
9455 DBUG_RETURN(-1);
9456 if (a->sort < b->sort)
9457 DBUG_RETURN(1);
9458 DBUG_RETURN(0);
9459 }
9460
spider_calc_for_sort(uint count,...)9461 ulong spider_calc_for_sort(
9462 uint count,
9463 ...
9464 ) {
9465 ulong sort = 0;
9466 va_list args;
9467 va_start(args, count);
9468 DBUG_ENTER("spider_calc_for_sort");
9469 while (count--)
9470 {
9471 char *start = va_arg(args, char *), *str;
9472 uint wild_pos = 0;
9473
9474 if ((str = start))
9475 {
9476 wild_pos = 128;
9477 for (; *str; str++)
9478 {
9479 if (*str == spider_wild_prefix && str[1])
9480 str++;
9481 else if (*str == spider_wild_many || *str == spider_wild_one)
9482 {
9483 wild_pos = (uint) (str - start) + 1;
9484 if (wild_pos > 127)
9485 wild_pos = 127;
9486 break;
9487 }
9488 }
9489 }
9490 sort = (sort << 8) + wild_pos;
9491 }
9492 va_end(args);
9493 DBUG_RETURN(sort);
9494 }
9495
spider_rand(uint32 rand_source)9496 double spider_rand(
9497 uint32 rand_source
9498 ) {
9499 #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
9500 struct my_rnd_struct rand;
9501 #else
9502 struct rand_struct rand;
9503 #endif
9504 DBUG_ENTER("spider_rand");
9505 /* generate same as rand function for applications */
9506 #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
9507 my_rnd_init(&rand, (uint32) (rand_source * 65537L + 55555555L),
9508 (uint32) (rand_source * 268435457L));
9509 #else
9510 randominit(&rand, (uint32) (rand_source * 65537L + 55555555L),
9511 (uint32) (rand_source * 268435457L));
9512 #endif
9513 DBUG_RETURN(my_rnd(&rand));
9514 }
9515
9516 #ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE
spider_discover_table_structure_internal(SPIDER_TRX * trx,SPIDER_SHARE * spider_share,spider_string * str)9517 int spider_discover_table_structure_internal(
9518 SPIDER_TRX *trx,
9519 SPIDER_SHARE *spider_share,
9520 spider_string *str
9521 ) {
9522 int error_num = 0, roop_count;
9523 DBUG_ENTER("spider_discover_table_structure_internal");
9524 for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++)
9525 {
9526 if (spider_bit_is_set(spider_share->dbton_bitmap, roop_count))
9527 {
9528 if ((error_num = spider_share->dbton_share[roop_count]->
9529 discover_table_structure(trx, spider_share, str)))
9530 {
9531 continue;
9532 }
9533 break;
9534 }
9535 }
9536 DBUG_RETURN(error_num);
9537 }
9538
spider_discover_table_structure(handlerton * hton,THD * thd,TABLE_SHARE * share,HA_CREATE_INFO * info)9539 int spider_discover_table_structure(
9540 handlerton *hton,
9541 THD* thd,
9542 TABLE_SHARE *share,
9543 HA_CREATE_INFO *info
9544 ) {
9545 int error_num = HA_ERR_WRONG_COMMAND, dummy;
9546 SPIDER_SHARE *spider_share;
9547 const char *table_name = share->path.str;
9548 uint table_name_length = (uint) strlen(table_name);
9549 SPIDER_TRX *trx;
9550 #ifdef WITH_PARTITION_STORAGE_ENGINE
9551 partition_info *part_info = thd->work_part_info;
9552 #endif
9553 SPIDER_Open_tables_backup open_tables_backup;
9554 TABLE *table_tables;
9555 #ifdef WITH_PARTITION_STORAGE_ENGINE
9556 uint str_len;
9557 #endif
9558 char buf[MAX_FIELD_WIDTH];
9559 spider_string str(buf, sizeof(buf), system_charset_info);
9560 DBUG_ENTER("spider_discover_table_structure");
9561 str.init_calc_mem(229);
9562 str.length(0);
9563 if (str.reserve(
9564 SPIDER_SQL_CREATE_TABLE_LEN + share->db.length +
9565 SPIDER_SQL_DOT_LEN + share->table_name.length +
9566 /* SPIDER_SQL_LCL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_OPEN_PAREN_LEN
9567 )) {
9568 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
9569 }
9570 str.q_append(SPIDER_SQL_CREATE_TABLE_STR, SPIDER_SQL_CREATE_TABLE_LEN);
9571 str.q_append(SPIDER_SQL_LCL_NAME_QUOTE_STR, SPIDER_SQL_LCL_NAME_QUOTE_LEN);
9572 str.q_append(share->db.str, share->db.length);
9573 str.q_append(SPIDER_SQL_LCL_NAME_QUOTE_STR, SPIDER_SQL_LCL_NAME_QUOTE_LEN);
9574 str.q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN);
9575 str.q_append(SPIDER_SQL_LCL_NAME_QUOTE_STR, SPIDER_SQL_LCL_NAME_QUOTE_LEN);
9576 str.q_append(share->table_name.str, share->table_name.length);
9577 str.q_append(SPIDER_SQL_LCL_NAME_QUOTE_STR, SPIDER_SQL_LCL_NAME_QUOTE_LEN);
9578 str.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN);
9579 #ifdef WITH_PARTITION_STORAGE_ENGINE
9580 str_len = str.length();
9581 #endif
9582 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
9583 my_hash_value_type hash_value = my_calc_hash(&spider_open_tables,
9584 (uchar*) table_name, table_name_length);
9585 #endif
9586 if (!(trx = spider_get_trx(thd, TRUE, &error_num)))
9587 {
9588 DBUG_PRINT("info",("spider spider_get_trx error"));
9589 my_error(error_num, MYF(0));
9590 DBUG_RETURN(error_num);
9591 }
9592 share->table_charset = info->default_table_charset;
9593 share->comment = info->comment;
9594 #ifdef WITH_PARTITION_STORAGE_ENGINE
9595 if (!part_info)
9596 {
9597 #endif
9598 if (!(spider_share = spider_create_share(table_name, share,
9599 #ifdef WITH_PARTITION_STORAGE_ENGINE
9600 NULL,
9601 #endif
9602 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
9603 hash_value,
9604 #endif
9605 &error_num
9606 ))) {
9607 DBUG_RETURN(error_num);
9608 }
9609
9610 error_num = spider_discover_table_structure_internal(trx, spider_share, &str);
9611
9612 if (!error_num)
9613 {
9614 if (
9615 (table_tables = spider_open_sys_table(
9616 thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
9617 SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, FALSE,
9618 &error_num))
9619 ) {
9620 #ifdef SPIDER_SUPPORT_CREATE_OR_REPLACE_TABLE
9621 if (thd->lex->create_info.or_replace())
9622 {
9623 error_num = spider_delete_tables(table_tables,
9624 spider_share->table_name, &dummy);
9625 }
9626 if (!error_num)
9627 {
9628 #endif
9629 error_num = spider_insert_tables(table_tables, spider_share);
9630 #ifdef SPIDER_SUPPORT_CREATE_OR_REPLACE_TABLE
9631 }
9632 #endif
9633 spider_close_sys_table(thd, table_tables,
9634 &open_tables_backup, FALSE);
9635 }
9636 }
9637
9638 spider_free_share_resource_only(spider_share);
9639 #ifdef WITH_PARTITION_STORAGE_ENGINE
9640 } else {
9641 char tmp_name[FN_REFLEN + 1];
9642 List_iterator<partition_element> part_it(part_info->partitions);
9643 List_iterator<partition_element> part_it2(part_info->partitions);
9644 partition_element *part_elem, *sub_elem;
9645 while ((part_elem = part_it++))
9646 {
9647 if ((part_elem)->subpartitions.elements)
9648 {
9649 List_iterator<partition_element> sub_it((part_elem)->subpartitions);
9650 while ((sub_elem = sub_it++))
9651 {
9652 str.length(str_len);
9653 if ((error_num = SPIDER_create_subpartition_name(
9654 tmp_name, FN_REFLEN + 1, table_name,
9655 (part_elem)->partition_name, (sub_elem)->partition_name,
9656 NORMAL_PART_NAME)))
9657 {
9658 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
9659 }
9660 DBUG_PRINT("info",("spider tmp_name=%s", tmp_name));
9661 if (!(spider_share = spider_create_share(tmp_name, share,
9662 part_info,
9663 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
9664 hash_value,
9665 #endif
9666 &error_num
9667 ))) {
9668 DBUG_RETURN(error_num);
9669 }
9670
9671 error_num = spider_discover_table_structure_internal(
9672 trx, spider_share, &str);
9673
9674 spider_free_share_resource_only(spider_share);
9675 if (!error_num)
9676 break;
9677 }
9678 if (!error_num)
9679 break;
9680 } else {
9681 str.length(str_len);
9682 if ((error_num = SPIDER_create_partition_name(
9683 tmp_name, FN_REFLEN + 1, table_name,
9684 (part_elem)->partition_name, NORMAL_PART_NAME, TRUE)))
9685 {
9686 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
9687 }
9688 DBUG_PRINT("info",("spider tmp_name=%s", tmp_name));
9689 if (!(spider_share = spider_create_share(tmp_name, share,
9690 part_info,
9691 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
9692 hash_value,
9693 #endif
9694 &error_num
9695 ))) {
9696 DBUG_RETURN(error_num);
9697 }
9698
9699 error_num = spider_discover_table_structure_internal(
9700 trx, spider_share, &str);
9701
9702 spider_free_share_resource_only(spider_share);
9703 if (!error_num)
9704 break;
9705 }
9706 }
9707 if (!error_num)
9708 {
9709 if (
9710 !(table_tables = spider_open_sys_table(
9711 thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
9712 SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, FALSE,
9713 &error_num))
9714 ) {
9715 DBUG_RETURN(error_num);
9716 }
9717 while ((part_elem = part_it2++))
9718 {
9719 if ((part_elem)->subpartitions.elements)
9720 {
9721 List_iterator<partition_element> sub_it((part_elem)->subpartitions);
9722 while ((sub_elem = sub_it++))
9723 {
9724 if ((error_num = SPIDER_create_subpartition_name(
9725 tmp_name, FN_REFLEN + 1, table_name,
9726 (part_elem)->partition_name, (sub_elem)->partition_name,
9727 NORMAL_PART_NAME)))
9728 {
9729 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
9730 }
9731 DBUG_PRINT("info",("spider tmp_name=%s", tmp_name));
9732 if (!(spider_share = spider_create_share(tmp_name, share,
9733 part_info,
9734 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
9735 hash_value,
9736 #endif
9737 &error_num
9738 ))) {
9739 DBUG_RETURN(error_num);
9740 }
9741
9742 #ifdef SPIDER_SUPPORT_CREATE_OR_REPLACE_TABLE
9743 if (thd->lex->create_info.or_replace())
9744 {
9745 error_num = spider_delete_tables(table_tables,
9746 spider_share->table_name, &dummy);
9747 }
9748 if (!error_num)
9749 {
9750 #endif
9751 error_num = spider_insert_tables(table_tables, spider_share);
9752 #ifdef SPIDER_SUPPORT_CREATE_OR_REPLACE_TABLE
9753 }
9754 #endif
9755
9756 spider_free_share_resource_only(spider_share);
9757 if (error_num)
9758 break;
9759 }
9760 if (error_num)
9761 break;
9762 } else {
9763 if ((error_num = SPIDER_create_partition_name(
9764 tmp_name, FN_REFLEN + 1, table_name,
9765 (part_elem)->partition_name, NORMAL_PART_NAME, TRUE)))
9766 {
9767 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
9768 }
9769 DBUG_PRINT("info",("spider tmp_name=%s", tmp_name));
9770 if (!(spider_share = spider_create_share(tmp_name, share,
9771 part_info,
9772 #ifdef SPIDER_HAS_HASH_VALUE_TYPE
9773 hash_value,
9774 #endif
9775 &error_num
9776 ))) {
9777 DBUG_RETURN(error_num);
9778 }
9779
9780 #ifdef SPIDER_SUPPORT_CREATE_OR_REPLACE_TABLE
9781 if (thd->lex->create_info.or_replace())
9782 {
9783 error_num = spider_delete_tables(table_tables,
9784 spider_share->table_name, &dummy);
9785 }
9786 if (!error_num)
9787 {
9788 #endif
9789 error_num = spider_insert_tables(table_tables, spider_share);
9790 #ifdef SPIDER_SUPPORT_CREATE_OR_REPLACE_TABLE
9791 }
9792 #endif
9793
9794 spider_free_share_resource_only(spider_share);
9795 if (error_num)
9796 break;
9797 }
9798 }
9799 spider_close_sys_table(thd, table_tables,
9800 &open_tables_backup, FALSE);
9801 }
9802 }
9803 #endif
9804
9805 if (!error_num)
9806 thd->clear_error();
9807 else
9808 DBUG_RETURN(error_num);
9809
9810 str.length(str.length() - SPIDER_SQL_COMMA_LEN);
9811 CHARSET_INFO *table_charset;
9812 if (share->table_charset)
9813 {
9814 table_charset = share->table_charset;
9815 } else {
9816 table_charset = system_charset_info;
9817 }
9818 uint csnamelen = strlen(table_charset->csname);
9819 uint collatelen = strlen(table_charset->name);
9820 if (str.reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_DEFAULT_CHARSET_LEN +
9821 csnamelen + SPIDER_SQL_COLLATE_LEN + collatelen +
9822 SPIDER_SQL_CONNECTION_LEN + SPIDER_SQL_VALUE_QUOTE_LEN +
9823 (share->comment.length * 2)
9824 )) {
9825 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
9826 }
9827 str.q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN);
9828 str.q_append(SPIDER_SQL_DEFAULT_CHARSET_STR, SPIDER_SQL_DEFAULT_CHARSET_LEN);
9829 str.q_append(table_charset->csname, csnamelen);
9830 str.q_append(SPIDER_SQL_COLLATE_STR, SPIDER_SQL_COLLATE_LEN);
9831 str.q_append(table_charset->name, collatelen);
9832 str.q_append(SPIDER_SQL_COMMENT_STR, SPIDER_SQL_COMMENT_LEN);
9833 str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
9834 str.append_escape_string(share->comment.str, share->comment.length);
9835 if (str.reserve(SPIDER_SQL_CONNECTION_LEN +
9836 (SPIDER_SQL_VALUE_QUOTE_LEN * 2) +
9837 (share->connect_string.length * 2)))
9838 {
9839 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
9840 }
9841 str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
9842 str.q_append(SPIDER_SQL_CONNECTION_STR, SPIDER_SQL_CONNECTION_LEN);
9843 str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
9844 str.append_escape_string(share->connect_string.str,
9845 share->connect_string.length);
9846 if (str.reserve(SPIDER_SQL_VALUE_QUOTE_LEN))
9847 {
9848 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
9849 }
9850 str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
9851 #ifdef WITH_PARTITION_STORAGE_ENGINE
9852 DBUG_PRINT("info",("spider part_info=%p", part_info));
9853 if (part_info)
9854 {
9855 uint part_syntax_len;
9856 char *part_syntax;
9857 List_iterator<partition_element> part_it(part_info->partitions);
9858 partition_element *part_elem, *sub_elem;
9859 while ((part_elem = part_it++))
9860 {
9861 part_elem->engine_type = hton;
9862 if ((part_elem)->subpartitions.elements)
9863 {
9864 List_iterator<partition_element> sub_it((part_elem)->subpartitions);
9865 while ((sub_elem = sub_it++))
9866 {
9867 sub_elem->engine_type = hton;
9868 }
9869 }
9870 }
9871 if (part_info->fix_parser_data(thd))
9872 {
9873 DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM);
9874 }
9875 if (!(part_syntax = SPIDER_generate_partition_syntax(thd, part_info,
9876 &part_syntax_len, FALSE, TRUE, info, NULL, NULL)))
9877 {
9878 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
9879 }
9880 if (str.reserve(part_syntax_len))
9881 {
9882 DBUG_RETURN(HA_ERR_OUT_OF_MEM);
9883 }
9884 str.q_append(part_syntax, part_syntax_len);
9885 SPIDER_free_part_syntax(part_syntax, MYF(0));
9886 }
9887 #endif
9888 DBUG_PRINT("info",("spider str=%s", str.c_ptr_safe()));
9889
9890 error_num = share->init_from_sql_statement_string(thd, TRUE, str.ptr(),
9891 str.length());
9892 DBUG_RETURN(error_num);
9893 }
9894 #endif
9895
9896 #ifndef WITHOUT_SPIDER_BG_SEARCH
spider_create_spider_object_for_share(SPIDER_TRX * trx,SPIDER_SHARE * share,ha_spider ** spider)9897 int spider_create_spider_object_for_share(
9898 SPIDER_TRX *trx,
9899 SPIDER_SHARE *share,
9900 ha_spider **spider
9901 ) {
9902 int error_num, roop_count, *need_mons;
9903 SPIDER_CONN **conns;
9904 uint *conn_link_idx;
9905 uchar *conn_can_fo;
9906 char **conn_keys;
9907 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
9908 char **hs_r_conn_keys;
9909 char **hs_w_conn_keys;
9910 #endif
9911 spider_db_handler **dbton_hdl;
9912 SPIDER_WIDE_HANDLER *wide_handler;
9913 DBUG_ENTER("spider_create_spider_object_for_share");
9914 DBUG_PRINT("info",("spider trx=%p", trx));
9915 DBUG_PRINT("info",("spider share=%p", share));
9916 DBUG_PRINT("info",("spider spider_ptr=%p", spider));
9917 DBUG_PRINT("info",("spider spider=%p", (*spider)));
9918
9919 if (*spider)
9920 {
9921 /* already exists */
9922 DBUG_RETURN(0);
9923 }
9924 (*spider) = new (&share->mem_root) ha_spider();
9925 if (!(*spider))
9926 {
9927 error_num = HA_ERR_OUT_OF_MEM;
9928 goto error_spider_alloc;
9929 }
9930 DBUG_PRINT("info",("spider spider=%p", (*spider)));
9931 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
9932 if (!(need_mons = (int *)
9933 spider_bulk_malloc(spider_current_trx, 255, MYF(MY_WME | MY_ZEROFILL),
9934 &need_mons, (uint) (sizeof(int) * share->link_count),
9935 &conns, (uint) (sizeof(SPIDER_CONN *) * share->link_count),
9936 &conn_link_idx, (uint) (sizeof(uint) * share->link_count),
9937 &conn_can_fo, (uint) (sizeof(uchar) * share->link_bitmap_size),
9938 &conn_keys, (uint) (sizeof(char *) * share->link_count),
9939 &hs_r_conn_keys, (uint) (sizeof(char *) * share->link_count),
9940 &hs_w_conn_keys, (uint) (sizeof(char *) * share->link_count),
9941 &dbton_hdl, (uint) (sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE),
9942 &wide_handler, (uint) sizeof(SPIDER_WIDE_HANDLER),
9943 NullS))
9944 )
9945 #else
9946 if (!(need_mons = (int *)
9947 spider_bulk_malloc(spider_current_trx, 255, MYF(MY_WME | MY_ZEROFILL),
9948 &need_mons, (uint) (sizeof(int) * share->link_count),
9949 &conns, (uint) (sizeof(SPIDER_CONN *) * share->link_count),
9950 &conn_link_idx, (uint) (sizeof(uint) * share->link_count),
9951 &conn_can_fo, (uint) (sizeof(uchar) * share->link_bitmap_size),
9952 &conn_keys, (uint) (sizeof(char *) * share->link_count),
9953 &dbton_hdl, (uint) (sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE),
9954 &wide_handler, (uint) sizeof(SPIDER_WIDE_HANDLER),
9955 NullS))
9956 )
9957 #endif
9958 {
9959 error_num = HA_ERR_OUT_OF_MEM;
9960 goto error_need_mons_alloc;
9961 }
9962 DBUG_PRINT("info",("spider need_mons=%p", need_mons));
9963 (*spider)->wide_handler = wide_handler;
9964 wide_handler->trx = trx;
9965 (*spider)->change_table_ptr(&share->table, share->table_share);
9966 (*spider)->share = share;
9967 (*spider)->conns = conns;
9968 (*spider)->conn_link_idx = conn_link_idx;
9969 (*spider)->conn_can_fo = conn_can_fo;
9970 (*spider)->need_mons = need_mons;
9971 (*spider)->conn_keys_first_ptr = share->conn_keys[0];
9972 (*spider)->conn_keys = conn_keys;
9973 #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
9974 (*spider)->hs_r_conn_keys = hs_r_conn_keys;
9975 (*spider)->hs_w_conn_keys = hs_w_conn_keys;
9976 #endif
9977 (*spider)->dbton_handler = dbton_hdl;
9978 (*spider)->search_link_idx = -1;
9979 for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++)
9980 {
9981 if (
9982 spider_bit_is_set(share->dbton_bitmap, roop_count) &&
9983 spider_dbton[roop_count].create_db_handler
9984 ) {
9985 if (!(dbton_hdl[roop_count] = spider_dbton[roop_count].create_db_handler(
9986 *spider, share->dbton_share[roop_count])))
9987 {
9988 error_num = HA_ERR_OUT_OF_MEM;
9989 goto error_init_db_handler;
9990 }
9991 if ((error_num = dbton_hdl[roop_count]->init()))
9992 goto error_init_db_handler;
9993 }
9994 }
9995 DBUG_PRINT("info",("spider share=%p", (*spider)->share));
9996 DBUG_PRINT("info",("spider need_mons=%p", (*spider)->need_mons));
9997 DBUG_RETURN(0);
9998
9999 error_init_db_handler:
10000 for (; roop_count >= 0; --roop_count)
10001 {
10002 if (
10003 spider_bit_is_set(share->dbton_bitmap, roop_count) &&
10004 dbton_hdl[roop_count]
10005 ) {
10006 delete dbton_hdl[roop_count];
10007 dbton_hdl[roop_count] = NULL;
10008 }
10009 }
10010 spider_free(spider_current_trx, (*spider)->need_mons, MYF(0));
10011 error_need_mons_alloc:
10012 delete (*spider);
10013 (*spider) = NULL;
10014 error_spider_alloc:
10015 DBUG_RETURN(error_num);
10016 }
10017
spider_free_spider_object_for_share(ha_spider ** spider)10018 void spider_free_spider_object_for_share(
10019 ha_spider **spider
10020 ) {
10021 int roop_count;
10022 SPIDER_SHARE *share = (*spider)->share;
10023 spider_db_handler **dbton_hdl = (*spider)->dbton_handler;
10024 DBUG_ENTER("spider_free_spider_object_for_share");
10025 DBUG_PRINT("info",("spider share=%p", share));
10026 DBUG_PRINT("info",("spider spider_ptr=%p", spider));
10027 DBUG_PRINT("info",("spider spider=%p", (*spider)));
10028 for (roop_count = SPIDER_DBTON_SIZE - 1; roop_count >= 0; --roop_count)
10029 {
10030 if (
10031 spider_bit_is_set(share->dbton_bitmap, roop_count) &&
10032 dbton_hdl[roop_count]
10033 ) {
10034 delete dbton_hdl[roop_count];
10035 dbton_hdl[roop_count] = NULL;
10036 }
10037 }
10038 spider_free(spider_current_trx, (*spider)->need_mons, MYF(0));
10039 delete (*spider);
10040 (*spider) = NULL;
10041 DBUG_VOID_RETURN;
10042 }
10043
spider_create_sts_threads(SPIDER_THREAD * spider_thread)10044 int spider_create_sts_threads(
10045 SPIDER_THREAD *spider_thread
10046 ) {
10047 int error_num;
10048 DBUG_ENTER("spider_create_sts_threads");
10049 #if MYSQL_VERSION_ID < 50500
10050 if (pthread_mutex_init(&spider_thread->mutex,
10051 MY_MUTEX_INIT_FAST))
10052 #else
10053 if (mysql_mutex_init(spd_key_mutex_bg_stss,
10054 &spider_thread->mutex, MY_MUTEX_INIT_FAST))
10055 #endif
10056 {
10057 error_num = HA_ERR_OUT_OF_MEM;
10058 goto error_mutex_init;
10059 }
10060 #if MYSQL_VERSION_ID < 50500
10061 if (pthread_cond_init(&spider_thread->cond, NULL))
10062 #else
10063 if (mysql_cond_init(spd_key_cond_bg_stss,
10064 &spider_thread->cond, NULL))
10065 #endif
10066 {
10067 error_num = HA_ERR_OUT_OF_MEM;
10068 goto error_cond_init;
10069 }
10070 #if MYSQL_VERSION_ID < 50500
10071 if (pthread_cond_init(&spider_thread->sync_cond, NULL))
10072 #else
10073 if (mysql_cond_init(spd_key_cond_bg_sts_syncs,
10074 &spider_thread->sync_cond, NULL))
10075 #endif
10076 {
10077 error_num = HA_ERR_OUT_OF_MEM;
10078 goto error_sync_cond_init;
10079 }
10080 #if MYSQL_VERSION_ID < 50500
10081 if (pthread_create(&spider_thread->thread, &spider_pt_attr,
10082 spider_table_bg_sts_action, (void *) spider_thread)
10083 )
10084 #else
10085 if (mysql_thread_create(spd_key_thd_bg_stss, &spider_thread->thread,
10086 &spider_pt_attr, spider_table_bg_sts_action, (void *) spider_thread)
10087 )
10088 #endif
10089 {
10090 error_num = HA_ERR_OUT_OF_MEM;
10091 goto error_thread_create;
10092 }
10093 DBUG_RETURN(0);
10094
10095 error_thread_create:
10096 pthread_cond_destroy(&spider_thread->sync_cond);
10097 error_sync_cond_init:
10098 pthread_cond_destroy(&spider_thread->cond);
10099 error_cond_init:
10100 pthread_mutex_destroy(&spider_thread->mutex);
10101 error_mutex_init:
10102 DBUG_RETURN(error_num);
10103 }
10104
spider_free_sts_threads(SPIDER_THREAD * spider_thread)10105 void spider_free_sts_threads(
10106 SPIDER_THREAD *spider_thread
10107 ) {
10108 bool thread_killed;
10109 DBUG_ENTER("spider_free_sts_threads");
10110 pthread_mutex_lock(&spider_thread->mutex);
10111 thread_killed = spider_thread->killed;
10112 spider_thread->killed = TRUE;
10113 if (!thread_killed)
10114 {
10115 if (spider_thread->thd_wait)
10116 {
10117 pthread_cond_signal(&spider_thread->cond);
10118 }
10119 pthread_cond_wait(&spider_thread->sync_cond, &spider_thread->mutex);
10120 }
10121 pthread_mutex_unlock(&spider_thread->mutex);
10122 pthread_join(spider_thread->thread, NULL);
10123 pthread_cond_destroy(&spider_thread->sync_cond);
10124 pthread_cond_destroy(&spider_thread->cond);
10125 pthread_mutex_destroy(&spider_thread->mutex);
10126 spider_thread->thd_wait = FALSE;
10127 spider_thread->killed = FALSE;
10128 DBUG_VOID_RETURN;
10129 }
10130
spider_create_crd_threads(SPIDER_THREAD * spider_thread)10131 int spider_create_crd_threads(
10132 SPIDER_THREAD *spider_thread
10133 ) {
10134 int error_num;
10135 DBUG_ENTER("spider_create_crd_threads");
10136 #if MYSQL_VERSION_ID < 50500
10137 if (pthread_mutex_init(&spider_thread->mutex,
10138 MY_MUTEX_INIT_FAST))
10139 #else
10140 if (mysql_mutex_init(spd_key_mutex_bg_crds,
10141 &spider_thread->mutex, MY_MUTEX_INIT_FAST))
10142 #endif
10143 {
10144 error_num = HA_ERR_OUT_OF_MEM;
10145 goto error_mutex_init;
10146 }
10147 #if MYSQL_VERSION_ID < 50500
10148 if (pthread_cond_init(&spider_thread->cond, NULL))
10149 #else
10150 if (mysql_cond_init(spd_key_cond_bg_crds,
10151 &spider_thread->cond, NULL))
10152 #endif
10153 {
10154 error_num = HA_ERR_OUT_OF_MEM;
10155 goto error_cond_init;
10156 }
10157 #if MYSQL_VERSION_ID < 50500
10158 if (pthread_cond_init(&spider_thread->sync_cond, NULL))
10159 #else
10160 if (mysql_cond_init(spd_key_cond_bg_crd_syncs,
10161 &spider_thread->sync_cond, NULL))
10162 #endif
10163 {
10164 error_num = HA_ERR_OUT_OF_MEM;
10165 goto error_sync_cond_init;
10166 }
10167 #if MYSQL_VERSION_ID < 50500
10168 if (pthread_create(&spider_thread->thread, &spider_pt_attr,
10169 spider_table_bg_crd_action, (void *) spider_thread)
10170 )
10171 #else
10172 if (mysql_thread_create(spd_key_thd_bg_crds, &spider_thread->thread,
10173 &spider_pt_attr, spider_table_bg_crd_action, (void *) spider_thread)
10174 )
10175 #endif
10176 {
10177 error_num = HA_ERR_OUT_OF_MEM;
10178 goto error_thread_create;
10179 }
10180 DBUG_RETURN(0);
10181
10182 error_thread_create:
10183 pthread_cond_destroy(&spider_thread->sync_cond);
10184 error_sync_cond_init:
10185 pthread_cond_destroy(&spider_thread->cond);
10186 error_cond_init:
10187 pthread_mutex_destroy(&spider_thread->mutex);
10188 error_mutex_init:
10189 DBUG_RETURN(error_num);
10190 }
10191
spider_free_crd_threads(SPIDER_THREAD * spider_thread)10192 void spider_free_crd_threads(
10193 SPIDER_THREAD *spider_thread
10194 ) {
10195 bool thread_killed;
10196 DBUG_ENTER("spider_free_crd_threads");
10197 pthread_mutex_lock(&spider_thread->mutex);
10198 thread_killed = spider_thread->killed;
10199 spider_thread->killed = TRUE;
10200 if (!thread_killed)
10201 {
10202 if (spider_thread->thd_wait)
10203 {
10204 pthread_cond_signal(&spider_thread->cond);
10205 }
10206 pthread_cond_wait(&spider_thread->sync_cond, &spider_thread->mutex);
10207 }
10208 pthread_mutex_unlock(&spider_thread->mutex);
10209 pthread_join(spider_thread->thread, NULL);
10210 pthread_cond_destroy(&spider_thread->sync_cond);
10211 pthread_cond_destroy(&spider_thread->cond);
10212 pthread_mutex_destroy(&spider_thread->mutex);
10213 spider_thread->thd_wait = FALSE;
10214 spider_thread->killed = FALSE;
10215 DBUG_VOID_RETURN;
10216 }
10217
spider_table_bg_sts_action(void * arg)10218 void *spider_table_bg_sts_action(
10219 void *arg
10220 ) {
10221 SPIDER_THREAD *thread = (SPIDER_THREAD *) arg;
10222 SPIDER_SHARE *share;
10223 SPIDER_TRX *trx;
10224 int error_num;
10225 ha_spider *spider;
10226 SPIDER_CONN **conns;
10227 THD *thd;
10228 my_thread_init();
10229 DBUG_ENTER("spider_table_bg_sts_action");
10230 /* init start */
10231 pthread_mutex_lock(&thread->mutex);
10232 if (!(thd = spider_create_sys_thd(thread)))
10233 {
10234 thread->thd_wait = FALSE;
10235 thread->killed = FALSE;
10236 pthread_mutex_unlock(&thread->mutex);
10237 my_thread_end();
10238 DBUG_RETURN(NULL);
10239 }
10240 SPIDER_set_next_thread_id(thd);
10241 #ifdef HAVE_PSI_INTERFACE
10242 mysql_thread_set_psi_id(thd->thread_id);
10243 #endif
10244 thd_proc_info(thd, "Spider table background statistics action handler");
10245 if (!(trx = spider_get_trx(NULL, FALSE, &error_num)))
10246 {
10247 spider_destroy_sys_thd(thd);
10248 thread->thd_wait = FALSE;
10249 thread->killed = FALSE;
10250 pthread_mutex_unlock(&thread->mutex);
10251 #if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32)
10252 set_current_thd(nullptr);
10253 #endif
10254 my_thread_end();
10255 DBUG_RETURN(NULL);
10256 }
10257 trx->thd = thd;
10258 /* init end */
10259
10260 if (thread->init_command)
10261 {
10262 uint i = 0;
10263 tmp_disable_binlog(thd);
10264 thd->security_ctx->skip_grants();
10265 thd->client_capabilities |= CLIENT_MULTI_RESULTS;
10266 if (!(*spd_mysqld_server_started) && !thd->killed)
10267 {
10268 pthread_mutex_lock(spd_LOCK_server_started);
10269 thd->mysys_var->current_cond = spd_COND_server_started;
10270 thd->mysys_var->current_mutex = spd_LOCK_server_started;
10271 if (!(*spd_mysqld_server_started) && !thd->killed)
10272 {
10273 do
10274 {
10275 struct timespec abstime;
10276 set_timespec_nsec(abstime, 1000);
10277 error_num = pthread_cond_timedwait(spd_COND_server_started,
10278 spd_LOCK_server_started, &abstime);
10279 } while (
10280 (error_num == ETIMEDOUT || error_num == ETIME) &&
10281 !(*spd_mysqld_server_started) && !thd->killed && !thread->killed
10282 );
10283 }
10284 pthread_mutex_unlock(spd_LOCK_server_started);
10285 thd->mysys_var->current_cond = &thread->cond;
10286 thd->mysys_var->current_mutex = &thread->mutex;
10287 }
10288 while (spider_init_queries[i].length && !thd->killed && !thread->killed)
10289 {
10290 dispatch_command(COM_QUERY, thd, spider_init_queries[i].str,
10291 (uint) spider_init_queries[i].length, FALSE, FALSE);
10292 if (unlikely(thd->is_error()))
10293 {
10294 fprintf(stderr, "[ERROR] %s\n", spider_stmt_da_message(thd));
10295 thd->clear_error();
10296 break;
10297 }
10298 ++i;
10299 }
10300 thd->mysys_var->current_cond = &thread->cond;
10301 thd->mysys_var->current_mutex = &thread->mutex;
10302 thd->client_capabilities -= CLIENT_MULTI_RESULTS;
10303 reenable_binlog(thd);
10304 thread->init_command = FALSE;
10305 pthread_cond_broadcast(&thread->sync_cond);
10306 }
10307 if (thd->killed)
10308 {
10309 thread->killed = TRUE;
10310 }
10311 if (thd->killed)
10312 {
10313 thread->killed = TRUE;
10314 }
10315
10316 while (TRUE)
10317 {
10318 DBUG_PRINT("info",("spider bg sts loop start"));
10319 if (thread->killed)
10320 {
10321 DBUG_PRINT("info",("spider bg sts kill start"));
10322 trx->thd = NULL;
10323 spider_free_trx(trx, TRUE);
10324 spider_destroy_sys_thd(thd);
10325 pthread_cond_signal(&thread->sync_cond);
10326 pthread_mutex_unlock(&thread->mutex);
10327 #if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32)
10328 set_current_thd(nullptr);
10329 #endif
10330 my_thread_end();
10331 DBUG_RETURN(NULL);
10332 }
10333 if (!thread->queue_first)
10334 {
10335 DBUG_PRINT("info",("spider bg sts has no job"));
10336 thread->thd_wait = TRUE;
10337 pthread_cond_wait(&thread->cond, &thread->mutex);
10338 thread->thd_wait = FALSE;
10339 if (thd->killed)
10340 thread->killed = TRUE;
10341 continue;
10342 }
10343 share = (SPIDER_SHARE *) thread->queue_first;
10344 share->sts_working = TRUE;
10345 pthread_mutex_unlock(&thread->mutex);
10346
10347 spider = share->sts_spider;
10348 conns = spider->conns;
10349 if (spider->search_link_idx < 0)
10350 {
10351 spider->wide_handler->trx = trx;
10352 spider_trx_set_link_idx_for_all(spider);
10353 spider->search_link_idx = spider_conn_first_link_idx(thd,
10354 share->link_statuses, share->access_balances, spider->conn_link_idx,
10355 share->link_count, SPIDER_LINK_STATUS_OK);
10356 }
10357 if (spider->search_link_idx >= 0)
10358 {
10359 DBUG_PRINT("info",
10360 ("spider difftime=%f",
10361 difftime(share->bg_sts_try_time, share->sts_get_time)));
10362 DBUG_PRINT("info",
10363 ("spider bg_sts_interval=%f", share->bg_sts_interval));
10364 if (difftime(share->bg_sts_try_time, share->sts_get_time) >=
10365 share->bg_sts_interval)
10366 {
10367 if (!conns[spider->search_link_idx])
10368 {
10369 spider_get_conn(share, spider->search_link_idx,
10370 share->conn_keys[spider->search_link_idx],
10371 trx, spider, FALSE, FALSE, SPIDER_CONN_KIND_MYSQL,
10372 &error_num);
10373 if (conns[spider->search_link_idx])
10374 {
10375 conns[spider->search_link_idx]->error_mode = 0;
10376 } else {
10377 spider->search_link_idx = -1;
10378 }
10379 }
10380 DBUG_PRINT("info",
10381 ("spider search_link_idx=%d", spider->search_link_idx));
10382 if (spider->search_link_idx >= 0 && conns[spider->search_link_idx])
10383 {
10384 #ifdef WITH_PARTITION_STORAGE_ENGINE
10385 if (spider_get_sts(share, spider->search_link_idx,
10386 share->bg_sts_try_time, spider,
10387 share->bg_sts_interval, share->bg_sts_mode,
10388 share->bg_sts_sync,
10389 2, HA_STATUS_CONST | HA_STATUS_VARIABLE))
10390 #else
10391 if (spider_get_sts(share, spider->search_link_idx,
10392 share->bg_sts_try_time, spider,
10393 share->bg_sts_interval, share->bg_sts_mode,
10394 2, HA_STATUS_CONST | HA_STATUS_VARIABLE))
10395 #endif
10396 {
10397 spider->search_link_idx = -1;
10398 }
10399 }
10400 }
10401 }
10402 memset(spider->need_mons, 0, sizeof(int) * share->link_count);
10403 pthread_mutex_lock(&thread->mutex);
10404 if (thread->queue_first == thread->queue_last)
10405 {
10406 thread->queue_first = NULL;
10407 thread->queue_last = NULL;
10408 } else {
10409 thread->queue_first = share->sts_next;
10410 share->sts_next->sts_prev = NULL;
10411 share->sts_next = NULL;
10412 }
10413 share->sts_working = FALSE;
10414 share->sts_wait = FALSE;
10415 if (thread->first_free_wait)
10416 {
10417 pthread_cond_signal(&thread->sync_cond);
10418 pthread_cond_wait(&thread->cond, &thread->mutex);
10419 if (thd->killed)
10420 thread->killed = TRUE;
10421 }
10422 }
10423 }
10424
spider_table_bg_crd_action(void * arg)10425 void *spider_table_bg_crd_action(
10426 void *arg
10427 ) {
10428 SPIDER_THREAD *thread = (SPIDER_THREAD *) arg;
10429 SPIDER_SHARE *share;
10430 SPIDER_TRX *trx;
10431 int error_num;
10432 ha_spider *spider;
10433 TABLE *table;
10434 SPIDER_CONN **conns;
10435 THD *thd;
10436 my_thread_init();
10437 DBUG_ENTER("spider_table_bg_crd_action");
10438 /* init start */
10439 pthread_mutex_lock(&thread->mutex);
10440 if (!(thd = spider_create_sys_thd(thread)))
10441 {
10442 thread->thd_wait = FALSE;
10443 thread->killed = FALSE;
10444 pthread_mutex_unlock(&thread->mutex);
10445 my_thread_end();
10446 DBUG_RETURN(NULL);
10447 }
10448 SPIDER_set_next_thread_id(thd);
10449 #ifdef HAVE_PSI_INTERFACE
10450 mysql_thread_set_psi_id(thd->thread_id);
10451 #endif
10452 thd_proc_info(thd, "Spider table background cardinality action handler");
10453 if (!(trx = spider_get_trx(NULL, FALSE, &error_num)))
10454 {
10455 spider_destroy_sys_thd(thd);
10456 thread->thd_wait = FALSE;
10457 thread->killed = FALSE;
10458 pthread_mutex_unlock(&thread->mutex);
10459 #if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32)
10460 set_current_thd(nullptr);
10461 #endif
10462 my_thread_end();
10463 DBUG_RETURN(NULL);
10464 }
10465 trx->thd = thd;
10466 /* init end */
10467
10468 while (TRUE)
10469 {
10470 DBUG_PRINT("info",("spider bg crd loop start"));
10471 if (thread->killed)
10472 {
10473 DBUG_PRINT("info",("spider bg crd kill start"));
10474 trx->thd = NULL;
10475 spider_free_trx(trx, TRUE);
10476 spider_destroy_sys_thd(thd);
10477 pthread_cond_signal(&thread->sync_cond);
10478 pthread_mutex_unlock(&thread->mutex);
10479 #if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32)
10480 set_current_thd(nullptr);
10481 #endif
10482 my_thread_end();
10483 DBUG_RETURN(NULL);
10484 }
10485 if (!thread->queue_first)
10486 {
10487 DBUG_PRINT("info",("spider bg crd has no job"));
10488 thread->thd_wait = TRUE;
10489 pthread_cond_wait(&thread->cond, &thread->mutex);
10490 thread->thd_wait = FALSE;
10491 if (thd->killed)
10492 thread->killed = TRUE;
10493 continue;
10494 }
10495 share = (SPIDER_SHARE *) thread->queue_first;
10496 share->crd_working = TRUE;
10497 pthread_mutex_unlock(&thread->mutex);
10498
10499 table = &share->table;
10500 spider = share->crd_spider;
10501 conns = spider->conns;
10502 if (spider->search_link_idx < 0)
10503 {
10504 spider->wide_handler->trx = trx;
10505 spider_trx_set_link_idx_for_all(spider);
10506 spider->search_link_idx = spider_conn_first_link_idx(thd,
10507 share->link_statuses, share->access_balances, spider->conn_link_idx,
10508 share->link_count, SPIDER_LINK_STATUS_OK);
10509 }
10510 if (spider->search_link_idx >= 0)
10511 {
10512 DBUG_PRINT("info",
10513 ("spider difftime=%f",
10514 difftime(share->bg_crd_try_time, share->crd_get_time)));
10515 DBUG_PRINT("info",
10516 ("spider bg_crd_interval=%f", share->bg_crd_interval));
10517 if (difftime(share->bg_crd_try_time, share->crd_get_time) >=
10518 share->bg_crd_interval)
10519 {
10520 if (!conns[spider->search_link_idx])
10521 {
10522 spider_get_conn(share, spider->search_link_idx,
10523 share->conn_keys[spider->search_link_idx],
10524 trx, spider, FALSE, FALSE, SPIDER_CONN_KIND_MYSQL,
10525 &error_num);
10526 if (conns[spider->search_link_idx])
10527 {
10528 conns[spider->search_link_idx]->error_mode = 0;
10529 } else {
10530 spider->search_link_idx = -1;
10531 }
10532 }
10533 DBUG_PRINT("info",
10534 ("spider search_link_idx=%d", spider->search_link_idx));
10535 if (spider->search_link_idx >= 0 && conns[spider->search_link_idx])
10536 {
10537 #ifdef WITH_PARTITION_STORAGE_ENGINE
10538 if (spider_get_crd(share, spider->search_link_idx,
10539 share->bg_crd_try_time, spider, table,
10540 share->bg_crd_interval, share->bg_crd_mode,
10541 share->bg_crd_sync,
10542 2))
10543 #else
10544 if (spider_get_crd(share, spider->search_link_idx,
10545 share->bg_crd_try_time, spider, table,
10546 share->bg_crd_interval, share->bg_crd_mode,
10547 2))
10548 #endif
10549 {
10550 spider->search_link_idx = -1;
10551 }
10552 }
10553 }
10554 }
10555 memset(spider->need_mons, 0, sizeof(int) * share->link_count);
10556 pthread_mutex_lock(&thread->mutex);
10557 if (thread->queue_first == thread->queue_last)
10558 {
10559 thread->queue_first = NULL;
10560 thread->queue_last = NULL;
10561 } else {
10562 thread->queue_first = share->crd_next;
10563 share->crd_next->crd_prev = NULL;
10564 share->crd_next = NULL;
10565 }
10566 share->crd_working = FALSE;
10567 share->crd_wait = FALSE;
10568 if (thread->first_free_wait)
10569 {
10570 pthread_cond_signal(&thread->sync_cond);
10571 pthread_cond_wait(&thread->cond, &thread->mutex);
10572 if (thd->killed)
10573 thread->killed = TRUE;
10574 }
10575 }
10576 }
10577
spider_table_add_share_to_sts_thread(SPIDER_SHARE * share)10578 void spider_table_add_share_to_sts_thread(
10579 SPIDER_SHARE *share
10580 ) {
10581 SPIDER_THREAD *spider_thread = share->sts_thread;
10582 DBUG_ENTER("spider_table_add_share_to_sts_thread");
10583 if (
10584 !share->sts_wait &&
10585 !pthread_mutex_trylock(&spider_thread->mutex)
10586 ) {
10587 if (!share->sts_wait)
10588 {
10589 if (spider_thread->queue_last)
10590 {
10591 DBUG_PRINT("info",("spider add to last"));
10592 share->sts_prev = spider_thread->queue_last;
10593 spider_thread->queue_last->sts_next = share;
10594 } else {
10595 spider_thread->queue_first = share;
10596 }
10597 spider_thread->queue_last = share;
10598 share->sts_wait = TRUE;
10599
10600 if (spider_thread->thd_wait)
10601 {
10602 pthread_cond_signal(&spider_thread->cond);
10603 }
10604 }
10605 pthread_mutex_unlock(&spider_thread->mutex);
10606 }
10607 DBUG_VOID_RETURN;
10608 }
10609
spider_table_add_share_to_crd_thread(SPIDER_SHARE * share)10610 void spider_table_add_share_to_crd_thread(
10611 SPIDER_SHARE *share
10612 ) {
10613 SPIDER_THREAD *spider_thread = share->crd_thread;
10614 DBUG_ENTER("spider_table_add_share_to_crd_thread");
10615 if (
10616 !share->crd_wait &&
10617 !pthread_mutex_trylock(&spider_thread->mutex)
10618 ) {
10619 if (!share->crd_wait)
10620 {
10621 if (spider_thread->queue_last)
10622 {
10623 DBUG_PRINT("info",("spider add to last"));
10624 share->crd_prev = spider_thread->queue_last;
10625 spider_thread->queue_last->crd_next = share;
10626 } else {
10627 spider_thread->queue_first = share;
10628 }
10629 spider_thread->queue_last = share;
10630 share->crd_wait = TRUE;
10631
10632 if (spider_thread->thd_wait)
10633 {
10634 pthread_cond_signal(&spider_thread->cond);
10635 }
10636 }
10637 pthread_mutex_unlock(&spider_thread->mutex);
10638 }
10639 DBUG_VOID_RETURN;
10640 }
10641
spider_table_remove_share_from_sts_thread(SPIDER_SHARE * share)10642 void spider_table_remove_share_from_sts_thread(
10643 SPIDER_SHARE *share
10644 ) {
10645 SPIDER_THREAD *spider_thread = share->sts_thread;
10646 DBUG_ENTER("spider_table_remove_share_from_sts_thread");
10647 if (share->sts_wait)
10648 {
10649 pthread_mutex_lock(&spider_thread->mutex);
10650 if (share->sts_wait)
10651 {
10652 if (share->sts_working)
10653 {
10654 DBUG_PRINT("info",("spider waiting bg sts start"));
10655 spider_thread->first_free_wait = TRUE;
10656 pthread_cond_wait(&spider_thread->sync_cond, &spider_thread->mutex);
10657 spider_thread->first_free_wait = FALSE;
10658 pthread_cond_signal(&spider_thread->cond);
10659 DBUG_PRINT("info",("spider waiting bg sts end"));
10660 }
10661
10662 if (share->sts_prev)
10663 {
10664 if (share->sts_next)
10665 {
10666 DBUG_PRINT("info",("spider remove middle one"));
10667 share->sts_prev->sts_next = share->sts_next;
10668 share->sts_next->sts_prev = share->sts_prev;
10669 } else {
10670 DBUG_PRINT("info",("spider remove last one"));
10671 share->sts_prev->sts_next = NULL;
10672 spider_thread->queue_last = share->sts_prev;
10673 }
10674 } else if (share->sts_next) {
10675 DBUG_PRINT("info",("spider remove first one"));
10676 share->sts_next->sts_prev = NULL;
10677 spider_thread->queue_first = share->sts_next;
10678 } else {
10679 DBUG_PRINT("info",("spider empty"));
10680 spider_thread->queue_first = NULL;
10681 spider_thread->queue_last = NULL;
10682 }
10683 }
10684 pthread_mutex_unlock(&spider_thread->mutex);
10685 }
10686 DBUG_VOID_RETURN;
10687 }
10688
spider_table_remove_share_from_crd_thread(SPIDER_SHARE * share)10689 void spider_table_remove_share_from_crd_thread(
10690 SPIDER_SHARE *share
10691 ) {
10692 SPIDER_THREAD *spider_thread = share->crd_thread;
10693 DBUG_ENTER("spider_table_remove_share_from_crd_thread");
10694 if (share->crd_wait)
10695 {
10696 pthread_mutex_lock(&spider_thread->mutex);
10697 if (share->crd_wait)
10698 {
10699 if (share->crd_working)
10700 {
10701 DBUG_PRINT("info",("spider waiting bg crd start"));
10702 spider_thread->first_free_wait = TRUE;
10703 pthread_cond_wait(&spider_thread->sync_cond, &spider_thread->mutex);
10704 spider_thread->first_free_wait = FALSE;
10705 pthread_cond_signal(&spider_thread->cond);
10706 DBUG_PRINT("info",("spider waiting bg crd end"));
10707 }
10708
10709 if (share->crd_prev)
10710 {
10711 if (share->crd_next)
10712 {
10713 DBUG_PRINT("info",("spider remove middle one"));
10714 share->crd_prev->crd_next = share->crd_next;
10715 share->crd_next->crd_prev = share->crd_prev;
10716 } else {
10717 DBUG_PRINT("info",("spider remove last one"));
10718 share->crd_prev->crd_next = NULL;
10719 spider_thread->queue_last = share->crd_prev;
10720 }
10721 } else if (share->crd_next) {
10722 DBUG_PRINT("info",("spider remove first one"));
10723 share->crd_next->crd_prev = NULL;
10724 spider_thread->queue_first = share->crd_next;
10725 } else {
10726 DBUG_PRINT("info",("spider empty"));
10727 spider_thread->queue_first = NULL;
10728 spider_thread->queue_last = NULL;
10729 }
10730 }
10731 pthread_mutex_unlock(&spider_thread->mutex);
10732 }
10733 DBUG_VOID_RETURN;
10734 }
10735 #endif
10736
spider_duplicate_char(uchar * dst,uchar esc,uchar * src,uint src_lgt)10737 uchar *spider_duplicate_char(
10738 uchar *dst,
10739 uchar esc,
10740 uchar *src,
10741 uint src_lgt
10742 ) {
10743 uchar *ed = src + src_lgt;
10744 DBUG_ENTER("spider_duplicate_char");
10745 while (src < ed)
10746 {
10747 *dst = *src;
10748 if (*src == esc)
10749 {
10750 ++dst;
10751 *dst = esc;
10752 }
10753 ++dst;
10754 ++src;
10755 }
10756 DBUG_RETURN(dst);
10757 }
10758