| 1 | /* Copyright (C) 2008-2017 Kentoku Shiba |
| 2 | |
| 3 | This program is free software; you can redistribute it and/or modify |
| 4 | it under the terms of the GNU General Public License as published by |
| 5 | the Free Software Foundation; version 2 of the License. |
| 6 | |
| 7 | This program is distributed in the hope that it will be useful, |
| 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | GNU General Public License for more details. |
| 11 | |
| 12 | You should have received a copy of the GNU General Public License |
| 13 | along with this program; if not, write to the Free Software |
| 14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
| 15 | |
| 16 | #define MYSQL_SERVER 1 |
| 17 | #include <my_global.h> |
| 18 | #include "mysql_version.h" |
| 19 | #include "spd_environ.h" |
| 20 | #if MYSQL_VERSION_ID < 50500 |
| 21 | #include "mysql_priv.h" |
| 22 | #include <mysql/plugin.h> |
| 23 | #else |
| 24 | #include "sql_priv.h" |
| 25 | #include "probes_mysql.h" |
| 26 | #include "my_getopt.h" |
| 27 | #include "sql_class.h" |
| 28 | #include "sql_partition.h" |
| 29 | #include "sql_servers.h" |
| 30 | #include "sql_select.h" |
| 31 | #include "tztime.h" |
| 32 | #endif |
| 33 | #include "spd_err.h" |
| 34 | #include "spd_param.h" |
| 35 | #include "spd_db_include.h" |
| 36 | #include "spd_include.h" |
| 37 | #include "spd_sys_table.h" |
| 38 | #include "ha_spider.h" |
| 39 | #include "spd_trx.h" |
| 40 | #include "spd_db_conn.h" |
| 41 | #include "spd_table.h" |
| 42 | #include "spd_conn.h" |
| 43 | #include "spd_ping_table.h" |
| 44 | #include "spd_direct_sql.h" |
| 45 | #include "spd_malloc.h" |
| 46 | #include "spd_group_by_handler.h" |
| 47 | |
| 48 | /* Background thread management */ |
| 49 | #ifdef SPIDER_HAS_NEXT_THREAD_ID |
| 50 | #define SPIDER_set_next_thread_id(A) |
| 51 | MYSQL_THD create_thd(); |
| 52 | void destroy_thd(MYSQL_THD thd); |
| 53 | #else |
| 54 | ulong *spd_db_att_thread_id; |
| 55 | inline void SPIDER_set_next_thread_id(THD *A) |
| 56 | { |
| 57 | pthread_mutex_lock(&LOCK_thread_count); |
| 58 | A->thread_id = (*spd_db_att_thread_id)++; |
| 59 | pthread_mutex_unlock(&LOCK_thread_count); |
| 60 | } |
| 61 | MYSQL_THD create_thd() |
| 62 | { |
| 63 | THD *thd = SPIDER_new_THD(next_thread_id()); |
| 64 | if (thd) |
| 65 | { |
| 66 | thd->thread_stack = (char*) &thd; |
| 67 | thd->store_globals(); |
| 68 | thd->set_command(COM_DAEMON); |
| 69 | thd->security_ctx->host_or_ip = "" ; |
| 70 | } |
| 71 | return thd; |
| 72 | } |
| 73 | void destroy_thd(MYSQL_THD thd) |
| 74 | { |
| 75 | delete thd; |
| 76 | } |
| 77 | #endif |
| 78 | inline MYSQL_THD spider_create_sys_thd(SPIDER_THREAD *thread) |
| 79 | { |
| 80 | THD *thd = create_thd(); |
| 81 | if (thd) |
| 82 | { |
| 83 | SPIDER_set_next_thread_id(thd); |
| 84 | thd->mysys_var->current_cond = &thread->cond; |
| 85 | thd->mysys_var->current_mutex = &thread->mutex; |
| 86 | } |
| 87 | return thd; |
| 88 | } |
| 89 | inline void spider_destroy_sys_thd(MYSQL_THD thd) |
| 90 | { |
| 91 | destroy_thd(thd); |
| 92 | } |
| 93 | inline MYSQL_THD spider_create_thd() |
| 94 | { |
| 95 | THD *thd; |
| 96 | my_thread_init(); |
| 97 | if (!(thd = new THD(next_thread_id()))) |
| 98 | my_thread_end(); |
| 99 | else |
| 100 | { |
| 101 | #ifdef HAVE_PSI_INTERFACE |
| 102 | mysql_thread_set_psi_id(thd->thread_id); |
| 103 | #endif |
| 104 | thd->thread_stack = (char *) &thd; |
| 105 | thd->store_globals(); |
| 106 | } |
| 107 | return thd; |
| 108 | } |
| 109 | inline void spider_destroy_thd(MYSQL_THD thd) |
| 110 | { |
| 111 | delete thd; |
| 112 | } |
| 113 | |
| 114 | #ifdef SPIDER_XID_USES_xid_cache_iterate |
| 115 | #else |
| 116 | #ifdef XID_CACHE_IS_SPLITTED |
| 117 | uint *spd_db_att_xid_cache_split_num; |
| 118 | #endif |
| 119 | pthread_mutex_t *spd_db_att_LOCK_xid_cache; |
| 120 | HASH *spd_db_att_xid_cache; |
| 121 | #endif |
| 122 | struct charset_info_st *spd_charset_utf8_bin; |
| 123 | const char **; |
| 124 | const char **spd_defaults_file; |
| 125 | bool volatile *spd_abort_loop; |
| 126 | Time_zone *spd_tz_system; |
| 127 | extern long spider_conn_mutex_id; |
| 128 | handlerton *spider_hton_ptr; |
| 129 | SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE]; |
| 130 | extern SPIDER_DBTON spider_dbton_mysql; |
| 131 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 132 | extern SPIDER_DBTON spider_dbton_handlersocket; |
| 133 | #endif |
| 134 | #ifdef HAVE_ORACLE_OCI |
| 135 | extern SPIDER_DBTON spider_dbton_oracle; |
| 136 | #endif |
| 137 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 138 | SPIDER_THREAD *spider_table_sts_threads; |
| 139 | SPIDER_THREAD *spider_table_crd_threads; |
| 140 | #endif |
| 141 | |
| 142 | #ifdef HAVE_PSI_INTERFACE |
| 143 | PSI_mutex_key spd_key_mutex_tbl; |
| 144 | PSI_mutex_key spd_key_mutex_init_error_tbl; |
| 145 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 146 | PSI_mutex_key spd_key_mutex_pt_share; |
| 147 | #endif |
| 148 | PSI_mutex_key spd_key_mutex_lgtm_tblhnd_share; |
| 149 | PSI_mutex_key spd_key_mutex_conn; |
| 150 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 151 | PSI_mutex_key spd_key_mutex_hs_r_conn; |
| 152 | PSI_mutex_key spd_key_mutex_hs_w_conn; |
| 153 | #endif |
| 154 | PSI_mutex_key spd_key_mutex_open_conn; |
| 155 | PSI_mutex_key spd_key_mutex_allocated_thds; |
| 156 | PSI_mutex_key spd_key_mutex_mon_table_cache; |
| 157 | PSI_mutex_key spd_key_mutex_udf_table_mon; |
| 158 | PSI_mutex_key spd_key_mutex_mta_conn; |
| 159 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 160 | PSI_mutex_key spd_key_mutex_bg_conn_chain; |
| 161 | PSI_mutex_key spd_key_mutex_bg_conn_sync; |
| 162 | PSI_mutex_key spd_key_mutex_bg_conn; |
| 163 | PSI_mutex_key spd_key_mutex_bg_job_stack; |
| 164 | PSI_mutex_key spd_key_mutex_bg_mon; |
| 165 | PSI_mutex_key spd_key_mutex_bg_direct_sql; |
| 166 | #endif |
| 167 | PSI_mutex_key spd_key_mutex_mon_list_caller; |
| 168 | PSI_mutex_key spd_key_mutex_mon_list_receptor; |
| 169 | PSI_mutex_key spd_key_mutex_mon_list_monitor; |
| 170 | PSI_mutex_key spd_key_mutex_mon_list_update_status; |
| 171 | PSI_mutex_key spd_key_mutex_share; |
| 172 | PSI_mutex_key spd_key_mutex_share_sts; |
| 173 | PSI_mutex_key spd_key_mutex_share_crd; |
| 174 | PSI_mutex_key spd_key_mutex_share_auto_increment; |
| 175 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 176 | PSI_mutex_key spd_key_mutex_pt_share_sts; |
| 177 | PSI_mutex_key spd_key_mutex_pt_share_crd; |
| 178 | PSI_mutex_key spd_key_mutex_pt_handler; |
| 179 | #endif |
| 180 | PSI_mutex_key spd_key_mutex_udf_table; |
| 181 | PSI_mutex_key spd_key_mutex_mem_calc; |
| 182 | PSI_mutex_key spd_key_thread_id; |
| 183 | PSI_mutex_key spd_key_conn_id; |
| 184 | PSI_mutex_key spd_key_mutex_ipport_count; |
| 185 | PSI_mutex_key spd_key_mutex_conn_i; |
| 186 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 187 | PSI_mutex_key spd_key_mutex_bg_stss; |
| 188 | PSI_mutex_key spd_key_mutex_bg_crds; |
| 189 | #endif |
| 190 | |
| 191 | static PSI_mutex_info all_spider_mutexes[]= |
| 192 | { |
| 193 | { &spd_key_mutex_tbl, "tbl" , PSI_FLAG_GLOBAL}, |
| 194 | { &spd_key_mutex_init_error_tbl, "init_error_tbl" , PSI_FLAG_GLOBAL}, |
| 195 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 196 | { &spd_key_mutex_pt_share, "pt_share" , PSI_FLAG_GLOBAL}, |
| 197 | #endif |
| 198 | { &spd_key_mutex_lgtm_tblhnd_share, "lgtm_tblhnd_share" , PSI_FLAG_GLOBAL}, |
| 199 | { &spd_key_mutex_conn, "conn" , PSI_FLAG_GLOBAL}, |
| 200 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 201 | { &spd_key_mutex_hs_r_conn, "hs_r_conn" , PSI_FLAG_GLOBAL}, |
| 202 | { &spd_key_mutex_hs_w_conn, "hs_w_conn" , PSI_FLAG_GLOBAL}, |
| 203 | #endif |
| 204 | { &spd_key_mutex_open_conn, "open_conn" , PSI_FLAG_GLOBAL}, |
| 205 | { &spd_key_mutex_allocated_thds, "allocated_thds" , PSI_FLAG_GLOBAL}, |
| 206 | { &spd_key_mutex_mon_table_cache, "mon_table_cache" , PSI_FLAG_GLOBAL}, |
| 207 | { &spd_key_mutex_udf_table_mon, "udf_table_mon" , PSI_FLAG_GLOBAL}, |
| 208 | { &spd_key_mutex_mem_calc, "mem_calc" , PSI_FLAG_GLOBAL}, |
| 209 | { &spd_key_thread_id, "thread_id" , PSI_FLAG_GLOBAL}, |
| 210 | { &spd_key_conn_id, "conn_id" , PSI_FLAG_GLOBAL}, |
| 211 | { &spd_key_mutex_ipport_count, "ipport_count" , PSI_FLAG_GLOBAL}, |
| 212 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 213 | { &spd_key_mutex_bg_stss, "bg_stss" , PSI_FLAG_GLOBAL}, |
| 214 | { &spd_key_mutex_bg_crds, "bg_crds" , PSI_FLAG_GLOBAL}, |
| 215 | #endif |
| 216 | { &spd_key_mutex_conn_i, "conn_i" , 0}, |
| 217 | { &spd_key_mutex_mta_conn, "mta_conn" , 0}, |
| 218 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 219 | { &spd_key_mutex_bg_conn_chain, "bg_conn_chain" , 0}, |
| 220 | { &spd_key_mutex_bg_conn_sync, "bg_conn_sync" , 0}, |
| 221 | { &spd_key_mutex_bg_conn, "bg_conn" , 0}, |
| 222 | { &spd_key_mutex_bg_job_stack, "bg_job_stack" , 0}, |
| 223 | { &spd_key_mutex_bg_mon, "bg_mon" , 0}, |
| 224 | { &spd_key_mutex_bg_direct_sql, "bg_direct_sql" , 0}, |
| 225 | #endif |
| 226 | { &spd_key_mutex_mon_list_caller, "mon_list_caller" , 0}, |
| 227 | { &spd_key_mutex_mon_list_receptor, "mon_list_receptor" , 0}, |
| 228 | { &spd_key_mutex_mon_list_monitor, "mon_list_monitor" , 0}, |
| 229 | { &spd_key_mutex_mon_list_update_status, "mon_list_update_status" , 0}, |
| 230 | { &spd_key_mutex_share, "share" , 0}, |
| 231 | { &spd_key_mutex_share_sts, "share_sts" , 0}, |
| 232 | { &spd_key_mutex_share_crd, "share_crd" , 0}, |
| 233 | { &spd_key_mutex_share_auto_increment, "share_auto_increment" , 0}, |
| 234 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 235 | { &spd_key_mutex_pt_share_sts, "pt_share_sts" , 0}, |
| 236 | { &spd_key_mutex_pt_share_crd, "pt_share_crd" , 0}, |
| 237 | { &spd_key_mutex_pt_handler, "pt_handler" , 0}, |
| 238 | #endif |
| 239 | { &spd_key_mutex_udf_table, "udf_table" , 0}, |
| 240 | }; |
| 241 | |
| 242 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 243 | PSI_cond_key spd_key_cond_bg_conn_sync; |
| 244 | PSI_cond_key spd_key_cond_bg_conn; |
| 245 | PSI_cond_key spd_key_cond_bg_sts; |
| 246 | PSI_cond_key spd_key_cond_bg_sts_sync; |
| 247 | PSI_cond_key spd_key_cond_bg_crd; |
| 248 | PSI_cond_key spd_key_cond_bg_crd_sync; |
| 249 | PSI_cond_key spd_key_cond_bg_mon; |
| 250 | PSI_cond_key spd_key_cond_bg_mon_sleep; |
| 251 | PSI_cond_key spd_key_cond_bg_direct_sql; |
| 252 | #endif |
| 253 | PSI_cond_key spd_key_cond_udf_table_mon; |
| 254 | PSI_cond_key spd_key_cond_conn_i; |
| 255 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 256 | PSI_cond_key spd_key_cond_bg_stss; |
| 257 | PSI_cond_key spd_key_cond_bg_sts_syncs; |
| 258 | PSI_cond_key spd_key_cond_bg_crds; |
| 259 | PSI_cond_key spd_key_cond_bg_crd_syncs; |
| 260 | #endif |
| 261 | |
| 262 | static PSI_cond_info all_spider_conds[] = { |
| 263 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 264 | {&spd_key_cond_bg_conn_sync, "bg_conn_sync" , 0}, |
| 265 | {&spd_key_cond_bg_conn, "bg_conn" , 0}, |
| 266 | {&spd_key_cond_bg_sts, "bg_sts" , 0}, |
| 267 | {&spd_key_cond_bg_sts_sync, "bg_sts_sync" , 0}, |
| 268 | {&spd_key_cond_bg_crd, "bg_crd" , 0}, |
| 269 | {&spd_key_cond_bg_crd_sync, "bg_crd_sync" , 0}, |
| 270 | {&spd_key_cond_bg_mon, "bg_mon" , 0}, |
| 271 | {&spd_key_cond_bg_mon_sleep, "bg_mon_sleep" , 0}, |
| 272 | {&spd_key_cond_bg_direct_sql, "bg_direct_sql" , 0}, |
| 273 | #endif |
| 274 | {&spd_key_cond_udf_table_mon, "udf_table_mon" , 0}, |
| 275 | {&spd_key_cond_conn_i, "conn_i" , 0}, |
| 276 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 277 | {&spd_key_cond_bg_stss, "bg_stss" , 0}, |
| 278 | {&spd_key_cond_bg_sts_syncs, "bg_sts_syncs" , 0}, |
| 279 | {&spd_key_cond_bg_crds, "bg_crds" , 0}, |
| 280 | {&spd_key_cond_bg_crd_syncs, "bg_crd_syncs" , 0}, |
| 281 | #endif |
| 282 | }; |
| 283 | |
| 284 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 285 | PSI_thread_key spd_key_thd_bg; |
| 286 | PSI_thread_key spd_key_thd_bg_sts; |
| 287 | PSI_thread_key spd_key_thd_bg_crd; |
| 288 | PSI_thread_key spd_key_thd_bg_mon; |
| 289 | PSI_thread_key spd_key_thd_bg_stss; |
| 290 | PSI_thread_key spd_key_thd_bg_crds; |
| 291 | #endif |
| 292 | |
| 293 | static PSI_thread_info all_spider_threads[] = { |
| 294 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 295 | {&spd_key_thd_bg, "bg" , 0}, |
| 296 | {&spd_key_thd_bg_sts, "bg_sts" , 0}, |
| 297 | {&spd_key_thd_bg_crd, "bg_crd" , 0}, |
| 298 | {&spd_key_thd_bg_mon, "bg_mon" , 0}, |
| 299 | {&spd_key_thd_bg_stss, "bg_stss" , 0}, |
| 300 | {&spd_key_thd_bg_crds, "bg_crds" , 0}, |
| 301 | #endif |
| 302 | }; |
| 303 | #endif |
| 304 | |
| 305 | extern HASH spider_open_connections; |
| 306 | extern HASH spider_ipport_conns; |
| 307 | extern uint spider_open_connections_id; |
| 308 | extern const char *spider_open_connections_func_name; |
| 309 | extern const char *spider_open_connections_file_name; |
| 310 | extern ulong spider_open_connections_line_no; |
| 311 | extern pthread_mutex_t spider_conn_mutex; |
| 312 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 313 | extern HASH spider_hs_r_conn_hash; |
| 314 | extern uint spider_hs_r_conn_hash_id; |
| 315 | extern const char *spider_hs_r_conn_hash_func_name; |
| 316 | extern const char *spider_hs_r_conn_hash_file_name; |
| 317 | extern ulong spider_hs_r_conn_hash_line_no; |
| 318 | extern pthread_mutex_t spider_hs_r_conn_mutex; |
| 319 | extern HASH spider_hs_w_conn_hash; |
| 320 | extern uint spider_hs_w_conn_hash_id; |
| 321 | extern const char *spider_hs_w_conn_hash_func_name; |
| 322 | extern const char *spider_hs_w_conn_hash_file_name; |
| 323 | extern ulong spider_hs_w_conn_hash_line_no; |
| 324 | extern pthread_mutex_t spider_hs_w_conn_mutex; |
| 325 | #endif |
| 326 | extern HASH *spider_udf_table_mon_list_hash; |
| 327 | extern uint spider_udf_table_mon_list_hash_id; |
| 328 | extern const char *spider_udf_table_mon_list_hash_func_name; |
| 329 | extern const char *spider_udf_table_mon_list_hash_file_name; |
| 330 | extern ulong spider_udf_table_mon_list_hash_line_no; |
| 331 | extern pthread_mutex_t *spider_udf_table_mon_mutexes; |
| 332 | extern pthread_cond_t *spider_udf_table_mon_conds; |
| 333 | extern pthread_mutex_t spider_open_conn_mutex; |
| 334 | extern pthread_mutex_t spider_mon_table_cache_mutex; |
| 335 | extern DYNAMIC_ARRAY spider_mon_table_cache; |
| 336 | extern uint spider_mon_table_cache_id; |
| 337 | extern const char *spider_mon_table_cache_func_name; |
| 338 | extern const char *spider_mon_table_cache_file_name; |
| 339 | extern ulong spider_mon_table_cache_line_no; |
| 340 | |
| 341 | HASH spider_open_tables; |
| 342 | uint spider_open_tables_id; |
| 343 | const char *spider_open_tables_func_name; |
| 344 | const char *spider_open_tables_file_name; |
| 345 | ulong spider_open_tables_line_no; |
| 346 | pthread_mutex_t spider_tbl_mutex; |
| 347 | HASH spider_init_error_tables; |
| 348 | uint spider_init_error_tables_id; |
| 349 | const char *spider_init_error_tables_func_name; |
| 350 | const char *spider_init_error_tables_file_name; |
| 351 | ulong spider_init_error_tables_line_no; |
| 352 | pthread_mutex_t spider_init_error_tbl_mutex; |
| 353 | |
| 354 | extern pthread_mutex_t spider_thread_id_mutex; |
| 355 | extern pthread_mutex_t spider_conn_id_mutex; |
| 356 | extern pthread_mutex_t spider_ipport_conn_mutex; |
| 357 | |
| 358 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 359 | HASH spider_open_pt_share; |
| 360 | uint spider_open_pt_share_id; |
| 361 | const char *spider_open_pt_share_func_name; |
| 362 | const char *spider_open_pt_share_file_name; |
| 363 | ulong spider_open_pt_share_line_no; |
| 364 | pthread_mutex_t spider_pt_share_mutex; |
| 365 | #endif |
| 366 | |
| 367 | HASH spider_lgtm_tblhnd_share_hash; |
| 368 | uint spider_lgtm_tblhnd_share_hash_id; |
| 369 | const char *spider_lgtm_tblhnd_share_hash_func_name; |
| 370 | const char *spider_lgtm_tblhnd_share_hash_file_name; |
| 371 | ulong spider_lgtm_tblhnd_share_hash_line_no; |
| 372 | pthread_mutex_t spider_lgtm_tblhnd_share_mutex; |
| 373 | |
| 374 | HASH spider_allocated_thds; |
| 375 | uint spider_allocated_thds_id; |
| 376 | const char *spider_allocated_thds_func_name; |
| 377 | const char *spider_allocated_thds_file_name; |
| 378 | ulong spider_allocated_thds_line_no; |
| 379 | pthread_mutex_t spider_allocated_thds_mutex; |
| 380 | |
| 381 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 382 | pthread_attr_t spider_pt_attr; |
| 383 | #endif |
| 384 | |
| 385 | extern pthread_mutex_t spider_mem_calc_mutex; |
| 386 | |
| 387 | extern const char *spider_alloc_func_name[SPIDER_MEM_CALC_LIST_NUM]; |
| 388 | extern const char *spider_alloc_file_name[SPIDER_MEM_CALC_LIST_NUM]; |
| 389 | extern ulong spider_alloc_line_no[SPIDER_MEM_CALC_LIST_NUM]; |
| 390 | extern ulonglong spider_total_alloc_mem[SPIDER_MEM_CALC_LIST_NUM]; |
| 391 | extern longlong spider_current_alloc_mem[SPIDER_MEM_CALC_LIST_NUM]; |
| 392 | extern ulonglong spider_alloc_mem_count[SPIDER_MEM_CALC_LIST_NUM]; |
| 393 | extern ulonglong spider_free_mem_count[SPIDER_MEM_CALC_LIST_NUM]; |
| 394 | |
| 395 | static char spider_wild_many = '%', spider_wild_one = '_', |
| 396 | spider_wild_prefix='\\'; |
| 397 | |
| 398 | // for spider_open_tables |
| 399 | uchar *spider_tbl_get_key( |
| 400 | SPIDER_SHARE *share, |
| 401 | size_t *length, |
| 402 | my_bool not_used __attribute__ ((unused)) |
| 403 | ) { |
| 404 | DBUG_ENTER("spider_tbl_get_key" ); |
| 405 | *length = share->table_name_length; |
| 406 | DBUG_RETURN((uchar*) share->table_name); |
| 407 | } |
| 408 | |
| 409 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 410 | uchar *spider_pt_share_get_key( |
| 411 | SPIDER_PARTITION_SHARE *share, |
| 412 | size_t *length, |
| 413 | my_bool not_used __attribute__ ((unused)) |
| 414 | ) { |
| 415 | DBUG_ENTER("spider_pt_share_get_key" ); |
| 416 | *length = share->table_name_length; |
| 417 | DBUG_RETURN((uchar*) share->table_name); |
| 418 | } |
| 419 | |
| 420 | uchar *spider_pt_handler_share_get_key( |
| 421 | SPIDER_PARTITION_HANDLER_SHARE *share, |
| 422 | size_t *length, |
| 423 | my_bool not_used __attribute__ ((unused)) |
| 424 | ) { |
| 425 | DBUG_ENTER("spider_pt_handler_share_get_key" ); |
| 426 | *length = sizeof(TABLE *); |
| 427 | DBUG_RETURN((uchar*) &share->table); |
| 428 | } |
| 429 | #endif |
| 430 | |
| 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 | |
| 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 | |
| 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 | |
| 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 | |
| 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 |
| 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 | |
| 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 | |
| 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_pk_names) |
| 789 | { |
| 790 | for (roop_count = 0; roop_count < (int) share->tgt_pk_names_length; |
| 791 | roop_count++) |
| 792 | { |
| 793 | if (share->tgt_pk_names[roop_count]) |
| 794 | spider_free(spider_current_trx, share->tgt_pk_names[roop_count], |
| 795 | MYF(0)); |
| 796 | } |
| 797 | spider_free(spider_current_trx, share->tgt_pk_names, MYF(0)); |
| 798 | } |
| 799 | if (share->tgt_sequence_names) |
| 800 | { |
| 801 | for (roop_count = 0; roop_count < (int) share->tgt_sequence_names_length; |
| 802 | roop_count++) |
| 803 | { |
| 804 | if (share->tgt_sequence_names[roop_count]) |
| 805 | spider_free(spider_current_trx, share->tgt_sequence_names[roop_count], |
| 806 | MYF(0)); |
| 807 | } |
| 808 | spider_free(spider_current_trx, share->tgt_sequence_names, MYF(0)); |
| 809 | } |
| 810 | if (share->static_link_ids) |
| 811 | { |
| 812 | for (roop_count = 0; roop_count < (int) share->static_link_ids_length; |
| 813 | roop_count++) |
| 814 | { |
| 815 | if (share->static_link_ids[roop_count]) |
| 816 | spider_free(spider_current_trx, share->static_link_ids[roop_count], |
| 817 | MYF(0)); |
| 818 | } |
| 819 | spider_free(spider_current_trx, share->static_link_ids, MYF(0)); |
| 820 | } |
| 821 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 822 | if (share->hs_read_socks) |
| 823 | { |
| 824 | for (roop_count = 0; roop_count < (int) share->hs_read_socks_length; |
| 825 | roop_count++) |
| 826 | { |
| 827 | if (share->hs_read_socks[roop_count]) |
| 828 | spider_free(spider_current_trx, share->hs_read_socks[roop_count], |
| 829 | MYF(0)); |
| 830 | } |
| 831 | spider_free(spider_current_trx, share->hs_read_socks, MYF(0)); |
| 832 | } |
| 833 | if (share->hs_write_socks) |
| 834 | { |
| 835 | for (roop_count = 0; roop_count < (int) share->hs_write_socks_length; |
| 836 | roop_count++) |
| 837 | { |
| 838 | if (share->hs_write_socks[roop_count]) |
| 839 | spider_free(spider_current_trx, share->hs_write_socks[roop_count], |
| 840 | MYF(0)); |
| 841 | } |
| 842 | spider_free(spider_current_trx, share->hs_write_socks, MYF(0)); |
| 843 | } |
| 844 | #endif |
| 845 | if (share->bka_engine) |
| 846 | spider_free(spider_current_trx, share->bka_engine, MYF(0)); |
| 847 | if (share->conn_keys) |
| 848 | spider_free(spider_current_trx, share->conn_keys, MYF(0)); |
| 849 | if (share->tgt_ports) |
| 850 | spider_free(spider_current_trx, share->tgt_ports, MYF(0)); |
| 851 | if (share->tgt_ssl_vscs) |
| 852 | spider_free(spider_current_trx, share->tgt_ssl_vscs, MYF(0)); |
| 853 | if (share->link_statuses) |
| 854 | spider_free(spider_current_trx, share->link_statuses, MYF(0)); |
| 855 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 856 | if (share->monitoring_bg_flag) |
| 857 | spider_free(spider_current_trx, share->monitoring_bg_flag, MYF(0)); |
| 858 | if (share->monitoring_bg_kind) |
| 859 | spider_free(spider_current_trx, share->monitoring_bg_kind, MYF(0)); |
| 860 | #endif |
| 861 | if (share->monitoring_binlog_pos_at_failing) |
| 862 | spider_free(spider_current_trx, share->monitoring_binlog_pos_at_failing, MYF(0)); |
| 863 | if (share->monitoring_flag) |
| 864 | spider_free(spider_current_trx, share->monitoring_flag, MYF(0)); |
| 865 | if (share->monitoring_kind) |
| 866 | spider_free(spider_current_trx, share->monitoring_kind, MYF(0)); |
| 867 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 868 | if (share->use_hs_reads) |
| 869 | spider_free(spider_current_trx, share->use_hs_reads, MYF(0)); |
| 870 | if (share->use_hs_writes) |
| 871 | spider_free(spider_current_trx, share->use_hs_writes, MYF(0)); |
| 872 | if (share->hs_read_ports) |
| 873 | spider_free(spider_current_trx, share->hs_read_ports, MYF(0)); |
| 874 | if (share->hs_write_ports) |
| 875 | spider_free(spider_current_trx, share->hs_write_ports, MYF(0)); |
| 876 | if (share->hs_write_to_reads) |
| 877 | spider_free(spider_current_trx, share->hs_write_to_reads, MYF(0)); |
| 878 | #endif |
| 879 | if (share->use_handlers) |
| 880 | spider_free(spider_current_trx, share->use_handlers, MYF(0)); |
| 881 | if (share->connect_timeouts) |
| 882 | spider_free(spider_current_trx, share->connect_timeouts, MYF(0)); |
| 883 | if (share->net_read_timeouts) |
| 884 | spider_free(spider_current_trx, share->net_read_timeouts, MYF(0)); |
| 885 | if (share->net_write_timeouts) |
| 886 | spider_free(spider_current_trx, share->net_write_timeouts, MYF(0)); |
| 887 | if (share->access_balances) |
| 888 | spider_free(spider_current_trx, share->access_balances, MYF(0)); |
| 889 | if (share->bka_table_name_types) |
| 890 | spider_free(spider_current_trx, share->bka_table_name_types, MYF(0)); |
| 891 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 892 | if (share->monitoring_bg_interval) |
| 893 | spider_free(spider_current_trx, share->monitoring_bg_interval, MYF(0)); |
| 894 | #endif |
| 895 | if (share->monitoring_limit) |
| 896 | spider_free(spider_current_trx, share->monitoring_limit, MYF(0)); |
| 897 | if (share->monitoring_sid) |
| 898 | spider_free(spider_current_trx, share->monitoring_sid, MYF(0)); |
| 899 | if (share->alter_table.tmp_server_names) |
| 900 | spider_free(spider_current_trx, share->alter_table.tmp_server_names, |
| 901 | MYF(0)); |
| 902 | if (share->key_hint) |
| 903 | { |
| 904 | delete [] share->key_hint; |
| 905 | share->key_hint = NULL; |
| 906 | } |
| 907 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 908 | if (share->partition_share) |
| 909 | spider_free_pt_share(share->partition_share); |
| 910 | #endif |
| 911 | DBUG_RETURN(0); |
| 912 | } |
| 913 | |
| 914 | void spider_free_tmp_share_alloc( |
| 915 | SPIDER_SHARE *share |
| 916 | ) { |
| 917 | DBUG_ENTER("spider_free_tmp_share_alloc" ); |
| 918 | if (share->server_names && share->server_names[0]) |
| 919 | { |
| 920 | spider_free(spider_current_trx, share->server_names[0], MYF(0)); |
| 921 | share->server_names[0] = NULL; |
| 922 | } |
| 923 | if (share->tgt_table_names && share->tgt_table_names[0]) |
| 924 | { |
| 925 | spider_free(spider_current_trx, share->tgt_table_names[0], MYF(0)); |
| 926 | share->tgt_table_names[0] = NULL; |
| 927 | } |
| 928 | if (share->tgt_dbs && share->tgt_dbs[0]) |
| 929 | { |
| 930 | spider_free(spider_current_trx, share->tgt_dbs[0], MYF(0)); |
| 931 | share->tgt_dbs[0] = NULL; |
| 932 | } |
| 933 | if (share->tgt_hosts && share->tgt_hosts[0]) |
| 934 | { |
| 935 | spider_free(spider_current_trx, share->tgt_hosts[0], MYF(0)); |
| 936 | share->tgt_hosts[0] = NULL; |
| 937 | } |
| 938 | if (share->tgt_usernames && share->tgt_usernames[0]) |
| 939 | { |
| 940 | spider_free(spider_current_trx, share->tgt_usernames[0], MYF(0)); |
| 941 | share->tgt_usernames[0] = NULL; |
| 942 | } |
| 943 | if (share->tgt_passwords && share->tgt_passwords[0]) |
| 944 | { |
| 945 | spider_free(spider_current_trx, share->tgt_passwords[0], MYF(0)); |
| 946 | share->tgt_passwords[0] = NULL; |
| 947 | } |
| 948 | if (share->tgt_sockets && share->tgt_sockets[0]) |
| 949 | { |
| 950 | spider_free(spider_current_trx, share->tgt_sockets[0], MYF(0)); |
| 951 | share->tgt_sockets[0] = NULL; |
| 952 | } |
| 953 | if (share->tgt_wrappers && share->tgt_wrappers[0]) |
| 954 | { |
| 955 | spider_free(spider_current_trx, share->tgt_wrappers[0], MYF(0)); |
| 956 | share->tgt_wrappers[0] = NULL; |
| 957 | } |
| 958 | if (share->tgt_ssl_cas && share->tgt_ssl_cas[0]) |
| 959 | { |
| 960 | spider_free(spider_current_trx, share->tgt_ssl_cas[0], MYF(0)); |
| 961 | share->tgt_ssl_cas[0] = NULL; |
| 962 | } |
| 963 | if (share->tgt_ssl_capaths && share->tgt_ssl_capaths[0]) |
| 964 | { |
| 965 | spider_free(spider_current_trx, share->tgt_ssl_capaths[0], MYF(0)); |
| 966 | share->tgt_ssl_capaths[0] = NULL; |
| 967 | } |
| 968 | if (share->tgt_ssl_certs && share->tgt_ssl_certs[0]) |
| 969 | { |
| 970 | spider_free(spider_current_trx, share->tgt_ssl_certs[0], MYF(0)); |
| 971 | share->tgt_ssl_certs[0] = NULL; |
| 972 | } |
| 973 | if (share->tgt_ssl_ciphers && share->tgt_ssl_ciphers[0]) |
| 974 | { |
| 975 | spider_free(spider_current_trx, share->tgt_ssl_ciphers[0], MYF(0)); |
| 976 | share->tgt_ssl_ciphers[0] = NULL; |
| 977 | } |
| 978 | if (share->tgt_ssl_keys && share->tgt_ssl_keys[0]) |
| 979 | { |
| 980 | spider_free(spider_current_trx, share->tgt_ssl_keys[0], MYF(0)); |
| 981 | share->tgt_ssl_keys[0] = NULL; |
| 982 | } |
| 983 | if (share->tgt_default_files && share->tgt_default_files[0]) |
| 984 | { |
| 985 | spider_free(spider_current_trx, share->tgt_default_files[0], MYF(0)); |
| 986 | share->tgt_default_files[0] = NULL; |
| 987 | } |
| 988 | if (share->tgt_default_groups && share->tgt_default_groups[0]) |
| 989 | { |
| 990 | spider_free(spider_current_trx, share->tgt_default_groups[0], MYF(0)); |
| 991 | share->tgt_default_groups[0] = NULL; |
| 992 | } |
| 993 | if (share->tgt_pk_names && share->tgt_pk_names[0]) |
| 994 | { |
| 995 | spider_free(spider_current_trx, share->tgt_pk_names[0], MYF(0)); |
| 996 | share->tgt_pk_names[0] = NULL; |
| 997 | } |
| 998 | if (share->tgt_sequence_names && share->tgt_sequence_names[0]) |
| 999 | { |
| 1000 | spider_free(spider_current_trx, share->tgt_sequence_names[0], MYF(0)); |
| 1001 | share->tgt_sequence_names[0] = NULL; |
| 1002 | } |
| 1003 | if (share->static_link_ids && share->static_link_ids[0]) |
| 1004 | { |
| 1005 | spider_free(spider_current_trx, share->static_link_ids[0], MYF(0)); |
| 1006 | share->static_link_ids[0] = NULL; |
| 1007 | } |
| 1008 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 1009 | if (share->hs_read_socks && share->hs_read_socks[0]) |
| 1010 | { |
| 1011 | spider_free(spider_current_trx, share->hs_read_socks[0], MYF(0)); |
| 1012 | share->hs_read_socks[0] = NULL; |
| 1013 | } |
| 1014 | if (share->hs_write_socks && share->hs_write_socks[0]) |
| 1015 | { |
| 1016 | spider_free(spider_current_trx, share->hs_write_socks[0], MYF(0)); |
| 1017 | share->hs_write_socks[0] = NULL; |
| 1018 | } |
| 1019 | #endif |
| 1020 | if (share->bka_engine) |
| 1021 | { |
| 1022 | spider_free(spider_current_trx, share->bka_engine, MYF(0)); |
| 1023 | share->bka_engine = NULL; |
| 1024 | } |
| 1025 | if (share->conn_keys) |
| 1026 | { |
| 1027 | spider_free(spider_current_trx, share->conn_keys, MYF(0)); |
| 1028 | share->conn_keys = NULL; |
| 1029 | } |
| 1030 | if (share->static_key_cardinality) |
| 1031 | spider_free(spider_current_trx, share->static_key_cardinality, MYF(0)); |
| 1032 | if (share->key_hint) |
| 1033 | { |
| 1034 | delete [] share->key_hint; |
| 1035 | share->key_hint = NULL; |
| 1036 | } |
| 1037 | DBUG_VOID_RETURN; |
| 1038 | } |
| 1039 | |
| 1040 | char *spider_get_string_between_quote( |
| 1041 | char *ptr, |
| 1042 | bool alloc, |
| 1043 | SPIDER_PARAM_STRING_PARSE *param_string_parse |
| 1044 | ) { |
| 1045 | char *start_ptr, *end_ptr, *tmp_ptr, *esc_ptr; |
| 1046 | bool find_flg = FALSE, esc_flg = FALSE; |
| 1047 | DBUG_ENTER("spider_get_string_between_quote" ); |
| 1048 | |
| 1049 | start_ptr = strchr(ptr, '\''); |
| 1050 | end_ptr = strchr(ptr, '"'); |
| 1051 | if (start_ptr && (!end_ptr || start_ptr < end_ptr)) |
| 1052 | { |
| 1053 | tmp_ptr = ++start_ptr; |
| 1054 | while (!find_flg) |
| 1055 | { |
| 1056 | if (!(end_ptr = strchr(tmp_ptr, '\''))) |
| 1057 | DBUG_RETURN(NULL); |
| 1058 | esc_ptr = tmp_ptr; |
| 1059 | while (!find_flg) |
| 1060 | { |
| 1061 | esc_ptr = strchr(esc_ptr, '\\'); |
| 1062 | if (!esc_ptr || esc_ptr > end_ptr) |
| 1063 | find_flg = TRUE; |
| 1064 | else if (esc_ptr == end_ptr - 1) |
| 1065 | { |
| 1066 | esc_flg = TRUE; |
| 1067 | tmp_ptr = end_ptr + 1; |
| 1068 | break; |
| 1069 | } else { |
| 1070 | esc_flg = TRUE; |
| 1071 | esc_ptr += 2; |
| 1072 | } |
| 1073 | } |
| 1074 | } |
| 1075 | } else if (end_ptr) |
| 1076 | { |
| 1077 | start_ptr = end_ptr; |
| 1078 | tmp_ptr = ++start_ptr; |
| 1079 | while (!find_flg) |
| 1080 | { |
| 1081 | if (!(end_ptr = strchr(tmp_ptr, '"'))) |
| 1082 | DBUG_RETURN(NULL); |
| 1083 | esc_ptr = tmp_ptr; |
| 1084 | while (!find_flg) |
| 1085 | { |
| 1086 | esc_ptr = strchr(esc_ptr, '\\'); |
| 1087 | if (!esc_ptr || esc_ptr > end_ptr) |
| 1088 | find_flg = TRUE; |
| 1089 | else if (esc_ptr == end_ptr - 1) |
| 1090 | { |
| 1091 | esc_flg = TRUE; |
| 1092 | tmp_ptr = end_ptr + 1; |
| 1093 | break; |
| 1094 | } else { |
| 1095 | esc_flg = TRUE; |
| 1096 | esc_ptr += 2; |
| 1097 | } |
| 1098 | } |
| 1099 | } |
| 1100 | } else |
| 1101 | DBUG_RETURN(NULL); |
| 1102 | |
| 1103 | *end_ptr = '\0'; |
| 1104 | if (esc_flg) |
| 1105 | { |
| 1106 | esc_ptr = start_ptr; |
| 1107 | while (TRUE) |
| 1108 | { |
| 1109 | esc_ptr = strchr(esc_ptr, '\\'); |
| 1110 | if (!esc_ptr) |
| 1111 | break; |
| 1112 | switch(*(esc_ptr + 1)) |
| 1113 | { |
| 1114 | case 'b': |
| 1115 | *esc_ptr = '\b'; |
| 1116 | break; |
| 1117 | case 'n': |
| 1118 | *esc_ptr = '\n'; |
| 1119 | break; |
| 1120 | case 'r': |
| 1121 | *esc_ptr = '\r'; |
| 1122 | break; |
| 1123 | case 't': |
| 1124 | *esc_ptr = '\t'; |
| 1125 | break; |
| 1126 | default: |
| 1127 | *esc_ptr = *(esc_ptr + 1); |
| 1128 | break; |
| 1129 | } |
| 1130 | esc_ptr++; |
| 1131 | strcpy(esc_ptr, esc_ptr + 1); |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | if (param_string_parse) |
| 1136 | param_string_parse->set_param_value(start_ptr, start_ptr + strlen(start_ptr) + 1); |
| 1137 | |
| 1138 | if (alloc) |
| 1139 | { |
| 1140 | DBUG_RETURN( |
| 1141 | spider_create_string( |
| 1142 | start_ptr, |
| 1143 | strlen(start_ptr)) |
| 1144 | ); |
| 1145 | } else { |
| 1146 | DBUG_RETURN(start_ptr); |
| 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | int spider_create_string_list( |
| 1151 | char ***string_list, |
| 1152 | uint **string_length_list, |
| 1153 | uint *list_length, |
| 1154 | char *str, |
| 1155 | uint length, |
| 1156 | SPIDER_PARAM_STRING_PARSE *param_string_parse |
| 1157 | ) { |
| 1158 | int roop_count; |
| 1159 | char *tmp_ptr, *tmp_ptr2, *tmp_ptr3, *esc_ptr; |
| 1160 | bool find_flg = FALSE; |
| 1161 | DBUG_ENTER("spider_create_string_list" ); |
| 1162 | |
| 1163 | *list_length = 0; |
| 1164 | param_string_parse->init_param_value(); |
| 1165 | if (!str) |
| 1166 | { |
| 1167 | *string_list = NULL; |
| 1168 | DBUG_RETURN(0); |
| 1169 | } |
| 1170 | |
| 1171 | tmp_ptr = str; |
| 1172 | while (*tmp_ptr == ' ') |
| 1173 | tmp_ptr++; |
| 1174 | if (*tmp_ptr) |
| 1175 | *list_length = 1; |
| 1176 | else { |
| 1177 | *string_list = NULL; |
| 1178 | DBUG_RETURN(0); |
| 1179 | } |
| 1180 | |
| 1181 | while (TRUE) |
| 1182 | { |
| 1183 | if ((tmp_ptr2 = strchr(tmp_ptr, ' '))) |
| 1184 | { |
| 1185 | esc_ptr = tmp_ptr; |
| 1186 | while (!find_flg) |
| 1187 | { |
| 1188 | esc_ptr = strchr(esc_ptr, '\\'); |
| 1189 | if (!esc_ptr || esc_ptr > tmp_ptr2) |
| 1190 | find_flg = TRUE; |
| 1191 | else if (esc_ptr == tmp_ptr2 - 1) |
| 1192 | { |
| 1193 | tmp_ptr = tmp_ptr2 + 1; |
| 1194 | break; |
| 1195 | } else |
| 1196 | esc_ptr += 2; |
| 1197 | } |
| 1198 | if (find_flg) |
| 1199 | { |
| 1200 | (*list_length)++; |
| 1201 | tmp_ptr = tmp_ptr2 + 1; |
| 1202 | while (*tmp_ptr == ' ') |
| 1203 | tmp_ptr++; |
| 1204 | } |
| 1205 | } else |
| 1206 | break; |
| 1207 | } |
| 1208 | |
| 1209 | if (!(*string_list = (char**) |
| 1210 | spider_bulk_malloc(spider_current_trx, 37, MYF(MY_WME | MY_ZEROFILL), |
| 1211 | string_list, sizeof(char*) * (*list_length), |
| 1212 | string_length_list, sizeof(int) * (*list_length), |
| 1213 | NullS)) |
| 1214 | ) { |
| 1215 | my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); |
| 1216 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 1217 | } |
| 1218 | |
| 1219 | tmp_ptr = str; |
| 1220 | while (*tmp_ptr == ' ') |
| 1221 | { |
| 1222 | *tmp_ptr = '\0'; |
| 1223 | tmp_ptr++; |
| 1224 | } |
| 1225 | tmp_ptr3 = tmp_ptr; |
| 1226 | |
| 1227 | for (roop_count = 0; roop_count < (int) *list_length - 1; roop_count++) |
| 1228 | { |
| 1229 | while (TRUE) |
| 1230 | { |
| 1231 | tmp_ptr2 = strchr(tmp_ptr, ' '); |
| 1232 | |
| 1233 | esc_ptr = tmp_ptr; |
| 1234 | while (!find_flg) |
| 1235 | { |
| 1236 | esc_ptr = strchr(esc_ptr, '\\'); |
| 1237 | if (!esc_ptr || esc_ptr > tmp_ptr2) |
| 1238 | find_flg = TRUE; |
| 1239 | else if (esc_ptr == tmp_ptr2 - 1) |
| 1240 | { |
| 1241 | tmp_ptr = tmp_ptr2 + 1; |
| 1242 | break; |
| 1243 | } else |
| 1244 | esc_ptr += 2; |
| 1245 | } |
| 1246 | if (find_flg) |
| 1247 | break; |
| 1248 | } |
| 1249 | tmp_ptr = tmp_ptr2; |
| 1250 | |
| 1251 | while (*tmp_ptr == ' ') |
| 1252 | { |
| 1253 | *tmp_ptr = '\0'; |
| 1254 | tmp_ptr++; |
| 1255 | } |
| 1256 | |
| 1257 | (*string_length_list)[roop_count] = strlen(tmp_ptr3); |
| 1258 | if (!((*string_list)[roop_count] = spider_create_string( |
| 1259 | tmp_ptr3, (*string_length_list)[roop_count])) |
| 1260 | ) { |
| 1261 | my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); |
| 1262 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 1263 | } |
| 1264 | DBUG_PRINT("info" ,("spider string_list[%d]=%s" , roop_count, |
| 1265 | (*string_list)[roop_count])); |
| 1266 | tmp_ptr3 = tmp_ptr; |
| 1267 | } |
| 1268 | (*string_length_list)[roop_count] = strlen(tmp_ptr3); |
| 1269 | if (!((*string_list)[roop_count] = spider_create_string( |
| 1270 | tmp_ptr3, (*string_length_list)[roop_count])) |
| 1271 | ) { |
| 1272 | my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); |
| 1273 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 1274 | } |
| 1275 | |
| 1276 | param_string_parse->set_param_value(tmp_ptr3, |
| 1277 | tmp_ptr3 + strlen(tmp_ptr3) + 1); |
| 1278 | |
| 1279 | DBUG_PRINT("info" ,("spider string_list[%d]=%s" , roop_count, |
| 1280 | (*string_list)[roop_count])); |
| 1281 | |
| 1282 | DBUG_RETURN(0); |
| 1283 | } |
| 1284 | |
| 1285 | int spider_create_long_list( |
| 1286 | long **long_list, |
| 1287 | uint *list_length, |
| 1288 | char *str, |
| 1289 | uint length, |
| 1290 | long min_val, |
| 1291 | long max_val, |
| 1292 | SPIDER_PARAM_STRING_PARSE *param_string_parse |
| 1293 | ) { |
| 1294 | int roop_count; |
| 1295 | char *tmp_ptr; |
| 1296 | DBUG_ENTER("spider_create_long_list" ); |
| 1297 | |
| 1298 | *list_length = 0; |
| 1299 | param_string_parse->init_param_value(); |
| 1300 | if (!str) |
| 1301 | { |
| 1302 | *long_list = NULL; |
| 1303 | DBUG_RETURN(0); |
| 1304 | } |
| 1305 | |
| 1306 | tmp_ptr = str; |
| 1307 | while (*tmp_ptr == ' ') |
| 1308 | tmp_ptr++; |
| 1309 | if (*tmp_ptr) |
| 1310 | *list_length = 1; |
| 1311 | else { |
| 1312 | *long_list = NULL; |
| 1313 | DBUG_RETURN(0); |
| 1314 | } |
| 1315 | |
| 1316 | while (TRUE) |
| 1317 | { |
| 1318 | if ((tmp_ptr = strchr(tmp_ptr, ' '))) |
| 1319 | { |
| 1320 | (*list_length)++; |
| 1321 | tmp_ptr = tmp_ptr + 1; |
| 1322 | while (*tmp_ptr == ' ') |
| 1323 | tmp_ptr++; |
| 1324 | } else |
| 1325 | break; |
| 1326 | } |
| 1327 | |
| 1328 | if (!(*long_list = (long*) |
| 1329 | spider_bulk_malloc(spider_current_trx, 38, MYF(MY_WME | MY_ZEROFILL), |
| 1330 | long_list, sizeof(long) * (*list_length), |
| 1331 | NullS)) |
| 1332 | ) { |
| 1333 | my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); |
| 1334 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 1335 | } |
| 1336 | |
| 1337 | tmp_ptr = str; |
| 1338 | for (roop_count = 0; roop_count < (int) *list_length; roop_count++) |
| 1339 | { |
| 1340 | if (roop_count != 0) |
| 1341 | tmp_ptr = strchr(tmp_ptr, ' '); |
| 1342 | |
| 1343 | while (*tmp_ptr == ' ') |
| 1344 | { |
| 1345 | *tmp_ptr = '\0'; |
| 1346 | tmp_ptr++; |
| 1347 | } |
| 1348 | (*long_list)[roop_count] = atol(tmp_ptr); |
| 1349 | if ((*long_list)[roop_count] < min_val) |
| 1350 | (*long_list)[roop_count] = min_val; |
| 1351 | else if ((*long_list)[roop_count] > max_val) |
| 1352 | (*long_list)[roop_count] = max_val; |
| 1353 | } |
| 1354 | |
| 1355 | param_string_parse->set_param_value(tmp_ptr, |
| 1356 | tmp_ptr + strlen(tmp_ptr) + 1); |
| 1357 | |
| 1358 | #ifndef DBUG_OFF |
| 1359 | for (roop_count = 0; roop_count < (int) *list_length; roop_count++) |
| 1360 | { |
| 1361 | DBUG_PRINT("info" ,("spider long_list[%d]=%ld" , roop_count, |
| 1362 | (*long_list)[roop_count])); |
| 1363 | } |
| 1364 | #endif |
| 1365 | |
| 1366 | DBUG_RETURN(0); |
| 1367 | } |
| 1368 | |
| 1369 | int spider_create_longlong_list( |
| 1370 | longlong **longlong_list, |
| 1371 | uint *list_length, |
| 1372 | char *str, |
| 1373 | uint length, |
| 1374 | longlong min_val, |
| 1375 | longlong max_val, |
| 1376 | SPIDER_PARAM_STRING_PARSE *param_string_parse |
| 1377 | ) { |
| 1378 | int error_num, roop_count; |
| 1379 | char *tmp_ptr; |
| 1380 | DBUG_ENTER("spider_create_longlong_list" ); |
| 1381 | |
| 1382 | *list_length = 0; |
| 1383 | param_string_parse->init_param_value(); |
| 1384 | if (!str) |
| 1385 | { |
| 1386 | *longlong_list = NULL; |
| 1387 | DBUG_RETURN(0); |
| 1388 | } |
| 1389 | |
| 1390 | tmp_ptr = str; |
| 1391 | while (*tmp_ptr == ' ') |
| 1392 | tmp_ptr++; |
| 1393 | if (*tmp_ptr) |
| 1394 | *list_length = 1; |
| 1395 | else { |
| 1396 | *longlong_list = NULL; |
| 1397 | DBUG_RETURN(0); |
| 1398 | } |
| 1399 | |
| 1400 | while (TRUE) |
| 1401 | { |
| 1402 | if ((tmp_ptr = strchr(tmp_ptr, ' '))) |
| 1403 | { |
| 1404 | (*list_length)++; |
| 1405 | tmp_ptr = tmp_ptr + 1; |
| 1406 | while (*tmp_ptr == ' ') |
| 1407 | tmp_ptr++; |
| 1408 | } else |
| 1409 | break; |
| 1410 | } |
| 1411 | |
| 1412 | if (!(*longlong_list = (longlong *) |
| 1413 | spider_bulk_malloc(spider_current_trx, 39, MYF(MY_WME | MY_ZEROFILL), |
| 1414 | longlong_list, sizeof(longlong) * (*list_length), |
| 1415 | NullS)) |
| 1416 | ) { |
| 1417 | my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); |
| 1418 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 1419 | } |
| 1420 | |
| 1421 | tmp_ptr = str; |
| 1422 | for (roop_count = 0; roop_count < (int) *list_length; roop_count++) |
| 1423 | { |
| 1424 | if (roop_count != 0) |
| 1425 | tmp_ptr = strchr(tmp_ptr, ' '); |
| 1426 | |
| 1427 | while (*tmp_ptr == ' ') |
| 1428 | { |
| 1429 | *tmp_ptr = '\0'; |
| 1430 | tmp_ptr++; |
| 1431 | } |
| 1432 | (*longlong_list)[roop_count] = my_strtoll10(tmp_ptr, (char**) NULL, |
| 1433 | &error_num); |
| 1434 | if ((*longlong_list)[roop_count] < min_val) |
| 1435 | (*longlong_list)[roop_count] = min_val; |
| 1436 | else if ((*longlong_list)[roop_count] > max_val) |
| 1437 | (*longlong_list)[roop_count] = max_val; |
| 1438 | } |
| 1439 | |
| 1440 | param_string_parse->set_param_value(tmp_ptr, |
| 1441 | tmp_ptr + strlen(tmp_ptr) + 1); |
| 1442 | |
| 1443 | #ifndef DBUG_OFF |
| 1444 | for (roop_count = 0; roop_count < (int) *list_length; roop_count++) |
| 1445 | { |
| 1446 | DBUG_PRINT("info" ,("spider longlong_list[%d]=%lld" , roop_count, |
| 1447 | (*longlong_list)[roop_count])); |
| 1448 | } |
| 1449 | #endif |
| 1450 | |
| 1451 | DBUG_RETURN(0); |
| 1452 | } |
| 1453 | |
| 1454 | int spider_increase_string_list( |
| 1455 | char ***string_list, |
| 1456 | uint **string_length_list, |
| 1457 | uint *list_length, |
| 1458 | uint *list_charlen, |
| 1459 | uint link_count |
| 1460 | ) { |
| 1461 | int roop_count; |
| 1462 | char **tmp_str_list, *tmp_str; |
| 1463 | uint *tmp_length_list, tmp_length; |
| 1464 | DBUG_ENTER("spider_increase_string_list" ); |
| 1465 | if (*list_length == link_count) |
| 1466 | DBUG_RETURN(0); |
| 1467 | if (*list_length > 1) |
| 1468 | { |
| 1469 | my_printf_error(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM, |
| 1470 | ER_SPIDER_DIFFERENT_LINK_COUNT_STR, MYF(0)); |
| 1471 | DBUG_RETURN(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM); |
| 1472 | } |
| 1473 | |
| 1474 | if (*string_list) |
| 1475 | { |
| 1476 | tmp_str = (*string_list)[0]; |
| 1477 | tmp_length = (*string_length_list)[0]; |
| 1478 | } else { |
| 1479 | tmp_str = NULL; |
| 1480 | tmp_length = 0; |
| 1481 | } |
| 1482 | |
| 1483 | if (!(tmp_str_list = (char**) |
| 1484 | spider_bulk_malloc(spider_current_trx, 40, MYF(MY_WME | MY_ZEROFILL), |
| 1485 | &tmp_str_list, sizeof(char*) * link_count, |
| 1486 | &tmp_length_list, sizeof(uint) * link_count, |
| 1487 | NullS)) |
| 1488 | ) { |
| 1489 | my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); |
| 1490 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 1491 | } |
| 1492 | |
| 1493 | for (roop_count = 0; roop_count < (int) link_count; roop_count++) |
| 1494 | { |
| 1495 | tmp_length_list[roop_count] = tmp_length; |
| 1496 | if (tmp_str) |
| 1497 | { |
| 1498 | if (!(tmp_str_list[roop_count] = spider_create_string( |
| 1499 | tmp_str, tmp_length)) |
| 1500 | ) |
| 1501 | goto error; |
| 1502 | DBUG_PRINT("info" ,("spider string_list[%d]=%s" , roop_count, |
| 1503 | tmp_str_list[roop_count])); |
| 1504 | } else |
| 1505 | tmp_str_list[roop_count] = NULL; |
| 1506 | } |
| 1507 | if (*string_list) |
| 1508 | { |
| 1509 | if ((*string_list)[0]) |
| 1510 | spider_free(spider_current_trx, (*string_list)[0], MYF(0)); |
| 1511 | spider_free(spider_current_trx, *string_list, MYF(0)); |
| 1512 | } |
| 1513 | *list_charlen = (tmp_length + 1) * link_count - 1; |
| 1514 | *list_length = link_count; |
| 1515 | *string_list = tmp_str_list; |
| 1516 | *string_length_list = tmp_length_list; |
| 1517 | |
| 1518 | DBUG_RETURN(0); |
| 1519 | |
| 1520 | error: |
| 1521 | for (roop_count = 0; roop_count < (int) link_count; roop_count++) |
| 1522 | { |
| 1523 | if (tmp_str_list[roop_count]) |
| 1524 | spider_free(spider_current_trx, tmp_str_list[roop_count], MYF(0)); |
| 1525 | } |
| 1526 | if (tmp_str_list) |
| 1527 | spider_free(spider_current_trx, tmp_str_list, MYF(0)); |
| 1528 | my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); |
| 1529 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 1530 | } |
| 1531 | |
| 1532 | int spider_increase_null_string_list( |
| 1533 | char ***string_list, |
| 1534 | uint **string_length_list, |
| 1535 | uint *list_length, |
| 1536 | uint *list_charlen, |
| 1537 | uint link_count |
| 1538 | ) { |
| 1539 | int roop_count; |
| 1540 | char **tmp_str_list; |
| 1541 | uint *tmp_length_list; |
| 1542 | DBUG_ENTER("spider_increase_null_string_list" ); |
| 1543 | if (*list_length == link_count) |
| 1544 | DBUG_RETURN(0); |
| 1545 | |
| 1546 | if (!(tmp_str_list = (char**) |
| 1547 | spider_bulk_malloc(spider_current_trx, 247, MYF(MY_WME | MY_ZEROFILL), |
| 1548 | &tmp_str_list, sizeof(char*) * link_count, |
| 1549 | &tmp_length_list, sizeof(uint) * link_count, |
| 1550 | NullS)) |
| 1551 | ) { |
| 1552 | my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); |
| 1553 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 1554 | } |
| 1555 | |
| 1556 | for (roop_count = 0; roop_count < (int) *list_length; roop_count++) |
| 1557 | { |
| 1558 | tmp_str_list[roop_count] = (*string_list)[roop_count]; |
| 1559 | tmp_length_list[roop_count] = (*string_length_list)[roop_count]; |
| 1560 | } |
| 1561 | if (*string_list) |
| 1562 | { |
| 1563 | spider_free(spider_current_trx, *string_list, MYF(0)); |
| 1564 | } |
| 1565 | *list_length = link_count; |
| 1566 | *string_list = tmp_str_list; |
| 1567 | *string_length_list = tmp_length_list; |
| 1568 | #ifndef DBUG_OFF |
| 1569 | DBUG_PRINT("info" ,("spider list_length=%u" , *list_length)); |
| 1570 | for (roop_count = 0; roop_count < (int) *list_length; roop_count++) |
| 1571 | { |
| 1572 | DBUG_PRINT("info" ,("spider string_list[%d]=%s" , roop_count, |
| 1573 | (*string_list)[roop_count] ? (*string_list)[roop_count] : "NULL" )); |
| 1574 | DBUG_PRINT("info" ,("spider string_length_list[%d]=%u" , roop_count, |
| 1575 | (*string_length_list)[roop_count])); |
| 1576 | } |
| 1577 | #endif |
| 1578 | |
| 1579 | DBUG_RETURN(0); |
| 1580 | } |
| 1581 | |
| 1582 | int spider_increase_long_list( |
| 1583 | long **long_list, |
| 1584 | uint *list_length, |
| 1585 | uint link_count |
| 1586 | ) { |
| 1587 | int roop_count; |
| 1588 | long *tmp_long_list, tmp_long; |
| 1589 | DBUG_ENTER("spider_increase_long_list" ); |
| 1590 | if (*list_length == link_count) |
| 1591 | DBUG_RETURN(0); |
| 1592 | if (*list_length > 1) |
| 1593 | { |
| 1594 | my_printf_error(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM, |
| 1595 | ER_SPIDER_DIFFERENT_LINK_COUNT_STR, MYF(0)); |
| 1596 | DBUG_RETURN(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM); |
| 1597 | } |
| 1598 | |
| 1599 | if (*long_list) |
| 1600 | tmp_long = (*long_list)[0]; |
| 1601 | else |
| 1602 | tmp_long = -1; |
| 1603 | |
| 1604 | if (!(tmp_long_list = (long*) |
| 1605 | spider_bulk_malloc(spider_current_trx, 41, MYF(MY_WME | MY_ZEROFILL), |
| 1606 | &tmp_long_list, sizeof(long) * link_count, |
| 1607 | NullS)) |
| 1608 | ) { |
| 1609 | my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); |
| 1610 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 1611 | } |
| 1612 | |
| 1613 | for (roop_count = 0; roop_count < (int) link_count; roop_count++) |
| 1614 | { |
| 1615 | tmp_long_list[roop_count] = tmp_long; |
| 1616 | DBUG_PRINT("info" ,("spider long_list[%d]=%ld" , roop_count, |
| 1617 | tmp_long)); |
| 1618 | } |
| 1619 | if (*long_list) |
| 1620 | spider_free(spider_current_trx, *long_list, MYF(0)); |
| 1621 | *list_length = link_count; |
| 1622 | *long_list = tmp_long_list; |
| 1623 | |
| 1624 | DBUG_RETURN(0); |
| 1625 | } |
| 1626 | |
| 1627 | int spider_increase_longlong_list( |
| 1628 | longlong **longlong_list, |
| 1629 | uint *list_length, |
| 1630 | uint link_count |
| 1631 | ) { |
| 1632 | int roop_count; |
| 1633 | longlong *tmp_longlong_list, tmp_longlong; |
| 1634 | DBUG_ENTER("spider_increase_longlong_list" ); |
| 1635 | if (*list_length == link_count) |
| 1636 | DBUG_RETURN(0); |
| 1637 | if (*list_length > 1) |
| 1638 | { |
| 1639 | my_printf_error(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM, |
| 1640 | ER_SPIDER_DIFFERENT_LINK_COUNT_STR, MYF(0)); |
| 1641 | DBUG_RETURN(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM); |
| 1642 | } |
| 1643 | |
| 1644 | if (*longlong_list) |
| 1645 | tmp_longlong = (*longlong_list)[0]; |
| 1646 | else |
| 1647 | tmp_longlong = -1; |
| 1648 | |
| 1649 | if (!(tmp_longlong_list = (longlong*) |
| 1650 | spider_bulk_malloc(spider_current_trx, 42, MYF(MY_WME | MY_ZEROFILL), |
| 1651 | &tmp_longlong_list, sizeof(longlong) * link_count, |
| 1652 | NullS)) |
| 1653 | ) { |
| 1654 | my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); |
| 1655 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 1656 | } |
| 1657 | |
| 1658 | for (roop_count = 0; roop_count < (int) link_count; roop_count++) |
| 1659 | { |
| 1660 | tmp_longlong_list[roop_count] = tmp_longlong; |
| 1661 | DBUG_PRINT("info" ,("spider longlong_list[%d]=%lld" , roop_count, |
| 1662 | tmp_longlong)); |
| 1663 | } |
| 1664 | if (*longlong_list) |
| 1665 | spider_free(spider_current_trx, *longlong_list, MYF(0)); |
| 1666 | *list_length = link_count; |
| 1667 | *longlong_list = tmp_longlong_list; |
| 1668 | |
| 1669 | DBUG_RETURN(0); |
| 1670 | } |
| 1671 | |
| 1672 | static int spider_set_ll_value( |
| 1673 | longlong *value, |
| 1674 | char *str |
| 1675 | ) { |
| 1676 | int error_num = 0; |
| 1677 | DBUG_ENTER("spider_set_ll_value" ); |
| 1678 | *value = my_strtoll10(str, (char**) NULL, &error_num); |
| 1679 | DBUG_RETURN(error_num); |
| 1680 | } |
| 1681 | |
| 1682 | /** |
| 1683 | Print a parameter string error message. |
| 1684 | |
| 1685 | @return Error code. |
| 1686 | */ |
| 1687 | |
| 1688 | int st_spider_param_string_parse::print_param_error() |
| 1689 | { |
| 1690 | if (start_title_ptr) |
| 1691 | { |
| 1692 | /* Restore the input delimiter characters */ |
| 1693 | restore_delims(); |
| 1694 | |
| 1695 | /* Print the error message */ |
| 1696 | switch (error_num) |
| 1697 | { |
| 1698 | case ER_SPIDER_INVALID_UDF_PARAM_NUM: |
| 1699 | my_printf_error(error_num, ER_SPIDER_INVALID_UDF_PARAM_STR, |
| 1700 | MYF(0), start_title_ptr); |
| 1701 | break; |
| 1702 | case ER_SPIDER_INVALID_CONNECT_INFO_NUM: |
| 1703 | default: |
| 1704 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, |
| 1705 | MYF(0), start_title_ptr); |
| 1706 | } |
| 1707 | |
| 1708 | return error_num; |
| 1709 | } |
| 1710 | else |
| 1711 | return 0; |
| 1712 | } |
| 1713 | |
| 1714 | #define SPIDER_PARAM_STR_LEN(name) name ## _length |
| 1715 | #define SPIDER_PARAM_STR(title_name, param_name) \ |
| 1716 | if (!strncasecmp(tmp_ptr, title_name, title_length)) \ |
| 1717 | { \ |
| 1718 | DBUG_PRINT("info",("spider " title_name " start")); \ |
| 1719 | if (!share->param_name) \ |
| 1720 | { \ |
| 1721 | if ((share->param_name = spider_get_string_between_quote( \ |
| 1722 | start_ptr, TRUE, &connect_string_parse))) \ |
| 1723 | share->SPIDER_PARAM_STR_LEN(param_name) = strlen(share->param_name); \ |
| 1724 | else \ |
| 1725 | { \ |
| 1726 | error_num = connect_string_parse.print_param_error(); \ |
| 1727 | goto error; \ |
| 1728 | } \ |
| 1729 | DBUG_PRINT("info",("spider " title_name "=%s", share->param_name)); \ |
| 1730 | } \ |
| 1731 | break; \ |
| 1732 | } |
| 1733 | #define SPIDER_PARAM_STR_LENS(name) name ## _lengths |
| 1734 | #define SPIDER_PARAM_STR_CHARLEN(name) name ## _charlen |
| 1735 | #define SPIDER_PARAM_STR_LIST(title_name, param_name) \ |
| 1736 | if (!strncasecmp(tmp_ptr, title_name, title_length)) \ |
| 1737 | { \ |
| 1738 | DBUG_PRINT("info",("spider " title_name " start")); \ |
| 1739 | if (!share->param_name) \ |
| 1740 | { \ |
| 1741 | if ((tmp_ptr2 = spider_get_string_between_quote( \ |
| 1742 | start_ptr, FALSE))) \ |
| 1743 | { \ |
| 1744 | share->SPIDER_PARAM_STR_CHARLEN(param_name) = strlen(tmp_ptr2); \ |
| 1745 | if ((error_num = spider_create_string_list( \ |
| 1746 | &share->param_name, \ |
| 1747 | &share->SPIDER_PARAM_STR_LENS(param_name), \ |
| 1748 | &share->SPIDER_PARAM_STR_LEN(param_name), \ |
| 1749 | tmp_ptr2, \ |
| 1750 | share->SPIDER_PARAM_STR_CHARLEN(param_name), \ |
| 1751 | &connect_string_parse))) \ |
| 1752 | goto error; \ |
| 1753 | } else { \ |
| 1754 | error_num = connect_string_parse.print_param_error(); \ |
| 1755 | goto error; \ |
| 1756 | } \ |
| 1757 | } \ |
| 1758 | break; \ |
| 1759 | } |
| 1760 | #define SPIDER_PARAM_HINT(title_name, param_name, check_length, max_size, append_method) \ |
| 1761 | if (!strncasecmp(tmp_ptr, title_name, check_length)) \ |
| 1762 | { \ |
| 1763 | DBUG_PRINT("info",("spider " title_name " start")); \ |
| 1764 | DBUG_PRINT("info",("spider max_size=%d", max_size)); \ |
| 1765 | int hint_num = atoi(tmp_ptr + check_length); \ |
| 1766 | DBUG_PRINT("info",("spider hint_num=%d", hint_num)); \ |
| 1767 | DBUG_PRINT("info",("spider share->param_name=%p", share->param_name)); \ |
| 1768 | if (share->param_name) \ |
| 1769 | { \ |
| 1770 | if (hint_num < 0 || hint_num >= max_size) \ |
| 1771 | { \ |
| 1772 | error_num = connect_string_parse.print_param_error(); \ |
| 1773 | goto error; \ |
| 1774 | } else if (share->param_name[hint_num].length() > 0) \ |
| 1775 | break; \ |
| 1776 | char *hint_str = spider_get_string_between_quote(start_ptr, FALSE); \ |
| 1777 | if ((error_num = \ |
| 1778 | append_method(&share->param_name[hint_num], hint_str))) \ |
| 1779 | goto error; \ |
| 1780 | DBUG_PRINT("info",("spider " title_name "[%d]=%s", hint_num, \ |
| 1781 | share->param_name[hint_num].ptr())); \ |
| 1782 | } else { \ |
| 1783 | error_num = connect_string_parse.print_param_error(); \ |
| 1784 | goto error; \ |
| 1785 | } \ |
| 1786 | break; \ |
| 1787 | } |
| 1788 | #define SPIDER_PARAM_NUMHINT(title_name, param_name, check_length, max_size, append_method) \ |
| 1789 | if (!strncasecmp(tmp_ptr, title_name, check_length)) \ |
| 1790 | { \ |
| 1791 | DBUG_PRINT("info",("spider " title_name " start")); \ |
| 1792 | DBUG_PRINT("info",("spider max_size=%d", max_size)); \ |
| 1793 | int hint_num = atoi(tmp_ptr + check_length); \ |
| 1794 | DBUG_PRINT("info",("spider hint_num=%d", hint_num)); \ |
| 1795 | DBUG_PRINT("info",("spider share->param_name=%p", share->param_name)); \ |
| 1796 | if (share->param_name) \ |
| 1797 | { \ |
| 1798 | if (hint_num < 0 || hint_num >= max_size) \ |
| 1799 | { \ |
| 1800 | error_num = connect_string_parse.print_param_error(); \ |
| 1801 | goto error; \ |
| 1802 | } else if (share->param_name[hint_num] != -1) \ |
| 1803 | break; \ |
| 1804 | char *hint_str = spider_get_string_between_quote(start_ptr, FALSE); \ |
| 1805 | if ((error_num = \ |
| 1806 | append_method(&share->param_name[hint_num], hint_str))) \ |
| 1807 | goto error; \ |
| 1808 | DBUG_PRINT("info",("spider " title_name "[%d]=%lld", hint_num, \ |
| 1809 | share->param_name[hint_num])); \ |
| 1810 | } else { \ |
| 1811 | error_num = connect_string_parse.print_param_error(); \ |
| 1812 | goto error; \ |
| 1813 | } \ |
| 1814 | break; \ |
| 1815 | } |
| 1816 | #define SPIDER_PARAM_LONG_LEN(name) name ## _length |
| 1817 | #define SPIDER_PARAM_LONG_LIST_WITH_MAX(title_name, param_name, \ |
| 1818 | min_val, max_val) \ |
| 1819 | if (!strncasecmp(tmp_ptr, title_name, title_length)) \ |
| 1820 | { \ |
| 1821 | DBUG_PRINT("info",("spider " title_name " start")); \ |
| 1822 | if (!share->param_name) \ |
| 1823 | { \ |
| 1824 | if ((tmp_ptr2 = spider_get_string_between_quote( \ |
| 1825 | start_ptr, FALSE))) \ |
| 1826 | { \ |
| 1827 | if ((error_num = spider_create_long_list( \ |
| 1828 | &share->param_name, \ |
| 1829 | &share->SPIDER_PARAM_LONG_LEN(param_name), \ |
| 1830 | tmp_ptr2, \ |
| 1831 | strlen(tmp_ptr2), \ |
| 1832 | min_val, max_val, \ |
| 1833 | &connect_string_parse))) \ |
| 1834 | goto error; \ |
| 1835 | } else { \ |
| 1836 | error_num = connect_string_parse.print_param_error(); \ |
| 1837 | goto error; \ |
| 1838 | } \ |
| 1839 | } \ |
| 1840 | break; \ |
| 1841 | } |
| 1842 | #define SPIDER_PARAM_LONGLONG_LEN(name) name ## _length |
| 1843 | #define SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(title_name, param_name, \ |
| 1844 | min_val, max_val) \ |
| 1845 | if (!strncasecmp(tmp_ptr, title_name, title_length)) \ |
| 1846 | { \ |
| 1847 | DBUG_PRINT("info",("spider " title_name " start")); \ |
| 1848 | if (!share->param_name) \ |
| 1849 | { \ |
| 1850 | if ((tmp_ptr2 = spider_get_string_between_quote( \ |
| 1851 | start_ptr, FALSE))) \ |
| 1852 | { \ |
| 1853 | if ((error_num = spider_create_longlong_list( \ |
| 1854 | &share->param_name, \ |
| 1855 | &share->SPIDER_PARAM_LONGLONG_LEN(param_name), \ |
| 1856 | tmp_ptr2, \ |
| 1857 | strlen(tmp_ptr2), \ |
| 1858 | min_val, max_val, \ |
| 1859 | &connect_string_parse))) \ |
| 1860 | goto error; \ |
| 1861 | } else { \ |
| 1862 | error_num = connect_string_parse.print_param_error(); \ |
| 1863 | goto error; \ |
| 1864 | } \ |
| 1865 | } \ |
| 1866 | break; \ |
| 1867 | } |
| 1868 | #define SPIDER_PARAM_INT_WITH_MAX(title_name, param_name, min_val, max_val) \ |
| 1869 | if (!strncasecmp(tmp_ptr, title_name, title_length)) \ |
| 1870 | { \ |
| 1871 | DBUG_PRINT("info",("spider " title_name " start")); \ |
| 1872 | if (share->param_name == -1) \ |
| 1873 | { \ |
| 1874 | if ((tmp_ptr2 = spider_get_string_between_quote( \ |
| 1875 | start_ptr, FALSE))) \ |
| 1876 | { \ |
| 1877 | share->param_name = atoi(tmp_ptr2); \ |
| 1878 | if (share->param_name < min_val) \ |
| 1879 | share->param_name = min_val; \ |
| 1880 | else if (share->param_name > max_val) \ |
| 1881 | share->param_name = max_val; \ |
| 1882 | connect_string_parse.set_param_value(tmp_ptr2, \ |
| 1883 | tmp_ptr2 + \ |
| 1884 | strlen(tmp_ptr2) + 1); \ |
| 1885 | } else { \ |
| 1886 | error_num = connect_string_parse.print_param_error(); \ |
| 1887 | goto error; \ |
| 1888 | } \ |
| 1889 | DBUG_PRINT("info",("spider " title_name "=%d", share->param_name)); \ |
| 1890 | } \ |
| 1891 | break; \ |
| 1892 | } |
| 1893 | #define SPIDER_PARAM_INT(title_name, param_name, min_val) \ |
| 1894 | if (!strncasecmp(tmp_ptr, title_name, title_length)) \ |
| 1895 | { \ |
| 1896 | DBUG_PRINT("info",("spider " title_name " start")); \ |
| 1897 | if (share->param_name == -1) \ |
| 1898 | { \ |
| 1899 | if ((tmp_ptr2 = spider_get_string_between_quote( \ |
| 1900 | start_ptr, FALSE))) \ |
| 1901 | { \ |
| 1902 | share->param_name = atoi(tmp_ptr2); \ |
| 1903 | if (share->param_name < min_val) \ |
| 1904 | share->param_name = min_val; \ |
| 1905 | connect_string_parse.set_param_value(tmp_ptr2, \ |
| 1906 | tmp_ptr2 + \ |
| 1907 | strlen(tmp_ptr2) + 1); \ |
| 1908 | } else { \ |
| 1909 | error_num = connect_string_parse.print_param_error(); \ |
| 1910 | goto error; \ |
| 1911 | } \ |
| 1912 | DBUG_PRINT("info",("spider " title_name "=%d", share->param_name)); \ |
| 1913 | } \ |
| 1914 | break; \ |
| 1915 | } |
| 1916 | #define SPIDER_PARAM_DOUBLE(title_name, param_name, min_val) \ |
| 1917 | if (!strncasecmp(tmp_ptr, title_name, title_length)) \ |
| 1918 | { \ |
| 1919 | DBUG_PRINT("info",("spider " title_name " start")); \ |
| 1920 | if (share->param_name == -1) \ |
| 1921 | { \ |
| 1922 | if ((tmp_ptr2 = spider_get_string_between_quote( \ |
| 1923 | start_ptr, FALSE))) \ |
| 1924 | { \ |
| 1925 | share->param_name = my_atof(tmp_ptr2); \ |
| 1926 | if (share->param_name < min_val) \ |
| 1927 | share->param_name = min_val; \ |
| 1928 | connect_string_parse.set_param_value(tmp_ptr2, \ |
| 1929 | tmp_ptr2 + \ |
| 1930 | strlen(tmp_ptr2) + 1); \ |
| 1931 | } else { \ |
| 1932 | error_num = connect_string_parse.print_param_error(); \ |
| 1933 | goto error; \ |
| 1934 | } \ |
| 1935 | DBUG_PRINT("info",("spider " title_name "=%f", share->param_name)); \ |
| 1936 | } \ |
| 1937 | break; \ |
| 1938 | } |
| 1939 | #define SPIDER_PARAM_LONGLONG(title_name, param_name, min_val) \ |
| 1940 | if (!strncasecmp(tmp_ptr, title_name, title_length)) \ |
| 1941 | { \ |
| 1942 | DBUG_PRINT("info",("spider " title_name " start")); \ |
| 1943 | if (share->param_name == -1) \ |
| 1944 | { \ |
| 1945 | if ((tmp_ptr2 = spider_get_string_between_quote( \ |
| 1946 | start_ptr, FALSE))) \ |
| 1947 | { \ |
| 1948 | share->param_name = my_strtoll10(tmp_ptr2, (char**) NULL, &error_num); \ |
| 1949 | if (share->param_name < min_val) \ |
| 1950 | share->param_name = min_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 "=%lld", share->param_name)); \ |
| 1959 | } \ |
| 1960 | break; \ |
| 1961 | } |
| 1962 | |
| 1963 | int spider_parse_connect_info( |
| 1964 | SPIDER_SHARE *share, |
| 1965 | TABLE_SHARE *table_share, |
| 1966 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 1967 | partition_info *part_info, |
| 1968 | #endif |
| 1969 | uint create_table |
| 1970 | ) { |
| 1971 | int error_num = 0; |
| 1972 | char *connect_string = NULL; |
| 1973 | char *sprit_ptr[2]; |
| 1974 | char *tmp_ptr, *tmp_ptr2, *start_ptr; |
| 1975 | int roop_count; |
| 1976 | int title_length; |
| 1977 | SPIDER_PARAM_STRING_PARSE connect_string_parse; |
| 1978 | SPIDER_ALTER_TABLE *share_alter; |
| 1979 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 1980 | partition_element *part_elem; |
| 1981 | partition_element *sub_elem; |
| 1982 | #endif |
| 1983 | DBUG_ENTER("spider_parse_connect_info" ); |
| 1984 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 1985 | #if MYSQL_VERSION_ID < 50500 |
| 1986 | DBUG_PRINT("info" ,("spider partition_info=%s" , table_share->partition_info)); |
| 1987 | #else |
| 1988 | DBUG_PRINT("info" ,("spider partition_info=%s" , |
| 1989 | table_share->partition_info_str)); |
| 1990 | #endif |
| 1991 | DBUG_PRINT("info" ,("spider part_info=%p" , part_info)); |
| 1992 | #endif |
| 1993 | DBUG_PRINT("info" ,("spider s->db=%s" , table_share->db.str)); |
| 1994 | DBUG_PRINT("info" ,("spider s->table_name=%s" , table_share->table_name.str)); |
| 1995 | DBUG_PRINT("info" ,("spider s->path=%s" , table_share->path.str)); |
| 1996 | DBUG_PRINT("info" , |
| 1997 | ("spider s->normalized_path=%s" , table_share->normalized_path.str)); |
| 1998 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 1999 | spider_get_partition_info(share->table_name, share->table_name_length, |
| 2000 | table_share, part_info, &part_elem, &sub_elem); |
| 2001 | #endif |
| 2002 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 2003 | share->sts_bg_mode = -1; |
| 2004 | #endif |
| 2005 | share->sts_interval = -1; |
| 2006 | share->sts_mode = -1; |
| 2007 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 2008 | share->sts_sync = -1; |
| 2009 | #endif |
| 2010 | share->store_last_sts = -1; |
| 2011 | share->load_sts_at_startup = -1; |
| 2012 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 2013 | share->crd_bg_mode = -1; |
| 2014 | #endif |
| 2015 | share->crd_interval = -1; |
| 2016 | share->crd_mode = -1; |
| 2017 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 2018 | share->crd_sync = -1; |
| 2019 | #endif |
| 2020 | share->store_last_crd = -1; |
| 2021 | share->load_crd_at_startup = -1; |
| 2022 | share->crd_type = -1; |
| 2023 | share->crd_weight = -1; |
| 2024 | share->internal_offset = -1; |
| 2025 | share->internal_limit = -1; |
| 2026 | share->split_read = -1; |
| 2027 | share->semi_split_read = -1; |
| 2028 | share->semi_split_read_limit = -1; |
| 2029 | share->init_sql_alloc_size = -1; |
| 2030 | share->reset_sql_alloc = -1; |
| 2031 | share->multi_split_read = -1; |
| 2032 | share->max_order = -1; |
| 2033 | share->semi_table_lock = -1; |
| 2034 | share->semi_table_lock_conn = -1; |
| 2035 | share->selupd_lock_mode = -1; |
| 2036 | share->query_cache = -1; |
| 2037 | share->query_cache_sync = -1; |
| 2038 | share->internal_delayed = -1; |
| 2039 | share->bulk_size = -1; |
| 2040 | share->bulk_update_mode = -1; |
| 2041 | share->bulk_update_size = -1; |
| 2042 | share->internal_optimize = -1; |
| 2043 | share->internal_optimize_local = -1; |
| 2044 | share->scan_rate = -1; |
| 2045 | share->read_rate = -1; |
| 2046 | share->priority = -1; |
| 2047 | share->quick_mode = -1; |
| 2048 | share->quick_page_size = -1; |
| 2049 | share->low_mem_read = -1; |
| 2050 | share->table_count_mode = -1; |
| 2051 | share->select_column_mode = -1; |
| 2052 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 2053 | share->bgs_mode = -1; |
| 2054 | share->bgs_first_read = -1; |
| 2055 | share->bgs_second_read = -1; |
| 2056 | #endif |
| 2057 | share->first_read = -1; |
| 2058 | share->second_read = -1; |
| 2059 | share->auto_increment_mode = -1; |
| 2060 | share->use_table_charset = -1; |
| 2061 | share->use_pushdown_udf = -1; |
| 2062 | share->skip_default_condition = -1; |
| 2063 | share->skip_parallel_search = -1; |
| 2064 | share->direct_dup_insert = -1; |
| 2065 | share->direct_order_limit = -1; |
| 2066 | share->bka_mode = -1; |
| 2067 | share->read_only_mode = -1; |
| 2068 | share->error_read_mode = -1; |
| 2069 | share->error_write_mode = -1; |
| 2070 | share->active_link_count = -1; |
| 2071 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 2072 | share->hs_result_free_size = -1; |
| 2073 | #endif |
| 2074 | #ifdef HA_CAN_BULK_ACCESS |
| 2075 | share->bulk_access_free = -1; |
| 2076 | #endif |
| 2077 | #ifdef HA_CAN_FORCE_BULK_UPDATE |
| 2078 | share->force_bulk_update = -1; |
| 2079 | #endif |
| 2080 | #ifdef HA_CAN_FORCE_BULK_DELETE |
| 2081 | share->force_bulk_delete = -1; |
| 2082 | #endif |
| 2083 | share->casual_read = -1; |
| 2084 | share->delete_all_rows_type = -1; |
| 2085 | share->static_records_for_status = -1; |
| 2086 | share->static_mean_rec_length = -1; |
| 2087 | for (roop_count = 0; roop_count < (int) table_share->keys; roop_count++) |
| 2088 | { |
| 2089 | share->static_key_cardinality[roop_count] = -1; |
| 2090 | } |
| 2091 | |
| 2092 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 2093 | for (roop_count = 4; roop_count > 0; roop_count--) |
| 2094 | #else |
| 2095 | for (roop_count = 2; roop_count > 0; roop_count--) |
| 2096 | #endif |
| 2097 | { |
| 2098 | if (connect_string) |
| 2099 | { |
| 2100 | spider_free(spider_current_trx, connect_string, MYF(0)); |
| 2101 | connect_string = NULL; |
| 2102 | } |
| 2103 | switch (roop_count) |
| 2104 | { |
| 2105 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 2106 | case 4: |
| 2107 | if (!sub_elem || !sub_elem->part_comment) |
| 2108 | continue; |
| 2109 | DBUG_PRINT("info" ,("spider create sub comment string" )); |
| 2110 | if ( |
| 2111 | !(connect_string = spider_create_string( |
| 2112 | sub_elem->part_comment, |
| 2113 | strlen(sub_elem->part_comment))) |
| 2114 | ) { |
| 2115 | error_num = HA_ERR_OUT_OF_MEM; |
| 2116 | goto error_alloc_conn_string; |
| 2117 | } |
| 2118 | DBUG_PRINT("info" ,("spider sub comment string=%s" , connect_string)); |
| 2119 | break; |
| 2120 | case 3: |
| 2121 | if (!part_elem || !part_elem->part_comment) |
| 2122 | continue; |
| 2123 | DBUG_PRINT("info" ,("spider create part comment string" )); |
| 2124 | if ( |
| 2125 | !(connect_string = spider_create_string( |
| 2126 | part_elem->part_comment, |
| 2127 | strlen(part_elem->part_comment))) |
| 2128 | ) { |
| 2129 | error_num = HA_ERR_OUT_OF_MEM; |
| 2130 | goto error_alloc_conn_string; |
| 2131 | } |
| 2132 | DBUG_PRINT("info" ,("spider part comment string=%s" , connect_string)); |
| 2133 | break; |
| 2134 | #endif |
| 2135 | case 2: |
| 2136 | if (table_share->comment.length == 0) |
| 2137 | continue; |
| 2138 | DBUG_PRINT("info" ,("spider create comment string" )); |
| 2139 | if ( |
| 2140 | !(connect_string = spider_create_string( |
| 2141 | table_share->comment.str, |
| 2142 | table_share->comment.length)) |
| 2143 | ) { |
| 2144 | error_num = HA_ERR_OUT_OF_MEM; |
| 2145 | goto error_alloc_conn_string; |
| 2146 | } |
| 2147 | DBUG_PRINT("info" ,("spider comment string=%s" , connect_string)); |
| 2148 | break; |
| 2149 | default: |
| 2150 | if (table_share->connect_string.length == 0) |
| 2151 | continue; |
| 2152 | DBUG_PRINT("info" ,("spider create connect_string string" )); |
| 2153 | if ( |
| 2154 | !(connect_string = spider_create_string( |
| 2155 | table_share->connect_string.str, |
| 2156 | table_share->connect_string.length)) |
| 2157 | ) { |
| 2158 | error_num = HA_ERR_OUT_OF_MEM; |
| 2159 | goto error_alloc_conn_string; |
| 2160 | } |
| 2161 | DBUG_PRINT("info" ,("spider connect_string=%s" , connect_string)); |
| 2162 | break; |
| 2163 | } |
| 2164 | |
| 2165 | sprit_ptr[0] = connect_string; |
| 2166 | connect_string_parse.init(connect_string, ER_SPIDER_INVALID_CONNECT_INFO_NUM); |
| 2167 | while (sprit_ptr[0]) |
| 2168 | { |
| 2169 | if ((sprit_ptr[1] = strchr(sprit_ptr[0], ','))) |
| 2170 | { |
| 2171 | *sprit_ptr[1] = '\0'; |
| 2172 | sprit_ptr[1]++; |
| 2173 | } |
| 2174 | tmp_ptr = sprit_ptr[0]; |
| 2175 | sprit_ptr[0] = sprit_ptr[1]; |
| 2176 | while (*tmp_ptr == ' ' || *tmp_ptr == '\r' || |
| 2177 | *tmp_ptr == '\n' || *tmp_ptr == '\t') |
| 2178 | tmp_ptr++; |
| 2179 | |
| 2180 | if (*tmp_ptr == '\0') |
| 2181 | continue; |
| 2182 | |
| 2183 | title_length = 0; |
| 2184 | start_ptr = tmp_ptr; |
| 2185 | while (*start_ptr != ' ' && *start_ptr != '\'' && |
| 2186 | *start_ptr != '"' && *start_ptr != '\0' && |
| 2187 | *start_ptr != '\r' && *start_ptr != '\n' && |
| 2188 | *start_ptr != '\t') |
| 2189 | { |
| 2190 | title_length++; |
| 2191 | start_ptr++; |
| 2192 | } |
| 2193 | connect_string_parse.set_param_title(tmp_ptr, tmp_ptr + title_length); |
| 2194 | |
| 2195 | switch (title_length) |
| 2196 | { |
| 2197 | case 0: |
| 2198 | error_num = connect_string_parse.print_param_error(); |
| 2199 | if (error_num) |
| 2200 | goto error; |
| 2201 | continue; |
| 2202 | case 3: |
| 2203 | SPIDER_PARAM_LONG_LIST_WITH_MAX("abl" , access_balances, 0, |
| 2204 | 2147483647); |
| 2205 | SPIDER_PARAM_INT_WITH_MAX("aim" , auto_increment_mode, 0, 3); |
| 2206 | SPIDER_PARAM_INT("alc" , active_link_count, 1); |
| 2207 | #ifdef HA_CAN_BULK_ACCESS |
| 2208 | SPIDER_PARAM_INT_WITH_MAX("baf" , bulk_access_free, 0, 1); |
| 2209 | #endif |
| 2210 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 2211 | SPIDER_PARAM_LONGLONG("bfr" , bgs_first_read, 0); |
| 2212 | SPIDER_PARAM_INT("bmd" , bgs_mode, 0); |
| 2213 | SPIDER_PARAM_LONGLONG("bsr" , bgs_second_read, 0); |
| 2214 | #endif |
| 2215 | SPIDER_PARAM_STR("bke" , bka_engine); |
| 2216 | SPIDER_PARAM_INT_WITH_MAX("bkm" , bka_mode, 0, 2); |
| 2217 | SPIDER_PARAM_INT("bsz" , bulk_size, 0); |
| 2218 | SPIDER_PARAM_LONG_LIST_WITH_MAX("btt" , bka_table_name_types, |
| 2219 | 0, 1); |
| 2220 | SPIDER_PARAM_INT_WITH_MAX("bum" , bulk_update_mode, 0, 2); |
| 2221 | SPIDER_PARAM_INT("bus" , bulk_update_size, 0); |
| 2222 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 2223 | SPIDER_PARAM_INT_WITH_MAX("cbm" , crd_bg_mode, 0, 2); |
| 2224 | #endif |
| 2225 | SPIDER_PARAM_DOUBLE("civ" , crd_interval, 0); |
| 2226 | SPIDER_PARAM_INT_WITH_MAX("cmd" , crd_mode, 0, 3); |
| 2227 | SPIDER_PARAM_INT_WITH_MAX("csr" , casual_read, 0, 63); |
| 2228 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 2229 | SPIDER_PARAM_INT_WITH_MAX("csy" , crd_sync, 0, 2); |
| 2230 | #endif |
| 2231 | SPIDER_PARAM_LONG_LIST_WITH_MAX("cto" , connect_timeouts, 0, |
| 2232 | 2147483647); |
| 2233 | SPIDER_PARAM_INT_WITH_MAX("ctp" , crd_type, 0, 2); |
| 2234 | SPIDER_PARAM_DOUBLE("cwg" , crd_weight, 1); |
| 2235 | SPIDER_PARAM_INT_WITH_MAX("dat" , delete_all_rows_type, 0, 1); |
| 2236 | SPIDER_PARAM_INT_WITH_MAX("ddi" , direct_dup_insert, 0, 1); |
| 2237 | SPIDER_PARAM_STR_LIST("dff" , tgt_default_files); |
| 2238 | SPIDER_PARAM_STR_LIST("dfg" , tgt_default_groups); |
| 2239 | SPIDER_PARAM_LONGLONG("dol" , direct_order_limit, 0); |
| 2240 | SPIDER_PARAM_INT_WITH_MAX("erm" , error_read_mode, 0, 1); |
| 2241 | SPIDER_PARAM_INT_WITH_MAX("ewm" , error_write_mode, 0, 1); |
| 2242 | #ifdef HA_CAN_FORCE_BULK_DELETE |
| 2243 | SPIDER_PARAM_INT_WITH_MAX("fbd" , force_bulk_delete, 0, 1); |
| 2244 | #endif |
| 2245 | #ifdef HA_CAN_FORCE_BULK_UPDATE |
| 2246 | SPIDER_PARAM_INT_WITH_MAX("fbu" , force_bulk_update, 0, 1); |
| 2247 | #endif |
| 2248 | SPIDER_PARAM_LONGLONG("frd" , first_read, 0); |
| 2249 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 2250 | SPIDER_PARAM_LONGLONG("hrf" , hs_result_free_size, 0); |
| 2251 | SPIDER_PARAM_LONG_LIST_WITH_MAX( |
| 2252 | "hrp" , hs_read_ports, 0, 65535); |
| 2253 | SPIDER_PARAM_STR_LIST("hrs" , hs_read_socks); |
| 2254 | SPIDER_PARAM_LONG_LIST_WITH_MAX( |
| 2255 | "hwp" , hs_write_ports, 0, 65535); |
| 2256 | SPIDER_PARAM_LONG_LIST_WITH_MAX( |
| 2257 | "hwr" , hs_write_to_reads, 0, 1); |
| 2258 | SPIDER_PARAM_STR_LIST("hws" , hs_write_socks); |
| 2259 | #endif |
| 2260 | SPIDER_PARAM_INT("isa" , init_sql_alloc_size, 0); |
| 2261 | SPIDER_PARAM_INT_WITH_MAX("idl" , internal_delayed, 0, 1); |
| 2262 | SPIDER_PARAM_LONGLONG("ilm" , internal_limit, 0); |
| 2263 | SPIDER_PARAM_LONGLONG("ios" , internal_offset, 0); |
| 2264 | SPIDER_PARAM_INT_WITH_MAX("iom" , internal_optimize, 0, 1); |
| 2265 | SPIDER_PARAM_INT_WITH_MAX("iol" , internal_optimize_local, 0, 1); |
| 2266 | SPIDER_PARAM_INT_WITH_MAX("lmr" , low_mem_read, 0, 1); |
| 2267 | SPIDER_PARAM_INT_WITH_MAX("lcs" , load_crd_at_startup, 0, 1); |
| 2268 | SPIDER_PARAM_INT_WITH_MAX("lss" , load_sts_at_startup, 0, 1); |
| 2269 | SPIDER_PARAM_LONG_LIST_WITH_MAX("lst" , link_statuses, 0, 3); |
| 2270 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 2271 | SPIDER_PARAM_LONG_LIST_WITH_MAX("mbf" , monitoring_bg_flag, 0, 1); |
| 2272 | SPIDER_PARAM_LONGLONG_LIST_WITH_MAX( |
| 2273 | "mbi" , monitoring_bg_interval, 0, 4294967295LL); |
| 2274 | SPIDER_PARAM_LONG_LIST_WITH_MAX("mbk" , monitoring_bg_kind, 0, 3); |
| 2275 | #endif |
| 2276 | SPIDER_PARAM_LONG_LIST_WITH_MAX("mbp" , monitoring_binlog_pos_at_failing, 0, 2); |
| 2277 | SPIDER_PARAM_LONG_LIST_WITH_MAX("mfg" , monitoring_flag, 0, 1); |
| 2278 | SPIDER_PARAM_LONG_LIST_WITH_MAX("mkd" , monitoring_kind, 0, 3); |
| 2279 | SPIDER_PARAM_LONGLONG_LIST_WITH_MAX( |
| 2280 | "mlt" , monitoring_limit, 0, 9223372036854775807LL); |
| 2281 | SPIDER_PARAM_INT("mod" , max_order, 0); |
| 2282 | SPIDER_PARAM_LONGLONG_LIST_WITH_MAX( |
| 2283 | "msi" , monitoring_sid, 0, 4294967295LL); |
| 2284 | SPIDER_PARAM_INT_WITH_MAX("msr" , multi_split_read, 0, 2147483647); |
| 2285 | SPIDER_PARAM_LONG_LIST_WITH_MAX("nrt" , net_read_timeouts, 0, |
| 2286 | 2147483647); |
| 2287 | SPIDER_PARAM_LONG_LIST_WITH_MAX("nwt" , net_write_timeouts, 0, |
| 2288 | 2147483647); |
| 2289 | SPIDER_PARAM_STR_LIST("pkn" , tgt_pk_names); |
| 2290 | SPIDER_PARAM_LONGLONG("prt" , priority, 0); |
| 2291 | SPIDER_PARAM_INT_WITH_MAX("qch" , query_cache, 0, 2); |
| 2292 | SPIDER_PARAM_INT_WITH_MAX("qcs" , query_cache_sync, 0, 3); |
| 2293 | SPIDER_PARAM_INT_WITH_MAX("qmd" , quick_mode, 0, 3); |
| 2294 | SPIDER_PARAM_LONGLONG("qps" , quick_page_size, 0); |
| 2295 | SPIDER_PARAM_INT_WITH_MAX("rom" , read_only_mode, 0, 1); |
| 2296 | SPIDER_PARAM_DOUBLE("rrt" , read_rate, 0); |
| 2297 | SPIDER_PARAM_INT_WITH_MAX("rsa" , reset_sql_alloc, 0, 1); |
| 2298 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 2299 | SPIDER_PARAM_INT_WITH_MAX("sbm" , sts_bg_mode, 0, 2); |
| 2300 | #endif |
| 2301 | SPIDER_PARAM_STR_LIST("sca" , tgt_ssl_cas); |
| 2302 | SPIDER_PARAM_STR_LIST("sch" , tgt_ssl_ciphers); |
| 2303 | SPIDER_PARAM_INT_WITH_MAX("scm" , select_column_mode, 0, 1); |
| 2304 | SPIDER_PARAM_STR_LIST("scp" , tgt_ssl_capaths); |
| 2305 | SPIDER_PARAM_STR_LIST("scr" , tgt_ssl_certs); |
| 2306 | SPIDER_PARAM_INT_WITH_MAX("sdc" , skip_default_condition, 0, 1); |
| 2307 | SPIDER_PARAM_DOUBLE("siv" , sts_interval, 0); |
| 2308 | SPIDER_PARAM_STR_LIST("sky" , tgt_ssl_keys); |
| 2309 | SPIDER_PARAM_STR_LIST("sli" , static_link_ids); |
| 2310 | SPIDER_PARAM_INT_WITH_MAX("slc" , store_last_crd, 0, 1); |
| 2311 | SPIDER_PARAM_INT_WITH_MAX("slm" , selupd_lock_mode, 0, 2); |
| 2312 | SPIDER_PARAM_INT_WITH_MAX("sls" , store_last_sts, 0, 1); |
| 2313 | SPIDER_PARAM_INT_WITH_MAX("smd" , sts_mode, 1, 2); |
| 2314 | SPIDER_PARAM_LONGLONG("smr" , static_mean_rec_length, 0); |
| 2315 | SPIDER_PARAM_LONGLONG("spr" , split_read, 0); |
| 2316 | SPIDER_PARAM_INT_WITH_MAX("sps" , skip_parallel_search, 0, 3); |
| 2317 | SPIDER_PARAM_STR_LIST("sqn" , tgt_sequence_names); |
| 2318 | SPIDER_PARAM_LONGLONG("srd" , second_read, 0); |
| 2319 | SPIDER_PARAM_DOUBLE("srt" , scan_rate, 0); |
| 2320 | SPIDER_PARAM_STR_LIST("srv" , server_names); |
| 2321 | SPIDER_PARAM_DOUBLE("ssr" , semi_split_read, 0); |
| 2322 | SPIDER_PARAM_LONGLONG("ssl" , semi_split_read_limit, 0); |
| 2323 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 2324 | SPIDER_PARAM_INT_WITH_MAX("ssy" , sts_sync, 0, 2); |
| 2325 | #endif |
| 2326 | SPIDER_PARAM_INT_WITH_MAX("stc" , semi_table_lock_conn, 0, 1); |
| 2327 | SPIDER_PARAM_INT_WITH_MAX("stl" , semi_table_lock, 0, 1); |
| 2328 | SPIDER_PARAM_LONGLONG("srs" , static_records_for_status, 0); |
| 2329 | SPIDER_PARAM_LONG_LIST_WITH_MAX("svc" , tgt_ssl_vscs, 0, 1); |
| 2330 | SPIDER_PARAM_STR_LIST("tbl" , tgt_table_names); |
| 2331 | SPIDER_PARAM_INT_WITH_MAX("tcm" , table_count_mode, 0, 3); |
| 2332 | SPIDER_PARAM_LONG_LIST_WITH_MAX("uhd" , use_handlers, 0, 3); |
| 2333 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 2334 | SPIDER_PARAM_LONG_LIST_WITH_MAX( |
| 2335 | "uhr" , use_hs_reads, 0, 1); |
| 2336 | SPIDER_PARAM_LONG_LIST_WITH_MAX( |
| 2337 | "uhw" , use_hs_writes, 0, 1); |
| 2338 | #endif |
| 2339 | SPIDER_PARAM_INT_WITH_MAX("upu" , use_pushdown_udf, 0, 1); |
| 2340 | SPIDER_PARAM_INT_WITH_MAX("utc" , use_table_charset, 0, 1); |
| 2341 | error_num = connect_string_parse.print_param_error(); |
| 2342 | goto error; |
| 2343 | case 4: |
| 2344 | SPIDER_PARAM_STR_LIST("host" , tgt_hosts); |
| 2345 | SPIDER_PARAM_STR_LIST("user" , tgt_usernames); |
| 2346 | SPIDER_PARAM_LONG_LIST_WITH_MAX("port" , tgt_ports, 0, 65535); |
| 2347 | error_num = connect_string_parse.print_param_error(); |
| 2348 | goto error; |
| 2349 | case 5: |
| 2350 | SPIDER_PARAM_STR_LIST("table" , tgt_table_names); |
| 2351 | error_num = connect_string_parse.print_param_error(); |
| 2352 | goto error; |
| 2353 | case 6: |
| 2354 | SPIDER_PARAM_STR_LIST("server" , server_names); |
| 2355 | SPIDER_PARAM_STR_LIST("socket" , tgt_sockets); |
| 2356 | SPIDER_PARAM_HINT("idx" , key_hint, 3, (int) table_share->keys, |
| 2357 | spider_db_append_key_hint); |
| 2358 | SPIDER_PARAM_STR_LIST("ssl_ca" , tgt_ssl_cas); |
| 2359 | SPIDER_PARAM_NUMHINT("skc" , static_key_cardinality, 3, |
| 2360 | (int) table_share->keys, spider_set_ll_value); |
| 2361 | error_num = connect_string_parse.print_param_error(); |
| 2362 | goto error; |
| 2363 | case 7: |
| 2364 | SPIDER_PARAM_STR_LIST("wrapper" , tgt_wrappers); |
| 2365 | SPIDER_PARAM_STR_LIST("ssl_key" , tgt_ssl_keys); |
| 2366 | SPIDER_PARAM_STR_LIST("pk_name" , tgt_pk_names); |
| 2367 | error_num = connect_string_parse.print_param_error(); |
| 2368 | goto error; |
| 2369 | case 8: |
| 2370 | SPIDER_PARAM_STR_LIST("database" , tgt_dbs); |
| 2371 | SPIDER_PARAM_STR_LIST("password" , tgt_passwords); |
| 2372 | SPIDER_PARAM_INT_WITH_MAX("sts_mode" , sts_mode, 1, 2); |
| 2373 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 2374 | SPIDER_PARAM_INT_WITH_MAX("sts_sync" , sts_sync, 0, 2); |
| 2375 | #endif |
| 2376 | SPIDER_PARAM_INT_WITH_MAX("crd_mode" , crd_mode, 0, 3); |
| 2377 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 2378 | SPIDER_PARAM_INT_WITH_MAX("crd_sync" , crd_sync, 0, 2); |
| 2379 | #endif |
| 2380 | SPIDER_PARAM_INT_WITH_MAX("crd_type" , crd_type, 0, 2); |
| 2381 | SPIDER_PARAM_LONGLONG("priority" , priority, 0); |
| 2382 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 2383 | SPIDER_PARAM_INT("bgs_mode" , bgs_mode, 0); |
| 2384 | #endif |
| 2385 | SPIDER_PARAM_STR_LIST("ssl_cert" , tgt_ssl_certs); |
| 2386 | SPIDER_PARAM_INT_WITH_MAX("bka_mode" , bka_mode, 0, 2); |
| 2387 | error_num = connect_string_parse.print_param_error(); |
| 2388 | goto error; |
| 2389 | case 9: |
| 2390 | SPIDER_PARAM_INT("max_order" , max_order, 0); |
| 2391 | SPIDER_PARAM_INT("bulk_size" , bulk_size, 0); |
| 2392 | SPIDER_PARAM_DOUBLE("scan_rate" , scan_rate, 0); |
| 2393 | SPIDER_PARAM_DOUBLE("read_rate" , read_rate, 0); |
| 2394 | error_num = connect_string_parse.print_param_error(); |
| 2395 | goto error; |
| 2396 | case 10: |
| 2397 | SPIDER_PARAM_DOUBLE("crd_weight" , crd_weight, 1); |
| 2398 | SPIDER_PARAM_LONGLONG("split_read" , split_read, 0); |
| 2399 | SPIDER_PARAM_INT_WITH_MAX("quick_mode" , quick_mode, 0, 3); |
| 2400 | SPIDER_PARAM_STR_LIST("ssl_cipher" , tgt_ssl_ciphers); |
| 2401 | SPIDER_PARAM_STR_LIST("ssl_capath" , tgt_ssl_capaths); |
| 2402 | SPIDER_PARAM_STR("bka_engine" , bka_engine); |
| 2403 | SPIDER_PARAM_LONGLONG("first_read" , first_read, 0); |
| 2404 | error_num = connect_string_parse.print_param_error(); |
| 2405 | goto error; |
| 2406 | case 11: |
| 2407 | SPIDER_PARAM_INT_WITH_MAX("query_cache" , query_cache, 0, 2); |
| 2408 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 2409 | SPIDER_PARAM_INT_WITH_MAX("crd_bg_mode" , crd_bg_mode, 0, 2); |
| 2410 | SPIDER_PARAM_INT_WITH_MAX("sts_bg_mode" , sts_bg_mode, 0, 2); |
| 2411 | #endif |
| 2412 | SPIDER_PARAM_LONG_LIST_WITH_MAX("link_status" , link_statuses, 0, 3); |
| 2413 | SPIDER_PARAM_LONG_LIST_WITH_MAX("use_handler" , use_handlers, 0, 3); |
| 2414 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 2415 | SPIDER_PARAM_LONG_LIST_WITH_MAX("use_hs_read" , use_hs_reads, 0, 1); |
| 2416 | #endif |
| 2417 | SPIDER_PARAM_INT_WITH_MAX("casual_read" , casual_read, 0, 63); |
| 2418 | error_num = connect_string_parse.print_param_error(); |
| 2419 | goto error; |
| 2420 | case 12: |
| 2421 | SPIDER_PARAM_DOUBLE("sts_interval" , sts_interval, 0); |
| 2422 | SPIDER_PARAM_DOUBLE("crd_interval" , crd_interval, 0); |
| 2423 | SPIDER_PARAM_INT_WITH_MAX("low_mem_read" , low_mem_read, 0, 1); |
| 2424 | SPIDER_PARAM_STR_LIST("default_file" , tgt_default_files); |
| 2425 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 2426 | SPIDER_PARAM_LONG_LIST_WITH_MAX( |
| 2427 | "use_hs_write" , use_hs_writes, 0, 1); |
| 2428 | SPIDER_PARAM_LONG_LIST_WITH_MAX( |
| 2429 | "hs_read_port" , hs_read_ports, 0, 65535); |
| 2430 | #endif |
| 2431 | error_num = connect_string_parse.print_param_error(); |
| 2432 | goto error; |
| 2433 | case 13: |
| 2434 | SPIDER_PARAM_STR_LIST("default_group" , tgt_default_groups); |
| 2435 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 2436 | SPIDER_PARAM_LONG_LIST_WITH_MAX( |
| 2437 | "hs_write_port" , hs_write_ports, 0, 65535); |
| 2438 | #endif |
| 2439 | SPIDER_PARAM_STR_LIST("sequence_name" , tgt_sequence_names); |
| 2440 | error_num = connect_string_parse.print_param_error(); |
| 2441 | goto error; |
| 2442 | case 14: |
| 2443 | SPIDER_PARAM_LONGLONG("internal_limit" , internal_limit, 0); |
| 2444 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 2445 | SPIDER_PARAM_LONGLONG("bgs_first_read" , bgs_first_read, 0); |
| 2446 | #endif |
| 2447 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 2448 | SPIDER_PARAM_STR_LIST( |
| 2449 | "hs_read_socket" , hs_read_socks); |
| 2450 | #endif |
| 2451 | SPIDER_PARAM_INT_WITH_MAX("read_only_mode" , read_only_mode, 0, 1); |
| 2452 | SPIDER_PARAM_LONG_LIST_WITH_MAX("access_balance" , access_balances, 0, |
| 2453 | 2147483647); |
| 2454 | SPIDER_PARAM_STR_LIST("static_link_id" , static_link_ids); |
| 2455 | SPIDER_PARAM_INT_WITH_MAX("store_last_crd" , store_last_crd, 0, 1); |
| 2456 | SPIDER_PARAM_INT_WITH_MAX("store_last_sts" , store_last_sts, 0, 1); |
| 2457 | error_num = connect_string_parse.print_param_error(); |
| 2458 | goto error; |
| 2459 | case 15: |
| 2460 | SPIDER_PARAM_LONGLONG("internal_offset" , internal_offset, 0); |
| 2461 | SPIDER_PARAM_INT_WITH_MAX("reset_sql_alloc" , reset_sql_alloc, 0, 1); |
| 2462 | SPIDER_PARAM_INT_WITH_MAX("semi_table_lock" , semi_table_lock, 0, 1); |
| 2463 | SPIDER_PARAM_LONGLONG("quick_page_size" , quick_page_size, 0); |
| 2464 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 2465 | SPIDER_PARAM_LONGLONG("bgs_second_read" , bgs_second_read, 0); |
| 2466 | #endif |
| 2467 | SPIDER_PARAM_LONG_LIST_WITH_MAX("monitoring_flag" , monitoring_flag, 0, 1); |
| 2468 | SPIDER_PARAM_LONG_LIST_WITH_MAX("monitoring_kind" , monitoring_kind, 0, 3); |
| 2469 | SPIDER_PARAM_DOUBLE("semi_split_read" , semi_split_read, 0); |
| 2470 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 2471 | SPIDER_PARAM_STR_LIST( |
| 2472 | "hs_write_socket" , hs_write_socks); |
| 2473 | #endif |
| 2474 | SPIDER_PARAM_LONG_LIST_WITH_MAX("connect_timeout" , connect_timeouts, |
| 2475 | 0, 2147483647); |
| 2476 | SPIDER_PARAM_INT_WITH_MAX("error_read_mode" , error_read_mode, 0, 1); |
| 2477 | error_num = connect_string_parse.print_param_error(); |
| 2478 | goto error; |
| 2479 | case 16: |
| 2480 | SPIDER_PARAM_INT_WITH_MAX( |
| 2481 | "multi_split_read" , multi_split_read, 0, 2147483647); |
| 2482 | SPIDER_PARAM_INT_WITH_MAX( |
| 2483 | "selupd_lock_mode" , selupd_lock_mode, 0, 2); |
| 2484 | SPIDER_PARAM_INT_WITH_MAX( |
| 2485 | "internal_delayed" , internal_delayed, 0, 1); |
| 2486 | SPIDER_PARAM_INT_WITH_MAX( |
| 2487 | "table_count_mode" , table_count_mode, 0, 3); |
| 2488 | SPIDER_PARAM_INT_WITH_MAX( |
| 2489 | "use_pushdown_udf" , use_pushdown_udf, 0, 1); |
| 2490 | SPIDER_PARAM_LONGLONG_LIST_WITH_MAX( |
| 2491 | "monitoring_limit" , monitoring_limit, 0, 9223372036854775807LL); |
| 2492 | SPIDER_PARAM_INT_WITH_MAX( |
| 2493 | "bulk_update_mode" , bulk_update_mode, 0, 2); |
| 2494 | SPIDER_PARAM_INT("bulk_update_size" , bulk_update_size, 0); |
| 2495 | SPIDER_PARAM_LONG_LIST_WITH_MAX("net_read_timeout" , |
| 2496 | net_read_timeouts, 0, 2147483647); |
| 2497 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 2498 | SPIDER_PARAM_LONG_LIST_WITH_MAX( |
| 2499 | "hs_write_to_read" , hs_write_to_reads, 0, 1); |
| 2500 | #endif |
| 2501 | SPIDER_PARAM_INT_WITH_MAX( |
| 2502 | "error_write_mode" , error_write_mode, 0, 1); |
| 2503 | #ifdef HA_CAN_BULK_ACCESS |
| 2504 | SPIDER_PARAM_INT_WITH_MAX( |
| 2505 | "bulk_access_free" , bulk_access_free, 0, 1); |
| 2506 | #endif |
| 2507 | SPIDER_PARAM_INT_WITH_MAX( |
| 2508 | "query_cache_sync" , query_cache_sync, 0, 3); |
| 2509 | error_num = connect_string_parse.print_param_error(); |
| 2510 | goto error; |
| 2511 | case 17: |
| 2512 | SPIDER_PARAM_INT_WITH_MAX( |
| 2513 | "internal_optimize" , internal_optimize, 0, 1); |
| 2514 | SPIDER_PARAM_INT_WITH_MAX( |
| 2515 | "use_table_charset" , use_table_charset, 0, 1); |
| 2516 | SPIDER_PARAM_INT_WITH_MAX( |
| 2517 | "direct_dup_insert" , direct_dup_insert, 0, 1); |
| 2518 | SPIDER_PARAM_INT("active_link_count" , active_link_count, 1); |
| 2519 | SPIDER_PARAM_LONG_LIST_WITH_MAX("net_write_timeout" , |
| 2520 | net_write_timeouts, 0, 2147483647); |
| 2521 | #ifdef HA_CAN_FORCE_BULK_DELETE |
| 2522 | SPIDER_PARAM_INT_WITH_MAX( |
| 2523 | "force_bulk_delete" , force_bulk_delete, 0, 1); |
| 2524 | #endif |
| 2525 | #ifdef HA_CAN_FORCE_BULK_UPDATE |
| 2526 | SPIDER_PARAM_INT_WITH_MAX( |
| 2527 | "force_bulk_update" , force_bulk_update, 0, 1); |
| 2528 | #endif |
| 2529 | error_num = connect_string_parse.print_param_error(); |
| 2530 | goto error; |
| 2531 | case 18: |
| 2532 | SPIDER_PARAM_INT_WITH_MAX( |
| 2533 | "select_column_mode" , select_column_mode, 0, 1); |
| 2534 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 2535 | SPIDER_PARAM_LONG_LIST_WITH_MAX( |
| 2536 | "monitoring_bg_flag" , monitoring_bg_flag, 0, 1); |
| 2537 | SPIDER_PARAM_LONG_LIST_WITH_MAX( |
| 2538 | "monitoring_bg_kind" , monitoring_bg_kind, 0, 3); |
| 2539 | #endif |
| 2540 | SPIDER_PARAM_LONGLONG( |
| 2541 | "direct_order_limit" , direct_order_limit, 0); |
| 2542 | error_num = connect_string_parse.print_param_error(); |
| 2543 | goto error; |
| 2544 | case 19: |
| 2545 | SPIDER_PARAM_INT("init_sql_alloc_size" , init_sql_alloc_size, 0); |
| 2546 | SPIDER_PARAM_INT_WITH_MAX( |
| 2547 | "auto_increment_mode" , auto_increment_mode, 0, 3); |
| 2548 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 2549 | SPIDER_PARAM_LONGLONG("hs_result_free_size" , hs_result_free_size, 0); |
| 2550 | #endif |
| 2551 | SPIDER_PARAM_LONG_LIST_WITH_MAX("bka_table_name_type" , |
| 2552 | bka_table_name_types, 0, 1); |
| 2553 | SPIDER_PARAM_INT_WITH_MAX( |
| 2554 | "load_crd_at_startup" , load_crd_at_startup, 0, 1); |
| 2555 | SPIDER_PARAM_INT_WITH_MAX( |
| 2556 | "load_sts_at_startup" , load_sts_at_startup, 0, 1); |
| 2557 | error_num = connect_string_parse.print_param_error(); |
| 2558 | goto error; |
| 2559 | case 20: |
| 2560 | SPIDER_PARAM_LONGLONG_LIST_WITH_MAX( |
| 2561 | "monitoring_server_id" , monitoring_sid, 0, 4294967295LL); |
| 2562 | SPIDER_PARAM_INT_WITH_MAX( |
| 2563 | "delete_all_rows_type" , delete_all_rows_type, 0, 1); |
| 2564 | SPIDER_PARAM_INT_WITH_MAX( |
| 2565 | "skip_parallel_search" , skip_parallel_search, 0, 3); |
| 2566 | error_num = connect_string_parse.print_param_error(); |
| 2567 | goto error; |
| 2568 | case 21: |
| 2569 | SPIDER_PARAM_LONGLONG( |
| 2570 | "semi_split_read_limit" , semi_split_read_limit, 0); |
| 2571 | error_num = connect_string_parse.print_param_error(); |
| 2572 | goto error; |
| 2573 | case 22: |
| 2574 | SPIDER_PARAM_LONG_LIST_WITH_MAX( |
| 2575 | "ssl_verify_server_cert" , tgt_ssl_vscs, 0, 1); |
| 2576 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 2577 | SPIDER_PARAM_LONGLONG_LIST_WITH_MAX( |
| 2578 | "monitoring_bg_interval" , monitoring_bg_interval, 0, 4294967295LL); |
| 2579 | #endif |
| 2580 | SPIDER_PARAM_INT_WITH_MAX( |
| 2581 | "skip_default_condition" , skip_default_condition, 0, 1); |
| 2582 | SPIDER_PARAM_LONGLONG( |
| 2583 | "static_mean_rec_length" , static_mean_rec_length, 0); |
| 2584 | error_num = connect_string_parse.print_param_error(); |
| 2585 | goto error; |
| 2586 | case 23: |
| 2587 | SPIDER_PARAM_INT_WITH_MAX( |
| 2588 | "internal_optimize_local" , internal_optimize_local, 0, 1); |
| 2589 | error_num = connect_string_parse.print_param_error(); |
| 2590 | goto error; |
| 2591 | case 25: |
| 2592 | SPIDER_PARAM_LONGLONG("static_records_for_status" , |
| 2593 | static_records_for_status, 0); |
| 2594 | SPIDER_PARAM_NUMHINT("static_key_cardinality" , static_key_cardinality, |
| 2595 | 3, (int) table_share->keys, spider_set_ll_value); |
| 2596 | error_num = connect_string_parse.print_param_error(); |
| 2597 | goto error; |
| 2598 | case 26: |
| 2599 | SPIDER_PARAM_INT_WITH_MAX( |
| 2600 | "semi_table_lock_connection" , semi_table_lock_conn, 0, 1); |
| 2601 | error_num = connect_string_parse.print_param_error(); |
| 2602 | goto error; |
| 2603 | case 32: |
| 2604 | SPIDER_PARAM_LONG_LIST_WITH_MAX("monitoring_binlog_pos_at_failing" , |
| 2605 | monitoring_binlog_pos_at_failing, 0, 2); |
| 2606 | error_num = connect_string_parse.print_param_error(); |
| 2607 | goto error; |
| 2608 | default: |
| 2609 | error_num = connect_string_parse.print_param_error(); |
| 2610 | goto error; |
| 2611 | } |
| 2612 | |
| 2613 | /* Verify that the remainder of the parameter value is whitespace */ |
| 2614 | if ((error_num = connect_string_parse.has_extra_parameter_values())) |
| 2615 | goto error; |
| 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | /* check all_link_count */ |
| 2620 | share->all_link_count = 1; |
| 2621 | if (share->all_link_count < share->server_names_length) |
| 2622 | share->all_link_count = share->server_names_length; |
| 2623 | if (share->all_link_count < share->tgt_table_names_length) |
| 2624 | share->all_link_count = share->tgt_table_names_length; |
| 2625 | if (share->all_link_count < share->tgt_dbs_length) |
| 2626 | share->all_link_count = share->tgt_dbs_length; |
| 2627 | if (share->all_link_count < share->tgt_hosts_length) |
| 2628 | share->all_link_count = share->tgt_hosts_length; |
| 2629 | if (share->all_link_count < share->tgt_usernames_length) |
| 2630 | share->all_link_count = share->tgt_usernames_length; |
| 2631 | if (share->all_link_count < share->tgt_passwords_length) |
| 2632 | share->all_link_count = share->tgt_passwords_length; |
| 2633 | if (share->all_link_count < share->tgt_sockets_length) |
| 2634 | share->all_link_count = share->tgt_sockets_length; |
| 2635 | if (share->all_link_count < share->tgt_wrappers_length) |
| 2636 | share->all_link_count = share->tgt_wrappers_length; |
| 2637 | if (share->all_link_count < share->tgt_ssl_cas_length) |
| 2638 | share->all_link_count = share->tgt_ssl_cas_length; |
| 2639 | if (share->all_link_count < share->tgt_ssl_capaths_length) |
| 2640 | share->all_link_count = share->tgt_ssl_capaths_length; |
| 2641 | if (share->all_link_count < share->tgt_ssl_certs_length) |
| 2642 | share->all_link_count = share->tgt_ssl_certs_length; |
| 2643 | if (share->all_link_count < share->tgt_ssl_ciphers_length) |
| 2644 | share->all_link_count = share->tgt_ssl_ciphers_length; |
| 2645 | if (share->all_link_count < share->tgt_ssl_keys_length) |
| 2646 | share->all_link_count = share->tgt_ssl_keys_length; |
| 2647 | if (share->all_link_count < share->tgt_default_files_length) |
| 2648 | share->all_link_count = share->tgt_default_files_length; |
| 2649 | if (share->all_link_count < share->tgt_default_groups_length) |
| 2650 | share->all_link_count = share->tgt_default_groups_length; |
| 2651 | if (share->all_link_count < share->tgt_pk_names_length) |
| 2652 | share->all_link_count = share->tgt_pk_names_length; |
| 2653 | if (share->all_link_count < share->tgt_sequence_names_length) |
| 2654 | share->all_link_count = share->tgt_sequence_names_length; |
| 2655 | if (share->all_link_count < share->static_link_ids_length) |
| 2656 | share->all_link_count = share->static_link_ids_length; |
| 2657 | if (share->all_link_count < share->tgt_ports_length) |
| 2658 | share->all_link_count = share->tgt_ports_length; |
| 2659 | if (share->all_link_count < share->tgt_ssl_vscs_length) |
| 2660 | share->all_link_count = share->tgt_ssl_vscs_length; |
| 2661 | if (share->all_link_count < share->link_statuses_length) |
| 2662 | share->all_link_count = share->link_statuses_length; |
| 2663 | if (share->all_link_count < share->monitoring_binlog_pos_at_failing_length) |
| 2664 | share->all_link_count = share->monitoring_binlog_pos_at_failing_length; |
| 2665 | if (share->all_link_count < share->monitoring_flag_length) |
| 2666 | share->all_link_count = share->monitoring_flag_length; |
| 2667 | if (share->all_link_count < share->monitoring_kind_length) |
| 2668 | share->all_link_count = share->monitoring_kind_length; |
| 2669 | if (share->all_link_count < share->monitoring_limit_length) |
| 2670 | share->all_link_count = share->monitoring_limit_length; |
| 2671 | if (share->all_link_count < share->monitoring_sid_length) |
| 2672 | share->all_link_count = share->monitoring_sid_length; |
| 2673 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 2674 | if (share->all_link_count < share->monitoring_bg_flag_length) |
| 2675 | share->all_link_count = share->monitoring_bg_flag_length; |
| 2676 | if (share->all_link_count < share->monitoring_bg_kind_length) |
| 2677 | share->all_link_count = share->monitoring_bg_kind_length; |
| 2678 | if (share->all_link_count < share->monitoring_bg_interval_length) |
| 2679 | share->all_link_count = share->monitoring_bg_interval_length; |
| 2680 | #endif |
| 2681 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 2682 | if (share->all_link_count < share->use_hs_reads_length) |
| 2683 | share->all_link_count = share->use_hs_reads_length; |
| 2684 | if (share->all_link_count < share->use_hs_writes_length) |
| 2685 | share->all_link_count = share->use_hs_writes_length; |
| 2686 | if (share->all_link_count < share->hs_read_ports_length) |
| 2687 | share->all_link_count = share->hs_read_ports_length; |
| 2688 | if (share->all_link_count < share->hs_write_ports_length) |
| 2689 | share->all_link_count = share->hs_write_ports_length; |
| 2690 | if (share->all_link_count < share->hs_read_socks_length) |
| 2691 | share->all_link_count = share->hs_read_socks_length; |
| 2692 | if (share->all_link_count < share->hs_write_socks_length) |
| 2693 | share->all_link_count = share->hs_write_socks_length; |
| 2694 | if (share->all_link_count < share->hs_write_to_reads_length) |
| 2695 | share->all_link_count = share->hs_write_to_reads_length; |
| 2696 | #endif |
| 2697 | if (share->all_link_count < share->use_handlers_length) |
| 2698 | share->all_link_count = share->use_handlers_length; |
| 2699 | if (share->all_link_count < share->connect_timeouts_length) |
| 2700 | share->all_link_count = share->connect_timeouts_length; |
| 2701 | if (share->all_link_count < share->net_read_timeouts_length) |
| 2702 | share->all_link_count = share->net_read_timeouts_length; |
| 2703 | if (share->all_link_count < share->net_write_timeouts_length) |
| 2704 | share->all_link_count = share->net_write_timeouts_length; |
| 2705 | if (share->all_link_count < share->access_balances_length) |
| 2706 | share->all_link_count = share->access_balances_length; |
| 2707 | if (share->all_link_count < share->bka_table_name_types_length) |
| 2708 | share->all_link_count = share->bka_table_name_types_length; |
| 2709 | if ((error_num = spider_increase_string_list( |
| 2710 | &share->server_names, |
| 2711 | &share->server_names_lengths, |
| 2712 | &share->server_names_length, |
| 2713 | &share->server_names_charlen, |
| 2714 | share->all_link_count))) |
| 2715 | goto error; |
| 2716 | if ((error_num = spider_increase_string_list( |
| 2717 | &share->tgt_table_names, |
| 2718 | &share->tgt_table_names_lengths, |
| 2719 | &share->tgt_table_names_length, |
| 2720 | &share->tgt_table_names_charlen, |
| 2721 | share->all_link_count))) |
| 2722 | goto error; |
| 2723 | if ((error_num = spider_increase_string_list( |
| 2724 | &share->tgt_dbs, |
| 2725 | &share->tgt_dbs_lengths, |
| 2726 | &share->tgt_dbs_length, |
| 2727 | &share->tgt_dbs_charlen, |
| 2728 | share->all_link_count))) |
| 2729 | goto error; |
| 2730 | if ((error_num = spider_increase_string_list( |
| 2731 | &share->tgt_hosts, |
| 2732 | &share->tgt_hosts_lengths, |
| 2733 | &share->tgt_hosts_length, |
| 2734 | &share->tgt_hosts_charlen, |
| 2735 | share->all_link_count))) |
| 2736 | goto error; |
| 2737 | if ((error_num = spider_increase_string_list( |
| 2738 | &share->tgt_usernames, |
| 2739 | &share->tgt_usernames_lengths, |
| 2740 | &share->tgt_usernames_length, |
| 2741 | &share->tgt_usernames_charlen, |
| 2742 | share->all_link_count))) |
| 2743 | goto error; |
| 2744 | if ((error_num = spider_increase_string_list( |
| 2745 | &share->tgt_passwords, |
| 2746 | &share->tgt_passwords_lengths, |
| 2747 | &share->tgt_passwords_length, |
| 2748 | &share->tgt_passwords_charlen, |
| 2749 | share->all_link_count))) |
| 2750 | goto error; |
| 2751 | if ((error_num = spider_increase_string_list( |
| 2752 | &share->tgt_sockets, |
| 2753 | &share->tgt_sockets_lengths, |
| 2754 | &share->tgt_sockets_length, |
| 2755 | &share->tgt_sockets_charlen, |
| 2756 | share->all_link_count))) |
| 2757 | goto error; |
| 2758 | if ((error_num = spider_increase_string_list( |
| 2759 | &share->tgt_wrappers, |
| 2760 | &share->tgt_wrappers_lengths, |
| 2761 | &share->tgt_wrappers_length, |
| 2762 | &share->tgt_wrappers_charlen, |
| 2763 | share->all_link_count))) |
| 2764 | goto error; |
| 2765 | if ((error_num = spider_increase_string_list( |
| 2766 | &share->tgt_ssl_cas, |
| 2767 | &share->tgt_ssl_cas_lengths, |
| 2768 | &share->tgt_ssl_cas_length, |
| 2769 | &share->tgt_ssl_cas_charlen, |
| 2770 | share->all_link_count))) |
| 2771 | goto error; |
| 2772 | if ((error_num = spider_increase_string_list( |
| 2773 | &share->tgt_ssl_capaths, |
| 2774 | &share->tgt_ssl_capaths_lengths, |
| 2775 | &share->tgt_ssl_capaths_length, |
| 2776 | &share->tgt_ssl_capaths_charlen, |
| 2777 | share->all_link_count))) |
| 2778 | goto error; |
| 2779 | if ((error_num = spider_increase_string_list( |
| 2780 | &share->tgt_ssl_certs, |
| 2781 | &share->tgt_ssl_certs_lengths, |
| 2782 | &share->tgt_ssl_certs_length, |
| 2783 | &share->tgt_ssl_certs_charlen, |
| 2784 | share->all_link_count))) |
| 2785 | goto error; |
| 2786 | if ((error_num = spider_increase_string_list( |
| 2787 | &share->tgt_ssl_ciphers, |
| 2788 | &share->tgt_ssl_ciphers_lengths, |
| 2789 | &share->tgt_ssl_ciphers_length, |
| 2790 | &share->tgt_ssl_ciphers_charlen, |
| 2791 | share->all_link_count))) |
| 2792 | goto error; |
| 2793 | if ((error_num = spider_increase_string_list( |
| 2794 | &share->tgt_ssl_keys, |
| 2795 | &share->tgt_ssl_keys_lengths, |
| 2796 | &share->tgt_ssl_keys_length, |
| 2797 | &share->tgt_ssl_keys_charlen, |
| 2798 | share->all_link_count))) |
| 2799 | goto error; |
| 2800 | if ((error_num = spider_increase_string_list( |
| 2801 | &share->tgt_default_files, |
| 2802 | &share->tgt_default_files_lengths, |
| 2803 | &share->tgt_default_files_length, |
| 2804 | &share->tgt_default_files_charlen, |
| 2805 | share->all_link_count))) |
| 2806 | goto error; |
| 2807 | if ((error_num = spider_increase_string_list( |
| 2808 | &share->tgt_default_groups, |
| 2809 | &share->tgt_default_groups_lengths, |
| 2810 | &share->tgt_default_groups_length, |
| 2811 | &share->tgt_default_groups_charlen, |
| 2812 | share->all_link_count))) |
| 2813 | goto error; |
| 2814 | if ((error_num = spider_increase_string_list( |
| 2815 | &share->tgt_pk_names, |
| 2816 | &share->tgt_pk_names_lengths, |
| 2817 | &share->tgt_pk_names_length, |
| 2818 | &share->tgt_pk_names_charlen, |
| 2819 | share->all_link_count))) |
| 2820 | goto error; |
| 2821 | if ((error_num = spider_increase_string_list( |
| 2822 | &share->tgt_sequence_names, |
| 2823 | &share->tgt_sequence_names_lengths, |
| 2824 | &share->tgt_sequence_names_length, |
| 2825 | &share->tgt_sequence_names_charlen, |
| 2826 | share->all_link_count))) |
| 2827 | goto error; |
| 2828 | if ((error_num = spider_increase_null_string_list( |
| 2829 | &share->static_link_ids, |
| 2830 | &share->static_link_ids_lengths, |
| 2831 | &share->static_link_ids_length, |
| 2832 | &share->static_link_ids_charlen, |
| 2833 | share->all_link_count))) |
| 2834 | goto error; |
| 2835 | if ((error_num = spider_increase_long_list( |
| 2836 | &share->tgt_ports, |
| 2837 | &share->tgt_ports_length, |
| 2838 | share->all_link_count))) |
| 2839 | goto error; |
| 2840 | if ((error_num = spider_increase_long_list( |
| 2841 | &share->tgt_ssl_vscs, |
| 2842 | &share->tgt_ssl_vscs_length, |
| 2843 | share->all_link_count))) |
| 2844 | goto error; |
| 2845 | if ((error_num = spider_increase_long_list( |
| 2846 | &share->link_statuses, |
| 2847 | &share->link_statuses_length, |
| 2848 | share->all_link_count))) |
| 2849 | goto error; |
| 2850 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 2851 | if ((error_num = spider_increase_long_list( |
| 2852 | &share->monitoring_bg_flag, |
| 2853 | &share->monitoring_bg_flag_length, |
| 2854 | share->all_link_count))) |
| 2855 | goto error; |
| 2856 | if ((error_num = spider_increase_long_list( |
| 2857 | &share->monitoring_bg_kind, |
| 2858 | &share->monitoring_bg_kind_length, |
| 2859 | share->all_link_count))) |
| 2860 | goto error; |
| 2861 | #endif |
| 2862 | if ((error_num = spider_increase_long_list( |
| 2863 | &share->monitoring_binlog_pos_at_failing, |
| 2864 | &share->monitoring_binlog_pos_at_failing_length, |
| 2865 | share->all_link_count))) |
| 2866 | goto error; |
| 2867 | if ((error_num = spider_increase_long_list( |
| 2868 | &share->monitoring_flag, |
| 2869 | &share->monitoring_flag_length, |
| 2870 | share->all_link_count))) |
| 2871 | goto error; |
| 2872 | if ((error_num = spider_increase_long_list( |
| 2873 | &share->monitoring_kind, |
| 2874 | &share->monitoring_kind_length, |
| 2875 | share->all_link_count))) |
| 2876 | goto error; |
| 2877 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 2878 | if ((error_num = spider_increase_longlong_list( |
| 2879 | &share->monitoring_bg_interval, |
| 2880 | &share->monitoring_bg_interval_length, |
| 2881 | share->all_link_count))) |
| 2882 | goto error; |
| 2883 | #endif |
| 2884 | if ((error_num = spider_increase_longlong_list( |
| 2885 | &share->monitoring_limit, |
| 2886 | &share->monitoring_limit_length, |
| 2887 | share->all_link_count))) |
| 2888 | goto error; |
| 2889 | if ((error_num = spider_increase_longlong_list( |
| 2890 | &share->monitoring_sid, |
| 2891 | &share->monitoring_sid_length, |
| 2892 | share->all_link_count))) |
| 2893 | goto error; |
| 2894 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 2895 | if ((error_num = spider_increase_long_list( |
| 2896 | &share->use_hs_reads, |
| 2897 | &share->use_hs_reads_length, |
| 2898 | share->all_link_count))) |
| 2899 | goto error; |
| 2900 | if ((error_num = spider_increase_long_list( |
| 2901 | &share->use_hs_writes, |
| 2902 | &share->use_hs_writes_length, |
| 2903 | share->all_link_count))) |
| 2904 | goto error; |
| 2905 | if ((error_num = spider_increase_long_list( |
| 2906 | &share->hs_read_ports, |
| 2907 | &share->hs_read_ports_length, |
| 2908 | share->all_link_count))) |
| 2909 | goto error; |
| 2910 | if ((error_num = spider_increase_long_list( |
| 2911 | &share->hs_write_ports, |
| 2912 | &share->hs_write_ports_length, |
| 2913 | share->all_link_count))) |
| 2914 | goto error; |
| 2915 | if ((error_num = spider_increase_string_list( |
| 2916 | &share->hs_read_socks, |
| 2917 | &share->hs_read_socks_lengths, |
| 2918 | &share->hs_read_socks_length, |
| 2919 | &share->hs_read_socks_charlen, |
| 2920 | share->all_link_count))) |
| 2921 | goto error; |
| 2922 | if ((error_num = spider_increase_string_list( |
| 2923 | &share->hs_write_socks, |
| 2924 | &share->hs_write_socks_lengths, |
| 2925 | &share->hs_write_socks_length, |
| 2926 | &share->hs_write_socks_charlen, |
| 2927 | share->all_link_count))) |
| 2928 | goto error; |
| 2929 | if ((error_num = spider_increase_long_list( |
| 2930 | &share->hs_write_to_reads, |
| 2931 | &share->hs_write_to_reads_length, |
| 2932 | share->all_link_count))) |
| 2933 | goto error; |
| 2934 | #endif |
| 2935 | if ((error_num = spider_increase_long_list( |
| 2936 | &share->use_handlers, |
| 2937 | &share->use_handlers_length, |
| 2938 | share->all_link_count))) |
| 2939 | goto error; |
| 2940 | if ((error_num = spider_increase_long_list( |
| 2941 | &share->connect_timeouts, |
| 2942 | &share->connect_timeouts_length, |
| 2943 | share->all_link_count))) |
| 2944 | goto error; |
| 2945 | if ((error_num = spider_increase_long_list( |
| 2946 | &share->net_read_timeouts, |
| 2947 | &share->net_read_timeouts_length, |
| 2948 | share->all_link_count))) |
| 2949 | goto error; |
| 2950 | if ((error_num = spider_increase_long_list( |
| 2951 | &share->net_write_timeouts, |
| 2952 | &share->net_write_timeouts_length, |
| 2953 | share->all_link_count))) |
| 2954 | goto error; |
| 2955 | if ((error_num = spider_increase_long_list( |
| 2956 | &share->access_balances, |
| 2957 | &share->access_balances_length, |
| 2958 | share->all_link_count))) |
| 2959 | goto error; |
| 2960 | if ((error_num = spider_increase_long_list( |
| 2961 | &share->bka_table_name_types, |
| 2962 | &share->bka_table_name_types_length, |
| 2963 | share->all_link_count))) |
| 2964 | goto error; |
| 2965 | |
| 2966 | /* copy for tables start */ |
| 2967 | share_alter = &share->alter_table; |
| 2968 | share_alter->all_link_count = share->all_link_count; |
| 2969 | if (!(share_alter->tmp_server_names = (char **) |
| 2970 | spider_bulk_malloc(spider_current_trx, 43, MYF(MY_WME | MY_ZEROFILL), |
| 2971 | &share_alter->tmp_server_names, |
| 2972 | sizeof(char *) * 16 * share->all_link_count, |
| 2973 | &share_alter->tmp_server_names_lengths, |
| 2974 | sizeof(uint *) * 16 * share->all_link_count, |
| 2975 | &share_alter->tmp_tgt_ports, |
| 2976 | sizeof(long) * share->all_link_count, |
| 2977 | &share_alter->tmp_tgt_ssl_vscs, |
| 2978 | sizeof(long) * share->all_link_count, |
| 2979 | &share_alter->tmp_monitoring_binlog_pos_at_failing, |
| 2980 | sizeof(long) * share->all_link_count, |
| 2981 | &share_alter->tmp_link_statuses, |
| 2982 | sizeof(long) * share->all_link_count, |
| 2983 | NullS)) |
| 2984 | ) { |
| 2985 | error_num = HA_ERR_OUT_OF_MEM; |
| 2986 | goto error; |
| 2987 | } |
| 2988 | |
| 2989 | |
| 2990 | memcpy(share_alter->tmp_server_names, share->server_names, |
| 2991 | sizeof(char *) * share->all_link_count); |
| 2992 | share_alter->tmp_tgt_table_names = |
| 2993 | share_alter->tmp_server_names + share->all_link_count; |
| 2994 | memcpy(share_alter->tmp_tgt_table_names, share->tgt_table_names, |
| 2995 | sizeof(char *) * share->all_link_count); |
| 2996 | share_alter->tmp_tgt_dbs = |
| 2997 | share_alter->tmp_tgt_table_names + share->all_link_count; |
| 2998 | memcpy(share_alter->tmp_tgt_dbs, share->tgt_dbs, |
| 2999 | sizeof(char *) * share->all_link_count); |
| 3000 | share_alter->tmp_tgt_hosts = |
| 3001 | share_alter->tmp_tgt_dbs + share->all_link_count; |
| 3002 | memcpy(share_alter->tmp_tgt_hosts, share->tgt_hosts, |
| 3003 | sizeof(char *) * share->all_link_count); |
| 3004 | share_alter->tmp_tgt_usernames = |
| 3005 | share_alter->tmp_tgt_hosts + share->all_link_count; |
| 3006 | memcpy(share_alter->tmp_tgt_usernames, share->tgt_usernames, |
| 3007 | sizeof(char *) * share->all_link_count); |
| 3008 | share_alter->tmp_tgt_passwords = |
| 3009 | share_alter->tmp_tgt_usernames + share->all_link_count; |
| 3010 | memcpy(share_alter->tmp_tgt_passwords, share->tgt_passwords, |
| 3011 | sizeof(char *) * share->all_link_count); |
| 3012 | share_alter->tmp_tgt_sockets = |
| 3013 | share_alter->tmp_tgt_passwords + share->all_link_count; |
| 3014 | memcpy(share_alter->tmp_tgt_sockets, share->tgt_sockets, |
| 3015 | sizeof(char *) * share->all_link_count); |
| 3016 | share_alter->tmp_tgt_wrappers = |
| 3017 | share_alter->tmp_tgt_sockets + share->all_link_count; |
| 3018 | memcpy(share_alter->tmp_tgt_wrappers, share->tgt_wrappers, |
| 3019 | sizeof(char *) * share->all_link_count); |
| 3020 | share_alter->tmp_tgt_ssl_cas = |
| 3021 | share_alter->tmp_tgt_wrappers + share->all_link_count; |
| 3022 | memcpy(share_alter->tmp_tgt_ssl_cas, share->tgt_ssl_cas, |
| 3023 | sizeof(char *) * share->all_link_count); |
| 3024 | share_alter->tmp_tgt_ssl_capaths = |
| 3025 | share_alter->tmp_tgt_ssl_cas + share->all_link_count; |
| 3026 | memcpy(share_alter->tmp_tgt_ssl_capaths, share->tgt_ssl_capaths, |
| 3027 | sizeof(char *) * share->all_link_count); |
| 3028 | share_alter->tmp_tgt_ssl_certs = |
| 3029 | share_alter->tmp_tgt_ssl_capaths + share->all_link_count; |
| 3030 | memcpy(share_alter->tmp_tgt_ssl_certs, share->tgt_ssl_certs, |
| 3031 | sizeof(char *) * share->all_link_count); |
| 3032 | share_alter->tmp_tgt_ssl_ciphers = |
| 3033 | share_alter->tmp_tgt_ssl_certs + share->all_link_count; |
| 3034 | memcpy(share_alter->tmp_tgt_ssl_ciphers, share->tgt_ssl_ciphers, |
| 3035 | sizeof(char *) * share->all_link_count); |
| 3036 | share_alter->tmp_tgt_ssl_keys = |
| 3037 | share_alter->tmp_tgt_ssl_ciphers + share->all_link_count; |
| 3038 | memcpy(share_alter->tmp_tgt_ssl_keys, share->tgt_ssl_keys, |
| 3039 | sizeof(char *) * share->all_link_count); |
| 3040 | share_alter->tmp_tgt_default_files = |
| 3041 | share_alter->tmp_tgt_ssl_keys + share->all_link_count; |
| 3042 | memcpy(share_alter->tmp_tgt_default_files, share->tgt_default_files, |
| 3043 | sizeof(char *) * share->all_link_count); |
| 3044 | share_alter->tmp_tgt_default_groups = |
| 3045 | share_alter->tmp_tgt_default_files + share->all_link_count; |
| 3046 | memcpy(share_alter->tmp_tgt_default_groups, share->tgt_default_groups, |
| 3047 | sizeof(char *) * share->all_link_count); |
| 3048 | share_alter->tmp_static_link_ids = |
| 3049 | share_alter->tmp_tgt_default_groups + share->all_link_count; |
| 3050 | memcpy(share_alter->tmp_static_link_ids, share->static_link_ids, |
| 3051 | sizeof(char *) * share->all_link_count); |
| 3052 | |
| 3053 | memcpy(share_alter->tmp_tgt_ports, share->tgt_ports, |
| 3054 | sizeof(long) * share->all_link_count); |
| 3055 | memcpy(share_alter->tmp_tgt_ssl_vscs, share->tgt_ssl_vscs, |
| 3056 | sizeof(long) * share->all_link_count); |
| 3057 | memcpy(share_alter->tmp_monitoring_binlog_pos_at_failing, |
| 3058 | share->monitoring_binlog_pos_at_failing, |
| 3059 | sizeof(long) * share->all_link_count); |
| 3060 | memcpy(share_alter->tmp_link_statuses, share->link_statuses, |
| 3061 | sizeof(long) * share->all_link_count); |
| 3062 | |
| 3063 | memcpy(share_alter->tmp_server_names_lengths, |
| 3064 | share->server_names_lengths, |
| 3065 | sizeof(uint) * share->all_link_count); |
| 3066 | share_alter->tmp_tgt_table_names_lengths = |
| 3067 | share_alter->tmp_server_names_lengths + share->all_link_count; |
| 3068 | memcpy(share_alter->tmp_tgt_table_names_lengths, |
| 3069 | share->tgt_table_names_lengths, |
| 3070 | sizeof(uint) * share->all_link_count); |
| 3071 | share_alter->tmp_tgt_dbs_lengths = |
| 3072 | share_alter->tmp_tgt_table_names_lengths + share->all_link_count; |
| 3073 | memcpy(share_alter->tmp_tgt_dbs_lengths, share->tgt_dbs_lengths, |
| 3074 | sizeof(uint) * share->all_link_count); |
| 3075 | share_alter->tmp_tgt_hosts_lengths = |
| 3076 | share_alter->tmp_tgt_dbs_lengths + share->all_link_count; |
| 3077 | memcpy(share_alter->tmp_tgt_hosts_lengths, share->tgt_hosts_lengths, |
| 3078 | sizeof(uint) * share->all_link_count); |
| 3079 | share_alter->tmp_tgt_usernames_lengths = |
| 3080 | share_alter->tmp_tgt_hosts_lengths + share->all_link_count; |
| 3081 | memcpy(share_alter->tmp_tgt_usernames_lengths, |
| 3082 | share->tgt_usernames_lengths, |
| 3083 | sizeof(uint) * share->all_link_count); |
| 3084 | share_alter->tmp_tgt_passwords_lengths = |
| 3085 | share_alter->tmp_tgt_usernames_lengths + share->all_link_count; |
| 3086 | memcpy(share_alter->tmp_tgt_passwords_lengths, |
| 3087 | share->tgt_passwords_lengths, |
| 3088 | sizeof(uint) * share->all_link_count); |
| 3089 | share_alter->tmp_tgt_sockets_lengths = |
| 3090 | share_alter->tmp_tgt_passwords_lengths + share->all_link_count; |
| 3091 | memcpy(share_alter->tmp_tgt_sockets_lengths, share->tgt_sockets_lengths, |
| 3092 | sizeof(uint) * share->all_link_count); |
| 3093 | share_alter->tmp_tgt_wrappers_lengths = |
| 3094 | share_alter->tmp_tgt_sockets_lengths + share->all_link_count; |
| 3095 | memcpy(share_alter->tmp_tgt_wrappers_lengths, |
| 3096 | share->tgt_wrappers_lengths, |
| 3097 | sizeof(uint) * share->all_link_count); |
| 3098 | share_alter->tmp_tgt_ssl_cas_lengths = |
| 3099 | share_alter->tmp_tgt_wrappers_lengths + share->all_link_count; |
| 3100 | memcpy(share_alter->tmp_tgt_ssl_cas_lengths, |
| 3101 | share->tgt_ssl_cas_lengths, |
| 3102 | sizeof(uint) * share->all_link_count); |
| 3103 | share_alter->tmp_tgt_ssl_capaths_lengths = |
| 3104 | share_alter->tmp_tgt_ssl_cas_lengths + share->all_link_count; |
| 3105 | memcpy(share_alter->tmp_tgt_ssl_capaths_lengths, |
| 3106 | share->tgt_ssl_capaths_lengths, |
| 3107 | sizeof(uint) * share->all_link_count); |
| 3108 | share_alter->tmp_tgt_ssl_certs_lengths = |
| 3109 | share_alter->tmp_tgt_ssl_capaths_lengths + share->all_link_count; |
| 3110 | memcpy(share_alter->tmp_tgt_ssl_certs_lengths, |
| 3111 | share->tgt_ssl_certs_lengths, |
| 3112 | sizeof(uint) * share->all_link_count); |
| 3113 | share_alter->tmp_tgt_ssl_ciphers_lengths = |
| 3114 | share_alter->tmp_tgt_ssl_certs_lengths + share->all_link_count; |
| 3115 | memcpy(share_alter->tmp_tgt_ssl_ciphers_lengths, |
| 3116 | share->tgt_ssl_ciphers_lengths, |
| 3117 | sizeof(uint) * share->all_link_count); |
| 3118 | share_alter->tmp_tgt_ssl_keys_lengths = |
| 3119 | share_alter->tmp_tgt_ssl_ciphers_lengths + share->all_link_count; |
| 3120 | memcpy(share_alter->tmp_tgt_ssl_keys_lengths, |
| 3121 | share->tgt_ssl_keys_lengths, |
| 3122 | sizeof(uint) * share->all_link_count); |
| 3123 | share_alter->tmp_tgt_default_files_lengths = |
| 3124 | share_alter->tmp_tgt_ssl_keys_lengths + share->all_link_count; |
| 3125 | memcpy(share_alter->tmp_tgt_default_files_lengths, |
| 3126 | share->tgt_default_files_lengths, |
| 3127 | sizeof(uint) * share->all_link_count); |
| 3128 | share_alter->tmp_tgt_default_groups_lengths = |
| 3129 | share_alter->tmp_tgt_default_files_lengths + share->all_link_count; |
| 3130 | memcpy(share_alter->tmp_tgt_default_groups_lengths, |
| 3131 | share->tgt_default_groups_lengths, |
| 3132 | sizeof(uint) * share->all_link_count); |
| 3133 | share_alter->tmp_static_link_ids_lengths = |
| 3134 | share_alter->tmp_tgt_default_groups_lengths + share->all_link_count; |
| 3135 | memcpy(share_alter->tmp_static_link_ids_lengths, |
| 3136 | share->static_link_ids_lengths, |
| 3137 | sizeof(uint) * share->all_link_count); |
| 3138 | |
| 3139 | share_alter->tmp_server_names_charlen = share->server_names_charlen; |
| 3140 | share_alter->tmp_tgt_table_names_charlen = share->tgt_table_names_charlen; |
| 3141 | share_alter->tmp_tgt_dbs_charlen = share->tgt_dbs_charlen; |
| 3142 | share_alter->tmp_tgt_hosts_charlen = share->tgt_hosts_charlen; |
| 3143 | share_alter->tmp_tgt_usernames_charlen = share->tgt_usernames_charlen; |
| 3144 | share_alter->tmp_tgt_passwords_charlen = share->tgt_passwords_charlen; |
| 3145 | share_alter->tmp_tgt_sockets_charlen = share->tgt_sockets_charlen; |
| 3146 | share_alter->tmp_tgt_wrappers_charlen = share->tgt_wrappers_charlen; |
| 3147 | share_alter->tmp_tgt_ssl_cas_charlen = share->tgt_ssl_cas_charlen; |
| 3148 | share_alter->tmp_tgt_ssl_capaths_charlen = share->tgt_ssl_capaths_charlen; |
| 3149 | share_alter->tmp_tgt_ssl_certs_charlen = share->tgt_ssl_certs_charlen; |
| 3150 | share_alter->tmp_tgt_ssl_ciphers_charlen = share->tgt_ssl_ciphers_charlen; |
| 3151 | share_alter->tmp_tgt_ssl_keys_charlen = share->tgt_ssl_keys_charlen; |
| 3152 | share_alter->tmp_tgt_default_files_charlen = |
| 3153 | share->tgt_default_files_charlen; |
| 3154 | share_alter->tmp_tgt_default_groups_charlen = |
| 3155 | share->tgt_default_groups_charlen; |
| 3156 | share_alter->tmp_static_link_ids_charlen = |
| 3157 | share->static_link_ids_charlen; |
| 3158 | |
| 3159 | share_alter->tmp_server_names_length = share->server_names_length; |
| 3160 | share_alter->tmp_tgt_table_names_length = share->tgt_table_names_length; |
| 3161 | share_alter->tmp_tgt_dbs_length = share->tgt_dbs_length; |
| 3162 | share_alter->tmp_tgt_hosts_length = share->tgt_hosts_length; |
| 3163 | share_alter->tmp_tgt_usernames_length = share->tgt_usernames_length; |
| 3164 | share_alter->tmp_tgt_passwords_length = share->tgt_passwords_length; |
| 3165 | share_alter->tmp_tgt_sockets_length = share->tgt_sockets_length; |
| 3166 | share_alter->tmp_tgt_wrappers_length = share->tgt_wrappers_length; |
| 3167 | share_alter->tmp_tgt_ssl_cas_length = share->tgt_ssl_cas_length; |
| 3168 | share_alter->tmp_tgt_ssl_capaths_length = share->tgt_ssl_capaths_length; |
| 3169 | share_alter->tmp_tgt_ssl_certs_length = share->tgt_ssl_certs_length; |
| 3170 | share_alter->tmp_tgt_ssl_ciphers_length = share->tgt_ssl_ciphers_length; |
| 3171 | share_alter->tmp_tgt_ssl_keys_length = share->tgt_ssl_keys_length; |
| 3172 | share_alter->tmp_tgt_default_files_length = share->tgt_default_files_length; |
| 3173 | share_alter->tmp_tgt_default_groups_length = |
| 3174 | share->tgt_default_groups_length; |
| 3175 | share_alter->tmp_static_link_ids_length = |
| 3176 | share->static_link_ids_length; |
| 3177 | share_alter->tmp_tgt_ports_length = share->tgt_ports_length; |
| 3178 | share_alter->tmp_tgt_ssl_vscs_length = share->tgt_ssl_vscs_length; |
| 3179 | share_alter->tmp_monitoring_binlog_pos_at_failing_length = |
| 3180 | share->monitoring_binlog_pos_at_failing_length; |
| 3181 | share_alter->tmp_link_statuses_length = share->link_statuses_length; |
| 3182 | /* copy for tables end */ |
| 3183 | |
| 3184 | if ((error_num = spider_set_connect_info_default( |
| 3185 | share, |
| 3186 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 3187 | part_elem, |
| 3188 | sub_elem, |
| 3189 | #endif |
| 3190 | table_share |
| 3191 | ))) |
| 3192 | goto error; |
| 3193 | |
| 3194 | if (create_table) |
| 3195 | { |
| 3196 | for (roop_count = 0; roop_count < (int) share->all_link_count; |
| 3197 | roop_count++) |
| 3198 | { |
| 3199 | int roop_count2; |
| 3200 | for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++) |
| 3201 | { |
| 3202 | if ( |
| 3203 | spider_dbton[roop_count2].wrapper && |
| 3204 | !strcmp(share->tgt_wrappers[roop_count], |
| 3205 | spider_dbton[roop_count2].wrapper) |
| 3206 | ) { |
| 3207 | break; |
| 3208 | } |
| 3209 | } |
| 3210 | if (roop_count2 == SPIDER_DBTON_SIZE) |
| 3211 | { |
| 3212 | DBUG_PRINT("info" ,("spider err tgt_wrappers[%d]=%s" , roop_count, |
| 3213 | share->tgt_wrappers[roop_count])); |
| 3214 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; |
| 3215 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, |
| 3216 | MYF(0), share->tgt_wrappers[roop_count]); |
| 3217 | goto error; |
| 3218 | } |
| 3219 | |
| 3220 | DBUG_PRINT("info" , |
| 3221 | ("spider server_names_lengths[%d] = %u" , roop_count, |
| 3222 | share->server_names_lengths[roop_count])); |
| 3223 | if (share->server_names_lengths[roop_count] > SPIDER_CONNECT_INFO_MAX_LEN) |
| 3224 | { |
| 3225 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; |
| 3226 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, |
| 3227 | MYF(0), share->server_names[roop_count], "server" ); |
| 3228 | goto error; |
| 3229 | } |
| 3230 | |
| 3231 | DBUG_PRINT("info" , |
| 3232 | ("spider tgt_table_names_lengths[%d] = %u" , roop_count, |
| 3233 | share->tgt_table_names_lengths[roop_count])); |
| 3234 | if (share->tgt_table_names_lengths[roop_count] > |
| 3235 | SPIDER_CONNECT_INFO_MAX_LEN) |
| 3236 | { |
| 3237 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; |
| 3238 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, |
| 3239 | MYF(0), share->tgt_table_names[roop_count], "table" ); |
| 3240 | goto error; |
| 3241 | } |
| 3242 | |
| 3243 | DBUG_PRINT("info" , |
| 3244 | ("spider tgt_dbs_lengths[%d] = %u" , roop_count, |
| 3245 | share->tgt_dbs_lengths[roop_count])); |
| 3246 | if (share->tgt_dbs_lengths[roop_count] > SPIDER_CONNECT_INFO_MAX_LEN) |
| 3247 | { |
| 3248 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; |
| 3249 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, |
| 3250 | MYF(0), share->tgt_dbs[roop_count], "database" ); |
| 3251 | goto error; |
| 3252 | } |
| 3253 | |
| 3254 | DBUG_PRINT("info" , |
| 3255 | ("spider tgt_hosts_lengths[%d] = %u" , roop_count, |
| 3256 | share->tgt_hosts_lengths[roop_count])); |
| 3257 | if (share->tgt_hosts_lengths[roop_count] > SPIDER_CONNECT_INFO_MAX_LEN) |
| 3258 | { |
| 3259 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; |
| 3260 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, |
| 3261 | MYF(0), share->tgt_hosts[roop_count], "host" ); |
| 3262 | goto error; |
| 3263 | } |
| 3264 | |
| 3265 | DBUG_PRINT("info" , |
| 3266 | ("spider tgt_usernames_lengths[%d] = %u" , roop_count, |
| 3267 | share->tgt_usernames_lengths[roop_count])); |
| 3268 | if (share->tgt_usernames_lengths[roop_count] > |
| 3269 | SPIDER_CONNECT_INFO_MAX_LEN) |
| 3270 | { |
| 3271 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; |
| 3272 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, |
| 3273 | MYF(0), share->tgt_usernames[roop_count], "user" ); |
| 3274 | goto error; |
| 3275 | } |
| 3276 | |
| 3277 | DBUG_PRINT("info" , |
| 3278 | ("spider tgt_passwords_lengths[%d] = %u" , roop_count, |
| 3279 | share->tgt_passwords_lengths[roop_count])); |
| 3280 | if (share->tgt_passwords_lengths[roop_count] > |
| 3281 | SPIDER_CONNECT_INFO_MAX_LEN) |
| 3282 | { |
| 3283 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; |
| 3284 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, |
| 3285 | MYF(0), share->tgt_passwords[roop_count], "password" ); |
| 3286 | goto error; |
| 3287 | } |
| 3288 | |
| 3289 | DBUG_PRINT("info" , |
| 3290 | ("spider tgt_sockets_lengths[%d] = %u" , roop_count, |
| 3291 | share->tgt_sockets_lengths[roop_count])); |
| 3292 | if (share->tgt_sockets_lengths[roop_count] > |
| 3293 | SPIDER_CONNECT_INFO_PATH_MAX_LEN) |
| 3294 | { |
| 3295 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; |
| 3296 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, |
| 3297 | MYF(0), share->tgt_sockets[roop_count], "socket" ); |
| 3298 | goto error; |
| 3299 | } |
| 3300 | |
| 3301 | DBUG_PRINT("info" , |
| 3302 | ("spider tgt_wrappers_lengths[%d] = %u" , roop_count, |
| 3303 | share->tgt_wrappers_lengths[roop_count])); |
| 3304 | if (share->tgt_wrappers_lengths[roop_count] > |
| 3305 | SPIDER_CONNECT_INFO_MAX_LEN) |
| 3306 | { |
| 3307 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; |
| 3308 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, |
| 3309 | MYF(0), share->tgt_wrappers[roop_count], "wrapper" ); |
| 3310 | goto error; |
| 3311 | } |
| 3312 | |
| 3313 | DBUG_PRINT("info" , |
| 3314 | ("spider tgt_ssl_cas_lengths[%d] = %u" , roop_count, |
| 3315 | share->tgt_ssl_cas_lengths[roop_count])); |
| 3316 | if (share->tgt_ssl_cas_lengths[roop_count] > |
| 3317 | SPIDER_CONNECT_INFO_PATH_MAX_LEN) |
| 3318 | { |
| 3319 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; |
| 3320 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, |
| 3321 | MYF(0), share->tgt_ssl_cas[roop_count], "ssl_ca" ); |
| 3322 | goto error; |
| 3323 | } |
| 3324 | |
| 3325 | DBUG_PRINT("info" , |
| 3326 | ("spider tgt_ssl_capaths_lengths[%d] = %u" , roop_count, |
| 3327 | share->tgt_ssl_capaths_lengths[roop_count])); |
| 3328 | if (share->tgt_ssl_capaths_lengths[roop_count] > |
| 3329 | SPIDER_CONNECT_INFO_PATH_MAX_LEN) |
| 3330 | { |
| 3331 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; |
| 3332 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, |
| 3333 | MYF(0), share->tgt_ssl_capaths[roop_count], "ssl_capath" ); |
| 3334 | goto error; |
| 3335 | } |
| 3336 | |
| 3337 | DBUG_PRINT("info" , |
| 3338 | ("spider tgt_ssl_certs_lengths[%d] = %u" , roop_count, |
| 3339 | share->tgt_ssl_certs_lengths[roop_count])); |
| 3340 | if (share->tgt_ssl_certs_lengths[roop_count] > |
| 3341 | SPIDER_CONNECT_INFO_PATH_MAX_LEN) |
| 3342 | { |
| 3343 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; |
| 3344 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, |
| 3345 | MYF(0), share->tgt_ssl_certs[roop_count], "ssl_cert" ); |
| 3346 | goto error; |
| 3347 | } |
| 3348 | |
| 3349 | DBUG_PRINT("info" , |
| 3350 | ("spider tgt_ssl_ciphers_lengths[%d] = %u" , roop_count, |
| 3351 | share->tgt_ssl_ciphers_lengths[roop_count])); |
| 3352 | if (share->tgt_ssl_ciphers_lengths[roop_count] > |
| 3353 | 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_ssl_ciphers[roop_count], "ssl_cipher" ); |
| 3358 | goto error; |
| 3359 | } |
| 3360 | |
| 3361 | DBUG_PRINT("info" , |
| 3362 | ("spider tgt_ssl_keys_lengths[%d] = %u" , roop_count, |
| 3363 | share->tgt_ssl_keys_lengths[roop_count])); |
| 3364 | if (share->tgt_ssl_keys_lengths[roop_count] > |
| 3365 | SPIDER_CONNECT_INFO_PATH_MAX_LEN) |
| 3366 | { |
| 3367 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; |
| 3368 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, |
| 3369 | MYF(0), share->tgt_ssl_keys[roop_count], "ssl_key" ); |
| 3370 | goto error; |
| 3371 | } |
| 3372 | |
| 3373 | DBUG_PRINT("info" , |
| 3374 | ("spider tgt_default_files_lengths[%d] = %u" , roop_count, |
| 3375 | share->tgt_default_files_lengths[roop_count])); |
| 3376 | if (share->tgt_default_files_lengths[roop_count] > |
| 3377 | SPIDER_CONNECT_INFO_PATH_MAX_LEN) |
| 3378 | { |
| 3379 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; |
| 3380 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, |
| 3381 | MYF(0), share->tgt_default_files[roop_count], "default_file" ); |
| 3382 | goto error; |
| 3383 | } |
| 3384 | |
| 3385 | DBUG_PRINT("info" , |
| 3386 | ("spider tgt_default_groups_lengths[%d] = %u" , roop_count, |
| 3387 | share->tgt_default_groups_lengths[roop_count])); |
| 3388 | if (share->tgt_default_groups_lengths[roop_count] > |
| 3389 | SPIDER_CONNECT_INFO_MAX_LEN) |
| 3390 | { |
| 3391 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; |
| 3392 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, |
| 3393 | MYF(0), share->tgt_default_groups[roop_count], "default_group" ); |
| 3394 | goto error; |
| 3395 | } |
| 3396 | |
| 3397 | DBUG_PRINT("info" , |
| 3398 | ("spider tgt_pk_names_lengths[%d] = %u" , roop_count, |
| 3399 | share->tgt_pk_names_lengths[roop_count])); |
| 3400 | if (share->tgt_pk_names_lengths[roop_count] > |
| 3401 | SPIDER_CONNECT_INFO_MAX_LEN) |
| 3402 | { |
| 3403 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; |
| 3404 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, |
| 3405 | MYF(0), share->tgt_pk_names[roop_count], "pk_name" ); |
| 3406 | goto error; |
| 3407 | } |
| 3408 | |
| 3409 | DBUG_PRINT("info" , |
| 3410 | ("spider tgt_sequence_names_lengths[%d] = %u" , roop_count, |
| 3411 | share->tgt_sequence_names_lengths[roop_count])); |
| 3412 | if (share->tgt_sequence_names_lengths[roop_count] > |
| 3413 | SPIDER_CONNECT_INFO_MAX_LEN) |
| 3414 | { |
| 3415 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; |
| 3416 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, |
| 3417 | MYF(0), share->tgt_sequence_names[roop_count], "sequence_name" ); |
| 3418 | goto error; |
| 3419 | } |
| 3420 | |
| 3421 | DBUG_PRINT("info" , |
| 3422 | ("spider static_link_ids_lengths[%d] = %u" , roop_count, |
| 3423 | share->static_link_ids_lengths[roop_count])); |
| 3424 | if (share->static_link_ids_lengths[roop_count] > |
| 3425 | SPIDER_CONNECT_INFO_MAX_LEN) |
| 3426 | { |
| 3427 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM; |
| 3428 | my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR, |
| 3429 | MYF(0), share->static_link_ids[roop_count], "static_link_id" ); |
| 3430 | goto error; |
| 3431 | } |
| 3432 | if (share->static_link_ids[roop_count]) |
| 3433 | { |
| 3434 | if ( |
| 3435 | share->static_link_ids_lengths[roop_count] > 0 && |
| 3436 | share->static_link_ids[roop_count][0] >= '0' && |
| 3437 | share->static_link_ids[roop_count][0] <= '9' |
| 3438 | ) { |
| 3439 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_START_WITH_NUM_NUM; |
| 3440 | my_printf_error(error_num, |
| 3441 | ER_SPIDER_INVALID_CONNECT_INFO_START_WITH_NUM_STR, |
| 3442 | MYF(0), share->static_link_ids[roop_count], "static_link_id" ); |
| 3443 | goto error; |
| 3444 | } |
| 3445 | for (roop_count2 = roop_count + 1; |
| 3446 | roop_count2 < (int) share->all_link_count; |
| 3447 | roop_count2++) |
| 3448 | { |
| 3449 | if ( |
| 3450 | share->static_link_ids_lengths[roop_count] == |
| 3451 | share->static_link_ids_lengths[roop_count2] && |
| 3452 | !memcmp(share->static_link_ids[roop_count], |
| 3453 | share->static_link_ids[roop_count2], |
| 3454 | share->static_link_ids_lengths[roop_count]) |
| 3455 | ) { |
| 3456 | error_num = ER_SPIDER_INVALID_CONNECT_INFO_SAME_NUM; |
| 3457 | my_printf_error(error_num, |
| 3458 | ER_SPIDER_INVALID_CONNECT_INFO_SAME_STR, |
| 3459 | MYF(0), share->static_link_ids[roop_count], |
| 3460 | "static_link_id" ); |
| 3461 | goto error; |
| 3462 | } |
| 3463 | } |
| 3464 | } |
| 3465 | } |
| 3466 | } |
| 3467 | |
| 3468 | DBUG_PRINT("info" , ("spider share->active_link_count = %d" , |
| 3469 | share->active_link_count)); |
| 3470 | share->link_count = (uint) share->active_link_count; |
| 3471 | share_alter->link_count = share->link_count; |
| 3472 | share->link_bitmap_size = (share->link_count + 7) / 8; |
| 3473 | |
| 3474 | if (connect_string) |
| 3475 | spider_free(spider_current_trx, connect_string, MYF(0)); |
| 3476 | DBUG_RETURN(0); |
| 3477 | |
| 3478 | error: |
| 3479 | if (connect_string) |
| 3480 | spider_free(spider_current_trx, connect_string, MYF(0)); |
| 3481 | error_alloc_conn_string: |
| 3482 | DBUG_RETURN(error_num); |
| 3483 | } |
| 3484 | |
| 3485 | int spider_set_connect_info_default( |
| 3486 | SPIDER_SHARE *share, |
| 3487 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 3488 | partition_element *part_elem, |
| 3489 | partition_element *sub_elem, |
| 3490 | #endif |
| 3491 | TABLE_SHARE *table_share |
| 3492 | ) { |
| 3493 | int error_num, roop_count; |
| 3494 | DBUG_ENTER("spider_set_connect_info_default" ); |
| 3495 | for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++) |
| 3496 | { |
| 3497 | if (share->server_names[roop_count]) |
| 3498 | { |
| 3499 | if ((error_num = spider_get_server(share, roop_count))) |
| 3500 | DBUG_RETURN(error_num); |
| 3501 | } |
| 3502 | |
| 3503 | if (!share->tgt_wrappers[roop_count]) |
| 3504 | { |
| 3505 | DBUG_PRINT("info" ,("spider create default tgt_wrappers" )); |
| 3506 | share->tgt_wrappers_lengths[roop_count] = SPIDER_DB_WRAPPER_LEN; |
| 3507 | if ( |
| 3508 | !(share->tgt_wrappers[roop_count] = spider_create_string( |
| 3509 | SPIDER_DB_WRAPPER_STR, |
| 3510 | share->tgt_wrappers_lengths[roop_count])) |
| 3511 | ) { |
| 3512 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 3513 | } |
| 3514 | } |
| 3515 | |
| 3516 | if (!share->tgt_hosts[roop_count]) |
| 3517 | { |
| 3518 | DBUG_PRINT("info" ,("spider create default tgt_hosts" )); |
| 3519 | share->tgt_hosts_lengths[roop_count] = strlen(my_localhost); |
| 3520 | if ( |
| 3521 | !(share->tgt_hosts[roop_count] = spider_create_string( |
| 3522 | my_localhost, |
| 3523 | share->tgt_hosts_lengths[roop_count])) |
| 3524 | ) { |
| 3525 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 3526 | } |
| 3527 | } |
| 3528 | |
| 3529 | if (!share->tgt_dbs[roop_count] && table_share) |
| 3530 | { |
| 3531 | DBUG_PRINT("info" ,("spider create default tgt_dbs" )); |
| 3532 | share->tgt_dbs_lengths[roop_count] = table_share->db.length; |
| 3533 | if ( |
| 3534 | !(share->tgt_dbs[roop_count] = spider_create_string( |
| 3535 | table_share->db.str, |
| 3536 | table_share->db.length)) |
| 3537 | ) { |
| 3538 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 3539 | } |
| 3540 | } |
| 3541 | |
| 3542 | if (!share->tgt_table_names[roop_count] && table_share) |
| 3543 | { |
| 3544 | DBUG_PRINT("info" ,("spider create default tgt_table_names" )); |
| 3545 | share->tgt_table_names_lengths[roop_count] = share->table_name_length; |
| 3546 | if ( |
| 3547 | !(share->tgt_table_names[roop_count] = spider_create_table_name_string( |
| 3548 | table_share->table_name.str, |
| 3549 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 3550 | (part_elem ? part_elem->partition_name : NULL), |
| 3551 | (sub_elem ? sub_elem->partition_name : NULL) |
| 3552 | #else |
| 3553 | NULL, |
| 3554 | NULL |
| 3555 | #endif |
| 3556 | )) |
| 3557 | ) { |
| 3558 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 3559 | } |
| 3560 | } |
| 3561 | |
| 3562 | if ( |
| 3563 | !share->tgt_default_files[roop_count] && |
| 3564 | share->tgt_default_groups[roop_count] && |
| 3565 | (*spd_defaults_file || *spd_defaults_extra_file) |
| 3566 | ) { |
| 3567 | DBUG_PRINT("info" ,("spider create default tgt_default_files" )); |
| 3568 | if (*spd_defaults_extra_file) |
| 3569 | { |
| 3570 | share->tgt_default_files_lengths[roop_count] = |
| 3571 | strlen(*spd_defaults_extra_file); |
| 3572 | if ( |
| 3573 | !(share->tgt_default_files[roop_count] = spider_create_string( |
| 3574 | *spd_defaults_extra_file, |
| 3575 | share->tgt_default_files_lengths[roop_count])) |
| 3576 | ) { |
| 3577 | my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); |
| 3578 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 3579 | } |
| 3580 | } else { |
| 3581 | share->tgt_default_files_lengths[roop_count] = |
| 3582 | strlen(*spd_defaults_file); |
| 3583 | if ( |
| 3584 | !(share->tgt_default_files[roop_count] = spider_create_string( |
| 3585 | *spd_defaults_file, |
| 3586 | share->tgt_default_files_lengths[roop_count])) |
| 3587 | ) { |
| 3588 | my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); |
| 3589 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 3590 | } |
| 3591 | } |
| 3592 | } |
| 3593 | |
| 3594 | if (!share->tgt_pk_names[roop_count]) |
| 3595 | { |
| 3596 | DBUG_PRINT("info" ,("spider create default tgt_pk_names" )); |
| 3597 | share->tgt_pk_names_lengths[roop_count] = SPIDER_DB_PK_NAME_LEN; |
| 3598 | if ( |
| 3599 | !(share->tgt_pk_names[roop_count] = spider_create_string( |
| 3600 | SPIDER_DB_PK_NAME_STR, |
| 3601 | share->tgt_pk_names_lengths[roop_count])) |
| 3602 | ) { |
| 3603 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 3604 | } |
| 3605 | } |
| 3606 | |
| 3607 | if (!share->tgt_sequence_names[roop_count]) |
| 3608 | { |
| 3609 | DBUG_PRINT("info" ,("spider create default tgt_sequence_names" )); |
| 3610 | share->tgt_sequence_names_lengths[roop_count] = |
| 3611 | SPIDER_DB_SEQUENCE_NAME_LEN; |
| 3612 | if ( |
| 3613 | !(share->tgt_sequence_names[roop_count] = spider_create_string( |
| 3614 | SPIDER_DB_SEQUENCE_NAME_STR, |
| 3615 | share->tgt_sequence_names_lengths[roop_count])) |
| 3616 | ) { |
| 3617 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 3618 | } |
| 3619 | } |
| 3620 | |
| 3621 | /* |
| 3622 | if (!share->static_link_ids[roop_count]) |
| 3623 | { |
| 3624 | DBUG_PRINT("info",("spider create default static_link_ids")); |
| 3625 | share->static_link_ids_lengths[roop_count] = |
| 3626 | SPIDER_DB_STATIC_LINK_ID_LEN; |
| 3627 | if ( |
| 3628 | !(share->static_link_ids[roop_count] = spider_create_string( |
| 3629 | SPIDER_DB_STATIC_LINK_ID_STR, |
| 3630 | share->static_link_ids_lengths[roop_count])) |
| 3631 | ) { |
| 3632 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 3633 | } |
| 3634 | } |
| 3635 | */ |
| 3636 | |
| 3637 | if (share->tgt_ports[roop_count] == -1) |
| 3638 | { |
| 3639 | share->tgt_ports[roop_count] = MYSQL_PORT; |
| 3640 | } else if (share->tgt_ports[roop_count] < 0) |
| 3641 | { |
| 3642 | share->tgt_ports[roop_count] = 0; |
| 3643 | } else if (share->tgt_ports[roop_count] > 65535) |
| 3644 | { |
| 3645 | share->tgt_ports[roop_count] = 65535; |
| 3646 | } |
| 3647 | |
| 3648 | if (share->tgt_ssl_vscs[roop_count] == -1) |
| 3649 | share->tgt_ssl_vscs[roop_count] = 0; |
| 3650 | |
| 3651 | if ( |
| 3652 | !share->tgt_sockets[roop_count] && |
| 3653 | !strcmp(share->tgt_hosts[roop_count], my_localhost) |
| 3654 | ) { |
| 3655 | DBUG_PRINT("info" ,("spider create default tgt_sockets" )); |
| 3656 | share->tgt_sockets_lengths[roop_count] = |
| 3657 | strlen((char *) MYSQL_UNIX_ADDR); |
| 3658 | if ( |
| 3659 | !(share->tgt_sockets[roop_count] = spider_create_string( |
| 3660 | (char *) MYSQL_UNIX_ADDR, |
| 3661 | share->tgt_sockets_lengths[roop_count])) |
| 3662 | ) { |
| 3663 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 3664 | } |
| 3665 | } |
| 3666 | |
| 3667 | if (share->link_statuses[roop_count] == -1) |
| 3668 | share->link_statuses[roop_count] = SPIDER_LINK_STATUS_NO_CHANGE; |
| 3669 | |
| 3670 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 3671 | if (share->monitoring_bg_flag[roop_count] == -1) |
| 3672 | share->monitoring_bg_flag[roop_count] = 0; |
| 3673 | if (share->monitoring_bg_kind[roop_count] == -1) |
| 3674 | share->monitoring_bg_kind[roop_count] = 0; |
| 3675 | #endif |
| 3676 | if (share->monitoring_binlog_pos_at_failing[roop_count] == -1) |
| 3677 | share->monitoring_binlog_pos_at_failing[roop_count] = 0; |
| 3678 | if (share->monitoring_flag[roop_count] == -1) |
| 3679 | share->monitoring_flag[roop_count] = 0; |
| 3680 | if (share->monitoring_kind[roop_count] == -1) |
| 3681 | share->monitoring_kind[roop_count] = 0; |
| 3682 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 3683 | if (share->monitoring_bg_interval[roop_count] == -1) |
| 3684 | share->monitoring_bg_interval[roop_count] = 10000000; |
| 3685 | #endif |
| 3686 | if (share->monitoring_limit[roop_count] == -1) |
| 3687 | share->monitoring_limit[roop_count] = 1; |
| 3688 | if (share->monitoring_sid[roop_count] == -1) |
| 3689 | #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002 |
| 3690 | share->monitoring_sid[roop_count] = global_system_variables.server_id; |
| 3691 | #else |
| 3692 | share->monitoring_sid[roop_count] = current_thd->server_id; |
| 3693 | #endif |
| 3694 | |
| 3695 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 3696 | if (share->use_hs_reads[roop_count] == -1) |
| 3697 | share->use_hs_reads[roop_count] = 0; |
| 3698 | if (share->use_hs_writes[roop_count] == -1) |
| 3699 | share->use_hs_writes[roop_count] = 0; |
| 3700 | if (share->hs_read_ports[roop_count] == -1) |
| 3701 | { |
| 3702 | share->hs_read_ports[roop_count] = 9998; |
| 3703 | } else if (share->hs_read_ports[roop_count] < 0) |
| 3704 | { |
| 3705 | share->hs_read_ports[roop_count] = 0; |
| 3706 | } else if (share->hs_read_ports[roop_count] > 65535) |
| 3707 | { |
| 3708 | share->hs_read_ports[roop_count] = 65535; |
| 3709 | } |
| 3710 | if (share->hs_write_ports[roop_count] == -1) |
| 3711 | { |
| 3712 | share->hs_write_ports[roop_count] = 9999; |
| 3713 | } else if (share->hs_write_ports[roop_count] < 0) |
| 3714 | { |
| 3715 | share->hs_write_ports[roop_count] = 0; |
| 3716 | } else if (share->hs_write_ports[roop_count] > 65535) |
| 3717 | { |
| 3718 | share->hs_write_ports[roop_count] = 65535; |
| 3719 | } |
| 3720 | if (share->hs_write_to_reads[roop_count] == -1) |
| 3721 | { |
| 3722 | share->hs_write_to_reads[roop_count] = 1; |
| 3723 | } else if (share->hs_write_to_reads[roop_count] < 0) |
| 3724 | { |
| 3725 | share->hs_write_to_reads[roop_count] = 0; |
| 3726 | } else if (share->hs_write_to_reads[roop_count] > 1) |
| 3727 | { |
| 3728 | share->hs_write_to_reads[roop_count] = 1; |
| 3729 | } |
| 3730 | #endif |
| 3731 | if (share->use_handlers[roop_count] == -1) |
| 3732 | share->use_handlers[roop_count] = 0; |
| 3733 | if (share->connect_timeouts[roop_count] == -1) |
| 3734 | share->connect_timeouts[roop_count] = 6; |
| 3735 | if (share->net_read_timeouts[roop_count] == -1) |
| 3736 | share->net_read_timeouts[roop_count] = 600; |
| 3737 | if (share->net_write_timeouts[roop_count] == -1) |
| 3738 | share->net_write_timeouts[roop_count] = 600; |
| 3739 | if (share->access_balances[roop_count] == -1) |
| 3740 | share->access_balances[roop_count] = 100; |
| 3741 | if (share->bka_table_name_types[roop_count] == -1) |
| 3742 | share->bka_table_name_types[roop_count] = 0; |
| 3743 | } |
| 3744 | |
| 3745 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 3746 | if (share->sts_bg_mode == -1) |
| 3747 | share->sts_bg_mode = 2; |
| 3748 | #endif |
| 3749 | if (share->sts_interval == -1) |
| 3750 | share->sts_interval = 10; |
| 3751 | if (share->sts_mode == -1) |
| 3752 | share->sts_mode = 1; |
| 3753 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 3754 | if (share->sts_sync == -1) |
| 3755 | share->sts_sync = 0; |
| 3756 | #endif |
| 3757 | if (share->store_last_sts == -1) |
| 3758 | share->store_last_sts = 1; |
| 3759 | if (share->load_sts_at_startup == -1) |
| 3760 | share->load_sts_at_startup = 1; |
| 3761 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 3762 | if (share->crd_bg_mode == -1) |
| 3763 | share->crd_bg_mode = 2; |
| 3764 | #endif |
| 3765 | if (share->crd_interval == -1) |
| 3766 | share->crd_interval = 51; |
| 3767 | if (share->crd_mode == -1) |
| 3768 | share->crd_mode = 1; |
| 3769 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 3770 | if (share->crd_sync == -1) |
| 3771 | share->crd_sync = 0; |
| 3772 | #endif |
| 3773 | if (share->store_last_crd == -1) |
| 3774 | share->store_last_crd = 1; |
| 3775 | if (share->load_crd_at_startup == -1) |
| 3776 | share->load_crd_at_startup = 1; |
| 3777 | if (share->crd_type == -1) |
| 3778 | share->crd_type = 2; |
| 3779 | if (share->crd_weight == -1) |
| 3780 | share->crd_weight = 2; |
| 3781 | if (share->internal_offset == -1) |
| 3782 | share->internal_offset = 0; |
| 3783 | if (share->internal_limit == -1) |
| 3784 | share->internal_limit = 9223372036854775807LL; |
| 3785 | if (share->split_read == -1) |
| 3786 | share->split_read = 9223372036854775807LL; |
| 3787 | if (share->semi_split_read == -1) |
| 3788 | share->semi_split_read = 2; |
| 3789 | if (share->semi_split_read_limit == -1) |
| 3790 | share->semi_split_read_limit = 9223372036854775807LL; |
| 3791 | if (share->init_sql_alloc_size == -1) |
| 3792 | share->init_sql_alloc_size = 1024; |
| 3793 | if (share->reset_sql_alloc == -1) |
| 3794 | share->reset_sql_alloc = 1; |
| 3795 | if (share->multi_split_read == -1) |
| 3796 | share->multi_split_read = 100; |
| 3797 | if (share->max_order == -1) |
| 3798 | share->max_order = 32767; |
| 3799 | if (share->semi_table_lock == -1) |
| 3800 | share->semi_table_lock = 0; |
| 3801 | if (share->semi_table_lock_conn == -1) |
| 3802 | share->semi_table_lock_conn = 1; |
| 3803 | if (share->selupd_lock_mode == -1) |
| 3804 | share->selupd_lock_mode = 1; |
| 3805 | if (share->query_cache == -1) |
| 3806 | share->query_cache = 0; |
| 3807 | if (share->query_cache_sync == -1) |
| 3808 | share->query_cache_sync = 0; |
| 3809 | if (share->internal_delayed == -1) |
| 3810 | share->internal_delayed = 0; |
| 3811 | if (share->bulk_size == -1) |
| 3812 | share->bulk_size = 16000; |
| 3813 | if (share->bulk_update_mode == -1) |
| 3814 | share->bulk_update_mode = 0; |
| 3815 | if (share->bulk_update_size == -1) |
| 3816 | share->bulk_update_size = 16000; |
| 3817 | if (share->internal_optimize == -1) |
| 3818 | share->internal_optimize = 0; |
| 3819 | if (share->internal_optimize_local == -1) |
| 3820 | share->internal_optimize_local = 0; |
| 3821 | if (share->scan_rate == -1) |
| 3822 | share->scan_rate = 1; |
| 3823 | if (share->read_rate == -1) |
| 3824 | share->read_rate = 0.0002; |
| 3825 | if (share->priority == -1) |
| 3826 | share->priority = 1000000; |
| 3827 | if (share->quick_mode == -1) |
| 3828 | share->quick_mode = 0; |
| 3829 | if (share->quick_page_size == -1) |
| 3830 | share->quick_page_size = 100; |
| 3831 | if (share->low_mem_read == -1) |
| 3832 | share->low_mem_read = 1; |
| 3833 | if (share->table_count_mode == -1) |
| 3834 | share->table_count_mode = 0; |
| 3835 | if (share->select_column_mode == -1) |
| 3836 | share->select_column_mode = 1; |
| 3837 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 3838 | if (share->bgs_mode == -1) |
| 3839 | share->bgs_mode = 0; |
| 3840 | if (share->bgs_first_read == -1) |
| 3841 | share->bgs_first_read = 2; |
| 3842 | if (share->bgs_second_read == -1) |
| 3843 | share->bgs_second_read = 100; |
| 3844 | #endif |
| 3845 | if (share->first_read == -1) |
| 3846 | share->first_read = 0; |
| 3847 | if (share->second_read == -1) |
| 3848 | share->second_read = 0; |
| 3849 | if (share->auto_increment_mode == -1) |
| 3850 | share->auto_increment_mode = 0; |
| 3851 | if (share->use_table_charset == -1) |
| 3852 | share->use_table_charset = 1; |
| 3853 | if (share->use_pushdown_udf == -1) |
| 3854 | share->use_pushdown_udf = 1; |
| 3855 | if (share->skip_default_condition == -1) |
| 3856 | share->skip_default_condition = 0; |
| 3857 | if (share->skip_parallel_search == -1) |
| 3858 | share->skip_parallel_search = 0; |
| 3859 | if (share->direct_dup_insert == -1) |
| 3860 | share->direct_dup_insert = 0; |
| 3861 | if (share->direct_order_limit == -1) |
| 3862 | share->direct_order_limit = 9223372036854775807LL; |
| 3863 | if (share->read_only_mode == -1) |
| 3864 | share->read_only_mode = 0; |
| 3865 | if (share->error_read_mode == -1) |
| 3866 | share->error_read_mode = 0; |
| 3867 | if (share->error_write_mode == -1) |
| 3868 | share->error_write_mode = 0; |
| 3869 | if (share->active_link_count == -1) |
| 3870 | share->active_link_count = share->all_link_count; |
| 3871 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 3872 | if (share->hs_result_free_size == -1) |
| 3873 | share->hs_result_free_size = 1048576; |
| 3874 | #endif |
| 3875 | #ifdef HA_CAN_BULK_ACCESS |
| 3876 | if (share->bulk_access_free == -1) |
| 3877 | share->bulk_access_free = 0; |
| 3878 | #endif |
| 3879 | #ifdef HA_CAN_FORCE_BULK_UPDATE |
| 3880 | if (share->force_bulk_update == -1) |
| 3881 | share->force_bulk_update = 0; |
| 3882 | #endif |
| 3883 | #ifdef HA_CAN_FORCE_BULK_DELETE |
| 3884 | if (share->force_bulk_delete == -1) |
| 3885 | share->force_bulk_delete = 0; |
| 3886 | #endif |
| 3887 | if (share->casual_read == -1) |
| 3888 | share->casual_read = 0; |
| 3889 | if (share->delete_all_rows_type == -1) |
| 3890 | { |
| 3891 | #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS |
| 3892 | share->delete_all_rows_type = 1; |
| 3893 | #else |
| 3894 | share->delete_all_rows_type = 0; |
| 3895 | #endif |
| 3896 | } |
| 3897 | if (share->bka_mode == -1) |
| 3898 | share->bka_mode = 1; |
| 3899 | if (!share->bka_engine) |
| 3900 | { |
| 3901 | DBUG_PRINT("info" ,("spider create default bka_engine" )); |
| 3902 | share->bka_engine_length = SPIDER_SQL_TMP_BKA_ENGINE_LEN; |
| 3903 | if ( |
| 3904 | !(share->bka_engine = spider_create_string( |
| 3905 | SPIDER_SQL_TMP_BKA_ENGINE_STR, |
| 3906 | SPIDER_SQL_TMP_BKA_ENGINE_LEN)) |
| 3907 | ) { |
| 3908 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 3909 | } |
| 3910 | } |
| 3911 | DBUG_RETURN(0); |
| 3912 | } |
| 3913 | |
| 3914 | int spider_set_connect_info_default_db_table( |
| 3915 | SPIDER_SHARE *share, |
| 3916 | const char *db_name, |
| 3917 | uint db_name_length, |
| 3918 | const char *table_name, |
| 3919 | uint table_name_length |
| 3920 | ) { |
| 3921 | int roop_count; |
| 3922 | DBUG_ENTER("spider_set_connect_info_default_db_table" ); |
| 3923 | for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) |
| 3924 | { |
| 3925 | if (!share->tgt_dbs[roop_count] && db_name) |
| 3926 | { |
| 3927 | DBUG_PRINT("info" ,("spider create default tgt_dbs" )); |
| 3928 | share->tgt_dbs_lengths[roop_count] = db_name_length; |
| 3929 | if ( |
| 3930 | !(share->tgt_dbs[roop_count] = spider_create_string( |
| 3931 | db_name, |
| 3932 | db_name_length)) |
| 3933 | ) { |
| 3934 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 3935 | } |
| 3936 | } |
| 3937 | |
| 3938 | if (!share->tgt_table_names[roop_count] && table_name) |
| 3939 | { |
| 3940 | const char *tmp_ptr; |
| 3941 | DBUG_PRINT("info" ,("spider create default tgt_table_names" )); |
| 3942 | if ((tmp_ptr = strstr(table_name, "#P#" ))) |
| 3943 | table_name_length = (uint) PTR_BYTE_DIFF(tmp_ptr, table_name); |
| 3944 | share->tgt_table_names_lengths[roop_count] = table_name_length; |
| 3945 | if ( |
| 3946 | !(share->tgt_table_names[roop_count] = spider_create_string( |
| 3947 | table_name, |
| 3948 | table_name_length)) |
| 3949 | ) { |
| 3950 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 3951 | } |
| 3952 | } |
| 3953 | } |
| 3954 | DBUG_RETURN(0); |
| 3955 | } |
| 3956 | |
| 3957 | int spider_set_connect_info_default_dbtable( |
| 3958 | SPIDER_SHARE *share, |
| 3959 | const char *dbtable_name, |
| 3960 | int dbtable_name_length |
| 3961 | ) { |
| 3962 | const char *ptr_db, *ptr_table; |
| 3963 | my_ptrdiff_t ptr_diff_db, ptr_diff_table; |
| 3964 | DBUG_ENTER("spider_set_connect_info_default_dbtable" ); |
| 3965 | ptr_db = strchr(dbtable_name, FN_LIBCHAR); |
| 3966 | ptr_db++; |
| 3967 | ptr_diff_db = PTR_BYTE_DIFF(ptr_db, dbtable_name); |
| 3968 | DBUG_PRINT("info" ,("spider ptr_diff_db = %lld" , (longlong) ptr_diff_db)); |
| 3969 | ptr_table = strchr(ptr_db, FN_LIBCHAR); |
| 3970 | ptr_table++; |
| 3971 | ptr_diff_table = PTR_BYTE_DIFF(ptr_table, ptr_db); |
| 3972 | DBUG_PRINT("info" ,("spider ptr_diff_table = %lld" , (longlong) ptr_diff_table)); |
| 3973 | DBUG_RETURN(spider_set_connect_info_default_db_table( |
| 3974 | share, |
| 3975 | ptr_db, |
| 3976 | (uint)(ptr_diff_table - 1), |
| 3977 | ptr_table, |
| 3978 | (uint)(dbtable_name_length - ptr_diff_db - ptr_diff_table) |
| 3979 | )); |
| 3980 | } |
| 3981 | |
| 3982 | #ifndef DBUG_OFF |
| 3983 | void spider_print_keys( |
| 3984 | const char *key, |
| 3985 | uint length |
| 3986 | ) { |
| 3987 | const char *end_ptr; |
| 3988 | uint roop_count = 1; |
| 3989 | DBUG_ENTER("spider_print_keys" ); |
| 3990 | DBUG_PRINT("info" ,("spider key_length=%u" , length)); |
| 3991 | end_ptr = key + length; |
| 3992 | while (key < end_ptr) |
| 3993 | { |
| 3994 | DBUG_PRINT("info" ,("spider key[%u]=%s" , roop_count, key)); |
| 3995 | key = strchr(key, '\0') + 1; |
| 3996 | roop_count++; |
| 3997 | } |
| 3998 | DBUG_VOID_RETURN; |
| 3999 | } |
| 4000 | #endif |
| 4001 | |
| 4002 | int spider_create_conn_keys( |
| 4003 | SPIDER_SHARE *share |
| 4004 | ) { |
| 4005 | int roop_count, roop_count2; |
| 4006 | char *tmp_name, port_str[6]; |
| 4007 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4008 | char *tmp_hs_r_name, *tmp_hs_w_name; |
| 4009 | #endif |
| 4010 | uint *conn_keys_lengths; |
| 4011 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4012 | uint *hs_r_conn_keys_lengths; |
| 4013 | uint *hs_w_conn_keys_lengths; |
| 4014 | #endif |
| 4015 | DBUG_ENTER("spider_create_conn_keys" ); |
| 4016 | char *ptr; |
| 4017 | uint length = sizeof(uint) * share->all_link_count; |
| 4018 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4019 | length += (sizeof(uint) * share->all_link_count) * 2; |
| 4020 | #endif |
| 4021 | ptr = (char *) my_alloca(length); |
| 4022 | if (!ptr) |
| 4023 | { |
| 4024 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 4025 | } |
| 4026 | conn_keys_lengths = (uint *) ptr; |
| 4027 | ptr += (sizeof(uint) * share->all_link_count); |
| 4028 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4029 | hs_r_conn_keys_lengths = (uint *) ptr; |
| 4030 | ptr += (sizeof(uint) * share->all_link_count); |
| 4031 | hs_w_conn_keys_lengths = (uint *) ptr; |
| 4032 | #endif |
| 4033 | |
| 4034 | share->conn_keys_charlen = 0; |
| 4035 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4036 | share->hs_read_conn_keys_charlen = 0; |
| 4037 | share->hs_write_conn_keys_charlen = 0; |
| 4038 | #endif |
| 4039 | for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++) |
| 4040 | { |
| 4041 | /* tgt_db not use */ |
| 4042 | conn_keys_lengths[roop_count] |
| 4043 | = 1 |
| 4044 | + share->tgt_wrappers_lengths[roop_count] + 1 |
| 4045 | + share->tgt_hosts_lengths[roop_count] + 1 |
| 4046 | + 5 + 1 |
| 4047 | + share->tgt_sockets_lengths[roop_count] + 1 |
| 4048 | + share->tgt_usernames_lengths[roop_count] + 1 |
| 4049 | + share->tgt_passwords_lengths[roop_count] + 1 |
| 4050 | + share->tgt_ssl_cas_lengths[roop_count] + 1 |
| 4051 | + share->tgt_ssl_capaths_lengths[roop_count] + 1 |
| 4052 | + share->tgt_ssl_certs_lengths[roop_count] + 1 |
| 4053 | + share->tgt_ssl_ciphers_lengths[roop_count] + 1 |
| 4054 | + share->tgt_ssl_keys_lengths[roop_count] + 1 |
| 4055 | + 1 + 1 |
| 4056 | + share->tgt_default_files_lengths[roop_count] + 1 |
| 4057 | + share->tgt_default_groups_lengths[roop_count]; |
| 4058 | share->conn_keys_charlen += conn_keys_lengths[roop_count] + 2; |
| 4059 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4060 | hs_r_conn_keys_lengths[roop_count] |
| 4061 | = 1 |
| 4062 | + share->tgt_wrappers_lengths[roop_count] + 1 |
| 4063 | + share->tgt_hosts_lengths[roop_count] + 1 |
| 4064 | + 5 + 1 |
| 4065 | + share->hs_read_socks_lengths[roop_count]; |
| 4066 | share->hs_read_conn_keys_charlen += |
| 4067 | hs_r_conn_keys_lengths[roop_count] + 2; |
| 4068 | hs_w_conn_keys_lengths[roop_count] |
| 4069 | = 1 |
| 4070 | + share->tgt_wrappers_lengths[roop_count] + 1 |
| 4071 | + share->tgt_hosts_lengths[roop_count] + 1 |
| 4072 | + 5 + 1 |
| 4073 | + share->hs_write_socks_lengths[roop_count]; |
| 4074 | share->hs_write_conn_keys_charlen += |
| 4075 | hs_w_conn_keys_lengths[roop_count] + 2; |
| 4076 | #endif |
| 4077 | } |
| 4078 | if (!(share->conn_keys = (char **) |
| 4079 | spider_bulk_alloc_mem(spider_current_trx, 45, |
| 4080 | __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), |
| 4081 | &share->conn_keys, sizeof(char *) * share->all_link_count, |
| 4082 | &share->conn_keys_lengths, sizeof(uint) * share->all_link_count, |
| 4083 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 4084 | &share->conn_keys_hash_value, |
| 4085 | sizeof(my_hash_value_type) * share->all_link_count, |
| 4086 | #endif |
| 4087 | &tmp_name, sizeof(char) * share->conn_keys_charlen, |
| 4088 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4089 | &share->hs_read_conn_keys, sizeof(char *) * share->all_link_count, |
| 4090 | &share->hs_read_conn_keys_lengths, sizeof(uint) * share->all_link_count, |
| 4091 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 4092 | &share->hs_read_conn_keys_hash_value, |
| 4093 | sizeof(my_hash_value_type) * share->all_link_count, |
| 4094 | #endif |
| 4095 | &tmp_hs_r_name, sizeof(char) * share->hs_read_conn_keys_charlen, |
| 4096 | &share->hs_write_conn_keys, sizeof(char *) * share->all_link_count, |
| 4097 | &share->hs_write_conn_keys_lengths, sizeof(uint) * share->all_link_count, |
| 4098 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 4099 | &share->hs_write_conn_keys_hash_value, |
| 4100 | sizeof(my_hash_value_type) * share->all_link_count, |
| 4101 | #endif |
| 4102 | &tmp_hs_w_name, sizeof(char) * share->hs_write_conn_keys_charlen, |
| 4103 | #endif |
| 4104 | &share->sql_dbton_ids, sizeof(uint) * share->all_link_count, |
| 4105 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4106 | &share->hs_dbton_ids, sizeof(uint) * share->all_link_count, |
| 4107 | #endif |
| 4108 | NullS)) |
| 4109 | ) { |
| 4110 | my_afree(conn_keys_lengths); |
| 4111 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 4112 | } |
| 4113 | share->conn_keys_length = share->all_link_count; |
| 4114 | memcpy(share->conn_keys_lengths, conn_keys_lengths, |
| 4115 | sizeof(uint) * share->all_link_count); |
| 4116 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4117 | share->hs_read_conn_keys_length = share->all_link_count; |
| 4118 | share->hs_write_conn_keys_length = share->all_link_count; |
| 4119 | memcpy(share->hs_read_conn_keys_lengths, hs_r_conn_keys_lengths, |
| 4120 | sizeof(uint) * share->all_link_count); |
| 4121 | memcpy(share->hs_write_conn_keys_lengths, hs_w_conn_keys_lengths, |
| 4122 | sizeof(uint) * share->all_link_count); |
| 4123 | #endif |
| 4124 | |
| 4125 | my_afree(conn_keys_lengths); |
| 4126 | |
| 4127 | for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++) |
| 4128 | { |
| 4129 | share->conn_keys[roop_count] = tmp_name; |
| 4130 | *tmp_name = '0'; |
| 4131 | DBUG_PRINT("info" ,("spider tgt_wrappers[%d]=%s" , roop_count, |
| 4132 | share->tgt_wrappers[roop_count])); |
| 4133 | tmp_name = strmov(tmp_name + 1, share->tgt_wrappers[roop_count]); |
| 4134 | DBUG_PRINT("info" ,("spider tgt_hosts[%d]=%s" , roop_count, |
| 4135 | share->tgt_hosts[roop_count])); |
| 4136 | tmp_name = strmov(tmp_name + 1, share->tgt_hosts[roop_count]); |
| 4137 | my_sprintf(port_str, (port_str, "%05ld" , share->tgt_ports[roop_count])); |
| 4138 | DBUG_PRINT("info" ,("spider port_str=%s" , port_str)); |
| 4139 | tmp_name = strmov(tmp_name + 1, port_str); |
| 4140 | if (share->tgt_sockets[roop_count]) |
| 4141 | { |
| 4142 | DBUG_PRINT("info" ,("spider tgt_sockets[%d]=%s" , roop_count, |
| 4143 | share->tgt_sockets[roop_count])); |
| 4144 | tmp_name = strmov(tmp_name + 1, share->tgt_sockets[roop_count]); |
| 4145 | } else |
| 4146 | tmp_name++; |
| 4147 | if (share->tgt_usernames[roop_count]) |
| 4148 | { |
| 4149 | DBUG_PRINT("info" ,("spider tgt_usernames[%d]=%s" , roop_count, |
| 4150 | share->tgt_usernames[roop_count])); |
| 4151 | tmp_name = strmov(tmp_name + 1, share->tgt_usernames[roop_count]); |
| 4152 | } else |
| 4153 | tmp_name++; |
| 4154 | if (share->tgt_passwords[roop_count]) |
| 4155 | { |
| 4156 | DBUG_PRINT("info" ,("spider tgt_passwords[%d]=%s" , roop_count, |
| 4157 | share->tgt_passwords[roop_count])); |
| 4158 | tmp_name = strmov(tmp_name + 1, share->tgt_passwords[roop_count]); |
| 4159 | } else |
| 4160 | tmp_name++; |
| 4161 | if (share->tgt_ssl_cas[roop_count]) |
| 4162 | { |
| 4163 | DBUG_PRINT("info" ,("spider tgt_ssl_cas[%d]=%s" , roop_count, |
| 4164 | share->tgt_ssl_cas[roop_count])); |
| 4165 | tmp_name = strmov(tmp_name + 1, share->tgt_ssl_cas[roop_count]); |
| 4166 | } else |
| 4167 | tmp_name++; |
| 4168 | if (share->tgt_ssl_capaths[roop_count]) |
| 4169 | { |
| 4170 | DBUG_PRINT("info" ,("spider tgt_ssl_capaths[%d]=%s" , roop_count, |
| 4171 | share->tgt_ssl_capaths[roop_count])); |
| 4172 | tmp_name = strmov(tmp_name + 1, share->tgt_ssl_capaths[roop_count]); |
| 4173 | } else |
| 4174 | tmp_name++; |
| 4175 | if (share->tgt_ssl_certs[roop_count]) |
| 4176 | { |
| 4177 | DBUG_PRINT("info" ,("spider tgt_ssl_certs[%d]=%s" , roop_count, |
| 4178 | share->tgt_ssl_certs[roop_count])); |
| 4179 | tmp_name = strmov(tmp_name + 1, share->tgt_ssl_certs[roop_count]); |
| 4180 | } else |
| 4181 | tmp_name++; |
| 4182 | if (share->tgt_ssl_ciphers[roop_count]) |
| 4183 | { |
| 4184 | DBUG_PRINT("info" ,("spider tgt_ssl_ciphers[%d]=%s" , roop_count, |
| 4185 | share->tgt_ssl_ciphers[roop_count])); |
| 4186 | tmp_name = strmov(tmp_name + 1, share->tgt_ssl_ciphers[roop_count]); |
| 4187 | } else |
| 4188 | tmp_name++; |
| 4189 | if (share->tgt_ssl_keys[roop_count]) |
| 4190 | { |
| 4191 | DBUG_PRINT("info" ,("spider tgt_ssl_keys[%d]=%s" , roop_count, |
| 4192 | share->tgt_ssl_keys[roop_count])); |
| 4193 | tmp_name = strmov(tmp_name + 1, share->tgt_ssl_keys[roop_count]); |
| 4194 | } else |
| 4195 | tmp_name++; |
| 4196 | tmp_name++; |
| 4197 | *tmp_name = '0' + ((char) share->tgt_ssl_vscs[roop_count]); |
| 4198 | if (share->tgt_default_files[roop_count]) |
| 4199 | { |
| 4200 | DBUG_PRINT("info" ,("spider tgt_default_files[%d]=%s" , roop_count, |
| 4201 | share->tgt_default_files[roop_count])); |
| 4202 | tmp_name = strmov(tmp_name + 1, share->tgt_default_files[roop_count]); |
| 4203 | } else |
| 4204 | tmp_name++; |
| 4205 | if (share->tgt_default_groups[roop_count]) |
| 4206 | { |
| 4207 | DBUG_PRINT("info" ,("spider tgt_default_groups[%d]=%s" , roop_count, |
| 4208 | share->tgt_default_groups[roop_count])); |
| 4209 | tmp_name = strmov(tmp_name + 1, share->tgt_default_groups[roop_count]); |
| 4210 | } else |
| 4211 | tmp_name++; |
| 4212 | tmp_name++; |
| 4213 | tmp_name++; |
| 4214 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 4215 | share->conn_keys_hash_value[roop_count] = my_calc_hash( |
| 4216 | &spider_open_connections, (uchar*) share->conn_keys[roop_count], |
| 4217 | share->conn_keys_lengths[roop_count]); |
| 4218 | #endif |
| 4219 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4220 | share->hs_read_conn_keys[roop_count] = tmp_hs_r_name; |
| 4221 | *tmp_hs_r_name = '0'; |
| 4222 | DBUG_PRINT("info" ,("spider tgt_wrappers[%d]=%s" , roop_count, |
| 4223 | share->tgt_wrappers[roop_count])); |
| 4224 | tmp_hs_r_name = strmov(tmp_hs_r_name + 1, share->tgt_wrappers[roop_count]); |
| 4225 | DBUG_PRINT("info" ,("spider tgt_hosts[%d]=%s" , roop_count, |
| 4226 | share->tgt_hosts[roop_count])); |
| 4227 | tmp_hs_r_name = strmov(tmp_hs_r_name + 1, share->tgt_hosts[roop_count]); |
| 4228 | my_sprintf(port_str, (port_str, "%05ld" , |
| 4229 | share->hs_read_ports[roop_count])); |
| 4230 | DBUG_PRINT("info" ,("spider port_str=%s" , port_str)); |
| 4231 | tmp_hs_r_name = strmov(tmp_hs_r_name + 1, port_str); |
| 4232 | if (share->hs_read_socks[roop_count]) |
| 4233 | { |
| 4234 | DBUG_PRINT("info" ,("spider hs_read_socks[%d]=%s" , roop_count, |
| 4235 | share->hs_read_socks[roop_count])); |
| 4236 | tmp_hs_r_name = strmov(tmp_hs_r_name + 1, |
| 4237 | share->hs_read_socks[roop_count]); |
| 4238 | } else |
| 4239 | tmp_hs_r_name++; |
| 4240 | tmp_hs_r_name++; |
| 4241 | tmp_hs_r_name++; |
| 4242 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 4243 | share->hs_read_conn_keys_hash_value[roop_count] = my_calc_hash( |
| 4244 | &spider_open_connections, (uchar*) share->hs_read_conn_keys[roop_count], |
| 4245 | share->hs_read_conn_keys_lengths[roop_count]); |
| 4246 | #endif |
| 4247 | share->hs_write_conn_keys[roop_count] = tmp_hs_w_name; |
| 4248 | *tmp_hs_w_name = '0'; |
| 4249 | DBUG_PRINT("info" ,("spider tgt_wrappers[%d]=%s" , roop_count, |
| 4250 | share->tgt_wrappers[roop_count])); |
| 4251 | tmp_hs_w_name = strmov(tmp_hs_w_name + 1, share->tgt_wrappers[roop_count]); |
| 4252 | DBUG_PRINT("info" ,("spider tgt_hosts[%d]=%s" , roop_count, |
| 4253 | share->tgt_hosts[roop_count])); |
| 4254 | tmp_hs_w_name = strmov(tmp_hs_w_name + 1, share->tgt_hosts[roop_count]); |
| 4255 | my_sprintf(port_str, (port_str, "%05ld" , |
| 4256 | share->hs_write_ports[roop_count])); |
| 4257 | DBUG_PRINT("info" ,("spider port_str=%s" , port_str)); |
| 4258 | tmp_hs_w_name = strmov(tmp_hs_w_name + 1, port_str); |
| 4259 | if (share->hs_write_socks[roop_count]) |
| 4260 | { |
| 4261 | DBUG_PRINT("info" ,("spider hs_write_socks[%d]=%s" , roop_count, |
| 4262 | share->hs_write_socks[roop_count])); |
| 4263 | tmp_hs_w_name = strmov(tmp_hs_w_name + 1, |
| 4264 | share->hs_write_socks[roop_count]); |
| 4265 | } else |
| 4266 | tmp_hs_w_name++; |
| 4267 | tmp_hs_w_name++; |
| 4268 | tmp_hs_w_name++; |
| 4269 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 4270 | share->hs_write_conn_keys_hash_value[roop_count] = my_calc_hash( |
| 4271 | &spider_open_connections, (uchar*) share->hs_write_conn_keys[roop_count], |
| 4272 | share->hs_write_conn_keys_lengths[roop_count]); |
| 4273 | #endif |
| 4274 | #endif |
| 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 | share->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 | share->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 | share->sql_dbton_ids[roop_count] = SPIDER_DBTON_SIZE; |
| 4324 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4325 | if (!get_nosql_id) |
| 4326 | share->hs_dbton_ids[roop_count] = SPIDER_DBTON_SIZE; |
| 4327 | #endif |
| 4328 | } |
| 4329 | for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++) |
| 4330 | { |
| 4331 | if (spider_bit_is_set(share->dbton_bitmap, roop_count2)) |
| 4332 | { |
| 4333 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4334 | if (spider_dbton[roop_count2].db_access_type == |
| 4335 | SPIDER_DB_ACCESS_TYPE_SQL) |
| 4336 | { |
| 4337 | #endif |
| 4338 | share->use_sql_dbton_ids[share->use_dbton_count] = roop_count2; |
| 4339 | share->sql_dbton_id_to_seq[roop_count2] = share->use_dbton_count; |
| 4340 | share->use_sql_dbton_count++; |
| 4341 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4342 | } else { |
| 4343 | share->use_hs_dbton_ids[share->use_hs_dbton_count] = roop_count2; |
| 4344 | share->hs_dbton_id_to_seq[roop_count2] = share->use_hs_dbton_count; |
| 4345 | share->use_hs_dbton_count++; |
| 4346 | } |
| 4347 | #endif |
| 4348 | share->use_dbton_ids[share->use_dbton_count] = roop_count2; |
| 4349 | share->dbton_id_to_seq[roop_count2] = share->use_dbton_count; |
| 4350 | share->use_dbton_count++; |
| 4351 | } |
| 4352 | } |
| 4353 | DBUG_RETURN(0); |
| 4354 | } |
| 4355 | |
| 4356 | SPIDER_SHARE *spider_create_share( |
| 4357 | const char *table_name, |
| 4358 | TABLE_SHARE *table_share, |
| 4359 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 4360 | partition_info *part_info, |
| 4361 | #endif |
| 4362 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 4363 | my_hash_value_type hash_value, |
| 4364 | #endif |
| 4365 | int *error_num |
| 4366 | ) { |
| 4367 | int bitmap_size, roop_count; |
| 4368 | uint length; |
| 4369 | int use_table_charset; |
| 4370 | SPIDER_SHARE *share; |
| 4371 | char *tmp_name; |
| 4372 | longlong *tmp_cardinality, *tmp_static_key_cardinality; |
| 4373 | uchar *tmp_cardinality_upd, *tmp_table_mon_mutex_bitmap; |
| 4374 | char buf[MAX_FIELD_WIDTH], *buf_pos; |
| 4375 | char link_idx_str[SPIDER_SQL_INT_LEN]; |
| 4376 | DBUG_ENTER("spider_create_share" ); |
| 4377 | length = (uint) strlen(table_name); |
| 4378 | bitmap_size = spider_bitmap_size(table_share->fields); |
| 4379 | if (!(share = (SPIDER_SHARE *) |
| 4380 | spider_bulk_malloc(spider_current_trx, 46, MYF(MY_WME | MY_ZEROFILL), |
| 4381 | &share, sizeof(*share), |
| 4382 | &tmp_name, length + 1, |
| 4383 | &tmp_static_key_cardinality, sizeof(*tmp_static_key_cardinality) * table_share->keys, |
| 4384 | &tmp_cardinality, sizeof(*tmp_cardinality) * table_share->fields, |
| 4385 | &tmp_cardinality_upd, sizeof(*tmp_cardinality_upd) * bitmap_size, |
| 4386 | &tmp_table_mon_mutex_bitmap, sizeof(*tmp_table_mon_mutex_bitmap) * |
| 4387 | ((spider_param_udf_table_mon_mutex_count() + 7) / 8), |
| 4388 | NullS)) |
| 4389 | ) { |
| 4390 | *error_num = HA_ERR_OUT_OF_MEM; |
| 4391 | goto error_alloc_share; |
| 4392 | } |
| 4393 | |
| 4394 | SPD_INIT_ALLOC_ROOT(&share->mem_root, 4096, 0, MYF(MY_WME)); |
| 4395 | share->use_count = 0; |
| 4396 | share->use_dbton_count = 0; |
| 4397 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4398 | share->use_hs_dbton_count = 0; |
| 4399 | #endif |
| 4400 | share->table_name_length = length; |
| 4401 | share->table_name = tmp_name; |
| 4402 | strmov(share->table_name, table_name); |
| 4403 | share->static_key_cardinality = tmp_static_key_cardinality; |
| 4404 | share->cardinality = tmp_cardinality; |
| 4405 | share->cardinality_upd = tmp_cardinality_upd; |
| 4406 | share->table_mon_mutex_bitmap = tmp_table_mon_mutex_bitmap; |
| 4407 | share->bitmap_size = bitmap_size; |
| 4408 | share->table_share = table_share; |
| 4409 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 4410 | share->table_name_hash_value = hash_value; |
| 4411 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 4412 | share->table_path_hash_value = my_calc_hash(&spider_open_tables, |
| 4413 | (uchar*) table_share->path.str, table_share->path.length); |
| 4414 | #endif |
| 4415 | #endif |
| 4416 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 4417 | share->table.s = table_share; |
| 4418 | share->table.field = table_share->field; |
| 4419 | share->table.key_info = table_share->key_info; |
| 4420 | share->table.read_set = &table_share->all_set; |
| 4421 | #endif |
| 4422 | |
| 4423 | if (table_share->keys > 0 && |
| 4424 | !(share->key_hint = new spider_string[table_share->keys]) |
| 4425 | ) { |
| 4426 | *error_num = HA_ERR_OUT_OF_MEM; |
| 4427 | goto error_init_hint_string; |
| 4428 | } |
| 4429 | for (roop_count = 0; roop_count < (int) table_share->keys; roop_count++) |
| 4430 | share->key_hint[roop_count].init_calc_mem(95); |
| 4431 | DBUG_PRINT("info" ,("spider share->key_hint=%p" , share->key_hint)); |
| 4432 | |
| 4433 | if ((*error_num = spider_parse_connect_info(share, table_share, |
| 4434 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 4435 | part_info, |
| 4436 | #endif |
| 4437 | 0))) |
| 4438 | goto error_parse_connect_string; |
| 4439 | |
| 4440 | for (roop_count = 0; roop_count < (int) share->all_link_count; |
| 4441 | roop_count++) |
| 4442 | { |
| 4443 | my_sprintf(link_idx_str, (link_idx_str, "%010d" , roop_count)); |
| 4444 | buf_pos = strmov(buf, share->table_name); |
| 4445 | buf_pos = strmov(buf_pos, link_idx_str); |
| 4446 | *buf_pos = '\0'; |
| 4447 | spider_set_bit(tmp_table_mon_mutex_bitmap, |
| 4448 | spider_udf_calc_hash(buf, spider_param_udf_table_mon_mutex_count()) |
| 4449 | ); |
| 4450 | } |
| 4451 | |
| 4452 | use_table_charset = spider_param_use_table_charset( |
| 4453 | share->use_table_charset); |
| 4454 | if (table_share->table_charset && use_table_charset) |
| 4455 | share->access_charset = table_share->table_charset; |
| 4456 | else |
| 4457 | share->access_charset = system_charset_info; |
| 4458 | |
| 4459 | if ((*error_num = spider_create_conn_keys(share))) |
| 4460 | goto error_create_conn_keys; |
| 4461 | |
| 4462 | if (share->table_count_mode & 1) |
| 4463 | share->additional_table_flags |= HA_STATS_RECORDS_IS_EXACT; |
| 4464 | if (share->table_count_mode & 2) |
| 4465 | share->additional_table_flags |= HA_HAS_RECORDS; |
| 4466 | |
| 4467 | #if MYSQL_VERSION_ID < 50500 |
| 4468 | if (pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST)) |
| 4469 | #else |
| 4470 | if (mysql_mutex_init(spd_key_mutex_share, |
| 4471 | &share->mutex, MY_MUTEX_INIT_FAST)) |
| 4472 | #endif |
| 4473 | { |
| 4474 | *error_num = HA_ERR_OUT_OF_MEM; |
| 4475 | goto error_init_mutex; |
| 4476 | } |
| 4477 | |
| 4478 | #if MYSQL_VERSION_ID < 50500 |
| 4479 | if (pthread_mutex_init(&share->sts_mutex, MY_MUTEX_INIT_FAST)) |
| 4480 | #else |
| 4481 | if (mysql_mutex_init(spd_key_mutex_share_sts, |
| 4482 | &share->sts_mutex, MY_MUTEX_INIT_FAST)) |
| 4483 | #endif |
| 4484 | { |
| 4485 | *error_num = HA_ERR_OUT_OF_MEM; |
| 4486 | goto error_init_sts_mutex; |
| 4487 | } |
| 4488 | |
| 4489 | #if MYSQL_VERSION_ID < 50500 |
| 4490 | if (pthread_mutex_init(&share->crd_mutex, MY_MUTEX_INIT_FAST)) |
| 4491 | #else |
| 4492 | if (mysql_mutex_init(spd_key_mutex_share_crd, |
| 4493 | &share->crd_mutex, MY_MUTEX_INIT_FAST)) |
| 4494 | #endif |
| 4495 | { |
| 4496 | *error_num = HA_ERR_OUT_OF_MEM; |
| 4497 | goto error_init_crd_mutex; |
| 4498 | } |
| 4499 | |
| 4500 | thr_lock_init(&share->lock); |
| 4501 | |
| 4502 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 4503 | if (!(share->lgtm_tblhnd_share = |
| 4504 | spider_get_lgtm_tblhnd_share(tmp_name, length, hash_value, FALSE, TRUE, |
| 4505 | error_num))) |
| 4506 | #else |
| 4507 | if (!(share->lgtm_tblhnd_share = |
| 4508 | spider_get_lgtm_tblhnd_share(tmp_name, length, FALSE, TRUE, error_num))) |
| 4509 | #endif |
| 4510 | { |
| 4511 | goto error_get_lgtm_tblhnd_share; |
| 4512 | } |
| 4513 | |
| 4514 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 4515 | if (!(share->partition_share = |
| 4516 | spider_get_pt_share(share, table_share, error_num))) |
| 4517 | goto error_get_pt_share; |
| 4518 | #endif |
| 4519 | |
| 4520 | for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++) |
| 4521 | { |
| 4522 | if (spider_bit_is_set(share->dbton_bitmap, roop_count)) |
| 4523 | { |
| 4524 | if (!(share->dbton_share[roop_count] = |
| 4525 | spider_dbton[roop_count].create_db_share(share))) |
| 4526 | { |
| 4527 | *error_num = HA_ERR_OUT_OF_MEM; |
| 4528 | goto error_init_dbton; |
| 4529 | } |
| 4530 | if ((*error_num = share->dbton_share[roop_count]->init())) |
| 4531 | { |
| 4532 | goto error_init_dbton; |
| 4533 | } |
| 4534 | } |
| 4535 | } |
| 4536 | DBUG_RETURN(share); |
| 4537 | |
| 4538 | /* |
| 4539 | roop_count = SPIDER_DBTON_SIZE - 1; |
| 4540 | */ |
| 4541 | error_init_dbton: |
| 4542 | for (; roop_count >= 0; roop_count--) |
| 4543 | { |
| 4544 | if (share->dbton_share[roop_count]) |
| 4545 | { |
| 4546 | delete share->dbton_share[roop_count]; |
| 4547 | share->dbton_share[roop_count] = NULL; |
| 4548 | } |
| 4549 | } |
| 4550 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 4551 | spider_free_pt_share(share->partition_share); |
| 4552 | error_get_pt_share: |
| 4553 | #endif |
| 4554 | error_get_lgtm_tblhnd_share: |
| 4555 | thr_lock_delete(&share->lock); |
| 4556 | pthread_mutex_destroy(&share->crd_mutex); |
| 4557 | error_init_crd_mutex: |
| 4558 | pthread_mutex_destroy(&share->sts_mutex); |
| 4559 | error_init_sts_mutex: |
| 4560 | pthread_mutex_destroy(&share->mutex); |
| 4561 | error_init_mutex: |
| 4562 | error_create_conn_keys: |
| 4563 | error_parse_connect_string: |
| 4564 | error_init_hint_string: |
| 4565 | spider_free_share_alloc(share); |
| 4566 | spider_free(spider_current_trx, share, MYF(0)); |
| 4567 | error_alloc_share: |
| 4568 | DBUG_RETURN(NULL); |
| 4569 | } |
| 4570 | |
| 4571 | SPIDER_SHARE *spider_get_share( |
| 4572 | const char *table_name, |
| 4573 | TABLE *table, |
| 4574 | THD *thd, |
| 4575 | ha_spider *spider, |
| 4576 | int *error_num |
| 4577 | ) { |
| 4578 | SPIDER_SHARE *share; |
| 4579 | TABLE_SHARE *table_share = table->s; |
| 4580 | SPIDER_RESULT_LIST *result_list = &spider->result_list; |
| 4581 | uint length, tmp_conn_link_idx = 0; |
| 4582 | char *tmp_name, *tmp_cid; |
| 4583 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4584 | char *tmp_hs_r_name, *tmp_hs_w_name; |
| 4585 | #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS |
| 4586 | uint32 *tmp_hs_r_ret_fields, *tmp_hs_w_ret_fields; |
| 4587 | #endif |
| 4588 | #endif |
| 4589 | int roop_count; |
| 4590 | double sts_interval; |
| 4591 | int sts_mode; |
| 4592 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 4593 | int sts_sync; |
| 4594 | int auto_increment_mode; |
| 4595 | #endif |
| 4596 | double crd_interval; |
| 4597 | int crd_mode; |
| 4598 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 4599 | int crd_sync; |
| 4600 | #endif |
| 4601 | char first_byte; |
| 4602 | int semi_table_lock_conn; |
| 4603 | int search_link_idx; |
| 4604 | uint sql_command = thd_sql_command(thd); |
| 4605 | #if MYSQL_VERSION_ID < 50500 |
| 4606 | Open_tables_state open_tables_backup; |
| 4607 | #else |
| 4608 | Open_tables_backup open_tables_backup; |
| 4609 | #endif |
| 4610 | MEM_ROOT mem_root; |
| 4611 | TABLE *table_tables = NULL; |
| 4612 | bool init_mem_root = FALSE; |
| 4613 | bool same_server_link; |
| 4614 | int load_sts_at_startup; |
| 4615 | int load_crd_at_startup; |
| 4616 | DBUG_ENTER("spider_get_share" ); |
| 4617 | |
| 4618 | length = (uint) strlen(table_name); |
| 4619 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 4620 | my_hash_value_type hash_value = my_calc_hash(&spider_open_tables, |
| 4621 | (uchar*) table_name, length); |
| 4622 | #endif |
| 4623 | pthread_mutex_lock(&spider_tbl_mutex); |
| 4624 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 4625 | if (!(share = (SPIDER_SHARE*) my_hash_search_using_hash_value( |
| 4626 | &spider_open_tables, hash_value, (uchar*) table_name, length))) |
| 4627 | #else |
| 4628 | if (!(share = (SPIDER_SHARE*) my_hash_search(&spider_open_tables, |
| 4629 | (uchar*) table_name, length))) |
| 4630 | #endif |
| 4631 | { |
| 4632 | if (!(share = spider_create_share( |
| 4633 | table_name, table_share, |
| 4634 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 4635 | table->part_info, |
| 4636 | #endif |
| 4637 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 4638 | hash_value, |
| 4639 | #endif |
| 4640 | error_num |
| 4641 | ))) { |
| 4642 | goto error_alloc_share; |
| 4643 | } |
| 4644 | |
| 4645 | uint old_elements = spider_open_tables.array.max_element; |
| 4646 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
| 4647 | if (my_hash_insert_with_hash_value(&spider_open_tables, hash_value, |
| 4648 | (uchar*) share)) |
| 4649 | #else |
| 4650 | if (my_hash_insert(&spider_open_tables, (uchar*) share)) |
| 4651 | #endif |
| 4652 | { |
| 4653 | *error_num = HA_ERR_OUT_OF_MEM; |
| 4654 | goto error_hash_insert; |
| 4655 | } |
| 4656 | if (spider_open_tables.array.max_element > old_elements) |
| 4657 | { |
| 4658 | spider_alloc_calc_mem(spider_current_trx, |
| 4659 | spider_open_tables, |
| 4660 | (spider_open_tables.array.max_element - old_elements) * |
| 4661 | spider_open_tables.array.size_of_element); |
| 4662 | } |
| 4663 | |
| 4664 | spider->share = share; |
| 4665 | spider->conn_link_idx = &tmp_conn_link_idx; |
| 4666 | |
| 4667 | share->use_count++; |
| 4668 | pthread_mutex_unlock(&spider_tbl_mutex); |
| 4669 | |
| 4670 | if (!share->link_status_init) |
| 4671 | { |
| 4672 | pthread_mutex_lock(&share->mutex); |
| 4673 | for (roop_count = 0; |
| 4674 | roop_count < (int) spider_param_udf_table_mon_mutex_count(); |
| 4675 | roop_count++ |
| 4676 | ) { |
| 4677 | if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count)) |
| 4678 | pthread_mutex_lock(&spider_udf_table_mon_mutexes[roop_count]); |
| 4679 | } |
| 4680 | if (!share->link_status_init) |
| 4681 | { |
| 4682 | if ( |
| 4683 | ( |
| 4684 | table_share->tmp_table == NO_TMP_TABLE && |
| 4685 | sql_command != SQLCOM_DROP_TABLE && |
| 4686 | sql_command != SQLCOM_SHOW_CREATE |
| 4687 | ) || |
| 4688 | /* for alter change link status */ |
| 4689 | sql_command == SQLCOM_ALTER_TABLE |
| 4690 | ) { |
| 4691 | SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); |
| 4692 | init_mem_root = TRUE; |
| 4693 | if ( |
| 4694 | !(table_tables = spider_open_sys_table( |
| 4695 | thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, |
| 4696 | SPIDER_SYS_TABLES_TABLE_NAME_LEN, FALSE, &open_tables_backup, |
| 4697 | FALSE, error_num)) |
| 4698 | ) { |
| 4699 | for (roop_count = 0; |
| 4700 | roop_count < (int) spider_param_udf_table_mon_mutex_count(); |
| 4701 | roop_count++ |
| 4702 | ) { |
| 4703 | if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count)) |
| 4704 | pthread_mutex_unlock(&spider_udf_table_mon_mutexes[roop_count]); |
| 4705 | } |
| 4706 | pthread_mutex_unlock(&share->mutex); |
| 4707 | share->init_error = TRUE; |
| 4708 | share->init_error_time = (time_t) time((time_t*) 0); |
| 4709 | share->init = TRUE; |
| 4710 | spider_free_share(share); |
| 4711 | goto error_open_sys_table; |
| 4712 | } |
| 4713 | *error_num = spider_get_link_statuses(table_tables, share, |
| 4714 | &mem_root); |
| 4715 | if (*error_num) |
| 4716 | { |
| 4717 | if ( |
| 4718 | *error_num != HA_ERR_KEY_NOT_FOUND && |
| 4719 | *error_num != HA_ERR_END_OF_FILE |
| 4720 | ) { |
| 4721 | for (roop_count = 0; |
| 4722 | roop_count < (int) spider_param_udf_table_mon_mutex_count(); |
| 4723 | roop_count++ |
| 4724 | ) { |
| 4725 | if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count)) |
| 4726 | pthread_mutex_unlock(&spider_udf_table_mon_mutexes[roop_count]); |
| 4727 | } |
| 4728 | pthread_mutex_unlock(&share->mutex); |
| 4729 | share->init_error = TRUE; |
| 4730 | share->init_error_time = (time_t) time((time_t*) 0); |
| 4731 | share->init = TRUE; |
| 4732 | spider_free_share(share); |
| 4733 | goto error_get_link_statuses; |
| 4734 | } |
| 4735 | } else { |
| 4736 | memcpy(share->alter_table.tmp_link_statuses, share->link_statuses, |
| 4737 | sizeof(long) * share->all_link_count); |
| 4738 | share->link_status_init = TRUE; |
| 4739 | } |
| 4740 | } |
| 4741 | share->have_recovery_link = spider_conn_check_recovery_link(share); |
| 4742 | if (table_tables) |
| 4743 | { |
| 4744 | spider_close_sys_table(thd, table_tables, |
| 4745 | &open_tables_backup, FALSE); |
| 4746 | table_tables = NULL; |
| 4747 | } |
| 4748 | if (init_mem_root) |
| 4749 | { |
| 4750 | free_root(&mem_root, MYF(0)); |
| 4751 | init_mem_root = FALSE; |
| 4752 | } |
| 4753 | } |
| 4754 | for (roop_count = 0; |
| 4755 | roop_count < (int) spider_param_udf_table_mon_mutex_count(); |
| 4756 | roop_count++ |
| 4757 | ) { |
| 4758 | if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count)) |
| 4759 | pthread_mutex_unlock(&spider_udf_table_mon_mutexes[roop_count]); |
| 4760 | } |
| 4761 | pthread_mutex_unlock(&share->mutex); |
| 4762 | } |
| 4763 | |
| 4764 | semi_table_lock_conn = spider_param_semi_table_lock_connection(thd, |
| 4765 | share->semi_table_lock_conn); |
| 4766 | if (semi_table_lock_conn) |
| 4767 | first_byte = '0' + |
| 4768 | spider_param_semi_table_lock(thd, share->semi_table_lock); |
| 4769 | else |
| 4770 | first_byte = '0'; |
| 4771 | |
| 4772 | if (!(spider->trx = spider_get_trx(thd, TRUE, error_num))) |
| 4773 | { |
| 4774 | share->init_error = TRUE; |
| 4775 | share->init_error_time = (time_t) time((time_t*) 0); |
| 4776 | share->init = TRUE; |
| 4777 | spider_free_share(share); |
| 4778 | goto error_but_no_delete; |
| 4779 | } |
| 4780 | spider->set_error_mode(); |
| 4781 | |
| 4782 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 4783 | if (!share->sts_spider_init) |
| 4784 | { |
| 4785 | pthread_mutex_lock(&share->mutex); |
| 4786 | if (!share->sts_spider_init) |
| 4787 | { |
| 4788 | if ((*error_num = spider_create_spider_object_for_share( |
| 4789 | spider->trx, share, &share->sts_spider))) |
| 4790 | { |
| 4791 | pthread_mutex_unlock(&share->mutex); |
| 4792 | share->init_error = TRUE; |
| 4793 | share->init_error_time = (time_t) time((time_t*) 0); |
| 4794 | share->init = TRUE; |
| 4795 | spider_free_share(share); |
| 4796 | goto error_sts_spider_init; |
| 4797 | } |
| 4798 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
| 4799 | share->sts_thread = &spider_table_sts_threads[ |
| 4800 | hash_value % spider_param_table_sts_thread_count()]; |
| 4801 | #else |
| 4802 | share->sts_thread = &spider_table_sts_threads[ |
| 4803 | my_calc_hash(&spider_open_tables, (uchar*) table_name, length) % |
| 4804 | spider_param_table_sts_thread_count()]; |
| 4805 | #endif |
| 4806 | share->sts_spider_init = TRUE; |
| 4807 | } |
| 4808 | pthread_mutex_unlock(&share->mutex); |
| 4809 | } |
| 4810 | |
| 4811 | if (!share->crd_spider_init) |
| 4812 | { |
| 4813 | pthread_mutex_lock(&share->mutex); |
| 4814 | if (!share->crd_spider_init) |
| 4815 | { |
| 4816 | if ((*error_num = spider_create_spider_object_for_share( |
| 4817 | spider->trx, share, &share->crd_spider))) |
| 4818 | { |
| 4819 | pthread_mutex_unlock(&share->mutex); |
| 4820 | share->init_error = TRUE; |
| 4821 | share->init_error_time = (time_t) time((time_t*) 0); |
| 4822 | share->init = TRUE; |
| 4823 | spider_free_share(share); |
| 4824 | goto error_crd_spider_init; |
| 4825 | } |
| 4826 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
| 4827 | share->crd_thread = &spider_table_crd_threads[ |
| 4828 | hash_value % spider_param_table_crd_thread_count()]; |
| 4829 | #else |
| 4830 | share->crd_thread = &spider_table_crd_threads[ |
| 4831 | my_calc_hash(&spider_open_tables, (uchar*) table_name, length) % |
| 4832 | spider_param_table_crd_thread_count()]; |
| 4833 | #endif |
| 4834 | share->crd_spider_init = TRUE; |
| 4835 | } |
| 4836 | pthread_mutex_unlock(&share->mutex); |
| 4837 | } |
| 4838 | #endif |
| 4839 | |
| 4840 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 4841 | if ( |
| 4842 | sql_command != SQLCOM_DROP_TABLE && |
| 4843 | sql_command != SQLCOM_ALTER_TABLE && |
| 4844 | sql_command != SQLCOM_SHOW_CREATE && |
| 4845 | (*error_num = spider_create_mon_threads(spider->trx, share)) |
| 4846 | ) { |
| 4847 | share->init_error = TRUE; |
| 4848 | share->init_error_time = (time_t) time((time_t*) 0); |
| 4849 | share->init = TRUE; |
| 4850 | spider_free_share(share); |
| 4851 | goto error_but_no_delete; |
| 4852 | } |
| 4853 | #endif |
| 4854 | |
| 4855 | if (!(spider->conn_keys = (char **) |
| 4856 | spider_bulk_alloc_mem(spider_current_trx, 47, |
| 4857 | __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), |
| 4858 | &spider->conn_keys, sizeof(char *) * share->link_count, |
| 4859 | &tmp_name, sizeof(char) * share->conn_keys_charlen, |
| 4860 | &spider->conns, sizeof(SPIDER_CONN *) * share->link_count, |
| 4861 | &spider->conn_link_idx, sizeof(uint) * share->link_count, |
| 4862 | &spider->conn_can_fo, sizeof(uchar) * share->link_bitmap_size, |
| 4863 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4864 | &spider->hs_r_conn_keys, sizeof(char *) * share->link_count, |
| 4865 | &tmp_hs_r_name, sizeof(char) * share->hs_read_conn_keys_charlen, |
| 4866 | &spider->hs_r_conns, sizeof(SPIDER_CONN *) * share->link_count, |
| 4867 | &spider->hs_r_conn_ages, sizeof(ulonglong) * share->link_count, |
| 4868 | &spider->hs_w_conn_keys, sizeof(char *) * share->link_count, |
| 4869 | &tmp_hs_w_name, sizeof(char) * share->hs_write_conn_keys_charlen, |
| 4870 | &spider->hs_w_conns, sizeof(SPIDER_CONN *) * share->link_count, |
| 4871 | &spider->hs_w_conn_ages, sizeof(ulonglong) * share->link_count, |
| 4872 | #endif |
| 4873 | &spider->sql_kind, sizeof(uint) * share->link_count, |
| 4874 | &spider->connection_ids, sizeof(ulonglong) * share->link_count, |
| 4875 | &spider->conn_kind, sizeof(uint) * share->link_count, |
| 4876 | &spider->db_request_id, sizeof(ulonglong) * share->link_count, |
| 4877 | &spider->db_request_phase, sizeof(uchar) * share->link_bitmap_size, |
| 4878 | &spider->m_handler_opened, sizeof(uchar) * share->link_bitmap_size, |
| 4879 | &spider->m_handler_id, sizeof(uint) * share->link_count, |
| 4880 | &spider->m_handler_cid, sizeof(char *) * share->link_count, |
| 4881 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4882 | &spider->r_handler_opened, sizeof(uchar) * share->link_bitmap_size, |
| 4883 | &spider->r_handler_id, sizeof(uint) * share->link_count, |
| 4884 | &spider->r_handler_index, sizeof(uint) * share->link_count, |
| 4885 | &spider->w_handler_opened, sizeof(uchar) * share->link_bitmap_size, |
| 4886 | &spider->w_handler_id, sizeof(uint) * share->link_count, |
| 4887 | &spider->w_handler_index, sizeof(uint) * share->link_count, |
| 4888 | #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS |
| 4889 | &spider->do_hs_direct_update, sizeof(uchar) * share->link_bitmap_size, |
| 4890 | &spider->hs_r_ret_fields, sizeof(uint32 *) * share->link_count, |
| 4891 | &spider->hs_w_ret_fields, sizeof(uint32 *) * share->link_count, |
| 4892 | &spider->hs_r_ret_fields_num, sizeof(size_t) * share->link_count, |
| 4893 | &spider->hs_w_ret_fields_num, sizeof(size_t) * share->link_count, |
| 4894 | &tmp_hs_r_ret_fields, |
| 4895 | sizeof(uint32) * share->link_count * table_share->fields, |
| 4896 | &tmp_hs_w_ret_fields, |
| 4897 | sizeof(uint32) * share->link_count * table_share->fields, |
| 4898 | &spider->tmp_column_bitmap, sizeof(uchar) * share->bitmap_size, |
| 4899 | #endif |
| 4900 | #endif |
| 4901 | &tmp_cid, sizeof(char) * (SPIDER_SQL_HANDLER_CID_LEN + 1) * |
| 4902 | share->link_count, |
| 4903 | &spider->need_mons, sizeof(int) * share->link_count, |
| 4904 | &spider->quick_targets, sizeof(void *) * share->link_count, |
| 4905 | &result_list->upd_tmp_tbls, sizeof(TABLE *) * share->link_count, |
| 4906 | &result_list->upd_tmp_tbl_prms, |
| 4907 | sizeof(TMP_TABLE_PARAM) * share->link_count, |
| 4908 | &result_list->tmp_table_join_first, |
| 4909 | sizeof(uchar) * share->link_bitmap_size, |
| 4910 | &result_list->tmp_table_created, |
| 4911 | sizeof(uchar) * share->link_bitmap_size, |
| 4912 | #ifdef HA_CAN_BULK_ACCESS |
| 4913 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4914 | &result_list->hs_r_bulk_open_index, |
| 4915 | sizeof(uchar) * share->link_bitmap_size, |
| 4916 | &result_list->hs_w_bulk_open_index, |
| 4917 | sizeof(uchar) * share->link_bitmap_size, |
| 4918 | #endif |
| 4919 | #endif |
| 4920 | &result_list->sql_kind_backup, sizeof(uint) * share->link_count, |
| 4921 | &result_list->casual_read, sizeof(int) * share->link_count, |
| 4922 | &spider->dbton_handler, |
| 4923 | sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE, |
| 4924 | NullS)) |
| 4925 | ) { |
| 4926 | share->init_error = TRUE; |
| 4927 | share->init_error_time = (time_t) time((time_t*) 0); |
| 4928 | share->init = TRUE; |
| 4929 | spider_free_share(share); |
| 4930 | goto error_but_no_delete; |
| 4931 | } |
| 4932 | memcpy(tmp_name, share->conn_keys[0], share->conn_keys_charlen); |
| 4933 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4934 | memcpy(tmp_hs_r_name, share->hs_read_conn_keys[0], |
| 4935 | share->hs_read_conn_keys_charlen); |
| 4936 | memcpy(tmp_hs_w_name, share->hs_write_conn_keys[0], |
| 4937 | share->hs_write_conn_keys_charlen); |
| 4938 | #endif |
| 4939 | |
| 4940 | spider->conn_keys_first_ptr = tmp_name; |
| 4941 | for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) |
| 4942 | { |
| 4943 | spider->conn_keys[roop_count] = tmp_name; |
| 4944 | *tmp_name = first_byte; |
| 4945 | tmp_name += share->conn_keys_lengths[roop_count] + 1; |
| 4946 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 4947 | spider->hs_r_conn_keys[roop_count] = tmp_hs_r_name; |
| 4948 | tmp_hs_r_name += share->hs_read_conn_keys_lengths[roop_count] + 1; |
| 4949 | spider->hs_w_conn_keys[roop_count] = tmp_hs_w_name; |
| 4950 | tmp_hs_w_name += share->hs_write_conn_keys_lengths[roop_count] + 1; |
| 4951 | #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS |
| 4952 | spider->hs_r_ret_fields[roop_count] = tmp_hs_r_ret_fields; |
| 4953 | tmp_hs_r_ret_fields += table_share->fields; |
| 4954 | spider->hs_w_ret_fields[roop_count] = tmp_hs_w_ret_fields; |
| 4955 | tmp_hs_w_ret_fields += table_share->fields; |
| 4956 | #endif |
| 4957 | #endif |
| 4958 | spider->m_handler_cid[roop_count] = tmp_cid; |
| 4959 | tmp_cid += SPIDER_SQL_HANDLER_CID_LEN + 1; |
| 4960 | result_list->upd_tmp_tbl_prms[roop_count].init(); |
| 4961 | result_list->upd_tmp_tbl_prms[roop_count].field_count = 1; |
| 4962 | spider->conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL; |
| 4963 | } |
| 4964 | spider_trx_set_link_idx_for_all(spider); |
| 4965 | |
| 4966 | for (roop_count = 0; roop_count < (int) share->use_dbton_count; |
| 4967 | roop_count++) |
| 4968 | { |
| 4969 | uint dbton_id = share->use_dbton_ids[roop_count]; |
| 4970 | if (!(spider->dbton_handler[dbton_id] = |
| 4971 | spider_dbton[dbton_id].create_db_handler(spider, |
| 4972 | share->dbton_share[dbton_id]))) |
| 4973 | { |
| 4974 | *error_num = HA_ERR_OUT_OF_MEM; |
| 4975 | break; |
| 4976 | } |
| 4977 | if ((*error_num = spider->dbton_handler[dbton_id]->init())) |
| 4978 | { |
| 4979 | break; |
| 4980 | } |
| 4981 | } |
| 4982 | if (roop_count < (int) share->use_dbton_count) |
| 4983 | { |
| 4984 | for (; roop_count >= 0; roop_count--) |
| 4985 | { |
| 4986 | uint dbton_id = share->use_dbton_ids[roop_count]; |
| 4987 | if (spider->dbton_handler[dbton_id]) |
| 4988 | { |
| 4989 | delete spider->dbton_handler[dbton_id]; |
| 4990 | spider->dbton_handler[dbton_id] = NULL; |
| 4991 | } |
| 4992 | } |
| 4993 | share->init_error = TRUE; |
| 4994 | share->init_error_time = (time_t) time((time_t*) 0); |
| 4995 | share->init = TRUE; |
| 4996 | spider_free_share(share); |
| 4997 | goto error_but_no_delete; |
| 4998 | } |
| 4999 | |
| 5000 | if ( |
| 5001 | sql_command != SQLCOM_DROP_TABLE && |
| 5002 | sql_command != SQLCOM_ALTER_TABLE && |
| 5003 | sql_command != SQLCOM_SHOW_CREATE |
| 5004 | ) { |
| 5005 | for ( |
| 5006 | roop_count = spider_conn_link_idx_next(share->link_statuses, |
| 5007 | spider->conn_link_idx, -1, share->link_count, |
| 5008 | SPIDER_LINK_STATUS_RECOVERY); |
| 5009 | roop_count < (int) share->link_count; |
| 5010 | roop_count = spider_conn_link_idx_next(share->link_statuses, |
| 5011 | spider->conn_link_idx, roop_count, share->link_count, |
| 5012 | SPIDER_LINK_STATUS_RECOVERY) |
| 5013 | ) { |
| 5014 | if ( |
| 5015 | !(spider->conns[roop_count] = |
| 5016 | spider_get_conn(share, roop_count, spider->conn_keys[roop_count], |
| 5017 | spider->trx, spider, FALSE, TRUE, SPIDER_CONN_KIND_MYSQL, |
| 5018 | error_num)) |
| 5019 | ) { |
| 5020 | if ( |
| 5021 | share->monitoring_kind[roop_count] && |
| 5022 | spider->need_mons[roop_count] |
| 5023 | ) { |
| 5024 | *error_num = spider_ping_table_mon_from_table( |
| 5025 | spider->trx, |
| 5026 | spider->trx->thd, |
| 5027 | share, |
| 5028 | roop_count, |
| 5029 | (uint32) share->monitoring_sid[roop_count], |
| 5030 | share->table_name, |
| 5031 | share->table_name_length, |
| 5032 | spider->conn_link_idx[roop_count], |
| 5033 | NULL, |
| 5034 | 0, |
| 5035 | share->monitoring_kind[roop_count], |
| 5036 | share->monitoring_limit[roop_count], |
| 5037 | share->monitoring_flag[roop_count], |
| 5038 | FALSE |
| 5039 | ); |
| 5040 | } |
| 5041 | share->init_error = TRUE; |
| 5042 | share->init_error_time = (time_t) time((time_t*) 0); |
| 5043 | share->init = TRUE; |
| 5044 | spider_free_share(share); |
| 5045 | goto error_but_no_delete; |
| 5046 | } |
| 5047 | spider->conns[roop_count]->error_mode &= spider->error_mode; |
| 5048 | } |
| 5049 | } |
| 5050 | search_link_idx = spider_conn_first_link_idx(thd, |
| 5051 | share->link_statuses, share->access_balances, spider->conn_link_idx, |
| 5052 | share->link_count, SPIDER_LINK_STATUS_OK); |
| 5053 | if (search_link_idx == -1) |
| 5054 | { |
| 5055 | char *db = (char *) my_alloca( |
| 5056 | table_share->db.length + 1 + table_share->table_name.length + 1); |
| 5057 | if (!db) |
| 5058 | { |
| 5059 | *error_num = HA_ERR_OUT_OF_MEM; |
| 5060 | share->init_error = TRUE; |
| 5061 | share->init_error_time = (time_t) time((time_t*) 0); |
| 5062 | share->init = TRUE; |
| 5063 | spider_free_share(share); |
| 5064 | goto error_but_no_delete; |
| 5065 | } |
| 5066 | char *table_name = db + table_share->db.length + 1; |
| 5067 | memcpy(db, table_share->db.str, table_share->db.length); |
| 5068 | db[table_share->db.length] = '\0'; |
| 5069 | memcpy(table_name, table_share->table_name.str, |
| 5070 | table_share->table_name.length); |
| 5071 | table_name[table_share->table_name.length] = '\0'; |
| 5072 | my_printf_error(ER_SPIDER_ALL_LINKS_FAILED_NUM, |
| 5073 | ER_SPIDER_ALL_LINKS_FAILED_STR, MYF(0), db, table_name); |
| 5074 | my_afree(db); |
| 5075 | *error_num = ER_SPIDER_ALL_LINKS_FAILED_NUM; |
| 5076 | share->init_error = TRUE; |
| 5077 | share->init_error_time = (time_t) time((time_t*) 0); |
| 5078 | share->init = TRUE; |
| 5079 | spider_free_share(share); |
| 5080 | goto error_but_no_delete; |
| 5081 | } else if (search_link_idx == -2) |
| 5082 | { |
| 5083 | *error_num = HA_ERR_OUT_OF_MEM; |
| 5084 | share->init_error = TRUE; |
| 5085 | share->init_error_time = (time_t) time((time_t*) 0); |
| 5086 | share->init = TRUE; |
| 5087 | spider_free_share(share); |
| 5088 | goto error_but_no_delete; |
| 5089 | } |
| 5090 | spider->search_link_idx = search_link_idx; |
| 5091 | |
| 5092 | same_server_link = spider_param_same_server_link(thd); |
| 5093 | load_sts_at_startup = |
| 5094 | spider_param_load_sts_at_startup(share->load_sts_at_startup); |
| 5095 | load_crd_at_startup = |
| 5096 | spider_param_load_crd_at_startup(share->load_crd_at_startup); |
| 5097 | if ( |
| 5098 | sql_command != SQLCOM_DROP_TABLE && |
| 5099 | sql_command != SQLCOM_ALTER_TABLE && |
| 5100 | sql_command != SQLCOM_SHOW_CREATE && |
| 5101 | !spider->error_mode && |
| 5102 | ( |
| 5103 | !same_server_link || |
| 5104 | load_sts_at_startup || |
| 5105 | load_crd_at_startup |
| 5106 | ) |
| 5107 | ) { |
| 5108 | SPIDER_INIT_ERROR_TABLE *spider_init_error_table; |
| 5109 | sts_interval = spider_param_sts_interval(thd, share->sts_interval); |
| 5110 | sts_mode = spider_param_sts_mode(thd, share->sts_mode); |
| 5111 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 5112 | sts_sync = spider_param_sts_sync(thd, share->sts_sync); |
| 5113 | auto_increment_mode = spider_param_auto_increment_mode(thd, |
| 5114 | share->auto_increment_mode); |
| 5115 | if (auto_increment_mode == 1) |
| 5116 | sts_sync = 0; |
| 5117 | #endif |
| 5118 | crd_interval = spider_param_crd_interval(thd, share->crd_interval); |
| 5119 | crd_mode = spider_param_crd_mode(thd, share->crd_mode); |
| 5120 | if (crd_mode == 3) |
| 5121 | crd_mode = 1; |
| 5122 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 5123 | crd_sync = spider_param_crd_sync(thd, share->crd_sync); |
| 5124 | #endif |
| 5125 | time_t tmp_time = (time_t) time((time_t*) 0); |
| 5126 | pthread_mutex_lock(&share->sts_mutex); |
| 5127 | pthread_mutex_lock(&share->crd_mutex); |
| 5128 | if ((spider_init_error_table = |
| 5129 | spider_get_init_error_table(spider->trx, share, FALSE))) |
| 5130 | { |
| 5131 | DBUG_PRINT("info" ,("spider diff1=%f" , |
| 5132 | difftime(tmp_time, spider_init_error_table->init_error_time))); |
| 5133 | if (difftime(tmp_time, |
| 5134 | spider_init_error_table->init_error_time) < |
| 5135 | spider_param_table_init_error_interval()) |
| 5136 | { |
| 5137 | *error_num = spider_init_error_table->init_error; |
| 5138 | if (spider_init_error_table->init_error_with_message) |
| 5139 | my_message(spider_init_error_table->init_error, |
| 5140 | spider_init_error_table->init_error_msg, MYF(0)); |
| 5141 | share->init_error = TRUE; |
| 5142 | share->init = TRUE; |
| 5143 | pthread_mutex_unlock(&share->crd_mutex); |
| 5144 | pthread_mutex_unlock(&share->sts_mutex); |
| 5145 | spider_free_share(share); |
| 5146 | goto error_but_no_delete; |
| 5147 | } |
| 5148 | } |
| 5149 | |
| 5150 | if ( |
| 5151 | ( |
| 5152 | !same_server_link || |
| 5153 | load_sts_at_startup |
| 5154 | ) && |
| 5155 | spider_get_sts(share, spider->search_link_idx, tmp_time, |
| 5156 | spider, sts_interval, sts_mode, |
| 5157 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 5158 | sts_sync, |
| 5159 | #endif |
| 5160 | 1, HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_AUTO) |
| 5161 | ) { |
| 5162 | thd->clear_error(); |
| 5163 | } |
| 5164 | if ( |
| 5165 | ( |
| 5166 | !same_server_link || |
| 5167 | load_crd_at_startup |
| 5168 | ) && |
| 5169 | spider_get_crd(share, spider->search_link_idx, tmp_time, |
| 5170 | spider, table, crd_interval, crd_mode, |
| 5171 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 5172 | crd_sync, |
| 5173 | #endif |
| 5174 | 1) |
| 5175 | ) { |
| 5176 | thd->clear_error(); |
| 5177 | } |
| 5178 | pthread_mutex_unlock(&share->crd_mutex); |
| 5179 | pthread_mutex_unlock(&share->sts_mutex); |
| 5180 | } |
| 5181 | |
| 5182 | share->init = TRUE; |
| 5183 | } else { |
| 5184 | share->use_count++; |
| 5185 | pthread_mutex_unlock(&spider_tbl_mutex); |
| 5186 | |
| 5187 | int sleep_cnt = 0; |
| 5188 | while (!share->init) |
| 5189 | { |
| 5190 | // avoid for dead loop |
| 5191 | if (sleep_cnt++ > 1000) |
| 5192 | { |
| 5193 | fprintf(stderr, " [WARN SPIDER RESULT] " |
| 5194 | "Wait share->init too long, table_name %s %s %ld\n" , |
| 5195 | share->table_name, share->tgt_hosts[0], share->tgt_ports[0]); |
| 5196 | *error_num = ER_SPIDER_TABLE_OPEN_TIMEOUT_NUM; |
| 5197 | my_printf_error(ER_SPIDER_TABLE_OPEN_TIMEOUT_NUM, |
| 5198 | ER_SPIDER_TABLE_OPEN_TIMEOUT_STR, MYF(0), |
| 5199 | table_share->db.str, table_share->table_name.str); |
| 5200 | goto error_but_no_delete; |
| 5201 | } |
| 5202 | my_sleep(10000); // wait 10 ms |
| 5203 | } |
| 5204 | |
| 5205 | if (!share->link_status_init) |
| 5206 | { |
| 5207 | pthread_mutex_lock(&share->mutex); |
| 5208 | for (roop_count = 0; |
| 5209 | roop_count < (int) spider_param_udf_table_mon_mutex_count(); |
| 5210 | roop_count++ |
| 5211 | ) { |
| 5212 | if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count)) |
| 5213 | pthread_mutex_lock(&spider_udf_table_mon_mutexes[roop_count]); |
| 5214 | } |
| 5215 | if (!share->link_status_init) |
| 5216 | { |
| 5217 | if ( |
| 5218 | ( |
| 5219 | table_share->tmp_table == NO_TMP_TABLE && |
| 5220 | sql_command != SQLCOM_DROP_TABLE && |
| 5221 | sql_command != SQLCOM_SHOW_CREATE |
| 5222 | ) || |
| 5223 | /* for alter change link status */ |
| 5224 | sql_command == SQLCOM_ALTER_TABLE |
| 5225 | ) { |
| 5226 | SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); |
| 5227 | init_mem_root = TRUE; |
| 5228 | if ( |
| 5229 | !(table_tables = spider_open_sys_table( |
| 5230 | thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, |
| 5231 | SPIDER_SYS_TABLES_TABLE_NAME_LEN, FALSE, &open_tables_backup, |
| 5232 | FALSE, error_num)) |
| 5233 | ) { |
| 5234 | for (roop_count = 0; |
| 5235 | roop_count < (int) spider_param_udf_table_mon_mutex_count(); |
| 5236 | roop_count++ |
| 5237 | ) { |
| 5238 | if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count)) |
| 5239 | pthread_mutex_unlock(&spider_udf_table_mon_mutexes[roop_count]); |
| 5240 | } |
| 5241 | pthread_mutex_unlock(&share->mutex); |
| 5242 | spider_free_share(share); |
| 5243 | goto error_open_sys_table; |
| 5244 | } |
| 5245 | *error_num = spider_get_link_statuses(table_tables, share, |
| 5246 | &mem_root); |
| 5247 | if (*error_num) |
| 5248 | { |
| 5249 | if ( |
| 5250 | *error_num != HA_ERR_KEY_NOT_FOUND && |
| 5251 | *error_num != HA_ERR_END_OF_FILE |
| 5252 | ) { |
| 5253 | for (roop_count = 0; |
| 5254 | roop_count < (int) spider_param_udf_table_mon_mutex_count(); |
| 5255 | roop_count++ |
| 5256 | ) { |
| 5257 | if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count)) |
| 5258 | pthread_mutex_unlock(&spider_udf_table_mon_mutexes[roop_count]); |
| 5259 | } |
| 5260 | pthread_mutex_unlock(&share->mutex); |
| 5261 | spider_free_share(share); |
| 5262 | goto error_get_link_statuses; |
| 5263 | } |
| 5264 | } else { |
| 5265 | memcpy(share->alter_table.tmp_link_statuses, share->link_statuses, |
| 5266 | sizeof(long) * share->all_link_count); |
| 5267 | share->link_status_init = TRUE; |
| 5268 | } |
| 5269 | } |
| 5270 | share->have_recovery_link = spider_conn_check_recovery_link(share); |
| 5271 | if (table_tables) |
| 5272 | { |
| 5273 | spider_close_sys_table(thd, table_tables, |
| 5274 | &open_tables_backup, FALSE); |
| 5275 | table_tables = NULL; |
| 5276 | } |
| 5277 | if (init_mem_root) |
| 5278 | { |
| 5279 | free_root(&mem_root, MYF(0)); |
| 5280 | init_mem_root = FALSE; |
| 5281 | } |
| 5282 | } |
| 5283 | for (roop_count = 0; |
| 5284 | roop_count < (int) spider_param_udf_table_mon_mutex_count(); |
| 5285 | roop_count++ |
| 5286 | ) { |
| 5287 | if (spider_bit_is_set(share->table_mon_mutex_bitmap, roop_count)) |
| 5288 | pthread_mutex_unlock(&spider_udf_table_mon_mutexes[roop_count]); |
| 5289 | } |
| 5290 | pthread_mutex_unlock(&share->mutex); |
| 5291 | } |
| 5292 | |
| 5293 | semi_table_lock_conn = spider_param_semi_table_lock_connection(thd, |
| 5294 | share->semi_table_lock_conn); |
| 5295 | if (semi_table_lock_conn) |
| 5296 | first_byte = '0' + |
| 5297 | spider_param_semi_table_lock(thd, share->semi_table_lock); |
| 5298 | else |
| 5299 | first_byte = '0'; |
| 5300 | |
| 5301 | spider->share = share; |
| 5302 | if (!(spider->trx = spider_get_trx(thd, TRUE, error_num))) |
| 5303 | { |
| 5304 | spider_free_share(share); |
| 5305 | goto error_but_no_delete; |
| 5306 | } |
| 5307 | spider->set_error_mode(); |
| 5308 | |
| 5309 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 5310 | if (!share->sts_spider_init) |
| 5311 | { |
| 5312 | pthread_mutex_lock(&share->mutex); |
| 5313 | if (!share->sts_spider_init) |
| 5314 | { |
| 5315 | if ((*error_num = spider_create_spider_object_for_share( |
| 5316 | spider->trx, share, &share->sts_spider))) |
| 5317 | { |
| 5318 | pthread_mutex_unlock(&share->mutex); |
| 5319 | spider_free_share(share); |
| 5320 | goto error_sts_spider_init; |
| 5321 | } |
| 5322 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
| 5323 | share->sts_thread = &spider_table_sts_threads[ |
| 5324 | hash_value % spider_param_table_sts_thread_count()]; |
| 5325 | #else |
| 5326 | share->sts_thread = &spider_table_sts_threads[ |
| 5327 | my_calc_hash(&spider_open_tables, (uchar*) table_name, length) % |
| 5328 | spider_param_table_sts_thread_count()]; |
| 5329 | #endif |
| 5330 | share->sts_spider_init = TRUE; |
| 5331 | } |
| 5332 | pthread_mutex_unlock(&share->mutex); |
| 5333 | } |
| 5334 | |
| 5335 | if (!share->crd_spider_init) |
| 5336 | { |
| 5337 | pthread_mutex_lock(&share->mutex); |
| 5338 | if (!share->crd_spider_init) |
| 5339 | { |
| 5340 | if ((*error_num = spider_create_spider_object_for_share( |
| 5341 | spider->trx, share, &share->crd_spider))) |
| 5342 | { |
| 5343 | pthread_mutex_unlock(&share->mutex); |
| 5344 | spider_free_share(share); |
| 5345 | goto error_crd_spider_init; |
| 5346 | } |
| 5347 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
| 5348 | share->crd_thread = &spider_table_crd_threads[ |
| 5349 | hash_value % spider_param_table_crd_thread_count()]; |
| 5350 | #else |
| 5351 | share->crd_thread = &spider_table_crd_threads[ |
| 5352 | my_calc_hash(&spider_open_tables, (uchar*) table_name, length) % |
| 5353 | spider_param_table_crd_thread_count()]; |
| 5354 | #endif |
| 5355 | share->crd_spider_init = TRUE; |
| 5356 | } |
| 5357 | pthread_mutex_unlock(&share->mutex); |
| 5358 | } |
| 5359 | #endif |
| 5360 | |
| 5361 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 5362 | if ( |
| 5363 | sql_command != SQLCOM_DROP_TABLE && |
| 5364 | sql_command != SQLCOM_ALTER_TABLE && |
| 5365 | sql_command != SQLCOM_SHOW_CREATE && |
| 5366 | (*error_num = spider_create_mon_threads(spider->trx, share)) |
| 5367 | ) { |
| 5368 | spider_free_share(share); |
| 5369 | goto error_but_no_delete; |
| 5370 | } |
| 5371 | #endif |
| 5372 | |
| 5373 | if (!(spider->conn_keys = (char **) |
| 5374 | spider_bulk_alloc_mem(spider_current_trx, 49, |
| 5375 | __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), |
| 5376 | &spider->conn_keys, sizeof(char *) * share->link_count, |
| 5377 | &tmp_name, sizeof(char) * share->conn_keys_charlen, |
| 5378 | &spider->conns, sizeof(SPIDER_CONN *) * share->link_count, |
| 5379 | &spider->conn_link_idx, sizeof(uint) * share->link_count, |
| 5380 | &spider->conn_can_fo, sizeof(uchar) * share->link_bitmap_size, |
| 5381 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 5382 | &spider->hs_r_conn_keys, sizeof(char *) * share->link_count, |
| 5383 | &tmp_hs_r_name, sizeof(char) * share->hs_read_conn_keys_charlen, |
| 5384 | &spider->hs_r_conns, sizeof(SPIDER_CONN *) * share->link_count, |
| 5385 | &spider->hs_r_conn_ages, sizeof(ulonglong) * share->link_count, |
| 5386 | &spider->hs_w_conn_keys, sizeof(char *) * share->link_count, |
| 5387 | &tmp_hs_w_name, sizeof(char) * share->hs_write_conn_keys_charlen, |
| 5388 | &spider->hs_w_conns, sizeof(SPIDER_CONN *) * share->link_count, |
| 5389 | &spider->hs_w_conn_ages, sizeof(ulonglong) * share->link_count, |
| 5390 | #endif |
| 5391 | &spider->sql_kind, sizeof(uint) * share->link_count, |
| 5392 | &spider->connection_ids, sizeof(ulonglong) * share->link_count, |
| 5393 | &spider->conn_kind, sizeof(uint) * share->link_count, |
| 5394 | &spider->db_request_id, sizeof(ulonglong) * share->link_count, |
| 5395 | &spider->db_request_phase, sizeof(uchar) * share->link_bitmap_size, |
| 5396 | &spider->m_handler_opened, sizeof(uchar) * share->link_bitmap_size, |
| 5397 | &spider->m_handler_id, sizeof(uint) * share->link_count, |
| 5398 | &spider->m_handler_cid, sizeof(char *) * share->link_count, |
| 5399 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 5400 | &spider->r_handler_opened, sizeof(uchar) * share->link_bitmap_size, |
| 5401 | &spider->r_handler_id, sizeof(uint) * share->link_count, |
| 5402 | &spider->r_handler_index, sizeof(uint) * share->link_count, |
| 5403 | &spider->w_handler_opened, sizeof(uchar) * share->link_bitmap_size, |
| 5404 | &spider->w_handler_id, sizeof(uint) * share->link_count, |
| 5405 | &spider->w_handler_index, sizeof(uint) * share->link_count, |
| 5406 | #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS |
| 5407 | &spider->do_hs_direct_update, sizeof(uchar) * share->link_bitmap_size, |
| 5408 | &spider->hs_r_ret_fields, sizeof(uint32 *) * share->link_count, |
| 5409 | &spider->hs_w_ret_fields, sizeof(uint32 *) * share->link_count, |
| 5410 | &spider->hs_r_ret_fields_num, sizeof(size_t) * share->link_count, |
| 5411 | &spider->hs_w_ret_fields_num, sizeof(size_t) * share->link_count, |
| 5412 | &tmp_hs_r_ret_fields, |
| 5413 | sizeof(uint32) * share->link_count * table_share->fields, |
| 5414 | &tmp_hs_w_ret_fields, |
| 5415 | sizeof(uint32) * share->link_count * table_share->fields, |
| 5416 | &spider->tmp_column_bitmap, sizeof(uchar) * share->bitmap_size, |
| 5417 | #endif |
| 5418 | #endif |
| 5419 | &tmp_cid, sizeof(char) * (SPIDER_SQL_HANDLER_CID_LEN + 1) * |
| 5420 | share->link_count, |
| 5421 | &spider->need_mons, sizeof(int) * share->link_count, |
| 5422 | &spider->quick_targets, sizeof(void *) * share->link_count, |
| 5423 | &result_list->upd_tmp_tbls, sizeof(TABLE *) * share->link_count, |
| 5424 | &result_list->upd_tmp_tbl_prms, |
| 5425 | sizeof(TMP_TABLE_PARAM) * share->link_count, |
| 5426 | &result_list->tmp_table_join_first, |
| 5427 | sizeof(uchar) * share->link_bitmap_size, |
| 5428 | &result_list->tmp_table_created, |
| 5429 | sizeof(uchar) * share->link_bitmap_size, |
| 5430 | #ifdef HA_CAN_BULK_ACCESS |
| 5431 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 5432 | &result_list->hs_r_bulk_open_index, |
| 5433 | sizeof(uchar) * share->link_bitmap_size, |
| 5434 | &result_list->hs_w_bulk_open_index, |
| 5435 | sizeof(uchar) * share->link_bitmap_size, |
| 5436 | #endif |
| 5437 | #endif |
| 5438 | &result_list->sql_kind_backup, sizeof(uint) * share->link_count, |
| 5439 | &result_list->casual_read, sizeof(int) * share->link_count, |
| 5440 | &spider->dbton_handler, |
| 5441 | sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE, |
| 5442 | NullS)) |
| 5443 | ) { |
| 5444 | spider_free_share(share); |
| 5445 | goto error_but_no_delete; |
| 5446 | } |
| 5447 | memcpy(tmp_name, share->conn_keys[0], share->conn_keys_charlen); |
| 5448 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 5449 | memcpy(tmp_hs_r_name, share->hs_read_conn_keys[0], |
| 5450 | share->hs_read_conn_keys_charlen); |
| 5451 | memcpy(tmp_hs_w_name, share->hs_write_conn_keys[0], |
| 5452 | share->hs_write_conn_keys_charlen); |
| 5453 | #endif |
| 5454 | |
| 5455 | spider->conn_keys_first_ptr = tmp_name; |
| 5456 | for (roop_count = 0; roop_count < (int) share->link_count; roop_count++) |
| 5457 | { |
| 5458 | spider->conn_keys[roop_count] = tmp_name; |
| 5459 | *tmp_name = first_byte; |
| 5460 | tmp_name += share->conn_keys_lengths[roop_count] + 1; |
| 5461 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 5462 | spider->hs_r_conn_keys[roop_count] = tmp_hs_r_name; |
| 5463 | tmp_hs_r_name += share->hs_read_conn_keys_lengths[roop_count] + 1; |
| 5464 | spider->hs_w_conn_keys[roop_count] = tmp_hs_w_name; |
| 5465 | tmp_hs_w_name += share->hs_write_conn_keys_lengths[roop_count] + 1; |
| 5466 | #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS |
| 5467 | spider->hs_r_ret_fields[roop_count] = tmp_hs_r_ret_fields; |
| 5468 | tmp_hs_r_ret_fields += table_share->fields; |
| 5469 | spider->hs_w_ret_fields[roop_count] = tmp_hs_w_ret_fields; |
| 5470 | tmp_hs_w_ret_fields += table_share->fields; |
| 5471 | #endif |
| 5472 | #endif |
| 5473 | spider->m_handler_cid[roop_count] = tmp_cid; |
| 5474 | tmp_cid += SPIDER_SQL_HANDLER_CID_LEN + 1; |
| 5475 | result_list->upd_tmp_tbl_prms[roop_count].init(); |
| 5476 | result_list->upd_tmp_tbl_prms[roop_count].field_count = 1; |
| 5477 | spider->conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL; |
| 5478 | } |
| 5479 | spider_trx_set_link_idx_for_all(spider); |
| 5480 | |
| 5481 | for (roop_count = 0; roop_count < (int) share->use_dbton_count; |
| 5482 | roop_count++) |
| 5483 | { |
| 5484 | uint dbton_id = share->use_dbton_ids[roop_count]; |
| 5485 | if (!(spider->dbton_handler[dbton_id] = |
| 5486 | spider_dbton[dbton_id].create_db_handler(spider, |
| 5487 | share->dbton_share[dbton_id]))) |
| 5488 | { |
| 5489 | *error_num = HA_ERR_OUT_OF_MEM; |
| 5490 | break; |
| 5491 | } |
| 5492 | if ((*error_num = spider->dbton_handler[dbton_id]->init())) |
| 5493 | { |
| 5494 | break; |
| 5495 | } |
| 5496 | } |
| 5497 | if (roop_count < (int) share->use_dbton_count) |
| 5498 | { |
| 5499 | for (; roop_count >= 0; roop_count--) |
| 5500 | { |
| 5501 | uint dbton_id = share->use_dbton_ids[roop_count]; |
| 5502 | if (spider->dbton_handler[dbton_id]) |
| 5503 | { |
| 5504 | delete spider->dbton_handler[dbton_id]; |
| 5505 | spider->dbton_handler[dbton_id] = NULL; |
| 5506 | } |
| 5507 | } |
| 5508 | goto error_but_no_delete; |
| 5509 | } |
| 5510 | |
| 5511 | if ( |
| 5512 | sql_command != SQLCOM_DROP_TABLE && |
| 5513 | sql_command != SQLCOM_ALTER_TABLE && |
| 5514 | sql_command != SQLCOM_SHOW_CREATE |
| 5515 | ) { |
| 5516 | for ( |
| 5517 | roop_count = spider_conn_link_idx_next(share->link_statuses, |
| 5518 | spider->conn_link_idx, -1, share->link_count, |
| 5519 | SPIDER_LINK_STATUS_RECOVERY); |
| 5520 | roop_count < (int) share->link_count; |
| 5521 | roop_count = spider_conn_link_idx_next(share->link_statuses, |
| 5522 | spider->conn_link_idx, roop_count, share->link_count, |
| 5523 | SPIDER_LINK_STATUS_RECOVERY) |
| 5524 | ) { |
| 5525 | if ( |
| 5526 | !(spider->conns[roop_count] = |
| 5527 | spider_get_conn(share, roop_count, spider->conn_keys[roop_count], |
| 5528 | spider->trx, spider, FALSE, TRUE, SPIDER_CONN_KIND_MYSQL, |
| 5529 | error_num)) |
| 5530 | ) { |
| 5531 | if ( |
| 5532 | share->monitoring_kind[roop_count] && |
| 5533 | spider->need_mons[roop_count] |
| 5534 | ) { |
| 5535 | *error_num = spider_ping_table_mon_from_table( |
| 5536 | spider->trx, |
| 5537 | spider->trx->thd, |
| 5538 | share, |
| 5539 | roop_count, |
| 5540 | (uint32) share->monitoring_sid[roop_count], |
| 5541 | share->table_name, |
| 5542 | share->table_name_length, |
| 5543 | spider->conn_link_idx[roop_count], |
| 5544 | NULL, |
| 5545 | 0, |
| 5546 | share->monitoring_kind[roop_count], |
| 5547 | share->monitoring_limit[roop_count], |
| 5548 | share->monitoring_flag[roop_count], |
| 5549 | FALSE |
| 5550 | ); |
| 5551 | } |
| 5552 | spider_free_share(share); |
| 5553 | goto error_but_no_delete; |
| 5554 | } |
| 5555 | spider->conns[roop_count]->error_mode &= spider->error_mode; |
| 5556 | } |
| 5557 | } |
| 5558 | search_link_idx = spider_conn_first_link_idx(thd, |
| 5559 | share->link_statuses, share->access_balances, spider->conn_link_idx, |
| 5560 | share->link_count, SPIDER_LINK_STATUS_OK); |
| 5561 | if (search_link_idx == -1) |
| 5562 | { |
| 5563 | char *db = (char *) my_alloca( |
| 5564 | table_share->db.length + 1 + table_share->table_name.length + 1); |
| 5565 | if (!db) |
| 5566 | { |
| 5567 | *error_num = HA_ERR_OUT_OF_MEM; |
| 5568 | spider_free_share(share); |
| 5569 | goto error_but_no_delete; |
| 5570 | } |
| 5571 | char *table_name = db + table_share->db.length + 1; |
| 5572 | memcpy(db, table_share->db.str, table_share->db.length); |
| 5573 | db[table_share->db.length] = '\0'; |
| 5574 | memcpy(table_name, table_share->table_name.str, |
| 5575 | table_share->table_name.length); |
| 5576 | table_name[table_share->table_name.length] = '\0'; |
| 5577 | my_printf_error(ER_SPIDER_ALL_LINKS_FAILED_NUM, |
| 5578 | ER_SPIDER_ALL_LINKS_FAILED_STR, MYF(0), db, table_name); |
| 5579 | my_afree(db); |
| 5580 | *error_num = ER_SPIDER_ALL_LINKS_FAILED_NUM; |
| 5581 | spider_free_share(share); |
| 5582 | goto error_but_no_delete; |
| 5583 | } else if (search_link_idx == -2) |
| 5584 | { |
| 5585 | *error_num = HA_ERR_OUT_OF_MEM; |
| 5586 | spider_free_share(share); |
| 5587 | goto error_but_no_delete; |
| 5588 | } |
| 5589 | spider->search_link_idx = search_link_idx; |
| 5590 | |
| 5591 | if (share->init_error) |
| 5592 | { |
| 5593 | pthread_mutex_lock(&share->sts_mutex); |
| 5594 | pthread_mutex_lock(&share->crd_mutex); |
| 5595 | if (share->init_error) |
| 5596 | { |
| 5597 | same_server_link = spider_param_same_server_link(thd); |
| 5598 | load_sts_at_startup = |
| 5599 | spider_param_load_sts_at_startup(share->load_sts_at_startup); |
| 5600 | load_crd_at_startup = |
| 5601 | spider_param_load_crd_at_startup(share->load_crd_at_startup); |
| 5602 | if ( |
| 5603 | sql_command != SQLCOM_DROP_TABLE && |
| 5604 | sql_command != SQLCOM_ALTER_TABLE && |
| 5605 | sql_command != SQLCOM_SHOW_CREATE && |
| 5606 | !spider->error_mode && |
| 5607 | ( |
| 5608 | !same_server_link || |
| 5609 | load_sts_at_startup || |
| 5610 | load_crd_at_startup |
| 5611 | ) |
| 5612 | ) { |
| 5613 | SPIDER_INIT_ERROR_TABLE *spider_init_error_table; |
| 5614 | sts_interval = spider_param_sts_interval(thd, share->sts_interval); |
| 5615 | sts_mode = spider_param_sts_mode(thd, share->sts_mode); |
| 5616 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 5617 | sts_sync = spider_param_sts_sync(thd, share->sts_sync); |
| 5618 | auto_increment_mode = spider_param_auto_increment_mode(thd, |
| 5619 | share->auto_increment_mode); |
| 5620 | if (auto_increment_mode == 1) |
| 5621 | sts_sync = 0; |
| 5622 | #endif |
| 5623 | crd_interval = spider_param_crd_interval(thd, share->crd_interval); |
| 5624 | crd_mode = spider_param_crd_mode(thd, share->crd_mode); |
| 5625 | if (crd_mode == 3) |
| 5626 | crd_mode = 1; |
| 5627 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 5628 | crd_sync = spider_param_crd_sync(thd, share->crd_sync); |
| 5629 | #endif |
| 5630 | time_t tmp_time = (time_t) time((time_t*) 0); |
| 5631 | if ((spider_init_error_table = |
| 5632 | spider_get_init_error_table(spider->trx, share, FALSE))) |
| 5633 | { |
| 5634 | DBUG_PRINT("info" ,("spider diff2=%f" , |
| 5635 | difftime(tmp_time, spider_init_error_table->init_error_time))); |
| 5636 | if (difftime(tmp_time, |
| 5637 | spider_init_error_table->init_error_time) < |
| 5638 | spider_param_table_init_error_interval()) |
| 5639 | { |
| 5640 | *error_num = spider_init_error_table->init_error; |
| 5641 | if (spider_init_error_table->init_error_with_message) |
| 5642 | my_message(spider_init_error_table->init_error, |
| 5643 | spider_init_error_table->init_error_msg, MYF(0)); |
| 5644 | pthread_mutex_unlock(&share->crd_mutex); |
| 5645 | pthread_mutex_unlock(&share->sts_mutex); |
| 5646 | spider_free_share(share); |
| 5647 | goto error_but_no_delete; |
| 5648 | } |
| 5649 | } |
| 5650 | |
| 5651 | if ( |
| 5652 | ( |
| 5653 | !same_server_link || |
| 5654 | load_sts_at_startup |
| 5655 | ) && |
| 5656 | spider_get_sts(share, spider->search_link_idx, |
| 5657 | tmp_time, spider, sts_interval, sts_mode, |
| 5658 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 5659 | sts_sync, |
| 5660 | #endif |
| 5661 | 1, HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_AUTO) |
| 5662 | ) { |
| 5663 | thd->clear_error(); |
| 5664 | } |
| 5665 | if ( |
| 5666 | ( |
| 5667 | !same_server_link || |
| 5668 | load_crd_at_startup |
| 5669 | ) && |
| 5670 | spider_get_crd(share, spider->search_link_idx, |
| 5671 | tmp_time, spider, table, crd_interval, crd_mode, |
| 5672 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 5673 | crd_sync, |
| 5674 | #endif |
| 5675 | 1) |
| 5676 | ) { |
| 5677 | thd->clear_error(); |
| 5678 | } |
| 5679 | } |
| 5680 | share->init_error = FALSE; |
| 5681 | } |
| 5682 | pthread_mutex_unlock(&share->crd_mutex); |
| 5683 | pthread_mutex_unlock(&share->sts_mutex); |
| 5684 | } |
| 5685 | } |
| 5686 | |
| 5687 | DBUG_PRINT("info" ,("spider share=%p" , share)); |
| 5688 | DBUG_RETURN(share); |
| 5689 | |
| 5690 | error_hash_insert: |
| 5691 | spider_free_share_resource_only(share); |
| 5692 | error_alloc_share: |
| 5693 | pthread_mutex_unlock(&spider_tbl_mutex); |
| 5694 | error_get_link_statuses: |
| 5695 | if (table_tables) |
| 5696 | { |
| 5697 | spider_close_sys_table(thd, table_tables, |
| 5698 | &open_tables_backup, FALSE); |
| 5699 | table_tables = NULL; |
| 5700 | } |
| 5701 | error_open_sys_table: |
| 5702 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 5703 | error_crd_spider_init: |
| 5704 | error_sts_spider_init: |
| 5705 | #endif |
| 5706 | if (init_mem_root) |
| 5707 | { |
| 5708 | free_root(&mem_root, MYF(0)); |
| 5709 | init_mem_root = FALSE; |
| 5710 | } |
| 5711 | error_but_no_delete: |
| 5712 | DBUG_RETURN(NULL); |
| 5713 | } |
| 5714 | |
| 5715 | void spider_free_share_resource_only( |
| 5716 | SPIDER_SHARE *share |
| 5717 | ) { |
| 5718 | DBUG_ENTER("spider_free_share_resource_only" ); |
| 5719 | spider_free_share_alloc(share); |
| 5720 | thr_lock_delete(&share->lock); |
| 5721 | pthread_mutex_destroy(&share->crd_mutex); |
| 5722 | pthread_mutex_destroy(&share->sts_mutex); |
| 5723 | pthread_mutex_destroy(&share->mutex); |
| 5724 | spider_free(spider_current_trx, share, MYF(0)); |
| 5725 | DBUG_VOID_RETURN; |
| 5726 | } |
| 5727 | |
| 5728 | int spider_free_share( |
| 5729 | SPIDER_SHARE *share |
| 5730 | ) { |
| 5731 | DBUG_ENTER("spider_free_share" ); |
| 5732 | pthread_mutex_lock(&spider_tbl_mutex); |
| 5733 | bool do_delete_thd = false; |
| 5734 | THD *thd = current_thd; |
| 5735 | if (!--share->use_count) |
| 5736 | { |
| 5737 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 5738 | spider_free_sts_thread(share); |
| 5739 | spider_free_crd_thread(share); |
| 5740 | spider_free_mon_threads(share); |
| 5741 | if (share->sts_spider_init) |
| 5742 | { |
| 5743 | spider_table_remove_share_from_sts_thread(share); |
| 5744 | spider_free_spider_object_for_share(&share->sts_spider); |
| 5745 | } |
| 5746 | if (share->crd_spider_init) |
| 5747 | { |
| 5748 | spider_table_remove_share_from_crd_thread(share); |
| 5749 | spider_free_spider_object_for_share(&share->crd_spider); |
| 5750 | } |
| 5751 | #endif |
| 5752 | if ( |
| 5753 | share->sts_init && |
| 5754 | spider_param_store_last_sts(share->store_last_sts) |
| 5755 | ) { |
| 5756 | if (!thd) |
| 5757 | { |
| 5758 | /* Create a thread for Spider system table update */ |
| 5759 | thd = spider_create_thd(); |
| 5760 | if (!thd) |
| 5761 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 5762 | do_delete_thd = TRUE; |
| 5763 | } |
| 5764 | spider_sys_insert_or_update_table_sts( |
| 5765 | thd, |
| 5766 | share->lgtm_tblhnd_share->table_name, |
| 5767 | share->lgtm_tblhnd_share->table_name_length, |
| 5768 | &share->data_file_length, |
| 5769 | &share->max_data_file_length, |
| 5770 | &share->index_file_length, |
| 5771 | &share->records, |
| 5772 | &share->mean_rec_length, |
| 5773 | &share->check_time, |
| 5774 | &share->create_time, |
| 5775 | &share->update_time, |
| 5776 | FALSE |
| 5777 | ); |
| 5778 | } |
| 5779 | if ( |
| 5780 | share->crd_init && |
| 5781 | spider_param_store_last_crd(share->store_last_crd) |
| 5782 | ) { |
| 5783 | if (!thd) |
| 5784 | { |
| 5785 | /* Create a thread for Spider system table update */ |
| 5786 | thd = spider_create_thd(); |
| 5787 | if (!thd) |
| 5788 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 5789 | do_delete_thd = TRUE; |
| 5790 | } |
| 5791 | spider_sys_insert_or_update_table_crd( |
| 5792 | thd, |
| 5793 | share->lgtm_tblhnd_share->table_name, |
| 5794 | share->lgtm_tblhnd_share->table_name_length, |
| 5795 | share->cardinality, |
| 5796 | share->table_share->fields, |
| 5797 | FALSE |
| 5798 | ); |
| 5799 | } |
| 5800 | spider_free_share_alloc(share); |
| 5801 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
| 5802 | my_hash_delete_with_hash_value(&spider_open_tables, |
| 5803 | share->table_name_hash_value, (uchar*) share); |
| 5804 | #else |
| 5805 | my_hash_delete(&spider_open_tables, (uchar*) share); |
| 5806 | #endif |
| 5807 | thr_lock_delete(&share->lock); |
| 5808 | pthread_mutex_destroy(&share->crd_mutex); |
| 5809 | pthread_mutex_destroy(&share->sts_mutex); |
| 5810 | pthread_mutex_destroy(&share->mutex); |
| 5811 | free_root(&share->mem_root, MYF(0)); |
| 5812 | spider_free(spider_current_trx, share, MYF(0)); |
| 5813 | } |
| 5814 | if (do_delete_thd) |
| 5815 | spider_destroy_thd(thd); |
| 5816 | pthread_mutex_unlock(&spider_tbl_mutex); |
| 5817 | DBUG_RETURN(0); |
| 5818 | } |
| 5819 | |
| 5820 | void spider_update_link_status_for_share( |
| 5821 | const char *table_name, |
| 5822 | uint table_name_length, |
| 5823 | int link_idx, |
| 5824 | long link_status |
| 5825 | ) { |
| 5826 | SPIDER_SHARE *share; |
| 5827 | DBUG_ENTER("spider_update_link_status_for_share" ); |
| 5828 | |
| 5829 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 5830 | my_hash_value_type hash_value = my_calc_hash(&spider_open_tables, |
| 5831 | (uchar*) table_name, table_name_length); |
| 5832 | #endif |
| 5833 | pthread_mutex_lock(&spider_tbl_mutex); |
| 5834 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 5835 | if ((share = (SPIDER_SHARE*) my_hash_search_using_hash_value( |
| 5836 | &spider_open_tables, hash_value, (uchar*) table_name, |
| 5837 | table_name_length))) |
| 5838 | #else |
| 5839 | if ((share = (SPIDER_SHARE*) my_hash_search(&spider_open_tables, |
| 5840 | (uchar*) table_name, table_name_length))) |
| 5841 | #endif |
| 5842 | { |
| 5843 | DBUG_PRINT("info" , ("spider share->link_status_init=%s" , |
| 5844 | share->link_status_init ? "TRUE" : "FALSE" )); |
| 5845 | if (share->link_status_init) |
| 5846 | { |
| 5847 | DBUG_PRINT("info" , ("spider share->link_statuses[%d]=%ld" , |
| 5848 | link_idx, link_status)); |
| 5849 | share->link_statuses[link_idx] = link_status; |
| 5850 | } |
| 5851 | } |
| 5852 | pthread_mutex_unlock(&spider_tbl_mutex); |
| 5853 | DBUG_VOID_RETURN; |
| 5854 | } |
| 5855 | |
| 5856 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 5857 | SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share( |
| 5858 | const char *table_name, |
| 5859 | uint table_name_length, |
| 5860 | my_hash_value_type hash_value, |
| 5861 | bool locked, |
| 5862 | bool need_to_create, |
| 5863 | int *error_num |
| 5864 | ) |
| 5865 | #else |
| 5866 | SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share( |
| 5867 | const char *table_name, |
| 5868 | uint table_name_length, |
| 5869 | bool locked, |
| 5870 | bool need_to_create, |
| 5871 | int *error_num |
| 5872 | ) |
| 5873 | #endif |
| 5874 | { |
| 5875 | SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share; |
| 5876 | char *tmp_name; |
| 5877 | DBUG_ENTER("spider_get_lgtm_tblhnd_share" ); |
| 5878 | |
| 5879 | if (!locked) |
| 5880 | pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex); |
| 5881 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 5882 | if (!(lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE*) |
| 5883 | my_hash_search_using_hash_value( |
| 5884 | &spider_lgtm_tblhnd_share_hash, hash_value, |
| 5885 | (uchar*) table_name, table_name_length))) |
| 5886 | #else |
| 5887 | if (!(lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE*) my_hash_search( |
| 5888 | &spider_lgtm_tblhnd_share_hash, |
| 5889 | (uchar*) table_name, table_name_length))) |
| 5890 | #endif |
| 5891 | { |
| 5892 | DBUG_PRINT("info" ,("spider create new lgtm tblhnd share" )); |
| 5893 | if (!(lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE *) |
| 5894 | spider_bulk_malloc(spider_current_trx, 244, MYF(MY_WME | MY_ZEROFILL), |
| 5895 | &lgtm_tblhnd_share, sizeof(*lgtm_tblhnd_share), |
| 5896 | &tmp_name, table_name_length + 1, |
| 5897 | NullS)) |
| 5898 | ) { |
| 5899 | *error_num = HA_ERR_OUT_OF_MEM; |
| 5900 | goto error_alloc_share; |
| 5901 | } |
| 5902 | |
| 5903 | lgtm_tblhnd_share->table_name_length = table_name_length; |
| 5904 | lgtm_tblhnd_share->table_name = tmp_name; |
| 5905 | memcpy(lgtm_tblhnd_share->table_name, table_name, |
| 5906 | lgtm_tblhnd_share->table_name_length); |
| 5907 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 5908 | lgtm_tblhnd_share->table_path_hash_value = hash_value; |
| 5909 | #endif |
| 5910 | |
| 5911 | #if MYSQL_VERSION_ID < 50500 |
| 5912 | if (pthread_mutex_init(&lgtm_tblhnd_share->auto_increment_mutex, |
| 5913 | MY_MUTEX_INIT_FAST)) |
| 5914 | #else |
| 5915 | if (mysql_mutex_init(spd_key_mutex_share_auto_increment, |
| 5916 | &lgtm_tblhnd_share->auto_increment_mutex, MY_MUTEX_INIT_FAST)) |
| 5917 | #endif |
| 5918 | { |
| 5919 | *error_num = HA_ERR_OUT_OF_MEM; |
| 5920 | goto error_init_auto_increment_mutex; |
| 5921 | } |
| 5922 | |
| 5923 | uint old_elements = spider_lgtm_tblhnd_share_hash.array.max_element; |
| 5924 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
| 5925 | if (my_hash_insert_with_hash_value(&spider_lgtm_tblhnd_share_hash, |
| 5926 | hash_value, (uchar*) lgtm_tblhnd_share)) |
| 5927 | #else |
| 5928 | if (my_hash_insert(&spider_lgtm_tblhnd_share_hash, |
| 5929 | (uchar*) lgtm_tblhnd_share)) |
| 5930 | #endif |
| 5931 | { |
| 5932 | *error_num = HA_ERR_OUT_OF_MEM; |
| 5933 | goto error_hash_insert; |
| 5934 | } |
| 5935 | if (spider_lgtm_tblhnd_share_hash.array.max_element > old_elements) |
| 5936 | { |
| 5937 | spider_alloc_calc_mem(spider_current_trx, |
| 5938 | spider_lgtm_tblhnd_share_hash, |
| 5939 | (spider_lgtm_tblhnd_share_hash.array.max_element - old_elements) * |
| 5940 | spider_lgtm_tblhnd_share_hash.array.size_of_element); |
| 5941 | } |
| 5942 | } |
| 5943 | if (!locked) |
| 5944 | pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex); |
| 5945 | |
| 5946 | DBUG_PRINT("info" ,("spider lgtm_tblhnd_share=%p" , lgtm_tblhnd_share)); |
| 5947 | DBUG_RETURN(lgtm_tblhnd_share); |
| 5948 | |
| 5949 | error_hash_insert: |
| 5950 | pthread_mutex_destroy(&lgtm_tblhnd_share->auto_increment_mutex); |
| 5951 | error_init_auto_increment_mutex: |
| 5952 | spider_free(spider_current_trx, lgtm_tblhnd_share, MYF(0)); |
| 5953 | error_alloc_share: |
| 5954 | if (!locked) |
| 5955 | pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex); |
| 5956 | DBUG_RETURN(NULL); |
| 5957 | } |
| 5958 | |
| 5959 | void spider_free_lgtm_tblhnd_share_alloc( |
| 5960 | SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share, |
| 5961 | bool locked |
| 5962 | ) { |
| 5963 | DBUG_ENTER("spider_free_lgtm_tblhnd_share" ); |
| 5964 | if (!locked) |
| 5965 | pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex); |
| 5966 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
| 5967 | my_hash_delete_with_hash_value(&spider_lgtm_tblhnd_share_hash, |
| 5968 | lgtm_tblhnd_share->table_path_hash_value, (uchar*) lgtm_tblhnd_share); |
| 5969 | #else |
| 5970 | my_hash_delete(&spider_lgtm_tblhnd_share_hash, (uchar*) lgtm_tblhnd_share); |
| 5971 | #endif |
| 5972 | pthread_mutex_destroy(&lgtm_tblhnd_share->auto_increment_mutex); |
| 5973 | spider_free(spider_current_trx, lgtm_tblhnd_share, MYF(0)); |
| 5974 | if (!locked) |
| 5975 | pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex); |
| 5976 | DBUG_VOID_RETURN; |
| 5977 | } |
| 5978 | |
| 5979 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 5980 | SPIDER_PARTITION_SHARE *spider_get_pt_share( |
| 5981 | SPIDER_SHARE *share, |
| 5982 | TABLE_SHARE *table_share, |
| 5983 | int *error_num |
| 5984 | ) { |
| 5985 | SPIDER_PARTITION_SHARE *partition_share; |
| 5986 | char *tmp_name; |
| 5987 | longlong *tmp_cardinality; |
| 5988 | DBUG_ENTER("spider_get_pt_share" ); |
| 5989 | |
| 5990 | pthread_mutex_lock(&spider_pt_share_mutex); |
| 5991 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 5992 | if (!(partition_share = (SPIDER_PARTITION_SHARE*) |
| 5993 | my_hash_search_using_hash_value( |
| 5994 | &spider_open_pt_share, share->table_path_hash_value, |
| 5995 | (uchar*) table_share->path.str, table_share->path.length))) |
| 5996 | #else |
| 5997 | if (!(partition_share = (SPIDER_PARTITION_SHARE*) my_hash_search( |
| 5998 | &spider_open_pt_share, |
| 5999 | (uchar*) table_share->path.str, table_share->path.length))) |
| 6000 | #endif |
| 6001 | { |
| 6002 | DBUG_PRINT("info" ,("spider create new pt share" )); |
| 6003 | if (!(partition_share = (SPIDER_PARTITION_SHARE *) |
| 6004 | spider_bulk_malloc(spider_current_trx, 51, MYF(MY_WME | MY_ZEROFILL), |
| 6005 | &partition_share, sizeof(*partition_share), |
| 6006 | &tmp_name, table_share->path.length + 1, |
| 6007 | &tmp_cardinality, sizeof(*tmp_cardinality) * table_share->fields, |
| 6008 | NullS)) |
| 6009 | ) { |
| 6010 | *error_num = HA_ERR_OUT_OF_MEM; |
| 6011 | goto error_alloc_share; |
| 6012 | } |
| 6013 | |
| 6014 | partition_share->use_count = 0; |
| 6015 | partition_share->table_name_length = table_share->path.length; |
| 6016 | partition_share->table_name = tmp_name; |
| 6017 | memcpy(partition_share->table_name, table_share->path.str, |
| 6018 | partition_share->table_name_length); |
| 6019 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 6020 | partition_share->table_path_hash_value = share->table_path_hash_value; |
| 6021 | #endif |
| 6022 | partition_share->cardinality = tmp_cardinality; |
| 6023 | |
| 6024 | partition_share->crd_get_time = partition_share->sts_get_time = |
| 6025 | share->crd_get_time; |
| 6026 | |
| 6027 | #if MYSQL_VERSION_ID < 50500 |
| 6028 | if (pthread_mutex_init(&partition_share->sts_mutex, MY_MUTEX_INIT_FAST)) |
| 6029 | #else |
| 6030 | if (mysql_mutex_init(spd_key_mutex_pt_share_sts, |
| 6031 | &partition_share->sts_mutex, MY_MUTEX_INIT_FAST)) |
| 6032 | #endif |
| 6033 | { |
| 6034 | *error_num = HA_ERR_OUT_OF_MEM; |
| 6035 | goto error_init_sts_mutex; |
| 6036 | } |
| 6037 | |
| 6038 | #if MYSQL_VERSION_ID < 50500 |
| 6039 | if (pthread_mutex_init(&partition_share->crd_mutex, MY_MUTEX_INIT_FAST)) |
| 6040 | #else |
| 6041 | if (mysql_mutex_init(spd_key_mutex_pt_share_crd, |
| 6042 | &partition_share->crd_mutex, MY_MUTEX_INIT_FAST)) |
| 6043 | #endif |
| 6044 | { |
| 6045 | *error_num = HA_ERR_OUT_OF_MEM; |
| 6046 | goto error_init_crd_mutex; |
| 6047 | } |
| 6048 | |
| 6049 | #if MYSQL_VERSION_ID < 50500 |
| 6050 | if (pthread_mutex_init(&partition_share->pt_handler_mutex, |
| 6051 | MY_MUTEX_INIT_FAST)) |
| 6052 | #else |
| 6053 | if (mysql_mutex_init(spd_key_mutex_pt_handler, |
| 6054 | &partition_share->pt_handler_mutex, MY_MUTEX_INIT_FAST)) |
| 6055 | #endif |
| 6056 | { |
| 6057 | *error_num = HA_ERR_OUT_OF_MEM; |
| 6058 | goto error_init_pt_handler_mutex; |
| 6059 | } |
| 6060 | |
| 6061 | if( |
| 6062 | my_hash_init(&partition_share->pt_handler_hash, spd_charset_utf8_bin, |
| 6063 | 32, 0, 0, (my_hash_get_key) spider_pt_handler_share_get_key, 0, 0) |
| 6064 | ) { |
| 6065 | *error_num = HA_ERR_OUT_OF_MEM; |
| 6066 | goto error_init_pt_handler_hash; |
| 6067 | } |
| 6068 | spider_alloc_calc_mem_init(partition_share->pt_handler_hash, 142); |
| 6069 | spider_alloc_calc_mem(spider_current_trx, |
| 6070 | partition_share->pt_handler_hash, |
| 6071 | partition_share->pt_handler_hash.array.max_element * |
| 6072 | partition_share->pt_handler_hash.array.size_of_element); |
| 6073 | |
| 6074 | uint old_elements = spider_open_pt_share.array.max_element; |
| 6075 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
| 6076 | if (my_hash_insert_with_hash_value(&spider_open_pt_share, |
| 6077 | share->table_path_hash_value, |
| 6078 | (uchar*) partition_share)) |
| 6079 | #else |
| 6080 | if (my_hash_insert(&spider_open_pt_share, (uchar*) partition_share)) |
| 6081 | #endif |
| 6082 | { |
| 6083 | *error_num = HA_ERR_OUT_OF_MEM; |
| 6084 | goto error_hash_insert; |
| 6085 | } |
| 6086 | if (spider_open_pt_share.array.max_element > old_elements) |
| 6087 | { |
| 6088 | spider_alloc_calc_mem(spider_current_trx, |
| 6089 | spider_open_pt_share, |
| 6090 | (spider_open_pt_share.array.max_element - old_elements) * |
| 6091 | spider_open_pt_share.array.size_of_element); |
| 6092 | } |
| 6093 | } |
| 6094 | partition_share->use_count++; |
| 6095 | pthread_mutex_unlock(&spider_pt_share_mutex); |
| 6096 | |
| 6097 | DBUG_PRINT("info" ,("spider partition_share=%p" , partition_share)); |
| 6098 | DBUG_RETURN(partition_share); |
| 6099 | |
| 6100 | error_hash_insert: |
| 6101 | spider_free_mem_calc(spider_current_trx, |
| 6102 | partition_share->pt_handler_hash_id, |
| 6103 | partition_share->pt_handler_hash.array.max_element * |
| 6104 | partition_share->pt_handler_hash.array.size_of_element); |
| 6105 | my_hash_free(&partition_share->pt_handler_hash); |
| 6106 | error_init_pt_handler_hash: |
| 6107 | pthread_mutex_destroy(&partition_share->pt_handler_mutex); |
| 6108 | error_init_pt_handler_mutex: |
| 6109 | pthread_mutex_destroy(&partition_share->crd_mutex); |
| 6110 | error_init_crd_mutex: |
| 6111 | pthread_mutex_destroy(&partition_share->sts_mutex); |
| 6112 | error_init_sts_mutex: |
| 6113 | spider_free(spider_current_trx, partition_share, MYF(0)); |
| 6114 | error_alloc_share: |
| 6115 | pthread_mutex_unlock(&spider_pt_share_mutex); |
| 6116 | DBUG_RETURN(NULL); |
| 6117 | } |
| 6118 | |
| 6119 | int spider_free_pt_share( |
| 6120 | SPIDER_PARTITION_SHARE *partition_share |
| 6121 | ) { |
| 6122 | DBUG_ENTER("spider_free_pt_share" ); |
| 6123 | pthread_mutex_lock(&spider_pt_share_mutex); |
| 6124 | if (!--partition_share->use_count) |
| 6125 | { |
| 6126 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
| 6127 | my_hash_delete_with_hash_value(&spider_open_pt_share, |
| 6128 | partition_share->table_path_hash_value, (uchar*) partition_share); |
| 6129 | #else |
| 6130 | my_hash_delete(&spider_open_pt_share, (uchar*) partition_share); |
| 6131 | #endif |
| 6132 | spider_free_mem_calc(spider_current_trx, |
| 6133 | partition_share->pt_handler_hash_id, |
| 6134 | partition_share->pt_handler_hash.array.max_element * |
| 6135 | partition_share->pt_handler_hash.array.size_of_element); |
| 6136 | my_hash_free(&partition_share->pt_handler_hash); |
| 6137 | pthread_mutex_destroy(&partition_share->pt_handler_mutex); |
| 6138 | pthread_mutex_destroy(&partition_share->crd_mutex); |
| 6139 | pthread_mutex_destroy(&partition_share->sts_mutex); |
| 6140 | spider_free(spider_current_trx, partition_share, MYF(0)); |
| 6141 | } |
| 6142 | pthread_mutex_unlock(&spider_pt_share_mutex); |
| 6143 | DBUG_RETURN(0); |
| 6144 | } |
| 6145 | |
| 6146 | void spider_copy_sts_to_pt_share( |
| 6147 | SPIDER_PARTITION_SHARE *partition_share, |
| 6148 | SPIDER_SHARE *share |
| 6149 | ) { |
| 6150 | DBUG_ENTER("spider_copy_sts_to_pt_share" ); |
| 6151 | memcpy(&partition_share->data_file_length, &share->data_file_length, |
| 6152 | sizeof(ulonglong) * 4 + sizeof(ha_rows) + |
| 6153 | sizeof(ulong) + sizeof(time_t) * 3); |
| 6154 | /* |
| 6155 | partition_share->data_file_length = share->data_file_length; |
| 6156 | partition_share->max_data_file_length = share->max_data_file_length; |
| 6157 | partition_share->index_file_length = share->index_file_length; |
| 6158 | partition_share->auto_increment_value = |
| 6159 | share->lgtm_tblhnd_share->auto_increment_value; |
| 6160 | partition_share->records = share->records; |
| 6161 | partition_share->mean_rec_length = share->mean_rec_length; |
| 6162 | partition_share->check_time = share->check_time; |
| 6163 | partition_share->create_time = share->create_time; |
| 6164 | partition_share->update_time = share->update_time; |
| 6165 | */ |
| 6166 | DBUG_VOID_RETURN; |
| 6167 | } |
| 6168 | |
| 6169 | void spider_copy_sts_to_share( |
| 6170 | SPIDER_SHARE *share, |
| 6171 | SPIDER_PARTITION_SHARE *partition_share |
| 6172 | ) { |
| 6173 | DBUG_ENTER("spider_copy_sts_to_share" ); |
| 6174 | memcpy(&share->data_file_length, &partition_share->data_file_length, |
| 6175 | sizeof(ulonglong) * 4 + sizeof(ha_rows) + |
| 6176 | sizeof(ulong) + sizeof(time_t) * 3); |
| 6177 | /* |
| 6178 | share->data_file_length = partition_share->data_file_length; |
| 6179 | share->max_data_file_length = partition_share->max_data_file_length; |
| 6180 | share->index_file_length = partition_share->index_file_length; |
| 6181 | share->lgtm_tblhnd_share->auto_increment_value = |
| 6182 | partition_share->auto_increment_value; |
| 6183 | DBUG_PRINT("info",("spider auto_increment_value=%llu", |
| 6184 | share->lgtm_tblhnd_share->auto_increment_value)); |
| 6185 | share->records = partition_share->records; |
| 6186 | share->mean_rec_length = partition_share->mean_rec_length; |
| 6187 | share->check_time = partition_share->check_time; |
| 6188 | share->create_time = partition_share->create_time; |
| 6189 | share->update_time = partition_share->update_time; |
| 6190 | */ |
| 6191 | DBUG_VOID_RETURN; |
| 6192 | } |
| 6193 | |
| 6194 | void spider_copy_crd_to_pt_share( |
| 6195 | SPIDER_PARTITION_SHARE *partition_share, |
| 6196 | SPIDER_SHARE *share, |
| 6197 | int fields |
| 6198 | ) { |
| 6199 | DBUG_ENTER("spider_copy_crd_to_pt_share" ); |
| 6200 | memcpy(partition_share->cardinality, share->cardinality, |
| 6201 | sizeof(longlong) * fields); |
| 6202 | DBUG_VOID_RETURN; |
| 6203 | } |
| 6204 | |
| 6205 | void spider_copy_crd_to_share( |
| 6206 | SPIDER_SHARE *share, |
| 6207 | SPIDER_PARTITION_SHARE *partition_share, |
| 6208 | int fields |
| 6209 | ) { |
| 6210 | DBUG_ENTER("spider_copy_crd_to_share" ); |
| 6211 | memcpy(share->cardinality, partition_share->cardinality, |
| 6212 | sizeof(longlong) * fields); |
| 6213 | DBUG_VOID_RETURN; |
| 6214 | } |
| 6215 | #endif |
| 6216 | |
| 6217 | int spider_open_all_tables( |
| 6218 | SPIDER_TRX *trx, |
| 6219 | bool lock |
| 6220 | ) { |
| 6221 | THD *thd = trx->thd; |
| 6222 | TABLE *table_tables; |
| 6223 | int error_num, *need_mon, mon_val; |
| 6224 | SPIDER_SHARE tmp_share; |
| 6225 | char *db_name, *table_name; |
| 6226 | uint db_name_length, table_name_length; |
| 6227 | char *tmp_connect_info[SPIDER_TMP_SHARE_CHAR_PTR_COUNT]; |
| 6228 | uint tmp_connect_info_length[SPIDER_TMP_SHARE_UINT_COUNT]; |
| 6229 | long tmp_long[SPIDER_TMP_SHARE_LONG_COUNT]; |
| 6230 | longlong tmp_longlong[SPIDER_TMP_SHARE_LONGLONG_COUNT]; |
| 6231 | SPIDER_CONN *conn, **conns; |
| 6232 | ha_spider *spider; |
| 6233 | SPIDER_SHARE *share; |
| 6234 | char **connect_info; |
| 6235 | uint *connect_info_length; |
| 6236 | long *long_info; |
| 6237 | longlong *longlong_info; |
| 6238 | MEM_ROOT mem_root; |
| 6239 | #if MYSQL_VERSION_ID < 50500 |
| 6240 | Open_tables_state open_tables_backup; |
| 6241 | #else |
| 6242 | Open_tables_backup open_tables_backup; |
| 6243 | #endif |
| 6244 | DBUG_ENTER("spider_open_all_tables" ); |
| 6245 | if ( |
| 6246 | !(table_tables = spider_open_sys_table( |
| 6247 | thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, |
| 6248 | SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, TRUE, |
| 6249 | &error_num)) |
| 6250 | ) |
| 6251 | DBUG_RETURN(error_num); |
| 6252 | if ( |
| 6253 | (error_num = spider_sys_index_first(table_tables, 1)) |
| 6254 | ) { |
| 6255 | if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) |
| 6256 | { |
| 6257 | table_tables->file->print_error(error_num, MYF(0)); |
| 6258 | spider_close_sys_table(thd, table_tables, |
| 6259 | &open_tables_backup, TRUE); |
| 6260 | DBUG_RETURN(error_num); |
| 6261 | } else { |
| 6262 | spider_close_sys_table(thd, table_tables, |
| 6263 | &open_tables_backup, TRUE); |
| 6264 | DBUG_RETURN(0); |
| 6265 | } |
| 6266 | } |
| 6267 | |
| 6268 | SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME)); |
| 6269 | memset(&tmp_share, 0, sizeof(SPIDER_SHARE)); |
| 6270 | memset(&tmp_connect_info, 0, |
| 6271 | sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT); |
| 6272 | memset(tmp_connect_info_length, 0, |
| 6273 | sizeof(uint) * SPIDER_TMP_SHARE_UINT_COUNT); |
| 6274 | memset(tmp_long, 0, sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT); |
| 6275 | memset(tmp_longlong, 0, sizeof(longlong) * SPIDER_TMP_SHARE_LONGLONG_COUNT); |
| 6276 | spider_set_tmp_share_pointer(&tmp_share, (char **) &tmp_connect_info, |
| 6277 | tmp_connect_info_length, tmp_long, tmp_longlong); |
| 6278 | tmp_share.link_statuses[0] = -1; |
| 6279 | |
| 6280 | do { |
| 6281 | if ( |
| 6282 | (error_num = spider_get_sys_tables( |
| 6283 | table_tables, &db_name, &table_name, &mem_root)) || |
| 6284 | (error_num = spider_get_sys_tables_connect_info( |
| 6285 | table_tables, &tmp_share, 0, &mem_root)) || |
| 6286 | (error_num = spider_set_connect_info_default( |
| 6287 | &tmp_share, |
| 6288 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 6289 | NULL, |
| 6290 | NULL, |
| 6291 | #endif |
| 6292 | NULL |
| 6293 | )) |
| 6294 | ) { |
| 6295 | spider_sys_index_end(table_tables); |
| 6296 | spider_close_sys_table(thd, table_tables, |
| 6297 | &open_tables_backup, TRUE); |
| 6298 | spider_free_tmp_share_alloc(&tmp_share); |
| 6299 | free_root(&mem_root, MYF(0)); |
| 6300 | DBUG_RETURN(error_num); |
| 6301 | } |
| 6302 | db_name_length = strlen(db_name); |
| 6303 | table_name_length = strlen(table_name); |
| 6304 | |
| 6305 | if ( |
| 6306 | (error_num = spider_set_connect_info_default_db_table( |
| 6307 | &tmp_share, |
| 6308 | db_name, |
| 6309 | db_name_length, |
| 6310 | table_name, |
| 6311 | table_name_length |
| 6312 | )) || |
| 6313 | (error_num = spider_create_conn_keys(&tmp_share)) || |
| 6314 | /* |
| 6315 | (error_num = spider_db_create_table_names_str(&tmp_share)) || |
| 6316 | */ |
| 6317 | (error_num = spider_create_tmp_dbton_share(&tmp_share)) |
| 6318 | ) { |
| 6319 | spider_sys_index_end(table_tables); |
| 6320 | spider_close_sys_table(thd, table_tables, |
| 6321 | &open_tables_backup, TRUE); |
| 6322 | spider_free_tmp_share_alloc(&tmp_share); |
| 6323 | free_root(&mem_root, MYF(0)); |
| 6324 | DBUG_RETURN(error_num); |
| 6325 | } |
| 6326 | |
| 6327 | /* create conn */ |
| 6328 | if ( |
| 6329 | !(conn = spider_get_conn( |
| 6330 | &tmp_share, 0, tmp_share.conn_keys[0], trx, NULL, FALSE, FALSE, |
| 6331 | SPIDER_CONN_KIND_MYSQL, &error_num)) |
| 6332 | ) { |
| 6333 | spider_sys_index_end(table_tables); |
| 6334 | spider_close_sys_table(thd, table_tables, |
| 6335 | &open_tables_backup, TRUE); |
| 6336 | spider_free_tmp_dbton_share(&tmp_share); |
| 6337 | spider_free_tmp_share_alloc(&tmp_share); |
| 6338 | free_root(&mem_root, MYF(0)); |
| 6339 | DBUG_RETURN(error_num); |
| 6340 | } |
| 6341 | conn->error_mode &= spider_param_error_read_mode(thd, 0); |
| 6342 | conn->error_mode &= spider_param_error_write_mode(thd, 0); |
| 6343 | pthread_mutex_lock(&conn->mta_conn_mutex); |
| 6344 | SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos); |
| 6345 | conn->need_mon = &mon_val; |
| 6346 | conn->mta_conn_mutex_lock_already = TRUE; |
| 6347 | conn->mta_conn_mutex_unlock_later = TRUE; |
| 6348 | if ((error_num = spider_db_before_query(conn, &mon_val))) |
| 6349 | { |
| 6350 | conn->mta_conn_mutex_lock_already = FALSE; |
| 6351 | conn->mta_conn_mutex_unlock_later = FALSE; |
| 6352 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
| 6353 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
| 6354 | spider_sys_index_end(table_tables); |
| 6355 | spider_close_sys_table(thd, table_tables, |
| 6356 | &open_tables_backup, TRUE); |
| 6357 | spider_free_tmp_dbton_share(&tmp_share); |
| 6358 | spider_free_tmp_share_alloc(&tmp_share); |
| 6359 | free_root(&mem_root, MYF(0)); |
| 6360 | DBUG_RETURN(error_num); |
| 6361 | } |
| 6362 | conn->mta_conn_mutex_lock_already = FALSE; |
| 6363 | conn->mta_conn_mutex_unlock_later = FALSE; |
| 6364 | SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); |
| 6365 | pthread_mutex_unlock(&conn->mta_conn_mutex); |
| 6366 | |
| 6367 | if (lock && spider_param_use_snapshot_with_flush_tables(thd) == 2) |
| 6368 | { |
| 6369 | if (!(spider = new ha_spider())) |
| 6370 | { |
| 6371 | spider_sys_index_end(table_tables); |
| 6372 | spider_close_sys_table(thd, table_tables, |
| 6373 | &open_tables_backup, TRUE); |
| 6374 | spider_free_tmp_dbton_share(&tmp_share); |
| 6375 | spider_free_tmp_share_alloc(&tmp_share); |
| 6376 | free_root(&mem_root, MYF(0)); |
| 6377 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 6378 | } |
| 6379 | spider->lock_type = TL_READ_NO_INSERT; |
| 6380 | |
| 6381 | if (!(share = (SPIDER_SHARE *) |
| 6382 | spider_bulk_malloc(spider_current_trx, 52, MYF(MY_WME | MY_ZEROFILL), |
| 6383 | &share, sizeof(*share), |
| 6384 | &connect_info, sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT, |
| 6385 | &connect_info_length, sizeof(uint) * SPIDER_TMP_SHARE_UINT_COUNT, |
| 6386 | &long_info, sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT, |
| 6387 | &longlong_info, sizeof(longlong) * SPIDER_TMP_SHARE_LONGLONG_COUNT, |
| 6388 | &conns, sizeof(SPIDER_CONN *), |
| 6389 | &need_mon, sizeof(int), |
| 6390 | &spider->conn_link_idx, sizeof(uint), |
| 6391 | &spider->conn_can_fo, sizeof(uchar), |
| 6392 | NullS)) |
| 6393 | ) { |
| 6394 | delete spider; |
| 6395 | spider_sys_index_end(table_tables); |
| 6396 | spider_close_sys_table(thd, table_tables, |
| 6397 | &open_tables_backup, TRUE); |
| 6398 | spider_free_tmp_dbton_share(&tmp_share); |
| 6399 | spider_free_tmp_share_alloc(&tmp_share); |
| 6400 | free_root(&mem_root, MYF(0)); |
| 6401 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 6402 | } |
| 6403 | memcpy(share, &tmp_share, sizeof(*share)); |
| 6404 | spider_set_tmp_share_pointer(share, connect_info, |
| 6405 | connect_info_length, long_info, longlong_info); |
| 6406 | memcpy(connect_info, &tmp_connect_info, sizeof(char *) * |
| 6407 | SPIDER_TMP_SHARE_CHAR_PTR_COUNT); |
| 6408 | memcpy(connect_info_length, &tmp_connect_info_length, sizeof(uint) * |
| 6409 | SPIDER_TMP_SHARE_UINT_COUNT); |
| 6410 | memcpy(long_info, &tmp_long, sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT); |
| 6411 | memcpy(longlong_info, &tmp_longlong, sizeof(longlong) * |
| 6412 | SPIDER_TMP_SHARE_LONGLONG_COUNT); |
| 6413 | spider->share = share; |
| 6414 | spider->trx = trx; |
| 6415 | spider->conns = conns; |
| 6416 | spider->need_mons = need_mon; |
| 6417 | spider->conn_link_idx[0] = 0; |
| 6418 | spider->conn_can_fo[0] = 0; |
| 6419 | if ((error_num = spider_create_tmp_dbton_handler(spider))) |
| 6420 | { |
| 6421 | spider_free(trx, share, MYF(0)); |
| 6422 | delete spider; |
| 6423 | spider_sys_index_end(table_tables); |
| 6424 | spider_close_sys_table(thd, table_tables, |
| 6425 | &open_tables_backup, TRUE); |
| 6426 | spider_free_tmp_dbton_share(&tmp_share); |
| 6427 | spider_free_tmp_share_alloc(&tmp_share); |
| 6428 | free_root(&mem_root, MYF(0)); |
| 6429 | DBUG_RETURN(error_num); |
| 6430 | } |
| 6431 | |
| 6432 | /* create another conn */ |
| 6433 | if ( |
| 6434 | (!(conn = spider_get_conn( |
| 6435 | &tmp_share, 0, tmp_share.conn_keys[0], trx, spider, TRUE, FALSE, |
| 6436 | SPIDER_CONN_KIND_MYSQL, &error_num))) |
| 6437 | ) { |
| 6438 | spider_free_tmp_dbton_handler(spider); |
| 6439 | spider_free(trx, share, MYF(0)); |
| 6440 | delete spider; |
| 6441 | spider_sys_index_end(table_tables); |
| 6442 | spider_close_sys_table(thd, table_tables, |
| 6443 | &open_tables_backup, TRUE); |
| 6444 | spider_free_tmp_dbton_share(&tmp_share); |
| 6445 | spider_free_tmp_share_alloc(&tmp_share); |
| 6446 | free_root(&mem_root, MYF(0)); |
| 6447 | DBUG_RETURN(error_num); |
| 6448 | } |
| 6449 | conn->error_mode &= spider_param_error_read_mode(thd, 0); |
| 6450 | conn->error_mode &= spider_param_error_write_mode(thd, 0); |
| 6451 | |
| 6452 | spider->next = NULL; |
| 6453 | if (conn->another_ha_last) |
| 6454 | { |
| 6455 | ((ha_spider*) conn->another_ha_last)->next = spider; |
| 6456 | } else { |
| 6457 | conn->another_ha_first = (void*) spider; |
| 6458 | } |
| 6459 | conn->another_ha_last = (void*) spider; |
| 6460 | |
| 6461 | int appended = 0; |
| 6462 | if ((error_num = spider->dbton_handler[conn->dbton_id]-> |
| 6463 | append_lock_tables_list(conn, 0, &appended))) |
| 6464 | { |
| 6465 | spider_free_tmp_dbton_handler(spider); |
| 6466 | spider_free(trx, share, MYF(0)); |
| 6467 | delete spider; |
| 6468 | spider_sys_index_end(table_tables); |
| 6469 | spider_close_sys_table(thd, table_tables, |
| 6470 | &open_tables_backup, TRUE); |
| 6471 | spider_free_tmp_dbton_share(&tmp_share); |
| 6472 | spider_free_tmp_share_alloc(&tmp_share); |
| 6473 | free_root(&mem_root, MYF(0)); |
| 6474 | DBUG_RETURN(error_num); |
| 6475 | } |
| 6476 | } else { |
| 6477 | spider_free_tmp_dbton_share(&tmp_share); |
| 6478 | spider_free_tmp_share_alloc(&tmp_share); |
| 6479 | } |
| 6480 | error_num = spider_sys_index_next(table_tables); |
| 6481 | } while (error_num == 0); |
| 6482 | free_root(&mem_root, MYF(0)); |
| 6483 | |
| 6484 | spider_sys_index_end(table_tables); |
| 6485 | spider_close_sys_table(thd, table_tables, |
| 6486 | &open_tables_backup, TRUE); |
| 6487 | DBUG_RETURN(0); |
| 6488 | } |
| 6489 | |
| 6490 | bool spider_flush_logs( |
| 6491 | handlerton *hton |
| 6492 | ) { |
| 6493 | int error_num; |
| 6494 | THD* thd = current_thd; |
| 6495 | SPIDER_TRX *trx; |
| 6496 | DBUG_ENTER("spider_flush_logs" ); |
| 6497 | |
| 6498 | if (!(trx = spider_get_trx(thd, TRUE, &error_num))) |
| 6499 | { |
| 6500 | my_errno = error_num; |
| 6501 | DBUG_RETURN(TRUE); |
| 6502 | } |
| 6503 | if ( |
| 6504 | spider_param_use_flash_logs(trx->thd) && |
| 6505 | ( |
| 6506 | !trx->trx_consistent_snapshot || |
| 6507 | !spider_param_use_all_conns_snapshot(trx->thd) || |
| 6508 | !spider_param_use_snapshot_with_flush_tables(trx->thd) |
| 6509 | ) |
| 6510 | ) { |
| 6511 | if ( |
| 6512 | (error_num = spider_open_all_tables(trx, FALSE)) || |
| 6513 | (error_num = spider_trx_all_flush_logs(trx)) |
| 6514 | ) { |
| 6515 | my_errno = error_num; |
| 6516 | DBUG_RETURN(TRUE); |
| 6517 | } |
| 6518 | } |
| 6519 | |
| 6520 | DBUG_RETURN(FALSE); |
| 6521 | } |
| 6522 | |
| 6523 | handler* spider_create_handler( |
| 6524 | handlerton *hton, |
| 6525 | TABLE_SHARE *table, |
| 6526 | MEM_ROOT *mem_root |
| 6527 | ) { |
| 6528 | DBUG_ENTER("spider_create_handler" ); |
| 6529 | DBUG_RETURN(new (mem_root) ha_spider(hton, table)); |
| 6530 | } |
| 6531 | |
| 6532 | int spider_close_connection( |
| 6533 | handlerton* hton, |
| 6534 | THD* thd |
| 6535 | ) { |
| 6536 | int roop_count = 0; |
| 6537 | SPIDER_CONN *conn; |
| 6538 | SPIDER_TRX *trx; |
| 6539 | DBUG_ENTER("spider_close_connection" ); |
| 6540 | if (!(trx = (SPIDER_TRX*) thd_get_ha_data(thd, spider_hton_ptr))) |
| 6541 | DBUG_RETURN(0); /* transaction is not started */ |
| 6542 | |
| 6543 | trx->tmp_spider->conns = &conn; |
| 6544 | while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_conn_hash, |
| 6545 | roop_count))) |
| 6546 | { |
| 6547 | SPIDER_BACKUP_DASTATUS; |
| 6548 | DBUG_PRINT("info" ,("spider conn->table_lock=%d" , conn->table_lock)); |
| 6549 | if (conn->table_lock > 0) |
| 6550 | { |
| 6551 | if (!conn->trx_start) |
| 6552 | conn->disable_reconnect = FALSE; |
| 6553 | if (conn->table_lock != 2) |
| 6554 | { |
| 6555 | spider_db_unlock_tables(trx->tmp_spider, 0); |
| 6556 | } |
| 6557 | conn->table_lock = 0; |
| 6558 | } |
| 6559 | roop_count++; |
| 6560 | SPIDER_CONN_RESTORE_DASTATUS; |
| 6561 | } |
| 6562 | |
| 6563 | spider_rollback(spider_hton_ptr, thd, TRUE); |
| 6564 | spider_free_trx(trx, TRUE); |
| 6565 | |
| 6566 | DBUG_RETURN(0); |
| 6567 | } |
| 6568 | |
| 6569 | void spider_drop_database( |
| 6570 | handlerton *hton, |
| 6571 | char* path |
| 6572 | ) { |
| 6573 | DBUG_ENTER("spider_drop_database" ); |
| 6574 | DBUG_VOID_RETURN; |
| 6575 | } |
| 6576 | |
| 6577 | bool spider_show_status( |
| 6578 | handlerton *hton, |
| 6579 | THD *thd, |
| 6580 | stat_print_fn *stat_print, |
| 6581 | enum ha_stat_type stat_type |
| 6582 | ) { |
| 6583 | DBUG_ENTER("spider_show_status" ); |
| 6584 | switch (stat_type) { |
| 6585 | case HA_ENGINE_STATUS: |
| 6586 | default: |
| 6587 | DBUG_RETURN(FALSE); |
| 6588 | } |
| 6589 | } |
| 6590 | |
| 6591 | int spider_db_done( |
| 6592 | void *p |
| 6593 | ) { |
| 6594 | int roop_count; |
| 6595 | bool do_delete_thd; |
| 6596 | THD *thd = current_thd, *tmp_thd; |
| 6597 | SPIDER_CONN *conn; |
| 6598 | SPIDER_INIT_ERROR_TABLE *spider_init_error_table; |
| 6599 | SPIDER_TABLE_MON_LIST *table_mon_list; |
| 6600 | SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share; |
| 6601 | DBUG_ENTER("spider_db_done" ); |
| 6602 | |
| 6603 | /* Begin Spider plugin deinit */ |
| 6604 | if (thd) |
| 6605 | do_delete_thd = FALSE; |
| 6606 | else |
| 6607 | { |
| 6608 | /* Create a thread for Spider plugin deinit */ |
| 6609 | thd = spider_create_thd(); |
| 6610 | if (!thd) |
| 6611 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 6612 | do_delete_thd = TRUE; |
| 6613 | } |
| 6614 | |
| 6615 | for (roop_count = SPIDER_DBTON_SIZE - 1; roop_count >= 0; roop_count--) |
| 6616 | { |
| 6617 | if (spider_dbton[roop_count].deinit) |
| 6618 | { |
| 6619 | spider_dbton[roop_count].deinit(); |
| 6620 | } |
| 6621 | } |
| 6622 | |
| 6623 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 6624 | for (roop_count = spider_param_table_crd_thread_count() - 1; |
| 6625 | roop_count >= 0; roop_count--) |
| 6626 | { |
| 6627 | spider_free_crd_threads(&spider_table_crd_threads[roop_count]); |
| 6628 | } |
| 6629 | for (roop_count = spider_param_table_sts_thread_count() - 1; |
| 6630 | roop_count >= 0; roop_count--) |
| 6631 | { |
| 6632 | spider_free_sts_threads(&spider_table_sts_threads[roop_count]); |
| 6633 | } |
| 6634 | spider_free(NULL, spider_table_sts_threads, MYF(0)); |
| 6635 | #endif |
| 6636 | |
| 6637 | for (roop_count = spider_param_udf_table_mon_mutex_count() - 1; |
| 6638 | roop_count >= 0; roop_count--) |
| 6639 | { |
| 6640 | while ((table_mon_list = (SPIDER_TABLE_MON_LIST *) my_hash_element( |
| 6641 | &spider_udf_table_mon_list_hash[roop_count], 0))) |
| 6642 | { |
| 6643 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
| 6644 | my_hash_delete_with_hash_value( |
| 6645 | &spider_udf_table_mon_list_hash[roop_count], |
| 6646 | table_mon_list->key_hash_value, (uchar*) table_mon_list); |
| 6647 | #else |
| 6648 | my_hash_delete(&spider_udf_table_mon_list_hash[roop_count], |
| 6649 | (uchar*) table_mon_list); |
| 6650 | #endif |
| 6651 | spider_ping_table_free_mon_list(table_mon_list); |
| 6652 | } |
| 6653 | spider_free_mem_calc(spider_current_trx, |
| 6654 | spider_udf_table_mon_list_hash_id, |
| 6655 | spider_udf_table_mon_list_hash[roop_count].array.max_element * |
| 6656 | spider_udf_table_mon_list_hash[roop_count].array.size_of_element); |
| 6657 | my_hash_free(&spider_udf_table_mon_list_hash[roop_count]); |
| 6658 | } |
| 6659 | for (roop_count = spider_param_udf_table_mon_mutex_count() - 1; |
| 6660 | roop_count >= 0; roop_count--) |
| 6661 | pthread_cond_destroy(&spider_udf_table_mon_conds[roop_count]); |
| 6662 | for (roop_count = spider_param_udf_table_mon_mutex_count() - 1; |
| 6663 | roop_count >= 0; roop_count--) |
| 6664 | pthread_mutex_destroy(&spider_udf_table_mon_mutexes[roop_count]); |
| 6665 | spider_free(NULL, spider_udf_table_mon_mutexes, MYF(0)); |
| 6666 | |
| 6667 | pthread_mutex_lock(&spider_allocated_thds_mutex); |
| 6668 | while ((tmp_thd = (THD *) my_hash_element(&spider_allocated_thds, 0))) |
| 6669 | { |
| 6670 | SPIDER_TRX *trx = (SPIDER_TRX *) |
| 6671 | thd_get_ha_data(tmp_thd, spider_hton_ptr); |
| 6672 | if (trx) |
| 6673 | { |
| 6674 | DBUG_ASSERT(tmp_thd == trx->thd); |
| 6675 | spider_free_trx(trx, FALSE); |
| 6676 | thd_set_ha_data(tmp_thd, spider_hton_ptr, NULL); |
| 6677 | } |
| 6678 | else |
| 6679 | my_hash_delete(&spider_allocated_thds, (uchar *) tmp_thd); |
| 6680 | } |
| 6681 | pthread_mutex_unlock(&spider_allocated_thds_mutex); |
| 6682 | |
| 6683 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 6684 | pthread_mutex_lock(&spider_hs_w_conn_mutex); |
| 6685 | while ((conn = (SPIDER_CONN*) my_hash_element(&spider_hs_w_conn_hash, 0))) |
| 6686 | { |
| 6687 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
| 6688 | my_hash_delete_with_hash_value(&spider_hs_w_conn_hash, |
| 6689 | conn->conn_key_hash_value, (uchar*) conn); |
| 6690 | #else |
| 6691 | my_hash_delete(&spider_hs_w_conn_hash, (uchar*) conn); |
| 6692 | #endif |
| 6693 | spider_free_conn(conn); |
| 6694 | } |
| 6695 | pthread_mutex_unlock(&spider_hs_w_conn_mutex); |
| 6696 | pthread_mutex_lock(&spider_hs_r_conn_mutex); |
| 6697 | while ((conn = (SPIDER_CONN*) my_hash_element(&spider_hs_r_conn_hash, 0))) |
| 6698 | { |
| 6699 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
| 6700 | my_hash_delete_with_hash_value(&spider_hs_r_conn_hash, |
| 6701 | conn->conn_key_hash_value, (uchar*) conn); |
| 6702 | #else |
| 6703 | my_hash_delete(&spider_hs_r_conn_hash, (uchar*) conn); |
| 6704 | #endif |
| 6705 | spider_free_conn(conn); |
| 6706 | } |
| 6707 | pthread_mutex_unlock(&spider_hs_r_conn_mutex); |
| 6708 | #endif |
| 6709 | pthread_mutex_lock(&spider_conn_mutex); |
| 6710 | while ((conn = (SPIDER_CONN*) my_hash_element(&spider_open_connections, 0))) |
| 6711 | { |
| 6712 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
| 6713 | my_hash_delete_with_hash_value(&spider_open_connections, |
| 6714 | conn->conn_key_hash_value, (uchar*) conn); |
| 6715 | #else |
| 6716 | my_hash_delete(&spider_open_connections, (uchar*) conn); |
| 6717 | #endif |
| 6718 | spider_free_conn(conn); |
| 6719 | } |
| 6720 | pthread_mutex_unlock(&spider_conn_mutex); |
| 6721 | pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex); |
| 6722 | while ((lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE*) my_hash_element( |
| 6723 | &spider_lgtm_tblhnd_share_hash, 0))) |
| 6724 | { |
| 6725 | spider_free_lgtm_tblhnd_share_alloc(lgtm_tblhnd_share, TRUE); |
| 6726 | } |
| 6727 | pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex); |
| 6728 | spider_free_mem_calc(spider_current_trx, |
| 6729 | spider_mon_table_cache_id, |
| 6730 | spider_mon_table_cache.max_element * |
| 6731 | spider_mon_table_cache.size_of_element); |
| 6732 | delete_dynamic(&spider_mon_table_cache); |
| 6733 | spider_free_mem_calc(spider_current_trx, |
| 6734 | spider_allocated_thds_id, |
| 6735 | spider_allocated_thds.array.max_element * |
| 6736 | spider_allocated_thds.array.size_of_element); |
| 6737 | my_hash_free(&spider_allocated_thds); |
| 6738 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 6739 | spider_free_mem_calc(spider_current_trx, |
| 6740 | spider_hs_w_conn_hash_id, |
| 6741 | spider_hs_w_conn_hash.array.max_element * |
| 6742 | spider_hs_w_conn_hash.array.size_of_element); |
| 6743 | my_hash_free(&spider_hs_w_conn_hash); |
| 6744 | spider_free_mem_calc(spider_current_trx, |
| 6745 | spider_hs_r_conn_hash_id, |
| 6746 | spider_hs_r_conn_hash.array.max_element * |
| 6747 | spider_hs_r_conn_hash.array.size_of_element); |
| 6748 | my_hash_free(&spider_hs_r_conn_hash); |
| 6749 | #endif |
| 6750 | spider_free_mem_calc(spider_current_trx, |
| 6751 | spider_open_connections_id, |
| 6752 | spider_open_connections.array.max_element * |
| 6753 | spider_open_connections.array.size_of_element); |
| 6754 | my_hash_free(&spider_open_connections); |
| 6755 | my_hash_free(&spider_ipport_conns); |
| 6756 | spider_free_mem_calc(spider_current_trx, |
| 6757 | spider_lgtm_tblhnd_share_hash_id, |
| 6758 | spider_lgtm_tblhnd_share_hash.array.max_element * |
| 6759 | spider_lgtm_tblhnd_share_hash.array.size_of_element); |
| 6760 | my_hash_free(&spider_lgtm_tblhnd_share_hash); |
| 6761 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 6762 | spider_free_mem_calc(spider_current_trx, |
| 6763 | spider_open_pt_share_id, |
| 6764 | spider_open_pt_share.array.max_element * |
| 6765 | spider_open_pt_share.array.size_of_element); |
| 6766 | my_hash_free(&spider_open_pt_share); |
| 6767 | #endif |
| 6768 | pthread_mutex_lock(&spider_init_error_tbl_mutex); |
| 6769 | while ((spider_init_error_table = (SPIDER_INIT_ERROR_TABLE*) |
| 6770 | my_hash_element(&spider_init_error_tables, 0))) |
| 6771 | { |
| 6772 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
| 6773 | my_hash_delete_with_hash_value(&spider_init_error_tables, |
| 6774 | spider_init_error_table->table_name_hash_value, |
| 6775 | (uchar*) spider_init_error_table); |
| 6776 | #else |
| 6777 | my_hash_delete(&spider_init_error_tables, |
| 6778 | (uchar*) spider_init_error_table); |
| 6779 | #endif |
| 6780 | spider_free(NULL, spider_init_error_table, MYF(0)); |
| 6781 | } |
| 6782 | pthread_mutex_unlock(&spider_init_error_tbl_mutex); |
| 6783 | spider_free_mem_calc(spider_current_trx, |
| 6784 | spider_init_error_tables_id, |
| 6785 | spider_init_error_tables.array.max_element * |
| 6786 | spider_init_error_tables.array.size_of_element); |
| 6787 | my_hash_free(&spider_init_error_tables); |
| 6788 | spider_free_mem_calc(spider_current_trx, |
| 6789 | spider_open_tables_id, |
| 6790 | spider_open_tables.array.max_element * |
| 6791 | spider_open_tables.array.size_of_element); |
| 6792 | my_hash_free(&spider_open_tables); |
| 6793 | pthread_mutex_destroy(&spider_mem_calc_mutex); |
| 6794 | pthread_mutex_destroy(&spider_mon_table_cache_mutex); |
| 6795 | pthread_mutex_destroy(&spider_allocated_thds_mutex); |
| 6796 | pthread_mutex_destroy(&spider_open_conn_mutex); |
| 6797 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 6798 | pthread_mutex_destroy(&spider_hs_w_conn_mutex); |
| 6799 | pthread_mutex_destroy(&spider_hs_r_conn_mutex); |
| 6800 | #endif |
| 6801 | pthread_mutex_destroy(&spider_conn_mutex); |
| 6802 | pthread_mutex_destroy(&spider_lgtm_tblhnd_share_mutex); |
| 6803 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 6804 | pthread_mutex_destroy(&spider_pt_share_mutex); |
| 6805 | #endif |
| 6806 | pthread_mutex_destroy(&spider_init_error_tbl_mutex); |
| 6807 | pthread_mutex_destroy(&spider_conn_id_mutex); |
| 6808 | pthread_mutex_destroy(&spider_ipport_conn_mutex); |
| 6809 | pthread_mutex_destroy(&spider_thread_id_mutex); |
| 6810 | pthread_mutex_destroy(&spider_tbl_mutex); |
| 6811 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 6812 | pthread_attr_destroy(&spider_pt_attr); |
| 6813 | #endif |
| 6814 | |
| 6815 | for (roop_count = 0; roop_count < SPIDER_MEM_CALC_LIST_NUM; roop_count++) |
| 6816 | { |
| 6817 | if (spider_alloc_func_name[roop_count]) |
| 6818 | DBUG_PRINT("info" ,("spider %d %s %s %lu %llu %lld %llu %llu %s" , |
| 6819 | roop_count, |
| 6820 | spider_alloc_func_name[roop_count], |
| 6821 | spider_alloc_file_name[roop_count], |
| 6822 | spider_alloc_line_no[roop_count], |
| 6823 | spider_total_alloc_mem[roop_count], |
| 6824 | spider_current_alloc_mem[roop_count], |
| 6825 | spider_alloc_mem_count[roop_count], |
| 6826 | spider_free_mem_count[roop_count], |
| 6827 | spider_current_alloc_mem[roop_count] ? "NG" : "OK" |
| 6828 | )); |
| 6829 | } |
| 6830 | |
| 6831 | /* End Spider plugin deinit */ |
| 6832 | if (do_delete_thd) |
| 6833 | spider_destroy_thd(thd); |
| 6834 | |
| 6835 | /* |
| 6836 | DBUG_ASSERT(0); |
| 6837 | */ |
| 6838 | DBUG_RETURN(0); |
| 6839 | } |
| 6840 | |
| 6841 | int spider_panic( |
| 6842 | handlerton *hton, |
| 6843 | ha_panic_function type |
| 6844 | ) { |
| 6845 | DBUG_ENTER("spider_panic" ); |
| 6846 | DBUG_RETURN(0); |
| 6847 | } |
| 6848 | |
| 6849 | int spider_db_init( |
| 6850 | void *p |
| 6851 | ) { |
| 6852 | int error_num, roop_count; |
| 6853 | uint dbton_id = 0; |
| 6854 | handlerton *spider_hton = (handlerton *)p; |
| 6855 | DBUG_ENTER("spider_db_init" ); |
| 6856 | spider_hton_ptr = spider_hton; |
| 6857 | |
| 6858 | spider_hton->state = SHOW_OPTION_YES; |
| 6859 | spider_hton->flags = HTON_NO_FLAGS; |
| 6860 | #ifdef HTON_CAN_READ_CONNECT_STRING_IN_PARTITION |
| 6861 | spider_hton->flags |= HTON_CAN_READ_CONNECT_STRING_IN_PARTITION; |
| 6862 | #endif |
| 6863 | /* spider_hton->db_type = DB_TYPE_SPIDER; */ |
| 6864 | /* |
| 6865 | spider_hton->savepoint_offset; |
| 6866 | spider_hton->savepoint_set = spider_savepoint_set; |
| 6867 | spider_hton->savepoint_rollback = spider_savepoint_rollback; |
| 6868 | spider_hton->savepoint_release = spider_savepoint_release; |
| 6869 | spider_hton->create_cursor_read_view = spider_create_cursor_read_view; |
| 6870 | spider_hton->set_cursor_read_view = spider_set_cursor_read_view; |
| 6871 | spider_hton->close_cursor_read_view = spider_close_cursor_read_view; |
| 6872 | */ |
| 6873 | spider_hton->panic = spider_panic; |
| 6874 | spider_hton->close_connection = spider_close_connection; |
| 6875 | spider_hton->start_consistent_snapshot = spider_start_consistent_snapshot; |
| 6876 | spider_hton->flush_logs = spider_flush_logs; |
| 6877 | spider_hton->commit = spider_commit; |
| 6878 | spider_hton->rollback = spider_rollback; |
| 6879 | #ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE |
| 6880 | spider_hton->discover_table_structure = spider_discover_table_structure; |
| 6881 | #endif |
| 6882 | if (spider_param_support_xa()) |
| 6883 | { |
| 6884 | spider_hton->prepare = spider_xa_prepare; |
| 6885 | spider_hton->recover = spider_xa_recover; |
| 6886 | spider_hton->commit_by_xid = spider_xa_commit_by_xid; |
| 6887 | spider_hton->rollback_by_xid = spider_xa_rollback_by_xid; |
| 6888 | } |
| 6889 | spider_hton->create = spider_create_handler; |
| 6890 | spider_hton->drop_database = spider_drop_database; |
| 6891 | spider_hton->show_status = spider_show_status; |
| 6892 | #ifdef SPIDER_HAS_GROUP_BY_HANDLER |
| 6893 | spider_hton->create_group_by = spider_create_group_by_handler; |
| 6894 | #endif |
| 6895 | |
| 6896 | memset(&spider_alloc_func_name, 0, sizeof(spider_alloc_func_name)); |
| 6897 | memset(&spider_alloc_file_name, 0, sizeof(spider_alloc_file_name)); |
| 6898 | memset(&spider_alloc_line_no, 0, sizeof(spider_alloc_line_no)); |
| 6899 | memset(&spider_total_alloc_mem, 0, sizeof(spider_total_alloc_mem)); |
| 6900 | memset(&spider_current_alloc_mem, 0, sizeof(spider_current_alloc_mem)); |
| 6901 | memset(&spider_alloc_mem_count, 0, sizeof(spider_alloc_mem_count)); |
| 6902 | memset(&spider_free_mem_count, 0, sizeof(spider_free_mem_count)); |
| 6903 | |
| 6904 | #ifdef _WIN32 |
| 6905 | HMODULE current_module = GetModuleHandle(NULL); |
| 6906 | #ifndef SPIDER_HAS_NEXT_THREAD_ID |
| 6907 | spd_db_att_thread_id = (ulong *) |
| 6908 | GetProcAddress(current_module, "?thread_id@@3KA" ); |
| 6909 | #endif |
| 6910 | #ifdef SPIDER_XID_USES_xid_cache_iterate |
| 6911 | #else |
| 6912 | #ifdef XID_CACHE_IS_SPLITTED |
| 6913 | spd_db_att_xid_cache_split_num = (uint *) |
| 6914 | GetProcAddress(current_module, |
| 6915 | "?opt_xid_cache_split_num@@3IA" ); |
| 6916 | spd_db_att_LOCK_xid_cache = *((pthread_mutex_t **) |
| 6917 | GetProcAddress(current_module, |
| 6918 | "?LOCK_xid_cache@@3PAUst_mysql_mutex@@A" )); |
| 6919 | spd_db_att_xid_cache = *((HASH **) |
| 6920 | GetProcAddress(current_module, "?xid_cache@@3PAUst_hash@@A" )); |
| 6921 | #else |
| 6922 | spd_db_att_LOCK_xid_cache = (pthread_mutex_t *) |
| 6923 | #if MYSQL_VERSION_ID < 50500 |
| 6924 | GetProcAddress(current_module, |
| 6925 | "?LOCK_xid_cache@@3U_RTL_CRITICAL_SECTION@@A" ); |
| 6926 | #else |
| 6927 | GetProcAddress(current_module, |
| 6928 | "?LOCK_xid_cache@@3Ust_mysql_mutex@@A" ); |
| 6929 | #endif |
| 6930 | spd_db_att_xid_cache = (HASH *) |
| 6931 | GetProcAddress(current_module, "?xid_cache@@3Ust_hash@@A" ); |
| 6932 | #endif |
| 6933 | #endif |
| 6934 | spd_charset_utf8_bin = (struct charset_info_st *) |
| 6935 | GetProcAddress(current_module, "my_charset_utf8_bin" ); |
| 6936 | spd_defaults_extra_file = (const char **) |
| 6937 | GetProcAddress(current_module, "my_defaults_extra_file" ); |
| 6938 | spd_defaults_file = (const char **) |
| 6939 | GetProcAddress(current_module, "my_defaults_file" ); |
| 6940 | spd_abort_loop = (bool volatile *) |
| 6941 | GetProcAddress(current_module, "?abort_loop@@3_NC" ); |
| 6942 | spd_tz_system = *(Time_zone **) |
| 6943 | #ifdef _WIN64 |
| 6944 | GetProcAddress(current_module, "?my_tz_SYSTEM@@3PEAVTime_zone@@EA" ); |
| 6945 | #else |
| 6946 | GetProcAddress(current_module, "?my_tz_SYSTEM@@3PAVTime_zone@@A" ); |
| 6947 | #endif |
| 6948 | #else |
| 6949 | #ifndef SPIDER_HAS_NEXT_THREAD_ID |
| 6950 | spd_db_att_thread_id = &thread_id; |
| 6951 | #endif |
| 6952 | #ifdef SPIDER_XID_USES_xid_cache_iterate |
| 6953 | #else |
| 6954 | #ifdef XID_CACHE_IS_SPLITTED |
| 6955 | spd_db_att_xid_cache_split_num = &opt_xid_cache_split_num; |
| 6956 | spd_db_att_LOCK_xid_cache = LOCK_xid_cache; |
| 6957 | spd_db_att_xid_cache = xid_cache; |
| 6958 | #else |
| 6959 | spd_db_att_LOCK_xid_cache = &LOCK_xid_cache; |
| 6960 | spd_db_att_xid_cache = &xid_cache; |
| 6961 | #endif |
| 6962 | #endif |
| 6963 | spd_charset_utf8_bin = &my_charset_utf8_bin; |
| 6964 | spd_defaults_extra_file = &my_defaults_extra_file; |
| 6965 | spd_defaults_file = &my_defaults_file; |
| 6966 | spd_abort_loop = &abort_loop; |
| 6967 | spd_tz_system = my_tz_SYSTEM; |
| 6968 | #endif |
| 6969 | |
| 6970 | #ifdef HAVE_PSI_INTERFACE |
| 6971 | init_spider_psi_keys(); |
| 6972 | #endif |
| 6973 | |
| 6974 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 6975 | if (pthread_attr_init(&spider_pt_attr)) |
| 6976 | { |
| 6977 | error_num = HA_ERR_OUT_OF_MEM; |
| 6978 | goto error_pt_attr_init; |
| 6979 | } |
| 6980 | /* |
| 6981 | if (pthread_attr_setdetachstate(&spider_pt_attr, PTHREAD_CREATE_DETACHED)) |
| 6982 | { |
| 6983 | error_num = HA_ERR_OUT_OF_MEM; |
| 6984 | goto error_pt_attr_setstate; |
| 6985 | } |
| 6986 | */ |
| 6987 | #endif |
| 6988 | |
| 6989 | #if MYSQL_VERSION_ID < 50500 |
| 6990 | if (pthread_mutex_init(&spider_tbl_mutex, MY_MUTEX_INIT_FAST)) |
| 6991 | #else |
| 6992 | if (mysql_mutex_init(spd_key_mutex_tbl, |
| 6993 | &spider_tbl_mutex, MY_MUTEX_INIT_FAST)) |
| 6994 | #endif |
| 6995 | { |
| 6996 | error_num = HA_ERR_OUT_OF_MEM; |
| 6997 | goto error_tbl_mutex_init; |
| 6998 | } |
| 6999 | #if MYSQL_VERSION_ID < 50500 |
| 7000 | if (pthread_mutex_init(&spider_thread_id_mutex, MY_MUTEX_INIT_FAST)) |
| 7001 | #else |
| 7002 | if (mysql_mutex_init(spd_key_thread_id, |
| 7003 | &spider_thread_id_mutex, MY_MUTEX_INIT_FAST)) |
| 7004 | #endif |
| 7005 | { |
| 7006 | error_num = HA_ERR_OUT_OF_MEM; |
| 7007 | goto error_thread_id_mutex_init; |
| 7008 | } |
| 7009 | #if MYSQL_VERSION_ID < 50500 |
| 7010 | if (pthread_mutex_init(&spider_conn_id_mutex, MY_MUTEX_INIT_FAST)) |
| 7011 | #else |
| 7012 | if (mysql_mutex_init(spd_key_conn_id, |
| 7013 | &spider_conn_id_mutex, MY_MUTEX_INIT_FAST)) |
| 7014 | #endif |
| 7015 | { |
| 7016 | error_num = HA_ERR_OUT_OF_MEM; |
| 7017 | goto error_conn_id_mutex_init; |
| 7018 | } |
| 7019 | #if MYSQL_VERSION_ID < 50500 |
| 7020 | if (pthread_mutex_init(&spider_ipport_conn_mutex, MY_MUTEX_INIT_FAST)) |
| 7021 | #else |
| 7022 | if (mysql_mutex_init(spd_key_mutex_ipport_count, |
| 7023 | &spider_ipport_conn_mutex, MY_MUTEX_INIT_FAST)) |
| 7024 | #endif |
| 7025 | { |
| 7026 | error_num = HA_ERR_OUT_OF_MEM; |
| 7027 | goto error_ipport_count_mutex_init; |
| 7028 | } |
| 7029 | |
| 7030 | #if MYSQL_VERSION_ID < 50500 |
| 7031 | if (pthread_mutex_init(&spider_init_error_tbl_mutex, MY_MUTEX_INIT_FAST)) |
| 7032 | #else |
| 7033 | if (mysql_mutex_init(spd_key_mutex_init_error_tbl, |
| 7034 | &spider_init_error_tbl_mutex, MY_MUTEX_INIT_FAST)) |
| 7035 | #endif |
| 7036 | { |
| 7037 | error_num = HA_ERR_OUT_OF_MEM; |
| 7038 | goto error_init_error_tbl_mutex_init; |
| 7039 | } |
| 7040 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7041 | #if MYSQL_VERSION_ID < 50500 |
| 7042 | if (pthread_mutex_init(&spider_pt_share_mutex, MY_MUTEX_INIT_FAST)) |
| 7043 | #else |
| 7044 | if (mysql_mutex_init(spd_key_mutex_pt_share, |
| 7045 | &spider_pt_share_mutex, MY_MUTEX_INIT_FAST)) |
| 7046 | #endif |
| 7047 | { |
| 7048 | error_num = HA_ERR_OUT_OF_MEM; |
| 7049 | goto error_pt_share_mutex_init; |
| 7050 | } |
| 7051 | #endif |
| 7052 | #if MYSQL_VERSION_ID < 50500 |
| 7053 | if (pthread_mutex_init(&spider_lgtm_tblhnd_share_mutex, MY_MUTEX_INIT_FAST)) |
| 7054 | #else |
| 7055 | if (mysql_mutex_init(spd_key_mutex_lgtm_tblhnd_share, |
| 7056 | &spider_lgtm_tblhnd_share_mutex, MY_MUTEX_INIT_FAST)) |
| 7057 | #endif |
| 7058 | { |
| 7059 | error_num = HA_ERR_OUT_OF_MEM; |
| 7060 | goto error_lgtm_tblhnd_share_mutex_init; |
| 7061 | } |
| 7062 | #if MYSQL_VERSION_ID < 50500 |
| 7063 | if (pthread_mutex_init(&spider_conn_mutex, MY_MUTEX_INIT_FAST)) |
| 7064 | #else |
| 7065 | if (mysql_mutex_init(spd_key_mutex_conn, |
| 7066 | &spider_conn_mutex, MY_MUTEX_INIT_FAST)) |
| 7067 | #endif |
| 7068 | { |
| 7069 | error_num = HA_ERR_OUT_OF_MEM; |
| 7070 | goto error_conn_mutex_init; |
| 7071 | } |
| 7072 | #if MYSQL_VERSION_ID < 50500 |
| 7073 | if (pthread_mutex_init(&spider_open_conn_mutex, MY_MUTEX_INIT_FAST)) |
| 7074 | #else |
| 7075 | if (mysql_mutex_init(spd_key_mutex_open_conn, |
| 7076 | &spider_open_conn_mutex, MY_MUTEX_INIT_FAST)) |
| 7077 | #endif |
| 7078 | { |
| 7079 | error_num = HA_ERR_OUT_OF_MEM; |
| 7080 | goto error_open_conn_mutex_init; |
| 7081 | } |
| 7082 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 7083 | #if MYSQL_VERSION_ID < 50500 |
| 7084 | if (pthread_mutex_init(&spider_hs_r_conn_mutex, MY_MUTEX_INIT_FAST)) |
| 7085 | #else |
| 7086 | if (mysql_mutex_init(spd_key_mutex_hs_r_conn, |
| 7087 | &spider_hs_r_conn_mutex, MY_MUTEX_INIT_FAST)) |
| 7088 | #endif |
| 7089 | { |
| 7090 | error_num = HA_ERR_OUT_OF_MEM; |
| 7091 | goto error_hs_r_conn_mutex_init; |
| 7092 | } |
| 7093 | #if MYSQL_VERSION_ID < 50500 |
| 7094 | if (pthread_mutex_init(&spider_hs_w_conn_mutex, MY_MUTEX_INIT_FAST)) |
| 7095 | #else |
| 7096 | if (mysql_mutex_init(spd_key_mutex_hs_w_conn, |
| 7097 | &spider_hs_w_conn_mutex, MY_MUTEX_INIT_FAST)) |
| 7098 | #endif |
| 7099 | { |
| 7100 | error_num = HA_ERR_OUT_OF_MEM; |
| 7101 | goto error_hs_w_conn_mutex_init; |
| 7102 | } |
| 7103 | #endif |
| 7104 | #if MYSQL_VERSION_ID < 50500 |
| 7105 | if (pthread_mutex_init(&spider_allocated_thds_mutex, MY_MUTEX_INIT_FAST)) |
| 7106 | #else |
| 7107 | if (mysql_mutex_init(spd_key_mutex_allocated_thds, |
| 7108 | &spider_allocated_thds_mutex, MY_MUTEX_INIT_FAST)) |
| 7109 | #endif |
| 7110 | { |
| 7111 | error_num = HA_ERR_OUT_OF_MEM; |
| 7112 | goto error_allocated_thds_mutex_init; |
| 7113 | } |
| 7114 | #if MYSQL_VERSION_ID < 50500 |
| 7115 | if (pthread_mutex_init(&spider_mon_table_cache_mutex, MY_MUTEX_INIT_FAST)) |
| 7116 | #else |
| 7117 | if (mysql_mutex_init(spd_key_mutex_mon_table_cache, |
| 7118 | &spider_mon_table_cache_mutex, MY_MUTEX_INIT_FAST)) |
| 7119 | #endif |
| 7120 | { |
| 7121 | error_num = HA_ERR_OUT_OF_MEM; |
| 7122 | goto error_mon_table_cache_mutex_init; |
| 7123 | } |
| 7124 | |
| 7125 | #if MYSQL_VERSION_ID < 50500 |
| 7126 | if (pthread_mutex_init(&spider_mem_calc_mutex, MY_MUTEX_INIT_FAST)) |
| 7127 | #else |
| 7128 | if (mysql_mutex_init(spd_key_mutex_mem_calc, |
| 7129 | &spider_mem_calc_mutex, MY_MUTEX_INIT_FAST)) |
| 7130 | #endif |
| 7131 | { |
| 7132 | error_num = HA_ERR_OUT_OF_MEM; |
| 7133 | goto error_mem_calc_mutex_init; |
| 7134 | } |
| 7135 | |
| 7136 | if( |
| 7137 | my_hash_init(&spider_open_tables, spd_charset_utf8_bin, 32, 0, 0, |
| 7138 | (my_hash_get_key) spider_tbl_get_key, 0, 0) |
| 7139 | ) { |
| 7140 | error_num = HA_ERR_OUT_OF_MEM; |
| 7141 | goto error_open_tables_hash_init; |
| 7142 | } |
| 7143 | spider_alloc_calc_mem_init(spider_open_tables, 143); |
| 7144 | spider_alloc_calc_mem(NULL, |
| 7145 | spider_open_tables, |
| 7146 | spider_open_tables.array.max_element * |
| 7147 | spider_open_tables.array.size_of_element); |
| 7148 | if( |
| 7149 | my_hash_init(&spider_init_error_tables, spd_charset_utf8_bin, 32, 0, 0, |
| 7150 | (my_hash_get_key) spider_tbl_get_key, 0, 0) |
| 7151 | ) { |
| 7152 | error_num = HA_ERR_OUT_OF_MEM; |
| 7153 | goto error_init_error_tables_hash_init; |
| 7154 | } |
| 7155 | spider_alloc_calc_mem_init(spider_init_error_tables, 144); |
| 7156 | spider_alloc_calc_mem(NULL, |
| 7157 | spider_init_error_tables, |
| 7158 | spider_init_error_tables.array.max_element * |
| 7159 | spider_init_error_tables.array.size_of_element); |
| 7160 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7161 | if( |
| 7162 | my_hash_init(&spider_open_pt_share, spd_charset_utf8_bin, 32, 0, 0, |
| 7163 | (my_hash_get_key) spider_pt_share_get_key, 0, 0) |
| 7164 | ) { |
| 7165 | error_num = HA_ERR_OUT_OF_MEM; |
| 7166 | goto error_open_pt_share_hash_init; |
| 7167 | } |
| 7168 | spider_alloc_calc_mem_init(spider_open_pt_share, 145); |
| 7169 | spider_alloc_calc_mem(NULL, |
| 7170 | spider_open_pt_share, |
| 7171 | spider_open_pt_share.array.max_element * |
| 7172 | spider_open_pt_share.array.size_of_element); |
| 7173 | #endif |
| 7174 | if( |
| 7175 | my_hash_init(&spider_lgtm_tblhnd_share_hash, spd_charset_utf8_bin, |
| 7176 | 32, 0, 0, |
| 7177 | (my_hash_get_key) spider_lgtm_tblhnd_share_hash_get_key, 0, 0) |
| 7178 | ) { |
| 7179 | error_num = HA_ERR_OUT_OF_MEM; |
| 7180 | goto error_lgtm_tblhnd_share_hash_init; |
| 7181 | } |
| 7182 | spider_alloc_calc_mem_init(spider_lgtm_tblhnd_share_hash, 245); |
| 7183 | spider_alloc_calc_mem(NULL, |
| 7184 | spider_lgtm_tblhnd_share_hash, |
| 7185 | spider_lgtm_tblhnd_share_hash.array.max_element * |
| 7186 | spider_lgtm_tblhnd_share_hash.array.size_of_element); |
| 7187 | if( |
| 7188 | my_hash_init(&spider_open_connections, spd_charset_utf8_bin, 32, 0, 0, |
| 7189 | (my_hash_get_key) spider_conn_get_key, 0, 0) |
| 7190 | ) { |
| 7191 | error_num = HA_ERR_OUT_OF_MEM; |
| 7192 | goto error_open_connections_hash_init; |
| 7193 | } |
| 7194 | if( |
| 7195 | my_hash_init(&spider_ipport_conns, spd_charset_utf8_bin, 32, 0, 0, |
| 7196 | (my_hash_get_key) spider_ipport_conn_get_key, spider_free_ipport_conn, 0) |
| 7197 | ) { |
| 7198 | error_num = HA_ERR_OUT_OF_MEM; |
| 7199 | goto error_ipport_conn__hash_init; |
| 7200 | } |
| 7201 | spider_alloc_calc_mem_init(spider_open_connections, 146); |
| 7202 | spider_alloc_calc_mem(NULL, |
| 7203 | spider_open_connections, |
| 7204 | spider_open_connections.array.max_element * |
| 7205 | spider_open_connections.array.size_of_element); |
| 7206 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 7207 | if( |
| 7208 | my_hash_init(&spider_hs_r_conn_hash, spd_charset_utf8_bin, 32, 0, 0, |
| 7209 | (my_hash_get_key) spider_conn_get_key, 0, 0) |
| 7210 | ) { |
| 7211 | error_num = HA_ERR_OUT_OF_MEM; |
| 7212 | goto error_hs_r_conn_hash_init; |
| 7213 | } |
| 7214 | spider_alloc_calc_mem_init(spider_hs_r_conn_hash, 147); |
| 7215 | spider_alloc_calc_mem(NULL, |
| 7216 | spider_hs_r_conn_hash, |
| 7217 | spider_hs_r_conn_hash.array.max_element * |
| 7218 | spider_hs_r_conn_hash.array.size_of_element); |
| 7219 | if( |
| 7220 | my_hash_init(&spider_hs_w_conn_hash, spd_charset_utf8_bin, 32, 0, 0, |
| 7221 | (my_hash_get_key) spider_conn_get_key, 0, 0) |
| 7222 | ) { |
| 7223 | error_num = HA_ERR_OUT_OF_MEM; |
| 7224 | goto error_hs_w_conn_hash_init; |
| 7225 | } |
| 7226 | spider_alloc_calc_mem_init(spider_hs_w_conn_hash, 148); |
| 7227 | spider_alloc_calc_mem(NULL, |
| 7228 | spider_hs_w_conn_hash, |
| 7229 | spider_hs_w_conn_hash.array.max_element * |
| 7230 | spider_hs_w_conn_hash.array.size_of_element); |
| 7231 | #endif |
| 7232 | if( |
| 7233 | my_hash_init(&spider_allocated_thds, spd_charset_utf8_bin, 32, 0, 0, |
| 7234 | (my_hash_get_key) spider_allocated_thds_get_key, 0, 0) |
| 7235 | ) { |
| 7236 | error_num = HA_ERR_OUT_OF_MEM; |
| 7237 | goto error_allocated_thds_hash_init; |
| 7238 | } |
| 7239 | spider_alloc_calc_mem_init(spider_allocated_thds, 149); |
| 7240 | spider_alloc_calc_mem(NULL, |
| 7241 | spider_allocated_thds, |
| 7242 | spider_allocated_thds.array.max_element * |
| 7243 | spider_allocated_thds.array.size_of_element); |
| 7244 | |
| 7245 | if( |
| 7246 | SPD_INIT_DYNAMIC_ARRAY2(&spider_mon_table_cache, sizeof(SPIDER_MON_KEY), |
| 7247 | NULL, 64, 64, MYF(MY_WME)) |
| 7248 | ) { |
| 7249 | error_num = HA_ERR_OUT_OF_MEM; |
| 7250 | goto error_mon_table_cache_array_init; |
| 7251 | } |
| 7252 | spider_alloc_calc_mem_init(spider_mon_table_cache, 165); |
| 7253 | spider_alloc_calc_mem(NULL, |
| 7254 | spider_mon_table_cache, |
| 7255 | spider_mon_table_cache.max_element * |
| 7256 | spider_mon_table_cache.size_of_element); |
| 7257 | |
| 7258 | if (!(spider_udf_table_mon_mutexes = (pthread_mutex_t *) |
| 7259 | spider_bulk_malloc(NULL, 53, MYF(MY_WME | MY_ZEROFILL), |
| 7260 | &spider_udf_table_mon_mutexes, sizeof(pthread_mutex_t) * |
| 7261 | spider_param_udf_table_mon_mutex_count(), |
| 7262 | &spider_udf_table_mon_conds, sizeof(pthread_cond_t) * |
| 7263 | spider_param_udf_table_mon_mutex_count(), |
| 7264 | &spider_udf_table_mon_list_hash, sizeof(HASH) * |
| 7265 | spider_param_udf_table_mon_mutex_count(), |
| 7266 | NullS)) |
| 7267 | ) |
| 7268 | goto error_alloc_mon_mutxes; |
| 7269 | |
| 7270 | for (roop_count = 0; |
| 7271 | roop_count < (int) spider_param_udf_table_mon_mutex_count(); |
| 7272 | roop_count++) |
| 7273 | { |
| 7274 | #if MYSQL_VERSION_ID < 50500 |
| 7275 | if (pthread_mutex_init(&spider_udf_table_mon_mutexes[roop_count], |
| 7276 | MY_MUTEX_INIT_FAST)) |
| 7277 | #else |
| 7278 | if (mysql_mutex_init(spd_key_mutex_udf_table_mon, |
| 7279 | &spider_udf_table_mon_mutexes[roop_count], MY_MUTEX_INIT_FAST)) |
| 7280 | #endif |
| 7281 | { |
| 7282 | error_num = HA_ERR_OUT_OF_MEM; |
| 7283 | goto error_init_udf_table_mon_mutex; |
| 7284 | } |
| 7285 | } |
| 7286 | for (roop_count = 0; |
| 7287 | roop_count < (int) spider_param_udf_table_mon_mutex_count(); |
| 7288 | roop_count++) |
| 7289 | { |
| 7290 | #if MYSQL_VERSION_ID < 50500 |
| 7291 | if (pthread_cond_init(&spider_udf_table_mon_conds[roop_count], NULL)) |
| 7292 | #else |
| 7293 | if (mysql_cond_init(spd_key_cond_udf_table_mon, |
| 7294 | &spider_udf_table_mon_conds[roop_count], NULL)) |
| 7295 | #endif |
| 7296 | { |
| 7297 | error_num = HA_ERR_OUT_OF_MEM; |
| 7298 | goto error_init_udf_table_mon_cond; |
| 7299 | } |
| 7300 | } |
| 7301 | for (roop_count = 0; |
| 7302 | roop_count < (int) spider_param_udf_table_mon_mutex_count(); |
| 7303 | roop_count++) |
| 7304 | { |
| 7305 | if (my_hash_init(&spider_udf_table_mon_list_hash[roop_count], |
| 7306 | spd_charset_utf8_bin, 32, 0, 0, |
| 7307 | (my_hash_get_key) spider_udf_tbl_mon_list_key, 0, 0)) |
| 7308 | { |
| 7309 | error_num = HA_ERR_OUT_OF_MEM; |
| 7310 | goto error_init_udf_table_mon_list_hash; |
| 7311 | } |
| 7312 | spider_alloc_calc_mem_init(spider_udf_table_mon_list_hash, 150); |
| 7313 | spider_alloc_calc_mem(NULL, |
| 7314 | spider_udf_table_mon_list_hash, |
| 7315 | spider_udf_table_mon_list_hash[roop_count].array.max_element * |
| 7316 | spider_udf_table_mon_list_hash[roop_count].array.size_of_element); |
| 7317 | } |
| 7318 | |
| 7319 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 7320 | if (!(spider_table_sts_threads = (SPIDER_THREAD *) |
| 7321 | spider_bulk_malloc(NULL, 256, MYF(MY_WME | MY_ZEROFILL), |
| 7322 | &spider_table_sts_threads, sizeof(SPIDER_THREAD) * |
| 7323 | spider_param_table_sts_thread_count(), |
| 7324 | &spider_table_crd_threads, sizeof(SPIDER_THREAD) * |
| 7325 | spider_param_table_crd_thread_count(), |
| 7326 | NullS)) |
| 7327 | ) |
| 7328 | goto error_alloc_mon_mutxes; |
| 7329 | |
| 7330 | for (roop_count = 0; |
| 7331 | roop_count < (int) spider_param_table_sts_thread_count(); |
| 7332 | roop_count++) |
| 7333 | { |
| 7334 | if ((error_num = spider_create_sts_threads(&spider_table_sts_threads[roop_count]))) |
| 7335 | { |
| 7336 | goto error_init_table_sts_threads; |
| 7337 | } |
| 7338 | } |
| 7339 | for (roop_count = 0; |
| 7340 | roop_count < (int) spider_param_table_crd_thread_count(); |
| 7341 | roop_count++) |
| 7342 | { |
| 7343 | if ((error_num = spider_create_crd_threads(&spider_table_crd_threads[roop_count]))) |
| 7344 | { |
| 7345 | goto error_init_table_crd_threads; |
| 7346 | } |
| 7347 | } |
| 7348 | #endif |
| 7349 | |
| 7350 | spider_dbton_mysql.dbton_id = dbton_id; |
| 7351 | spider_dbton[dbton_id] = spider_dbton_mysql; |
| 7352 | ++dbton_id; |
| 7353 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 7354 | spider_dbton_handlersocket.dbton_id = dbton_id; |
| 7355 | spider_dbton[dbton_id] = spider_dbton_handlersocket; |
| 7356 | ++dbton_id; |
| 7357 | #endif |
| 7358 | #ifdef HAVE_ORACLE_OCI |
| 7359 | spider_dbton_oracle.dbton_id = dbton_id; |
| 7360 | spider_dbton[dbton_id] = spider_dbton_oracle; |
| 7361 | ++dbton_id; |
| 7362 | #endif |
| 7363 | for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++) |
| 7364 | { |
| 7365 | if (spider_dbton[roop_count].init) |
| 7366 | { |
| 7367 | if ((error_num = spider_dbton[roop_count].init())) |
| 7368 | { |
| 7369 | goto error_init_dbton; |
| 7370 | } |
| 7371 | } |
| 7372 | } |
| 7373 | |
| 7374 | DBUG_RETURN(0); |
| 7375 | |
| 7376 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 7377 | error_init_dbton: |
| 7378 | for (roop_count--; roop_count >= 0; roop_count--) |
| 7379 | { |
| 7380 | if (spider_dbton[roop_count].deinit) |
| 7381 | { |
| 7382 | spider_dbton[roop_count].deinit(); |
| 7383 | } |
| 7384 | } |
| 7385 | roop_count = spider_param_table_crd_thread_count() - 1; |
| 7386 | error_init_table_crd_threads: |
| 7387 | for (; roop_count >= 0; roop_count--) |
| 7388 | { |
| 7389 | spider_free_crd_threads(&spider_table_crd_threads[roop_count]); |
| 7390 | } |
| 7391 | roop_count = spider_param_table_sts_thread_count() - 1; |
| 7392 | error_init_table_sts_threads: |
| 7393 | for (; roop_count >= 0; roop_count--) |
| 7394 | { |
| 7395 | spider_free_sts_threads(&spider_table_sts_threads[roop_count]); |
| 7396 | } |
| 7397 | spider_free(NULL, spider_table_sts_threads, MYF(0)); |
| 7398 | roop_count = spider_param_udf_table_mon_mutex_count() - 1; |
| 7399 | #endif |
| 7400 | error_init_udf_table_mon_list_hash: |
| 7401 | for (; roop_count >= 0; roop_count--) |
| 7402 | { |
| 7403 | spider_free_mem_calc(NULL, |
| 7404 | spider_udf_table_mon_list_hash_id, |
| 7405 | spider_udf_table_mon_list_hash[roop_count].array.max_element * |
| 7406 | spider_udf_table_mon_list_hash[roop_count].array.size_of_element); |
| 7407 | my_hash_free(&spider_udf_table_mon_list_hash[roop_count]); |
| 7408 | } |
| 7409 | roop_count = spider_param_udf_table_mon_mutex_count() - 1; |
| 7410 | error_init_udf_table_mon_cond: |
| 7411 | for (; roop_count >= 0; roop_count--) |
| 7412 | pthread_cond_destroy(&spider_udf_table_mon_conds[roop_count]); |
| 7413 | roop_count = spider_param_udf_table_mon_mutex_count() - 1; |
| 7414 | error_init_udf_table_mon_mutex: |
| 7415 | for (; roop_count >= 0; roop_count--) |
| 7416 | pthread_mutex_destroy(&spider_udf_table_mon_mutexes[roop_count]); |
| 7417 | spider_free(NULL, spider_udf_table_mon_mutexes, MYF(0)); |
| 7418 | error_alloc_mon_mutxes: |
| 7419 | spider_free_mem_calc(NULL, |
| 7420 | spider_mon_table_cache_id, |
| 7421 | spider_mon_table_cache.max_element * |
| 7422 | spider_mon_table_cache.size_of_element); |
| 7423 | delete_dynamic(&spider_mon_table_cache); |
| 7424 | error_mon_table_cache_array_init: |
| 7425 | spider_free_mem_calc(NULL, |
| 7426 | spider_allocated_thds_id, |
| 7427 | spider_allocated_thds.array.max_element * |
| 7428 | spider_allocated_thds.array.size_of_element); |
| 7429 | my_hash_free(&spider_allocated_thds); |
| 7430 | error_allocated_thds_hash_init: |
| 7431 | my_hash_free(&spider_ipport_conns); |
| 7432 | error_ipport_conn__hash_init: |
| 7433 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 7434 | spider_free_mem_calc(NULL, |
| 7435 | spider_hs_w_conn_hash_id, |
| 7436 | spider_hs_w_conn_hash.array.max_element * |
| 7437 | spider_hs_w_conn_hash.array.size_of_element); |
| 7438 | my_hash_free(&spider_hs_w_conn_hash); |
| 7439 | error_hs_w_conn_hash_init: |
| 7440 | spider_free_mem_calc(NULL, |
| 7441 | spider_hs_r_conn_hash_id, |
| 7442 | spider_hs_r_conn_hash.array.max_element * |
| 7443 | spider_hs_r_conn_hash.array.size_of_element); |
| 7444 | my_hash_free(&spider_hs_r_conn_hash); |
| 7445 | error_hs_r_conn_hash_init: |
| 7446 | #endif |
| 7447 | spider_free_mem_calc(NULL, |
| 7448 | spider_open_connections_id, |
| 7449 | spider_open_connections.array.max_element * |
| 7450 | spider_open_connections.array.size_of_element); |
| 7451 | my_hash_free(&spider_open_connections); |
| 7452 | error_open_connections_hash_init: |
| 7453 | spider_free_mem_calc(NULL, |
| 7454 | spider_lgtm_tblhnd_share_hash_id, |
| 7455 | spider_lgtm_tblhnd_share_hash.array.max_element * |
| 7456 | spider_lgtm_tblhnd_share_hash.array.size_of_element); |
| 7457 | my_hash_free(&spider_lgtm_tblhnd_share_hash); |
| 7458 | error_lgtm_tblhnd_share_hash_init: |
| 7459 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7460 | spider_free_mem_calc(NULL, |
| 7461 | spider_open_pt_share_id, |
| 7462 | spider_open_pt_share.array.max_element * |
| 7463 | spider_open_pt_share.array.size_of_element); |
| 7464 | my_hash_free(&spider_open_pt_share); |
| 7465 | error_open_pt_share_hash_init: |
| 7466 | #endif |
| 7467 | spider_free_mem_calc(NULL, |
| 7468 | spider_init_error_tables_id, |
| 7469 | spider_init_error_tables.array.max_element * |
| 7470 | spider_init_error_tables.array.size_of_element); |
| 7471 | my_hash_free(&spider_init_error_tables); |
| 7472 | error_init_error_tables_hash_init: |
| 7473 | spider_free_mem_calc(NULL, |
| 7474 | spider_open_tables_id, |
| 7475 | spider_open_tables.array.max_element * |
| 7476 | spider_open_tables.array.size_of_element); |
| 7477 | my_hash_free(&spider_open_tables); |
| 7478 | error_open_tables_hash_init: |
| 7479 | pthread_mutex_destroy(&spider_mem_calc_mutex); |
| 7480 | error_mem_calc_mutex_init: |
| 7481 | pthread_mutex_destroy(&spider_mon_table_cache_mutex); |
| 7482 | error_mon_table_cache_mutex_init: |
| 7483 | pthread_mutex_destroy(&spider_allocated_thds_mutex); |
| 7484 | error_allocated_thds_mutex_init: |
| 7485 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 7486 | pthread_mutex_destroy(&spider_hs_w_conn_mutex); |
| 7487 | error_hs_w_conn_mutex_init: |
| 7488 | pthread_mutex_destroy(&spider_hs_r_conn_mutex); |
| 7489 | error_hs_r_conn_mutex_init: |
| 7490 | #endif |
| 7491 | pthread_mutex_destroy(&spider_open_conn_mutex); |
| 7492 | error_open_conn_mutex_init: |
| 7493 | pthread_mutex_destroy(&spider_conn_mutex); |
| 7494 | error_conn_mutex_init: |
| 7495 | pthread_mutex_destroy(&spider_lgtm_tblhnd_share_mutex); |
| 7496 | error_lgtm_tblhnd_share_mutex_init: |
| 7497 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7498 | pthread_mutex_destroy(&spider_pt_share_mutex); |
| 7499 | error_pt_share_mutex_init: |
| 7500 | #endif |
| 7501 | pthread_mutex_destroy(&spider_init_error_tbl_mutex); |
| 7502 | error_init_error_tbl_mutex_init: |
| 7503 | pthread_mutex_destroy(&spider_ipport_conn_mutex); |
| 7504 | error_ipport_count_mutex_init: |
| 7505 | pthread_mutex_destroy(&spider_conn_id_mutex); |
| 7506 | error_conn_id_mutex_init: |
| 7507 | pthread_mutex_destroy(&spider_thread_id_mutex); |
| 7508 | error_thread_id_mutex_init: |
| 7509 | pthread_mutex_destroy(&spider_tbl_mutex); |
| 7510 | error_tbl_mutex_init: |
| 7511 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 7512 | /* |
| 7513 | error_pt_attr_setstate: |
| 7514 | */ |
| 7515 | pthread_attr_destroy(&spider_pt_attr); |
| 7516 | error_pt_attr_init: |
| 7517 | #endif |
| 7518 | DBUG_RETURN(error_num); |
| 7519 | } |
| 7520 | |
| 7521 | char *spider_create_string( |
| 7522 | const char *str, |
| 7523 | uint length |
| 7524 | ) { |
| 7525 | char *res; |
| 7526 | DBUG_ENTER("spider_create_string" ); |
| 7527 | if (!(res = (char*) spider_malloc(spider_current_trx, 13, length + 1, |
| 7528 | MYF(MY_WME)))) |
| 7529 | DBUG_RETURN(NULL); |
| 7530 | memcpy(res, str, length); |
| 7531 | res[length] = '\0'; |
| 7532 | DBUG_RETURN(res); |
| 7533 | } |
| 7534 | |
| 7535 | char *spider_create_table_name_string( |
| 7536 | const char *table_name, |
| 7537 | const char *part_name, |
| 7538 | const char *sub_name |
| 7539 | ) { |
| 7540 | char *res, *tmp; |
| 7541 | uint length = strlen(table_name); |
| 7542 | DBUG_ENTER("spider_create_table_name_string" ); |
| 7543 | if (part_name) |
| 7544 | { |
| 7545 | length += sizeof("#P#" ) - 1 + strlen(part_name); |
| 7546 | if (sub_name) |
| 7547 | length += sizeof("#SP#" ) - 1 + strlen(sub_name); |
| 7548 | } |
| 7549 | if (!(res = (char*) spider_malloc(spider_current_trx, 14, length + 1, |
| 7550 | MYF(MY_WME)))) |
| 7551 | DBUG_RETURN(NULL); |
| 7552 | tmp = strmov(res, table_name); |
| 7553 | if (part_name) |
| 7554 | { |
| 7555 | tmp = strmov(tmp, "#P#" ); |
| 7556 | tmp = strmov(tmp, part_name); |
| 7557 | if (sub_name) |
| 7558 | { |
| 7559 | tmp = strmov(tmp, "#SP#" ); |
| 7560 | tmp = strmov(tmp, sub_name); |
| 7561 | } |
| 7562 | } |
| 7563 | DBUG_RETURN(res); |
| 7564 | } |
| 7565 | |
| 7566 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7567 | void spider_get_partition_info( |
| 7568 | const char *table_name, |
| 7569 | uint table_name_length, |
| 7570 | const TABLE_SHARE *table_share, |
| 7571 | partition_info *part_info, |
| 7572 | partition_element **part_elem, |
| 7573 | partition_element **sub_elem |
| 7574 | ) { |
| 7575 | char tmp_name[FN_REFLEN + 1]; |
| 7576 | partition_element *tmp_part_elem = NULL, *tmp_sub_elem = NULL; |
| 7577 | bool tmp_flg = FALSE, tmp_find_flg = FALSE; |
| 7578 | DBUG_ENTER("spider_get_partition_info" ); |
| 7579 | *part_elem = NULL; |
| 7580 | *sub_elem = NULL; |
| 7581 | if (!part_info) |
| 7582 | DBUG_VOID_RETURN; |
| 7583 | |
| 7584 | if (!memcmp(table_name + table_name_length - 5, "#TMP#" , 5)) |
| 7585 | tmp_flg = TRUE; |
| 7586 | |
| 7587 | DBUG_PRINT("info" ,("spider table_name=%s" , table_name)); |
| 7588 | List_iterator<partition_element> part_it(part_info->partitions); |
| 7589 | while ((*part_elem = part_it++)) |
| 7590 | { |
| 7591 | if ((*part_elem)->subpartitions.elements) |
| 7592 | { |
| 7593 | List_iterator<partition_element> sub_it((*part_elem)->subpartitions); |
| 7594 | while ((*sub_elem = sub_it++)) |
| 7595 | { |
| 7596 | if (SPIDER_create_subpartition_name( |
| 7597 | tmp_name, FN_REFLEN + 1, table_share->path.str, |
| 7598 | (*part_elem)->partition_name, (*sub_elem)->partition_name, |
| 7599 | NORMAL_PART_NAME)) |
| 7600 | { |
| 7601 | DBUG_VOID_RETURN; |
| 7602 | } |
| 7603 | DBUG_PRINT("info" ,("spider tmp_name=%s" , tmp_name)); |
| 7604 | if (!memcmp(table_name, tmp_name, table_name_length + 1)) |
| 7605 | DBUG_VOID_RETURN; |
| 7606 | if ( |
| 7607 | tmp_flg && |
| 7608 | *(tmp_name + table_name_length - 5) == '\0' && |
| 7609 | !memcmp(table_name, tmp_name, table_name_length - 5) |
| 7610 | ) { |
| 7611 | tmp_part_elem = *part_elem; |
| 7612 | tmp_sub_elem = *sub_elem; |
| 7613 | tmp_flg = FALSE; |
| 7614 | tmp_find_flg = TRUE; |
| 7615 | } |
| 7616 | } |
| 7617 | } else { |
| 7618 | if (SPIDER_create_partition_name( |
| 7619 | tmp_name, FN_REFLEN + 1, table_share->path.str, |
| 7620 | (*part_elem)->partition_name, NORMAL_PART_NAME, TRUE)) |
| 7621 | { |
| 7622 | DBUG_VOID_RETURN; |
| 7623 | } |
| 7624 | DBUG_PRINT("info" ,("spider tmp_name=%s" , tmp_name)); |
| 7625 | if (!memcmp(table_name, tmp_name, table_name_length + 1)) |
| 7626 | DBUG_VOID_RETURN; |
| 7627 | if ( |
| 7628 | tmp_flg && |
| 7629 | *(tmp_name + table_name_length - 5) == '\0' && |
| 7630 | !memcmp(table_name, tmp_name, table_name_length - 5) |
| 7631 | ) { |
| 7632 | tmp_part_elem = *part_elem; |
| 7633 | tmp_flg = FALSE; |
| 7634 | tmp_find_flg = TRUE; |
| 7635 | } |
| 7636 | } |
| 7637 | } |
| 7638 | if (tmp_find_flg) |
| 7639 | { |
| 7640 | *part_elem = tmp_part_elem; |
| 7641 | *sub_elem = tmp_sub_elem; |
| 7642 | DBUG_PRINT("info" ,("spider tmp find" )); |
| 7643 | DBUG_VOID_RETURN; |
| 7644 | } |
| 7645 | *part_elem = NULL; |
| 7646 | *sub_elem = NULL; |
| 7647 | DBUG_PRINT("info" ,("spider no hit" )); |
| 7648 | DBUG_VOID_RETURN; |
| 7649 | } |
| 7650 | #endif |
| 7651 | |
| 7652 | int spider_get_sts( |
| 7653 | SPIDER_SHARE *share, |
| 7654 | int link_idx, |
| 7655 | time_t tmp_time, |
| 7656 | ha_spider *spider, |
| 7657 | double sts_interval, |
| 7658 | int sts_mode, |
| 7659 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7660 | int sts_sync, |
| 7661 | #endif |
| 7662 | int sts_sync_level, |
| 7663 | uint flag |
| 7664 | ) { |
| 7665 | int get_type; |
| 7666 | int error_num = 0; |
| 7667 | bool need_to_get = TRUE; |
| 7668 | DBUG_ENTER("spider_get_sts" ); |
| 7669 | |
| 7670 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7671 | if ( |
| 7672 | sts_sync == 0 |
| 7673 | ) { |
| 7674 | #endif |
| 7675 | /* get */ |
| 7676 | get_type = 1; |
| 7677 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7678 | } else if ( |
| 7679 | !share->partition_share->sts_init |
| 7680 | ) { |
| 7681 | pthread_mutex_lock(&share->partition_share->sts_mutex); |
| 7682 | if (!share->partition_share->sts_init) |
| 7683 | { |
| 7684 | /* get after mutex_lock */ |
| 7685 | get_type = 2; |
| 7686 | } else { |
| 7687 | pthread_mutex_unlock(&share->partition_share->sts_mutex); |
| 7688 | /* copy */ |
| 7689 | get_type = 0; |
| 7690 | } |
| 7691 | } else if ( |
| 7692 | difftime(share->sts_get_time, share->partition_share->sts_get_time) < |
| 7693 | sts_interval |
| 7694 | ) { |
| 7695 | /* copy */ |
| 7696 | get_type = 0; |
| 7697 | } else if ( |
| 7698 | !pthread_mutex_trylock(&share->partition_share->sts_mutex) |
| 7699 | ) { |
| 7700 | /* get after mutex_trylock */ |
| 7701 | get_type = 3; |
| 7702 | } else { |
| 7703 | /* copy */ |
| 7704 | get_type = 0; |
| 7705 | } |
| 7706 | #endif |
| 7707 | if ( |
| 7708 | !share->sts_init && |
| 7709 | spider_param_load_sts_at_startup(share->load_sts_at_startup) && |
| 7710 | (!share->init || share->init_error) |
| 7711 | ) { |
| 7712 | error_num = spider_sys_get_table_sts( |
| 7713 | current_thd, |
| 7714 | share->lgtm_tblhnd_share->table_name, |
| 7715 | share->lgtm_tblhnd_share->table_name_length, |
| 7716 | &share->data_file_length, |
| 7717 | &share->max_data_file_length, |
| 7718 | &share->index_file_length, |
| 7719 | &share->records, |
| 7720 | &share->mean_rec_length, |
| 7721 | &share->check_time, |
| 7722 | &share->create_time, |
| 7723 | &share->update_time, |
| 7724 | FALSE |
| 7725 | ); |
| 7726 | if ( |
| 7727 | !error_num || |
| 7728 | (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) |
| 7729 | ) |
| 7730 | need_to_get = FALSE; |
| 7731 | } |
| 7732 | |
| 7733 | if (need_to_get) |
| 7734 | { |
| 7735 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7736 | if (get_type == 0) |
| 7737 | spider_copy_sts_to_share(share, share->partition_share); |
| 7738 | else { |
| 7739 | #endif |
| 7740 | error_num = spider_db_show_table_status(spider, link_idx, sts_mode, flag); |
| 7741 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7742 | } |
| 7743 | #endif |
| 7744 | } |
| 7745 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7746 | if (get_type >= 2) |
| 7747 | pthread_mutex_unlock(&share->partition_share->sts_mutex); |
| 7748 | #endif |
| 7749 | if (error_num) |
| 7750 | { |
| 7751 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7752 | SPIDER_PARTITION_HANDLER_SHARE *partition_handler_share = |
| 7753 | spider->partition_handler_share; |
| 7754 | if ( |
| 7755 | !share->partition_share->sts_init && |
| 7756 | sts_sync >= sts_sync_level && |
| 7757 | get_type > 1 && |
| 7758 | partition_handler_share && |
| 7759 | partition_handler_share->handlers && |
| 7760 | partition_handler_share->handlers[0] == spider |
| 7761 | ) { |
| 7762 | int roop_count; |
| 7763 | ha_spider *tmp_spider; |
| 7764 | SPIDER_SHARE *tmp_share; |
| 7765 | double tmp_sts_interval; |
| 7766 | int tmp_sts_mode; |
| 7767 | int tmp_sts_sync; |
| 7768 | THD *thd = spider->trx->thd; |
| 7769 | for (roop_count = 1; |
| 7770 | roop_count < (int) partition_handler_share->use_count; |
| 7771 | roop_count++) |
| 7772 | { |
| 7773 | tmp_spider = |
| 7774 | (ha_spider *) partition_handler_share->handlers[roop_count]; |
| 7775 | tmp_share = tmp_spider->share; |
| 7776 | tmp_sts_interval = spider_param_sts_interval(thd, share->sts_interval); |
| 7777 | tmp_sts_mode = spider_param_sts_mode(thd, share->sts_mode); |
| 7778 | tmp_sts_sync = spider_param_sts_sync(thd, share->sts_sync); |
| 7779 | spider_get_sts(tmp_share, tmp_spider->search_link_idx, |
| 7780 | tmp_time, tmp_spider, tmp_sts_interval, tmp_sts_mode, tmp_sts_sync, |
| 7781 | 1, flag); |
| 7782 | if (share->partition_share->sts_init) |
| 7783 | { |
| 7784 | error_num = 0; |
| 7785 | thd->clear_error(); |
| 7786 | get_type = 0; |
| 7787 | spider_copy_sts_to_share(share, share->partition_share); |
| 7788 | break; |
| 7789 | } |
| 7790 | } |
| 7791 | } |
| 7792 | if (error_num) |
| 7793 | #endif |
| 7794 | DBUG_RETURN(error_num); |
| 7795 | } |
| 7796 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7797 | if (sts_sync >= sts_sync_level && get_type > 0) |
| 7798 | { |
| 7799 | spider_copy_sts_to_pt_share(share->partition_share, share); |
| 7800 | share->partition_share->sts_get_time = tmp_time; |
| 7801 | share->partition_share->sts_init = TRUE; |
| 7802 | } |
| 7803 | #endif |
| 7804 | share->sts_get_time = tmp_time; |
| 7805 | share->sts_init = TRUE; |
| 7806 | DBUG_RETURN(0); |
| 7807 | } |
| 7808 | |
| 7809 | int spider_get_crd( |
| 7810 | SPIDER_SHARE *share, |
| 7811 | int link_idx, |
| 7812 | time_t tmp_time, |
| 7813 | ha_spider *spider, |
| 7814 | TABLE *table, |
| 7815 | double crd_interval, |
| 7816 | int crd_mode, |
| 7817 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7818 | int crd_sync, |
| 7819 | #endif |
| 7820 | int crd_sync_level |
| 7821 | ) { |
| 7822 | int get_type; |
| 7823 | int error_num = 0; |
| 7824 | bool need_to_get = TRUE; |
| 7825 | DBUG_ENTER("spider_get_crd" ); |
| 7826 | |
| 7827 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7828 | if ( |
| 7829 | crd_sync == 0 |
| 7830 | ) { |
| 7831 | #endif |
| 7832 | /* get */ |
| 7833 | get_type = 1; |
| 7834 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7835 | } else if ( |
| 7836 | !share->partition_share->crd_init |
| 7837 | ) { |
| 7838 | pthread_mutex_lock(&share->partition_share->crd_mutex); |
| 7839 | if (!share->partition_share->crd_init) |
| 7840 | { |
| 7841 | /* get after mutex_lock */ |
| 7842 | get_type = 2; |
| 7843 | } else { |
| 7844 | pthread_mutex_unlock(&share->partition_share->crd_mutex); |
| 7845 | /* copy */ |
| 7846 | get_type = 0; |
| 7847 | } |
| 7848 | } else if ( |
| 7849 | difftime(share->crd_get_time, share->partition_share->crd_get_time) < |
| 7850 | crd_interval |
| 7851 | ) { |
| 7852 | /* copy */ |
| 7853 | get_type = 0; |
| 7854 | } else if ( |
| 7855 | !pthread_mutex_trylock(&share->partition_share->crd_mutex) |
| 7856 | ) { |
| 7857 | /* get after mutex_trylock */ |
| 7858 | get_type = 3; |
| 7859 | } else { |
| 7860 | /* copy */ |
| 7861 | get_type = 0; |
| 7862 | } |
| 7863 | #endif |
| 7864 | if ( |
| 7865 | !share->crd_init && |
| 7866 | spider_param_load_sts_at_startup(share->load_crd_at_startup) |
| 7867 | ) { |
| 7868 | error_num = spider_sys_get_table_crd( |
| 7869 | current_thd, |
| 7870 | share->lgtm_tblhnd_share->table_name, |
| 7871 | share->lgtm_tblhnd_share->table_name_length, |
| 7872 | share->cardinality, |
| 7873 | table->s->fields, |
| 7874 | FALSE |
| 7875 | ); |
| 7876 | if ( |
| 7877 | !error_num || |
| 7878 | (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE) |
| 7879 | ) |
| 7880 | need_to_get = FALSE; |
| 7881 | } |
| 7882 | |
| 7883 | if (need_to_get) |
| 7884 | { |
| 7885 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7886 | if (get_type == 0) |
| 7887 | spider_copy_crd_to_share(share, share->partition_share, |
| 7888 | table->s->fields); |
| 7889 | else { |
| 7890 | #endif |
| 7891 | error_num = spider_db_show_index(spider, link_idx, table, crd_mode); |
| 7892 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7893 | } |
| 7894 | #endif |
| 7895 | } |
| 7896 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7897 | if (get_type >= 2) |
| 7898 | pthread_mutex_unlock(&share->partition_share->crd_mutex); |
| 7899 | #endif |
| 7900 | if (error_num) |
| 7901 | { |
| 7902 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7903 | SPIDER_PARTITION_HANDLER_SHARE *partition_handler_share = |
| 7904 | spider->partition_handler_share; |
| 7905 | if ( |
| 7906 | !share->partition_share->crd_init && |
| 7907 | crd_sync >= crd_sync_level && |
| 7908 | get_type > 1 && |
| 7909 | partition_handler_share && |
| 7910 | partition_handler_share->handlers && |
| 7911 | partition_handler_share->handlers[0] == spider |
| 7912 | ) { |
| 7913 | int roop_count; |
| 7914 | ha_spider *tmp_spider; |
| 7915 | SPIDER_SHARE *tmp_share; |
| 7916 | double tmp_crd_interval; |
| 7917 | int tmp_crd_mode; |
| 7918 | int tmp_crd_sync; |
| 7919 | THD *thd = spider->trx->thd; |
| 7920 | for (roop_count = 1; |
| 7921 | roop_count < (int) partition_handler_share->use_count; |
| 7922 | roop_count++) |
| 7923 | { |
| 7924 | tmp_spider = |
| 7925 | (ha_spider *) partition_handler_share->handlers[roop_count]; |
| 7926 | tmp_share = tmp_spider->share; |
| 7927 | tmp_crd_interval = spider_param_crd_interval(thd, share->crd_interval); |
| 7928 | tmp_crd_mode = spider_param_crd_mode(thd, share->crd_mode); |
| 7929 | tmp_crd_sync = spider_param_crd_sync(thd, share->crd_sync); |
| 7930 | spider_get_crd(tmp_share, tmp_spider->search_link_idx, |
| 7931 | tmp_time, tmp_spider, table, tmp_crd_interval, tmp_crd_mode, |
| 7932 | tmp_crd_sync, 1); |
| 7933 | if (share->partition_share->crd_init) |
| 7934 | { |
| 7935 | error_num = 0; |
| 7936 | thd->clear_error(); |
| 7937 | get_type = 0; |
| 7938 | spider_copy_crd_to_share(share, share->partition_share, |
| 7939 | table->s->fields); |
| 7940 | break; |
| 7941 | } |
| 7942 | } |
| 7943 | } |
| 7944 | if (error_num) |
| 7945 | #endif |
| 7946 | DBUG_RETURN(error_num); |
| 7947 | } |
| 7948 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 7949 | if (crd_sync >= crd_sync_level && get_type > 0) |
| 7950 | { |
| 7951 | spider_copy_crd_to_pt_share(share->partition_share, share, |
| 7952 | table->s->fields); |
| 7953 | share->partition_share->crd_get_time = tmp_time; |
| 7954 | share->partition_share->crd_init = TRUE; |
| 7955 | } |
| 7956 | #endif |
| 7957 | share->crd_get_time = tmp_time; |
| 7958 | share->crd_init = TRUE; |
| 7959 | DBUG_RETURN(0); |
| 7960 | } |
| 7961 | |
| 7962 | void spider_set_result_list_param( |
| 7963 | ha_spider *spider |
| 7964 | ) { |
| 7965 | SPIDER_RESULT_LIST *result_list = &spider->result_list; |
| 7966 | SPIDER_SHARE *share = spider->share; |
| 7967 | THD *thd = spider->trx->thd; |
| 7968 | DBUG_ENTER("spider_set_result_list_param" ); |
| 7969 | result_list->internal_offset = |
| 7970 | spider_param_internal_offset(thd, share->internal_offset); |
| 7971 | result_list->internal_limit = |
| 7972 | #ifdef INFO_KIND_FORCE_LIMIT_BEGIN |
| 7973 | spider->info_limit < 9223372036854775807LL ? |
| 7974 | spider->info_limit : |
| 7975 | #endif |
| 7976 | spider_param_internal_limit(thd, share->internal_limit); |
| 7977 | result_list->split_read = spider_split_read_param(spider); |
| 7978 | if (spider->support_multi_split_read_sql()) |
| 7979 | { |
| 7980 | result_list->multi_split_read = |
| 7981 | spider_param_multi_split_read(thd, share->multi_split_read); |
| 7982 | } else { |
| 7983 | result_list->multi_split_read = 1; |
| 7984 | } |
| 7985 | result_list->max_order = |
| 7986 | spider_param_max_order(thd, share->max_order); |
| 7987 | result_list->quick_mode = |
| 7988 | spider_param_quick_mode(thd, share->quick_mode); |
| 7989 | result_list->quick_page_size = |
| 7990 | spider_param_quick_page_size(thd, share->quick_page_size); |
| 7991 | result_list->low_mem_read = |
| 7992 | spider_param_low_mem_read(thd, share->low_mem_read); |
| 7993 | DBUG_VOID_RETURN; |
| 7994 | } |
| 7995 | |
| 7996 | SPIDER_INIT_ERROR_TABLE *spider_get_init_error_table( |
| 7997 | SPIDER_TRX *trx, |
| 7998 | SPIDER_SHARE *share, |
| 7999 | bool create |
| 8000 | ) { |
| 8001 | SPIDER_INIT_ERROR_TABLE *spider_init_error_table; |
| 8002 | char *tmp_name; |
| 8003 | DBUG_ENTER("spider_get_init_error_table" ); |
| 8004 | pthread_mutex_lock(&spider_init_error_tbl_mutex); |
| 8005 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 8006 | if (!(spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *) |
| 8007 | my_hash_search_using_hash_value( |
| 8008 | &spider_init_error_tables, share->table_name_hash_value, |
| 8009 | (uchar*) share->table_name, share->table_name_length))) |
| 8010 | #else |
| 8011 | if (!(spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *) my_hash_search( |
| 8012 | &spider_init_error_tables, |
| 8013 | (uchar*) share->table_name, share->table_name_length))) |
| 8014 | #endif |
| 8015 | { |
| 8016 | if (!create) |
| 8017 | { |
| 8018 | pthread_mutex_unlock(&spider_init_error_tbl_mutex); |
| 8019 | DBUG_RETURN(NULL); |
| 8020 | } |
| 8021 | if (!(spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *) |
| 8022 | spider_bulk_malloc(spider_current_trx, 54, MYF(MY_WME | MY_ZEROFILL), |
| 8023 | &spider_init_error_table, sizeof(*spider_init_error_table), |
| 8024 | &tmp_name, share->table_name_length + 1, |
| 8025 | NullS)) |
| 8026 | ) { |
| 8027 | pthread_mutex_unlock(&spider_init_error_tbl_mutex); |
| 8028 | DBUG_RETURN(NULL); |
| 8029 | } |
| 8030 | memcpy(tmp_name, share->table_name, share->table_name_length); |
| 8031 | spider_init_error_table->table_name = tmp_name; |
| 8032 | spider_init_error_table->table_name_length = share->table_name_length; |
| 8033 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 8034 | spider_init_error_table->table_name_hash_value = |
| 8035 | share->table_name_hash_value; |
| 8036 | #endif |
| 8037 | uint old_elements = spider_init_error_tables.array.max_element; |
| 8038 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
| 8039 | if (my_hash_insert_with_hash_value(&spider_init_error_tables, |
| 8040 | share->table_name_hash_value, (uchar*) spider_init_error_table)) |
| 8041 | #else |
| 8042 | if (my_hash_insert(&spider_init_error_tables, |
| 8043 | (uchar*) spider_init_error_table)) |
| 8044 | #endif |
| 8045 | { |
| 8046 | spider_free(trx, spider_init_error_table, MYF(0)); |
| 8047 | pthread_mutex_unlock(&spider_init_error_tbl_mutex); |
| 8048 | DBUG_RETURN(NULL); |
| 8049 | } |
| 8050 | if (spider_init_error_tables.array.max_element > old_elements) |
| 8051 | { |
| 8052 | spider_alloc_calc_mem(spider_current_trx, |
| 8053 | spider_init_error_tables, |
| 8054 | (spider_init_error_tables.array.max_element - old_elements) * |
| 8055 | spider_init_error_tables.array.size_of_element); |
| 8056 | } |
| 8057 | } |
| 8058 | pthread_mutex_unlock(&spider_init_error_tbl_mutex); |
| 8059 | DBUG_RETURN(spider_init_error_table); |
| 8060 | } |
| 8061 | |
| 8062 | void spider_delete_init_error_table( |
| 8063 | const char *name |
| 8064 | ) { |
| 8065 | SPIDER_INIT_ERROR_TABLE *spider_init_error_table; |
| 8066 | uint length = strlen(name); |
| 8067 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 8068 | my_hash_value_type hash_value = my_calc_hash(&spider_open_tables, |
| 8069 | (uchar*) name, length); |
| 8070 | #endif |
| 8071 | DBUG_ENTER("spider_delete_init_error_table" ); |
| 8072 | pthread_mutex_lock(&spider_init_error_tbl_mutex); |
| 8073 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 8074 | if ((spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *) |
| 8075 | my_hash_search_using_hash_value(&spider_init_error_tables, hash_value, |
| 8076 | (uchar*) name, length))) |
| 8077 | #else |
| 8078 | if ((spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *) my_hash_search( |
| 8079 | &spider_init_error_tables, (uchar*) name, length))) |
| 8080 | #endif |
| 8081 | { |
| 8082 | #ifdef HASH_UPDATE_WITH_HASH_VALUE |
| 8083 | my_hash_delete_with_hash_value(&spider_init_error_tables, |
| 8084 | spider_init_error_table->table_name_hash_value, |
| 8085 | (uchar*) spider_init_error_table); |
| 8086 | #else |
| 8087 | my_hash_delete(&spider_init_error_tables, |
| 8088 | (uchar*) spider_init_error_table); |
| 8089 | #endif |
| 8090 | spider_free(spider_current_trx, spider_init_error_table, MYF(0)); |
| 8091 | } |
| 8092 | pthread_mutex_unlock(&spider_init_error_tbl_mutex); |
| 8093 | DBUG_VOID_RETURN; |
| 8094 | } |
| 8095 | |
| 8096 | bool spider_check_pk_update( |
| 8097 | TABLE *table |
| 8098 | ) { |
| 8099 | int roop_count; |
| 8100 | TABLE_SHARE *table_share = table->s; |
| 8101 | KEY *key_info; |
| 8102 | KEY_PART_INFO *key_part; |
| 8103 | DBUG_ENTER("spider_check_pk_update" ); |
| 8104 | if (table_share->primary_key == MAX_KEY) |
| 8105 | DBUG_RETURN(FALSE); |
| 8106 | |
| 8107 | key_info = &table_share->key_info[table_share->primary_key]; |
| 8108 | key_part = key_info->key_part; |
| 8109 | for (roop_count = 0; |
| 8110 | roop_count < (int) spider_user_defined_key_parts(key_info); roop_count++) |
| 8111 | { |
| 8112 | if (bitmap_is_set(table->write_set, |
| 8113 | key_part[roop_count].field->field_index)) |
| 8114 | DBUG_RETURN(TRUE); |
| 8115 | } |
| 8116 | DBUG_RETURN(FALSE); |
| 8117 | } |
| 8118 | |
| 8119 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 8120 | #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS |
| 8121 | bool spider_check_hs_pk_update( |
| 8122 | ha_spider *spider, |
| 8123 | key_range *key |
| 8124 | ) { |
| 8125 | uint roop_count, field_index, set_count = 0; |
| 8126 | TABLE *table = spider->get_table(); |
| 8127 | TABLE_SHARE *table_share = table->s; |
| 8128 | SPIDER_SHARE *share = spider->share; |
| 8129 | KEY *key_info; |
| 8130 | KEY_PART_INFO *key_part; |
| 8131 | char buf[MAX_FIELD_WIDTH], buf2[MAX_FIELD_WIDTH]; |
| 8132 | spider_string tmp_str(buf, MAX_FIELD_WIDTH, &my_charset_bin), |
| 8133 | tmp_str2(buf2, MAX_FIELD_WIDTH, &my_charset_bin); |
| 8134 | String *str, *str2; |
| 8135 | DBUG_ENTER("spider_check_hs_pk_update" ); |
| 8136 | tmp_str.init_calc_mem(137); |
| 8137 | |
| 8138 | if (table_share->primary_key == MAX_KEY) |
| 8139 | DBUG_RETURN(FALSE); |
| 8140 | memset(spider->tmp_column_bitmap, 0, sizeof(uchar) * share->bitmap_size); |
| 8141 | key_info = &table->key_info[table_share->primary_key]; |
| 8142 | key_part = key_info->key_part; |
| 8143 | for (roop_count = 0; roop_count < spider_user_defined_key_parts(key_info); |
| 8144 | roop_count++) |
| 8145 | { |
| 8146 | field_index = key_part[roop_count].field->field_index; |
| 8147 | if (bitmap_is_set(table->write_set, field_index)) |
| 8148 | { |
| 8149 | DBUG_PRINT("info" , ("spider set key_part=%u field_index=%u" , |
| 8150 | roop_count, field_index)); |
| 8151 | spider_set_bit(spider->tmp_column_bitmap, field_index); |
| 8152 | set_count++; |
| 8153 | } |
| 8154 | } |
| 8155 | DBUG_PRINT("info" , ("spider set_count=%u" , set_count)); |
| 8156 | |
| 8157 | Field *field; |
| 8158 | uint store_length, length, var_len; |
| 8159 | const uchar *ptr; |
| 8160 | bool key_eq; |
| 8161 | key_part_map tgt_key_part_map = key->keypart_map; |
| 8162 | key_info = &table->key_info[spider->active_index]; |
| 8163 | for ( |
| 8164 | key_part = key_info->key_part, |
| 8165 | length = 0; |
| 8166 | tgt_key_part_map; |
| 8167 | length += store_length, |
| 8168 | tgt_key_part_map >>= 1, |
| 8169 | key_part++ |
| 8170 | ) { |
| 8171 | store_length = key_part->store_length; |
| 8172 | field = key_part->field; |
| 8173 | field_index = field->field_index; |
| 8174 | if (spider_bit_is_set(spider->tmp_column_bitmap, field_index)) |
| 8175 | { |
| 8176 | ptr = key->key + length; |
| 8177 | key_eq = (tgt_key_part_map > 1); |
| 8178 | if (key_part->null_bit && *ptr++) |
| 8179 | { |
| 8180 | if (key->flag != HA_READ_KEY_EXACT || !field->is_null()) |
| 8181 | { |
| 8182 | DBUG_PRINT("info" , ("spider flag=%u is_null=%s" , |
| 8183 | key->flag, field->is_null() ? "TRUE" : "FALSE" )); |
| 8184 | DBUG_RETURN(TRUE); |
| 8185 | } |
| 8186 | } else { |
| 8187 | if ( |
| 8188 | field->type() == MYSQL_TYPE_BLOB || |
| 8189 | field->real_type() == MYSQL_TYPE_VARCHAR || |
| 8190 | field->type() == MYSQL_TYPE_GEOMETRY |
| 8191 | ) { |
| 8192 | var_len = uint2korr(ptr); |
| 8193 | tmp_str.set_quick((char *) ptr + HA_KEY_BLOB_LENGTH, var_len, |
| 8194 | &my_charset_bin); |
| 8195 | str = tmp_str.get_str(); |
| 8196 | } else { |
| 8197 | str = field->val_str(tmp_str.get_str(), ptr); |
| 8198 | tmp_str.mem_calc(); |
| 8199 | } |
| 8200 | str2 = field->val_str(tmp_str2.get_str()); |
| 8201 | tmp_str2.mem_calc(); |
| 8202 | if ( |
| 8203 | str->length() != str2->length() || |
| 8204 | memcmp(str->ptr(), str2->ptr(), str->length()) |
| 8205 | ) { |
| 8206 | DBUG_PRINT("info" , ("spider length=%u %u" , |
| 8207 | str->length(), str2->length())); |
| 8208 | DBUG_PRINT("info" , ("spider length=%s %s" , |
| 8209 | str->c_ptr_safe(), str2->c_ptr_safe())); |
| 8210 | DBUG_RETURN(TRUE); |
| 8211 | } |
| 8212 | } |
| 8213 | set_count--; |
| 8214 | } |
| 8215 | } |
| 8216 | DBUG_PRINT("info" , ("spider set_count=%u" , set_count)); |
| 8217 | if (set_count) |
| 8218 | { |
| 8219 | DBUG_RETURN(TRUE); |
| 8220 | } |
| 8221 | DBUG_RETURN(FALSE); |
| 8222 | } |
| 8223 | #endif |
| 8224 | #endif |
| 8225 | |
| 8226 | void spider_set_tmp_share_pointer( |
| 8227 | SPIDER_SHARE *tmp_share, |
| 8228 | char **tmp_connect_info, |
| 8229 | uint *tmp_connect_info_length, |
| 8230 | long *tmp_long, |
| 8231 | longlong *tmp_longlong |
| 8232 | ) { |
| 8233 | DBUG_ENTER("spider_set_tmp_share_pointer" ); |
| 8234 | tmp_share->link_count = 1; |
| 8235 | tmp_share->all_link_count = 1; |
| 8236 | tmp_share->server_names = &tmp_connect_info[0]; |
| 8237 | tmp_share->tgt_table_names = &tmp_connect_info[1]; |
| 8238 | tmp_share->tgt_dbs = &tmp_connect_info[2]; |
| 8239 | tmp_share->tgt_hosts = &tmp_connect_info[3]; |
| 8240 | tmp_share->tgt_usernames = &tmp_connect_info[4]; |
| 8241 | tmp_share->tgt_passwords = &tmp_connect_info[5]; |
| 8242 | tmp_share->tgt_sockets = &tmp_connect_info[6]; |
| 8243 | tmp_share->tgt_wrappers = &tmp_connect_info[7]; |
| 8244 | tmp_share->tgt_ssl_cas = &tmp_connect_info[8]; |
| 8245 | tmp_share->tgt_ssl_capaths = &tmp_connect_info[9]; |
| 8246 | tmp_share->tgt_ssl_certs = &tmp_connect_info[10]; |
| 8247 | tmp_share->tgt_ssl_ciphers = &tmp_connect_info[11]; |
| 8248 | tmp_share->tgt_ssl_keys = &tmp_connect_info[12]; |
| 8249 | tmp_share->tgt_default_files = &tmp_connect_info[13]; |
| 8250 | tmp_share->tgt_default_groups = &tmp_connect_info[14]; |
| 8251 | tmp_share->tgt_pk_names = &tmp_connect_info[15]; |
| 8252 | tmp_share->tgt_sequence_names = &tmp_connect_info[16]; |
| 8253 | tmp_share->static_link_ids = &tmp_connect_info[17]; |
| 8254 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 8255 | tmp_share->hs_read_socks = &tmp_connect_info[18]; |
| 8256 | tmp_share->hs_write_socks = &tmp_connect_info[19]; |
| 8257 | #endif |
| 8258 | tmp_share->tgt_ports = &tmp_long[0]; |
| 8259 | tmp_share->tgt_ssl_vscs = &tmp_long[1]; |
| 8260 | tmp_share->link_statuses = &tmp_long[2]; |
| 8261 | tmp_share->monitoring_binlog_pos_at_failing = &tmp_long[3]; |
| 8262 | tmp_share->monitoring_flag = &tmp_long[4]; |
| 8263 | tmp_share->monitoring_kind = &tmp_long[5]; |
| 8264 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 8265 | tmp_share->monitoring_bg_flag = &tmp_long[6]; |
| 8266 | tmp_share->monitoring_bg_kind = &tmp_long[7]; |
| 8267 | #endif |
| 8268 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 8269 | tmp_share->use_hs_reads = &tmp_long[8]; |
| 8270 | tmp_share->use_hs_writes = &tmp_long[9]; |
| 8271 | tmp_share->hs_read_ports = &tmp_long[10]; |
| 8272 | tmp_share->hs_write_ports = &tmp_long[11]; |
| 8273 | tmp_share->hs_write_to_reads = &tmp_long[12]; |
| 8274 | #endif |
| 8275 | tmp_share->use_handlers = &tmp_long[13]; |
| 8276 | tmp_share->connect_timeouts = &tmp_long[14]; |
| 8277 | tmp_long[13] = -1; |
| 8278 | tmp_share->net_read_timeouts = &tmp_long[15]; |
| 8279 | tmp_long[14] = -1; |
| 8280 | tmp_share->net_write_timeouts = &tmp_long[16]; |
| 8281 | tmp_long[15] = -1; |
| 8282 | tmp_share->access_balances = &tmp_long[17]; |
| 8283 | tmp_share->bka_table_name_types = &tmp_long[18]; |
| 8284 | tmp_share->monitoring_limit = &tmp_longlong[0]; |
| 8285 | tmp_share->monitoring_sid = &tmp_longlong[1]; |
| 8286 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 8287 | tmp_share->monitoring_bg_interval = &tmp_longlong[2]; |
| 8288 | #endif |
| 8289 | tmp_share->server_names_lengths = &tmp_connect_info_length[0]; |
| 8290 | tmp_share->tgt_table_names_lengths = &tmp_connect_info_length[1]; |
| 8291 | tmp_share->tgt_dbs_lengths = &tmp_connect_info_length[2]; |
| 8292 | tmp_share->tgt_hosts_lengths = &tmp_connect_info_length[3]; |
| 8293 | tmp_share->tgt_usernames_lengths = &tmp_connect_info_length[4]; |
| 8294 | tmp_share->tgt_passwords_lengths = &tmp_connect_info_length[5]; |
| 8295 | tmp_share->tgt_sockets_lengths = &tmp_connect_info_length[6]; |
| 8296 | tmp_share->tgt_wrappers_lengths = &tmp_connect_info_length[7]; |
| 8297 | tmp_share->tgt_ssl_cas_lengths = &tmp_connect_info_length[8]; |
| 8298 | tmp_share->tgt_ssl_capaths_lengths = &tmp_connect_info_length[9]; |
| 8299 | tmp_share->tgt_ssl_certs_lengths = &tmp_connect_info_length[10]; |
| 8300 | tmp_share->tgt_ssl_ciphers_lengths = &tmp_connect_info_length[11]; |
| 8301 | tmp_share->tgt_ssl_keys_lengths = &tmp_connect_info_length[12]; |
| 8302 | tmp_share->tgt_default_files_lengths = &tmp_connect_info_length[13]; |
| 8303 | tmp_share->tgt_default_groups_lengths = &tmp_connect_info_length[14]; |
| 8304 | tmp_share->tgt_pk_names_lengths = &tmp_connect_info_length[15]; |
| 8305 | tmp_share->tgt_sequence_names_lengths = &tmp_connect_info_length[16]; |
| 8306 | tmp_share->static_link_ids_lengths = &tmp_connect_info_length[17]; |
| 8307 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 8308 | tmp_share->hs_read_socks_lengths = &tmp_connect_info_length[18]; |
| 8309 | tmp_share->hs_write_socks_lengths = &tmp_connect_info_length[19]; |
| 8310 | #endif |
| 8311 | tmp_share->server_names_length = 1; |
| 8312 | tmp_share->tgt_table_names_length = 1; |
| 8313 | tmp_share->tgt_dbs_length = 1; |
| 8314 | tmp_share->tgt_hosts_length = 1; |
| 8315 | tmp_share->tgt_usernames_length = 1; |
| 8316 | tmp_share->tgt_passwords_length = 1; |
| 8317 | tmp_share->tgt_sockets_length = 1; |
| 8318 | tmp_share->tgt_wrappers_length = 1; |
| 8319 | tmp_share->tgt_ssl_cas_length = 1; |
| 8320 | tmp_share->tgt_ssl_capaths_length = 1; |
| 8321 | tmp_share->tgt_ssl_certs_length = 1; |
| 8322 | tmp_share->tgt_ssl_ciphers_length = 1; |
| 8323 | tmp_share->tgt_ssl_keys_length = 1; |
| 8324 | tmp_share->tgt_default_files_length = 1; |
| 8325 | tmp_share->tgt_default_groups_length = 1; |
| 8326 | tmp_share->tgt_pk_names_length = 1; |
| 8327 | tmp_share->tgt_sequence_names_length = 1; |
| 8328 | tmp_share->static_link_ids_length = 1; |
| 8329 | tmp_share->tgt_ports_length = 1; |
| 8330 | tmp_share->tgt_ssl_vscs_length = 1; |
| 8331 | tmp_share->link_statuses_length = 1; |
| 8332 | tmp_share->monitoring_binlog_pos_at_failing_length = 1; |
| 8333 | tmp_share->monitoring_flag_length = 1; |
| 8334 | tmp_share->monitoring_kind_length = 1; |
| 8335 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 8336 | tmp_share->monitoring_bg_flag_length = 1; |
| 8337 | tmp_share->monitoring_bg_kind_length = 1; |
| 8338 | #endif |
| 8339 | tmp_share->monitoring_limit_length = 1; |
| 8340 | tmp_share->monitoring_sid_length = 1; |
| 8341 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 8342 | tmp_share->monitoring_bg_interval_length = 1; |
| 8343 | #endif |
| 8344 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 8345 | tmp_share->hs_read_socks_length = 1; |
| 8346 | tmp_share->hs_write_socks_length = 1; |
| 8347 | tmp_share->use_hs_reads_length = 1; |
| 8348 | tmp_share->use_hs_writes_length = 1; |
| 8349 | tmp_share->hs_read_ports_length = 1; |
| 8350 | tmp_share->hs_write_ports_length = 1; |
| 8351 | tmp_share->hs_write_to_reads_length = 1; |
| 8352 | #endif |
| 8353 | tmp_share->use_handlers_length = 1; |
| 8354 | tmp_share->connect_timeouts_length = 1; |
| 8355 | tmp_share->net_read_timeouts_length = 1; |
| 8356 | tmp_share->net_write_timeouts_length = 1; |
| 8357 | tmp_share->access_balances_length = 1; |
| 8358 | tmp_share->bka_table_name_types_length = 1; |
| 8359 | |
| 8360 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 8361 | tmp_share->monitoring_bg_flag[0] = -1; |
| 8362 | tmp_share->monitoring_bg_kind[0] = -1; |
| 8363 | #endif |
| 8364 | tmp_share->monitoring_binlog_pos_at_failing[0] = -1; |
| 8365 | tmp_share->monitoring_flag[0] = -1; |
| 8366 | tmp_share->monitoring_kind[0] = -1; |
| 8367 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 8368 | tmp_share->monitoring_bg_interval[0] = -1; |
| 8369 | #endif |
| 8370 | tmp_share->monitoring_limit[0] = -1; |
| 8371 | tmp_share->monitoring_sid[0] = -1; |
| 8372 | tmp_share->bka_engine = NULL; |
| 8373 | tmp_share->use_dbton_count = 0; |
| 8374 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 8375 | tmp_share->use_hs_dbton_count = 0; |
| 8376 | #endif |
| 8377 | DBUG_VOID_RETURN; |
| 8378 | } |
| 8379 | |
| 8380 | int spider_create_tmp_dbton_share( |
| 8381 | SPIDER_SHARE *tmp_share |
| 8382 | ) { |
| 8383 | int error_num; |
| 8384 | uint dbton_id = tmp_share->use_dbton_ids[0]; |
| 8385 | DBUG_ENTER("spider_create_tmp_dbton_share" ); |
| 8386 | if (!(tmp_share->dbton_share[dbton_id] = |
| 8387 | spider_dbton[dbton_id].create_db_share(tmp_share))) |
| 8388 | { |
| 8389 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 8390 | } |
| 8391 | if ((error_num = tmp_share->dbton_share[dbton_id]->init())) |
| 8392 | { |
| 8393 | delete tmp_share->dbton_share[dbton_id]; |
| 8394 | tmp_share->dbton_share[dbton_id] = NULL; |
| 8395 | DBUG_RETURN(error_num); |
| 8396 | } |
| 8397 | DBUG_RETURN(0); |
| 8398 | } |
| 8399 | |
| 8400 | void spider_free_tmp_dbton_share( |
| 8401 | SPIDER_SHARE *tmp_share |
| 8402 | ) { |
| 8403 | uint dbton_id = tmp_share->use_dbton_ids[0]; |
| 8404 | DBUG_ENTER("spider_free_tmp_dbton_share" ); |
| 8405 | if (tmp_share->dbton_share[dbton_id]) |
| 8406 | { |
| 8407 | delete tmp_share->dbton_share[dbton_id]; |
| 8408 | tmp_share->dbton_share[dbton_id] = NULL; |
| 8409 | } |
| 8410 | DBUG_VOID_RETURN; |
| 8411 | } |
| 8412 | |
| 8413 | int spider_create_tmp_dbton_handler( |
| 8414 | ha_spider *tmp_spider |
| 8415 | ) { |
| 8416 | int error_num; |
| 8417 | SPIDER_SHARE *tmp_share = tmp_spider->share; |
| 8418 | uint dbton_id = tmp_share->use_dbton_ids[0]; |
| 8419 | DBUG_ENTER("spider_create_tmp_dbton_handler" ); |
| 8420 | if (!(tmp_spider->dbton_handler[dbton_id] = |
| 8421 | spider_dbton[dbton_id].create_db_handler(tmp_spider, |
| 8422 | tmp_share->dbton_share[dbton_id]))) |
| 8423 | { |
| 8424 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 8425 | } |
| 8426 | if ((error_num = tmp_spider->dbton_handler[dbton_id]->init())) |
| 8427 | { |
| 8428 | delete tmp_spider->dbton_handler[dbton_id]; |
| 8429 | tmp_spider->dbton_handler[dbton_id] = NULL; |
| 8430 | DBUG_RETURN(error_num); |
| 8431 | } |
| 8432 | DBUG_RETURN(0); |
| 8433 | } |
| 8434 | |
| 8435 | void spider_free_tmp_dbton_handler( |
| 8436 | ha_spider *tmp_spider |
| 8437 | ) { |
| 8438 | SPIDER_SHARE *tmp_share = tmp_spider->share; |
| 8439 | uint dbton_id = tmp_share->use_dbton_ids[0]; |
| 8440 | DBUG_ENTER("spider_create_tmp_dbton_handler" ); |
| 8441 | if (tmp_spider->dbton_handler[dbton_id]) |
| 8442 | { |
| 8443 | delete tmp_spider->dbton_handler[dbton_id]; |
| 8444 | tmp_spider->dbton_handler[dbton_id] = NULL; |
| 8445 | } |
| 8446 | DBUG_VOID_RETURN; |
| 8447 | } |
| 8448 | |
| 8449 | TABLE_LIST *spider_get_parent_table_list( |
| 8450 | ha_spider *spider |
| 8451 | ) { |
| 8452 | TABLE *table = spider->get_table(); |
| 8453 | TABLE_LIST *table_list = table->pos_in_table_list; |
| 8454 | DBUG_ENTER("spider_get_parent_table_list" ); |
| 8455 | if (table_list) |
| 8456 | { |
| 8457 | while (table_list->parent_l) |
| 8458 | table_list = table_list->parent_l; |
| 8459 | DBUG_RETURN(table_list); |
| 8460 | } |
| 8461 | DBUG_RETURN(NULL); |
| 8462 | } |
| 8463 | |
| 8464 | List<Index_hint> *spider_get_index_hints( |
| 8465 | ha_spider *spider |
| 8466 | ) { |
| 8467 | TABLE_LIST *table_list = spider_get_parent_table_list(spider); |
| 8468 | DBUG_ENTER("spider_get_index_hint" ); |
| 8469 | if (table_list) |
| 8470 | { |
| 8471 | DBUG_RETURN(table_list->index_hints); |
| 8472 | } |
| 8473 | DBUG_RETURN(NULL); |
| 8474 | } |
| 8475 | |
| 8476 | |
| 8477 | st_select_lex *spider_get_select_lex( |
| 8478 | ha_spider *spider |
| 8479 | ) { |
| 8480 | TABLE_LIST *table_list = spider_get_parent_table_list(spider); |
| 8481 | DBUG_ENTER("spider_get_select_lex" ); |
| 8482 | if (table_list) |
| 8483 | { |
| 8484 | DBUG_RETURN(table_list->select_lex); |
| 8485 | } |
| 8486 | DBUG_RETURN(NULL); |
| 8487 | } |
| 8488 | |
| 8489 | void spider_get_select_limit_from_select_lex( |
| 8490 | st_select_lex *select_lex, |
| 8491 | longlong *select_limit, |
| 8492 | longlong *offset_limit |
| 8493 | ) { |
| 8494 | DBUG_ENTER("spider_get_select_limit_from_select_lex" ); |
| 8495 | *select_limit = 9223372036854775807LL; |
| 8496 | *offset_limit = 0; |
| 8497 | if (select_lex && select_lex->explicit_limit) |
| 8498 | { |
| 8499 | *select_limit = select_lex->select_limit ? |
| 8500 | select_lex->select_limit->val_int() : 0; |
| 8501 | *offset_limit = select_lex->offset_limit ? |
| 8502 | select_lex->offset_limit->val_int() : 0; |
| 8503 | } |
| 8504 | DBUG_VOID_RETURN; |
| 8505 | } |
| 8506 | |
| 8507 | void spider_get_select_limit( |
| 8508 | ha_spider *spider, |
| 8509 | st_select_lex **select_lex, |
| 8510 | longlong *select_limit, |
| 8511 | longlong *offset_limit |
| 8512 | ) { |
| 8513 | DBUG_ENTER("spider_get_select_limit" ); |
| 8514 | *select_lex = spider_get_select_lex(spider); |
| 8515 | spider_get_select_limit_from_select_lex( |
| 8516 | *select_lex, select_limit, offset_limit); |
| 8517 | DBUG_VOID_RETURN; |
| 8518 | } |
| 8519 | |
| 8520 | longlong spider_split_read_param( |
| 8521 | ha_spider *spider |
| 8522 | ) { |
| 8523 | SPIDER_SHARE *share = spider->share; |
| 8524 | SPIDER_RESULT_LIST *result_list = &spider->result_list; |
| 8525 | THD *thd = spider->trx->thd; |
| 8526 | st_select_lex *select_lex; |
| 8527 | longlong select_limit; |
| 8528 | longlong offset_limit; |
| 8529 | double semi_split_read; |
| 8530 | longlong split_read; |
| 8531 | DBUG_ENTER("spider_split_read_param" ); |
| 8532 | result_list->set_split_read_count = 1; |
| 8533 | #ifdef INFO_KIND_FORCE_LIMIT_BEGIN |
| 8534 | if (spider->info_limit < 9223372036854775807LL) |
| 8535 | { |
| 8536 | DBUG_PRINT("info" ,("spider info_limit=%lld" , spider->info_limit)); |
| 8537 | longlong info_limit = spider->info_limit; |
| 8538 | result_list->split_read_base = info_limit; |
| 8539 | result_list->semi_split_read = 0; |
| 8540 | result_list->first_read = info_limit; |
| 8541 | result_list->second_read = info_limit; |
| 8542 | result_list->semi_split_read_base = 0; |
| 8543 | result_list->set_split_read = FALSE; |
| 8544 | DBUG_RETURN(info_limit); |
| 8545 | } |
| 8546 | #endif |
| 8547 | if (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER) |
| 8548 | { |
| 8549 | DBUG_RETURN(result_list->semi_split_read_base); |
| 8550 | } |
| 8551 | spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit); |
| 8552 | DBUG_PRINT("info" ,("spider result_list->set_split_read=%s" , result_list->set_split_read ? "TRUE" : "FALSE" )); |
| 8553 | if (!result_list->set_split_read) |
| 8554 | { |
| 8555 | int bulk_update_mode = spider_param_bulk_update_mode(thd, |
| 8556 | share->bulk_update_mode); |
| 8557 | DBUG_PRINT("info" ,("spider sql_command=%u" , spider->sql_command)); |
| 8558 | DBUG_PRINT("info" ,("spider bulk_update_mode=%d" , bulk_update_mode)); |
| 8559 | DBUG_PRINT("info" ,("spider support_bulk_update_sql=%s" , |
| 8560 | spider->support_bulk_update_sql() ? "TRUE" : "FALSE" )); |
| 8561 | #ifdef SPIDER_HAS_GROUP_BY_HANDLER |
| 8562 | bool inserting = |
| 8563 | ( |
| 8564 | #ifdef HS_HAS_SQLCOM |
| 8565 | spider->sql_command == SQLCOM_HS_INSERT || |
| 8566 | #endif |
| 8567 | spider->sql_command == SQLCOM_INSERT || |
| 8568 | spider->sql_command == SQLCOM_INSERT_SELECT |
| 8569 | ); |
| 8570 | #endif |
| 8571 | bool updating = |
| 8572 | ( |
| 8573 | #ifdef HS_HAS_SQLCOM |
| 8574 | spider->sql_command == SQLCOM_HS_UPDATE || |
| 8575 | #endif |
| 8576 | spider->sql_command == SQLCOM_UPDATE || |
| 8577 | spider->sql_command == SQLCOM_UPDATE_MULTI |
| 8578 | ); |
| 8579 | bool deleting = |
| 8580 | ( |
| 8581 | #ifdef HS_HAS_SQLCOM |
| 8582 | spider->sql_command == SQLCOM_HS_DELETE || |
| 8583 | #endif |
| 8584 | spider->sql_command == SQLCOM_DELETE || |
| 8585 | spider->sql_command == SQLCOM_DELETE_MULTI |
| 8586 | ); |
| 8587 | bool replacing = |
| 8588 | ( |
| 8589 | spider->sql_command == SQLCOM_REPLACE || |
| 8590 | spider->sql_command == SQLCOM_REPLACE_SELECT |
| 8591 | ); |
| 8592 | DBUG_PRINT("info" ,("spider updating=%s" , updating ? "TRUE" : "FALSE" )); |
| 8593 | DBUG_PRINT("info" ,("spider deleting=%s" , deleting ? "TRUE" : "FALSE" )); |
| 8594 | DBUG_PRINT("info" ,("spider replacing=%s" , replacing ? "TRUE" : "FALSE" )); |
| 8595 | TABLE *table = spider->get_table(); |
| 8596 | if ( |
| 8597 | #ifdef SPIDER_HAS_GROUP_BY_HANDLER |
| 8598 | ( |
| 8599 | inserting && |
| 8600 | spider->use_fields |
| 8601 | ) || |
| 8602 | #endif |
| 8603 | replacing || |
| 8604 | ( |
| 8605 | ( |
| 8606 | updating || |
| 8607 | deleting |
| 8608 | ) && |
| 8609 | ( |
| 8610 | bulk_update_mode != 2 || |
| 8611 | !spider->support_bulk_update_sql() || |
| 8612 | ( |
| 8613 | updating && |
| 8614 | table->triggers && |
| 8615 | #ifdef HA_CAN_FORCE_BULK_UPDATE |
| 8616 | !(table->file->ha_table_flags() & HA_CAN_FORCE_BULK_UPDATE) && |
| 8617 | #endif |
| 8618 | table->triggers->has_triggers(TRG_EVENT_UPDATE, TRG_ACTION_AFTER) |
| 8619 | ) || |
| 8620 | ( |
| 8621 | deleting && |
| 8622 | table->triggers && |
| 8623 | #ifdef HA_CAN_FORCE_BULK_DELETE |
| 8624 | !(table->file->ha_table_flags() & HA_CAN_FORCE_BULK_DELETE) && |
| 8625 | #endif |
| 8626 | table->triggers->has_triggers(TRG_EVENT_DELETE, TRG_ACTION_AFTER) |
| 8627 | ) |
| 8628 | ) |
| 8629 | ) |
| 8630 | ) { |
| 8631 | /* This case must select by one shot */ |
| 8632 | DBUG_PRINT("info" ,("spider cancel split read" )); |
| 8633 | result_list->split_read_base = 9223372036854775807LL; |
| 8634 | result_list->semi_split_read = 0; |
| 8635 | result_list->semi_split_read_limit = 9223372036854775807LL; |
| 8636 | result_list->first_read = 9223372036854775807LL; |
| 8637 | result_list->second_read = 9223372036854775807LL; |
| 8638 | result_list->semi_split_read_base = 0; |
| 8639 | result_list->set_split_read = TRUE; |
| 8640 | DBUG_RETURN(9223372036854775807LL); |
| 8641 | } |
| 8642 | #ifdef SPIDER_HAS_EXPLAIN_QUERY |
| 8643 | Explain_query *explain = thd->lex->explain; |
| 8644 | bool filesort = FALSE; |
| 8645 | if (explain) |
| 8646 | { |
| 8647 | DBUG_PRINT("info" ,("spider explain=%p" , explain)); |
| 8648 | Explain_select *explain_select = NULL; |
| 8649 | if (select_lex) |
| 8650 | { |
| 8651 | DBUG_PRINT("info" ,("spider select_lex=%p" , select_lex)); |
| 8652 | DBUG_PRINT("info" ,("spider select_number=%u" , |
| 8653 | select_lex->select_number)); |
| 8654 | explain_select = |
| 8655 | explain->get_select(select_lex->select_number); |
| 8656 | } |
| 8657 | if (explain_select) |
| 8658 | { |
| 8659 | DBUG_PRINT("info" ,("spider explain_select=%p" , explain_select)); |
| 8660 | if (explain_select->using_filesort) |
| 8661 | { |
| 8662 | DBUG_PRINT("info" ,("spider using filesort" )); |
| 8663 | filesort = TRUE; |
| 8664 | } |
| 8665 | } |
| 8666 | } |
| 8667 | #endif |
| 8668 | result_list->split_read_base = |
| 8669 | spider_param_split_read(thd, share->split_read); |
| 8670 | #ifdef SPIDER_HAS_EXPLAIN_QUERY |
| 8671 | if (filesort) |
| 8672 | { |
| 8673 | result_list->semi_split_read = 0; |
| 8674 | result_list->semi_split_read_limit = 9223372036854775807LL; |
| 8675 | } else { |
| 8676 | #endif |
| 8677 | result_list->semi_split_read = |
| 8678 | spider_param_semi_split_read(thd, share->semi_split_read); |
| 8679 | result_list->semi_split_read_limit = |
| 8680 | spider_param_semi_split_read_limit(thd, share->semi_split_read_limit); |
| 8681 | #ifdef SPIDER_HAS_EXPLAIN_QUERY |
| 8682 | } |
| 8683 | #endif |
| 8684 | result_list->first_read = |
| 8685 | spider_param_first_read(thd, share->first_read); |
| 8686 | result_list->second_read = |
| 8687 | spider_param_second_read(thd, share->second_read); |
| 8688 | result_list->semi_split_read_base = 0; |
| 8689 | result_list->set_split_read = TRUE; |
| 8690 | } |
| 8691 | DBUG_PRINT("info" ,("spider result_list->semi_split_read=%f" , result_list->semi_split_read)); |
| 8692 | DBUG_PRINT("info" ,("spider select_lex->explicit_limit=%d" , select_lex ? select_lex->explicit_limit : 0)); |
| 8693 | DBUG_PRINT("info" ,("spider OPTION_FOUND_ROWS=%s" , select_lex && (select_lex->options & OPTION_FOUND_ROWS) ? "TRUE" : "FALSE" )); |
| 8694 | DBUG_PRINT("info" ,("spider select_lex->group_list.elements=%u" , select_lex ? select_lex->group_list.elements : 0)); |
| 8695 | DBUG_PRINT("info" ,("spider select_lex->with_sum_func=%s" , select_lex && select_lex->with_sum_func ? "TRUE" : "FALSE" )); |
| 8696 | if ( |
| 8697 | result_list->semi_split_read > 0 && |
| 8698 | select_lex && select_lex->explicit_limit && |
| 8699 | !(select_lex->options & OPTION_FOUND_ROWS) && |
| 8700 | !select_lex->group_list.elements && |
| 8701 | !select_lex->with_sum_func |
| 8702 | ) { |
| 8703 | semi_split_read = result_list->semi_split_read * |
| 8704 | (select_limit + offset_limit); |
| 8705 | DBUG_PRINT("info" ,("spider semi_split_read=%f" , semi_split_read)); |
| 8706 | if (semi_split_read >= result_list->semi_split_read_limit) |
| 8707 | { |
| 8708 | result_list->semi_split_read_base = result_list->semi_split_read_limit; |
| 8709 | DBUG_RETURN(result_list->semi_split_read_limit); |
| 8710 | } else { |
| 8711 | split_read = (longlong) semi_split_read; |
| 8712 | if (split_read < 0) |
| 8713 | { |
| 8714 | result_list->semi_split_read_base = result_list->semi_split_read_limit; |
| 8715 | DBUG_RETURN(result_list->semi_split_read_limit); |
| 8716 | } else if (split_read == 0) |
| 8717 | { |
| 8718 | result_list->semi_split_read_base = 1; |
| 8719 | DBUG_RETURN(1); |
| 8720 | } else { |
| 8721 | result_list->semi_split_read_base = split_read; |
| 8722 | DBUG_RETURN(split_read); |
| 8723 | } |
| 8724 | } |
| 8725 | } else if (result_list->first_read > 0) |
| 8726 | DBUG_RETURN(result_list->first_read); |
| 8727 | DBUG_RETURN(result_list->split_read_base); |
| 8728 | } |
| 8729 | |
| 8730 | longlong spider_bg_split_read_param( |
| 8731 | ha_spider *spider |
| 8732 | ) { |
| 8733 | SPIDER_RESULT_LIST *result_list = &spider->result_list; |
| 8734 | DBUG_ENTER("spider_bg_split_read_param" ); |
| 8735 | if (result_list->semi_split_read_base) |
| 8736 | DBUG_RETURN(result_list->semi_split_read_base); |
| 8737 | DBUG_RETURN(result_list->split_read_base); |
| 8738 | } |
| 8739 | |
| 8740 | void spider_first_split_read_param( |
| 8741 | ha_spider *spider |
| 8742 | ) { |
| 8743 | SPIDER_RESULT_LIST *result_list = &spider->result_list; |
| 8744 | DBUG_ENTER("spider_first_split_read_param" ); |
| 8745 | if (result_list->semi_split_read_base) |
| 8746 | result_list->split_read = result_list->semi_split_read_base; |
| 8747 | else if (result_list->second_read > 0) |
| 8748 | result_list->split_read = result_list->first_read; |
| 8749 | else |
| 8750 | result_list->split_read = result_list->split_read_base; |
| 8751 | result_list->set_split_read_count = 1; |
| 8752 | DBUG_VOID_RETURN; |
| 8753 | } |
| 8754 | |
| 8755 | void spider_next_split_read_param( |
| 8756 | ha_spider *spider |
| 8757 | ) { |
| 8758 | SPIDER_RESULT_LIST *result_list = &spider->result_list; |
| 8759 | DBUG_ENTER("spider_next_split_read_param" ); |
| 8760 | if (result_list->semi_split_read_base) |
| 8761 | result_list->split_read = result_list->semi_split_read_base; |
| 8762 | else if ( |
| 8763 | result_list->set_split_read_count == 1 && |
| 8764 | result_list->second_read > 0 |
| 8765 | ) |
| 8766 | result_list->split_read = result_list->second_read; |
| 8767 | else |
| 8768 | result_list->split_read = result_list->split_read_base; |
| 8769 | result_list->set_split_read_count++; |
| 8770 | DBUG_VOID_RETURN; |
| 8771 | } |
| 8772 | |
| 8773 | bool spider_check_direct_order_limit( |
| 8774 | ha_spider *spider |
| 8775 | ) { |
| 8776 | THD *thd = spider->trx->thd; |
| 8777 | SPIDER_SHARE *share = spider->share; |
| 8778 | st_select_lex *select_lex; |
| 8779 | longlong select_limit; |
| 8780 | longlong offset_limit; |
| 8781 | DBUG_ENTER("spider_check_direct_order_limit" ); |
| 8782 | if (spider_check_index_merge(spider->get_top_table(), |
| 8783 | spider_get_select_lex(spider))) |
| 8784 | { |
| 8785 | DBUG_PRINT("info" ,("spider set use_index_merge" )); |
| 8786 | spider->use_index_merge = TRUE; |
| 8787 | } |
| 8788 | DBUG_PRINT("info" ,("spider SQLCOM_HA_READ=%s" , |
| 8789 | (spider->sql_command == SQLCOM_HA_READ) ? "TRUE" : "FALSE" )); |
| 8790 | DBUG_PRINT("info" ,("spider sql_kinds with SPIDER_SQL_KIND_HANDLER=%s" , |
| 8791 | (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER) ? "TRUE" : "FALSE" )); |
| 8792 | DBUG_PRINT("info" ,("spider use_index_merge=%s" , |
| 8793 | spider->use_index_merge ? "TRUE" : "FALSE" )); |
| 8794 | DBUG_PRINT("info" ,("spider is_clone=%s" , |
| 8795 | spider->is_clone ? "TRUE" : "FALSE" )); |
| 8796 | #ifdef HA_CAN_BULK_ACCESS |
| 8797 | DBUG_PRINT("info" ,("spider is_bulk_access_clone=%s" , |
| 8798 | spider->is_bulk_access_clone ? "TRUE" : "FALSE" )); |
| 8799 | #endif |
| 8800 | if ( |
| 8801 | spider->sql_command != SQLCOM_HA_READ && |
| 8802 | !spider->use_index_merge && |
| 8803 | #ifdef HA_CAN_BULK_ACCESS |
| 8804 | (!spider->is_clone || spider->is_bulk_access_clone) |
| 8805 | #else |
| 8806 | !spider->is_clone |
| 8807 | #endif |
| 8808 | ) { |
| 8809 | spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit); |
| 8810 | bool first_check = TRUE; |
| 8811 | DBUG_PRINT("info" ,("spider select_lex=%p" , select_lex)); |
| 8812 | #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 |
| 8813 | DBUG_PRINT("info" ,("spider leaf_tables.elements=%u" , |
| 8814 | select_lex ? select_lex->leaf_tables.elements : 0)); |
| 8815 | #endif |
| 8816 | |
| 8817 | if (select_lex && (select_lex->options & SELECT_DISTINCT)) |
| 8818 | { |
| 8819 | DBUG_PRINT("info" ,("spider with distinct" )); |
| 8820 | spider->result_list.direct_distinct = TRUE; |
| 8821 | } |
| 8822 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
| 8823 | spider->result_list.direct_aggregate = TRUE; |
| 8824 | #endif |
| 8825 | DBUG_PRINT("info" ,("spider select_limit=%lld" , select_limit)); |
| 8826 | DBUG_PRINT("info" ,("spider offset_limit=%lld" , offset_limit)); |
| 8827 | if ( |
| 8828 | #if MYSQL_VERSION_ID < 50500 |
| 8829 | !thd->variables.engine_condition_pushdown || |
| 8830 | #else |
| 8831 | #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON |
| 8832 | #else |
| 8833 | !(thd->variables.optimizer_switch & |
| 8834 | OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || |
| 8835 | #endif |
| 8836 | #endif |
| 8837 | #ifdef SPIDER_NEED_CHECK_CONDITION_AT_CHECKING_DIRECT_ORDER_LIMIT |
| 8838 | !spider->condition || |
| 8839 | #endif |
| 8840 | !select_lex || |
| 8841 | #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 |
| 8842 | select_lex->leaf_tables.elements != 1 || |
| 8843 | #endif |
| 8844 | select_lex->table_list.elements != 1 |
| 8845 | ) { |
| 8846 | DBUG_PRINT("info" ,("spider first_check is FALSE" )); |
| 8847 | first_check = FALSE; |
| 8848 | spider->result_list.direct_distinct = FALSE; |
| 8849 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
| 8850 | spider->result_list.direct_aggregate = FALSE; |
| 8851 | #endif |
| 8852 | } else if (spider_db_append_condition(spider, NULL, 0, TRUE)) |
| 8853 | { |
| 8854 | DBUG_PRINT("info" ,("spider FALSE by condition" )); |
| 8855 | first_check = FALSE; |
| 8856 | spider->result_list.direct_distinct = FALSE; |
| 8857 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
| 8858 | spider->result_list.direct_aggregate = FALSE; |
| 8859 | #endif |
| 8860 | } else if (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER) |
| 8861 | { |
| 8862 | DBUG_PRINT("info" ,("spider sql_kinds with SPIDER_SQL_KIND_HANDLER" )); |
| 8863 | spider->result_list.direct_distinct = FALSE; |
| 8864 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
| 8865 | spider->result_list.direct_aggregate = FALSE; |
| 8866 | } else if ( |
| 8867 | !select_lex->group_list.elements && |
| 8868 | !select_lex->with_sum_func |
| 8869 | ) { |
| 8870 | DBUG_PRINT("info" ,("spider this SQL is not aggregate SQL" )); |
| 8871 | spider->result_list.direct_aggregate = FALSE; |
| 8872 | } else { |
| 8873 | ORDER *group; |
| 8874 | for (group = (ORDER *) select_lex->group_list.first; group; |
| 8875 | group = group->next) |
| 8876 | { |
| 8877 | if (spider->print_item_type((*group->item), NULL, NULL, 0)) |
| 8878 | { |
| 8879 | DBUG_PRINT("info" ,("spider aggregate FALSE by group" )); |
| 8880 | spider->result_list.direct_aggregate = FALSE; |
| 8881 | break; |
| 8882 | } |
| 8883 | } |
| 8884 | JOIN *join = select_lex->join; |
| 8885 | Item_sum **item_sum_ptr; |
| 8886 | for (item_sum_ptr = join->sum_funcs; *item_sum_ptr; ++item_sum_ptr) |
| 8887 | { |
| 8888 | if (spider->print_item_type(*item_sum_ptr, NULL, NULL, 0)) |
| 8889 | { |
| 8890 | DBUG_PRINT("info" ,("spider aggregate FALSE by not supported" )); |
| 8891 | spider->result_list.direct_aggregate = FALSE; |
| 8892 | break; |
| 8893 | } |
| 8894 | } |
| 8895 | #endif |
| 8896 | } |
| 8897 | |
| 8898 | longlong direct_order_limit = spider_param_direct_order_limit(thd, |
| 8899 | share->direct_order_limit); |
| 8900 | DBUG_PRINT("info" ,("spider direct_order_limit=%lld" , direct_order_limit)); |
| 8901 | if (direct_order_limit) |
| 8902 | { |
| 8903 | DBUG_PRINT("info" ,("spider first_check=%s" , |
| 8904 | first_check ? "TRUE" : "FALSE" )); |
| 8905 | DBUG_PRINT("info" ,("spider (select_lex->options & OPTION_FOUND_ROWS)=%s" , |
| 8906 | select_lex && (select_lex->options & OPTION_FOUND_ROWS) ? "TRUE" : "FALSE" )); |
| 8907 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
| 8908 | DBUG_PRINT("info" ,("spider direct_aggregate=%s" , |
| 8909 | spider->result_list.direct_aggregate ? "TRUE" : "FALSE" )); |
| 8910 | #endif |
| 8911 | DBUG_PRINT("info" ,("spider select_lex->group_list.elements=%u" , |
| 8912 | select_lex ? select_lex->group_list.elements : 0)); |
| 8913 | DBUG_PRINT("info" ,("spider select_lex->with_sum_func=%s" , |
| 8914 | select_lex && select_lex->with_sum_func ? "TRUE" : "FALSE" )); |
| 8915 | DBUG_PRINT("info" ,("spider select_lex->having=%s" , |
| 8916 | select_lex && select_lex->having ? "TRUE" : "FALSE" )); |
| 8917 | DBUG_PRINT("info" ,("spider select_lex->order_list.elements=%u" , |
| 8918 | select_lex ? select_lex->order_list.elements : 0)); |
| 8919 | if ( |
| 8920 | !first_check || |
| 8921 | !select_lex->explicit_limit || |
| 8922 | (select_lex->options & OPTION_FOUND_ROWS) || |
| 8923 | ( |
| 8924 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
| 8925 | !spider->result_list.direct_aggregate && |
| 8926 | #endif |
| 8927 | ( |
| 8928 | select_lex->group_list.elements || |
| 8929 | select_lex->with_sum_func |
| 8930 | ) |
| 8931 | ) || |
| 8932 | select_lex->having || |
| 8933 | !select_lex->order_list.elements || |
| 8934 | select_limit > direct_order_limit - offset_limit |
| 8935 | ) { |
| 8936 | DBUG_PRINT("info" ,("spider FALSE by select_lex" )); |
| 8937 | DBUG_RETURN(FALSE); |
| 8938 | } |
| 8939 | ORDER *order; |
| 8940 | for (order = (ORDER *) select_lex->order_list.first; order; |
| 8941 | order = order->next) |
| 8942 | { |
| 8943 | if (spider->print_item_type((*order->item), NULL, NULL, 0)) |
| 8944 | { |
| 8945 | DBUG_PRINT("info" ,("spider FALSE by order" )); |
| 8946 | DBUG_RETURN(FALSE); |
| 8947 | } |
| 8948 | } |
| 8949 | DBUG_PRINT("info" ,("spider TRUE" )); |
| 8950 | spider->result_list.internal_limit = select_limit + offset_limit; |
| 8951 | spider->result_list.split_read = select_limit + offset_limit; |
| 8952 | spider->trx->direct_order_limit_count++; |
| 8953 | DBUG_RETURN(TRUE); |
| 8954 | } |
| 8955 | } |
| 8956 | DBUG_PRINT("info" ,("spider FALSE by parameter" )); |
| 8957 | DBUG_RETURN(FALSE); |
| 8958 | } |
| 8959 | |
| 8960 | int spider_set_direct_limit_offset( |
| 8961 | ha_spider *spider |
| 8962 | ) { |
| 8963 | THD *thd = spider->trx->thd; |
| 8964 | st_select_lex *select_lex; |
| 8965 | longlong select_limit; |
| 8966 | longlong offset_limit; |
| 8967 | TABLE_LIST *table_list; |
| 8968 | DBUG_ENTER("spider_set_direct_limit_offset" ); |
| 8969 | |
| 8970 | if (spider->result_list.direct_limit_offset) |
| 8971 | DBUG_RETURN(TRUE); |
| 8972 | |
| 8973 | if ( |
| 8974 | spider->pt_handler_share_creator && |
| 8975 | spider->pt_handler_share_creator != spider |
| 8976 | ) { |
| 8977 | if (spider->pt_handler_share_creator->result_list.direct_limit_offset == TRUE) |
| 8978 | { |
| 8979 | spider->result_list.direct_limit_offset = TRUE; |
| 8980 | DBUG_RETURN(TRUE); |
| 8981 | } else { |
| 8982 | DBUG_RETURN(FALSE); |
| 8983 | } |
| 8984 | } |
| 8985 | |
| 8986 | if ( |
| 8987 | spider->sql_command != SQLCOM_SELECT || |
| 8988 | #ifdef HANDLER_HAS_DIRECT_AGGREGATE |
| 8989 | spider->result_list.direct_aggregate || |
| 8990 | #endif |
| 8991 | spider->result_list.direct_order_limit || |
| 8992 | spider->prev_index_rnd_init != SPD_RND // must be RND_INIT and not be INDEX_INIT |
| 8993 | ) |
| 8994 | DBUG_RETURN(FALSE); |
| 8995 | |
| 8996 | spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit); |
| 8997 | |
| 8998 | // limit and offset is non-zero |
| 8999 | if (!(select_limit && offset_limit)) |
| 9000 | DBUG_RETURN(FALSE); |
| 9001 | |
| 9002 | // more than one table |
| 9003 | if ( |
| 9004 | !select_lex || |
| 9005 | select_lex->table_list.elements != 1 |
| 9006 | ) |
| 9007 | DBUG_RETURN(FALSE); |
| 9008 | |
| 9009 | table_list = (TABLE_LIST *) select_lex->table_list.first; |
| 9010 | if (table_list->table->file->partition_ht() != spider_hton_ptr) |
| 9011 | { |
| 9012 | DBUG_PRINT("info" ,("spider ht1=%u ht2=%u" , |
| 9013 | table_list->table->file->partition_ht()->slot, |
| 9014 | spider_hton_ptr->slot |
| 9015 | )); |
| 9016 | DBUG_RETURN(FALSE); |
| 9017 | } |
| 9018 | |
| 9019 | // contain where |
| 9020 | if ( |
| 9021 | #if MYSQL_VERSION_ID < 50500 |
| 9022 | !thd->variables.engine_condition_pushdown || |
| 9023 | #else |
| 9024 | #ifdef SPIDER_ENGINE_CONDITION_PUSHDOWN_IS_ALWAYS_ON |
| 9025 | #else |
| 9026 | !(thd->variables.optimizer_switch & |
| 9027 | OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN) || |
| 9028 | #endif |
| 9029 | #endif |
| 9030 | spider->condition // conditions is null may be no where condition in rand_init |
| 9031 | ) |
| 9032 | DBUG_RETURN(FALSE); |
| 9033 | |
| 9034 | // ignore condition like 1=1 |
| 9035 | if (select_lex->where && select_lex->where->with_subquery()) |
| 9036 | DBUG_RETURN(FALSE); |
| 9037 | |
| 9038 | if ( |
| 9039 | select_lex->group_list.elements || |
| 9040 | select_lex->with_sum_func || |
| 9041 | select_lex->having || |
| 9042 | select_lex->order_list.elements |
| 9043 | ) |
| 9044 | DBUG_RETURN(FALSE); |
| 9045 | |
| 9046 | // must not be derived table |
| 9047 | if (&thd->lex->select_lex != select_lex) |
| 9048 | DBUG_RETURN(FALSE); |
| 9049 | |
| 9050 | spider->direct_select_offset = offset_limit; |
| 9051 | spider->direct_current_offset = offset_limit; |
| 9052 | spider->direct_select_limit = select_limit; |
| 9053 | spider->result_list.direct_limit_offset = TRUE; |
| 9054 | DBUG_RETURN(TRUE); |
| 9055 | } |
| 9056 | |
| 9057 | |
| 9058 | bool spider_check_index_merge( |
| 9059 | TABLE *table, |
| 9060 | st_select_lex *select_lex |
| 9061 | ) { |
| 9062 | uint roop_count; |
| 9063 | JOIN *join; |
| 9064 | DBUG_ENTER("spider_check_index_merge" ); |
| 9065 | if (!select_lex) |
| 9066 | { |
| 9067 | DBUG_PRINT("info" ,("spider select_lex is null" )); |
| 9068 | DBUG_RETURN(FALSE); |
| 9069 | } |
| 9070 | join = select_lex->join; |
| 9071 | if (!join) |
| 9072 | { |
| 9073 | DBUG_PRINT("info" ,("spider join is null" )); |
| 9074 | DBUG_RETURN(FALSE); |
| 9075 | } |
| 9076 | if (!join->join_tab) |
| 9077 | { |
| 9078 | DBUG_PRINT("info" ,("spider join->join_tab is null" )); |
| 9079 | DBUG_RETURN(FALSE); |
| 9080 | } |
| 9081 | for (roop_count = 0; roop_count < spider_join_table_count(join); ++roop_count) |
| 9082 | { |
| 9083 | JOIN_TAB *join_tab = &join->join_tab[roop_count]; |
| 9084 | if (join_tab->table == table) |
| 9085 | { |
| 9086 | DBUG_PRINT("info" ,("spider join_tab->type=%u" , join_tab->type)); |
| 9087 | if ( |
| 9088 | #ifdef SPIDER_HAS_JT_HASH_INDEX_MERGE |
| 9089 | join_tab->type == JT_HASH_INDEX_MERGE || |
| 9090 | #endif |
| 9091 | join_tab->type == JT_INDEX_MERGE |
| 9092 | ) { |
| 9093 | DBUG_RETURN(TRUE); |
| 9094 | } |
| 9095 | /* |
| 9096 | DBUG_PRINT("info",("spider join_tab->quick->get_type()=%u", |
| 9097 | join_tab->quick ? join_tab->quick->get_type() : 0)); |
| 9098 | if ( |
| 9099 | join_tab->quick && |
| 9100 | join_tab->quick->get_type() == QUICK_SELECT_I::QS_TYPE_INDEX_MERGE |
| 9101 | ) { |
| 9102 | DBUG_RETURN(TRUE); |
| 9103 | } |
| 9104 | */ |
| 9105 | DBUG_PRINT("info" ,("spider join_tab->select->quick->get_type()=%u" , |
| 9106 | join_tab->select && join_tab->select->quick ? join_tab->select->quick->get_type() : 0)); |
| 9107 | if ( |
| 9108 | join_tab->select && |
| 9109 | join_tab->select->quick && |
| 9110 | join_tab->select->quick->get_type() == QUICK_SELECT_I::QS_TYPE_INDEX_MERGE |
| 9111 | ) { |
| 9112 | DBUG_RETURN(TRUE); |
| 9113 | } |
| 9114 | break; |
| 9115 | } |
| 9116 | } |
| 9117 | DBUG_RETURN(FALSE); |
| 9118 | } |
| 9119 | |
| 9120 | int spider_compare_for_sort( |
| 9121 | SPIDER_SORT *a, |
| 9122 | SPIDER_SORT *b |
| 9123 | ) { |
| 9124 | DBUG_ENTER("spider_compare_for_sort" ); |
| 9125 | if (a->sort > b->sort) |
| 9126 | DBUG_RETURN(-1); |
| 9127 | if (a->sort < b->sort) |
| 9128 | DBUG_RETURN(1); |
| 9129 | DBUG_RETURN(0); |
| 9130 | } |
| 9131 | |
| 9132 | ulong spider_calc_for_sort( |
| 9133 | uint count, |
| 9134 | ... |
| 9135 | ) { |
| 9136 | ulong sort = 0; |
| 9137 | va_list args; |
| 9138 | va_start(args, count); |
| 9139 | DBUG_ENTER("spider_calc_for_sort" ); |
| 9140 | while (count--) |
| 9141 | { |
| 9142 | char *start = va_arg(args, char *), *str; |
| 9143 | uint wild_pos = 0; |
| 9144 | |
| 9145 | if ((str = start)) |
| 9146 | { |
| 9147 | wild_pos = 128; |
| 9148 | for (; *str; str++) |
| 9149 | { |
| 9150 | if (*str == spider_wild_prefix && str[1]) |
| 9151 | str++; |
| 9152 | else if (*str == spider_wild_many || *str == spider_wild_one) |
| 9153 | { |
| 9154 | wild_pos = (uint) (str - start) + 1; |
| 9155 | if (wild_pos > 127) |
| 9156 | wild_pos = 127; |
| 9157 | break; |
| 9158 | } |
| 9159 | } |
| 9160 | } |
| 9161 | sort = (sort << 8) + wild_pos; |
| 9162 | } |
| 9163 | va_end(args); |
| 9164 | DBUG_RETURN(sort); |
| 9165 | } |
| 9166 | |
| 9167 | double spider_rand( |
| 9168 | uint32 rand_source |
| 9169 | ) { |
| 9170 | #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 |
| 9171 | struct my_rnd_struct rand; |
| 9172 | #else |
| 9173 | struct rand_struct rand; |
| 9174 | #endif |
| 9175 | DBUG_ENTER("spider_rand" ); |
| 9176 | /* generate same as rand function for applications */ |
| 9177 | #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 |
| 9178 | my_rnd_init(&rand, (uint32) (rand_source * 65537L + 55555555L), |
| 9179 | (uint32) (rand_source * 268435457L)); |
| 9180 | #else |
| 9181 | randominit(&rand, (uint32) (rand_source * 65537L + 55555555L), |
| 9182 | (uint32) (rand_source * 268435457L)); |
| 9183 | #endif |
| 9184 | DBUG_RETURN(my_rnd(&rand)); |
| 9185 | } |
| 9186 | |
| 9187 | #ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE |
| 9188 | int spider_discover_table_structure_internal( |
| 9189 | SPIDER_TRX *trx, |
| 9190 | SPIDER_SHARE *spider_share, |
| 9191 | spider_string *str |
| 9192 | ) { |
| 9193 | int error_num = 0, roop_count; |
| 9194 | DBUG_ENTER("spider_discover_table_structure_internal" ); |
| 9195 | for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++) |
| 9196 | { |
| 9197 | if (spider_bit_is_set(spider_share->dbton_bitmap, roop_count)) |
| 9198 | { |
| 9199 | if ((error_num = spider_share->dbton_share[roop_count]-> |
| 9200 | discover_table_structure(trx, spider_share, str))) |
| 9201 | { |
| 9202 | continue; |
| 9203 | } |
| 9204 | break; |
| 9205 | } |
| 9206 | } |
| 9207 | DBUG_RETURN(error_num); |
| 9208 | } |
| 9209 | |
| 9210 | int spider_discover_table_structure( |
| 9211 | handlerton *hton, |
| 9212 | THD* thd, |
| 9213 | TABLE_SHARE *share, |
| 9214 | HA_CREATE_INFO *info |
| 9215 | ) { |
| 9216 | int error_num = HA_ERR_WRONG_COMMAND, dummy; |
| 9217 | SPIDER_SHARE *spider_share; |
| 9218 | const char *table_name = share->path.str; |
| 9219 | uint table_name_length = (uint) strlen(table_name); |
| 9220 | SPIDER_TRX *trx; |
| 9221 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 9222 | partition_info *part_info = thd->work_part_info; |
| 9223 | #endif |
| 9224 | Open_tables_backup open_tables_backup; |
| 9225 | TABLE *table_tables; |
| 9226 | uint str_len; |
| 9227 | char buf[MAX_FIELD_WIDTH]; |
| 9228 | spider_string str(buf, sizeof(buf), system_charset_info); |
| 9229 | DBUG_ENTER("spider_discover_table_structure" ); |
| 9230 | str.init_calc_mem(229); |
| 9231 | str.length(0); |
| 9232 | if (str.reserve( |
| 9233 | SPIDER_SQL_CREATE_TABLE_LEN + share->db.length + |
| 9234 | SPIDER_SQL_DOT_LEN + share->table_name.length + |
| 9235 | /* SPIDER_SQL_LCL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_OPEN_PAREN_LEN |
| 9236 | )) { |
| 9237 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 9238 | } |
| 9239 | str.q_append(SPIDER_SQL_CREATE_TABLE_STR, SPIDER_SQL_CREATE_TABLE_LEN); |
| 9240 | str.q_append(SPIDER_SQL_LCL_NAME_QUOTE_STR, SPIDER_SQL_LCL_NAME_QUOTE_LEN); |
| 9241 | str.q_append(share->db.str, share->db.length); |
| 9242 | str.q_append(SPIDER_SQL_LCL_NAME_QUOTE_STR, SPIDER_SQL_LCL_NAME_QUOTE_LEN); |
| 9243 | str.q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN); |
| 9244 | str.q_append(SPIDER_SQL_LCL_NAME_QUOTE_STR, SPIDER_SQL_LCL_NAME_QUOTE_LEN); |
| 9245 | str.q_append(share->table_name.str, share->table_name.length); |
| 9246 | str.q_append(SPIDER_SQL_LCL_NAME_QUOTE_STR, SPIDER_SQL_LCL_NAME_QUOTE_LEN); |
| 9247 | str.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN); |
| 9248 | str_len = str.length(); |
| 9249 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 9250 | my_hash_value_type hash_value = my_calc_hash(&spider_open_tables, |
| 9251 | (uchar*) table_name, table_name_length); |
| 9252 | #endif |
| 9253 | if (!(trx = spider_get_trx(thd, TRUE, &error_num))) |
| 9254 | { |
| 9255 | DBUG_PRINT("info" ,("spider spider_get_trx error" )); |
| 9256 | my_error(error_num, MYF(0)); |
| 9257 | DBUG_RETURN(error_num); |
| 9258 | } |
| 9259 | share->table_charset = info->default_table_charset; |
| 9260 | share->comment = info->comment; |
| 9261 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 9262 | if (!part_info) |
| 9263 | { |
| 9264 | #endif |
| 9265 | if (!(spider_share = spider_create_share(table_name, share, |
| 9266 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 9267 | NULL, |
| 9268 | #endif |
| 9269 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 9270 | hash_value, |
| 9271 | #endif |
| 9272 | &error_num |
| 9273 | ))) { |
| 9274 | DBUG_RETURN(error_num); |
| 9275 | } |
| 9276 | |
| 9277 | error_num = spider_discover_table_structure_internal(trx, spider_share, &str); |
| 9278 | |
| 9279 | if (!error_num) |
| 9280 | { |
| 9281 | if ( |
| 9282 | (table_tables = spider_open_sys_table( |
| 9283 | thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, |
| 9284 | SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, FALSE, |
| 9285 | &error_num)) |
| 9286 | ) { |
| 9287 | #ifdef SPIDER_SUPPORT_CREATE_OR_REPLACE_TABLE |
| 9288 | if (thd->lex->create_info.or_replace()) |
| 9289 | { |
| 9290 | error_num = spider_delete_tables(table_tables, |
| 9291 | spider_share->table_name, &dummy); |
| 9292 | } |
| 9293 | if (!error_num) |
| 9294 | { |
| 9295 | #endif |
| 9296 | error_num = spider_insert_tables(table_tables, spider_share); |
| 9297 | #ifdef SPIDER_SUPPORT_CREATE_OR_REPLACE_TABLE |
| 9298 | } |
| 9299 | #endif |
| 9300 | spider_close_sys_table(thd, table_tables, |
| 9301 | &open_tables_backup, FALSE); |
| 9302 | } |
| 9303 | } |
| 9304 | |
| 9305 | spider_free_share_resource_only(spider_share); |
| 9306 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 9307 | } else { |
| 9308 | char tmp_name[FN_REFLEN + 1]; |
| 9309 | List_iterator<partition_element> part_it(part_info->partitions); |
| 9310 | List_iterator<partition_element> part_it2(part_info->partitions); |
| 9311 | partition_element *part_elem, *sub_elem; |
| 9312 | while ((part_elem = part_it++)) |
| 9313 | { |
| 9314 | if ((part_elem)->subpartitions.elements) |
| 9315 | { |
| 9316 | List_iterator<partition_element> sub_it((part_elem)->subpartitions); |
| 9317 | while ((sub_elem = sub_it++)) |
| 9318 | { |
| 9319 | str.length(str_len); |
| 9320 | if ((error_num = SPIDER_create_subpartition_name( |
| 9321 | tmp_name, FN_REFLEN + 1, table_name, |
| 9322 | (part_elem)->partition_name, (sub_elem)->partition_name, |
| 9323 | NORMAL_PART_NAME))) |
| 9324 | { |
| 9325 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 9326 | } |
| 9327 | DBUG_PRINT("info" ,("spider tmp_name=%s" , tmp_name)); |
| 9328 | if (!(spider_share = spider_create_share(tmp_name, share, |
| 9329 | part_info, |
| 9330 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 9331 | hash_value, |
| 9332 | #endif |
| 9333 | &error_num |
| 9334 | ))) { |
| 9335 | DBUG_RETURN(error_num); |
| 9336 | } |
| 9337 | |
| 9338 | error_num = spider_discover_table_structure_internal( |
| 9339 | trx, spider_share, &str); |
| 9340 | |
| 9341 | spider_free_share_resource_only(spider_share); |
| 9342 | if (!error_num) |
| 9343 | break; |
| 9344 | } |
| 9345 | if (!error_num) |
| 9346 | break; |
| 9347 | } else { |
| 9348 | str.length(str_len); |
| 9349 | if ((error_num = SPIDER_create_partition_name( |
| 9350 | tmp_name, FN_REFLEN + 1, table_name, |
| 9351 | (part_elem)->partition_name, NORMAL_PART_NAME, TRUE))) |
| 9352 | { |
| 9353 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 9354 | } |
| 9355 | DBUG_PRINT("info" ,("spider tmp_name=%s" , tmp_name)); |
| 9356 | if (!(spider_share = spider_create_share(tmp_name, share, |
| 9357 | part_info, |
| 9358 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 9359 | hash_value, |
| 9360 | #endif |
| 9361 | &error_num |
| 9362 | ))) { |
| 9363 | DBUG_RETURN(error_num); |
| 9364 | } |
| 9365 | |
| 9366 | error_num = spider_discover_table_structure_internal( |
| 9367 | trx, spider_share, &str); |
| 9368 | |
| 9369 | spider_free_share_resource_only(spider_share); |
| 9370 | if (!error_num) |
| 9371 | break; |
| 9372 | } |
| 9373 | } |
| 9374 | if (!error_num) |
| 9375 | { |
| 9376 | if ( |
| 9377 | !(table_tables = spider_open_sys_table( |
| 9378 | thd, SPIDER_SYS_TABLES_TABLE_NAME_STR, |
| 9379 | SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, FALSE, |
| 9380 | &error_num)) |
| 9381 | ) { |
| 9382 | DBUG_RETURN(error_num); |
| 9383 | } |
| 9384 | while ((part_elem = part_it2++)) |
| 9385 | { |
| 9386 | if ((part_elem)->subpartitions.elements) |
| 9387 | { |
| 9388 | List_iterator<partition_element> sub_it((part_elem)->subpartitions); |
| 9389 | while ((sub_elem = sub_it++)) |
| 9390 | { |
| 9391 | if ((error_num = SPIDER_create_subpartition_name( |
| 9392 | tmp_name, FN_REFLEN + 1, table_name, |
| 9393 | (part_elem)->partition_name, (sub_elem)->partition_name, |
| 9394 | NORMAL_PART_NAME))) |
| 9395 | { |
| 9396 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 9397 | } |
| 9398 | DBUG_PRINT("info" ,("spider tmp_name=%s" , tmp_name)); |
| 9399 | if (!(spider_share = spider_create_share(tmp_name, share, |
| 9400 | part_info, |
| 9401 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 9402 | hash_value, |
| 9403 | #endif |
| 9404 | &error_num |
| 9405 | ))) { |
| 9406 | DBUG_RETURN(error_num); |
| 9407 | } |
| 9408 | |
| 9409 | #ifdef SPIDER_SUPPORT_CREATE_OR_REPLACE_TABLE |
| 9410 | if (thd->lex->create_info.or_replace()) |
| 9411 | { |
| 9412 | error_num = spider_delete_tables(table_tables, |
| 9413 | spider_share->table_name, &dummy); |
| 9414 | } |
| 9415 | if (!error_num) |
| 9416 | { |
| 9417 | #endif |
| 9418 | error_num = spider_insert_tables(table_tables, spider_share); |
| 9419 | #ifdef SPIDER_SUPPORT_CREATE_OR_REPLACE_TABLE |
| 9420 | } |
| 9421 | #endif |
| 9422 | |
| 9423 | spider_free_share_resource_only(spider_share); |
| 9424 | if (error_num) |
| 9425 | break; |
| 9426 | } |
| 9427 | if (error_num) |
| 9428 | break; |
| 9429 | } else { |
| 9430 | if ((error_num = SPIDER_create_partition_name( |
| 9431 | tmp_name, FN_REFLEN + 1, table_name, |
| 9432 | (part_elem)->partition_name, NORMAL_PART_NAME, TRUE))) |
| 9433 | { |
| 9434 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 9435 | } |
| 9436 | DBUG_PRINT("info" ,("spider tmp_name=%s" , tmp_name)); |
| 9437 | if (!(spider_share = spider_create_share(tmp_name, share, |
| 9438 | part_info, |
| 9439 | #ifdef SPIDER_HAS_HASH_VALUE_TYPE |
| 9440 | hash_value, |
| 9441 | #endif |
| 9442 | &error_num |
| 9443 | ))) { |
| 9444 | DBUG_RETURN(error_num); |
| 9445 | } |
| 9446 | |
| 9447 | #ifdef SPIDER_SUPPORT_CREATE_OR_REPLACE_TABLE |
| 9448 | if (thd->lex->create_info.or_replace()) |
| 9449 | { |
| 9450 | error_num = spider_delete_tables(table_tables, |
| 9451 | spider_share->table_name, &dummy); |
| 9452 | } |
| 9453 | if (!error_num) |
| 9454 | { |
| 9455 | #endif |
| 9456 | error_num = spider_insert_tables(table_tables, spider_share); |
| 9457 | #ifdef SPIDER_SUPPORT_CREATE_OR_REPLACE_TABLE |
| 9458 | } |
| 9459 | #endif |
| 9460 | |
| 9461 | spider_free_share_resource_only(spider_share); |
| 9462 | if (error_num) |
| 9463 | break; |
| 9464 | } |
| 9465 | } |
| 9466 | spider_close_sys_table(thd, table_tables, |
| 9467 | &open_tables_backup, FALSE); |
| 9468 | } |
| 9469 | } |
| 9470 | #endif |
| 9471 | |
| 9472 | if (!error_num) |
| 9473 | thd->clear_error(); |
| 9474 | else |
| 9475 | DBUG_RETURN(error_num); |
| 9476 | |
| 9477 | str.length(str.length() - SPIDER_SQL_COMMA_LEN); |
| 9478 | CHARSET_INFO *table_charset; |
| 9479 | if (share->table_charset) |
| 9480 | { |
| 9481 | table_charset = share->table_charset; |
| 9482 | } else { |
| 9483 | table_charset = system_charset_info; |
| 9484 | } |
| 9485 | uint csnamelen = strlen(table_charset->csname); |
| 9486 | uint collatelen = strlen(table_charset->name); |
| 9487 | if (str.reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_DEFAULT_CHARSET_LEN + |
| 9488 | csnamelen + SPIDER_SQL_COLLATE_LEN + collatelen + |
| 9489 | SPIDER_SQL_CONNECTION_LEN + SPIDER_SQL_VALUE_QUOTE_LEN |
| 9490 | )) { |
| 9491 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 9492 | } |
| 9493 | str.q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN); |
| 9494 | str.q_append(SPIDER_SQL_DEFAULT_CHARSET_STR, SPIDER_SQL_DEFAULT_CHARSET_LEN); |
| 9495 | str.q_append(table_charset->csname, csnamelen); |
| 9496 | str.q_append(SPIDER_SQL_COLLATE_STR, SPIDER_SQL_COLLATE_LEN); |
| 9497 | str.q_append(table_charset->name, collatelen); |
| 9498 | str.q_append(SPIDER_SQL_COMMENT_STR, SPIDER_SQL_COMMENT_LEN); |
| 9499 | str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
| 9500 | str.append_escape_string(share->comment.str, share->comment.length); |
| 9501 | if (str.reserve(SPIDER_SQL_CONNECTION_LEN + |
| 9502 | (SPIDER_SQL_VALUE_QUOTE_LEN * 2))) |
| 9503 | { |
| 9504 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 9505 | } |
| 9506 | str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
| 9507 | str.q_append(SPIDER_SQL_CONNECTION_STR, SPIDER_SQL_CONNECTION_LEN); |
| 9508 | str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
| 9509 | str.append_escape_string(share->connect_string.str, |
| 9510 | share->connect_string.length); |
| 9511 | if (str.reserve(SPIDER_SQL_VALUE_QUOTE_LEN)) |
| 9512 | { |
| 9513 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 9514 | } |
| 9515 | str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN); |
| 9516 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 9517 | DBUG_PRINT("info" ,("spider part_info=%p" , part_info)); |
| 9518 | if (part_info) |
| 9519 | { |
| 9520 | uint part_syntax_len; |
| 9521 | char *part_syntax; |
| 9522 | List_iterator<partition_element> part_it(part_info->partitions); |
| 9523 | partition_element *part_elem, *sub_elem; |
| 9524 | while ((part_elem = part_it++)) |
| 9525 | { |
| 9526 | part_elem->engine_type = hton; |
| 9527 | if ((part_elem)->subpartitions.elements) |
| 9528 | { |
| 9529 | List_iterator<partition_element> sub_it((part_elem)->subpartitions); |
| 9530 | while ((sub_elem = sub_it++)) |
| 9531 | { |
| 9532 | sub_elem->engine_type = hton; |
| 9533 | } |
| 9534 | } |
| 9535 | } |
| 9536 | if (part_info->fix_parser_data(thd)) |
| 9537 | { |
| 9538 | DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM); |
| 9539 | } |
| 9540 | if (!(part_syntax = SPIDER_generate_partition_syntax(thd, part_info, |
| 9541 | &part_syntax_len, FALSE, TRUE, info, NULL, NULL))) |
| 9542 | { |
| 9543 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 9544 | } |
| 9545 | if (str.reserve(part_syntax_len)) |
| 9546 | { |
| 9547 | DBUG_RETURN(HA_ERR_OUT_OF_MEM); |
| 9548 | } |
| 9549 | str.q_append(part_syntax, part_syntax_len); |
| 9550 | SPIDER_free_part_syntax(part_syntax, MYF(0)); |
| 9551 | } |
| 9552 | #endif |
| 9553 | DBUG_PRINT("info" ,("spider str=%s" , str.c_ptr_safe())); |
| 9554 | |
| 9555 | error_num = share->init_from_sql_statement_string(thd, TRUE, str.ptr(), |
| 9556 | str.length()); |
| 9557 | DBUG_RETURN(error_num); |
| 9558 | } |
| 9559 | #endif |
| 9560 | |
| 9561 | #ifndef WITHOUT_SPIDER_BG_SEARCH |
| 9562 | int spider_create_spider_object_for_share( |
| 9563 | SPIDER_TRX *trx, |
| 9564 | SPIDER_SHARE *share, |
| 9565 | ha_spider **spider |
| 9566 | ) { |
| 9567 | int error_num, roop_count, *need_mons; |
| 9568 | SPIDER_CONN **conns; |
| 9569 | uint *conn_link_idx; |
| 9570 | uchar *conn_can_fo; |
| 9571 | char **conn_keys; |
| 9572 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 9573 | char **hs_r_conn_keys; |
| 9574 | char **hs_w_conn_keys; |
| 9575 | #endif |
| 9576 | spider_db_handler **dbton_hdl; |
| 9577 | DBUG_ENTER("spider_create_spider_object_for_share" ); |
| 9578 | DBUG_PRINT("info" ,("spider trx=%p" , trx)); |
| 9579 | DBUG_PRINT("info" ,("spider share=%p" , share)); |
| 9580 | DBUG_PRINT("info" ,("spider spider_ptr=%p" , spider)); |
| 9581 | DBUG_PRINT("info" ,("spider spider=%p" , (*spider))); |
| 9582 | |
| 9583 | if (*spider) |
| 9584 | { |
| 9585 | /* already exists */ |
| 9586 | DBUG_RETURN(0); |
| 9587 | } |
| 9588 | (*spider) = new (&share->mem_root) ha_spider(); |
| 9589 | if (!(*spider)) |
| 9590 | { |
| 9591 | error_num = HA_ERR_OUT_OF_MEM; |
| 9592 | goto error_spider_alloc; |
| 9593 | } |
| 9594 | DBUG_PRINT("info" ,("spider spider=%p" , (*spider))); |
| 9595 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 9596 | if (!(need_mons = (int *) |
| 9597 | spider_bulk_malloc(spider_current_trx, 255, MYF(MY_WME | MY_ZEROFILL), |
| 9598 | &need_mons, (sizeof(int) * share->link_count), |
| 9599 | &conns, (sizeof(SPIDER_CONN *) * share->link_count), |
| 9600 | &conn_link_idx, (sizeof(uint) * share->link_count), |
| 9601 | &conn_can_fo, (sizeof(uchar) * share->link_bitmap_size), |
| 9602 | &conn_keys, (sizeof(char *) * share->link_count), |
| 9603 | &hs_r_conn_keys, (sizeof(char *) * share->link_count), |
| 9604 | &hs_w_conn_keys, (sizeof(char *) * share->link_count), |
| 9605 | &dbton_hdl, (sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE), |
| 9606 | NullS)) |
| 9607 | ) |
| 9608 | #else |
| 9609 | if (!(need_mons = (int *) |
| 9610 | spider_bulk_malloc(spider_current_trx, 255, MYF(MY_WME | MY_ZEROFILL), |
| 9611 | &need_mons, (sizeof(int) * share->link_count), |
| 9612 | &conns, (sizeof(SPIDER_CONN *) * share->link_count), |
| 9613 | &conn_link_idx, (sizeof(uint) * share->link_count), |
| 9614 | &conn_can_fo, (sizeof(uchar) * share->link_bitmap_size), |
| 9615 | &conn_keys, (sizeof(char *) * share->link_count), |
| 9616 | &dbton_hdl, (sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE), |
| 9617 | NullS)) |
| 9618 | ) |
| 9619 | #endif |
| 9620 | { |
| 9621 | error_num = HA_ERR_OUT_OF_MEM; |
| 9622 | goto error_need_mons_alloc; |
| 9623 | } |
| 9624 | DBUG_PRINT("info" ,("spider need_mons=%p" , need_mons)); |
| 9625 | (*spider)->trx = trx; |
| 9626 | (*spider)->change_table_ptr(&share->table, share->table_share); |
| 9627 | (*spider)->share = share; |
| 9628 | (*spider)->conns = conns; |
| 9629 | (*spider)->conn_link_idx = conn_link_idx; |
| 9630 | (*spider)->conn_can_fo = conn_can_fo; |
| 9631 | (*spider)->need_mons = need_mons; |
| 9632 | (*spider)->conn_keys_first_ptr = share->conn_keys[0]; |
| 9633 | (*spider)->conn_keys = conn_keys; |
| 9634 | #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) |
| 9635 | (*spider)->hs_r_conn_keys = hs_r_conn_keys; |
| 9636 | (*spider)->hs_w_conn_keys = hs_w_conn_keys; |
| 9637 | #endif |
| 9638 | (*spider)->dbton_handler = dbton_hdl; |
| 9639 | (*spider)->search_link_idx = -1; |
| 9640 | for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++) |
| 9641 | { |
| 9642 | if ( |
| 9643 | spider_bit_is_set(share->dbton_bitmap, roop_count) && |
| 9644 | spider_dbton[roop_count].create_db_handler |
| 9645 | ) { |
| 9646 | if (!(dbton_hdl[roop_count] = spider_dbton[roop_count].create_db_handler( |
| 9647 | *spider, share->dbton_share[roop_count]))) |
| 9648 | { |
| 9649 | error_num = HA_ERR_OUT_OF_MEM; |
| 9650 | goto error_init_db_handler; |
| 9651 | } |
| 9652 | if ((error_num = dbton_hdl[roop_count]->init())) |
| 9653 | goto error_init_db_handler; |
| 9654 | } |
| 9655 | } |
| 9656 | DBUG_PRINT("info" ,("spider share=%p" , (*spider)->share)); |
| 9657 | DBUG_PRINT("info" ,("spider need_mons=%p" , (*spider)->need_mons)); |
| 9658 | DBUG_RETURN(0); |
| 9659 | |
| 9660 | error_init_db_handler: |
| 9661 | for (; roop_count >= 0; --roop_count) |
| 9662 | { |
| 9663 | if ( |
| 9664 | spider_bit_is_set(share->dbton_bitmap, roop_count) && |
| 9665 | dbton_hdl[roop_count] |
| 9666 | ) { |
| 9667 | delete dbton_hdl[roop_count]; |
| 9668 | dbton_hdl[roop_count] = NULL; |
| 9669 | } |
| 9670 | } |
| 9671 | spider_free(spider_current_trx, (*spider)->need_mons, MYF(0)); |
| 9672 | error_need_mons_alloc: |
| 9673 | delete (*spider); |
| 9674 | (*spider) = NULL; |
| 9675 | error_spider_alloc: |
| 9676 | DBUG_RETURN(error_num); |
| 9677 | } |
| 9678 | |
| 9679 | void spider_free_spider_object_for_share( |
| 9680 | ha_spider **spider |
| 9681 | ) { |
| 9682 | int roop_count; |
| 9683 | SPIDER_SHARE *share = (*spider)->share; |
| 9684 | spider_db_handler **dbton_hdl = (*spider)->dbton_handler; |
| 9685 | DBUG_ENTER("spider_free_spider_object_for_share" ); |
| 9686 | DBUG_PRINT("info" ,("spider share=%p" , share)); |
| 9687 | DBUG_PRINT("info" ,("spider spider_ptr=%p" , spider)); |
| 9688 | DBUG_PRINT("info" ,("spider spider=%p" , (*spider))); |
| 9689 | for (roop_count = SPIDER_DBTON_SIZE - 1; roop_count >= 0; --roop_count) |
| 9690 | { |
| 9691 | if ( |
| 9692 | spider_bit_is_set(share->dbton_bitmap, roop_count) && |
| 9693 | dbton_hdl[roop_count] |
| 9694 | ) { |
| 9695 | delete dbton_hdl[roop_count]; |
| 9696 | dbton_hdl[roop_count] = NULL; |
| 9697 | } |
| 9698 | } |
| 9699 | spider_free(spider_current_trx, (*spider)->need_mons, MYF(0)); |
| 9700 | delete (*spider); |
| 9701 | (*spider) = NULL; |
| 9702 | DBUG_VOID_RETURN; |
| 9703 | } |
| 9704 | |
| 9705 | int spider_create_sts_threads( |
| 9706 | SPIDER_THREAD *spider_thread |
| 9707 | ) { |
| 9708 | int error_num; |
| 9709 | DBUG_ENTER("spider_create_sts_threads" ); |
| 9710 | #if MYSQL_VERSION_ID < 50500 |
| 9711 | if (pthread_mutex_init(&spider_thread->mutex, |
| 9712 | MY_MUTEX_INIT_FAST)) |
| 9713 | #else |
| 9714 | if (mysql_mutex_init(spd_key_mutex_bg_stss, |
| 9715 | &spider_thread->mutex, MY_MUTEX_INIT_FAST)) |
| 9716 | #endif |
| 9717 | { |
| 9718 | error_num = HA_ERR_OUT_OF_MEM; |
| 9719 | goto error_mutex_init; |
| 9720 | } |
| 9721 | #if MYSQL_VERSION_ID < 50500 |
| 9722 | if (pthread_cond_init(&spider_thread->cond, NULL)) |
| 9723 | #else |
| 9724 | if (mysql_cond_init(spd_key_cond_bg_stss, |
| 9725 | &spider_thread->cond, NULL)) |
| 9726 | #endif |
| 9727 | { |
| 9728 | error_num = HA_ERR_OUT_OF_MEM; |
| 9729 | goto error_cond_init; |
| 9730 | } |
| 9731 | #if MYSQL_VERSION_ID < 50500 |
| 9732 | if (pthread_cond_init(&spider_thread->sync_cond, NULL)) |
| 9733 | #else |
| 9734 | if (mysql_cond_init(spd_key_cond_bg_sts_syncs, |
| 9735 | &spider_thread->sync_cond, NULL)) |
| 9736 | #endif |
| 9737 | { |
| 9738 | error_num = HA_ERR_OUT_OF_MEM; |
| 9739 | goto error_sync_cond_init; |
| 9740 | } |
| 9741 | #if MYSQL_VERSION_ID < 50500 |
| 9742 | if (pthread_create(&spider_thread->thread, &spider_pt_attr, |
| 9743 | spider_table_bg_sts_action, (void *) spider_thread) |
| 9744 | ) |
| 9745 | #else |
| 9746 | if (mysql_thread_create(spd_key_thd_bg_stss, &spider_thread->thread, |
| 9747 | &spider_pt_attr, spider_table_bg_sts_action, (void *) spider_thread) |
| 9748 | ) |
| 9749 | #endif |
| 9750 | { |
| 9751 | error_num = HA_ERR_OUT_OF_MEM; |
| 9752 | goto error_thread_create; |
| 9753 | } |
| 9754 | DBUG_RETURN(0); |
| 9755 | |
| 9756 | error_thread_create: |
| 9757 | pthread_cond_destroy(&spider_thread->sync_cond); |
| 9758 | error_sync_cond_init: |
| 9759 | pthread_cond_destroy(&spider_thread->cond); |
| 9760 | error_cond_init: |
| 9761 | pthread_mutex_destroy(&spider_thread->mutex); |
| 9762 | error_mutex_init: |
| 9763 | DBUG_RETURN(error_num); |
| 9764 | } |
| 9765 | |
| 9766 | void spider_free_sts_threads( |
| 9767 | SPIDER_THREAD *spider_thread |
| 9768 | ) { |
| 9769 | bool thread_killed; |
| 9770 | DBUG_ENTER("spider_free_sts_threads" ); |
| 9771 | pthread_mutex_lock(&spider_thread->mutex); |
| 9772 | thread_killed = spider_thread->killed; |
| 9773 | spider_thread->killed = TRUE; |
| 9774 | if (!thread_killed) |
| 9775 | { |
| 9776 | if (spider_thread->thd_wait) |
| 9777 | { |
| 9778 | pthread_cond_signal(&spider_thread->cond); |
| 9779 | } |
| 9780 | pthread_cond_wait(&spider_thread->sync_cond, &spider_thread->mutex); |
| 9781 | } |
| 9782 | pthread_mutex_unlock(&spider_thread->mutex); |
| 9783 | pthread_join(spider_thread->thread, NULL); |
| 9784 | pthread_cond_destroy(&spider_thread->sync_cond); |
| 9785 | pthread_cond_destroy(&spider_thread->cond); |
| 9786 | pthread_mutex_destroy(&spider_thread->mutex); |
| 9787 | spider_thread->thd_wait = FALSE; |
| 9788 | spider_thread->killed = FALSE; |
| 9789 | DBUG_VOID_RETURN; |
| 9790 | } |
| 9791 | |
| 9792 | int spider_create_crd_threads( |
| 9793 | SPIDER_THREAD *spider_thread |
| 9794 | ) { |
| 9795 | int error_num; |
| 9796 | DBUG_ENTER("spider_create_crd_threads" ); |
| 9797 | #if MYSQL_VERSION_ID < 50500 |
| 9798 | if (pthread_mutex_init(&spider_thread->mutex, |
| 9799 | MY_MUTEX_INIT_FAST)) |
| 9800 | #else |
| 9801 | if (mysql_mutex_init(spd_key_mutex_bg_crds, |
| 9802 | &spider_thread->mutex, MY_MUTEX_INIT_FAST)) |
| 9803 | #endif |
| 9804 | { |
| 9805 | error_num = HA_ERR_OUT_OF_MEM; |
| 9806 | goto error_mutex_init; |
| 9807 | } |
| 9808 | #if MYSQL_VERSION_ID < 50500 |
| 9809 | if (pthread_cond_init(&spider_thread->cond, NULL)) |
| 9810 | #else |
| 9811 | if (mysql_cond_init(spd_key_cond_bg_crds, |
| 9812 | &spider_thread->cond, NULL)) |
| 9813 | #endif |
| 9814 | { |
| 9815 | error_num = HA_ERR_OUT_OF_MEM; |
| 9816 | goto error_cond_init; |
| 9817 | } |
| 9818 | #if MYSQL_VERSION_ID < 50500 |
| 9819 | if (pthread_cond_init(&spider_thread->sync_cond, NULL)) |
| 9820 | #else |
| 9821 | if (mysql_cond_init(spd_key_cond_bg_crd_syncs, |
| 9822 | &spider_thread->sync_cond, NULL)) |
| 9823 | #endif |
| 9824 | { |
| 9825 | error_num = HA_ERR_OUT_OF_MEM; |
| 9826 | goto error_sync_cond_init; |
| 9827 | } |
| 9828 | #if MYSQL_VERSION_ID < 50500 |
| 9829 | if (pthread_create(&spider_thread->thread, &spider_pt_attr, |
| 9830 | spider_table_bg_crd_action, (void *) spider_thread) |
| 9831 | ) |
| 9832 | #else |
| 9833 | if (mysql_thread_create(spd_key_thd_bg_crds, &spider_thread->thread, |
| 9834 | &spider_pt_attr, spider_table_bg_crd_action, (void *) spider_thread) |
| 9835 | ) |
| 9836 | #endif |
| 9837 | { |
| 9838 | error_num = HA_ERR_OUT_OF_MEM; |
| 9839 | goto error_thread_create; |
| 9840 | } |
| 9841 | DBUG_RETURN(0); |
| 9842 | |
| 9843 | error_thread_create: |
| 9844 | pthread_cond_destroy(&spider_thread->sync_cond); |
| 9845 | error_sync_cond_init: |
| 9846 | pthread_cond_destroy(&spider_thread->cond); |
| 9847 | error_cond_init: |
| 9848 | pthread_mutex_destroy(&spider_thread->mutex); |
| 9849 | error_mutex_init: |
| 9850 | DBUG_RETURN(error_num); |
| 9851 | } |
| 9852 | |
| 9853 | void spider_free_crd_threads( |
| 9854 | SPIDER_THREAD *spider_thread |
| 9855 | ) { |
| 9856 | bool thread_killed; |
| 9857 | DBUG_ENTER("spider_free_crd_threads" ); |
| 9858 | pthread_mutex_lock(&spider_thread->mutex); |
| 9859 | thread_killed = spider_thread->killed; |
| 9860 | spider_thread->killed = TRUE; |
| 9861 | if (!thread_killed) |
| 9862 | { |
| 9863 | if (spider_thread->thd_wait) |
| 9864 | { |
| 9865 | pthread_cond_signal(&spider_thread->cond); |
| 9866 | } |
| 9867 | pthread_cond_wait(&spider_thread->sync_cond, &spider_thread->mutex); |
| 9868 | } |
| 9869 | pthread_mutex_unlock(&spider_thread->mutex); |
| 9870 | pthread_join(spider_thread->thread, NULL); |
| 9871 | pthread_cond_destroy(&spider_thread->sync_cond); |
| 9872 | pthread_cond_destroy(&spider_thread->cond); |
| 9873 | pthread_mutex_destroy(&spider_thread->mutex); |
| 9874 | spider_thread->thd_wait = FALSE; |
| 9875 | spider_thread->killed = FALSE; |
| 9876 | DBUG_VOID_RETURN; |
| 9877 | } |
| 9878 | |
| 9879 | void *spider_table_bg_sts_action( |
| 9880 | void *arg |
| 9881 | ) { |
| 9882 | SPIDER_THREAD *thread = (SPIDER_THREAD *) arg; |
| 9883 | SPIDER_SHARE *share; |
| 9884 | SPIDER_TRX *trx; |
| 9885 | int error_num; |
| 9886 | ha_spider *spider; |
| 9887 | SPIDER_CONN **conns; |
| 9888 | THD *thd; |
| 9889 | my_thread_init(); |
| 9890 | DBUG_ENTER("spider_table_bg_sts_action" ); |
| 9891 | /* init start */ |
| 9892 | pthread_mutex_lock(&thread->mutex); |
| 9893 | if (!(thd = spider_create_sys_thd(thread))) |
| 9894 | { |
| 9895 | thread->thd_wait = FALSE; |
| 9896 | thread->killed = FALSE; |
| 9897 | pthread_mutex_unlock(&thread->mutex); |
| 9898 | my_thread_end(); |
| 9899 | DBUG_RETURN(NULL); |
| 9900 | } |
| 9901 | SPIDER_set_next_thread_id(thd); |
| 9902 | #ifdef HAVE_PSI_INTERFACE |
| 9903 | mysql_thread_set_psi_id(thd->thread_id); |
| 9904 | #endif |
| 9905 | thd_proc_info(thd, "Spider table background statistics action handler" ); |
| 9906 | if (!(trx = spider_get_trx(NULL, FALSE, &error_num))) |
| 9907 | { |
| 9908 | spider_destroy_sys_thd(thd); |
| 9909 | thread->thd_wait = FALSE; |
| 9910 | thread->killed = FALSE; |
| 9911 | pthread_mutex_unlock(&thread->mutex); |
| 9912 | #if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) |
| 9913 | my_pthread_setspecific_ptr(THR_THD, NULL); |
| 9914 | #endif |
| 9915 | my_thread_end(); |
| 9916 | DBUG_RETURN(NULL); |
| 9917 | } |
| 9918 | trx->thd = thd; |
| 9919 | /* init end */ |
| 9920 | |
| 9921 | while (TRUE) |
| 9922 | { |
| 9923 | DBUG_PRINT("info" ,("spider bg sts loop start" )); |
| 9924 | if (thread->killed) |
| 9925 | { |
| 9926 | DBUG_PRINT("info" ,("spider bg sts kill start" )); |
| 9927 | trx->thd = NULL; |
| 9928 | spider_free_trx(trx, TRUE); |
| 9929 | spider_destroy_sys_thd(thd); |
| 9930 | pthread_cond_signal(&thread->sync_cond); |
| 9931 | pthread_mutex_unlock(&thread->mutex); |
| 9932 | #if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) |
| 9933 | my_pthread_setspecific_ptr(THR_THD, NULL); |
| 9934 | #endif |
| 9935 | my_thread_end(); |
| 9936 | DBUG_RETURN(NULL); |
| 9937 | } |
| 9938 | if (!thread->queue_first) |
| 9939 | { |
| 9940 | DBUG_PRINT("info" ,("spider bg sts has no job" )); |
| 9941 | thread->thd_wait = TRUE; |
| 9942 | pthread_cond_wait(&thread->cond, &thread->mutex); |
| 9943 | thread->thd_wait = FALSE; |
| 9944 | if (thd->killed) |
| 9945 | thread->killed = TRUE; |
| 9946 | continue; |
| 9947 | } |
| 9948 | share = (SPIDER_SHARE *) thread->queue_first; |
| 9949 | share->sts_working = TRUE; |
| 9950 | pthread_mutex_unlock(&thread->mutex); |
| 9951 | |
| 9952 | spider = share->sts_spider; |
| 9953 | conns = spider->conns; |
| 9954 | if (spider->search_link_idx < 0) |
| 9955 | { |
| 9956 | spider->trx = trx; |
| 9957 | spider_trx_set_link_idx_for_all(spider); |
| 9958 | spider->search_link_idx = spider_conn_first_link_idx(thd, |
| 9959 | share->link_statuses, share->access_balances, spider->conn_link_idx, |
| 9960 | share->link_count, SPIDER_LINK_STATUS_OK); |
| 9961 | } |
| 9962 | if (spider->search_link_idx >= 0) |
| 9963 | { |
| 9964 | DBUG_PRINT("info" , |
| 9965 | ("spider difftime=%f" , |
| 9966 | difftime(share->bg_sts_try_time, share->sts_get_time))); |
| 9967 | DBUG_PRINT("info" , |
| 9968 | ("spider bg_sts_interval=%f" , share->bg_sts_interval)); |
| 9969 | if (difftime(share->bg_sts_try_time, share->sts_get_time) >= |
| 9970 | share->bg_sts_interval) |
| 9971 | { |
| 9972 | if (!conns[spider->search_link_idx]) |
| 9973 | { |
| 9974 | spider_get_conn(share, spider->search_link_idx, |
| 9975 | share->conn_keys[spider->search_link_idx], |
| 9976 | trx, spider, FALSE, FALSE, SPIDER_CONN_KIND_MYSQL, |
| 9977 | &error_num); |
| 9978 | if (conns[spider->search_link_idx]) |
| 9979 | { |
| 9980 | conns[spider->search_link_idx]->error_mode = 0; |
| 9981 | } else { |
| 9982 | spider->search_link_idx = -1; |
| 9983 | } |
| 9984 | } |
| 9985 | DBUG_PRINT("info" , |
| 9986 | ("spider search_link_idx=%d" , spider->search_link_idx)); |
| 9987 | if (spider->search_link_idx >= 0 && conns[spider->search_link_idx]) |
| 9988 | { |
| 9989 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 9990 | if (spider_get_sts(share, spider->search_link_idx, |
| 9991 | share->bg_sts_try_time, spider, |
| 9992 | share->bg_sts_interval, share->bg_sts_mode, |
| 9993 | share->bg_sts_sync, |
| 9994 | 2, HA_STATUS_CONST | HA_STATUS_VARIABLE)) |
| 9995 | #else |
| 9996 | if (spider_get_sts(share, spider->search_link_idx, |
| 9997 | share->bg_sts_try_time, spider, |
| 9998 | share->bg_sts_interval, share->bg_sts_mode, |
| 9999 | 2, HA_STATUS_CONST | HA_STATUS_VARIABLE)) |
| 10000 | #endif |
| 10001 | { |
| 10002 | spider->search_link_idx = -1; |
| 10003 | } |
| 10004 | } |
| 10005 | } |
| 10006 | } |
| 10007 | memset(spider->need_mons, 0, sizeof(int) * share->link_count); |
| 10008 | pthread_mutex_lock(&thread->mutex); |
| 10009 | if (thread->queue_first == thread->queue_last) |
| 10010 | { |
| 10011 | thread->queue_first = NULL; |
| 10012 | thread->queue_last = NULL; |
| 10013 | } else { |
| 10014 | thread->queue_first = share->sts_next; |
| 10015 | share->sts_next->sts_prev = NULL; |
| 10016 | share->sts_next = NULL; |
| 10017 | } |
| 10018 | share->sts_working = FALSE; |
| 10019 | share->sts_wait = FALSE; |
| 10020 | if (thread->first_free_wait) |
| 10021 | { |
| 10022 | pthread_cond_signal(&thread->sync_cond); |
| 10023 | pthread_cond_wait(&thread->cond, &thread->mutex); |
| 10024 | if (thd->killed) |
| 10025 | thread->killed = TRUE; |
| 10026 | } |
| 10027 | } |
| 10028 | } |
| 10029 | |
| 10030 | void *spider_table_bg_crd_action( |
| 10031 | void *arg |
| 10032 | ) { |
| 10033 | SPIDER_THREAD *thread = (SPIDER_THREAD *) arg; |
| 10034 | SPIDER_SHARE *share; |
| 10035 | SPIDER_TRX *trx; |
| 10036 | int error_num; |
| 10037 | ha_spider *spider; |
| 10038 | TABLE *table; |
| 10039 | SPIDER_CONN **conns; |
| 10040 | THD *thd; |
| 10041 | my_thread_init(); |
| 10042 | DBUG_ENTER("spider_table_bg_crd_action" ); |
| 10043 | /* init start */ |
| 10044 | pthread_mutex_lock(&thread->mutex); |
| 10045 | if (!(thd = spider_create_sys_thd(thread))) |
| 10046 | { |
| 10047 | thread->thd_wait = FALSE; |
| 10048 | thread->killed = FALSE; |
| 10049 | pthread_mutex_unlock(&thread->mutex); |
| 10050 | my_thread_end(); |
| 10051 | DBUG_RETURN(NULL); |
| 10052 | } |
| 10053 | SPIDER_set_next_thread_id(thd); |
| 10054 | #ifdef HAVE_PSI_INTERFACE |
| 10055 | mysql_thread_set_psi_id(thd->thread_id); |
| 10056 | #endif |
| 10057 | thd_proc_info(thd, "Spider table background cardinality action handler" ); |
| 10058 | if (!(trx = spider_get_trx(NULL, FALSE, &error_num))) |
| 10059 | { |
| 10060 | spider_destroy_sys_thd(thd); |
| 10061 | thread->thd_wait = FALSE; |
| 10062 | thread->killed = FALSE; |
| 10063 | pthread_mutex_unlock(&thread->mutex); |
| 10064 | #if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) |
| 10065 | my_pthread_setspecific_ptr(THR_THD, NULL); |
| 10066 | #endif |
| 10067 | my_thread_end(); |
| 10068 | DBUG_RETURN(NULL); |
| 10069 | } |
| 10070 | trx->thd = thd; |
| 10071 | /* init end */ |
| 10072 | |
| 10073 | while (TRUE) |
| 10074 | { |
| 10075 | DBUG_PRINT("info" ,("spider bg crd loop start" )); |
| 10076 | if (thread->killed) |
| 10077 | { |
| 10078 | DBUG_PRINT("info" ,("spider bg crd kill start" )); |
| 10079 | trx->thd = NULL; |
| 10080 | spider_free_trx(trx, TRUE); |
| 10081 | spider_destroy_sys_thd(thd); |
| 10082 | pthread_cond_signal(&thread->sync_cond); |
| 10083 | pthread_mutex_unlock(&thread->mutex); |
| 10084 | #if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) |
| 10085 | my_pthread_setspecific_ptr(THR_THD, NULL); |
| 10086 | #endif |
| 10087 | my_thread_end(); |
| 10088 | DBUG_RETURN(NULL); |
| 10089 | } |
| 10090 | if (!thread->queue_first) |
| 10091 | { |
| 10092 | DBUG_PRINT("info" ,("spider bg crd has no job" )); |
| 10093 | thread->thd_wait = TRUE; |
| 10094 | pthread_cond_wait(&thread->cond, &thread->mutex); |
| 10095 | thread->thd_wait = FALSE; |
| 10096 | if (thd->killed) |
| 10097 | thread->killed = TRUE; |
| 10098 | continue; |
| 10099 | } |
| 10100 | share = (SPIDER_SHARE *) thread->queue_first; |
| 10101 | share->crd_working = TRUE; |
| 10102 | pthread_mutex_unlock(&thread->mutex); |
| 10103 | |
| 10104 | table = &share->table; |
| 10105 | spider = share->crd_spider; |
| 10106 | conns = spider->conns; |
| 10107 | if (spider->search_link_idx < 0) |
| 10108 | { |
| 10109 | spider->trx = trx; |
| 10110 | spider_trx_set_link_idx_for_all(spider); |
| 10111 | spider->search_link_idx = spider_conn_first_link_idx(thd, |
| 10112 | share->link_statuses, share->access_balances, spider->conn_link_idx, |
| 10113 | share->link_count, SPIDER_LINK_STATUS_OK); |
| 10114 | } |
| 10115 | if (spider->search_link_idx >= 0) |
| 10116 | { |
| 10117 | DBUG_PRINT("info" , |
| 10118 | ("spider difftime=%f" , |
| 10119 | difftime(share->bg_crd_try_time, share->crd_get_time))); |
| 10120 | DBUG_PRINT("info" , |
| 10121 | ("spider bg_crd_interval=%f" , share->bg_crd_interval)); |
| 10122 | if (difftime(share->bg_crd_try_time, share->crd_get_time) >= |
| 10123 | share->bg_crd_interval) |
| 10124 | { |
| 10125 | if (!conns[spider->search_link_idx]) |
| 10126 | { |
| 10127 | spider_get_conn(share, spider->search_link_idx, |
| 10128 | share->conn_keys[spider->search_link_idx], |
| 10129 | trx, spider, FALSE, FALSE, SPIDER_CONN_KIND_MYSQL, |
| 10130 | &error_num); |
| 10131 | if (conns[spider->search_link_idx]) |
| 10132 | { |
| 10133 | conns[spider->search_link_idx]->error_mode = 0; |
| 10134 | } else { |
| 10135 | spider->search_link_idx = -1; |
| 10136 | } |
| 10137 | } |
| 10138 | DBUG_PRINT("info" , |
| 10139 | ("spider search_link_idx=%d" , spider->search_link_idx)); |
| 10140 | if (spider->search_link_idx >= 0 && conns[spider->search_link_idx]) |
| 10141 | { |
| 10142 | #ifdef WITH_PARTITION_STORAGE_ENGINE |
| 10143 | if (spider_get_crd(share, spider->search_link_idx, |
| 10144 | share->bg_crd_try_time, spider, table, |
| 10145 | share->bg_crd_interval, share->bg_crd_mode, |
| 10146 | share->bg_crd_sync, |
| 10147 | 2)) |
| 10148 | #else |
| 10149 | if (spider_get_crd(share, spider->search_link_idx, |
| 10150 | share->bg_crd_try_time, spider, table, |
| 10151 | share->bg_crd_interval, share->bg_crd_mode, |
| 10152 | 2)) |
| 10153 | #endif |
| 10154 | { |
| 10155 | spider->search_link_idx = -1; |
| 10156 | } |
| 10157 | } |
| 10158 | } |
| 10159 | } |
| 10160 | memset(spider->need_mons, 0, sizeof(int) * share->link_count); |
| 10161 | pthread_mutex_lock(&thread->mutex); |
| 10162 | if (thread->queue_first == thread->queue_last) |
| 10163 | { |
| 10164 | thread->queue_first = NULL; |
| 10165 | thread->queue_last = NULL; |
| 10166 | } else { |
| 10167 | thread->queue_first = share->crd_next; |
| 10168 | share->crd_next->crd_prev = NULL; |
| 10169 | share->crd_next = NULL; |
| 10170 | } |
| 10171 | share->crd_working = FALSE; |
| 10172 | share->crd_wait = FALSE; |
| 10173 | if (thread->first_free_wait) |
| 10174 | { |
| 10175 | pthread_cond_signal(&thread->sync_cond); |
| 10176 | pthread_cond_wait(&thread->cond, &thread->mutex); |
| 10177 | if (thd->killed) |
| 10178 | thread->killed = TRUE; |
| 10179 | } |
| 10180 | } |
| 10181 | } |
| 10182 | |
| 10183 | void spider_table_add_share_to_sts_thread( |
| 10184 | SPIDER_SHARE *share |
| 10185 | ) { |
| 10186 | SPIDER_THREAD *spider_thread = share->sts_thread; |
| 10187 | DBUG_ENTER("spider_table_add_share_to_sts_thread" ); |
| 10188 | if ( |
| 10189 | !share->sts_wait && |
| 10190 | !pthread_mutex_trylock(&spider_thread->mutex) |
| 10191 | ) { |
| 10192 | if (!share->sts_wait) |
| 10193 | { |
| 10194 | if (spider_thread->queue_last) |
| 10195 | { |
| 10196 | DBUG_PRINT("info" ,("spider add to last" )); |
| 10197 | share->sts_prev = spider_thread->queue_last; |
| 10198 | spider_thread->queue_last->sts_next = share; |
| 10199 | } else { |
| 10200 | spider_thread->queue_first = share; |
| 10201 | } |
| 10202 | spider_thread->queue_last = share; |
| 10203 | share->sts_wait = TRUE; |
| 10204 | |
| 10205 | if (spider_thread->thd_wait) |
| 10206 | { |
| 10207 | pthread_cond_signal(&spider_thread->cond); |
| 10208 | } |
| 10209 | } |
| 10210 | pthread_mutex_unlock(&spider_thread->mutex); |
| 10211 | } |
| 10212 | DBUG_VOID_RETURN; |
| 10213 | } |
| 10214 | |
| 10215 | void spider_table_add_share_to_crd_thread( |
| 10216 | SPIDER_SHARE *share |
| 10217 | ) { |
| 10218 | SPIDER_THREAD *spider_thread = share->crd_thread; |
| 10219 | DBUG_ENTER("spider_table_add_share_to_crd_thread" ); |
| 10220 | if ( |
| 10221 | !share->crd_wait && |
| 10222 | !pthread_mutex_trylock(&spider_thread->mutex) |
| 10223 | ) { |
| 10224 | if (!share->crd_wait) |
| 10225 | { |
| 10226 | if (spider_thread->queue_last) |
| 10227 | { |
| 10228 | DBUG_PRINT("info" ,("spider add to last" )); |
| 10229 | share->crd_prev = spider_thread->queue_last; |
| 10230 | spider_thread->queue_last->crd_next = share; |
| 10231 | } else { |
| 10232 | spider_thread->queue_first = share; |
| 10233 | } |
| 10234 | spider_thread->queue_last = share; |
| 10235 | share->crd_wait = TRUE; |
| 10236 | |
| 10237 | if (spider_thread->thd_wait) |
| 10238 | { |
| 10239 | pthread_cond_signal(&spider_thread->cond); |
| 10240 | } |
| 10241 | } |
| 10242 | pthread_mutex_unlock(&spider_thread->mutex); |
| 10243 | } |
| 10244 | DBUG_VOID_RETURN; |
| 10245 | } |
| 10246 | |
| 10247 | void spider_table_remove_share_from_sts_thread( |
| 10248 | SPIDER_SHARE *share |
| 10249 | ) { |
| 10250 | SPIDER_THREAD *spider_thread = share->sts_thread; |
| 10251 | DBUG_ENTER("spider_table_remove_share_from_sts_thread" ); |
| 10252 | if (share->sts_wait) |
| 10253 | { |
| 10254 | pthread_mutex_lock(&spider_thread->mutex); |
| 10255 | if (share->sts_wait) |
| 10256 | { |
| 10257 | if (share->sts_working) |
| 10258 | { |
| 10259 | DBUG_PRINT("info" ,("spider waiting bg sts start" )); |
| 10260 | spider_thread->first_free_wait = TRUE; |
| 10261 | pthread_cond_wait(&spider_thread->sync_cond, &spider_thread->mutex); |
| 10262 | spider_thread->first_free_wait = FALSE; |
| 10263 | pthread_cond_signal(&spider_thread->cond); |
| 10264 | DBUG_PRINT("info" ,("spider waiting bg sts end" )); |
| 10265 | } |
| 10266 | |
| 10267 | if (share->sts_prev) |
| 10268 | { |
| 10269 | if (share->sts_next) |
| 10270 | { |
| 10271 | DBUG_PRINT("info" ,("spider remove middle one" )); |
| 10272 | share->sts_prev->sts_next = share->sts_next; |
| 10273 | share->sts_next->sts_prev = share->sts_prev; |
| 10274 | } else { |
| 10275 | DBUG_PRINT("info" ,("spider remove last one" )); |
| 10276 | share->sts_prev->sts_next = NULL; |
| 10277 | spider_thread->queue_last = share->sts_prev; |
| 10278 | } |
| 10279 | } else if (share->sts_next) { |
| 10280 | DBUG_PRINT("info" ,("spider remove first one" )); |
| 10281 | share->sts_next->sts_prev = NULL; |
| 10282 | spider_thread->queue_first = share->sts_next; |
| 10283 | } else { |
| 10284 | DBUG_PRINT("info" ,("spider empty" )); |
| 10285 | spider_thread->queue_first = NULL; |
| 10286 | spider_thread->queue_last = NULL; |
| 10287 | } |
| 10288 | } |
| 10289 | pthread_mutex_unlock(&spider_thread->mutex); |
| 10290 | } |
| 10291 | DBUG_VOID_RETURN; |
| 10292 | } |
| 10293 | |
| 10294 | void spider_table_remove_share_from_crd_thread( |
| 10295 | SPIDER_SHARE *share |
| 10296 | ) { |
| 10297 | SPIDER_THREAD *spider_thread = share->crd_thread; |
| 10298 | DBUG_ENTER("spider_table_remove_share_from_crd_thread" ); |
| 10299 | if (share->crd_wait) |
| 10300 | { |
| 10301 | pthread_mutex_lock(&spider_thread->mutex); |
| 10302 | if (share->crd_wait) |
| 10303 | { |
| 10304 | if (share->crd_working) |
| 10305 | { |
| 10306 | DBUG_PRINT("info" ,("spider waiting bg crd start" )); |
| 10307 | spider_thread->first_free_wait = TRUE; |
| 10308 | pthread_cond_wait(&spider_thread->sync_cond, &spider_thread->mutex); |
| 10309 | spider_thread->first_free_wait = FALSE; |
| 10310 | pthread_cond_signal(&spider_thread->cond); |
| 10311 | DBUG_PRINT("info" ,("spider waiting bg crd end" )); |
| 10312 | } |
| 10313 | |
| 10314 | if (share->crd_prev) |
| 10315 | { |
| 10316 | if (share->crd_next) |
| 10317 | { |
| 10318 | DBUG_PRINT("info" ,("spider remove middle one" )); |
| 10319 | share->crd_prev->crd_next = share->crd_next; |
| 10320 | share->crd_next->crd_prev = share->crd_prev; |
| 10321 | } else { |
| 10322 | DBUG_PRINT("info" ,("spider remove last one" )); |
| 10323 | share->crd_prev->crd_next = NULL; |
| 10324 | spider_thread->queue_last = share->crd_prev; |
| 10325 | } |
| 10326 | } else if (share->crd_next) { |
| 10327 | DBUG_PRINT("info" ,("spider remove first one" )); |
| 10328 | share->crd_next->crd_prev = NULL; |
| 10329 | spider_thread->queue_first = share->crd_next; |
| 10330 | } else { |
| 10331 | DBUG_PRINT("info" ,("spider empty" )); |
| 10332 | spider_thread->queue_first = NULL; |
| 10333 | spider_thread->queue_last = NULL; |
| 10334 | } |
| 10335 | } |
| 10336 | pthread_mutex_unlock(&spider_thread->mutex); |
| 10337 | } |
| 10338 | DBUG_VOID_RETURN; |
| 10339 | } |
| 10340 | #endif |
| 10341 | |