You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

8322 lines
277 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
  1. /* Copyright (C) 2008-2014 Kentoku Shiba
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  12. #define MYSQL_SERVER 1
  13. #include "mysql_version.h"
  14. #if MYSQL_VERSION_ID < 50500
  15. #include "mysql_priv.h"
  16. #include <mysql/plugin.h>
  17. #else
  18. #include "sql_priv.h"
  19. #include "probes_mysql.h"
  20. #include "my_getopt.h"
  21. #include "sql_class.h"
  22. #include "sql_partition.h"
  23. #include "sql_servers.h"
  24. #ifdef HANDLER_HAS_DIRECT_AGGREGATE
  25. #include "sql_select.h"
  26. #endif
  27. #endif
  28. #include "spd_err.h"
  29. #include "spd_param.h"
  30. #include "spd_db_include.h"
  31. #include "spd_include.h"
  32. #include "spd_sys_table.h"
  33. #include "ha_spider.h"
  34. #include "spd_trx.h"
  35. #include "spd_db_conn.h"
  36. #include "spd_table.h"
  37. #include "spd_conn.h"
  38. #include "spd_ping_table.h"
  39. #include "spd_malloc.h"
  40. ulong *spd_db_att_thread_id;
  41. #ifdef XID_CACHE_IS_SPLITTED
  42. uint *spd_db_att_xid_cache_split_num;
  43. #endif
  44. pthread_mutex_t *spd_db_att_LOCK_xid_cache;
  45. HASH *spd_db_att_xid_cache;
  46. struct charset_info_st *spd_charset_utf8_bin;
  47. const char **spd_defaults_extra_file;
  48. const char **spd_defaults_file;
  49. bool volatile *spd_abort_loop;
  50. handlerton *spider_hton_ptr;
  51. SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE];
  52. extern SPIDER_DBTON spider_dbton_mysql;
  53. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  54. extern SPIDER_DBTON spider_dbton_handlersocket;
  55. #endif
  56. #ifdef HAVE_ORACLE_OCI
  57. extern SPIDER_DBTON spider_dbton_oracle;
  58. #endif
  59. #ifdef HAVE_PSI_INTERFACE
  60. PSI_mutex_key spd_key_mutex_tbl;
  61. PSI_mutex_key spd_key_mutex_init_error_tbl;
  62. #ifdef WITH_PARTITION_STORAGE_ENGINE
  63. PSI_mutex_key spd_key_mutex_pt_share;
  64. #endif
  65. PSI_mutex_key spd_key_mutex_lgtm_tblhnd_share;
  66. PSI_mutex_key spd_key_mutex_conn;
  67. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  68. PSI_mutex_key spd_key_mutex_hs_r_conn;
  69. PSI_mutex_key spd_key_mutex_hs_w_conn;
  70. #endif
  71. #ifndef WITHOUT_SPIDER_BG_SEARCH
  72. PSI_mutex_key spd_key_mutex_global_trx;
  73. #endif
  74. PSI_mutex_key spd_key_mutex_open_conn;
  75. PSI_mutex_key spd_key_mutex_allocated_thds;
  76. PSI_mutex_key spd_key_mutex_mon_table_cache;
  77. PSI_mutex_key spd_key_mutex_udf_table_mon;
  78. PSI_mutex_key spd_key_mutex_mta_conn;
  79. #ifndef WITHOUT_SPIDER_BG_SEARCH
  80. PSI_mutex_key spd_key_mutex_bg_conn_chain;
  81. PSI_mutex_key spd_key_mutex_bg_conn_sync;
  82. PSI_mutex_key spd_key_mutex_bg_conn;
  83. PSI_mutex_key spd_key_mutex_bg_job_stack;
  84. PSI_mutex_key spd_key_mutex_bg_mon;
  85. PSI_mutex_key spd_key_mutex_bg_direct_sql;
  86. #endif
  87. PSI_mutex_key spd_key_mutex_mon_list_caller;
  88. PSI_mutex_key spd_key_mutex_mon_list_receptor;
  89. PSI_mutex_key spd_key_mutex_mon_list_monitor;
  90. PSI_mutex_key spd_key_mutex_mon_list_update_status;
  91. PSI_mutex_key spd_key_mutex_share;
  92. PSI_mutex_key spd_key_mutex_share_sts;
  93. PSI_mutex_key spd_key_mutex_share_crd;
  94. PSI_mutex_key spd_key_mutex_share_auto_increment;
  95. #ifdef WITH_PARTITION_STORAGE_ENGINE
  96. PSI_mutex_key spd_key_mutex_pt_share_sts;
  97. PSI_mutex_key spd_key_mutex_pt_share_crd;
  98. PSI_mutex_key spd_key_mutex_pt_handler;
  99. #endif
  100. PSI_mutex_key spd_key_mutex_udf_table;
  101. PSI_mutex_key spd_key_mutex_mem_calc;
  102. PSI_mutex_key spd_key_thread_id;
  103. PSI_mutex_key spd_key_conn_id;
  104. static PSI_mutex_info all_spider_mutexes[]=
  105. {
  106. { &spd_key_mutex_tbl, "tbl", PSI_FLAG_GLOBAL},
  107. { &spd_key_mutex_init_error_tbl, "init_error_tbl", PSI_FLAG_GLOBAL},
  108. #ifdef WITH_PARTITION_STORAGE_ENGINE
  109. { &spd_key_mutex_pt_share, "pt_share", PSI_FLAG_GLOBAL},
  110. #endif
  111. { &spd_key_mutex_lgtm_tblhnd_share, "lgtm_tblhnd_share", PSI_FLAG_GLOBAL},
  112. { &spd_key_mutex_conn, "conn", PSI_FLAG_GLOBAL},
  113. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  114. { &spd_key_mutex_hs_r_conn, "hs_r_conn", PSI_FLAG_GLOBAL},
  115. { &spd_key_mutex_hs_w_conn, "hs_w_conn", PSI_FLAG_GLOBAL},
  116. #endif
  117. #ifndef WITHOUT_SPIDER_BG_SEARCH
  118. { &spd_key_mutex_global_trx, "global_trx", PSI_FLAG_GLOBAL},
  119. #endif
  120. { &spd_key_mutex_open_conn, "open_conn", PSI_FLAG_GLOBAL},
  121. { &spd_key_mutex_allocated_thds, "allocated_thds", PSI_FLAG_GLOBAL},
  122. { &spd_key_mutex_mon_table_cache, "mon_table_cache", PSI_FLAG_GLOBAL},
  123. { &spd_key_mutex_udf_table_mon, "udf_table_mon", PSI_FLAG_GLOBAL},
  124. { &spd_key_mutex_mem_calc, "mem_calc", PSI_FLAG_GLOBAL},
  125. { &spd_key_thread_id, "thread_id", PSI_FLAG_GLOBAL},
  126. { &spd_key_conn_id, "conn_id", PSI_FLAG_GLOBAL},
  127. { &spd_key_mutex_mta_conn, "mta_conn", 0},
  128. #ifndef WITHOUT_SPIDER_BG_SEARCH
  129. { &spd_key_mutex_bg_conn_chain, "bg_conn_chain", 0},
  130. { &spd_key_mutex_bg_conn_sync, "bg_conn_sync", 0},
  131. { &spd_key_mutex_bg_conn, "bg_conn", 0},
  132. { &spd_key_mutex_bg_job_stack, "bg_job_stack", 0},
  133. { &spd_key_mutex_bg_mon, "bg_mon", 0},
  134. { &spd_key_mutex_bg_direct_sql, "bg_direct_sql", 0},
  135. #endif
  136. { &spd_key_mutex_mon_list_caller, "mon_list_caller", 0},
  137. { &spd_key_mutex_mon_list_receptor, "mon_list_receptor", 0},
  138. { &spd_key_mutex_mon_list_monitor, "mon_list_monitor", 0},
  139. { &spd_key_mutex_mon_list_update_status, "mon_list_update_status", 0},
  140. { &spd_key_mutex_share, "share", 0},
  141. { &spd_key_mutex_share_sts, "share_sts", 0},
  142. { &spd_key_mutex_share_crd, "share_crd", 0},
  143. { &spd_key_mutex_share_auto_increment, "share_auto_increment", 0},
  144. #ifdef WITH_PARTITION_STORAGE_ENGINE
  145. { &spd_key_mutex_pt_share_sts, "pt_share_sts", 0},
  146. { &spd_key_mutex_pt_share_crd, "pt_share_crd", 0},
  147. { &spd_key_mutex_pt_handler, "pt_handler", 0},
  148. #endif
  149. { &spd_key_mutex_udf_table, "udf_table", 0},
  150. };
  151. #ifndef WITHOUT_SPIDER_BG_SEARCH
  152. PSI_cond_key spd_key_cond_bg_conn_sync;
  153. PSI_cond_key spd_key_cond_bg_conn;
  154. PSI_cond_key spd_key_cond_bg_sts;
  155. PSI_cond_key spd_key_cond_bg_sts_sync;
  156. PSI_cond_key spd_key_cond_bg_crd;
  157. PSI_cond_key spd_key_cond_bg_crd_sync;
  158. PSI_cond_key spd_key_cond_bg_mon;
  159. PSI_cond_key spd_key_cond_bg_mon_sleep;
  160. PSI_cond_key spd_key_cond_bg_direct_sql;
  161. #endif
  162. PSI_cond_key spd_key_cond_udf_table_mon;
  163. static PSI_cond_info all_spider_conds[] = {
  164. #ifndef WITHOUT_SPIDER_BG_SEARCH
  165. {&spd_key_cond_bg_conn_sync, "bg_conn_sync", 0},
  166. {&spd_key_cond_bg_conn, "bg_conn", 0},
  167. {&spd_key_cond_bg_sts, "bg_sts", 0},
  168. {&spd_key_cond_bg_sts_sync, "bg_sts_sync", 0},
  169. {&spd_key_cond_bg_crd, "bg_crd", 0},
  170. {&spd_key_cond_bg_crd_sync, "bg_crd_sync", 0},
  171. {&spd_key_cond_bg_mon, "bg_mon", 0},
  172. {&spd_key_cond_bg_mon_sleep, "bg_mon_sleep", 0},
  173. {&spd_key_cond_bg_direct_sql, "bg_direct_sql", 0},
  174. #endif
  175. {&spd_key_cond_udf_table_mon, "udf_table_mon", 0},
  176. };
  177. #ifndef WITHOUT_SPIDER_BG_SEARCH
  178. PSI_thread_key spd_key_thd_bg;
  179. PSI_thread_key spd_key_thd_bg_sts;
  180. PSI_thread_key spd_key_thd_bg_crd;
  181. PSI_thread_key spd_key_thd_bg_mon;
  182. #endif
  183. static PSI_thread_info all_spider_threads[] = {
  184. #ifndef WITHOUT_SPIDER_BG_SEARCH
  185. {&spd_key_thd_bg, "bg", 0},
  186. {&spd_key_thd_bg_sts, "bg_sts", 0},
  187. {&spd_key_thd_bg_crd, "bg_crd", 0},
  188. {&spd_key_thd_bg_mon, "bg_mon", 0},
  189. #endif
  190. };
  191. #endif
  192. extern HASH spider_open_connections;
  193. extern uint spider_open_connections_id;
  194. extern const char *spider_open_connections_func_name;
  195. extern const char *spider_open_connections_file_name;
  196. extern ulong spider_open_connections_line_no;
  197. extern pthread_mutex_t spider_conn_mutex;
  198. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  199. extern HASH spider_hs_r_conn_hash;
  200. extern uint spider_hs_r_conn_hash_id;
  201. extern const char *spider_hs_r_conn_hash_func_name;
  202. extern const char *spider_hs_r_conn_hash_file_name;
  203. extern ulong spider_hs_r_conn_hash_line_no;
  204. extern pthread_mutex_t spider_hs_r_conn_mutex;
  205. extern HASH spider_hs_w_conn_hash;
  206. extern uint spider_hs_w_conn_hash_id;
  207. extern const char *spider_hs_w_conn_hash_func_name;
  208. extern const char *spider_hs_w_conn_hash_file_name;
  209. extern ulong spider_hs_w_conn_hash_line_no;
  210. extern pthread_mutex_t spider_hs_w_conn_mutex;
  211. #endif
  212. extern HASH *spider_udf_table_mon_list_hash;
  213. extern uint spider_udf_table_mon_list_hash_id;
  214. extern const char *spider_udf_table_mon_list_hash_func_name;
  215. extern const char *spider_udf_table_mon_list_hash_file_name;
  216. extern ulong spider_udf_table_mon_list_hash_line_no;
  217. extern pthread_mutex_t *spider_udf_table_mon_mutexes;
  218. extern pthread_cond_t *spider_udf_table_mon_conds;
  219. extern pthread_mutex_t spider_open_conn_mutex;
  220. extern pthread_mutex_t spider_mon_table_cache_mutex;
  221. extern DYNAMIC_ARRAY spider_mon_table_cache;
  222. extern uint spider_mon_table_cache_id;
  223. extern const char *spider_mon_table_cache_func_name;
  224. extern const char *spider_mon_table_cache_file_name;
  225. extern ulong spider_mon_table_cache_line_no;
  226. HASH spider_open_tables;
  227. uint spider_open_tables_id;
  228. const char *spider_open_tables_func_name;
  229. const char *spider_open_tables_file_name;
  230. ulong spider_open_tables_line_no;
  231. pthread_mutex_t spider_tbl_mutex;
  232. HASH spider_init_error_tables;
  233. uint spider_init_error_tables_id;
  234. const char *spider_init_error_tables_func_name;
  235. const char *spider_init_error_tables_file_name;
  236. ulong spider_init_error_tables_line_no;
  237. pthread_mutex_t spider_init_error_tbl_mutex;
  238. extern pthread_mutex_t spider_thread_id_mutex;
  239. extern pthread_mutex_t spider_conn_id_mutex;
  240. #ifdef WITH_PARTITION_STORAGE_ENGINE
  241. HASH spider_open_pt_share;
  242. uint spider_open_pt_share_id;
  243. const char *spider_open_pt_share_func_name;
  244. const char *spider_open_pt_share_file_name;
  245. ulong spider_open_pt_share_line_no;
  246. pthread_mutex_t spider_pt_share_mutex;
  247. #endif
  248. HASH spider_lgtm_tblhnd_share_hash;
  249. uint spider_lgtm_tblhnd_share_hash_id;
  250. const char *spider_lgtm_tblhnd_share_hash_func_name;
  251. const char *spider_lgtm_tblhnd_share_hash_file_name;
  252. ulong spider_lgtm_tblhnd_share_hash_line_no;
  253. pthread_mutex_t spider_lgtm_tblhnd_share_mutex;
  254. HASH spider_allocated_thds;
  255. uint spider_allocated_thds_id;
  256. const char *spider_allocated_thds_func_name;
  257. const char *spider_allocated_thds_file_name;
  258. ulong spider_allocated_thds_line_no;
  259. pthread_mutex_t spider_allocated_thds_mutex;
  260. #ifndef WITHOUT_SPIDER_BG_SEARCH
  261. pthread_attr_t spider_pt_attr;
  262. pthread_mutex_t spider_global_trx_mutex;
  263. SPIDER_TRX *spider_global_trx;
  264. #endif
  265. extern pthread_mutex_t spider_mem_calc_mutex;
  266. extern const char *spider_alloc_func_name[SPIDER_MEM_CALC_LIST_NUM];
  267. extern const char *spider_alloc_file_name[SPIDER_MEM_CALC_LIST_NUM];
  268. extern ulong spider_alloc_line_no[SPIDER_MEM_CALC_LIST_NUM];
  269. extern ulonglong spider_total_alloc_mem[SPIDER_MEM_CALC_LIST_NUM];
  270. extern longlong spider_current_alloc_mem[SPIDER_MEM_CALC_LIST_NUM];
  271. extern ulonglong spider_alloc_mem_count[SPIDER_MEM_CALC_LIST_NUM];
  272. extern ulonglong spider_free_mem_count[SPIDER_MEM_CALC_LIST_NUM];
  273. static char spider_wild_many = '%', spider_wild_one = '_',
  274. spider_wild_prefix='\\';
  275. // for spider_open_tables
  276. uchar *spider_tbl_get_key(
  277. SPIDER_SHARE *share,
  278. size_t *length,
  279. my_bool not_used __attribute__ ((unused))
  280. ) {
  281. DBUG_ENTER("spider_tbl_get_key");
  282. *length = share->table_name_length;
  283. DBUG_RETURN((uchar*) share->table_name);
  284. }
  285. #ifdef WITH_PARTITION_STORAGE_ENGINE
  286. uchar *spider_pt_share_get_key(
  287. SPIDER_PARTITION_SHARE *share,
  288. size_t *length,
  289. my_bool not_used __attribute__ ((unused))
  290. ) {
  291. DBUG_ENTER("spider_pt_share_get_key");
  292. *length = share->table_name_length;
  293. DBUG_RETURN((uchar*) share->table_name);
  294. }
  295. uchar *spider_pt_handler_share_get_key(
  296. SPIDER_PARTITION_HANDLER_SHARE *share,
  297. size_t *length,
  298. my_bool not_used __attribute__ ((unused))
  299. ) {
  300. DBUG_ENTER("spider_pt_handler_share_get_key");
  301. *length = sizeof(TABLE *);
  302. DBUG_RETURN((uchar*) &share->table);
  303. }
  304. #endif
  305. uchar *spider_lgtm_tblhnd_share_hash_get_key(
  306. SPIDER_LGTM_TBLHND_SHARE *share,
  307. size_t *length,
  308. my_bool not_used __attribute__ ((unused))
  309. ) {
  310. DBUG_ENTER("spider_lgtm_tblhnd_share_hash_get_key");
  311. *length = share->table_name_length;
  312. DBUG_RETURN((uchar*) share->table_name);
  313. }
  314. uchar *spider_link_get_key(
  315. SPIDER_LINK_FOR_HASH *link_for_hash,
  316. size_t *length,
  317. my_bool not_used __attribute__ ((unused))
  318. ) {
  319. DBUG_ENTER("spider_link_get_key");
  320. *length = link_for_hash->db_table_str->length();
  321. DBUG_RETURN((uchar*) link_for_hash->db_table_str->ptr());
  322. }
  323. uchar *spider_ha_get_key(
  324. ha_spider *spider,
  325. size_t *length,
  326. my_bool not_used __attribute__ ((unused))
  327. ) {
  328. DBUG_ENTER("spider_ha_get_key");
  329. *length = spider->share->table_name_length;
  330. DBUG_RETURN((uchar*) spider->share->table_name);
  331. }
  332. uchar *spider_udf_tbl_mon_list_key(
  333. SPIDER_TABLE_MON_LIST *table_mon_list,
  334. size_t *length,
  335. my_bool not_used __attribute__ ((unused))
  336. ) {
  337. DBUG_ENTER("spider_udf_tbl_mon_list_key");
  338. DBUG_PRINT("info",("spider hash key=%s", table_mon_list->key));
  339. DBUG_PRINT("info",("spider hash key length=%u", table_mon_list->key_length));
  340. *length = table_mon_list->key_length;
  341. DBUG_RETURN((uchar*) table_mon_list->key);
  342. }
  343. uchar *spider_allocated_thds_get_key(
  344. THD *thd,
  345. size_t *length,
  346. my_bool not_used __attribute__ ((unused))
  347. ) {
  348. DBUG_ENTER("spider_allocated_thds_get_key");
  349. *length = sizeof(THD *);
  350. DBUG_RETURN((uchar*) thd);
  351. }
  352. #ifdef HAVE_PSI_INTERFACE
  353. static void init_spider_psi_keys()
  354. {
  355. DBUG_ENTER("init_spider_psi_keys");
  356. if (PSI_server == NULL)
  357. DBUG_VOID_RETURN;
  358. PSI_server->register_mutex("spider", all_spider_mutexes,
  359. array_elements(all_spider_mutexes));
  360. PSI_server->register_cond("spider", all_spider_conds,
  361. array_elements(all_spider_conds));
  362. PSI_server->register_thread("spider", all_spider_threads,
  363. array_elements(all_spider_threads));
  364. DBUG_VOID_RETURN;
  365. }
  366. #endif
  367. int spider_get_server(
  368. SPIDER_SHARE *share,
  369. int link_idx
  370. ) {
  371. MEM_ROOT mem_root;
  372. int error_num, length;
  373. FOREIGN_SERVER *server, server_buf;
  374. DBUG_ENTER("spider_get_server");
  375. SPD_INIT_ALLOC_ROOT(&mem_root, 128, 0, MYF(MY_WME));
  376. if (!(server
  377. = get_server_by_name(&mem_root, share->server_names[link_idx],
  378. &server_buf)))
  379. {
  380. error_num = ER_FOREIGN_SERVER_DOESNT_EXIST;
  381. goto error;
  382. }
  383. if (!share->tgt_wrappers[link_idx] && server->scheme)
  384. {
  385. share->tgt_wrappers_lengths[link_idx] = strlen(server->scheme);
  386. if (!(share->tgt_wrappers[link_idx] =
  387. spider_create_string(server->scheme,
  388. share->tgt_wrappers_lengths[link_idx])))
  389. {
  390. error_num = HA_ERR_OUT_OF_MEM;
  391. goto error;
  392. }
  393. DBUG_PRINT("info",("spider tgt_wrappers=%s",
  394. share->tgt_wrappers[link_idx]));
  395. }
  396. if (!share->tgt_hosts[link_idx] && server->host)
  397. {
  398. share->tgt_hosts_lengths[link_idx] = strlen(server->host);
  399. if (!(share->tgt_hosts[link_idx] =
  400. spider_create_string(server->host, share->tgt_hosts_lengths[link_idx])))
  401. {
  402. error_num = HA_ERR_OUT_OF_MEM;
  403. goto error;
  404. }
  405. DBUG_PRINT("info",("spider tgt_hosts=%s", share->tgt_hosts[link_idx]));
  406. }
  407. if (share->tgt_ports[link_idx] == -1)
  408. {
  409. share->tgt_ports[link_idx] = server->port;
  410. DBUG_PRINT("info",("spider tgt_ports=%ld", share->tgt_ports[link_idx]));
  411. }
  412. if (!share->tgt_sockets[link_idx] && server->socket)
  413. {
  414. share->tgt_sockets_lengths[link_idx] = strlen(server->socket);
  415. if (!(share->tgt_sockets[link_idx] =
  416. spider_create_string(server->socket,
  417. share->tgt_sockets_lengths[link_idx])))
  418. {
  419. error_num = HA_ERR_OUT_OF_MEM;
  420. goto error;
  421. }
  422. DBUG_PRINT("info",("spider tgt_sockets=%s", share->tgt_sockets[link_idx]));
  423. }
  424. if (!share->tgt_dbs[link_idx] && server->db && (length = strlen(server->db)))
  425. {
  426. share->tgt_dbs_lengths[link_idx] = length;
  427. if (!(share->tgt_dbs[link_idx] =
  428. spider_create_string(server->db, length)))
  429. {
  430. error_num = HA_ERR_OUT_OF_MEM;
  431. goto error;
  432. }
  433. DBUG_PRINT("info",("spider tgt_dbs=%s", share->tgt_dbs[link_idx]));
  434. }
  435. if (!share->tgt_usernames[link_idx] && server->username)
  436. {
  437. share->tgt_usernames_lengths[link_idx] = strlen(server->username);
  438. if (!(share->tgt_usernames[link_idx] =
  439. spider_create_string(server->username,
  440. share->tgt_usernames_lengths[link_idx])))
  441. {
  442. error_num = HA_ERR_OUT_OF_MEM;
  443. goto error;
  444. }
  445. DBUG_PRINT("info",("spider tgt_usernames=%s",
  446. share->tgt_usernames[link_idx]));
  447. }
  448. if (!share->tgt_passwords[link_idx] && server->password)
  449. {
  450. share->tgt_passwords_lengths[link_idx] = strlen(server->password);
  451. if (!(share->tgt_passwords[link_idx] =
  452. spider_create_string(server->password,
  453. share->tgt_passwords_lengths[link_idx])))
  454. {
  455. error_num = HA_ERR_OUT_OF_MEM;
  456. goto error;
  457. }
  458. DBUG_PRINT("info",("spider tgt_passwords=%s",
  459. share->tgt_passwords[link_idx]));
  460. }
  461. free_root(&mem_root, MYF(0));
  462. DBUG_RETURN(0);
  463. error:
  464. free_root(&mem_root, MYF(0));
  465. my_error(error_num, MYF(0), share->server_names[link_idx]);
  466. DBUG_RETURN(error_num);
  467. }
  468. int spider_free_share_alloc(
  469. SPIDER_SHARE *share
  470. ) {
  471. int roop_count;
  472. DBUG_ENTER("spider_free_share_alloc");
  473. if (share->dbton_bitmap)
  474. {
  475. for (roop_count = SPIDER_DBTON_SIZE - 1; roop_count >= 0; roop_count--)
  476. {
  477. if (share->dbton_share[roop_count])
  478. {
  479. delete share->dbton_share[roop_count];
  480. share->dbton_share[roop_count] = NULL;
  481. }
  482. }
  483. }
  484. if (share->server_names)
  485. {
  486. for (roop_count = 0; roop_count < (int) share->server_names_length;
  487. roop_count++)
  488. {
  489. if (share->server_names[roop_count])
  490. spider_free(spider_current_trx, share->server_names[roop_count],
  491. MYF(0));
  492. }
  493. spider_free(spider_current_trx, share->server_names, MYF(0));
  494. }
  495. if (share->tgt_table_names)
  496. {
  497. for (roop_count = 0; roop_count < (int) share->tgt_table_names_length;
  498. roop_count++)
  499. {
  500. if (share->tgt_table_names[roop_count])
  501. spider_free(spider_current_trx, share->tgt_table_names[roop_count],
  502. MYF(0));
  503. }
  504. spider_free(spider_current_trx, share->tgt_table_names, MYF(0));
  505. }
  506. if (share->tgt_dbs)
  507. {
  508. for (roop_count = 0; roop_count < (int) share->tgt_dbs_length;
  509. roop_count++)
  510. {
  511. if (share->tgt_dbs[roop_count])
  512. spider_free(spider_current_trx, share->tgt_dbs[roop_count], MYF(0));
  513. }
  514. spider_free(spider_current_trx, share->tgt_dbs, MYF(0));
  515. }
  516. if (share->tgt_hosts)
  517. {
  518. for (roop_count = 0; roop_count < (int) share->tgt_hosts_length;
  519. roop_count++)
  520. {
  521. if (share->tgt_hosts[roop_count])
  522. spider_free(spider_current_trx, share->tgt_hosts[roop_count], MYF(0));
  523. }
  524. spider_free(spider_current_trx, share->tgt_hosts, MYF(0));
  525. }
  526. if (share->tgt_usernames)
  527. {
  528. for (roop_count = 0; roop_count < (int) share->tgt_usernames_length;
  529. roop_count++)
  530. {
  531. if (share->tgt_usernames[roop_count])
  532. spider_free(spider_current_trx, share->tgt_usernames[roop_count],
  533. MYF(0));
  534. }
  535. spider_free(spider_current_trx, share->tgt_usernames, MYF(0));
  536. }
  537. if (share->tgt_passwords)
  538. {
  539. for (roop_count = 0; roop_count < (int) share->tgt_passwords_length;
  540. roop_count++)
  541. {
  542. if (share->tgt_passwords[roop_count])
  543. spider_free(spider_current_trx, share->tgt_passwords[roop_count],
  544. MYF(0));
  545. }
  546. spider_free(spider_current_trx, share->tgt_passwords, MYF(0));
  547. }
  548. if (share->tgt_sockets)
  549. {
  550. for (roop_count = 0; roop_count < (int) share->tgt_sockets_length;
  551. roop_count++)
  552. {
  553. if (share->tgt_sockets[roop_count])
  554. spider_free(spider_current_trx, share->tgt_sockets[roop_count],
  555. MYF(0));
  556. }
  557. spider_free(spider_current_trx, share->tgt_sockets, MYF(0));
  558. }
  559. if (share->tgt_wrappers)
  560. {
  561. for (roop_count = 0; roop_count < (int) share->tgt_wrappers_length;
  562. roop_count++)
  563. {
  564. if (share->tgt_wrappers[roop_count])
  565. spider_free(spider_current_trx, share->tgt_wrappers[roop_count],
  566. MYF(0));
  567. }
  568. spider_free(spider_current_trx, share->tgt_wrappers, MYF(0));
  569. }
  570. if (share->tgt_ssl_cas)
  571. {
  572. for (roop_count = 0; roop_count < (int) share->tgt_ssl_cas_length;
  573. roop_count++)
  574. {
  575. if (share->tgt_ssl_cas[roop_count])
  576. spider_free(spider_current_trx, share->tgt_ssl_cas[roop_count],
  577. MYF(0));
  578. }
  579. spider_free(spider_current_trx, share->tgt_ssl_cas, MYF(0));
  580. }
  581. if (share->tgt_ssl_capaths)
  582. {
  583. for (roop_count = 0; roop_count < (int) share->tgt_ssl_capaths_length;
  584. roop_count++)
  585. {
  586. if (share->tgt_ssl_capaths[roop_count])
  587. spider_free(spider_current_trx, share->tgt_ssl_capaths[roop_count],
  588. MYF(0));
  589. }
  590. spider_free(spider_current_trx, share->tgt_ssl_capaths, MYF(0));
  591. }
  592. if (share->tgt_ssl_certs)
  593. {
  594. for (roop_count = 0; roop_count < (int) share->tgt_ssl_certs_length;
  595. roop_count++)
  596. {
  597. if (share->tgt_ssl_certs[roop_count])
  598. spider_free(spider_current_trx, share->tgt_ssl_certs[roop_count],
  599. MYF(0));
  600. }
  601. spider_free(spider_current_trx, share->tgt_ssl_certs, MYF(0));
  602. }
  603. if (share->tgt_ssl_ciphers)
  604. {
  605. for (roop_count = 0; roop_count < (int) share->tgt_ssl_ciphers_length;
  606. roop_count++)
  607. {
  608. if (share->tgt_ssl_ciphers[roop_count])
  609. spider_free(spider_current_trx, share->tgt_ssl_ciphers[roop_count],
  610. MYF(0));
  611. }
  612. spider_free(spider_current_trx, share->tgt_ssl_ciphers, MYF(0));
  613. }
  614. if (share->tgt_ssl_keys)
  615. {
  616. for (roop_count = 0; roop_count < (int) share->tgt_ssl_keys_length;
  617. roop_count++)
  618. {
  619. if (share->tgt_ssl_keys[roop_count])
  620. spider_free(spider_current_trx, share->tgt_ssl_keys[roop_count],
  621. MYF(0));
  622. }
  623. spider_free(spider_current_trx, share->tgt_ssl_keys, MYF(0));
  624. }
  625. if (share->tgt_default_files)
  626. {
  627. for (roop_count = 0; roop_count < (int) share->tgt_default_files_length;
  628. roop_count++)
  629. {
  630. if (share->tgt_default_files[roop_count])
  631. spider_free(spider_current_trx, share->tgt_default_files[roop_count],
  632. MYF(0));
  633. }
  634. spider_free(spider_current_trx, share->tgt_default_files, MYF(0));
  635. }
  636. if (share->tgt_default_groups)
  637. {
  638. for (roop_count = 0; roop_count < (int) share->tgt_default_groups_length;
  639. roop_count++)
  640. {
  641. if (share->tgt_default_groups[roop_count])
  642. spider_free(spider_current_trx, share->tgt_default_groups[roop_count],
  643. MYF(0));
  644. }
  645. spider_free(spider_current_trx, share->tgt_default_groups, MYF(0));
  646. }
  647. if (share->tgt_pk_names)
  648. {
  649. for (roop_count = 0; roop_count < (int) share->tgt_pk_names_length;
  650. roop_count++)
  651. {
  652. if (share->tgt_pk_names[roop_count])
  653. spider_free(spider_current_trx, share->tgt_pk_names[roop_count],
  654. MYF(0));
  655. }
  656. spider_free(spider_current_trx, share->tgt_pk_names, MYF(0));
  657. }
  658. if (share->tgt_sequence_names)
  659. {
  660. for (roop_count = 0; roop_count < (int) share->tgt_sequence_names_length;
  661. roop_count++)
  662. {
  663. if (share->tgt_sequence_names[roop_count])
  664. spider_free(spider_current_trx, share->tgt_sequence_names[roop_count],
  665. MYF(0));
  666. }
  667. spider_free(spider_current_trx, share->tgt_sequence_names, MYF(0));
  668. }
  669. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  670. if (share->hs_read_socks)
  671. {
  672. for (roop_count = 0; roop_count < (int) share->hs_read_socks_length;
  673. roop_count++)
  674. {
  675. if (share->hs_read_socks[roop_count])
  676. spider_free(spider_current_trx, share->hs_read_socks[roop_count],
  677. MYF(0));
  678. }
  679. spider_free(spider_current_trx, share->hs_read_socks, MYF(0));
  680. }
  681. if (share->hs_write_socks)
  682. {
  683. for (roop_count = 0; roop_count < (int) share->hs_write_socks_length;
  684. roop_count++)
  685. {
  686. if (share->hs_write_socks[roop_count])
  687. spider_free(spider_current_trx, share->hs_write_socks[roop_count],
  688. MYF(0));
  689. }
  690. spider_free(spider_current_trx, share->hs_write_socks, MYF(0));
  691. }
  692. #endif
  693. if (share->bka_engine)
  694. spider_free(spider_current_trx, share->bka_engine, MYF(0));
  695. if (share->conn_keys)
  696. spider_free(spider_current_trx, share->conn_keys, MYF(0));
  697. if (share->tgt_ports)
  698. spider_free(spider_current_trx, share->tgt_ports, MYF(0));
  699. if (share->tgt_ssl_vscs)
  700. spider_free(spider_current_trx, share->tgt_ssl_vscs, MYF(0));
  701. if (share->link_statuses)
  702. spider_free(spider_current_trx, share->link_statuses, MYF(0));
  703. #ifndef WITHOUT_SPIDER_BG_SEARCH
  704. if (share->monitoring_bg_kind)
  705. spider_free(spider_current_trx, share->monitoring_bg_kind, MYF(0));
  706. #endif
  707. if (share->monitoring_kind)
  708. spider_free(spider_current_trx, share->monitoring_kind, MYF(0));
  709. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  710. if (share->use_hs_reads)
  711. spider_free(spider_current_trx, share->use_hs_reads, MYF(0));
  712. if (share->use_hs_writes)
  713. spider_free(spider_current_trx, share->use_hs_writes, MYF(0));
  714. if (share->hs_read_ports)
  715. spider_free(spider_current_trx, share->hs_read_ports, MYF(0));
  716. if (share->hs_write_ports)
  717. spider_free(spider_current_trx, share->hs_write_ports, MYF(0));
  718. if (share->hs_write_to_reads)
  719. spider_free(spider_current_trx, share->hs_write_to_reads, MYF(0));
  720. #endif
  721. if (share->use_handlers)
  722. spider_free(spider_current_trx, share->use_handlers, MYF(0));
  723. if (share->connect_timeouts)
  724. spider_free(spider_current_trx, share->connect_timeouts, MYF(0));
  725. if (share->net_read_timeouts)
  726. spider_free(spider_current_trx, share->net_read_timeouts, MYF(0));
  727. if (share->net_write_timeouts)
  728. spider_free(spider_current_trx, share->net_write_timeouts, MYF(0));
  729. if (share->access_balances)
  730. spider_free(spider_current_trx, share->access_balances, MYF(0));
  731. #ifndef WITHOUT_SPIDER_BG_SEARCH
  732. if (share->monitoring_bg_interval)
  733. spider_free(spider_current_trx, share->monitoring_bg_interval, MYF(0));
  734. #endif
  735. if (share->monitoring_limit)
  736. spider_free(spider_current_trx, share->monitoring_limit, MYF(0));
  737. if (share->monitoring_sid)
  738. spider_free(spider_current_trx, share->monitoring_sid, MYF(0));
  739. if (share->alter_table.tmp_server_names)
  740. spider_free(spider_current_trx, share->alter_table.tmp_server_names,
  741. MYF(0));
  742. if (share->key_hint)
  743. {
  744. delete [] share->key_hint;
  745. share->key_hint = NULL;
  746. }
  747. #ifdef WITH_PARTITION_STORAGE_ENGINE
  748. if (share->partition_share)
  749. spider_free_pt_share(share->partition_share);
  750. #endif
  751. DBUG_RETURN(0);
  752. }
  753. void spider_free_tmp_share_alloc(
  754. SPIDER_SHARE *share
  755. ) {
  756. DBUG_ENTER("spider_free_tmp_share_alloc");
  757. if (share->server_names && share->server_names[0])
  758. {
  759. spider_free(spider_current_trx, share->server_names[0], MYF(0));
  760. share->server_names[0] = NULL;
  761. }
  762. if (share->tgt_table_names && share->tgt_table_names[0])
  763. {
  764. spider_free(spider_current_trx, share->tgt_table_names[0], MYF(0));
  765. share->tgt_table_names[0] = NULL;
  766. }
  767. if (share->tgt_dbs && share->tgt_dbs[0])
  768. {
  769. spider_free(spider_current_trx, share->tgt_dbs[0], MYF(0));
  770. share->tgt_dbs[0] = NULL;
  771. }
  772. if (share->tgt_hosts && share->tgt_hosts[0])
  773. {
  774. spider_free(spider_current_trx, share->tgt_hosts[0], MYF(0));
  775. share->tgt_hosts[0] = NULL;
  776. }
  777. if (share->tgt_usernames && share->tgt_usernames[0])
  778. {
  779. spider_free(spider_current_trx, share->tgt_usernames[0], MYF(0));
  780. share->tgt_usernames[0] = NULL;
  781. }
  782. if (share->tgt_passwords && share->tgt_passwords[0])
  783. {
  784. spider_free(spider_current_trx, share->tgt_passwords[0], MYF(0));
  785. share->tgt_passwords[0] = NULL;
  786. }
  787. if (share->tgt_sockets && share->tgt_sockets[0])
  788. {
  789. spider_free(spider_current_trx, share->tgt_sockets[0], MYF(0));
  790. share->tgt_sockets[0] = NULL;
  791. }
  792. if (share->tgt_wrappers && share->tgt_wrappers[0])
  793. {
  794. spider_free(spider_current_trx, share->tgt_wrappers[0], MYF(0));
  795. share->tgt_wrappers[0] = NULL;
  796. }
  797. if (share->tgt_ssl_cas && share->tgt_ssl_cas[0])
  798. {
  799. spider_free(spider_current_trx, share->tgt_ssl_cas[0], MYF(0));
  800. share->tgt_ssl_cas[0] = NULL;
  801. }
  802. if (share->tgt_ssl_capaths && share->tgt_ssl_capaths[0])
  803. {
  804. spider_free(spider_current_trx, share->tgt_ssl_capaths[0], MYF(0));
  805. share->tgt_ssl_capaths[0] = NULL;
  806. }
  807. if (share->tgt_ssl_certs && share->tgt_ssl_certs[0])
  808. {
  809. spider_free(spider_current_trx, share->tgt_ssl_certs[0], MYF(0));
  810. share->tgt_ssl_certs[0] = NULL;
  811. }
  812. if (share->tgt_ssl_ciphers && share->tgt_ssl_ciphers[0])
  813. {
  814. spider_free(spider_current_trx, share->tgt_ssl_ciphers[0], MYF(0));
  815. share->tgt_ssl_ciphers[0] = NULL;
  816. }
  817. if (share->tgt_ssl_keys && share->tgt_ssl_keys[0])
  818. {
  819. spider_free(spider_current_trx, share->tgt_ssl_keys[0], MYF(0));
  820. share->tgt_ssl_keys[0] = NULL;
  821. }
  822. if (share->tgt_default_files && share->tgt_default_files[0])
  823. {
  824. spider_free(spider_current_trx, share->tgt_default_files[0], MYF(0));
  825. share->tgt_default_files[0] = NULL;
  826. }
  827. if (share->tgt_default_groups && share->tgt_default_groups[0])
  828. {
  829. spider_free(spider_current_trx, share->tgt_default_groups[0], MYF(0));
  830. share->tgt_default_groups[0] = NULL;
  831. }
  832. if (share->tgt_pk_names && share->tgt_pk_names[0])
  833. {
  834. spider_free(spider_current_trx, share->tgt_pk_names[0], MYF(0));
  835. share->tgt_pk_names[0] = NULL;
  836. }
  837. if (share->tgt_sequence_names && share->tgt_sequence_names[0])
  838. {
  839. spider_free(spider_current_trx, share->tgt_sequence_names[0], MYF(0));
  840. share->tgt_sequence_names[0] = NULL;
  841. }
  842. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  843. if (share->hs_read_socks && share->hs_read_socks[0])
  844. {
  845. spider_free(spider_current_trx, share->hs_read_socks[0], MYF(0));
  846. share->hs_read_socks[0] = NULL;
  847. }
  848. if (share->hs_write_socks && share->hs_write_socks[0])
  849. {
  850. spider_free(spider_current_trx, share->hs_write_socks[0], MYF(0));
  851. share->hs_write_socks[0] = NULL;
  852. }
  853. #endif
  854. if (share->bka_engine)
  855. {
  856. spider_free(spider_current_trx, share->bka_engine, MYF(0));
  857. share->bka_engine = NULL;
  858. }
  859. if (share->conn_keys)
  860. {
  861. spider_free(spider_current_trx, share->conn_keys, MYF(0));
  862. share->conn_keys = NULL;
  863. }
  864. if (share->key_hint)
  865. {
  866. delete [] share->key_hint;
  867. share->key_hint = NULL;
  868. }
  869. DBUG_VOID_RETURN;
  870. }
  871. char *spider_get_string_between_quote(
  872. char *ptr,
  873. bool alloc
  874. ) {
  875. char *start_ptr, *end_ptr, *tmp_ptr, *esc_ptr;
  876. bool find_flg = FALSE, esc_flg = FALSE;
  877. DBUG_ENTER("spider_get_string_between_quote");
  878. start_ptr = strchr(ptr, '\'');
  879. end_ptr = strchr(ptr, '"');
  880. if (start_ptr && (!end_ptr || start_ptr < end_ptr))
  881. {
  882. tmp_ptr = ++start_ptr;
  883. while (!find_flg)
  884. {
  885. if (!(end_ptr = strchr(tmp_ptr, '\'')))
  886. DBUG_RETURN(NULL);
  887. esc_ptr = tmp_ptr;
  888. while (!find_flg)
  889. {
  890. esc_ptr = strchr(esc_ptr, '\\');
  891. if (!esc_ptr || esc_ptr > end_ptr)
  892. find_flg = TRUE;
  893. else if (esc_ptr == end_ptr - 1)
  894. {
  895. esc_flg = TRUE;
  896. tmp_ptr = end_ptr + 1;
  897. break;
  898. } else {
  899. esc_flg = TRUE;
  900. esc_ptr += 2;
  901. }
  902. }
  903. }
  904. } else if (end_ptr)
  905. {
  906. start_ptr = end_ptr;
  907. tmp_ptr = ++start_ptr;
  908. while (!find_flg)
  909. {
  910. if (!(end_ptr = strchr(tmp_ptr, '"')))
  911. DBUG_RETURN(NULL);
  912. esc_ptr = tmp_ptr;
  913. while (!find_flg)
  914. {
  915. esc_ptr = strchr(esc_ptr, '\\');
  916. if (!esc_ptr || esc_ptr > end_ptr)
  917. find_flg = TRUE;
  918. else if (esc_ptr == end_ptr - 1)
  919. {
  920. esc_flg = TRUE;
  921. tmp_ptr = end_ptr + 1;
  922. break;
  923. } else {
  924. esc_flg = TRUE;
  925. esc_ptr += 2;
  926. }
  927. }
  928. }
  929. } else
  930. DBUG_RETURN(NULL);
  931. *end_ptr = '\0';
  932. if (esc_flg)
  933. {
  934. esc_ptr = start_ptr;
  935. while (TRUE)
  936. {
  937. esc_ptr = strchr(esc_ptr, '\\');
  938. if (!esc_ptr)
  939. break;
  940. switch(*(esc_ptr + 1))
  941. {
  942. case 'b':
  943. *esc_ptr = '\b';
  944. break;
  945. case 'n':
  946. *esc_ptr = '\n';
  947. break;
  948. case 'r':
  949. *esc_ptr = '\r';
  950. break;
  951. case 't':
  952. *esc_ptr = '\t';
  953. break;
  954. default:
  955. *esc_ptr = *(esc_ptr + 1);
  956. break;
  957. }
  958. esc_ptr++;
  959. strcpy(esc_ptr, esc_ptr + 1);
  960. }
  961. }
  962. if (alloc)
  963. {
  964. DBUG_RETURN(
  965. spider_create_string(
  966. start_ptr,
  967. strlen(start_ptr))
  968. );
  969. } else {
  970. DBUG_RETURN(start_ptr);
  971. }
  972. }
  973. int spider_create_string_list(
  974. char ***string_list,
  975. uint **string_length_list,
  976. uint *list_length,
  977. char *str,
  978. uint length
  979. ) {
  980. int roop_count;
  981. char *tmp_ptr, *tmp_ptr2, *tmp_ptr3, *esc_ptr;
  982. bool find_flg = FALSE;
  983. DBUG_ENTER("spider_create_string_list");
  984. *list_length = 0;
  985. if (!str)
  986. {
  987. *string_list = NULL;
  988. DBUG_RETURN(0);
  989. }
  990. tmp_ptr = str;
  991. while (*tmp_ptr == ' ')
  992. tmp_ptr++;
  993. if (*tmp_ptr)
  994. *list_length = 1;
  995. else {
  996. *string_list = NULL;
  997. DBUG_RETURN(0);
  998. }
  999. while (TRUE)
  1000. {
  1001. if ((tmp_ptr2 = strchr(tmp_ptr, ' ')))
  1002. {
  1003. esc_ptr = tmp_ptr;
  1004. while (!find_flg)
  1005. {
  1006. esc_ptr = strchr(esc_ptr, '\\');
  1007. if (!esc_ptr || esc_ptr > tmp_ptr2)
  1008. find_flg = TRUE;
  1009. else if (esc_ptr == tmp_ptr2 - 1)
  1010. {
  1011. tmp_ptr = tmp_ptr2 + 1;
  1012. break;
  1013. } else
  1014. esc_ptr += 2;
  1015. }
  1016. if (find_flg)
  1017. {
  1018. (*list_length)++;
  1019. tmp_ptr = tmp_ptr2 + 1;
  1020. while (*tmp_ptr == ' ')
  1021. tmp_ptr++;
  1022. }
  1023. } else
  1024. break;
  1025. }
  1026. if (!(*string_list = (char**)
  1027. spider_bulk_malloc(spider_current_trx, 37, MYF(MY_WME | MY_ZEROFILL),
  1028. string_list, sizeof(char*) * (*list_length),
  1029. string_length_list, sizeof(int) * (*list_length),
  1030. NullS))
  1031. ) {
  1032. my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
  1033. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  1034. }
  1035. tmp_ptr = str;
  1036. while (*tmp_ptr == ' ')
  1037. {
  1038. *tmp_ptr = '\0';
  1039. tmp_ptr++;
  1040. }
  1041. tmp_ptr3 = tmp_ptr;
  1042. for (roop_count = 0; roop_count < (int) *list_length - 1; roop_count++)
  1043. {
  1044. while (TRUE)
  1045. {
  1046. tmp_ptr2 = strchr(tmp_ptr, ' ');
  1047. esc_ptr = tmp_ptr;
  1048. while (!find_flg)
  1049. {
  1050. esc_ptr = strchr(esc_ptr, '\\');
  1051. if (!esc_ptr || esc_ptr > tmp_ptr2)
  1052. find_flg = TRUE;
  1053. else if (esc_ptr == tmp_ptr2 - 1)
  1054. {
  1055. tmp_ptr = tmp_ptr2 + 1;
  1056. break;
  1057. } else
  1058. esc_ptr += 2;
  1059. }
  1060. if (find_flg)
  1061. break;
  1062. }
  1063. tmp_ptr = tmp_ptr2;
  1064. while (*tmp_ptr == ' ')
  1065. {
  1066. *tmp_ptr = '\0';
  1067. tmp_ptr++;
  1068. }
  1069. (*string_length_list)[roop_count] = strlen(tmp_ptr3);
  1070. if (!((*string_list)[roop_count] = spider_create_string(
  1071. tmp_ptr3, (*string_length_list)[roop_count]))
  1072. ) {
  1073. my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
  1074. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  1075. }
  1076. DBUG_PRINT("info",("spider string_list[%d]=%s", roop_count,
  1077. (*string_list)[roop_count]));
  1078. tmp_ptr3 = tmp_ptr;
  1079. }
  1080. (*string_length_list)[roop_count] = strlen(tmp_ptr3);
  1081. if (!((*string_list)[roop_count] = spider_create_string(
  1082. tmp_ptr3, (*string_length_list)[roop_count]))
  1083. ) {
  1084. my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
  1085. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  1086. }
  1087. DBUG_PRINT("info",("spider string_list[%d]=%s", roop_count,
  1088. (*string_list)[roop_count]));
  1089. DBUG_RETURN(0);
  1090. }
  1091. int spider_create_long_list(
  1092. long **long_list,
  1093. uint *list_length,
  1094. char *str,
  1095. uint length,
  1096. long min_val,
  1097. long max_val
  1098. ) {
  1099. int roop_count;
  1100. char *tmp_ptr;
  1101. DBUG_ENTER("spider_create_long_list");
  1102. *list_length = 0;
  1103. if (!str)
  1104. {
  1105. *long_list = NULL;
  1106. DBUG_RETURN(0);
  1107. }
  1108. tmp_ptr = str;
  1109. while (*tmp_ptr == ' ')
  1110. tmp_ptr++;
  1111. if (*tmp_ptr)
  1112. *list_length = 1;
  1113. else {
  1114. *long_list = NULL;
  1115. DBUG_RETURN(0);
  1116. }
  1117. while (TRUE)
  1118. {
  1119. if ((tmp_ptr = strchr(tmp_ptr, ' ')))
  1120. {
  1121. (*list_length)++;
  1122. tmp_ptr = tmp_ptr + 1;
  1123. while (*tmp_ptr == ' ')
  1124. tmp_ptr++;
  1125. } else
  1126. break;
  1127. }
  1128. if (!(*long_list = (long*)
  1129. spider_bulk_malloc(spider_current_trx, 38, MYF(MY_WME | MY_ZEROFILL),
  1130. long_list, sizeof(long) * (*list_length),
  1131. NullS))
  1132. ) {
  1133. my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
  1134. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  1135. }
  1136. tmp_ptr = str;
  1137. for (roop_count = 0; roop_count < (int) *list_length; roop_count++)
  1138. {
  1139. if (roop_count != 0)
  1140. tmp_ptr = strchr(tmp_ptr, ' ');
  1141. while (*tmp_ptr == ' ')
  1142. {
  1143. *tmp_ptr = '\0';
  1144. tmp_ptr++;
  1145. }
  1146. (*long_list)[roop_count] = atol(tmp_ptr);
  1147. if ((*long_list)[roop_count] < min_val)
  1148. (*long_list)[roop_count] = min_val;
  1149. else if ((*long_list)[roop_count] > max_val)
  1150. (*long_list)[roop_count] = max_val;
  1151. }
  1152. #ifndef DBUG_OFF
  1153. for (roop_count = 0; roop_count < (int) *list_length; roop_count++)
  1154. {
  1155. DBUG_PRINT("info",("spider long_list[%d]=%ld", roop_count,
  1156. (*long_list)[roop_count]));
  1157. }
  1158. #endif
  1159. DBUG_RETURN(0);
  1160. }
  1161. int spider_create_longlong_list(
  1162. longlong **longlong_list,
  1163. uint *list_length,
  1164. char *str,
  1165. uint length,
  1166. longlong min_val,
  1167. longlong max_val
  1168. ) {
  1169. int error_num, roop_count;
  1170. char *tmp_ptr;
  1171. DBUG_ENTER("spider_create_longlong_list");
  1172. *list_length = 0;
  1173. if (!str)
  1174. {
  1175. *longlong_list = NULL;
  1176. DBUG_RETURN(0);
  1177. }
  1178. tmp_ptr = str;
  1179. while (*tmp_ptr == ' ')
  1180. tmp_ptr++;
  1181. if (*tmp_ptr)
  1182. *list_length = 1;
  1183. else {
  1184. *longlong_list = NULL;
  1185. DBUG_RETURN(0);
  1186. }
  1187. while (TRUE)
  1188. {
  1189. if ((tmp_ptr = strchr(tmp_ptr, ' ')))
  1190. {
  1191. (*list_length)++;
  1192. tmp_ptr = tmp_ptr + 1;
  1193. while (*tmp_ptr == ' ')
  1194. tmp_ptr++;
  1195. } else
  1196. break;
  1197. }
  1198. if (!(*longlong_list = (longlong *)
  1199. spider_bulk_malloc(spider_current_trx, 39, MYF(MY_WME | MY_ZEROFILL),
  1200. longlong_list, sizeof(longlong) * (*list_length),
  1201. NullS))
  1202. ) {
  1203. my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
  1204. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  1205. }
  1206. tmp_ptr = str;
  1207. for (roop_count = 0; roop_count < (int) *list_length; roop_count++)
  1208. {
  1209. if (roop_count != 0)
  1210. tmp_ptr = strchr(tmp_ptr, ' ');
  1211. while (*tmp_ptr == ' ')
  1212. {
  1213. *tmp_ptr = '\0';
  1214. tmp_ptr++;
  1215. }
  1216. (*longlong_list)[roop_count] = my_strtoll10(tmp_ptr, (char**) NULL,
  1217. &error_num);
  1218. if ((*longlong_list)[roop_count] < min_val)
  1219. (*longlong_list)[roop_count] = min_val;
  1220. else if ((*longlong_list)[roop_count] > max_val)
  1221. (*longlong_list)[roop_count] = max_val;
  1222. }
  1223. #ifndef DBUG_OFF
  1224. for (roop_count = 0; roop_count < (int) *list_length; roop_count++)
  1225. {
  1226. DBUG_PRINT("info",("spider longlong_list[%d]=%lld", roop_count,
  1227. (*longlong_list)[roop_count]));
  1228. }
  1229. #endif
  1230. DBUG_RETURN(0);
  1231. }
  1232. int spider_increase_string_list(
  1233. char ***string_list,
  1234. uint **string_length_list,
  1235. uint *list_length,
  1236. uint *list_charlen,
  1237. uint link_count
  1238. ) {
  1239. int roop_count;
  1240. char **tmp_str_list, *tmp_str;
  1241. uint *tmp_length_list, tmp_length;
  1242. DBUG_ENTER("spider_increase_string_list");
  1243. if (*list_length == link_count)
  1244. DBUG_RETURN(0);
  1245. if (*list_length > 1)
  1246. {
  1247. my_printf_error(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM,
  1248. ER_SPIDER_DIFFERENT_LINK_COUNT_STR, MYF(0));
  1249. DBUG_RETURN(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM);
  1250. }
  1251. if (*string_list)
  1252. {
  1253. tmp_str = (*string_list)[0];
  1254. tmp_length = (*string_length_list)[0];
  1255. } else {
  1256. tmp_str = NULL;
  1257. tmp_length = 0;
  1258. }
  1259. if (!(tmp_str_list = (char**)
  1260. spider_bulk_malloc(spider_current_trx, 40, MYF(MY_WME | MY_ZEROFILL),
  1261. &tmp_str_list, sizeof(char*) * link_count,
  1262. &tmp_length_list, sizeof(uint) * link_count,
  1263. NullS))
  1264. ) {
  1265. my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
  1266. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  1267. }
  1268. for (roop_count = 0; roop_count < (int) link_count; roop_count++)
  1269. {
  1270. tmp_length_list[roop_count] = tmp_length;
  1271. if (tmp_str)
  1272. {
  1273. if (!(tmp_str_list[roop_count] = spider_create_string(
  1274. tmp_str, tmp_length))
  1275. )
  1276. goto error;
  1277. DBUG_PRINT("info",("spider string_list[%d]=%s", roop_count,
  1278. tmp_str_list[roop_count]));
  1279. } else
  1280. tmp_str_list[roop_count] = NULL;
  1281. }
  1282. if (*string_list)
  1283. {
  1284. if ((*string_list)[0])
  1285. spider_free(spider_current_trx, (*string_list)[0], MYF(0));
  1286. spider_free(spider_current_trx, *string_list, MYF(0));
  1287. }
  1288. *list_charlen = (tmp_length + 1) * link_count - 1;
  1289. *list_length = link_count;
  1290. *string_list = tmp_str_list;
  1291. *string_length_list = tmp_length_list;
  1292. DBUG_RETURN(0);
  1293. error:
  1294. for (roop_count = 0; roop_count < (int) link_count; roop_count++)
  1295. {
  1296. if (tmp_str_list[roop_count])
  1297. spider_free(spider_current_trx, tmp_str_list[roop_count], MYF(0));
  1298. }
  1299. if (tmp_str_list)
  1300. spider_free(spider_current_trx, tmp_str_list, MYF(0));
  1301. my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
  1302. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  1303. }
  1304. int spider_increase_long_list(
  1305. long **long_list,
  1306. uint *list_length,
  1307. uint link_count
  1308. ) {
  1309. int roop_count;
  1310. long *tmp_long_list, tmp_long;
  1311. DBUG_ENTER("spider_increase_long_list");
  1312. if (*list_length == link_count)
  1313. DBUG_RETURN(0);
  1314. if (*list_length > 1)
  1315. {
  1316. my_printf_error(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM,
  1317. ER_SPIDER_DIFFERENT_LINK_COUNT_STR, MYF(0));
  1318. DBUG_RETURN(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM);
  1319. }
  1320. if (*long_list)
  1321. tmp_long = (*long_list)[0];
  1322. else
  1323. tmp_long = -1;
  1324. if (!(tmp_long_list = (long*)
  1325. spider_bulk_malloc(spider_current_trx, 41, MYF(MY_WME | MY_ZEROFILL),
  1326. &tmp_long_list, sizeof(long) * link_count,
  1327. NullS))
  1328. ) {
  1329. my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
  1330. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  1331. }
  1332. for (roop_count = 0; roop_count < (int) link_count; roop_count++)
  1333. {
  1334. tmp_long_list[roop_count] = tmp_long;
  1335. DBUG_PRINT("info",("spider long_list[%d]=%ld", roop_count,
  1336. tmp_long));
  1337. }
  1338. if (*long_list)
  1339. spider_free(spider_current_trx, *long_list, MYF(0));
  1340. *list_length = link_count;
  1341. *long_list = tmp_long_list;
  1342. DBUG_RETURN(0);
  1343. }
  1344. int spider_increase_longlong_list(
  1345. longlong **longlong_list,
  1346. uint *list_length,
  1347. uint link_count
  1348. ) {
  1349. int roop_count;
  1350. longlong *tmp_longlong_list, tmp_longlong;
  1351. DBUG_ENTER("spider_increase_longlong_list");
  1352. if (*list_length == link_count)
  1353. DBUG_RETURN(0);
  1354. if (*list_length > 1)
  1355. {
  1356. my_printf_error(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM,
  1357. ER_SPIDER_DIFFERENT_LINK_COUNT_STR, MYF(0));
  1358. DBUG_RETURN(ER_SPIDER_DIFFERENT_LINK_COUNT_NUM);
  1359. }
  1360. if (*longlong_list)
  1361. tmp_longlong = (*longlong_list)[0];
  1362. else
  1363. tmp_longlong = -1;
  1364. if (!(tmp_longlong_list = (longlong*)
  1365. spider_bulk_malloc(spider_current_trx, 42, MYF(MY_WME | MY_ZEROFILL),
  1366. &tmp_longlong_list, sizeof(longlong) * link_count,
  1367. NullS))
  1368. ) {
  1369. my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
  1370. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  1371. }
  1372. for (roop_count = 0; roop_count < (int) link_count; roop_count++)
  1373. {
  1374. tmp_longlong_list[roop_count] = tmp_longlong;
  1375. DBUG_PRINT("info",("spider longlong_list[%d]=%lld", roop_count,
  1376. tmp_longlong));
  1377. }
  1378. if (*longlong_list)
  1379. spider_free(spider_current_trx, *longlong_list, MYF(0));
  1380. *list_length = link_count;
  1381. *longlong_list = tmp_longlong_list;
  1382. DBUG_RETURN(0);
  1383. }
  1384. #define SPIDER_PARAM_STR_LEN(name) name ## _length
  1385. #define SPIDER_PARAM_STR(title_name, param_name) \
  1386. if (!strncasecmp(tmp_ptr, title_name, title_length)) \
  1387. { \
  1388. DBUG_PRINT("info",("spider "title_name" start")); \
  1389. if (!share->param_name) \
  1390. { \
  1391. if ((share->param_name = spider_get_string_between_quote( \
  1392. start_ptr, TRUE))) \
  1393. share->SPIDER_PARAM_STR_LEN(param_name) = strlen(share->param_name); \
  1394. else { \
  1395. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \
  1396. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \
  1397. MYF(0), tmp_ptr); \
  1398. goto error; \
  1399. } \
  1400. DBUG_PRINT("info",("spider "title_name"=%s", share->param_name)); \
  1401. } \
  1402. break; \
  1403. }
  1404. #define SPIDER_PARAM_STR_LENS(name) name ## _lengths
  1405. #define SPIDER_PARAM_STR_CHARLEN(name) name ## _charlen
  1406. #define SPIDER_PARAM_STR_LIST(title_name, param_name) \
  1407. if (!strncasecmp(tmp_ptr, title_name, title_length)) \
  1408. { \
  1409. DBUG_PRINT("info",("spider "title_name" start")); \
  1410. if (!share->param_name) \
  1411. { \
  1412. if ((tmp_ptr2 = spider_get_string_between_quote( \
  1413. start_ptr, FALSE))) \
  1414. { \
  1415. share->SPIDER_PARAM_STR_CHARLEN(param_name) = strlen(tmp_ptr2); \
  1416. if ((error_num = spider_create_string_list( \
  1417. &share->param_name, \
  1418. &share->SPIDER_PARAM_STR_LENS(param_name), \
  1419. &share->SPIDER_PARAM_STR_LEN(param_name), \
  1420. tmp_ptr2, \
  1421. share->SPIDER_PARAM_STR_CHARLEN(param_name)))) \
  1422. goto error; \
  1423. } else { \
  1424. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \
  1425. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \
  1426. MYF(0), tmp_ptr); \
  1427. goto error; \
  1428. } \
  1429. } \
  1430. break; \
  1431. }
  1432. #define SPIDER_PARAM_HINT(title_name, param_name, check_length, max_size, append_method) \
  1433. if (!strncasecmp(tmp_ptr, title_name, check_length)) \
  1434. { \
  1435. DBUG_PRINT("info",("spider "title_name" start")); \
  1436. DBUG_PRINT("info",("spider max_size=%d", max_size)); \
  1437. int hint_num = atoi(tmp_ptr + check_length); \
  1438. DBUG_PRINT("info",("spider hint_num=%d", hint_num)); \
  1439. DBUG_PRINT("info",("spider share->param_name=%p", share->param_name)); \
  1440. if (share->param_name) \
  1441. { \
  1442. if (hint_num < 0 || hint_num >= max_size) \
  1443. { \
  1444. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \
  1445. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \
  1446. MYF(0), tmp_ptr); \
  1447. goto error; \
  1448. } else if (share->param_name[hint_num].length() > 0) \
  1449. break; \
  1450. char *hint_str = spider_get_string_between_quote(start_ptr, FALSE); \
  1451. if ((error_num = \
  1452. append_method(&share->param_name[hint_num], hint_str))) \
  1453. goto error; \
  1454. DBUG_PRINT("info",("spider "title_name"[%d]=%s", hint_num, \
  1455. share->param_name[hint_num].ptr())); \
  1456. } else { \
  1457. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \
  1458. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \
  1459. MYF(0), tmp_ptr); \
  1460. goto error; \
  1461. } \
  1462. break; \
  1463. }
  1464. #define SPIDER_PARAM_LONG_LEN(name) name ## _length
  1465. #define SPIDER_PARAM_LONG_LIST_WITH_MAX(title_name, param_name, \
  1466. min_val, max_val) \
  1467. if (!strncasecmp(tmp_ptr, title_name, title_length)) \
  1468. { \
  1469. DBUG_PRINT("info",("spider "title_name" start")); \
  1470. if (!share->param_name) \
  1471. { \
  1472. if ((tmp_ptr2 = spider_get_string_between_quote( \
  1473. start_ptr, FALSE))) \
  1474. { \
  1475. if ((error_num = spider_create_long_list( \
  1476. &share->param_name, \
  1477. &share->SPIDER_PARAM_LONG_LEN(param_name), \
  1478. tmp_ptr2, \
  1479. strlen(tmp_ptr2), \
  1480. min_val, max_val))) \
  1481. goto error; \
  1482. } else { \
  1483. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \
  1484. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \
  1485. MYF(0), tmp_ptr); \
  1486. goto error; \
  1487. } \
  1488. } \
  1489. break; \
  1490. }
  1491. #define SPIDER_PARAM_LONGLONG_LEN(name) name ## _length
  1492. #define SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(title_name, param_name, \
  1493. min_val, max_val) \
  1494. if (!strncasecmp(tmp_ptr, title_name, title_length)) \
  1495. { \
  1496. DBUG_PRINT("info",("spider "title_name" start")); \
  1497. if (!share->param_name) \
  1498. { \
  1499. if ((tmp_ptr2 = spider_get_string_between_quote( \
  1500. start_ptr, FALSE))) \
  1501. { \
  1502. if ((error_num = spider_create_longlong_list( \
  1503. &share->param_name, \
  1504. &share->SPIDER_PARAM_LONGLONG_LEN(param_name), \
  1505. tmp_ptr2, \
  1506. strlen(tmp_ptr2), \
  1507. min_val, max_val))) \
  1508. goto error; \
  1509. } else { \
  1510. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \
  1511. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \
  1512. MYF(0), tmp_ptr); \
  1513. goto error; \
  1514. } \
  1515. } \
  1516. break; \
  1517. }
  1518. #define SPIDER_PARAM_INT_WITH_MAX(title_name, param_name, min_val, max_val) \
  1519. if (!strncasecmp(tmp_ptr, title_name, title_length)) \
  1520. { \
  1521. DBUG_PRINT("info",("spider "title_name" start")); \
  1522. if (share->param_name == -1) \
  1523. { \
  1524. if ((tmp_ptr2 = spider_get_string_between_quote( \
  1525. start_ptr, FALSE))) \
  1526. { \
  1527. share->param_name = atoi(tmp_ptr2); \
  1528. if (share->param_name < min_val) \
  1529. share->param_name = min_val; \
  1530. else if (share->param_name > max_val) \
  1531. share->param_name = max_val; \
  1532. } else { \
  1533. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \
  1534. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \
  1535. MYF(0), tmp_ptr); \
  1536. goto error; \
  1537. } \
  1538. DBUG_PRINT("info",("spider "title_name"=%d", share->param_name)); \
  1539. } \
  1540. break; \
  1541. }
  1542. #define SPIDER_PARAM_INT(title_name, param_name, min_val) \
  1543. if (!strncasecmp(tmp_ptr, title_name, title_length)) \
  1544. { \
  1545. DBUG_PRINT("info",("spider "title_name" start")); \
  1546. if (share->param_name == -1) \
  1547. { \
  1548. if ((tmp_ptr2 = spider_get_string_between_quote( \
  1549. start_ptr, FALSE))) \
  1550. { \
  1551. share->param_name = atoi(tmp_ptr2); \
  1552. if (share->param_name < min_val) \
  1553. share->param_name = min_val; \
  1554. } else { \
  1555. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \
  1556. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \
  1557. MYF(0), tmp_ptr); \
  1558. goto error; \
  1559. } \
  1560. DBUG_PRINT("info",("spider "title_name"=%d", share->param_name)); \
  1561. } \
  1562. break; \
  1563. }
  1564. #define SPIDER_PARAM_DOUBLE(title_name, param_name, min_val) \
  1565. if (!strncasecmp(tmp_ptr, title_name, title_length)) \
  1566. { \
  1567. DBUG_PRINT("info",("spider "title_name" start")); \
  1568. if (share->param_name == -1) \
  1569. { \
  1570. if ((tmp_ptr2 = spider_get_string_between_quote( \
  1571. start_ptr, FALSE))) \
  1572. { \
  1573. share->param_name = my_atof(tmp_ptr2); \
  1574. if (share->param_name < min_val) \
  1575. share->param_name = min_val; \
  1576. } else { \
  1577. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \
  1578. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \
  1579. MYF(0), tmp_ptr); \
  1580. goto error; \
  1581. } \
  1582. DBUG_PRINT("info",("spider "title_name"=%f", share->param_name)); \
  1583. } \
  1584. break; \
  1585. }
  1586. #define SPIDER_PARAM_LONGLONG(title_name, param_name, min_val) \
  1587. if (!strncasecmp(tmp_ptr, title_name, title_length)) \
  1588. { \
  1589. DBUG_PRINT("info",("spider "title_name" start")); \
  1590. if (share->param_name == -1) \
  1591. { \
  1592. if ((tmp_ptr2 = spider_get_string_between_quote( \
  1593. start_ptr, FALSE))) \
  1594. { \
  1595. share->param_name = my_strtoll10(tmp_ptr2, (char**) NULL, &error_num); \
  1596. if (share->param_name < min_val) \
  1597. share->param_name = min_val; \
  1598. } else { \
  1599. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM; \
  1600. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR, \
  1601. MYF(0), tmp_ptr); \
  1602. goto error; \
  1603. } \
  1604. DBUG_PRINT("info",("spider "title_name"=%lld", share->param_name)); \
  1605. } \
  1606. break; \
  1607. }
  1608. int spider_parse_connect_info(
  1609. SPIDER_SHARE *share,
  1610. TABLE_SHARE *table_share,
  1611. #ifdef WITH_PARTITION_STORAGE_ENGINE
  1612. partition_info *part_info,
  1613. #endif
  1614. uint create_table
  1615. ) {
  1616. int error_num = 0;
  1617. char *connect_string = NULL;
  1618. char *sprit_ptr[2];
  1619. char *tmp_ptr, *tmp_ptr2, *start_ptr;
  1620. int roop_count;
  1621. int title_length;
  1622. SPIDER_ALTER_TABLE *share_alter;
  1623. #ifdef WITH_PARTITION_STORAGE_ENGINE
  1624. partition_element *part_elem;
  1625. partition_element *sub_elem;
  1626. #endif
  1627. DBUG_ENTER("spider_parse_connect_info");
  1628. #ifdef WITH_PARTITION_STORAGE_ENGINE
  1629. #if MYSQL_VERSION_ID < 50500
  1630. DBUG_PRINT("info",("spider partition_info=%s", table_share->partition_info));
  1631. #else
  1632. DBUG_PRINT("info",("spider partition_info=%s",
  1633. table_share->partition_info_str));
  1634. #endif
  1635. DBUG_PRINT("info",("spider part_info=%p", part_info));
  1636. #endif
  1637. DBUG_PRINT("info",("spider s->db=%s", table_share->db.str));
  1638. DBUG_PRINT("info",("spider s->table_name=%s", table_share->table_name.str));
  1639. DBUG_PRINT("info",("spider s->path=%s", table_share->path.str));
  1640. DBUG_PRINT("info",
  1641. ("spider s->normalized_path=%s", table_share->normalized_path.str));
  1642. #ifdef WITH_PARTITION_STORAGE_ENGINE
  1643. spider_get_partition_info(share->table_name, share->table_name_length,
  1644. table_share, part_info, &part_elem, &sub_elem);
  1645. #endif
  1646. #ifndef WITHOUT_SPIDER_BG_SEARCH
  1647. share->sts_bg_mode = -1;
  1648. #endif
  1649. share->sts_interval = -1;
  1650. share->sts_mode = -1;
  1651. #ifdef WITH_PARTITION_STORAGE_ENGINE
  1652. share->sts_sync = -1;
  1653. #endif
  1654. #ifndef WITHOUT_SPIDER_BG_SEARCH
  1655. share->crd_bg_mode = -1;
  1656. #endif
  1657. share->crd_interval = -1;
  1658. share->crd_mode = -1;
  1659. #ifdef WITH_PARTITION_STORAGE_ENGINE
  1660. share->crd_sync = -1;
  1661. #endif
  1662. share->crd_type = -1;
  1663. share->crd_weight = -1;
  1664. share->internal_offset = -1;
  1665. share->internal_limit = -1;
  1666. share->split_read = -1;
  1667. share->semi_split_read = -1;
  1668. share->semi_split_read_limit = -1;
  1669. share->init_sql_alloc_size = -1;
  1670. share->reset_sql_alloc = -1;
  1671. share->multi_split_read = -1;
  1672. share->max_order = -1;
  1673. share->semi_table_lock = -1;
  1674. share->semi_table_lock_conn = -1;
  1675. share->selupd_lock_mode = -1;
  1676. share->query_cache = -1;
  1677. share->query_cache_sync = -1;
  1678. share->internal_delayed = -1;
  1679. share->bulk_size = -1;
  1680. share->bulk_update_mode = -1;
  1681. share->bulk_update_size = -1;
  1682. share->internal_optimize = -1;
  1683. share->internal_optimize_local = -1;
  1684. share->scan_rate = -1;
  1685. share->read_rate = -1;
  1686. share->priority = -1;
  1687. share->quick_mode = -1;
  1688. share->quick_page_size = -1;
  1689. share->low_mem_read = -1;
  1690. share->table_count_mode = -1;
  1691. share->select_column_mode = -1;
  1692. #ifndef WITHOUT_SPIDER_BG_SEARCH
  1693. share->bgs_mode = -1;
  1694. share->bgs_first_read = -1;
  1695. share->bgs_second_read = -1;
  1696. #endif
  1697. share->first_read = -1;
  1698. share->second_read = -1;
  1699. share->auto_increment_mode = -1;
  1700. share->use_table_charset = -1;
  1701. share->use_pushdown_udf = -1;
  1702. share->skip_default_condition = -1;
  1703. share->direct_dup_insert = -1;
  1704. share->direct_order_limit = -1;
  1705. share->bka_mode = -1;
  1706. share->read_only_mode = -1;
  1707. share->error_read_mode = -1;
  1708. share->error_write_mode = -1;
  1709. share->active_link_count = -1;
  1710. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  1711. share->hs_result_free_size = -1;
  1712. #endif
  1713. #ifdef HA_CAN_BULK_ACCESS
  1714. share->bulk_access_free = -1;
  1715. #endif
  1716. #ifdef HA_CAN_FORCE_BULK_UPDATE
  1717. share->force_bulk_update = -1;
  1718. #endif
  1719. #ifdef HA_CAN_FORCE_BULK_DELETE
  1720. share->force_bulk_delete = -1;
  1721. #endif
  1722. share->casual_read = -1;
  1723. share->delete_all_rows_type = -1;
  1724. #ifdef WITH_PARTITION_STORAGE_ENGINE
  1725. for (roop_count = 4; roop_count > 0; roop_count--)
  1726. #else
  1727. for (roop_count = 2; roop_count > 0; roop_count--)
  1728. #endif
  1729. {
  1730. if (connect_string)
  1731. {
  1732. spider_free(spider_current_trx, connect_string, MYF(0));
  1733. connect_string = NULL;
  1734. }
  1735. switch (roop_count)
  1736. {
  1737. #ifdef WITH_PARTITION_STORAGE_ENGINE
  1738. case 4:
  1739. if (!sub_elem || !sub_elem->part_comment)
  1740. continue;
  1741. DBUG_PRINT("info",("spider create sub comment string"));
  1742. if (
  1743. !(connect_string = spider_create_string(
  1744. sub_elem->part_comment,
  1745. strlen(sub_elem->part_comment)))
  1746. ) {
  1747. error_num = HA_ERR_OUT_OF_MEM;
  1748. goto error_alloc_conn_string;
  1749. }
  1750. DBUG_PRINT("info",("spider sub comment string=%s", connect_string));
  1751. break;
  1752. case 3:
  1753. if (!part_elem || !part_elem->part_comment)
  1754. continue;
  1755. DBUG_PRINT("info",("spider create part comment string"));
  1756. if (
  1757. !(connect_string = spider_create_string(
  1758. part_elem->part_comment,
  1759. strlen(part_elem->part_comment)))
  1760. ) {
  1761. error_num = HA_ERR_OUT_OF_MEM;
  1762. goto error_alloc_conn_string;
  1763. }
  1764. DBUG_PRINT("info",("spider part comment string=%s", connect_string));
  1765. break;
  1766. #endif
  1767. case 2:
  1768. if (table_share->comment.length == 0)
  1769. continue;
  1770. DBUG_PRINT("info",("spider create comment string"));
  1771. if (
  1772. !(connect_string = spider_create_string(
  1773. table_share->comment.str,
  1774. table_share->comment.length))
  1775. ) {
  1776. error_num = HA_ERR_OUT_OF_MEM;
  1777. goto error_alloc_conn_string;
  1778. }
  1779. DBUG_PRINT("info",("spider comment string=%s", connect_string));
  1780. break;
  1781. default:
  1782. if (table_share->connect_string.length == 0)
  1783. continue;
  1784. DBUG_PRINT("info",("spider create connect_string string"));
  1785. if (
  1786. !(connect_string = spider_create_string(
  1787. table_share->connect_string.str,
  1788. table_share->connect_string.length))
  1789. ) {
  1790. error_num = HA_ERR_OUT_OF_MEM;
  1791. goto error_alloc_conn_string;
  1792. }
  1793. DBUG_PRINT("info",("spider connect_string=%s", connect_string));
  1794. break;
  1795. }
  1796. sprit_ptr[0] = connect_string;
  1797. while (sprit_ptr[0])
  1798. {
  1799. if ((sprit_ptr[1] = strchr(sprit_ptr[0], ',')))
  1800. {
  1801. *sprit_ptr[1] = '\0';
  1802. sprit_ptr[1]++;
  1803. }
  1804. tmp_ptr = sprit_ptr[0];
  1805. sprit_ptr[0] = sprit_ptr[1];
  1806. while (*tmp_ptr == ' ' || *tmp_ptr == '\r' ||
  1807. *tmp_ptr == '\n' || *tmp_ptr == '\t')
  1808. tmp_ptr++;
  1809. if (*tmp_ptr == '\0')
  1810. continue;
  1811. title_length = 0;
  1812. start_ptr = tmp_ptr;
  1813. while (*start_ptr != ' ' && *start_ptr != '\'' &&
  1814. *start_ptr != '"' && *start_ptr != '\0' &&
  1815. *start_ptr != '\r' && *start_ptr != '\n' &&
  1816. *start_ptr != '\t')
  1817. {
  1818. title_length++;
  1819. start_ptr++;
  1820. }
  1821. switch (title_length)
  1822. {
  1823. case 0:
  1824. continue;
  1825. case 3:
  1826. SPIDER_PARAM_LONG_LIST_WITH_MAX("abl", access_balances, 0,
  1827. 2147483647);
  1828. SPIDER_PARAM_INT_WITH_MAX("aim", auto_increment_mode, 0, 3);
  1829. SPIDER_PARAM_INT("alc", active_link_count, 1);
  1830. #ifdef HA_CAN_BULK_ACCESS
  1831. SPIDER_PARAM_INT_WITH_MAX("baf", bulk_access_free, 0, 1);
  1832. #endif
  1833. #ifndef WITHOUT_SPIDER_BG_SEARCH
  1834. SPIDER_PARAM_LONGLONG("bfr", bgs_first_read, 0);
  1835. SPIDER_PARAM_INT("bmd", bgs_mode, 0);
  1836. SPIDER_PARAM_LONGLONG("bsr", bgs_second_read, 0);
  1837. #endif
  1838. SPIDER_PARAM_STR("bke", bka_engine);
  1839. SPIDER_PARAM_INT_WITH_MAX("bkm", bka_mode, 0, 2);
  1840. SPIDER_PARAM_INT("bsz", bulk_size, 0);
  1841. SPIDER_PARAM_INT_WITH_MAX("bum", bulk_update_mode, 0, 2);
  1842. SPIDER_PARAM_INT("bus", bulk_update_size, 0);
  1843. #ifndef WITHOUT_SPIDER_BG_SEARCH
  1844. SPIDER_PARAM_INT_WITH_MAX("cbm", crd_bg_mode, 0, 1);
  1845. #endif
  1846. SPIDER_PARAM_DOUBLE("civ", crd_interval, 0);
  1847. SPIDER_PARAM_INT_WITH_MAX("cmd", crd_mode, 0, 3);
  1848. SPIDER_PARAM_INT_WITH_MAX("csr", casual_read, 0, 63);
  1849. #ifdef WITH_PARTITION_STORAGE_ENGINE
  1850. SPIDER_PARAM_INT_WITH_MAX("csy", crd_sync, 0, 2);
  1851. #endif
  1852. SPIDER_PARAM_LONG_LIST_WITH_MAX("cto", connect_timeouts, 0,
  1853. 2147483647);
  1854. SPIDER_PARAM_INT_WITH_MAX("ctp", crd_type, 0, 2);
  1855. SPIDER_PARAM_DOUBLE("cwg", crd_weight, 1);
  1856. SPIDER_PARAM_INT_WITH_MAX("dat", delete_all_rows_type, 0, 1);
  1857. SPIDER_PARAM_INT_WITH_MAX("ddi", direct_dup_insert, 0, 1);
  1858. SPIDER_PARAM_STR_LIST("dff", tgt_default_files);
  1859. SPIDER_PARAM_STR_LIST("dfg", tgt_default_groups);
  1860. SPIDER_PARAM_LONGLONG("dol", direct_order_limit, 0);
  1861. SPIDER_PARAM_INT_WITH_MAX("erm", error_read_mode, 0, 1);
  1862. SPIDER_PARAM_INT_WITH_MAX("ewm", error_write_mode, 0, 1);
  1863. #ifdef HA_CAN_FORCE_BULK_DELETE
  1864. SPIDER_PARAM_INT_WITH_MAX("fbd", force_bulk_delete, 0, 1);
  1865. #endif
  1866. #ifdef HA_CAN_FORCE_BULK_UPDATE
  1867. SPIDER_PARAM_INT_WITH_MAX("fbu", force_bulk_update, 0, 1);
  1868. #endif
  1869. SPIDER_PARAM_LONGLONG("frd", first_read, 0);
  1870. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  1871. SPIDER_PARAM_LONGLONG("hrf", hs_result_free_size, 0);
  1872. SPIDER_PARAM_LONG_LIST_WITH_MAX(
  1873. "hrp", hs_read_ports, 0, 65535);
  1874. SPIDER_PARAM_STR_LIST("hrs", hs_read_socks);
  1875. SPIDER_PARAM_LONG_LIST_WITH_MAX(
  1876. "hwp", hs_write_ports, 0, 65535);
  1877. SPIDER_PARAM_LONG_LIST_WITH_MAX(
  1878. "hwr", hs_write_to_reads, 0, 1);
  1879. SPIDER_PARAM_STR_LIST("hws", hs_write_socks);
  1880. #endif
  1881. SPIDER_PARAM_INT("isa", init_sql_alloc_size, 0);
  1882. SPIDER_PARAM_INT_WITH_MAX("idl", internal_delayed, 0, 1);
  1883. SPIDER_PARAM_LONGLONG("ilm", internal_limit, 0);
  1884. SPIDER_PARAM_LONGLONG("ios", internal_offset, 0);
  1885. SPIDER_PARAM_INT_WITH_MAX("iom", internal_optimize, 0, 1);
  1886. SPIDER_PARAM_INT_WITH_MAX("iol", internal_optimize_local, 0, 1);
  1887. SPIDER_PARAM_INT_WITH_MAX("lmr", low_mem_read, 0, 1);
  1888. SPIDER_PARAM_LONG_LIST_WITH_MAX("lst", link_statuses, 0, 3);
  1889. #ifndef WITHOUT_SPIDER_BG_SEARCH
  1890. SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(
  1891. "mbi", monitoring_bg_interval, 0, 4294967295LL);
  1892. SPIDER_PARAM_LONG_LIST_WITH_MAX("mbk", monitoring_bg_kind, 0, 3);
  1893. #endif
  1894. SPIDER_PARAM_LONG_LIST_WITH_MAX("mkd", monitoring_kind, 0, 3);
  1895. SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(
  1896. "mlt", monitoring_limit, 0, 9223372036854775807LL);
  1897. SPIDER_PARAM_INT("mod", max_order, 0);
  1898. SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(
  1899. "msi", monitoring_sid, 0, 4294967295LL);
  1900. SPIDER_PARAM_INT_WITH_MAX("msr", multi_split_read, 0, 2147483647);
  1901. SPIDER_PARAM_LONG_LIST_WITH_MAX("nrt", net_read_timeouts, 0,
  1902. 2147483647);
  1903. SPIDER_PARAM_LONG_LIST_WITH_MAX("nwt", net_write_timeouts, 0,
  1904. 2147483647);
  1905. SPIDER_PARAM_STR_LIST("pkn", tgt_pk_names);
  1906. SPIDER_PARAM_LONGLONG("prt", priority, 0);
  1907. SPIDER_PARAM_INT_WITH_MAX("qch", query_cache, 0, 2);
  1908. SPIDER_PARAM_INT_WITH_MAX("qcs", query_cache_sync, 0, 3);
  1909. SPIDER_PARAM_INT_WITH_MAX("qmd", quick_mode, 0, 3);
  1910. SPIDER_PARAM_LONGLONG("qps", quick_page_size, 0);
  1911. SPIDER_PARAM_INT_WITH_MAX("rom", read_only_mode, 0, 1);
  1912. SPIDER_PARAM_DOUBLE("rrt", read_rate, 0);
  1913. SPIDER_PARAM_INT_WITH_MAX("rsa", reset_sql_alloc, 0, 1);
  1914. #ifndef WITHOUT_SPIDER_BG_SEARCH
  1915. SPIDER_PARAM_INT_WITH_MAX("sbm", sts_bg_mode, 0, 1);
  1916. #endif
  1917. SPIDER_PARAM_STR_LIST("sca", tgt_ssl_cas);
  1918. SPIDER_PARAM_STR_LIST("sch", tgt_ssl_ciphers);
  1919. SPIDER_PARAM_INT_WITH_MAX("scm", select_column_mode, 0, 1);
  1920. SPIDER_PARAM_STR_LIST("scp", tgt_ssl_capaths);
  1921. SPIDER_PARAM_STR_LIST("scr", tgt_ssl_certs);
  1922. SPIDER_PARAM_INT_WITH_MAX("sdc", skip_default_condition, 0, 1);
  1923. SPIDER_PARAM_DOUBLE("siv", sts_interval, 0);
  1924. SPIDER_PARAM_STR_LIST("sky", tgt_ssl_keys);
  1925. SPIDER_PARAM_INT_WITH_MAX("slm", selupd_lock_mode, 0, 2);
  1926. SPIDER_PARAM_INT_WITH_MAX("smd", sts_mode, 1, 2);
  1927. SPIDER_PARAM_LONGLONG("spr", split_read, 0);
  1928. SPIDER_PARAM_STR_LIST("sqn", tgt_sequence_names);
  1929. SPIDER_PARAM_LONGLONG("srd", second_read, 0);
  1930. SPIDER_PARAM_DOUBLE("srt", scan_rate, 0);
  1931. SPIDER_PARAM_STR_LIST("srv", server_names);
  1932. SPIDER_PARAM_DOUBLE("ssr", semi_split_read, 0);
  1933. SPIDER_PARAM_LONGLONG("ssl", semi_split_read_limit, 0);
  1934. #ifdef WITH_PARTITION_STORAGE_ENGINE
  1935. SPIDER_PARAM_INT_WITH_MAX("ssy", sts_sync, 0, 2);
  1936. #endif
  1937. SPIDER_PARAM_INT_WITH_MAX("stc", semi_table_lock_conn, 0, 1);
  1938. SPIDER_PARAM_INT_WITH_MAX("stl", semi_table_lock, 0, 1);
  1939. SPIDER_PARAM_LONG_LIST_WITH_MAX("svc", tgt_ssl_vscs, 0, 1);
  1940. SPIDER_PARAM_STR_LIST("tbl", tgt_table_names);
  1941. SPIDER_PARAM_INT_WITH_MAX("tcm", table_count_mode, 0, 3);
  1942. SPIDER_PARAM_LONG_LIST_WITH_MAX("uhd", use_handlers, 0, 3);
  1943. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  1944. SPIDER_PARAM_LONG_LIST_WITH_MAX(
  1945. "uhr", use_hs_reads, 0, 1);
  1946. SPIDER_PARAM_LONG_LIST_WITH_MAX(
  1947. "uhw", use_hs_writes, 0, 1);
  1948. #endif
  1949. SPIDER_PARAM_INT_WITH_MAX("upu", use_pushdown_udf, 0, 1);
  1950. SPIDER_PARAM_INT_WITH_MAX("utc", use_table_charset, 0, 1);
  1951. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  1952. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  1953. MYF(0), tmp_ptr);
  1954. goto error;
  1955. case 4:
  1956. SPIDER_PARAM_STR_LIST("host", tgt_hosts);
  1957. SPIDER_PARAM_STR_LIST("user", tgt_usernames);
  1958. SPIDER_PARAM_LONG_LIST_WITH_MAX("port", tgt_ports, 0, 65535);
  1959. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  1960. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  1961. MYF(0), tmp_ptr);
  1962. goto error;
  1963. case 5:
  1964. SPIDER_PARAM_STR_LIST("table", tgt_table_names);
  1965. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  1966. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  1967. MYF(0), tmp_ptr);
  1968. goto error;
  1969. case 6:
  1970. SPIDER_PARAM_STR_LIST("server", server_names);
  1971. SPIDER_PARAM_STR_LIST("socket", tgt_sockets);
  1972. SPIDER_PARAM_HINT("idx", key_hint, 3, (int) table_share->keys,
  1973. spider_db_append_key_hint);
  1974. SPIDER_PARAM_STR_LIST("ssl_ca", tgt_ssl_cas);
  1975. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  1976. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  1977. MYF(0), tmp_ptr);
  1978. goto error;
  1979. case 7:
  1980. SPIDER_PARAM_STR_LIST("wrapper", tgt_wrappers);
  1981. SPIDER_PARAM_STR_LIST("ssl_key", tgt_ssl_keys);
  1982. SPIDER_PARAM_STR_LIST("pk_name", tgt_pk_names);
  1983. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  1984. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  1985. MYF(0), tmp_ptr);
  1986. goto error;
  1987. case 8:
  1988. SPIDER_PARAM_STR_LIST("database", tgt_dbs);
  1989. SPIDER_PARAM_STR_LIST("password", tgt_passwords);
  1990. SPIDER_PARAM_INT_WITH_MAX("sts_mode", sts_mode, 1, 2);
  1991. #ifdef WITH_PARTITION_STORAGE_ENGINE
  1992. SPIDER_PARAM_INT_WITH_MAX("sts_sync", sts_sync, 0, 2);
  1993. #endif
  1994. SPIDER_PARAM_INT_WITH_MAX("crd_mode", crd_mode, 0, 3);
  1995. #ifdef WITH_PARTITION_STORAGE_ENGINE
  1996. SPIDER_PARAM_INT_WITH_MAX("crd_sync", crd_sync, 0, 2);
  1997. #endif
  1998. SPIDER_PARAM_INT_WITH_MAX("crd_type", crd_type, 0, 2);
  1999. SPIDER_PARAM_LONGLONG("priority", priority, 0);
  2000. #ifndef WITHOUT_SPIDER_BG_SEARCH
  2001. SPIDER_PARAM_INT("bgs_mode", bgs_mode, 0);
  2002. #endif
  2003. SPIDER_PARAM_STR_LIST("ssl_cert", tgt_ssl_certs);
  2004. SPIDER_PARAM_INT_WITH_MAX("bka_mode", bka_mode, 0, 2);
  2005. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2006. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2007. MYF(0), tmp_ptr);
  2008. goto error;
  2009. case 9:
  2010. SPIDER_PARAM_INT("max_order", max_order, 0);
  2011. SPIDER_PARAM_INT("bulk_size", bulk_size, 0);
  2012. SPIDER_PARAM_DOUBLE("scan_rate", scan_rate, 0);
  2013. SPIDER_PARAM_DOUBLE("read_rate", read_rate, 0);
  2014. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2015. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2016. MYF(0), tmp_ptr);
  2017. goto error;
  2018. case 10:
  2019. SPIDER_PARAM_DOUBLE("crd_weight", crd_weight, 1);
  2020. SPIDER_PARAM_LONGLONG("split_read", split_read, 0);
  2021. SPIDER_PARAM_INT_WITH_MAX("quick_mode", quick_mode, 0, 3);
  2022. SPIDER_PARAM_STR_LIST("ssl_cipher", tgt_ssl_ciphers);
  2023. SPIDER_PARAM_STR_LIST("ssl_capath", tgt_ssl_capaths);
  2024. SPIDER_PARAM_STR("bka_engine", bka_engine);
  2025. SPIDER_PARAM_LONGLONG("first_read", first_read, 0);
  2026. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2027. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2028. MYF(0), tmp_ptr);
  2029. goto error;
  2030. case 11:
  2031. SPIDER_PARAM_INT_WITH_MAX("query_cache", query_cache, 0, 2);
  2032. #ifndef WITHOUT_SPIDER_BG_SEARCH
  2033. SPIDER_PARAM_INT_WITH_MAX("crd_bg_mode", crd_bg_mode, 0, 1);
  2034. SPIDER_PARAM_INT_WITH_MAX("sts_bg_mode", sts_bg_mode, 0, 1);
  2035. #endif
  2036. SPIDER_PARAM_LONG_LIST_WITH_MAX("link_status", link_statuses, 0, 3);
  2037. SPIDER_PARAM_LONG_LIST_WITH_MAX("use_handler", use_handlers, 0, 3);
  2038. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  2039. SPIDER_PARAM_LONG_LIST_WITH_MAX("use_hs_read", use_hs_reads, 0, 1);
  2040. #endif
  2041. SPIDER_PARAM_INT_WITH_MAX("casual_read", casual_read, 0, 63);
  2042. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2043. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2044. MYF(0), tmp_ptr);
  2045. goto error;
  2046. case 12:
  2047. SPIDER_PARAM_DOUBLE("sts_interval", sts_interval, 0);
  2048. SPIDER_PARAM_DOUBLE("crd_interval", crd_interval, 0);
  2049. SPIDER_PARAM_INT_WITH_MAX("low_mem_read", low_mem_read, 0, 1);
  2050. SPIDER_PARAM_STR_LIST("default_file", tgt_default_files);
  2051. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  2052. SPIDER_PARAM_LONG_LIST_WITH_MAX(
  2053. "use_hs_write", use_hs_writes, 0, 1);
  2054. SPIDER_PARAM_LONG_LIST_WITH_MAX(
  2055. "hs_read_port", hs_read_ports, 0, 65535);
  2056. #endif
  2057. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2058. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2059. MYF(0), tmp_ptr);
  2060. goto error;
  2061. case 13:
  2062. SPIDER_PARAM_STR_LIST("default_group", tgt_default_groups);
  2063. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  2064. SPIDER_PARAM_LONG_LIST_WITH_MAX(
  2065. "hs_write_port", hs_write_ports, 0, 65535);
  2066. #endif
  2067. SPIDER_PARAM_STR_LIST("sequence_name", tgt_sequence_names);
  2068. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2069. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2070. MYF(0), tmp_ptr);
  2071. goto error;
  2072. case 14:
  2073. SPIDER_PARAM_LONGLONG("internal_limit", internal_limit, 0);
  2074. #ifndef WITHOUT_SPIDER_BG_SEARCH
  2075. SPIDER_PARAM_LONGLONG("bgs_first_read", bgs_first_read, 0);
  2076. #endif
  2077. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  2078. SPIDER_PARAM_STR_LIST(
  2079. "hs_read_socket", hs_read_socks);
  2080. #endif
  2081. SPIDER_PARAM_INT_WITH_MAX("read_only_mode", read_only_mode, 0, 1);
  2082. SPIDER_PARAM_LONG_LIST_WITH_MAX("access_balance", access_balances, 0,
  2083. 2147483647);
  2084. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2085. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2086. MYF(0), tmp_ptr);
  2087. goto error;
  2088. case 15:
  2089. SPIDER_PARAM_LONGLONG("internal_offset", internal_offset, 0);
  2090. SPIDER_PARAM_INT_WITH_MAX("reset_sql_alloc", reset_sql_alloc, 0, 1);
  2091. SPIDER_PARAM_INT_WITH_MAX("semi_table_lock", semi_table_lock, 0, 1);
  2092. SPIDER_PARAM_LONGLONG("quick_page_size", quick_page_size, 0);
  2093. #ifndef WITHOUT_SPIDER_BG_SEARCH
  2094. SPIDER_PARAM_LONGLONG("bgs_second_read", bgs_second_read, 0);
  2095. #endif
  2096. SPIDER_PARAM_LONG_LIST_WITH_MAX("monitoring_kind", monitoring_kind, 0, 3);
  2097. SPIDER_PARAM_DOUBLE("semi_split_read", semi_split_read, 0);
  2098. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  2099. SPIDER_PARAM_STR_LIST(
  2100. "hs_write_socket", hs_write_socks);
  2101. #endif
  2102. SPIDER_PARAM_LONG_LIST_WITH_MAX("connect_timeout", connect_timeouts,
  2103. 0, 2147483647);
  2104. SPIDER_PARAM_INT_WITH_MAX("error_read_mode", error_read_mode, 0, 1);
  2105. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2106. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2107. MYF(0), tmp_ptr);
  2108. goto error;
  2109. case 16:
  2110. SPIDER_PARAM_INT_WITH_MAX(
  2111. "multi_split_read", multi_split_read, 0, 2147483647);
  2112. SPIDER_PARAM_INT_WITH_MAX(
  2113. "selupd_lock_mode", selupd_lock_mode, 0, 2);
  2114. SPIDER_PARAM_INT_WITH_MAX(
  2115. "internal_delayed", internal_delayed, 0, 1);
  2116. SPIDER_PARAM_INT_WITH_MAX(
  2117. "table_count_mode", table_count_mode, 0, 3);
  2118. SPIDER_PARAM_INT_WITH_MAX(
  2119. "use_pushdown_udf", use_pushdown_udf, 0, 1);
  2120. SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(
  2121. "monitoring_limit", monitoring_limit, 0, 9223372036854775807LL);
  2122. SPIDER_PARAM_INT_WITH_MAX(
  2123. "bulk_update_mode", bulk_update_mode, 0, 2);
  2124. SPIDER_PARAM_INT("bulk_update_size", bulk_update_size, 0);
  2125. SPIDER_PARAM_LONG_LIST_WITH_MAX("net_read_timeout",
  2126. net_read_timeouts, 0, 2147483647);
  2127. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  2128. SPIDER_PARAM_LONG_LIST_WITH_MAX(
  2129. "hs_write_to_read", hs_write_to_reads, 0, 1);
  2130. #endif
  2131. SPIDER_PARAM_INT_WITH_MAX(
  2132. "error_write_mode", error_write_mode, 0, 1);
  2133. #ifdef HA_CAN_BULK_ACCESS
  2134. SPIDER_PARAM_INT_WITH_MAX(
  2135. "bulk_access_free", bulk_access_free, 0, 1);
  2136. #endif
  2137. SPIDER_PARAM_INT_WITH_MAX(
  2138. "query_cache_sync", query_cache_sync, 0, 3);
  2139. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2140. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2141. MYF(0), tmp_ptr);
  2142. goto error;
  2143. case 17:
  2144. SPIDER_PARAM_INT_WITH_MAX(
  2145. "internal_optimize", internal_optimize, 0, 1);
  2146. SPIDER_PARAM_INT_WITH_MAX(
  2147. "use_table_charset", use_table_charset, 0, 1);
  2148. SPIDER_PARAM_INT_WITH_MAX(
  2149. "direct_dup_insert", direct_dup_insert, 0, 1);
  2150. SPIDER_PARAM_INT("active_link_count", active_link_count, 1);
  2151. SPIDER_PARAM_LONG_LIST_WITH_MAX("net_write_timeout",
  2152. net_write_timeouts, 0, 2147483647);
  2153. #ifdef HA_CAN_FORCE_BULK_DELETE
  2154. SPIDER_PARAM_INT_WITH_MAX(
  2155. "force_bulk_delete", force_bulk_delete, 0, 1);
  2156. #endif
  2157. #ifdef HA_CAN_FORCE_BULK_UPDATE
  2158. SPIDER_PARAM_INT_WITH_MAX(
  2159. "force_bulk_update", force_bulk_update, 0, 1);
  2160. #endif
  2161. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2162. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2163. MYF(0), tmp_ptr);
  2164. goto error;
  2165. case 18:
  2166. SPIDER_PARAM_INT_WITH_MAX(
  2167. "select_column_mode", select_column_mode, 0, 1);
  2168. #ifndef WITHOUT_SPIDER_BG_SEARCH
  2169. SPIDER_PARAM_LONG_LIST_WITH_MAX(
  2170. "monitoring_bg_kind", monitoring_bg_kind, 0, 3);
  2171. #endif
  2172. SPIDER_PARAM_LONGLONG(
  2173. "direct_order_limit", direct_order_limit, 0);
  2174. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2175. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2176. MYF(0), tmp_ptr);
  2177. goto error;
  2178. case 19:
  2179. SPIDER_PARAM_INT("init_sql_alloc_size", init_sql_alloc_size, 0);
  2180. SPIDER_PARAM_INT_WITH_MAX(
  2181. "auto_increment_mode", auto_increment_mode, 0, 3);
  2182. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  2183. SPIDER_PARAM_LONGLONG("hs_result_free_size", hs_result_free_size, 0);
  2184. #endif
  2185. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2186. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2187. MYF(0), tmp_ptr);
  2188. goto error;
  2189. case 20:
  2190. SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(
  2191. "monitoring_server_id", monitoring_sid, 0, 4294967295LL);
  2192. SPIDER_PARAM_INT_WITH_MAX(
  2193. "delete_all_rows_type", delete_all_rows_type, 0, 1);
  2194. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2195. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2196. MYF(0), tmp_ptr);
  2197. goto error;
  2198. case 21:
  2199. SPIDER_PARAM_LONGLONG(
  2200. "semi_split_read_limit", semi_split_read_limit, 0);
  2201. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2202. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2203. MYF(0), tmp_ptr);
  2204. goto error;
  2205. case 22:
  2206. SPIDER_PARAM_LONG_LIST_WITH_MAX(
  2207. "ssl_verify_server_cert", tgt_ssl_vscs, 0, 1);
  2208. #ifndef WITHOUT_SPIDER_BG_SEARCH
  2209. SPIDER_PARAM_LONGLONG_LIST_WITH_MAX(
  2210. "monitoring_bg_interval", monitoring_bg_interval, 0, 4294967295LL);
  2211. #endif
  2212. SPIDER_PARAM_INT_WITH_MAX(
  2213. "skip_default_condition", skip_default_condition, 0, 1);
  2214. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2215. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2216. MYF(0), tmp_ptr);
  2217. goto error;
  2218. case 23:
  2219. SPIDER_PARAM_INT_WITH_MAX(
  2220. "internal_optimize_local", internal_optimize_local, 0, 1);
  2221. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2222. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2223. MYF(0), tmp_ptr);
  2224. goto error;
  2225. case 26:
  2226. SPIDER_PARAM_INT_WITH_MAX(
  2227. "semi_table_lock_connection", semi_table_lock_conn, 0, 1);
  2228. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2229. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2230. MYF(0), tmp_ptr);
  2231. goto error;
  2232. default:
  2233. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2234. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2235. MYF(0), tmp_ptr);
  2236. goto error;
  2237. }
  2238. }
  2239. }
  2240. /* check all_link_count */
  2241. share->all_link_count = 1;
  2242. if (share->all_link_count < share->server_names_length)
  2243. share->all_link_count = share->server_names_length;
  2244. if (share->all_link_count < share->tgt_table_names_length)
  2245. share->all_link_count = share->tgt_table_names_length;
  2246. if (share->all_link_count < share->tgt_dbs_length)
  2247. share->all_link_count = share->tgt_dbs_length;
  2248. if (share->all_link_count < share->tgt_hosts_length)
  2249. share->all_link_count = share->tgt_hosts_length;
  2250. if (share->all_link_count < share->tgt_usernames_length)
  2251. share->all_link_count = share->tgt_usernames_length;
  2252. if (share->all_link_count < share->tgt_passwords_length)
  2253. share->all_link_count = share->tgt_passwords_length;
  2254. if (share->all_link_count < share->tgt_sockets_length)
  2255. share->all_link_count = share->tgt_sockets_length;
  2256. if (share->all_link_count < share->tgt_wrappers_length)
  2257. share->all_link_count = share->tgt_wrappers_length;
  2258. if (share->all_link_count < share->tgt_ssl_cas_length)
  2259. share->all_link_count = share->tgt_ssl_cas_length;
  2260. if (share->all_link_count < share->tgt_ssl_capaths_length)
  2261. share->all_link_count = share->tgt_ssl_capaths_length;
  2262. if (share->all_link_count < share->tgt_ssl_certs_length)
  2263. share->all_link_count = share->tgt_ssl_certs_length;
  2264. if (share->all_link_count < share->tgt_ssl_ciphers_length)
  2265. share->all_link_count = share->tgt_ssl_ciphers_length;
  2266. if (share->all_link_count < share->tgt_ssl_keys_length)
  2267. share->all_link_count = share->tgt_ssl_keys_length;
  2268. if (share->all_link_count < share->tgt_default_files_length)
  2269. share->all_link_count = share->tgt_default_files_length;
  2270. if (share->all_link_count < share->tgt_default_groups_length)
  2271. share->all_link_count = share->tgt_default_groups_length;
  2272. if (share->all_link_count < share->tgt_pk_names_length)
  2273. share->all_link_count = share->tgt_pk_names_length;
  2274. if (share->all_link_count < share->tgt_sequence_names_length)
  2275. share->all_link_count = share->tgt_sequence_names_length;
  2276. if (share->all_link_count < share->tgt_ports_length)
  2277. share->all_link_count = share->tgt_ports_length;
  2278. if (share->all_link_count < share->tgt_ssl_vscs_length)
  2279. share->all_link_count = share->tgt_ssl_vscs_length;
  2280. if (share->all_link_count < share->link_statuses_length)
  2281. share->all_link_count = share->link_statuses_length;
  2282. if (share->all_link_count < share->monitoring_kind_length)
  2283. share->all_link_count = share->monitoring_kind_length;
  2284. if (share->all_link_count < share->monitoring_limit_length)
  2285. share->all_link_count = share->monitoring_limit_length;
  2286. if (share->all_link_count < share->monitoring_sid_length)
  2287. share->all_link_count = share->monitoring_sid_length;
  2288. #ifndef WITHOUT_SPIDER_BG_SEARCH
  2289. if (share->all_link_count < share->monitoring_bg_kind_length)
  2290. share->all_link_count = share->monitoring_bg_kind_length;
  2291. if (share->all_link_count < share->monitoring_bg_interval_length)
  2292. share->all_link_count = share->monitoring_bg_interval_length;
  2293. #endif
  2294. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  2295. if (share->all_link_count < share->use_hs_reads_length)
  2296. share->all_link_count = share->use_hs_reads_length;
  2297. if (share->all_link_count < share->use_hs_writes_length)
  2298. share->all_link_count = share->use_hs_writes_length;
  2299. if (share->all_link_count < share->hs_read_ports_length)
  2300. share->all_link_count = share->hs_read_ports_length;
  2301. if (share->all_link_count < share->hs_write_ports_length)
  2302. share->all_link_count = share->hs_write_ports_length;
  2303. if (share->all_link_count < share->hs_read_socks_length)
  2304. share->all_link_count = share->hs_read_socks_length;
  2305. if (share->all_link_count < share->hs_write_socks_length)
  2306. share->all_link_count = share->hs_write_socks_length;
  2307. if (share->all_link_count < share->hs_write_to_reads_length)
  2308. share->all_link_count = share->hs_write_to_reads_length;
  2309. #endif
  2310. if (share->all_link_count < share->use_handlers_length)
  2311. share->all_link_count = share->use_handlers_length;
  2312. if (share->all_link_count < share->connect_timeouts_length)
  2313. share->all_link_count = share->connect_timeouts_length;
  2314. if (share->all_link_count < share->net_read_timeouts_length)
  2315. share->all_link_count = share->net_read_timeouts_length;
  2316. if (share->all_link_count < share->net_write_timeouts_length)
  2317. share->all_link_count = share->net_write_timeouts_length;
  2318. if (share->all_link_count < share->access_balances_length)
  2319. share->all_link_count = share->access_balances_length;
  2320. if ((error_num = spider_increase_string_list(
  2321. &share->server_names,
  2322. &share->server_names_lengths,
  2323. &share->server_names_length,
  2324. &share->server_names_charlen,
  2325. share->all_link_count)))
  2326. goto error;
  2327. if ((error_num = spider_increase_string_list(
  2328. &share->tgt_table_names,
  2329. &share->tgt_table_names_lengths,
  2330. &share->tgt_table_names_length,
  2331. &share->tgt_table_names_charlen,
  2332. share->all_link_count)))
  2333. goto error;
  2334. if ((error_num = spider_increase_string_list(
  2335. &share->tgt_dbs,
  2336. &share->tgt_dbs_lengths,
  2337. &share->tgt_dbs_length,
  2338. &share->tgt_dbs_charlen,
  2339. share->all_link_count)))
  2340. goto error;
  2341. if ((error_num = spider_increase_string_list(
  2342. &share->tgt_hosts,
  2343. &share->tgt_hosts_lengths,
  2344. &share->tgt_hosts_length,
  2345. &share->tgt_hosts_charlen,
  2346. share->all_link_count)))
  2347. goto error;
  2348. if ((error_num = spider_increase_string_list(
  2349. &share->tgt_usernames,
  2350. &share->tgt_usernames_lengths,
  2351. &share->tgt_usernames_length,
  2352. &share->tgt_usernames_charlen,
  2353. share->all_link_count)))
  2354. goto error;
  2355. if ((error_num = spider_increase_string_list(
  2356. &share->tgt_passwords,
  2357. &share->tgt_passwords_lengths,
  2358. &share->tgt_passwords_length,
  2359. &share->tgt_passwords_charlen,
  2360. share->all_link_count)))
  2361. goto error;
  2362. if ((error_num = spider_increase_string_list(
  2363. &share->tgt_sockets,
  2364. &share->tgt_sockets_lengths,
  2365. &share->tgt_sockets_length,
  2366. &share->tgt_sockets_charlen,
  2367. share->all_link_count)))
  2368. goto error;
  2369. if ((error_num = spider_increase_string_list(
  2370. &share->tgt_wrappers,
  2371. &share->tgt_wrappers_lengths,
  2372. &share->tgt_wrappers_length,
  2373. &share->tgt_wrappers_charlen,
  2374. share->all_link_count)))
  2375. goto error;
  2376. if ((error_num = spider_increase_string_list(
  2377. &share->tgt_ssl_cas,
  2378. &share->tgt_ssl_cas_lengths,
  2379. &share->tgt_ssl_cas_length,
  2380. &share->tgt_ssl_cas_charlen,
  2381. share->all_link_count)))
  2382. goto error;
  2383. if ((error_num = spider_increase_string_list(
  2384. &share->tgt_ssl_capaths,
  2385. &share->tgt_ssl_capaths_lengths,
  2386. &share->tgt_ssl_capaths_length,
  2387. &share->tgt_ssl_capaths_charlen,
  2388. share->all_link_count)))
  2389. goto error;
  2390. if ((error_num = spider_increase_string_list(
  2391. &share->tgt_ssl_certs,
  2392. &share->tgt_ssl_certs_lengths,
  2393. &share->tgt_ssl_certs_length,
  2394. &share->tgt_ssl_certs_charlen,
  2395. share->all_link_count)))
  2396. goto error;
  2397. if ((error_num = spider_increase_string_list(
  2398. &share->tgt_ssl_ciphers,
  2399. &share->tgt_ssl_ciphers_lengths,
  2400. &share->tgt_ssl_ciphers_length,
  2401. &share->tgt_ssl_ciphers_charlen,
  2402. share->all_link_count)))
  2403. goto error;
  2404. if ((error_num = spider_increase_string_list(
  2405. &share->tgt_ssl_keys,
  2406. &share->tgt_ssl_keys_lengths,
  2407. &share->tgt_ssl_keys_length,
  2408. &share->tgt_ssl_keys_charlen,
  2409. share->all_link_count)))
  2410. goto error;
  2411. if ((error_num = spider_increase_string_list(
  2412. &share->tgt_default_files,
  2413. &share->tgt_default_files_lengths,
  2414. &share->tgt_default_files_length,
  2415. &share->tgt_default_files_charlen,
  2416. share->all_link_count)))
  2417. goto error;
  2418. if ((error_num = spider_increase_string_list(
  2419. &share->tgt_default_groups,
  2420. &share->tgt_default_groups_lengths,
  2421. &share->tgt_default_groups_length,
  2422. &share->tgt_default_groups_charlen,
  2423. share->all_link_count)))
  2424. goto error;
  2425. if ((error_num = spider_increase_string_list(
  2426. &share->tgt_pk_names,
  2427. &share->tgt_pk_names_lengths,
  2428. &share->tgt_pk_names_length,
  2429. &share->tgt_pk_names_charlen,
  2430. share->all_link_count)))
  2431. goto error;
  2432. if ((error_num = spider_increase_string_list(
  2433. &share->tgt_sequence_names,
  2434. &share->tgt_sequence_names_lengths,
  2435. &share->tgt_sequence_names_length,
  2436. &share->tgt_sequence_names_charlen,
  2437. share->all_link_count)))
  2438. goto error;
  2439. if ((error_num = spider_increase_long_list(
  2440. &share->tgt_ports,
  2441. &share->tgt_ports_length,
  2442. share->all_link_count)))
  2443. goto error;
  2444. if ((error_num = spider_increase_long_list(
  2445. &share->tgt_ssl_vscs,
  2446. &share->tgt_ssl_vscs_length,
  2447. share->all_link_count)))
  2448. goto error;
  2449. if ((error_num = spider_increase_long_list(
  2450. &share->link_statuses,
  2451. &share->link_statuses_length,
  2452. share->all_link_count)))
  2453. goto error;
  2454. #ifndef WITHOUT_SPIDER_BG_SEARCH
  2455. if ((error_num = spider_increase_long_list(
  2456. &share->monitoring_bg_kind,
  2457. &share->monitoring_bg_kind_length,
  2458. share->all_link_count)))
  2459. goto error;
  2460. #endif
  2461. if ((error_num = spider_increase_long_list(
  2462. &share->monitoring_kind,
  2463. &share->monitoring_kind_length,
  2464. share->all_link_count)))
  2465. goto error;
  2466. #ifndef WITHOUT_SPIDER_BG_SEARCH
  2467. if ((error_num = spider_increase_longlong_list(
  2468. &share->monitoring_bg_interval,
  2469. &share->monitoring_bg_interval_length,
  2470. share->all_link_count)))
  2471. goto error;
  2472. #endif
  2473. if ((error_num = spider_increase_longlong_list(
  2474. &share->monitoring_limit,
  2475. &share->monitoring_limit_length,
  2476. share->all_link_count)))
  2477. goto error;
  2478. if ((error_num = spider_increase_longlong_list(
  2479. &share->monitoring_sid,
  2480. &share->monitoring_sid_length,
  2481. share->all_link_count)))
  2482. goto error;
  2483. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  2484. if ((error_num = spider_increase_long_list(
  2485. &share->use_hs_reads,
  2486. &share->use_hs_reads_length,
  2487. share->all_link_count)))
  2488. goto error;
  2489. if ((error_num = spider_increase_long_list(
  2490. &share->use_hs_writes,
  2491. &share->use_hs_writes_length,
  2492. share->all_link_count)))
  2493. goto error;
  2494. if ((error_num = spider_increase_long_list(
  2495. &share->hs_read_ports,
  2496. &share->hs_read_ports_length,
  2497. share->all_link_count)))
  2498. goto error;
  2499. if ((error_num = spider_increase_long_list(
  2500. &share->hs_write_ports,
  2501. &share->hs_write_ports_length,
  2502. share->all_link_count)))
  2503. goto error;
  2504. if ((error_num = spider_increase_string_list(
  2505. &share->hs_read_socks,
  2506. &share->hs_read_socks_lengths,
  2507. &share->hs_read_socks_length,
  2508. &share->hs_read_socks_charlen,
  2509. share->all_link_count)))
  2510. goto error;
  2511. if ((error_num = spider_increase_string_list(
  2512. &share->hs_write_socks,
  2513. &share->hs_write_socks_lengths,
  2514. &share->hs_write_socks_length,
  2515. &share->hs_write_socks_charlen,
  2516. share->all_link_count)))
  2517. goto error;
  2518. if ((error_num = spider_increase_long_list(
  2519. &share->hs_write_to_reads,
  2520. &share->hs_write_to_reads_length,
  2521. share->all_link_count)))
  2522. goto error;
  2523. #endif
  2524. if ((error_num = spider_increase_long_list(
  2525. &share->use_handlers,
  2526. &share->use_handlers_length,
  2527. share->all_link_count)))
  2528. goto error;
  2529. if ((error_num = spider_increase_long_list(
  2530. &share->connect_timeouts,
  2531. &share->connect_timeouts_length,
  2532. share->all_link_count)))
  2533. goto error;
  2534. if ((error_num = spider_increase_long_list(
  2535. &share->net_read_timeouts,
  2536. &share->net_read_timeouts_length,
  2537. share->all_link_count)))
  2538. goto error;
  2539. if ((error_num = spider_increase_long_list(
  2540. &share->net_write_timeouts,
  2541. &share->net_write_timeouts_length,
  2542. share->all_link_count)))
  2543. goto error;
  2544. if ((error_num = spider_increase_long_list(
  2545. &share->access_balances,
  2546. &share->access_balances_length,
  2547. share->all_link_count)))
  2548. goto error;
  2549. /* copy for tables start */
  2550. share_alter = &share->alter_table;
  2551. share_alter->all_link_count = share->all_link_count;
  2552. if (!(share_alter->tmp_server_names = (char **)
  2553. spider_bulk_malloc(spider_current_trx, 43, MYF(MY_WME | MY_ZEROFILL),
  2554. &share_alter->tmp_server_names,
  2555. sizeof(char *) * 15 * share->all_link_count,
  2556. &share_alter->tmp_server_names_lengths,
  2557. sizeof(uint *) * 15 * share->all_link_count,
  2558. &share_alter->tmp_tgt_ports,
  2559. sizeof(long) * share->all_link_count,
  2560. &share_alter->tmp_tgt_ssl_vscs,
  2561. sizeof(long) * share->all_link_count,
  2562. &share_alter->tmp_link_statuses,
  2563. sizeof(long) * share->all_link_count,
  2564. NullS))
  2565. ) {
  2566. error_num = HA_ERR_OUT_OF_MEM;
  2567. goto error;
  2568. }
  2569. memcpy(share_alter->tmp_server_names, share->server_names,
  2570. sizeof(char *) * share->all_link_count);
  2571. share_alter->tmp_tgt_table_names =
  2572. share_alter->tmp_server_names + share->all_link_count;
  2573. memcpy(share_alter->tmp_tgt_table_names, share->tgt_table_names,
  2574. sizeof(char *) * share->all_link_count);
  2575. share_alter->tmp_tgt_dbs =
  2576. share_alter->tmp_tgt_table_names + share->all_link_count;
  2577. memcpy(share_alter->tmp_tgt_dbs, share->tgt_dbs,
  2578. sizeof(char *) * share->all_link_count);
  2579. share_alter->tmp_tgt_hosts =
  2580. share_alter->tmp_tgt_dbs + share->all_link_count;
  2581. memcpy(share_alter->tmp_tgt_hosts, share->tgt_hosts,
  2582. sizeof(char *) * share->all_link_count);
  2583. share_alter->tmp_tgt_usernames =
  2584. share_alter->tmp_tgt_hosts + share->all_link_count;
  2585. memcpy(share_alter->tmp_tgt_usernames, share->tgt_usernames,
  2586. sizeof(char *) * share->all_link_count);
  2587. share_alter->tmp_tgt_passwords =
  2588. share_alter->tmp_tgt_usernames + share->all_link_count;
  2589. memcpy(share_alter->tmp_tgt_passwords, share->tgt_passwords,
  2590. sizeof(char *) * share->all_link_count);
  2591. share_alter->tmp_tgt_sockets =
  2592. share_alter->tmp_tgt_passwords + share->all_link_count;
  2593. memcpy(share_alter->tmp_tgt_sockets, share->tgt_sockets,
  2594. sizeof(char *) * share->all_link_count);
  2595. share_alter->tmp_tgt_wrappers =
  2596. share_alter->tmp_tgt_sockets + share->all_link_count;
  2597. memcpy(share_alter->tmp_tgt_wrappers, share->tgt_wrappers,
  2598. sizeof(char *) * share->all_link_count);
  2599. share_alter->tmp_tgt_ssl_cas =
  2600. share_alter->tmp_tgt_wrappers + share->all_link_count;
  2601. memcpy(share_alter->tmp_tgt_ssl_cas, share->tgt_ssl_cas,
  2602. sizeof(char *) * share->all_link_count);
  2603. share_alter->tmp_tgt_ssl_capaths =
  2604. share_alter->tmp_tgt_ssl_cas + share->all_link_count;
  2605. memcpy(share_alter->tmp_tgt_ssl_capaths, share->tgt_ssl_capaths,
  2606. sizeof(char *) * share->all_link_count);
  2607. share_alter->tmp_tgt_ssl_certs =
  2608. share_alter->tmp_tgt_ssl_capaths + share->all_link_count;
  2609. memcpy(share_alter->tmp_tgt_ssl_certs, share->tgt_ssl_certs,
  2610. sizeof(char *) * share->all_link_count);
  2611. share_alter->tmp_tgt_ssl_ciphers =
  2612. share_alter->tmp_tgt_ssl_certs + share->all_link_count;
  2613. memcpy(share_alter->tmp_tgt_ssl_ciphers, share->tgt_ssl_ciphers,
  2614. sizeof(char *) * share->all_link_count);
  2615. share_alter->tmp_tgt_ssl_keys =
  2616. share_alter->tmp_tgt_ssl_ciphers + share->all_link_count;
  2617. memcpy(share_alter->tmp_tgt_ssl_keys, share->tgt_ssl_keys,
  2618. sizeof(char *) * share->all_link_count);
  2619. share_alter->tmp_tgt_default_files =
  2620. share_alter->tmp_tgt_ssl_keys + share->all_link_count;
  2621. memcpy(share_alter->tmp_tgt_default_files, share->tgt_default_files,
  2622. sizeof(char *) * share->all_link_count);
  2623. share_alter->tmp_tgt_default_groups =
  2624. share_alter->tmp_tgt_default_files + share->all_link_count;
  2625. memcpy(share_alter->tmp_tgt_default_groups, share->tgt_default_groups,
  2626. sizeof(char *) * share->all_link_count);
  2627. memcpy(share_alter->tmp_tgt_ports, share->tgt_ports,
  2628. sizeof(long) * share->all_link_count);
  2629. memcpy(share_alter->tmp_tgt_ssl_vscs, share->tgt_ssl_vscs,
  2630. sizeof(long) * share->all_link_count);
  2631. memcpy(share_alter->tmp_link_statuses, share->link_statuses,
  2632. sizeof(long) * share->all_link_count);
  2633. memcpy(share_alter->tmp_server_names_lengths,
  2634. share->server_names_lengths,
  2635. sizeof(uint) * share->all_link_count);
  2636. share_alter->tmp_tgt_table_names_lengths =
  2637. share_alter->tmp_server_names_lengths + share->all_link_count;
  2638. memcpy(share_alter->tmp_tgt_table_names_lengths,
  2639. share->tgt_table_names_lengths,
  2640. sizeof(uint) * share->all_link_count);
  2641. share_alter->tmp_tgt_dbs_lengths =
  2642. share_alter->tmp_tgt_table_names_lengths + share->all_link_count;
  2643. memcpy(share_alter->tmp_tgt_dbs_lengths, share->tgt_dbs_lengths,
  2644. sizeof(uint) * share->all_link_count);
  2645. share_alter->tmp_tgt_hosts_lengths =
  2646. share_alter->tmp_tgt_dbs_lengths + share->all_link_count;
  2647. memcpy(share_alter->tmp_tgt_hosts_lengths, share->tgt_hosts_lengths,
  2648. sizeof(uint) * share->all_link_count);
  2649. share_alter->tmp_tgt_usernames_lengths =
  2650. share_alter->tmp_tgt_hosts_lengths + share->all_link_count;
  2651. memcpy(share_alter->tmp_tgt_usernames_lengths,
  2652. share->tgt_usernames_lengths,
  2653. sizeof(uint) * share->all_link_count);
  2654. share_alter->tmp_tgt_passwords_lengths =
  2655. share_alter->tmp_tgt_usernames_lengths + share->all_link_count;
  2656. memcpy(share_alter->tmp_tgt_passwords_lengths,
  2657. share->tgt_passwords_lengths,
  2658. sizeof(uint) * share->all_link_count);
  2659. share_alter->tmp_tgt_sockets_lengths =
  2660. share_alter->tmp_tgt_passwords_lengths + share->all_link_count;
  2661. memcpy(share_alter->tmp_tgt_sockets_lengths, share->tgt_sockets_lengths,
  2662. sizeof(uint) * share->all_link_count);
  2663. share_alter->tmp_tgt_wrappers_lengths =
  2664. share_alter->tmp_tgt_sockets_lengths + share->all_link_count;
  2665. memcpy(share_alter->tmp_tgt_wrappers_lengths,
  2666. share->tgt_wrappers_lengths,
  2667. sizeof(uint) * share->all_link_count);
  2668. share_alter->tmp_tgt_ssl_cas_lengths =
  2669. share_alter->tmp_tgt_wrappers_lengths + share->all_link_count;
  2670. memcpy(share_alter->tmp_tgt_ssl_cas_lengths,
  2671. share->tgt_ssl_cas_lengths,
  2672. sizeof(uint) * share->all_link_count);
  2673. share_alter->tmp_tgt_ssl_capaths_lengths =
  2674. share_alter->tmp_tgt_ssl_cas_lengths + share->all_link_count;
  2675. memcpy(share_alter->tmp_tgt_ssl_capaths_lengths,
  2676. share->tgt_ssl_capaths_lengths,
  2677. sizeof(uint) * share->all_link_count);
  2678. share_alter->tmp_tgt_ssl_certs_lengths =
  2679. share_alter->tmp_tgt_ssl_capaths_lengths + share->all_link_count;
  2680. memcpy(share_alter->tmp_tgt_ssl_certs_lengths,
  2681. share->tgt_ssl_certs_lengths,
  2682. sizeof(uint) * share->all_link_count);
  2683. share_alter->tmp_tgt_ssl_ciphers_lengths =
  2684. share_alter->tmp_tgt_ssl_certs_lengths + share->all_link_count;
  2685. memcpy(share_alter->tmp_tgt_ssl_ciphers_lengths,
  2686. share->tgt_ssl_ciphers_lengths,
  2687. sizeof(uint) * share->all_link_count);
  2688. share_alter->tmp_tgt_ssl_keys_lengths =
  2689. share_alter->tmp_tgt_ssl_ciphers_lengths + share->all_link_count;
  2690. memcpy(share_alter->tmp_tgt_ssl_keys_lengths,
  2691. share->tgt_ssl_keys_lengths,
  2692. sizeof(uint) * share->all_link_count);
  2693. share_alter->tmp_tgt_default_files_lengths =
  2694. share_alter->tmp_tgt_ssl_keys_lengths + share->all_link_count;
  2695. memcpy(share_alter->tmp_tgt_default_files_lengths,
  2696. share->tgt_default_files_lengths,
  2697. sizeof(uint) * share->all_link_count);
  2698. share_alter->tmp_tgt_default_groups_lengths =
  2699. share_alter->tmp_tgt_default_files_lengths + share->all_link_count;
  2700. memcpy(share_alter->tmp_tgt_default_groups_lengths,
  2701. share->tgt_default_groups_lengths,
  2702. sizeof(uint) * share->all_link_count);
  2703. share_alter->tmp_server_names_charlen = share->server_names_charlen;
  2704. share_alter->tmp_tgt_table_names_charlen = share->tgt_table_names_charlen;
  2705. share_alter->tmp_tgt_dbs_charlen = share->tgt_dbs_charlen;
  2706. share_alter->tmp_tgt_hosts_charlen = share->tgt_hosts_charlen;
  2707. share_alter->tmp_tgt_usernames_charlen = share->tgt_usernames_charlen;
  2708. share_alter->tmp_tgt_passwords_charlen = share->tgt_passwords_charlen;
  2709. share_alter->tmp_tgt_sockets_charlen = share->tgt_sockets_charlen;
  2710. share_alter->tmp_tgt_wrappers_charlen = share->tgt_wrappers_charlen;
  2711. share_alter->tmp_tgt_ssl_cas_charlen = share->tgt_ssl_cas_charlen;
  2712. share_alter->tmp_tgt_ssl_capaths_charlen = share->tgt_ssl_capaths_charlen;
  2713. share_alter->tmp_tgt_ssl_certs_charlen = share->tgt_ssl_certs_charlen;
  2714. share_alter->tmp_tgt_ssl_ciphers_charlen = share->tgt_ssl_ciphers_charlen;
  2715. share_alter->tmp_tgt_ssl_keys_charlen = share->tgt_ssl_keys_charlen;
  2716. share_alter->tmp_tgt_default_files_charlen =
  2717. share->tgt_default_files_charlen;
  2718. share_alter->tmp_tgt_default_groups_charlen =
  2719. share->tgt_default_groups_charlen;
  2720. share_alter->tmp_server_names_length = share->server_names_length;
  2721. share_alter->tmp_tgt_table_names_length = share->tgt_table_names_length;
  2722. share_alter->tmp_tgt_dbs_length = share->tgt_dbs_length;
  2723. share_alter->tmp_tgt_hosts_length = share->tgt_hosts_length;
  2724. share_alter->tmp_tgt_usernames_length = share->tgt_usernames_length;
  2725. share_alter->tmp_tgt_passwords_length = share->tgt_passwords_length;
  2726. share_alter->tmp_tgt_sockets_length = share->tgt_sockets_length;
  2727. share_alter->tmp_tgt_wrappers_length = share->tgt_wrappers_length;
  2728. share_alter->tmp_tgt_ssl_cas_length = share->tgt_ssl_cas_length;
  2729. share_alter->tmp_tgt_ssl_capaths_length = share->tgt_ssl_capaths_length;
  2730. share_alter->tmp_tgt_ssl_certs_length = share->tgt_ssl_certs_length;
  2731. share_alter->tmp_tgt_ssl_ciphers_length = share->tgt_ssl_ciphers_length;
  2732. share_alter->tmp_tgt_ssl_keys_length = share->tgt_ssl_keys_length;
  2733. share_alter->tmp_tgt_default_files_length = share->tgt_default_files_length;
  2734. share_alter->tmp_tgt_default_groups_length =
  2735. share->tgt_default_groups_length;
  2736. share_alter->tmp_tgt_ports_length = share->tgt_ports_length;
  2737. share_alter->tmp_tgt_ssl_vscs_length = share->tgt_ssl_vscs_length;
  2738. share_alter->tmp_link_statuses_length = share->link_statuses_length;
  2739. /* copy for tables end */
  2740. if ((error_num = spider_set_connect_info_default(
  2741. share,
  2742. #ifdef WITH_PARTITION_STORAGE_ENGINE
  2743. part_elem,
  2744. sub_elem,
  2745. #endif
  2746. table_share
  2747. )))
  2748. goto error;
  2749. if (create_table)
  2750. {
  2751. for (roop_count = 0; roop_count < (int) share->all_link_count;
  2752. roop_count++)
  2753. {
  2754. int roop_count2;
  2755. for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++)
  2756. {
  2757. if (
  2758. spider_dbton[roop_count2].wrapper &&
  2759. !strcmp(share->tgt_wrappers[roop_count],
  2760. spider_dbton[roop_count2].wrapper)
  2761. ) {
  2762. break;
  2763. }
  2764. }
  2765. if (roop_count2 == SPIDER_DBTON_SIZE)
  2766. {
  2767. DBUG_PRINT("info",("spider err tgt_wrappers[%d]=%s", roop_count,
  2768. share->tgt_wrappers[roop_count]));
  2769. error_num = ER_SPIDER_INVALID_CONNECT_INFO_NUM;
  2770. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_STR,
  2771. MYF(0), share->tgt_wrappers[roop_count]);
  2772. goto error;
  2773. }
  2774. DBUG_PRINT("info",
  2775. ("spider server_names_lengths[%d] = %u", roop_count,
  2776. share->server_names_lengths[roop_count]));
  2777. if (share->server_names_lengths[roop_count] > SPIDER_CONNECT_INFO_MAX_LEN)
  2778. {
  2779. error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
  2780. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
  2781. MYF(0), share->server_names[roop_count], "server");
  2782. goto error;
  2783. }
  2784. DBUG_PRINT("info",
  2785. ("spider tgt_table_names_lengths[%d] = %u", roop_count,
  2786. share->tgt_table_names_lengths[roop_count]));
  2787. if (share->tgt_table_names_lengths[roop_count] >
  2788. SPIDER_CONNECT_INFO_MAX_LEN)
  2789. {
  2790. error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
  2791. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
  2792. MYF(0), share->tgt_table_names[roop_count], "table");
  2793. goto error;
  2794. }
  2795. DBUG_PRINT("info",
  2796. ("spider tgt_dbs_lengths[%d] = %u", roop_count,
  2797. share->tgt_dbs_lengths[roop_count]));
  2798. if (share->tgt_dbs_lengths[roop_count] > SPIDER_CONNECT_INFO_MAX_LEN)
  2799. {
  2800. error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
  2801. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
  2802. MYF(0), share->tgt_dbs[roop_count], "database");
  2803. goto error;
  2804. }
  2805. DBUG_PRINT("info",
  2806. ("spider tgt_hosts_lengths[%d] = %u", roop_count,
  2807. share->tgt_hosts_lengths[roop_count]));
  2808. if (share->tgt_hosts_lengths[roop_count] > SPIDER_CONNECT_INFO_MAX_LEN)
  2809. {
  2810. error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
  2811. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
  2812. MYF(0), share->tgt_hosts[roop_count], "host");
  2813. goto error;
  2814. }
  2815. DBUG_PRINT("info",
  2816. ("spider tgt_usernames_lengths[%d] = %u", roop_count,
  2817. share->tgt_usernames_lengths[roop_count]));
  2818. if (share->tgt_usernames_lengths[roop_count] >
  2819. SPIDER_CONNECT_INFO_MAX_LEN)
  2820. {
  2821. error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
  2822. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
  2823. MYF(0), share->tgt_usernames[roop_count], "user");
  2824. goto error;
  2825. }
  2826. DBUG_PRINT("info",
  2827. ("spider tgt_passwords_lengths[%d] = %u", roop_count,
  2828. share->tgt_passwords_lengths[roop_count]));
  2829. if (share->tgt_passwords_lengths[roop_count] >
  2830. SPIDER_CONNECT_INFO_MAX_LEN)
  2831. {
  2832. error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
  2833. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
  2834. MYF(0), share->tgt_passwords[roop_count], "password");
  2835. goto error;
  2836. }
  2837. DBUG_PRINT("info",
  2838. ("spider tgt_sockets_lengths[%d] = %u", roop_count,
  2839. share->tgt_sockets_lengths[roop_count]));
  2840. if (share->tgt_sockets_lengths[roop_count] >
  2841. SPIDER_CONNECT_INFO_PATH_MAX_LEN)
  2842. {
  2843. error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
  2844. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
  2845. MYF(0), share->tgt_sockets[roop_count], "socket");
  2846. goto error;
  2847. }
  2848. DBUG_PRINT("info",
  2849. ("spider tgt_wrappers_lengths[%d] = %u", roop_count,
  2850. share->tgt_wrappers_lengths[roop_count]));
  2851. if (share->tgt_wrappers_lengths[roop_count] >
  2852. SPIDER_CONNECT_INFO_MAX_LEN)
  2853. {
  2854. error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
  2855. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
  2856. MYF(0), share->tgt_wrappers[roop_count], "wrapper");
  2857. goto error;
  2858. }
  2859. DBUG_PRINT("info",
  2860. ("spider tgt_ssl_cas_lengths[%d] = %u", roop_count,
  2861. share->tgt_ssl_cas_lengths[roop_count]));
  2862. if (share->tgt_ssl_cas_lengths[roop_count] >
  2863. SPIDER_CONNECT_INFO_PATH_MAX_LEN)
  2864. {
  2865. error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
  2866. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
  2867. MYF(0), share->tgt_ssl_cas[roop_count], "ssl_ca");
  2868. goto error;
  2869. }
  2870. DBUG_PRINT("info",
  2871. ("spider tgt_ssl_capaths_lengths[%d] = %u", roop_count,
  2872. share->tgt_ssl_capaths_lengths[roop_count]));
  2873. if (share->tgt_ssl_capaths_lengths[roop_count] >
  2874. SPIDER_CONNECT_INFO_PATH_MAX_LEN)
  2875. {
  2876. error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
  2877. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
  2878. MYF(0), share->tgt_ssl_capaths[roop_count], "ssl_capath");
  2879. goto error;
  2880. }
  2881. DBUG_PRINT("info",
  2882. ("spider tgt_ssl_certs_lengths[%d] = %u", roop_count,
  2883. share->tgt_ssl_certs_lengths[roop_count]));
  2884. if (share->tgt_ssl_certs_lengths[roop_count] >
  2885. SPIDER_CONNECT_INFO_PATH_MAX_LEN)
  2886. {
  2887. error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
  2888. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
  2889. MYF(0), share->tgt_ssl_certs[roop_count], "ssl_cert");
  2890. goto error;
  2891. }
  2892. DBUG_PRINT("info",
  2893. ("spider tgt_ssl_ciphers_lengths[%d] = %u", roop_count,
  2894. share->tgt_ssl_ciphers_lengths[roop_count]));
  2895. if (share->tgt_ssl_ciphers_lengths[roop_count] >
  2896. SPIDER_CONNECT_INFO_MAX_LEN)
  2897. {
  2898. error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
  2899. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
  2900. MYF(0), share->tgt_ssl_ciphers[roop_count], "ssl_cipher");
  2901. goto error;
  2902. }
  2903. DBUG_PRINT("info",
  2904. ("spider tgt_ssl_keys_lengths[%d] = %u", roop_count,
  2905. share->tgt_ssl_keys_lengths[roop_count]));
  2906. if (share->tgt_ssl_keys_lengths[roop_count] >
  2907. SPIDER_CONNECT_INFO_PATH_MAX_LEN)
  2908. {
  2909. error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
  2910. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
  2911. MYF(0), share->tgt_ssl_keys[roop_count], "ssl_key");
  2912. goto error;
  2913. }
  2914. DBUG_PRINT("info",
  2915. ("spider tgt_default_files_lengths[%d] = %u", roop_count,
  2916. share->tgt_default_files_lengths[roop_count]));
  2917. if (share->tgt_default_files_lengths[roop_count] >
  2918. SPIDER_CONNECT_INFO_PATH_MAX_LEN)
  2919. {
  2920. error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
  2921. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
  2922. MYF(0), share->tgt_default_files[roop_count], "default_file");
  2923. goto error;
  2924. }
  2925. DBUG_PRINT("info",
  2926. ("spider tgt_default_groups_lengths[%d] = %u", roop_count,
  2927. share->tgt_default_groups_lengths[roop_count]));
  2928. if (share->tgt_default_groups_lengths[roop_count] >
  2929. SPIDER_CONNECT_INFO_MAX_LEN)
  2930. {
  2931. error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
  2932. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
  2933. MYF(0), share->tgt_default_groups[roop_count], "default_group");
  2934. goto error;
  2935. }
  2936. DBUG_PRINT("info",
  2937. ("spider tgt_pk_names_lengths[%d] = %u", roop_count,
  2938. share->tgt_pk_names_lengths[roop_count]));
  2939. if (share->tgt_pk_names_lengths[roop_count] >
  2940. SPIDER_CONNECT_INFO_MAX_LEN)
  2941. {
  2942. error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
  2943. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
  2944. MYF(0), share->tgt_pk_names[roop_count], "pk_name");
  2945. goto error;
  2946. }
  2947. DBUG_PRINT("info",
  2948. ("spider tgt_sequence_names_lengths[%d] = %u", roop_count,
  2949. share->tgt_sequence_names_lengths[roop_count]));
  2950. if (share->tgt_sequence_names_lengths[roop_count] >
  2951. SPIDER_CONNECT_INFO_MAX_LEN)
  2952. {
  2953. error_num = ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_NUM;
  2954. my_printf_error(error_num, ER_SPIDER_INVALID_CONNECT_INFO_TOO_LONG_STR,
  2955. MYF(0), share->tgt_sequence_names[roop_count], "sequence_name");
  2956. goto error;
  2957. }
  2958. }
  2959. }
  2960. DBUG_PRINT("info", ("spider share->active_link_count = %d",
  2961. share->active_link_count));
  2962. share->link_count = (uint) share->active_link_count;
  2963. share_alter->link_count = share->link_count;
  2964. share->link_bitmap_size = (share->link_count + 7) / 8;
  2965. if (connect_string)
  2966. spider_free(spider_current_trx, connect_string, MYF(0));
  2967. DBUG_RETURN(0);
  2968. error:
  2969. if (connect_string)
  2970. spider_free(spider_current_trx, connect_string, MYF(0));
  2971. error_alloc_conn_string:
  2972. DBUG_RETURN(error_num);
  2973. }
  2974. int spider_set_connect_info_default(
  2975. SPIDER_SHARE *share,
  2976. #ifdef WITH_PARTITION_STORAGE_ENGINE
  2977. partition_element *part_elem,
  2978. partition_element *sub_elem,
  2979. #endif
  2980. TABLE_SHARE *table_share
  2981. ) {
  2982. int error_num, roop_count;
  2983. DBUG_ENTER("spider_set_connect_info_default");
  2984. for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++)
  2985. {
  2986. if (share->server_names[roop_count])
  2987. {
  2988. if ((error_num = spider_get_server(share, roop_count)))
  2989. DBUG_RETURN(error_num);
  2990. }
  2991. if (!share->tgt_wrappers[roop_count])
  2992. {
  2993. DBUG_PRINT("info",("spider create default tgt_wrappers"));
  2994. share->tgt_wrappers_lengths[roop_count] = SPIDER_DB_WRAPPER_LEN;
  2995. if (
  2996. !(share->tgt_wrappers[roop_count] = spider_create_string(
  2997. SPIDER_DB_WRAPPER_STR,
  2998. share->tgt_wrappers_lengths[roop_count]))
  2999. ) {
  3000. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  3001. }
  3002. }
  3003. if (!share->tgt_hosts[roop_count])
  3004. {
  3005. DBUG_PRINT("info",("spider create default tgt_hosts"));
  3006. share->tgt_hosts_lengths[roop_count] = strlen(my_localhost);
  3007. if (
  3008. !(share->tgt_hosts[roop_count] = spider_create_string(
  3009. my_localhost,
  3010. share->tgt_hosts_lengths[roop_count]))
  3011. ) {
  3012. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  3013. }
  3014. }
  3015. if (!share->tgt_dbs[roop_count] && table_share)
  3016. {
  3017. DBUG_PRINT("info",("spider create default tgt_dbs"));
  3018. share->tgt_dbs_lengths[roop_count] = table_share->db.length;
  3019. if (
  3020. !(share->tgt_dbs[roop_count] = spider_create_string(
  3021. table_share->db.str,
  3022. table_share->db.length))
  3023. ) {
  3024. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  3025. }
  3026. }
  3027. if (!share->tgt_table_names[roop_count] && table_share)
  3028. {
  3029. DBUG_PRINT("info",("spider create default tgt_table_names"));
  3030. share->tgt_table_names_lengths[roop_count] = share->table_name_length;
  3031. if (
  3032. !(share->tgt_table_names[roop_count] = spider_create_table_name_string(
  3033. table_share->table_name.str,
  3034. #ifdef WITH_PARTITION_STORAGE_ENGINE
  3035. (part_elem ? part_elem->partition_name : NULL),
  3036. (sub_elem ? sub_elem->partition_name : NULL)
  3037. #else
  3038. NULL,
  3039. NULL
  3040. #endif
  3041. ))
  3042. ) {
  3043. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  3044. }
  3045. }
  3046. if (
  3047. !share->tgt_default_files[roop_count] &&
  3048. share->tgt_default_groups[roop_count] &&
  3049. (*spd_defaults_file || *spd_defaults_extra_file)
  3050. ) {
  3051. DBUG_PRINT("info",("spider create default tgt_default_files"));
  3052. if (*spd_defaults_extra_file)
  3053. {
  3054. share->tgt_default_files_lengths[roop_count] =
  3055. strlen(*spd_defaults_extra_file);
  3056. if (
  3057. !(share->tgt_default_files[roop_count] = spider_create_string(
  3058. *spd_defaults_extra_file,
  3059. share->tgt_default_files_lengths[roop_count]))
  3060. ) {
  3061. my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
  3062. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  3063. }
  3064. } else {
  3065. share->tgt_default_files_lengths[roop_count] =
  3066. strlen(*spd_defaults_file);
  3067. if (
  3068. !(share->tgt_default_files[roop_count] = spider_create_string(
  3069. *spd_defaults_file,
  3070. share->tgt_default_files_lengths[roop_count]))
  3071. ) {
  3072. my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
  3073. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  3074. }
  3075. }
  3076. }
  3077. if (!share->tgt_pk_names[roop_count])
  3078. {
  3079. DBUG_PRINT("info",("spider create default tgt_pk_names"));
  3080. share->tgt_pk_names_lengths[roop_count] = SPIDER_DB_PK_NAME_LEN;
  3081. if (
  3082. !(share->tgt_pk_names[roop_count] = spider_create_string(
  3083. SPIDER_DB_PK_NAME_STR,
  3084. share->tgt_pk_names_lengths[roop_count]))
  3085. ) {
  3086. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  3087. }
  3088. }
  3089. if (!share->tgt_sequence_names[roop_count])
  3090. {
  3091. DBUG_PRINT("info",("spider create default tgt_sequence_names"));
  3092. share->tgt_sequence_names_lengths[roop_count] =
  3093. SPIDER_DB_SEQUENCE_NAME_LEN;
  3094. if (
  3095. !(share->tgt_sequence_names[roop_count] = spider_create_string(
  3096. SPIDER_DB_SEQUENCE_NAME_STR,
  3097. share->tgt_sequence_names_lengths[roop_count]))
  3098. ) {
  3099. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  3100. }
  3101. }
  3102. if (share->tgt_ports[roop_count] == -1)
  3103. {
  3104. share->tgt_ports[roop_count] = MYSQL_PORT;
  3105. } else if (share->tgt_ports[roop_count] < 0)
  3106. {
  3107. share->tgt_ports[roop_count] = 0;
  3108. } else if (share->tgt_ports[roop_count] > 65535)
  3109. {
  3110. share->tgt_ports[roop_count] = 65535;
  3111. }
  3112. if (share->tgt_ssl_vscs[roop_count] == -1)
  3113. share->tgt_ssl_vscs[roop_count] = 0;
  3114. if (
  3115. !share->tgt_sockets[roop_count] &&
  3116. !strcmp(share->tgt_hosts[roop_count], my_localhost)
  3117. ) {
  3118. DBUG_PRINT("info",("spider create default tgt_sockets"));
  3119. share->tgt_sockets_lengths[roop_count] =
  3120. strlen((char *) MYSQL_UNIX_ADDR);
  3121. if (
  3122. !(share->tgt_sockets[roop_count] = spider_create_string(
  3123. (char *) MYSQL_UNIX_ADDR,
  3124. share->tgt_sockets_lengths[roop_count]))
  3125. ) {
  3126. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  3127. }
  3128. }
  3129. if (share->link_statuses[roop_count] == -1)
  3130. share->link_statuses[roop_count] = SPIDER_LINK_STATUS_NO_CHANGE;
  3131. #ifndef WITHOUT_SPIDER_BG_SEARCH
  3132. if (share->monitoring_bg_kind[roop_count] == -1)
  3133. share->monitoring_bg_kind[roop_count] = 0;
  3134. #endif
  3135. if (share->monitoring_kind[roop_count] == -1)
  3136. share->monitoring_kind[roop_count] = 0;
  3137. #ifndef WITHOUT_SPIDER_BG_SEARCH
  3138. if (share->monitoring_bg_interval[roop_count] == -1)
  3139. share->monitoring_bg_interval[roop_count] = 10000000;
  3140. #endif
  3141. if (share->monitoring_limit[roop_count] == -1)
  3142. share->monitoring_limit[roop_count] = 1;
  3143. if (share->monitoring_sid[roop_count] == -1)
  3144. #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100002
  3145. share->monitoring_sid[roop_count] = global_system_variables.server_id;
  3146. #else
  3147. share->monitoring_sid[roop_count] = current_thd->server_id;
  3148. #endif
  3149. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3150. if (share->use_hs_reads[roop_count] == -1)
  3151. share->use_hs_reads[roop_count] = 0;
  3152. if (share->use_hs_writes[roop_count] == -1)
  3153. share->use_hs_writes[roop_count] = 0;
  3154. if (share->hs_read_ports[roop_count] == -1)
  3155. {
  3156. share->hs_read_ports[roop_count] = 9998;
  3157. } else if (share->hs_read_ports[roop_count] < 0)
  3158. {
  3159. share->hs_read_ports[roop_count] = 0;
  3160. } else if (share->hs_read_ports[roop_count] > 65535)
  3161. {
  3162. share->hs_read_ports[roop_count] = 65535;
  3163. }
  3164. if (share->hs_write_ports[roop_count] == -1)
  3165. {
  3166. share->hs_write_ports[roop_count] = 9999;
  3167. } else if (share->hs_write_ports[roop_count] < 0)
  3168. {
  3169. share->hs_write_ports[roop_count] = 0;
  3170. } else if (share->hs_write_ports[roop_count] > 65535)
  3171. {
  3172. share->hs_write_ports[roop_count] = 65535;
  3173. }
  3174. if (share->hs_write_to_reads[roop_count] == -1)
  3175. {
  3176. share->hs_write_to_reads[roop_count] = 1;
  3177. } else if (share->hs_write_to_reads[roop_count] < 0)
  3178. {
  3179. share->hs_write_to_reads[roop_count] = 0;
  3180. } else if (share->hs_write_to_reads[roop_count] > 1)
  3181. {
  3182. share->hs_write_to_reads[roop_count] = 1;
  3183. }
  3184. #endif
  3185. if (share->use_handlers[roop_count] == -1)
  3186. share->use_handlers[roop_count] = 0;
  3187. if (share->connect_timeouts[roop_count] == -1)
  3188. share->connect_timeouts[roop_count] = 6;
  3189. if (share->net_read_timeouts[roop_count] == -1)
  3190. share->net_read_timeouts[roop_count] = 600;
  3191. if (share->net_write_timeouts[roop_count] == -1)
  3192. share->net_write_timeouts[roop_count] = 600;
  3193. if (share->access_balances[roop_count] == -1)
  3194. share->access_balances[roop_count] = 100;
  3195. }
  3196. #ifndef WITHOUT_SPIDER_BG_SEARCH
  3197. if (share->sts_bg_mode == -1)
  3198. share->sts_bg_mode = 1;
  3199. #endif
  3200. if (share->sts_interval == -1)
  3201. share->sts_interval = 10;
  3202. if (share->sts_mode == -1)
  3203. share->sts_mode = 1;
  3204. #ifdef WITH_PARTITION_STORAGE_ENGINE
  3205. if (share->sts_sync == -1)
  3206. share->sts_sync = 0;
  3207. #endif
  3208. #ifndef WITHOUT_SPIDER_BG_SEARCH
  3209. if (share->crd_bg_mode == -1)
  3210. share->crd_bg_mode = 1;
  3211. #endif
  3212. if (share->crd_interval == -1)
  3213. share->crd_interval = 51;
  3214. if (share->crd_mode == -1)
  3215. share->crd_mode = 1;
  3216. #ifdef WITH_PARTITION_STORAGE_ENGINE
  3217. if (share->crd_sync == -1)
  3218. share->crd_sync = 0;
  3219. #endif
  3220. if (share->crd_type == -1)
  3221. share->crd_type = 2;
  3222. if (share->crd_weight == -1)
  3223. share->crd_weight = 2;
  3224. if (share->internal_offset == -1)
  3225. share->internal_offset = 0;
  3226. if (share->internal_limit == -1)
  3227. share->internal_limit = 9223372036854775807LL;
  3228. if (share->split_read == -1)
  3229. share->split_read = 9223372036854775807LL;
  3230. if (share->semi_split_read == -1)
  3231. share->semi_split_read = 2;
  3232. if (share->semi_split_read_limit == -1)
  3233. share->semi_split_read_limit = 9223372036854775807LL;
  3234. if (share->init_sql_alloc_size == -1)
  3235. share->init_sql_alloc_size = 1024;
  3236. if (share->reset_sql_alloc == -1)
  3237. share->reset_sql_alloc = 1;
  3238. if (share->multi_split_read == -1)
  3239. share->multi_split_read = 100;
  3240. if (share->max_order == -1)
  3241. share->max_order = 32767;
  3242. if (share->semi_table_lock == -1)
  3243. share->semi_table_lock = 0;
  3244. if (share->semi_table_lock_conn == -1)
  3245. share->semi_table_lock_conn = 1;
  3246. if (share->selupd_lock_mode == -1)
  3247. share->selupd_lock_mode = 1;
  3248. if (share->query_cache == -1)
  3249. share->query_cache = 0;
  3250. if (share->query_cache_sync == -1)
  3251. share->query_cache_sync = 0;
  3252. if (share->internal_delayed == -1)
  3253. share->internal_delayed = 0;
  3254. if (share->bulk_size == -1)
  3255. share->bulk_size = 16000;
  3256. if (share->bulk_update_mode == -1)
  3257. share->bulk_update_mode = 0;
  3258. if (share->bulk_update_size == -1)
  3259. share->bulk_update_size = 16000;
  3260. if (share->internal_optimize == -1)
  3261. share->internal_optimize = 0;
  3262. if (share->internal_optimize_local == -1)
  3263. share->internal_optimize_local = 0;
  3264. if (share->scan_rate == -1)
  3265. share->scan_rate = 1;
  3266. if (share->read_rate == -1)
  3267. share->read_rate = 0.0002;
  3268. if (share->priority == -1)
  3269. share->priority = 1000000;
  3270. if (share->quick_mode == -1)
  3271. share->quick_mode = 0;
  3272. if (share->quick_page_size == -1)
  3273. share->quick_page_size = 100;
  3274. if (share->low_mem_read == -1)
  3275. share->low_mem_read = 1;
  3276. if (share->table_count_mode == -1)
  3277. share->table_count_mode = 0;
  3278. if (share->select_column_mode == -1)
  3279. share->select_column_mode = 1;
  3280. #ifndef WITHOUT_SPIDER_BG_SEARCH
  3281. if (share->bgs_mode == -1)
  3282. share->bgs_mode = 0;
  3283. if (share->bgs_first_read == -1)
  3284. share->bgs_first_read = 2;
  3285. if (share->bgs_second_read == -1)
  3286. share->bgs_second_read = 100;
  3287. #endif
  3288. if (share->first_read == -1)
  3289. share->first_read = 0;
  3290. if (share->second_read == -1)
  3291. share->second_read = 0;
  3292. if (share->auto_increment_mode == -1)
  3293. share->auto_increment_mode = 0;
  3294. if (share->use_table_charset == -1)
  3295. share->use_table_charset = 1;
  3296. if (share->use_pushdown_udf == -1)
  3297. share->use_pushdown_udf = 1;
  3298. if (share->skip_default_condition == -1)
  3299. share->skip_default_condition = 0;
  3300. if (share->direct_dup_insert == -1)
  3301. share->direct_dup_insert = 0;
  3302. if (share->direct_order_limit == -1)
  3303. share->direct_order_limit = 9223372036854775807LL;
  3304. if (share->read_only_mode == -1)
  3305. share->read_only_mode = 0;
  3306. if (share->error_read_mode == -1)
  3307. share->error_read_mode = 0;
  3308. if (share->error_write_mode == -1)
  3309. share->error_write_mode = 0;
  3310. if (share->active_link_count == -1)
  3311. share->active_link_count = share->all_link_count;
  3312. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3313. if (share->hs_result_free_size == -1)
  3314. share->hs_result_free_size = 1048576;
  3315. #endif
  3316. #ifdef HA_CAN_BULK_ACCESS
  3317. if (share->bulk_access_free == -1)
  3318. share->bulk_access_free = 0;
  3319. #endif
  3320. #ifdef HA_CAN_FORCE_BULK_UPDATE
  3321. if (share->force_bulk_update == -1)
  3322. share->force_bulk_update = 0;
  3323. #endif
  3324. #ifdef HA_CAN_FORCE_BULK_DELETE
  3325. if (share->force_bulk_delete == -1)
  3326. share->force_bulk_delete = 0;
  3327. #endif
  3328. if (share->casual_read == -1)
  3329. share->casual_read = 0;
  3330. if (share->delete_all_rows_type == -1)
  3331. {
  3332. #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
  3333. share->delete_all_rows_type = 1;
  3334. #else
  3335. share->delete_all_rows_type = 0;
  3336. #endif
  3337. }
  3338. if (share->bka_mode == -1)
  3339. share->bka_mode = 1;
  3340. if (!share->bka_engine)
  3341. {
  3342. DBUG_PRINT("info",("spider create default bka_engine"));
  3343. share->bka_engine_length = SPIDER_SQL_TMP_BKA_ENGINE_LEN;
  3344. if (
  3345. !(share->bka_engine = spider_create_string(
  3346. SPIDER_SQL_TMP_BKA_ENGINE_STR,
  3347. SPIDER_SQL_TMP_BKA_ENGINE_LEN))
  3348. ) {
  3349. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  3350. }
  3351. }
  3352. DBUG_RETURN(0);
  3353. }
  3354. int spider_set_connect_info_default_db_table(
  3355. SPIDER_SHARE *share,
  3356. const char *db_name,
  3357. uint db_name_length,
  3358. const char *table_name,
  3359. uint table_name_length
  3360. ) {
  3361. int roop_count;
  3362. DBUG_ENTER("spider_set_connect_info_default_db_table");
  3363. for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
  3364. {
  3365. if (!share->tgt_dbs[roop_count] && db_name)
  3366. {
  3367. DBUG_PRINT("info",("spider create default tgt_dbs"));
  3368. share->tgt_dbs_lengths[roop_count] = db_name_length;
  3369. if (
  3370. !(share->tgt_dbs[roop_count] = spider_create_string(
  3371. db_name,
  3372. db_name_length))
  3373. ) {
  3374. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  3375. }
  3376. }
  3377. if (!share->tgt_table_names[roop_count] && table_name)
  3378. {
  3379. const char *tmp_ptr;
  3380. DBUG_PRINT("info",("spider create default tgt_table_names"));
  3381. if ((tmp_ptr = strstr(table_name, "#P#")))
  3382. table_name_length = (uint) PTR_BYTE_DIFF(tmp_ptr, table_name);
  3383. share->tgt_table_names_lengths[roop_count] = table_name_length;
  3384. if (
  3385. !(share->tgt_table_names[roop_count] = spider_create_string(
  3386. table_name,
  3387. table_name_length))
  3388. ) {
  3389. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  3390. }
  3391. }
  3392. }
  3393. DBUG_RETURN(0);
  3394. }
  3395. int spider_set_connect_info_default_dbtable(
  3396. SPIDER_SHARE *share,
  3397. const char *dbtable_name,
  3398. int dbtable_name_length
  3399. ) {
  3400. const char *ptr_db, *ptr_table;
  3401. my_ptrdiff_t ptr_diff_db, ptr_diff_table;
  3402. DBUG_ENTER("spider_set_connect_info_default_dbtable");
  3403. ptr_db = strchr(dbtable_name, FN_LIBCHAR);
  3404. ptr_db++;
  3405. ptr_diff_db = PTR_BYTE_DIFF(ptr_db, dbtable_name);
  3406. DBUG_PRINT("info",("spider ptr_diff_db = %lld", (longlong) ptr_diff_db));
  3407. ptr_table = strchr(ptr_db, FN_LIBCHAR);
  3408. ptr_table++;
  3409. ptr_diff_table = PTR_BYTE_DIFF(ptr_table, ptr_db);
  3410. DBUG_PRINT("info",("spider ptr_diff_table = %lld", (longlong) ptr_diff_table));
  3411. DBUG_RETURN(spider_set_connect_info_default_db_table(
  3412. share,
  3413. ptr_db,
  3414. (uint)(ptr_diff_table - 1),
  3415. ptr_table,
  3416. (uint)(dbtable_name_length - ptr_diff_db - ptr_diff_table)
  3417. ));
  3418. }
  3419. #ifndef DBUG_OFF
  3420. void spider_print_keys(
  3421. const char *key,
  3422. uint length
  3423. ) {
  3424. const char *end_ptr;
  3425. uint roop_count = 1;
  3426. DBUG_ENTER("spider_print_keys");
  3427. DBUG_PRINT("info",("spider key_length=%u", length));
  3428. end_ptr = key + length;
  3429. while (key < end_ptr)
  3430. {
  3431. DBUG_PRINT("info",("spider key[%u]=%s", roop_count, key));
  3432. key = strchr(key, '\0') + 1;
  3433. roop_count++;
  3434. }
  3435. DBUG_VOID_RETURN;
  3436. }
  3437. #endif
  3438. int spider_create_conn_keys(
  3439. SPIDER_SHARE *share
  3440. ) {
  3441. int roop_count, roop_count2;
  3442. char *tmp_name, port_str[6];
  3443. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3444. char *tmp_hs_r_name, *tmp_hs_w_name;
  3445. #endif
  3446. #ifdef _MSC_VER
  3447. uint *conn_keys_lengths;
  3448. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3449. uint *hs_r_conn_keys_lengths;
  3450. uint *hs_w_conn_keys_lengths;
  3451. #endif
  3452. #else
  3453. uint conn_keys_lengths[share->all_link_count];
  3454. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3455. uint hs_r_conn_keys_lengths[share->all_link_count];
  3456. uint hs_w_conn_keys_lengths[share->all_link_count];
  3457. #endif
  3458. #endif
  3459. DBUG_ENTER("spider_create_conn_keys");
  3460. #ifdef _MSC_VER
  3461. if (!(conn_keys_lengths =
  3462. (uint *) spider_bulk_alloc_mem(spider_current_trx, 44,
  3463. __func__, __FILE__, __LINE__, MYF(MY_WME),
  3464. &conn_keys_lengths, sizeof(uint) * share->all_link_count,
  3465. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3466. &hs_r_conn_keys_lengths, sizeof(uint) * share->all_link_count,
  3467. &hs_w_conn_keys_lengths, sizeof(uint) * share->all_link_count,
  3468. #endif
  3469. NullS)))
  3470. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  3471. #endif
  3472. share->conn_keys_charlen = 0;
  3473. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3474. share->hs_read_conn_keys_charlen = 0;
  3475. share->hs_write_conn_keys_charlen = 0;
  3476. #endif
  3477. for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++)
  3478. {
  3479. /* tgt_db not use */
  3480. conn_keys_lengths[roop_count]
  3481. = 1
  3482. + share->tgt_wrappers_lengths[roop_count] + 1
  3483. + share->tgt_hosts_lengths[roop_count] + 1
  3484. + 5 + 1
  3485. + share->tgt_sockets_lengths[roop_count] + 1
  3486. + share->tgt_usernames_lengths[roop_count] + 1
  3487. + share->tgt_passwords_lengths[roop_count] + 1
  3488. + share->tgt_ssl_cas_lengths[roop_count] + 1
  3489. + share->tgt_ssl_capaths_lengths[roop_count] + 1
  3490. + share->tgt_ssl_certs_lengths[roop_count] + 1
  3491. + share->tgt_ssl_ciphers_lengths[roop_count] + 1
  3492. + share->tgt_ssl_keys_lengths[roop_count] + 1
  3493. + 1 + 1
  3494. + share->tgt_default_files_lengths[roop_count] + 1
  3495. + share->tgt_default_groups_lengths[roop_count];
  3496. share->conn_keys_charlen += conn_keys_lengths[roop_count] + 2;
  3497. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3498. hs_r_conn_keys_lengths[roop_count]
  3499. = 1
  3500. + share->tgt_wrappers_lengths[roop_count] + 1
  3501. + share->tgt_hosts_lengths[roop_count] + 1
  3502. + 5 + 1
  3503. + share->hs_read_socks_lengths[roop_count];
  3504. share->hs_read_conn_keys_charlen +=
  3505. hs_r_conn_keys_lengths[roop_count] + 2;
  3506. hs_w_conn_keys_lengths[roop_count]
  3507. = 1
  3508. + share->tgt_wrappers_lengths[roop_count] + 1
  3509. + share->tgt_hosts_lengths[roop_count] + 1
  3510. + 5 + 1
  3511. + share->hs_write_socks_lengths[roop_count];
  3512. share->hs_write_conn_keys_charlen +=
  3513. hs_w_conn_keys_lengths[roop_count] + 2;
  3514. #endif
  3515. }
  3516. if (!(share->conn_keys = (char **)
  3517. spider_bulk_alloc_mem(spider_current_trx, 45,
  3518. __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL),
  3519. &share->conn_keys, sizeof(char *) * share->all_link_count,
  3520. &share->conn_keys_lengths, sizeof(uint) * share->all_link_count,
  3521. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  3522. &share->conn_keys_hash_value,
  3523. sizeof(my_hash_value_type) * share->all_link_count,
  3524. #endif
  3525. &tmp_name, sizeof(char) * share->conn_keys_charlen,
  3526. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3527. &share->hs_read_conn_keys, sizeof(char *) * share->all_link_count,
  3528. &share->hs_read_conn_keys_lengths, sizeof(uint) * share->all_link_count,
  3529. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  3530. &share->hs_read_conn_keys_hash_value,
  3531. sizeof(my_hash_value_type) * share->all_link_count,
  3532. #endif
  3533. &tmp_hs_r_name, sizeof(char) * share->hs_read_conn_keys_charlen,
  3534. &share->hs_write_conn_keys, sizeof(char *) * share->all_link_count,
  3535. &share->hs_write_conn_keys_lengths, sizeof(uint) * share->all_link_count,
  3536. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  3537. &share->hs_write_conn_keys_hash_value,
  3538. sizeof(my_hash_value_type) * share->all_link_count,
  3539. #endif
  3540. &tmp_hs_w_name, sizeof(char) * share->hs_write_conn_keys_charlen,
  3541. #endif
  3542. &share->sql_dbton_ids, sizeof(uint) * share->all_link_count,
  3543. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3544. &share->hs_dbton_ids, sizeof(uint) * share->all_link_count,
  3545. #endif
  3546. NullS))
  3547. ) {
  3548. #ifdef _MSC_VER
  3549. spider_free(spider_current_trx, conn_keys_lengths, MYF(MY_WME));
  3550. #endif
  3551. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  3552. }
  3553. share->conn_keys_length = share->all_link_count;
  3554. memcpy(share->conn_keys_lengths, conn_keys_lengths,
  3555. sizeof(uint) * share->all_link_count);
  3556. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3557. share->hs_read_conn_keys_length = share->all_link_count;
  3558. share->hs_write_conn_keys_length = share->all_link_count;
  3559. memcpy(share->hs_read_conn_keys_lengths, hs_r_conn_keys_lengths,
  3560. sizeof(uint) * share->all_link_count);
  3561. memcpy(share->hs_write_conn_keys_lengths, hs_w_conn_keys_lengths,
  3562. sizeof(uint) * share->all_link_count);
  3563. #endif
  3564. #ifdef _MSC_VER
  3565. spider_free(spider_current_trx, conn_keys_lengths, MYF(MY_WME));
  3566. #endif
  3567. for (roop_count = 0; roop_count < (int) share->all_link_count; roop_count++)
  3568. {
  3569. share->conn_keys[roop_count] = tmp_name;
  3570. *tmp_name = '0';
  3571. DBUG_PRINT("info",("spider tgt_wrappers[%d]=%s", roop_count,
  3572. share->tgt_wrappers[roop_count]));
  3573. tmp_name = strmov(tmp_name + 1, share->tgt_wrappers[roop_count]);
  3574. DBUG_PRINT("info",("spider tgt_hosts[%d]=%s", roop_count,
  3575. share->tgt_hosts[roop_count]));
  3576. tmp_name = strmov(tmp_name + 1, share->tgt_hosts[roop_count]);
  3577. my_sprintf(port_str, (port_str, "%05ld", share->tgt_ports[roop_count]));
  3578. DBUG_PRINT("info",("spider port_str=%s", port_str));
  3579. tmp_name = strmov(tmp_name + 1, port_str);
  3580. if (share->tgt_sockets[roop_count])
  3581. {
  3582. DBUG_PRINT("info",("spider tgt_sockets[%d]=%s", roop_count,
  3583. share->tgt_sockets[roop_count]));
  3584. tmp_name = strmov(tmp_name + 1, share->tgt_sockets[roop_count]);
  3585. } else
  3586. tmp_name++;
  3587. if (share->tgt_usernames[roop_count])
  3588. {
  3589. DBUG_PRINT("info",("spider tgt_usernames[%d]=%s", roop_count,
  3590. share->tgt_usernames[roop_count]));
  3591. tmp_name = strmov(tmp_name + 1, share->tgt_usernames[roop_count]);
  3592. } else
  3593. tmp_name++;
  3594. if (share->tgt_passwords[roop_count])
  3595. {
  3596. DBUG_PRINT("info",("spider tgt_passwords[%d]=%s", roop_count,
  3597. share->tgt_passwords[roop_count]));
  3598. tmp_name = strmov(tmp_name + 1, share->tgt_passwords[roop_count]);
  3599. } else
  3600. tmp_name++;
  3601. if (share->tgt_ssl_cas[roop_count])
  3602. {
  3603. DBUG_PRINT("info",("spider tgt_ssl_cas[%d]=%s", roop_count,
  3604. share->tgt_ssl_cas[roop_count]));
  3605. tmp_name = strmov(tmp_name + 1, share->tgt_ssl_cas[roop_count]);
  3606. } else
  3607. tmp_name++;
  3608. if (share->tgt_ssl_capaths[roop_count])
  3609. {
  3610. DBUG_PRINT("info",("spider tgt_ssl_capaths[%d]=%s", roop_count,
  3611. share->tgt_ssl_capaths[roop_count]));
  3612. tmp_name = strmov(tmp_name + 1, share->tgt_ssl_capaths[roop_count]);
  3613. } else
  3614. tmp_name++;
  3615. if (share->tgt_ssl_certs[roop_count])
  3616. {
  3617. DBUG_PRINT("info",("spider tgt_ssl_certs[%d]=%s", roop_count,
  3618. share->tgt_ssl_certs[roop_count]));
  3619. tmp_name = strmov(tmp_name + 1, share->tgt_ssl_certs[roop_count]);
  3620. } else
  3621. tmp_name++;
  3622. if (share->tgt_ssl_ciphers[roop_count])
  3623. {
  3624. DBUG_PRINT("info",("spider tgt_ssl_ciphers[%d]=%s", roop_count,
  3625. share->tgt_ssl_ciphers[roop_count]));
  3626. tmp_name = strmov(tmp_name + 1, share->tgt_ssl_ciphers[roop_count]);
  3627. } else
  3628. tmp_name++;
  3629. if (share->tgt_ssl_keys[roop_count])
  3630. {
  3631. DBUG_PRINT("info",("spider tgt_ssl_keys[%d]=%s", roop_count,
  3632. share->tgt_ssl_keys[roop_count]));
  3633. tmp_name = strmov(tmp_name + 1, share->tgt_ssl_keys[roop_count]);
  3634. } else
  3635. tmp_name++;
  3636. tmp_name++;
  3637. *tmp_name = '0' + ((char) share->tgt_ssl_vscs[roop_count]);
  3638. if (share->tgt_default_files[roop_count])
  3639. {
  3640. DBUG_PRINT("info",("spider tgt_default_files[%d]=%s", roop_count,
  3641. share->tgt_default_files[roop_count]));
  3642. tmp_name = strmov(tmp_name + 1, share->tgt_default_files[roop_count]);
  3643. } else
  3644. tmp_name++;
  3645. if (share->tgt_default_groups[roop_count])
  3646. {
  3647. DBUG_PRINT("info",("spider tgt_default_groups[%d]=%s", roop_count,
  3648. share->tgt_default_groups[roop_count]));
  3649. tmp_name = strmov(tmp_name + 1, share->tgt_default_groups[roop_count]);
  3650. } else
  3651. tmp_name++;
  3652. tmp_name++;
  3653. tmp_name++;
  3654. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  3655. share->conn_keys_hash_value[roop_count] = my_calc_hash(
  3656. &spider_open_connections, (uchar*) share->conn_keys[roop_count],
  3657. share->conn_keys_lengths[roop_count]);
  3658. #endif
  3659. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3660. share->hs_read_conn_keys[roop_count] = tmp_hs_r_name;
  3661. *tmp_hs_r_name = '0';
  3662. DBUG_PRINT("info",("spider tgt_wrappers[%d]=%s", roop_count,
  3663. share->tgt_wrappers[roop_count]));
  3664. tmp_hs_r_name = strmov(tmp_hs_r_name + 1, share->tgt_wrappers[roop_count]);
  3665. DBUG_PRINT("info",("spider tgt_hosts[%d]=%s", roop_count,
  3666. share->tgt_hosts[roop_count]));
  3667. tmp_hs_r_name = strmov(tmp_hs_r_name + 1, share->tgt_hosts[roop_count]);
  3668. my_sprintf(port_str, (port_str, "%05ld",
  3669. share->hs_read_ports[roop_count]));
  3670. DBUG_PRINT("info",("spider port_str=%s", port_str));
  3671. tmp_hs_r_name = strmov(tmp_hs_r_name + 1, port_str);
  3672. if (share->hs_read_socks[roop_count])
  3673. {
  3674. DBUG_PRINT("info",("spider hs_read_socks[%d]=%s", roop_count,
  3675. share->hs_read_socks[roop_count]));
  3676. tmp_hs_r_name = strmov(tmp_hs_r_name + 1,
  3677. share->hs_read_socks[roop_count]);
  3678. } else
  3679. tmp_hs_r_name++;
  3680. tmp_hs_r_name++;
  3681. tmp_hs_r_name++;
  3682. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  3683. share->hs_read_conn_keys_hash_value[roop_count] = my_calc_hash(
  3684. &spider_open_connections, (uchar*) share->hs_read_conn_keys[roop_count],
  3685. share->hs_read_conn_keys_lengths[roop_count]);
  3686. #endif
  3687. share->hs_write_conn_keys[roop_count] = tmp_hs_w_name;
  3688. *tmp_hs_w_name = '0';
  3689. DBUG_PRINT("info",("spider tgt_wrappers[%d]=%s", roop_count,
  3690. share->tgt_wrappers[roop_count]));
  3691. tmp_hs_w_name = strmov(tmp_hs_w_name + 1, share->tgt_wrappers[roop_count]);
  3692. DBUG_PRINT("info",("spider tgt_hosts[%d]=%s", roop_count,
  3693. share->tgt_hosts[roop_count]));
  3694. tmp_hs_w_name = strmov(tmp_hs_w_name + 1, share->tgt_hosts[roop_count]);
  3695. my_sprintf(port_str, (port_str, "%05ld",
  3696. share->hs_write_ports[roop_count]));
  3697. DBUG_PRINT("info",("spider port_str=%s", port_str));
  3698. tmp_hs_w_name = strmov(tmp_hs_w_name + 1, port_str);
  3699. if (share->hs_write_socks[roop_count])
  3700. {
  3701. DBUG_PRINT("info",("spider hs_write_socks[%d]=%s", roop_count,
  3702. share->hs_write_socks[roop_count]));
  3703. tmp_hs_w_name = strmov(tmp_hs_w_name + 1,
  3704. share->hs_write_socks[roop_count]);
  3705. } else
  3706. tmp_hs_w_name++;
  3707. tmp_hs_w_name++;
  3708. tmp_hs_w_name++;
  3709. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  3710. share->hs_write_conn_keys_hash_value[roop_count] = my_calc_hash(
  3711. &spider_open_connections, (uchar*) share->hs_write_conn_keys[roop_count],
  3712. share->hs_write_conn_keys_lengths[roop_count]);
  3713. #endif
  3714. #endif
  3715. bool get_sql_id = FALSE;
  3716. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3717. bool get_nosql_id = FALSE;
  3718. #endif
  3719. for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++)
  3720. {
  3721. DBUG_PRINT("info",("spider share->tgt_wrappers[%d]=%s", roop_count,
  3722. share->tgt_wrappers[roop_count]));
  3723. DBUG_PRINT("info",("spider spider_dbton[%d].wrapper=%s", roop_count2,
  3724. spider_dbton[roop_count2].wrapper ?
  3725. spider_dbton[roop_count2].wrapper : "NULL"));
  3726. if (
  3727. spider_dbton[roop_count2].wrapper &&
  3728. !strcmp(share->tgt_wrappers[roop_count],
  3729. spider_dbton[roop_count2].wrapper)
  3730. ) {
  3731. spider_set_bit(share->dbton_bitmap, roop_count2);
  3732. if (
  3733. !get_sql_id &&
  3734. spider_dbton[roop_count2].db_access_type == SPIDER_DB_ACCESS_TYPE_SQL
  3735. ) {
  3736. share->sql_dbton_ids[roop_count] = roop_count2;
  3737. get_sql_id = TRUE;
  3738. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3739. if (get_nosql_id)
  3740. #endif
  3741. break;
  3742. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3743. else
  3744. continue;
  3745. #endif
  3746. }
  3747. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3748. if (
  3749. !get_nosql_id &&
  3750. spider_dbton[roop_count2].db_access_type ==
  3751. SPIDER_DB_ACCESS_TYPE_NOSQL
  3752. ) {
  3753. share->hs_dbton_ids[roop_count] = roop_count2;
  3754. get_nosql_id = TRUE;
  3755. if (get_sql_id)
  3756. break;
  3757. }
  3758. #endif
  3759. }
  3760. }
  3761. if (!get_sql_id)
  3762. share->sql_dbton_ids[roop_count] = SPIDER_DBTON_SIZE;
  3763. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3764. if (!get_nosql_id)
  3765. share->hs_dbton_ids[roop_count] = SPIDER_DBTON_SIZE;
  3766. #endif
  3767. }
  3768. for (roop_count2 = 0; roop_count2 < SPIDER_DBTON_SIZE; roop_count2++)
  3769. {
  3770. if (spider_bit_is_set(share->dbton_bitmap, roop_count2))
  3771. {
  3772. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3773. if (spider_dbton[roop_count2].db_access_type ==
  3774. SPIDER_DB_ACCESS_TYPE_SQL)
  3775. {
  3776. #endif
  3777. share->use_sql_dbton_ids[share->use_dbton_count] = roop_count2;
  3778. share->sql_dbton_id_to_seq[roop_count2] = share->use_dbton_count;
  3779. share->use_sql_dbton_count++;
  3780. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3781. } else {
  3782. share->use_hs_dbton_ids[share->use_hs_dbton_count] = roop_count2;
  3783. share->hs_dbton_id_to_seq[roop_count2] = share->use_hs_dbton_count;
  3784. share->use_hs_dbton_count++;
  3785. }
  3786. #endif
  3787. share->use_dbton_ids[share->use_dbton_count] = roop_count2;
  3788. share->dbton_id_to_seq[roop_count2] = share->use_dbton_count;
  3789. share->use_dbton_count++;
  3790. }
  3791. }
  3792. DBUG_RETURN(0);
  3793. }
  3794. SPIDER_SHARE *spider_create_share(
  3795. const char *table_name,
  3796. TABLE_SHARE *table_share,
  3797. #ifdef WITH_PARTITION_STORAGE_ENGINE
  3798. partition_info *part_info,
  3799. #endif
  3800. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  3801. my_hash_value_type hash_value,
  3802. #endif
  3803. int *error_num
  3804. ) {
  3805. int bitmap_size, roop_count;
  3806. uint length;
  3807. int use_table_charset;
  3808. SPIDER_SHARE *share;
  3809. char *tmp_name;
  3810. longlong *tmp_cardinality;
  3811. uchar *tmp_cardinality_upd;
  3812. DBUG_ENTER("spider_create_share");
  3813. length = (uint) strlen(table_name);
  3814. bitmap_size = spider_bitmap_size(table_share->fields);
  3815. if (!(share = (SPIDER_SHARE *)
  3816. spider_bulk_malloc(spider_current_trx, 46, MYF(MY_WME | MY_ZEROFILL),
  3817. &share, sizeof(*share),
  3818. &tmp_name, length + 1,
  3819. &tmp_cardinality, sizeof(*tmp_cardinality) * table_share->fields,
  3820. &tmp_cardinality_upd, sizeof(*tmp_cardinality_upd) * bitmap_size,
  3821. NullS))
  3822. ) {
  3823. *error_num = HA_ERR_OUT_OF_MEM;
  3824. goto error_alloc_share;
  3825. }
  3826. share->use_count = 0;
  3827. share->use_dbton_count = 0;
  3828. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3829. share->use_hs_dbton_count = 0;
  3830. #endif
  3831. share->table_name_length = length;
  3832. share->table_name = tmp_name;
  3833. strmov(share->table_name, table_name);
  3834. share->cardinality = tmp_cardinality;
  3835. share->cardinality_upd = tmp_cardinality_upd;
  3836. share->bitmap_size = bitmap_size;
  3837. share->table_share = table_share;
  3838. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  3839. share->table_name_hash_value = hash_value;
  3840. #ifdef WITH_PARTITION_STORAGE_ENGINE
  3841. share->table_path_hash_value = my_calc_hash(&spider_open_tables,
  3842. (uchar*) table_share->path.str, table_share->path.length);
  3843. #endif
  3844. #endif
  3845. if (table_share->keys > 0 &&
  3846. !(share->key_hint = new spider_string[table_share->keys])
  3847. ) {
  3848. *error_num = HA_ERR_OUT_OF_MEM;
  3849. goto error_init_hint_string;
  3850. }
  3851. for (roop_count = 0; roop_count < (int) table_share->keys; roop_count++)
  3852. share->key_hint[roop_count].init_calc_mem(95);
  3853. DBUG_PRINT("info",("spider share->key_hint=%p", share->key_hint));
  3854. if ((*error_num = spider_parse_connect_info(share, table_share,
  3855. #ifdef WITH_PARTITION_STORAGE_ENGINE
  3856. part_info,
  3857. #endif
  3858. 0)))
  3859. goto error_parse_connect_string;
  3860. use_table_charset = spider_param_use_table_charset(
  3861. share->use_table_charset);
  3862. if (table_share->table_charset && use_table_charset)
  3863. share->access_charset = table_share->table_charset;
  3864. else
  3865. share->access_charset = system_charset_info;
  3866. if ((*error_num = spider_create_conn_keys(share)))
  3867. goto error_create_conn_keys;
  3868. if (share->table_count_mode & 1)
  3869. share->additional_table_flags |= HA_STATS_RECORDS_IS_EXACT;
  3870. if (share->table_count_mode & 2)
  3871. share->additional_table_flags |= HA_HAS_RECORDS;
  3872. #if MYSQL_VERSION_ID < 50500
  3873. if (pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST))
  3874. #else
  3875. if (mysql_mutex_init(spd_key_mutex_share,
  3876. &share->mutex, MY_MUTEX_INIT_FAST))
  3877. #endif
  3878. {
  3879. *error_num = HA_ERR_OUT_OF_MEM;
  3880. goto error_init_mutex;
  3881. }
  3882. #if MYSQL_VERSION_ID < 50500
  3883. if (pthread_mutex_init(&share->sts_mutex, MY_MUTEX_INIT_FAST))
  3884. #else
  3885. if (mysql_mutex_init(spd_key_mutex_share_sts,
  3886. &share->sts_mutex, MY_MUTEX_INIT_FAST))
  3887. #endif
  3888. {
  3889. *error_num = HA_ERR_OUT_OF_MEM;
  3890. goto error_init_sts_mutex;
  3891. }
  3892. #if MYSQL_VERSION_ID < 50500
  3893. if (pthread_mutex_init(&share->crd_mutex, MY_MUTEX_INIT_FAST))
  3894. #else
  3895. if (mysql_mutex_init(spd_key_mutex_share_crd,
  3896. &share->crd_mutex, MY_MUTEX_INIT_FAST))
  3897. #endif
  3898. {
  3899. *error_num = HA_ERR_OUT_OF_MEM;
  3900. goto error_init_crd_mutex;
  3901. }
  3902. thr_lock_init(&share->lock);
  3903. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  3904. if (!(share->lgtm_tblhnd_share =
  3905. spider_get_lgtm_tblhnd_share(tmp_name, length, hash_value, FALSE, TRUE,
  3906. error_num)))
  3907. #else
  3908. if (!(share->lgtm_tblhnd_share =
  3909. spider_get_lgtm_tblhnd_share(tmp_name, length, FALSE, TRUE, error_num)))
  3910. #endif
  3911. {
  3912. goto error_get_lgtm_tblhnd_share;
  3913. }
  3914. #ifdef WITH_PARTITION_STORAGE_ENGINE
  3915. if (!(share->partition_share =
  3916. spider_get_pt_share(share, table_share, error_num)))
  3917. goto error_get_pt_share;
  3918. #endif
  3919. for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++)
  3920. {
  3921. if (spider_bit_is_set(share->dbton_bitmap, roop_count))
  3922. {
  3923. if (!(share->dbton_share[roop_count] =
  3924. spider_dbton[roop_count].create_db_share(share)))
  3925. {
  3926. *error_num = HA_ERR_OUT_OF_MEM;
  3927. goto error_init_dbton;
  3928. }
  3929. if ((*error_num = share->dbton_share[roop_count]->init()))
  3930. {
  3931. goto error_init_dbton;
  3932. }
  3933. }
  3934. }
  3935. DBUG_RETURN(share);
  3936. /*
  3937. roop_count = SPIDER_DBTON_SIZE - 1;
  3938. */
  3939. error_init_dbton:
  3940. for (; roop_count >= 0; roop_count--)
  3941. {
  3942. if (share->dbton_share[roop_count])
  3943. {
  3944. delete share->dbton_share[roop_count];
  3945. share->dbton_share[roop_count] = NULL;
  3946. }
  3947. }
  3948. #ifdef WITH_PARTITION_STORAGE_ENGINE
  3949. spider_free_pt_share(share->partition_share);
  3950. error_get_pt_share:
  3951. #endif
  3952. error_get_lgtm_tblhnd_share:
  3953. thr_lock_delete(&share->lock);
  3954. pthread_mutex_destroy(&share->crd_mutex);
  3955. error_init_crd_mutex:
  3956. pthread_mutex_destroy(&share->sts_mutex);
  3957. error_init_sts_mutex:
  3958. pthread_mutex_destroy(&share->mutex);
  3959. error_init_mutex:
  3960. error_create_conn_keys:
  3961. error_parse_connect_string:
  3962. error_init_hint_string:
  3963. spider_free_share_alloc(share);
  3964. spider_free(spider_current_trx, share, MYF(0));
  3965. error_alloc_share:
  3966. DBUG_RETURN(NULL);
  3967. }
  3968. SPIDER_SHARE *spider_get_share(
  3969. const char *table_name,
  3970. TABLE *table,
  3971. THD *thd,
  3972. ha_spider *spider,
  3973. int *error_num
  3974. ) {
  3975. SPIDER_SHARE *share;
  3976. TABLE_SHARE *table_share = table->s;
  3977. SPIDER_RESULT_LIST *result_list = &spider->result_list;
  3978. uint length, tmp_conn_link_idx = 0;
  3979. char *tmp_name, *tmp_cid;
  3980. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  3981. char *tmp_hs_r_name, *tmp_hs_w_name;
  3982. #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
  3983. uint32 *tmp_hs_r_ret_fields, *tmp_hs_w_ret_fields;
  3984. #endif
  3985. #endif
  3986. int roop_count;
  3987. double sts_interval;
  3988. int sts_mode;
  3989. #ifdef WITH_PARTITION_STORAGE_ENGINE
  3990. int sts_sync;
  3991. int auto_increment_mode;
  3992. #endif
  3993. double crd_interval;
  3994. int crd_mode;
  3995. #ifdef WITH_PARTITION_STORAGE_ENGINE
  3996. int crd_sync;
  3997. #endif
  3998. char first_byte;
  3999. int semi_table_lock_conn;
  4000. int search_link_idx;
  4001. uint sql_command = thd_sql_command(thd);
  4002. #if MYSQL_VERSION_ID < 50500
  4003. Open_tables_state open_tables_backup;
  4004. #else
  4005. Open_tables_backup open_tables_backup;
  4006. #endif
  4007. MEM_ROOT mem_root;
  4008. TABLE *table_tables = NULL;
  4009. bool init_mem_root = FALSE;
  4010. DBUG_ENTER("spider_get_share");
  4011. length = (uint) strlen(table_name);
  4012. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  4013. my_hash_value_type hash_value = my_calc_hash(&spider_open_tables,
  4014. (uchar*) table_name, length);
  4015. #endif
  4016. pthread_mutex_lock(&spider_tbl_mutex);
  4017. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  4018. if (!(share = (SPIDER_SHARE*) my_hash_search_using_hash_value(
  4019. &spider_open_tables, hash_value, (uchar*) table_name, length)))
  4020. #else
  4021. if (!(share = (SPIDER_SHARE*) my_hash_search(&spider_open_tables,
  4022. (uchar*) table_name, length)))
  4023. #endif
  4024. {
  4025. if (!(share = spider_create_share(
  4026. table_name, table_share,
  4027. #ifdef WITH_PARTITION_STORAGE_ENGINE
  4028. table->part_info,
  4029. #endif
  4030. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  4031. hash_value,
  4032. #endif
  4033. error_num
  4034. ))) {
  4035. goto error_alloc_share;
  4036. }
  4037. uint old_elements = spider_open_tables.array.max_element;
  4038. #ifdef HASH_UPDATE_WITH_HASH_VALUE
  4039. if (my_hash_insert_with_hash_value(&spider_open_tables, hash_value,
  4040. (uchar*) share))
  4041. #else
  4042. if (my_hash_insert(&spider_open_tables, (uchar*) share))
  4043. #endif
  4044. {
  4045. *error_num = HA_ERR_OUT_OF_MEM;
  4046. goto error_hash_insert;
  4047. }
  4048. if (spider_open_tables.array.max_element > old_elements)
  4049. {
  4050. spider_alloc_calc_mem(spider_current_trx,
  4051. spider_open_tables,
  4052. (spider_open_tables.array.max_element - old_elements) *
  4053. spider_open_tables.array.size_of_element);
  4054. }
  4055. spider->share = share;
  4056. spider->conn_link_idx = &tmp_conn_link_idx;
  4057. share->use_count++;
  4058. pthread_mutex_unlock(&spider_tbl_mutex);
  4059. if (!share->link_status_init)
  4060. {
  4061. pthread_mutex_lock(&share->mutex);
  4062. if (!share->link_status_init)
  4063. {
  4064. if (
  4065. table_share->tmp_table == NO_TMP_TABLE &&
  4066. sql_command != SQLCOM_DROP_TABLE &&
  4067. sql_command != SQLCOM_ALTER_TABLE &&
  4068. sql_command != SQLCOM_SHOW_CREATE
  4069. ) {
  4070. SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME));
  4071. init_mem_root = TRUE;
  4072. if (
  4073. !(table_tables = spider_open_sys_table(
  4074. thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
  4075. SPIDER_SYS_TABLES_TABLE_NAME_LEN, FALSE, &open_tables_backup,
  4076. FALSE, error_num))
  4077. ) {
  4078. pthread_mutex_unlock(&share->mutex);
  4079. spider_free_share(share);
  4080. goto error_open_sys_table;
  4081. }
  4082. *error_num = spider_get_link_statuses(table_tables, share,
  4083. &mem_root);
  4084. if (*error_num)
  4085. {
  4086. pthread_mutex_unlock(&share->mutex);
  4087. spider_free_share(share);
  4088. goto error_get_link_statuses;
  4089. }
  4090. }
  4091. share->have_recovery_link = spider_conn_check_recovery_link(share);
  4092. if (table_tables)
  4093. {
  4094. spider_close_sys_table(thd, table_tables,
  4095. &open_tables_backup, FALSE);
  4096. table_tables = NULL;
  4097. }
  4098. if (init_mem_root)
  4099. {
  4100. free_root(&mem_root, MYF(0));
  4101. init_mem_root = FALSE;
  4102. }
  4103. }
  4104. pthread_mutex_unlock(&share->mutex);
  4105. }
  4106. semi_table_lock_conn = spider_param_semi_table_lock_connection(thd,
  4107. share->semi_table_lock_conn);
  4108. if (semi_table_lock_conn)
  4109. first_byte = '0' +
  4110. spider_param_semi_table_lock(thd, share->semi_table_lock);
  4111. else
  4112. first_byte = '0';
  4113. if (!(spider->trx = spider_get_trx(thd, TRUE, error_num)))
  4114. {
  4115. share->init_error = TRUE;
  4116. share->init_error_time = (time_t) time((time_t*) 0);
  4117. share->init = TRUE;
  4118. spider_free_share(share);
  4119. goto error_but_no_delete;
  4120. }
  4121. spider->set_error_mode();
  4122. #ifndef WITHOUT_SPIDER_BG_SEARCH
  4123. if (
  4124. sql_command != SQLCOM_DROP_TABLE &&
  4125. sql_command != SQLCOM_ALTER_TABLE &&
  4126. sql_command != SQLCOM_SHOW_CREATE &&
  4127. (*error_num = spider_create_mon_threads(spider->trx, share))
  4128. ) {
  4129. share->init_error = TRUE;
  4130. share->init_error_time = (time_t) time((time_t*) 0);
  4131. share->init = TRUE;
  4132. spider_free_share(share);
  4133. goto error_but_no_delete;
  4134. }
  4135. #endif
  4136. if (!(spider->conn_keys = (char **)
  4137. spider_bulk_alloc_mem(spider_current_trx, 47,
  4138. __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL),
  4139. &spider->conn_keys, sizeof(char *) * share->link_count,
  4140. &tmp_name, sizeof(char) * share->conn_keys_charlen,
  4141. &spider->conns, sizeof(SPIDER_CONN *) * share->link_count,
  4142. &spider->conn_link_idx, sizeof(uint) * share->link_count,
  4143. &spider->conn_can_fo, sizeof(uchar) * share->link_bitmap_size,
  4144. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  4145. &spider->hs_r_conn_keys, sizeof(char *) * share->link_count,
  4146. &tmp_hs_r_name, sizeof(char) * share->hs_read_conn_keys_charlen,
  4147. &spider->hs_r_conns, sizeof(SPIDER_CONN *) * share->link_count,
  4148. &spider->hs_r_conn_ages, sizeof(ulonglong) * share->link_count,
  4149. &spider->hs_w_conn_keys, sizeof(char *) * share->link_count,
  4150. &tmp_hs_w_name, sizeof(char) * share->hs_write_conn_keys_charlen,
  4151. &spider->hs_w_conns, sizeof(SPIDER_CONN *) * share->link_count,
  4152. &spider->hs_w_conn_ages, sizeof(ulonglong) * share->link_count,
  4153. #endif
  4154. &spider->sql_kind, sizeof(uint) * share->link_count,
  4155. &spider->connection_ids, sizeof(ulonglong) * share->link_count,
  4156. &spider->conn_kind, sizeof(uint) * share->link_count,
  4157. &spider->db_request_id, sizeof(ulonglong) * share->link_count,
  4158. &spider->db_request_phase, sizeof(uchar) * share->link_bitmap_size,
  4159. &spider->m_handler_opened, sizeof(uchar) * share->link_bitmap_size,
  4160. &spider->m_handler_id, sizeof(uint) * share->link_count,
  4161. &spider->m_handler_cid, sizeof(char *) * share->link_count,
  4162. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  4163. &spider->r_handler_opened, sizeof(uchar) * share->link_bitmap_size,
  4164. &spider->r_handler_id, sizeof(uint) * share->link_count,
  4165. &spider->r_handler_index, sizeof(uint) * share->link_count,
  4166. &spider->w_handler_opened, sizeof(uchar) * share->link_bitmap_size,
  4167. &spider->w_handler_id, sizeof(uint) * share->link_count,
  4168. &spider->w_handler_index, sizeof(uint) * share->link_count,
  4169. #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
  4170. &spider->do_hs_direct_update, sizeof(uchar) * share->link_bitmap_size,
  4171. &spider->hs_r_ret_fields, sizeof(uint32 *) * share->link_count,
  4172. &spider->hs_w_ret_fields, sizeof(uint32 *) * share->link_count,
  4173. &spider->hs_r_ret_fields_num, sizeof(size_t) * share->link_count,
  4174. &spider->hs_w_ret_fields_num, sizeof(size_t) * share->link_count,
  4175. &tmp_hs_r_ret_fields,
  4176. sizeof(uint32) * share->link_count * table_share->fields,
  4177. &tmp_hs_w_ret_fields,
  4178. sizeof(uint32) * share->link_count * table_share->fields,
  4179. &spider->tmp_column_bitmap, sizeof(uchar) * share->bitmap_size,
  4180. #endif
  4181. #endif
  4182. &tmp_cid, sizeof(char) * (SPIDER_SQL_HANDLER_CID_LEN + 1) *
  4183. share->link_count,
  4184. &spider->need_mons, sizeof(int) * share->link_count,
  4185. &spider->quick_targets, sizeof(void *) * share->link_count,
  4186. &result_list->upd_tmp_tbls, sizeof(TABLE *) * share->link_count,
  4187. &result_list->upd_tmp_tbl_prms,
  4188. sizeof(TMP_TABLE_PARAM) * share->link_count,
  4189. &result_list->tmp_table_join_first,
  4190. sizeof(uchar) * share->link_bitmap_size,
  4191. &result_list->tmp_table_created,
  4192. sizeof(uchar) * share->link_bitmap_size,
  4193. #ifdef HA_CAN_BULK_ACCESS
  4194. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  4195. &result_list->hs_r_bulk_open_index,
  4196. sizeof(uchar) * share->link_bitmap_size,
  4197. &result_list->hs_w_bulk_open_index,
  4198. sizeof(uchar) * share->link_bitmap_size,
  4199. #endif
  4200. #endif
  4201. &result_list->sql_kind_backup, sizeof(uint) * share->link_count,
  4202. &result_list->casual_read, sizeof(int) * share->link_count,
  4203. &spider->dbton_handler,
  4204. sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE,
  4205. NullS))
  4206. ) {
  4207. share->init_error = TRUE;
  4208. share->init_error_time = (time_t) time((time_t*) 0);
  4209. share->init = TRUE;
  4210. spider_free_share(share);
  4211. goto error_but_no_delete;
  4212. }
  4213. memcpy(tmp_name, share->conn_keys[0], share->conn_keys_charlen);
  4214. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  4215. memcpy(tmp_hs_r_name, share->hs_read_conn_keys[0],
  4216. share->hs_read_conn_keys_charlen);
  4217. memcpy(tmp_hs_w_name, share->hs_write_conn_keys[0],
  4218. share->hs_write_conn_keys_charlen);
  4219. #endif
  4220. spider->conn_keys_first_ptr = tmp_name;
  4221. for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
  4222. {
  4223. spider->conn_keys[roop_count] = tmp_name;
  4224. *tmp_name = first_byte;
  4225. tmp_name += share->conn_keys_lengths[roop_count] + 1;
  4226. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  4227. spider->hs_r_conn_keys[roop_count] = tmp_hs_r_name;
  4228. tmp_hs_r_name += share->hs_read_conn_keys_lengths[roop_count] + 1;
  4229. spider->hs_w_conn_keys[roop_count] = tmp_hs_w_name;
  4230. tmp_hs_w_name += share->hs_write_conn_keys_lengths[roop_count] + 1;
  4231. #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
  4232. spider->hs_r_ret_fields[roop_count] = tmp_hs_r_ret_fields;
  4233. tmp_hs_r_ret_fields += table_share->fields;
  4234. spider->hs_w_ret_fields[roop_count] = tmp_hs_w_ret_fields;
  4235. tmp_hs_w_ret_fields += table_share->fields;
  4236. #endif
  4237. #endif
  4238. spider->m_handler_cid[roop_count] = tmp_cid;
  4239. tmp_cid += SPIDER_SQL_HANDLER_CID_LEN + 1;
  4240. result_list->upd_tmp_tbl_prms[roop_count].init();
  4241. result_list->upd_tmp_tbl_prms[roop_count].field_count = 1;
  4242. spider->conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL;
  4243. }
  4244. spider_trx_set_link_idx_for_all(spider);
  4245. for (roop_count = 0; roop_count < (int) share->use_dbton_count;
  4246. roop_count++)
  4247. {
  4248. uint dbton_id = share->use_dbton_ids[roop_count];
  4249. if (!(spider->dbton_handler[dbton_id] =
  4250. spider_dbton[dbton_id].create_db_handler(spider,
  4251. share->dbton_share[dbton_id])))
  4252. {
  4253. *error_num = HA_ERR_OUT_OF_MEM;
  4254. break;
  4255. }
  4256. if ((*error_num = spider->dbton_handler[dbton_id]->init()))
  4257. {
  4258. break;
  4259. }
  4260. }
  4261. if (roop_count < (int) share->use_dbton_count)
  4262. {
  4263. for (; roop_count >= 0; roop_count--)
  4264. {
  4265. uint dbton_id = share->use_dbton_ids[roop_count];
  4266. if (spider->dbton_handler[dbton_id])
  4267. {
  4268. delete spider->dbton_handler[dbton_id];
  4269. spider->dbton_handler[dbton_id] = NULL;
  4270. }
  4271. }
  4272. goto error_but_no_delete;
  4273. }
  4274. if (
  4275. sql_command != SQLCOM_DROP_TABLE &&
  4276. sql_command != SQLCOM_ALTER_TABLE &&
  4277. sql_command != SQLCOM_SHOW_CREATE
  4278. ) {
  4279. for (
  4280. roop_count = spider_conn_link_idx_next(share->link_statuses,
  4281. spider->conn_link_idx, -1, share->link_count,
  4282. SPIDER_LINK_STATUS_RECOVERY);
  4283. roop_count < (int) share->link_count;
  4284. roop_count = spider_conn_link_idx_next(share->link_statuses,
  4285. spider->conn_link_idx, roop_count, share->link_count,
  4286. SPIDER_LINK_STATUS_RECOVERY)
  4287. ) {
  4288. if (
  4289. !(spider->conns[roop_count] =
  4290. spider_get_conn(share, roop_count, spider->conn_keys[roop_count],
  4291. spider->trx, spider, FALSE, TRUE, SPIDER_CONN_KIND_MYSQL,
  4292. error_num))
  4293. ) {
  4294. if (
  4295. share->monitoring_kind[roop_count] &&
  4296. spider->need_mons[roop_count]
  4297. ) {
  4298. *error_num = spider_ping_table_mon_from_table(
  4299. spider->trx,
  4300. spider->trx->thd,
  4301. share,
  4302. (uint32) share->monitoring_sid[roop_count],
  4303. share->table_name,
  4304. share->table_name_length,
  4305. spider->conn_link_idx[roop_count],
  4306. NULL,
  4307. 0,
  4308. share->monitoring_kind[roop_count],
  4309. share->monitoring_limit[roop_count],
  4310. FALSE
  4311. );
  4312. }
  4313. share->init_error = TRUE;
  4314. share->init_error_time = (time_t) time((time_t*) 0);
  4315. share->init = TRUE;
  4316. spider_free_share(share);
  4317. goto error_but_no_delete;
  4318. }
  4319. spider->conns[roop_count]->error_mode &= spider->error_mode;
  4320. }
  4321. }
  4322. search_link_idx = spider_conn_first_link_idx(thd,
  4323. share->link_statuses, share->access_balances, spider->conn_link_idx,
  4324. share->link_count, SPIDER_LINK_STATUS_OK);
  4325. if (search_link_idx == -1)
  4326. {
  4327. #ifdef _MSC_VER
  4328. char *db, *table_name;
  4329. if (!(db = (char *)
  4330. spider_bulk_malloc(spider_current_trx, 48, MYF(MY_WME),
  4331. &db, table_share->db.length + 1,
  4332. &table_name, table_share->table_name.length + 1,
  4333. NullS))
  4334. ) {
  4335. *error_num = HA_ERR_OUT_OF_MEM;
  4336. share->init_error = TRUE;
  4337. share->init_error_time = (time_t) time((time_t*) 0);
  4338. share->init = TRUE;
  4339. spider_free_share(share);
  4340. goto error_but_no_delete;
  4341. }
  4342. #else
  4343. char db[table_share->db.length + 1],
  4344. table_name[table_share->table_name.length + 1];
  4345. #endif
  4346. memcpy(db, table_share->db.str, table_share->db.length);
  4347. db[table_share->db.length] = '\0';
  4348. memcpy(table_name, table_share->table_name.str,
  4349. table_share->table_name.length);
  4350. table_name[table_share->table_name.length] = '\0';
  4351. my_printf_error(ER_SPIDER_ALL_LINKS_FAILED_NUM,
  4352. ER_SPIDER_ALL_LINKS_FAILED_STR, MYF(0), db, table_name);
  4353. #ifdef _MSC_VER
  4354. spider_free(spider->trx, db, MYF(MY_WME));
  4355. #endif
  4356. *error_num = ER_SPIDER_ALL_LINKS_FAILED_NUM;
  4357. share->init_error = TRUE;
  4358. share->init_error_time = (time_t) time((time_t*) 0);
  4359. share->init = TRUE;
  4360. spider_free_share(share);
  4361. goto error_but_no_delete;
  4362. }
  4363. spider->search_link_idx = search_link_idx;
  4364. if (
  4365. sql_command != SQLCOM_DROP_TABLE &&
  4366. sql_command != SQLCOM_ALTER_TABLE &&
  4367. sql_command != SQLCOM_SHOW_CREATE &&
  4368. !spider->error_mode &&
  4369. !spider_param_same_server_link(thd)
  4370. ) {
  4371. SPIDER_INIT_ERROR_TABLE *spider_init_error_table;
  4372. sts_interval = spider_param_sts_interval(thd, share->sts_interval);
  4373. sts_mode = spider_param_sts_mode(thd, share->sts_mode);
  4374. #ifdef WITH_PARTITION_STORAGE_ENGINE
  4375. sts_sync = spider_param_sts_sync(thd, share->sts_sync);
  4376. auto_increment_mode = spider_param_auto_increment_mode(thd,
  4377. share->auto_increment_mode);
  4378. if (auto_increment_mode == 1)
  4379. sts_sync = 0;
  4380. #endif
  4381. crd_interval = spider_param_crd_interval(thd, share->crd_interval);
  4382. crd_mode = spider_param_crd_mode(thd, share->crd_mode);
  4383. if (crd_mode == 3)
  4384. crd_mode = 1;
  4385. #ifdef WITH_PARTITION_STORAGE_ENGINE
  4386. crd_sync = spider_param_crd_sync(thd, share->crd_sync);
  4387. #endif
  4388. time_t tmp_time = (time_t) time((time_t*) 0);
  4389. pthread_mutex_lock(&share->sts_mutex);
  4390. pthread_mutex_lock(&share->crd_mutex);
  4391. if ((spider_init_error_table =
  4392. spider_get_init_error_table(spider->trx, share, FALSE)))
  4393. {
  4394. DBUG_PRINT("info",("spider diff1=%f",
  4395. difftime(tmp_time, spider_init_error_table->init_error_time)));
  4396. if (difftime(tmp_time,
  4397. spider_init_error_table->init_error_time) <
  4398. spider_param_table_init_error_interval())
  4399. {
  4400. *error_num = spider_init_error_table->init_error;
  4401. if (spider_init_error_table->init_error_with_message)
  4402. my_message(spider_init_error_table->init_error,
  4403. spider_init_error_table->init_error_msg, MYF(0));
  4404. share->init_error = TRUE;
  4405. share->init = TRUE;
  4406. pthread_mutex_unlock(&share->crd_mutex);
  4407. pthread_mutex_unlock(&share->sts_mutex);
  4408. spider_free_share(share);
  4409. goto error_but_no_delete;
  4410. }
  4411. }
  4412. if (spider_get_sts(share, spider->search_link_idx, tmp_time,
  4413. spider, sts_interval, sts_mode,
  4414. #ifdef WITH_PARTITION_STORAGE_ENGINE
  4415. sts_sync,
  4416. #endif
  4417. 1, HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_AUTO))
  4418. {
  4419. thd->clear_error();
  4420. }
  4421. if (spider_get_crd(share, spider->search_link_idx, tmp_time,
  4422. spider, table, crd_interval, crd_mode,
  4423. #ifdef WITH_PARTITION_STORAGE_ENGINE
  4424. crd_sync,
  4425. #endif
  4426. 1))
  4427. {
  4428. thd->clear_error();
  4429. }
  4430. /*
  4431. if (
  4432. (*error_num = spider_get_sts(share, spider->search_link_idx, tmp_time,
  4433. spider, sts_interval, sts_mode,
  4434. #ifdef WITH_PARTITION_STORAGE_ENGINE
  4435. sts_sync,
  4436. #endif
  4437. 1)) ||
  4438. (*error_num = spider_get_crd(share, spider->search_link_idx, tmp_time,
  4439. spider, table, crd_interval, crd_mode,
  4440. #ifdef WITH_PARTITION_STORAGE_ENGINE
  4441. crd_sync,
  4442. #endif
  4443. 1))
  4444. ) {
  4445. if (
  4446. share->monitoring_kind[spider->search_link_idx] &&
  4447. spider->need_mons[spider->search_link_idx]
  4448. ) {
  4449. *error_num = spider_ping_table_mon_from_table(
  4450. spider->trx,
  4451. spider->trx->thd,
  4452. share,
  4453. share->monitoring_sid[spider->search_link_idx],
  4454. share->table_name,
  4455. share->table_name_length,
  4456. spider->conn_link_idx[spider->search_link_idx],
  4457. NULL,
  4458. 0,
  4459. share->monitoring_kind[spider->search_link_idx],
  4460. share->monitoring_limit[spider->search_link_idx],
  4461. FALSE
  4462. );
  4463. }
  4464. if (
  4465. spider_init_error_table ||
  4466. (spider_init_error_table =
  4467. spider_get_init_error_table(spider->trx, share, TRUE))
  4468. ) {
  4469. spider_init_error_table->init_error = *error_num;
  4470. if ((spider_init_error_table->init_error_with_message =
  4471. thd->is_error()))
  4472. strmov(spider_init_error_table->init_error_msg,
  4473. spider_stmt_da_message(thd));
  4474. spider_init_error_table->init_error_time =
  4475. (time_t) time((time_t*) 0);
  4476. }
  4477. share->init_error = TRUE;
  4478. share->init = TRUE;
  4479. spider_free_share(share);
  4480. goto error_but_no_delete;
  4481. }
  4482. */
  4483. pthread_mutex_unlock(&share->crd_mutex);
  4484. pthread_mutex_unlock(&share->sts_mutex);
  4485. }
  4486. share->init = TRUE;
  4487. } else {
  4488. share->use_count++;
  4489. pthread_mutex_unlock(&spider_tbl_mutex);
  4490. while (!share->init)
  4491. {
  4492. my_sleep(10);
  4493. }
  4494. if (!share->link_status_init)
  4495. {
  4496. pthread_mutex_lock(&share->mutex);
  4497. if (!share->link_status_init)
  4498. {
  4499. if (
  4500. table_share->tmp_table == NO_TMP_TABLE &&
  4501. sql_command != SQLCOM_DROP_TABLE &&
  4502. sql_command != SQLCOM_ALTER_TABLE &&
  4503. sql_command != SQLCOM_SHOW_CREATE
  4504. ) {
  4505. SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME));
  4506. init_mem_root = TRUE;
  4507. if (
  4508. !(table_tables = spider_open_sys_table(
  4509. thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
  4510. SPIDER_SYS_TABLES_TABLE_NAME_LEN, FALSE, &open_tables_backup,
  4511. FALSE, error_num))
  4512. ) {
  4513. pthread_mutex_unlock(&share->mutex);
  4514. spider_free_share(share);
  4515. goto error_open_sys_table;
  4516. }
  4517. *error_num = spider_get_link_statuses(table_tables, share,
  4518. &mem_root);
  4519. if (*error_num)
  4520. {
  4521. pthread_mutex_unlock(&share->mutex);
  4522. spider_free_share(share);
  4523. goto error_get_link_statuses;
  4524. }
  4525. }
  4526. share->have_recovery_link = spider_conn_check_recovery_link(share);
  4527. if (table_tables)
  4528. {
  4529. spider_close_sys_table(thd, table_tables,
  4530. &open_tables_backup, FALSE);
  4531. table_tables = NULL;
  4532. }
  4533. if (init_mem_root)
  4534. {
  4535. free_root(&mem_root, MYF(0));
  4536. init_mem_root = FALSE;
  4537. }
  4538. }
  4539. pthread_mutex_unlock(&share->mutex);
  4540. }
  4541. semi_table_lock_conn = spider_param_semi_table_lock_connection(thd,
  4542. share->semi_table_lock_conn);
  4543. if (semi_table_lock_conn)
  4544. first_byte = '0' +
  4545. spider_param_semi_table_lock(thd, share->semi_table_lock);
  4546. else
  4547. first_byte = '0';
  4548. spider->share = share;
  4549. if (!(spider->trx = spider_get_trx(thd, TRUE, error_num)))
  4550. {
  4551. spider_free_share(share);
  4552. goto error_but_no_delete;
  4553. }
  4554. spider->set_error_mode();
  4555. #ifndef WITHOUT_SPIDER_BG_SEARCH
  4556. if (
  4557. sql_command != SQLCOM_DROP_TABLE &&
  4558. sql_command != SQLCOM_ALTER_TABLE &&
  4559. sql_command != SQLCOM_SHOW_CREATE &&
  4560. (*error_num = spider_create_mon_threads(spider->trx, share))
  4561. ) {
  4562. spider_free_share(share);
  4563. goto error_but_no_delete;
  4564. }
  4565. #endif
  4566. if (!(spider->conn_keys = (char **)
  4567. spider_bulk_alloc_mem(spider_current_trx, 49,
  4568. __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL),
  4569. &spider->conn_keys, sizeof(char *) * share->link_count,
  4570. &tmp_name, sizeof(char) * share->conn_keys_charlen,
  4571. &spider->conns, sizeof(SPIDER_CONN *) * share->link_count,
  4572. &spider->conn_link_idx, sizeof(uint) * share->link_count,
  4573. &spider->conn_can_fo, sizeof(uchar) * share->link_bitmap_size,
  4574. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  4575. &spider->hs_r_conn_keys, sizeof(char *) * share->link_count,
  4576. &tmp_hs_r_name, sizeof(char) * share->hs_read_conn_keys_charlen,
  4577. &spider->hs_r_conns, sizeof(SPIDER_CONN *) * share->link_count,
  4578. &spider->hs_r_conn_ages, sizeof(ulonglong) * share->link_count,
  4579. &spider->hs_w_conn_keys, sizeof(char *) * share->link_count,
  4580. &tmp_hs_w_name, sizeof(char) * share->hs_write_conn_keys_charlen,
  4581. &spider->hs_w_conns, sizeof(SPIDER_CONN *) * share->link_count,
  4582. &spider->hs_w_conn_ages, sizeof(ulonglong) * share->link_count,
  4583. #endif
  4584. &spider->sql_kind, sizeof(uint) * share->link_count,
  4585. &spider->connection_ids, sizeof(ulonglong) * share->link_count,
  4586. &spider->conn_kind, sizeof(uint) * share->link_count,
  4587. &spider->db_request_id, sizeof(ulonglong) * share->link_count,
  4588. &spider->db_request_phase, sizeof(uchar) * share->link_bitmap_size,
  4589. &spider->m_handler_opened, sizeof(uchar) * share->link_bitmap_size,
  4590. &spider->m_handler_id, sizeof(uint) * share->link_count,
  4591. &spider->m_handler_cid, sizeof(char *) * share->link_count,
  4592. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  4593. &spider->r_handler_opened, sizeof(uchar) * share->link_bitmap_size,
  4594. &spider->r_handler_id, sizeof(uint) * share->link_count,
  4595. &spider->r_handler_index, sizeof(uint) * share->link_count,
  4596. &spider->w_handler_opened, sizeof(uchar) * share->link_bitmap_size,
  4597. &spider->w_handler_id, sizeof(uint) * share->link_count,
  4598. &spider->w_handler_index, sizeof(uint) * share->link_count,
  4599. #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
  4600. &spider->do_hs_direct_update, sizeof(uchar) * share->link_bitmap_size,
  4601. &spider->hs_r_ret_fields, sizeof(uint32 *) * share->link_count,
  4602. &spider->hs_w_ret_fields, sizeof(uint32 *) * share->link_count,
  4603. &spider->hs_r_ret_fields_num, sizeof(size_t) * share->link_count,
  4604. &spider->hs_w_ret_fields_num, sizeof(size_t) * share->link_count,
  4605. &tmp_hs_r_ret_fields,
  4606. sizeof(uint32) * share->link_count * table_share->fields,
  4607. &tmp_hs_w_ret_fields,
  4608. sizeof(uint32) * share->link_count * table_share->fields,
  4609. &spider->tmp_column_bitmap, sizeof(uchar) * share->bitmap_size,
  4610. #endif
  4611. #endif
  4612. &tmp_cid, sizeof(char) * (SPIDER_SQL_HANDLER_CID_LEN + 1) *
  4613. share->link_count,
  4614. &spider->need_mons, sizeof(int) * share->link_count,
  4615. &spider->quick_targets, sizeof(void *) * share->link_count,
  4616. &result_list->upd_tmp_tbls, sizeof(TABLE *) * share->link_count,
  4617. &result_list->upd_tmp_tbl_prms,
  4618. sizeof(TMP_TABLE_PARAM) * share->link_count,
  4619. &result_list->tmp_table_join_first,
  4620. sizeof(uchar) * share->link_bitmap_size,
  4621. &result_list->tmp_table_created,
  4622. sizeof(uchar) * share->link_bitmap_size,
  4623. #ifdef HA_CAN_BULK_ACCESS
  4624. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  4625. &result_list->hs_r_bulk_open_index,
  4626. sizeof(uchar) * share->link_bitmap_size,
  4627. &result_list->hs_w_bulk_open_index,
  4628. sizeof(uchar) * share->link_bitmap_size,
  4629. #endif
  4630. #endif
  4631. &result_list->sql_kind_backup, sizeof(uint) * share->link_count,
  4632. &result_list->casual_read, sizeof(int) * share->link_count,
  4633. &spider->dbton_handler,
  4634. sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE,
  4635. NullS))
  4636. ) {
  4637. spider_free_share(share);
  4638. goto error_but_no_delete;
  4639. }
  4640. memcpy(tmp_name, share->conn_keys[0], share->conn_keys_charlen);
  4641. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  4642. memcpy(tmp_hs_r_name, share->hs_read_conn_keys[0],
  4643. share->hs_read_conn_keys_charlen);
  4644. memcpy(tmp_hs_w_name, share->hs_write_conn_keys[0],
  4645. share->hs_write_conn_keys_charlen);
  4646. #endif
  4647. spider->conn_keys_first_ptr = tmp_name;
  4648. for (roop_count = 0; roop_count < (int) share->link_count; roop_count++)
  4649. {
  4650. spider->conn_keys[roop_count] = tmp_name;
  4651. *tmp_name = first_byte;
  4652. tmp_name += share->conn_keys_lengths[roop_count] + 1;
  4653. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  4654. spider->hs_r_conn_keys[roop_count] = tmp_hs_r_name;
  4655. tmp_hs_r_name += share->hs_read_conn_keys_lengths[roop_count] + 1;
  4656. spider->hs_w_conn_keys[roop_count] = tmp_hs_w_name;
  4657. tmp_hs_w_name += share->hs_write_conn_keys_lengths[roop_count] + 1;
  4658. #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
  4659. spider->hs_r_ret_fields[roop_count] = tmp_hs_r_ret_fields;
  4660. tmp_hs_r_ret_fields += table_share->fields;
  4661. spider->hs_w_ret_fields[roop_count] = tmp_hs_w_ret_fields;
  4662. tmp_hs_w_ret_fields += table_share->fields;
  4663. #endif
  4664. #endif
  4665. spider->m_handler_cid[roop_count] = tmp_cid;
  4666. tmp_cid += SPIDER_SQL_HANDLER_CID_LEN + 1;
  4667. result_list->upd_tmp_tbl_prms[roop_count].init();
  4668. result_list->upd_tmp_tbl_prms[roop_count].field_count = 1;
  4669. spider->conn_kind[roop_count] = SPIDER_CONN_KIND_MYSQL;
  4670. }
  4671. spider_trx_set_link_idx_for_all(spider);
  4672. for (roop_count = 0; roop_count < (int) share->use_dbton_count;
  4673. roop_count++)
  4674. {
  4675. uint dbton_id = share->use_dbton_ids[roop_count];
  4676. if (!(spider->dbton_handler[dbton_id] =
  4677. spider_dbton[dbton_id].create_db_handler(spider,
  4678. share->dbton_share[dbton_id])))
  4679. {
  4680. *error_num = HA_ERR_OUT_OF_MEM;
  4681. break;
  4682. }
  4683. if ((*error_num = spider->dbton_handler[dbton_id]->init()))
  4684. {
  4685. break;
  4686. }
  4687. }
  4688. if (roop_count < (int) share->use_dbton_count)
  4689. {
  4690. for (; roop_count >= 0; roop_count--)
  4691. {
  4692. uint dbton_id = share->use_dbton_ids[roop_count];
  4693. if (spider->dbton_handler[dbton_id])
  4694. {
  4695. delete spider->dbton_handler[dbton_id];
  4696. spider->dbton_handler[dbton_id] = NULL;
  4697. }
  4698. }
  4699. goto error_but_no_delete;
  4700. }
  4701. if (
  4702. sql_command != SQLCOM_DROP_TABLE &&
  4703. sql_command != SQLCOM_ALTER_TABLE &&
  4704. sql_command != SQLCOM_SHOW_CREATE
  4705. ) {
  4706. for (
  4707. roop_count = spider_conn_link_idx_next(share->link_statuses,
  4708. spider->conn_link_idx, -1, share->link_count,
  4709. SPIDER_LINK_STATUS_RECOVERY);
  4710. roop_count < (int) share->link_count;
  4711. roop_count = spider_conn_link_idx_next(share->link_statuses,
  4712. spider->conn_link_idx, roop_count, share->link_count,
  4713. SPIDER_LINK_STATUS_RECOVERY)
  4714. ) {
  4715. if (
  4716. !(spider->conns[roop_count] =
  4717. spider_get_conn(share, roop_count, spider->conn_keys[roop_count],
  4718. spider->trx, spider, FALSE, TRUE, SPIDER_CONN_KIND_MYSQL,
  4719. error_num))
  4720. ) {
  4721. if (
  4722. share->monitoring_kind[roop_count] &&
  4723. spider->need_mons[roop_count]
  4724. ) {
  4725. *error_num = spider_ping_table_mon_from_table(
  4726. spider->trx,
  4727. spider->trx->thd,
  4728. share,
  4729. (uint32) share->monitoring_sid[roop_count],
  4730. share->table_name,
  4731. share->table_name_length,
  4732. spider->conn_link_idx[roop_count],
  4733. NULL,
  4734. 0,
  4735. share->monitoring_kind[roop_count],
  4736. share->monitoring_limit[roop_count],
  4737. FALSE
  4738. );
  4739. }
  4740. spider_free_share(share);
  4741. goto error_but_no_delete;
  4742. }
  4743. spider->conns[roop_count]->error_mode &= spider->error_mode;
  4744. }
  4745. }
  4746. search_link_idx = spider_conn_first_link_idx(thd,
  4747. share->link_statuses, share->access_balances, spider->conn_link_idx,
  4748. share->link_count, SPIDER_LINK_STATUS_OK);
  4749. if (search_link_idx == -1)
  4750. {
  4751. #ifdef _MSC_VER
  4752. char *db, *table_name;
  4753. if (!(db = (char *)
  4754. spider_bulk_malloc(spider_current_trx, 50, MYF(MY_WME),
  4755. &db, table_share->db.length + 1,
  4756. &table_name, table_share->table_name.length + 1,
  4757. NullS))
  4758. ) {
  4759. *error_num = HA_ERR_OUT_OF_MEM;
  4760. spider_free_share(share);
  4761. goto error_but_no_delete;
  4762. }
  4763. #else
  4764. char db[table_share->db.length + 1],
  4765. table_name[table_share->table_name.length + 1];
  4766. #endif
  4767. memcpy(db, table_share->db.str, table_share->db.length);
  4768. db[table_share->db.length] = '\0';
  4769. memcpy(table_name, table_share->table_name.str,
  4770. table_share->table_name.length);
  4771. table_name[table_share->table_name.length] = '\0';
  4772. my_printf_error(ER_SPIDER_ALL_LINKS_FAILED_NUM,
  4773. ER_SPIDER_ALL_LINKS_FAILED_STR, MYF(0), db, table_name);
  4774. #ifdef _MSC_VER
  4775. spider_free(spider->trx, db, MYF(MY_WME));
  4776. #endif
  4777. *error_num = ER_SPIDER_ALL_LINKS_FAILED_NUM;
  4778. spider_free_share(share);
  4779. goto error_but_no_delete;
  4780. }
  4781. spider->search_link_idx = search_link_idx;
  4782. if (share->init_error)
  4783. {
  4784. pthread_mutex_lock(&share->sts_mutex);
  4785. pthread_mutex_lock(&share->crd_mutex);
  4786. if (share->init_error)
  4787. {
  4788. if (
  4789. sql_command != SQLCOM_DROP_TABLE &&
  4790. sql_command != SQLCOM_ALTER_TABLE &&
  4791. sql_command != SQLCOM_SHOW_CREATE &&
  4792. !spider->error_mode &&
  4793. !spider_param_same_server_link(thd)
  4794. ) {
  4795. SPIDER_INIT_ERROR_TABLE *spider_init_error_table;
  4796. sts_interval = spider_param_sts_interval(thd, share->sts_interval);
  4797. sts_mode = spider_param_sts_mode(thd, share->sts_mode);
  4798. #ifdef WITH_PARTITION_STORAGE_ENGINE
  4799. sts_sync = spider_param_sts_sync(thd, share->sts_sync);
  4800. auto_increment_mode = spider_param_auto_increment_mode(thd,
  4801. share->auto_increment_mode);
  4802. if (auto_increment_mode == 1)
  4803. sts_sync = 0;
  4804. #endif
  4805. crd_interval = spider_param_crd_interval(thd, share->crd_interval);
  4806. crd_mode = spider_param_crd_mode(thd, share->crd_mode);
  4807. if (crd_mode == 3)
  4808. crd_mode = 1;
  4809. #ifdef WITH_PARTITION_STORAGE_ENGINE
  4810. crd_sync = spider_param_crd_sync(thd, share->crd_sync);
  4811. #endif
  4812. time_t tmp_time = (time_t) time((time_t*) 0);
  4813. if ((spider_init_error_table =
  4814. spider_get_init_error_table(spider->trx, share, FALSE)))
  4815. {
  4816. DBUG_PRINT("info",("spider diff2=%f",
  4817. difftime(tmp_time, spider_init_error_table->init_error_time)));
  4818. if (difftime(tmp_time,
  4819. spider_init_error_table->init_error_time) <
  4820. spider_param_table_init_error_interval())
  4821. {
  4822. *error_num = spider_init_error_table->init_error;
  4823. if (spider_init_error_table->init_error_with_message)
  4824. my_message(spider_init_error_table->init_error,
  4825. spider_init_error_table->init_error_msg, MYF(0));
  4826. pthread_mutex_unlock(&share->crd_mutex);
  4827. pthread_mutex_unlock(&share->sts_mutex);
  4828. spider_free_share(share);
  4829. goto error_but_no_delete;
  4830. }
  4831. }
  4832. if (spider_get_sts(share, spider->search_link_idx,
  4833. tmp_time, spider, sts_interval, sts_mode,
  4834. #ifdef WITH_PARTITION_STORAGE_ENGINE
  4835. sts_sync,
  4836. #endif
  4837. 1, HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_AUTO))
  4838. {
  4839. thd->clear_error();
  4840. }
  4841. if (spider_get_crd(share, spider->search_link_idx,
  4842. tmp_time, spider, table, crd_interval, crd_mode,
  4843. #ifdef WITH_PARTITION_STORAGE_ENGINE
  4844. crd_sync,
  4845. #endif
  4846. 1))
  4847. {
  4848. thd->clear_error();
  4849. }
  4850. /*
  4851. if (
  4852. (*error_num = spider_get_sts(share, spider->search_link_idx,
  4853. tmp_time, spider, sts_interval, sts_mode,
  4854. #ifdef WITH_PARTITION_STORAGE_ENGINE
  4855. sts_sync,
  4856. #endif
  4857. 1)) ||
  4858. (*error_num = spider_get_crd(share, spider->search_link_idx,
  4859. tmp_time, spider, table, crd_interval, crd_mode,
  4860. #ifdef WITH_PARTITION_STORAGE_ENGINE
  4861. crd_sync,
  4862. #endif
  4863. 1))
  4864. ) {
  4865. if (
  4866. share->monitoring_kind[spider->search_link_idx] &&
  4867. spider->need_mons[spider->search_link_idx]
  4868. ) {
  4869. *error_num = spider_ping_table_mon_from_table(
  4870. spider->trx,
  4871. spider->trx->thd,
  4872. share,
  4873. share->monitoring_sid[spider->search_link_idx],
  4874. share->table_name,
  4875. share->table_name_length,
  4876. spider->conn_link_idx[spider->search_link_idx],
  4877. NULL,
  4878. 0,
  4879. share->monitoring_kind[spider->search_link_idx],
  4880. share->monitoring_limit[spider->search_link_idx],
  4881. FALSE
  4882. );
  4883. }
  4884. if (
  4885. spider_init_error_table ||
  4886. (spider_init_error_table =
  4887. spider_get_init_error_table(spider->trx, share, TRUE))
  4888. ) {
  4889. spider_init_error_table->init_error = *error_num;
  4890. if ((spider_init_error_table->init_error_with_message =
  4891. thd->is_error()))
  4892. strmov(spider_init_error_table->init_error_msg,
  4893. spider_stmt_da_message(thd));
  4894. spider_init_error_table->init_error_time =
  4895. (time_t) time((time_t*) 0);
  4896. }
  4897. pthread_mutex_unlock(&share->crd_mutex);
  4898. pthread_mutex_unlock(&share->sts_mutex);
  4899. spider_free_share(share);
  4900. goto error_but_no_delete;
  4901. }
  4902. */
  4903. }
  4904. share->init_error = FALSE;
  4905. }
  4906. pthread_mutex_unlock(&share->crd_mutex);
  4907. pthread_mutex_unlock(&share->sts_mutex);
  4908. }
  4909. }
  4910. DBUG_PRINT("info",("spider share=%p", share));
  4911. DBUG_RETURN(share);
  4912. error_hash_insert:
  4913. spider_free_share_resource_only(share);
  4914. error_alloc_share:
  4915. pthread_mutex_unlock(&spider_tbl_mutex);
  4916. error_get_link_statuses:
  4917. if (table_tables)
  4918. {
  4919. spider_close_sys_table(thd, table_tables,
  4920. &open_tables_backup, FALSE);
  4921. table_tables = NULL;
  4922. }
  4923. error_open_sys_table:
  4924. if (init_mem_root)
  4925. {
  4926. free_root(&mem_root, MYF(0));
  4927. init_mem_root = FALSE;
  4928. }
  4929. error_but_no_delete:
  4930. DBUG_RETURN(NULL);
  4931. }
  4932. void spider_free_share_resource_only(
  4933. SPIDER_SHARE *share
  4934. ) {
  4935. DBUG_ENTER("spider_free_share_resource_only");
  4936. spider_free_share_alloc(share);
  4937. thr_lock_delete(&share->lock);
  4938. pthread_mutex_destroy(&share->crd_mutex);
  4939. pthread_mutex_destroy(&share->sts_mutex);
  4940. pthread_mutex_destroy(&share->mutex);
  4941. spider_free(spider_current_trx, share, MYF(0));
  4942. DBUG_VOID_RETURN;
  4943. }
  4944. int spider_free_share(
  4945. SPIDER_SHARE *share
  4946. ) {
  4947. DBUG_ENTER("spider_free_share");
  4948. pthread_mutex_lock(&spider_tbl_mutex);
  4949. if (!--share->use_count)
  4950. {
  4951. #ifndef WITHOUT_SPIDER_BG_SEARCH
  4952. spider_free_sts_thread(share);
  4953. spider_free_crd_thread(share);
  4954. spider_free_mon_threads(share);
  4955. #endif
  4956. spider_free_share_alloc(share);
  4957. #ifdef HASH_UPDATE_WITH_HASH_VALUE
  4958. my_hash_delete_with_hash_value(&spider_open_tables,
  4959. share->table_name_hash_value, (uchar*) share);
  4960. #else
  4961. my_hash_delete(&spider_open_tables, (uchar*) share);
  4962. #endif
  4963. thr_lock_delete(&share->lock);
  4964. pthread_mutex_destroy(&share->crd_mutex);
  4965. pthread_mutex_destroy(&share->sts_mutex);
  4966. pthread_mutex_destroy(&share->mutex);
  4967. spider_free(spider_current_trx, share, MYF(0));
  4968. }
  4969. pthread_mutex_unlock(&spider_tbl_mutex);
  4970. DBUG_RETURN(0);
  4971. }
  4972. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  4973. SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share(
  4974. const char *table_name,
  4975. uint table_name_length,
  4976. my_hash_value_type hash_value,
  4977. bool locked,
  4978. bool need_to_create,
  4979. int *error_num
  4980. )
  4981. #else
  4982. SPIDER_LGTM_TBLHND_SHARE *spider_get_lgtm_tblhnd_share(
  4983. const char *table_name,
  4984. uint table_name_length,
  4985. bool locked,
  4986. bool need_to_create,
  4987. int *error_num
  4988. )
  4989. #endif
  4990. {
  4991. SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share;
  4992. char *tmp_name;
  4993. DBUG_ENTER("spider_get_lgtm_tblhnd_share");
  4994. if (!locked)
  4995. pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex);
  4996. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  4997. if (!(lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE*)
  4998. my_hash_search_using_hash_value(
  4999. &spider_lgtm_tblhnd_share_hash, hash_value,
  5000. (uchar*) table_name, table_name_length)))
  5001. #else
  5002. if (!(lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE*) my_hash_search(
  5003. &spider_lgtm_tblhnd_share_hash,
  5004. (uchar*) table_name, table_name_length)))
  5005. #endif
  5006. {
  5007. DBUG_PRINT("info",("spider create new lgtm tblhnd share"));
  5008. if (!(lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE *)
  5009. spider_bulk_malloc(spider_current_trx, 244, MYF(MY_WME | MY_ZEROFILL),
  5010. &lgtm_tblhnd_share, sizeof(*lgtm_tblhnd_share),
  5011. &tmp_name, table_name_length + 1,
  5012. NullS))
  5013. ) {
  5014. *error_num = HA_ERR_OUT_OF_MEM;
  5015. goto error_alloc_share;
  5016. }
  5017. lgtm_tblhnd_share->table_name_length = table_name_length;
  5018. lgtm_tblhnd_share->table_name = tmp_name;
  5019. memcpy(lgtm_tblhnd_share->table_name, table_name,
  5020. lgtm_tblhnd_share->table_name_length);
  5021. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  5022. lgtm_tblhnd_share->table_path_hash_value = hash_value;
  5023. #endif
  5024. #if MYSQL_VERSION_ID < 50500
  5025. if (pthread_mutex_init(&lgtm_tblhnd_share->auto_increment_mutex,
  5026. MY_MUTEX_INIT_FAST))
  5027. #else
  5028. if (mysql_mutex_init(spd_key_mutex_share_auto_increment,
  5029. &lgtm_tblhnd_share->auto_increment_mutex, MY_MUTEX_INIT_FAST))
  5030. #endif
  5031. {
  5032. *error_num = HA_ERR_OUT_OF_MEM;
  5033. goto error_init_auto_increment_mutex;
  5034. }
  5035. uint old_elements = spider_lgtm_tblhnd_share_hash.array.max_element;
  5036. #ifdef HASH_UPDATE_WITH_HASH_VALUE
  5037. if (my_hash_insert_with_hash_value(&spider_lgtm_tblhnd_share_hash,
  5038. hash_value, (uchar*) lgtm_tblhnd_share))
  5039. #else
  5040. if (my_hash_insert(&spider_lgtm_tblhnd_share_hash,
  5041. (uchar*) lgtm_tblhnd_share))
  5042. #endif
  5043. {
  5044. *error_num = HA_ERR_OUT_OF_MEM;
  5045. goto error_hash_insert;
  5046. }
  5047. if (spider_lgtm_tblhnd_share_hash.array.max_element > old_elements)
  5048. {
  5049. spider_alloc_calc_mem(spider_current_trx,
  5050. spider_lgtm_tblhnd_share_hash,
  5051. (spider_lgtm_tblhnd_share_hash.array.max_element - old_elements) *
  5052. spider_lgtm_tblhnd_share_hash.array.size_of_element);
  5053. }
  5054. }
  5055. if (!locked)
  5056. pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
  5057. DBUG_PRINT("info",("spider lgtm_tblhnd_share=%p", lgtm_tblhnd_share));
  5058. DBUG_RETURN(lgtm_tblhnd_share);
  5059. error_hash_insert:
  5060. pthread_mutex_destroy(&lgtm_tblhnd_share->auto_increment_mutex);
  5061. error_init_auto_increment_mutex:
  5062. spider_free(spider_current_trx, lgtm_tblhnd_share, MYF(0));
  5063. error_alloc_share:
  5064. if (!locked)
  5065. pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
  5066. DBUG_RETURN(NULL);
  5067. }
  5068. void spider_free_lgtm_tblhnd_share_alloc(
  5069. SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share,
  5070. bool locked
  5071. ) {
  5072. DBUG_ENTER("spider_free_lgtm_tblhnd_share");
  5073. if (!locked)
  5074. pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex);
  5075. #ifdef HASH_UPDATE_WITH_HASH_VALUE
  5076. my_hash_delete_with_hash_value(&spider_lgtm_tblhnd_share_hash,
  5077. lgtm_tblhnd_share->table_path_hash_value, (uchar*) lgtm_tblhnd_share);
  5078. #else
  5079. my_hash_delete(&spider_lgtm_tblhnd_share_hash, (uchar*) lgtm_tblhnd_share);
  5080. #endif
  5081. pthread_mutex_destroy(&lgtm_tblhnd_share->auto_increment_mutex);
  5082. spider_free(spider_current_trx, lgtm_tblhnd_share, MYF(0));
  5083. if (!locked)
  5084. pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
  5085. DBUG_VOID_RETURN;
  5086. }
  5087. #ifdef WITH_PARTITION_STORAGE_ENGINE
  5088. SPIDER_PARTITION_SHARE *spider_get_pt_share(
  5089. SPIDER_SHARE *share,
  5090. TABLE_SHARE *table_share,
  5091. int *error_num
  5092. ) {
  5093. SPIDER_PARTITION_SHARE *partition_share;
  5094. char *tmp_name;
  5095. longlong *tmp_cardinality;
  5096. DBUG_ENTER("spider_get_pt_share");
  5097. pthread_mutex_lock(&spider_pt_share_mutex);
  5098. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  5099. if (!(partition_share = (SPIDER_PARTITION_SHARE*)
  5100. my_hash_search_using_hash_value(
  5101. &spider_open_pt_share, share->table_path_hash_value,
  5102. (uchar*) table_share->path.str, table_share->path.length)))
  5103. #else
  5104. if (!(partition_share = (SPIDER_PARTITION_SHARE*) my_hash_search(
  5105. &spider_open_pt_share,
  5106. (uchar*) table_share->path.str, table_share->path.length)))
  5107. #endif
  5108. {
  5109. DBUG_PRINT("info",("spider create new pt share"));
  5110. if (!(partition_share = (SPIDER_PARTITION_SHARE *)
  5111. spider_bulk_malloc(spider_current_trx, 51, MYF(MY_WME | MY_ZEROFILL),
  5112. &partition_share, sizeof(*partition_share),
  5113. &tmp_name, table_share->path.length + 1,
  5114. &tmp_cardinality, sizeof(*tmp_cardinality) * table_share->fields,
  5115. NullS))
  5116. ) {
  5117. *error_num = HA_ERR_OUT_OF_MEM;
  5118. goto error_alloc_share;
  5119. }
  5120. partition_share->use_count = 0;
  5121. partition_share->table_name_length = table_share->path.length;
  5122. partition_share->table_name = tmp_name;
  5123. memcpy(partition_share->table_name, table_share->path.str,
  5124. partition_share->table_name_length);
  5125. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  5126. partition_share->table_path_hash_value = share->table_path_hash_value;
  5127. #endif
  5128. partition_share->cardinality = tmp_cardinality;
  5129. partition_share->crd_get_time = partition_share->sts_get_time =
  5130. share->crd_get_time;
  5131. #if MYSQL_VERSION_ID < 50500
  5132. if (pthread_mutex_init(&partition_share->sts_mutex, MY_MUTEX_INIT_FAST))
  5133. #else
  5134. if (mysql_mutex_init(spd_key_mutex_pt_share_sts,
  5135. &partition_share->sts_mutex, MY_MUTEX_INIT_FAST))
  5136. #endif
  5137. {
  5138. *error_num = HA_ERR_OUT_OF_MEM;
  5139. goto error_init_sts_mutex;
  5140. }
  5141. #if MYSQL_VERSION_ID < 50500
  5142. if (pthread_mutex_init(&partition_share->crd_mutex, MY_MUTEX_INIT_FAST))
  5143. #else
  5144. if (mysql_mutex_init(spd_key_mutex_pt_share_crd,
  5145. &partition_share->crd_mutex, MY_MUTEX_INIT_FAST))
  5146. #endif
  5147. {
  5148. *error_num = HA_ERR_OUT_OF_MEM;
  5149. goto error_init_crd_mutex;
  5150. }
  5151. #if MYSQL_VERSION_ID < 50500
  5152. if (pthread_mutex_init(&partition_share->pt_handler_mutex,
  5153. MY_MUTEX_INIT_FAST))
  5154. #else
  5155. if (mysql_mutex_init(spd_key_mutex_pt_handler,
  5156. &partition_share->pt_handler_mutex, MY_MUTEX_INIT_FAST))
  5157. #endif
  5158. {
  5159. *error_num = HA_ERR_OUT_OF_MEM;
  5160. goto error_init_pt_handler_mutex;
  5161. }
  5162. if(
  5163. my_hash_init(&partition_share->pt_handler_hash, spd_charset_utf8_bin,
  5164. 32, 0, 0, (my_hash_get_key) spider_pt_handler_share_get_key, 0, 0)
  5165. ) {
  5166. *error_num = HA_ERR_OUT_OF_MEM;
  5167. goto error_init_pt_handler_hash;
  5168. }
  5169. spider_alloc_calc_mem_init(partition_share->pt_handler_hash, 142);
  5170. spider_alloc_calc_mem(spider_current_trx,
  5171. partition_share->pt_handler_hash,
  5172. partition_share->pt_handler_hash.array.max_element *
  5173. partition_share->pt_handler_hash.array.size_of_element);
  5174. uint old_elements = spider_open_pt_share.array.max_element;
  5175. #ifdef HASH_UPDATE_WITH_HASH_VALUE
  5176. if (my_hash_insert_with_hash_value(&spider_open_pt_share,
  5177. share->table_path_hash_value,
  5178. (uchar*) partition_share))
  5179. #else
  5180. if (my_hash_insert(&spider_open_pt_share, (uchar*) partition_share))
  5181. #endif
  5182. {
  5183. *error_num = HA_ERR_OUT_OF_MEM;
  5184. goto error_hash_insert;
  5185. }
  5186. if (spider_open_pt_share.array.max_element > old_elements)
  5187. {
  5188. spider_alloc_calc_mem(spider_current_trx,
  5189. spider_open_pt_share,
  5190. (spider_open_pt_share.array.max_element - old_elements) *
  5191. spider_open_pt_share.array.size_of_element);
  5192. }
  5193. }
  5194. partition_share->use_count++;
  5195. pthread_mutex_unlock(&spider_pt_share_mutex);
  5196. DBUG_PRINT("info",("spider partition_share=%p", partition_share));
  5197. DBUG_RETURN(partition_share);
  5198. error_hash_insert:
  5199. spider_free_mem_calc(spider_current_trx,
  5200. partition_share->pt_handler_hash_id,
  5201. partition_share->pt_handler_hash.array.max_element *
  5202. partition_share->pt_handler_hash.array.size_of_element);
  5203. my_hash_free(&partition_share->pt_handler_hash);
  5204. error_init_pt_handler_hash:
  5205. pthread_mutex_destroy(&partition_share->pt_handler_mutex);
  5206. error_init_pt_handler_mutex:
  5207. pthread_mutex_destroy(&partition_share->crd_mutex);
  5208. error_init_crd_mutex:
  5209. pthread_mutex_destroy(&partition_share->sts_mutex);
  5210. error_init_sts_mutex:
  5211. spider_free(spider_current_trx, partition_share, MYF(0));
  5212. error_alloc_share:
  5213. pthread_mutex_unlock(&spider_pt_share_mutex);
  5214. DBUG_RETURN(NULL);
  5215. }
  5216. int spider_free_pt_share(
  5217. SPIDER_PARTITION_SHARE *partition_share
  5218. ) {
  5219. DBUG_ENTER("spider_free_pt_share");
  5220. pthread_mutex_lock(&spider_pt_share_mutex);
  5221. if (!--partition_share->use_count)
  5222. {
  5223. #ifdef HASH_UPDATE_WITH_HASH_VALUE
  5224. my_hash_delete_with_hash_value(&spider_open_pt_share,
  5225. partition_share->table_path_hash_value, (uchar*) partition_share);
  5226. #else
  5227. my_hash_delete(&spider_open_pt_share, (uchar*) partition_share);
  5228. #endif
  5229. spider_free_mem_calc(spider_current_trx,
  5230. partition_share->pt_handler_hash_id,
  5231. partition_share->pt_handler_hash.array.max_element *
  5232. partition_share->pt_handler_hash.array.size_of_element);
  5233. my_hash_free(&partition_share->pt_handler_hash);
  5234. pthread_mutex_destroy(&partition_share->pt_handler_mutex);
  5235. pthread_mutex_destroy(&partition_share->crd_mutex);
  5236. pthread_mutex_destroy(&partition_share->sts_mutex);
  5237. spider_free(spider_current_trx, partition_share, MYF(0));
  5238. }
  5239. pthread_mutex_unlock(&spider_pt_share_mutex);
  5240. DBUG_RETURN(0);
  5241. }
  5242. void spider_copy_sts_to_pt_share(
  5243. SPIDER_PARTITION_SHARE *partition_share,
  5244. SPIDER_SHARE *share
  5245. ) {
  5246. DBUG_ENTER("spider_copy_sts_to_pt_share");
  5247. memcpy(&partition_share->data_file_length, &share->data_file_length,
  5248. sizeof(ulonglong) * 4 + sizeof(ha_rows) +
  5249. sizeof(ulong) + sizeof(time_t) * 3);
  5250. /*
  5251. partition_share->data_file_length = share->data_file_length;
  5252. partition_share->max_data_file_length = share->max_data_file_length;
  5253. partition_share->index_file_length = share->index_file_length;
  5254. partition_share->auto_increment_value =
  5255. share->lgtm_tblhnd_share->auto_increment_value;
  5256. partition_share->records = share->records;
  5257. partition_share->mean_rec_length = share->mean_rec_length;
  5258. partition_share->check_time = share->check_time;
  5259. partition_share->create_time = share->create_time;
  5260. partition_share->update_time = share->update_time;
  5261. */
  5262. DBUG_VOID_RETURN;
  5263. }
  5264. void spider_copy_sts_to_share(
  5265. SPIDER_SHARE *share,
  5266. SPIDER_PARTITION_SHARE *partition_share
  5267. ) {
  5268. DBUG_ENTER("spider_copy_sts_to_share");
  5269. memcpy(&share->data_file_length, &partition_share->data_file_length,
  5270. sizeof(ulonglong) * 4 + sizeof(ha_rows) +
  5271. sizeof(ulong) + sizeof(time_t) * 3);
  5272. /*
  5273. share->data_file_length = partition_share->data_file_length;
  5274. share->max_data_file_length = partition_share->max_data_file_length;
  5275. share->index_file_length = partition_share->index_file_length;
  5276. share->lgtm_tblhnd_share->auto_increment_value =
  5277. partition_share->auto_increment_value;
  5278. DBUG_PRINT("info",("spider auto_increment_value=%llu",
  5279. share->lgtm_tblhnd_share->auto_increment_value));
  5280. share->records = partition_share->records;
  5281. share->mean_rec_length = partition_share->mean_rec_length;
  5282. share->check_time = partition_share->check_time;
  5283. share->create_time = partition_share->create_time;
  5284. share->update_time = partition_share->update_time;
  5285. */
  5286. DBUG_VOID_RETURN;
  5287. }
  5288. void spider_copy_crd_to_pt_share(
  5289. SPIDER_PARTITION_SHARE *partition_share,
  5290. SPIDER_SHARE *share,
  5291. int fields
  5292. ) {
  5293. DBUG_ENTER("spider_copy_crd_to_pt_share");
  5294. memcpy(partition_share->cardinality, share->cardinality,
  5295. sizeof(longlong) * fields);
  5296. DBUG_VOID_RETURN;
  5297. }
  5298. void spider_copy_crd_to_share(
  5299. SPIDER_SHARE *share,
  5300. SPIDER_PARTITION_SHARE *partition_share,
  5301. int fields
  5302. ) {
  5303. DBUG_ENTER("spider_copy_crd_to_share");
  5304. memcpy(share->cardinality, partition_share->cardinality,
  5305. sizeof(longlong) * fields);
  5306. DBUG_VOID_RETURN;
  5307. }
  5308. #endif
  5309. int spider_open_all_tables(
  5310. SPIDER_TRX *trx,
  5311. bool lock
  5312. ) {
  5313. THD *thd = trx->thd;
  5314. TABLE *table_tables;
  5315. int error_num, *need_mon, mon_val;
  5316. SPIDER_SHARE tmp_share;
  5317. char *db_name, *table_name;
  5318. uint db_name_length, table_name_length;
  5319. char *tmp_connect_info[SPIDER_TMP_SHARE_CHAR_PTR_COUNT];
  5320. uint tmp_connect_info_length[SPIDER_TMP_SHARE_UINT_COUNT];
  5321. long tmp_long[SPIDER_TMP_SHARE_LONG_COUNT];
  5322. longlong tmp_longlong[SPIDER_TMP_SHARE_LONGLONG_COUNT];
  5323. SPIDER_CONN *conn, **conns;
  5324. ha_spider *spider;
  5325. SPIDER_SHARE *share;
  5326. char **connect_info;
  5327. uint *connect_info_length;
  5328. long *long_info;
  5329. longlong *longlong_info;
  5330. MEM_ROOT mem_root;
  5331. #if MYSQL_VERSION_ID < 50500
  5332. Open_tables_state open_tables_backup;
  5333. #else
  5334. Open_tables_backup open_tables_backup;
  5335. #endif
  5336. DBUG_ENTER("spider_open_all_tables");
  5337. if (
  5338. !(table_tables = spider_open_sys_table(
  5339. thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
  5340. SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, TRUE,
  5341. &error_num))
  5342. )
  5343. DBUG_RETURN(error_num);
  5344. if (
  5345. (error_num = spider_sys_index_first(table_tables, 1))
  5346. ) {
  5347. if (error_num != HA_ERR_KEY_NOT_FOUND && error_num != HA_ERR_END_OF_FILE)
  5348. {
  5349. table_tables->file->print_error(error_num, MYF(0));
  5350. spider_close_sys_table(thd, table_tables,
  5351. &open_tables_backup, TRUE);
  5352. DBUG_RETURN(error_num);
  5353. } else {
  5354. spider_close_sys_table(thd, table_tables,
  5355. &open_tables_backup, TRUE);
  5356. DBUG_RETURN(0);
  5357. }
  5358. }
  5359. SPD_INIT_ALLOC_ROOT(&mem_root, 4096, 0, MYF(MY_WME));
  5360. memset(&tmp_share, 0, sizeof(SPIDER_SHARE));
  5361. memset(&tmp_connect_info, 0,
  5362. sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT);
  5363. memset(tmp_connect_info_length, 0,
  5364. sizeof(uint) * SPIDER_TMP_SHARE_UINT_COUNT);
  5365. memset(tmp_long, 0, sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT);
  5366. memset(tmp_longlong, 0, sizeof(longlong) * SPIDER_TMP_SHARE_LONGLONG_COUNT);
  5367. spider_set_tmp_share_pointer(&tmp_share, (char **) &tmp_connect_info,
  5368. tmp_connect_info_length, tmp_long, tmp_longlong);
  5369. tmp_share.link_statuses[0] = -1;
  5370. do {
  5371. if (
  5372. (error_num = spider_get_sys_tables(
  5373. table_tables, &db_name, &table_name, &mem_root)) ||
  5374. (error_num = spider_get_sys_tables_connect_info(
  5375. table_tables, &tmp_share, 0, &mem_root)) ||
  5376. (error_num = spider_set_connect_info_default(
  5377. &tmp_share,
  5378. #ifdef WITH_PARTITION_STORAGE_ENGINE
  5379. NULL,
  5380. NULL,
  5381. #endif
  5382. NULL
  5383. ))
  5384. ) {
  5385. spider_sys_index_end(table_tables);
  5386. spider_close_sys_table(thd, table_tables,
  5387. &open_tables_backup, TRUE);
  5388. spider_free_tmp_share_alloc(&tmp_share);
  5389. free_root(&mem_root, MYF(0));
  5390. DBUG_RETURN(error_num);
  5391. }
  5392. db_name_length = strlen(db_name);
  5393. table_name_length = strlen(table_name);
  5394. if (
  5395. (error_num = spider_set_connect_info_default_db_table(
  5396. &tmp_share,
  5397. db_name,
  5398. db_name_length,
  5399. table_name,
  5400. table_name_length
  5401. )) ||
  5402. (error_num = spider_create_conn_keys(&tmp_share)) ||
  5403. /*
  5404. (error_num = spider_db_create_table_names_str(&tmp_share)) ||
  5405. */
  5406. (error_num = spider_create_tmp_dbton_share(&tmp_share))
  5407. ) {
  5408. spider_sys_index_end(table_tables);
  5409. spider_close_sys_table(thd, table_tables,
  5410. &open_tables_backup, TRUE);
  5411. spider_free_tmp_share_alloc(&tmp_share);
  5412. free_root(&mem_root, MYF(0));
  5413. DBUG_RETURN(error_num);
  5414. }
  5415. /* create conn */
  5416. if (
  5417. !(conn = spider_get_conn(
  5418. &tmp_share, 0, tmp_share.conn_keys[0], trx, NULL, FALSE, FALSE,
  5419. SPIDER_CONN_KIND_MYSQL, &error_num))
  5420. ) {
  5421. spider_sys_index_end(table_tables);
  5422. spider_close_sys_table(thd, table_tables,
  5423. &open_tables_backup, TRUE);
  5424. spider_free_tmp_dbton_share(&tmp_share);
  5425. spider_free_tmp_share_alloc(&tmp_share);
  5426. free_root(&mem_root, MYF(0));
  5427. DBUG_RETURN(error_num);
  5428. }
  5429. conn->error_mode &= spider_param_error_read_mode(thd, 0);
  5430. conn->error_mode &= spider_param_error_write_mode(thd, 0);
  5431. pthread_mutex_lock(&conn->mta_conn_mutex);
  5432. SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
  5433. conn->need_mon = &mon_val;
  5434. conn->mta_conn_mutex_lock_already = TRUE;
  5435. conn->mta_conn_mutex_unlock_later = TRUE;
  5436. if ((error_num = spider_db_before_query(conn, &mon_val)))
  5437. {
  5438. conn->mta_conn_mutex_lock_already = FALSE;
  5439. conn->mta_conn_mutex_unlock_later = FALSE;
  5440. SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
  5441. pthread_mutex_unlock(&conn->mta_conn_mutex);
  5442. spider_sys_index_end(table_tables);
  5443. spider_close_sys_table(thd, table_tables,
  5444. &open_tables_backup, TRUE);
  5445. spider_free_tmp_dbton_share(&tmp_share);
  5446. spider_free_tmp_share_alloc(&tmp_share);
  5447. free_root(&mem_root, MYF(0));
  5448. DBUG_RETURN(error_num);
  5449. }
  5450. conn->mta_conn_mutex_lock_already = FALSE;
  5451. conn->mta_conn_mutex_unlock_later = FALSE;
  5452. SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
  5453. pthread_mutex_unlock(&conn->mta_conn_mutex);
  5454. if (lock && spider_param_use_snapshot_with_flush_tables(thd) == 2)
  5455. {
  5456. if (!(spider = new ha_spider()))
  5457. {
  5458. spider_sys_index_end(table_tables);
  5459. spider_close_sys_table(thd, table_tables,
  5460. &open_tables_backup, TRUE);
  5461. spider_free_tmp_dbton_share(&tmp_share);
  5462. spider_free_tmp_share_alloc(&tmp_share);
  5463. free_root(&mem_root, MYF(0));
  5464. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  5465. }
  5466. spider->lock_type = TL_READ_NO_INSERT;
  5467. if (!(share = (SPIDER_SHARE *)
  5468. spider_bulk_malloc(spider_current_trx, 52, MYF(MY_WME | MY_ZEROFILL),
  5469. &share, sizeof(*share),
  5470. &connect_info, sizeof(char *) * SPIDER_TMP_SHARE_CHAR_PTR_COUNT,
  5471. &connect_info_length, sizeof(uint) * SPIDER_TMP_SHARE_UINT_COUNT,
  5472. &long_info, sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT,
  5473. &longlong_info, sizeof(longlong) * SPIDER_TMP_SHARE_LONGLONG_COUNT,
  5474. &conns, sizeof(SPIDER_CONN *),
  5475. &need_mon, sizeof(int),
  5476. &spider->conn_link_idx, sizeof(uint),
  5477. &spider->conn_can_fo, sizeof(uchar),
  5478. NullS))
  5479. ) {
  5480. delete spider;
  5481. spider_sys_index_end(table_tables);
  5482. spider_close_sys_table(thd, table_tables,
  5483. &open_tables_backup, TRUE);
  5484. spider_free_tmp_dbton_share(&tmp_share);
  5485. spider_free_tmp_share_alloc(&tmp_share);
  5486. free_root(&mem_root, MYF(0));
  5487. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  5488. }
  5489. memcpy(share, &tmp_share, sizeof(*share));
  5490. spider_set_tmp_share_pointer(share, connect_info,
  5491. connect_info_length, long_info, longlong_info);
  5492. memcpy(connect_info, &tmp_connect_info, sizeof(char *) *
  5493. SPIDER_TMP_SHARE_CHAR_PTR_COUNT);
  5494. memcpy(connect_info_length, &tmp_connect_info_length, sizeof(uint) *
  5495. SPIDER_TMP_SHARE_UINT_COUNT);
  5496. memcpy(long_info, &tmp_long, sizeof(long) * SPIDER_TMP_SHARE_LONG_COUNT);
  5497. memcpy(longlong_info, &tmp_longlong, sizeof(longlong) *
  5498. SPIDER_TMP_SHARE_LONGLONG_COUNT);
  5499. spider->share = share;
  5500. spider->trx = trx;
  5501. spider->conns = conns;
  5502. spider->need_mons = need_mon;
  5503. spider->conn_link_idx[0] = 0;
  5504. spider->conn_can_fo[0] = 0;
  5505. if ((error_num = spider_create_tmp_dbton_handler(spider)))
  5506. {
  5507. spider_free(trx, share, MYF(0));
  5508. delete spider;
  5509. spider_sys_index_end(table_tables);
  5510. spider_close_sys_table(thd, table_tables,
  5511. &open_tables_backup, TRUE);
  5512. spider_free_tmp_dbton_share(&tmp_share);
  5513. spider_free_tmp_share_alloc(&tmp_share);
  5514. free_root(&mem_root, MYF(0));
  5515. DBUG_RETURN(error_num);
  5516. }
  5517. /* create another conn */
  5518. if (
  5519. (!(conn = spider_get_conn(
  5520. &tmp_share, 0, tmp_share.conn_keys[0], trx, spider, TRUE, FALSE,
  5521. SPIDER_CONN_KIND_MYSQL, &error_num)))
  5522. ) {
  5523. spider_free_tmp_dbton_handler(spider);
  5524. spider_free(trx, share, MYF(0));
  5525. delete spider;
  5526. spider_sys_index_end(table_tables);
  5527. spider_close_sys_table(thd, table_tables,
  5528. &open_tables_backup, TRUE);
  5529. spider_free_tmp_dbton_share(&tmp_share);
  5530. spider_free_tmp_share_alloc(&tmp_share);
  5531. free_root(&mem_root, MYF(0));
  5532. DBUG_RETURN(error_num);
  5533. }
  5534. conn->error_mode &= spider_param_error_read_mode(thd, 0);
  5535. conn->error_mode &= spider_param_error_write_mode(thd, 0);
  5536. spider->next = NULL;
  5537. if (conn->another_ha_last)
  5538. {
  5539. ((ha_spider*) conn->another_ha_last)->next = spider;
  5540. } else {
  5541. conn->another_ha_first = (void*) spider;
  5542. }
  5543. conn->another_ha_last = (void*) spider;
  5544. int appended = 0;
  5545. if ((error_num = spider->dbton_handler[conn->dbton_id]->
  5546. append_lock_tables_list(conn, 0, &appended)))
  5547. {
  5548. spider_free_tmp_dbton_handler(spider);
  5549. spider_free(trx, share, MYF(0));
  5550. delete spider;
  5551. spider_sys_index_end(table_tables);
  5552. spider_close_sys_table(thd, table_tables,
  5553. &open_tables_backup, TRUE);
  5554. spider_free_tmp_dbton_share(&tmp_share);
  5555. spider_free_tmp_share_alloc(&tmp_share);
  5556. free_root(&mem_root, MYF(0));
  5557. DBUG_RETURN(error_num);
  5558. }
  5559. } else {
  5560. spider_free_tmp_dbton_share(&tmp_share);
  5561. spider_free_tmp_share_alloc(&tmp_share);
  5562. }
  5563. error_num = spider_sys_index_next(table_tables);
  5564. } while (error_num == 0);
  5565. free_root(&mem_root, MYF(0));
  5566. spider_sys_index_end(table_tables);
  5567. spider_close_sys_table(thd, table_tables,
  5568. &open_tables_backup, TRUE);
  5569. DBUG_RETURN(0);
  5570. }
  5571. bool spider_flush_logs(
  5572. handlerton *hton
  5573. ) {
  5574. int error_num;
  5575. THD* thd = current_thd;
  5576. SPIDER_TRX *trx;
  5577. DBUG_ENTER("spider_flush_logs");
  5578. if (!(trx = spider_get_trx(thd, TRUE, &error_num)))
  5579. {
  5580. my_errno = error_num;
  5581. DBUG_RETURN(TRUE);
  5582. }
  5583. if (
  5584. spider_param_use_flash_logs(trx->thd) &&
  5585. (
  5586. !trx->trx_consistent_snapshot ||
  5587. !spider_param_use_all_conns_snapshot(trx->thd) ||
  5588. !spider_param_use_snapshot_with_flush_tables(trx->thd)
  5589. )
  5590. ) {
  5591. if (
  5592. (error_num = spider_open_all_tables(trx, FALSE)) ||
  5593. (error_num = spider_trx_all_flush_logs(trx))
  5594. ) {
  5595. my_errno = error_num;
  5596. DBUG_RETURN(TRUE);
  5597. }
  5598. }
  5599. DBUG_RETURN(FALSE);
  5600. }
  5601. handler* spider_create_handler(
  5602. handlerton *hton,
  5603. TABLE_SHARE *table,
  5604. MEM_ROOT *mem_root
  5605. ) {
  5606. DBUG_ENTER("spider_create_handler");
  5607. DBUG_RETURN(new (mem_root) ha_spider(hton, table));
  5608. }
  5609. int spider_close_connection(
  5610. handlerton* hton,
  5611. THD* thd
  5612. ) {
  5613. int roop_count = 0;
  5614. SPIDER_CONN *conn;
  5615. SPIDER_TRX *trx;
  5616. DBUG_ENTER("spider_close_connection");
  5617. if (!(trx = (SPIDER_TRX*) *thd_ha_data(thd, spider_hton_ptr)))
  5618. DBUG_RETURN(0); /* transaction is not started */
  5619. trx->tmp_spider->conns = &conn;
  5620. while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_conn_hash,
  5621. roop_count)))
  5622. {
  5623. SPIDER_BACKUP_DASTATUS;
  5624. DBUG_PRINT("info",("spider conn->table_lock=%d", conn->table_lock));
  5625. if (conn->table_lock > 0)
  5626. {
  5627. if (!conn->trx_start)
  5628. conn->disable_reconnect = FALSE;
  5629. if (conn->table_lock != 2)
  5630. {
  5631. spider_db_unlock_tables(trx->tmp_spider, 0);
  5632. }
  5633. conn->table_lock = 0;
  5634. }
  5635. roop_count++;
  5636. SPIDER_CONN_RESTORE_DASTATUS;
  5637. }
  5638. spider_rollback(spider_hton_ptr, thd, TRUE);
  5639. spider_free_trx(trx, TRUE);
  5640. DBUG_RETURN(0);
  5641. }
  5642. void spider_drop_database(
  5643. handlerton *hton,
  5644. char* path
  5645. ) {
  5646. DBUG_ENTER("spider_drop_database");
  5647. DBUG_VOID_RETURN;
  5648. }
  5649. bool spider_show_status(
  5650. handlerton *hton,
  5651. THD *thd,
  5652. stat_print_fn *stat_print,
  5653. enum ha_stat_type stat_type
  5654. ) {
  5655. DBUG_ENTER("spider_show_status");
  5656. switch (stat_type) {
  5657. case HA_ENGINE_STATUS:
  5658. default:
  5659. DBUG_RETURN(FALSE);
  5660. }
  5661. }
  5662. int spider_db_done(
  5663. void *p
  5664. ) {
  5665. int roop_count;
  5666. THD *thd = current_thd, *tmp_thd;
  5667. SPIDER_CONN *conn;
  5668. SPIDER_INIT_ERROR_TABLE *spider_init_error_table;
  5669. SPIDER_TABLE_MON_LIST *table_mon_list;
  5670. SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share;
  5671. DBUG_ENTER("spider_db_done");
  5672. #ifndef WITHOUT_SPIDER_BG_SEARCH
  5673. spider_free_trx(spider_global_trx, TRUE);
  5674. #endif
  5675. for (roop_count = SPIDER_DBTON_SIZE - 1; roop_count >= 0; roop_count--)
  5676. {
  5677. if (spider_dbton[roop_count].deinit)
  5678. {
  5679. spider_dbton[roop_count].deinit();
  5680. }
  5681. }
  5682. for (roop_count = spider_param_udf_table_mon_mutex_count() - 1;
  5683. roop_count >= 0; roop_count--)
  5684. {
  5685. while ((table_mon_list = (SPIDER_TABLE_MON_LIST *) my_hash_element(
  5686. &spider_udf_table_mon_list_hash[roop_count], 0)))
  5687. {
  5688. #ifdef HASH_UPDATE_WITH_HASH_VALUE
  5689. my_hash_delete_with_hash_value(
  5690. &spider_udf_table_mon_list_hash[roop_count],
  5691. table_mon_list->key_hash_value, (uchar*) table_mon_list);
  5692. #else
  5693. my_hash_delete(&spider_udf_table_mon_list_hash[roop_count],
  5694. (uchar*) table_mon_list);
  5695. #endif
  5696. spider_ping_table_free_mon_list(table_mon_list);
  5697. }
  5698. spider_free_mem_calc(spider_current_trx,
  5699. spider_udf_table_mon_list_hash_id,
  5700. spider_udf_table_mon_list_hash[roop_count].array.max_element *
  5701. spider_udf_table_mon_list_hash[roop_count].array.size_of_element);
  5702. my_hash_free(&spider_udf_table_mon_list_hash[roop_count]);
  5703. }
  5704. for (roop_count = spider_param_udf_table_mon_mutex_count() - 1;
  5705. roop_count >= 0; roop_count--)
  5706. pthread_cond_destroy(&spider_udf_table_mon_conds[roop_count]);
  5707. for (roop_count = spider_param_udf_table_mon_mutex_count() - 1;
  5708. roop_count >= 0; roop_count--)
  5709. pthread_mutex_destroy(&spider_udf_table_mon_mutexes[roop_count]);
  5710. spider_free(NULL, spider_udf_table_mon_mutexes, MYF(0));
  5711. if (thd && thd_sql_command(thd) == SQLCOM_UNINSTALL_PLUGIN) {
  5712. pthread_mutex_lock(&spider_allocated_thds_mutex);
  5713. while ((tmp_thd = (THD *) my_hash_element(&spider_allocated_thds, 0)))
  5714. {
  5715. SPIDER_TRX *trx = (SPIDER_TRX *) *thd_ha_data(tmp_thd, spider_hton_ptr);
  5716. if (trx)
  5717. {
  5718. DBUG_ASSERT(tmp_thd == trx->thd);
  5719. spider_free_trx(trx, FALSE);
  5720. *thd_ha_data(tmp_thd, spider_hton_ptr) = (void *) NULL;
  5721. } else
  5722. my_hash_delete(&spider_allocated_thds, (uchar *) tmp_thd);
  5723. }
  5724. pthread_mutex_unlock(&spider_allocated_thds_mutex);
  5725. }
  5726. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  5727. pthread_mutex_lock(&spider_hs_w_conn_mutex);
  5728. while ((conn = (SPIDER_CONN*) my_hash_element(&spider_hs_w_conn_hash, 0)))
  5729. {
  5730. #ifdef HASH_UPDATE_WITH_HASH_VALUE
  5731. my_hash_delete_with_hash_value(&spider_hs_w_conn_hash,
  5732. conn->conn_key_hash_value, (uchar*) conn);
  5733. #else
  5734. my_hash_delete(&spider_hs_w_conn_hash, (uchar*) conn);
  5735. #endif
  5736. spider_free_conn(conn);
  5737. }
  5738. pthread_mutex_unlock(&spider_hs_w_conn_mutex);
  5739. pthread_mutex_lock(&spider_hs_r_conn_mutex);
  5740. while ((conn = (SPIDER_CONN*) my_hash_element(&spider_hs_r_conn_hash, 0)))
  5741. {
  5742. #ifdef HASH_UPDATE_WITH_HASH_VALUE
  5743. my_hash_delete_with_hash_value(&spider_hs_r_conn_hash,
  5744. conn->conn_key_hash_value, (uchar*) conn);
  5745. #else
  5746. my_hash_delete(&spider_hs_r_conn_hash, (uchar*) conn);
  5747. #endif
  5748. spider_free_conn(conn);
  5749. }
  5750. pthread_mutex_unlock(&spider_hs_r_conn_mutex);
  5751. #endif
  5752. pthread_mutex_lock(&spider_conn_mutex);
  5753. while ((conn = (SPIDER_CONN*) my_hash_element(&spider_open_connections, 0)))
  5754. {
  5755. #ifdef HASH_UPDATE_WITH_HASH_VALUE
  5756. my_hash_delete_with_hash_value(&spider_open_connections,
  5757. conn->conn_key_hash_value, (uchar*) conn);
  5758. #else
  5759. my_hash_delete(&spider_open_connections, (uchar*) conn);
  5760. #endif
  5761. spider_free_conn(conn);
  5762. }
  5763. pthread_mutex_unlock(&spider_conn_mutex);
  5764. pthread_mutex_lock(&spider_lgtm_tblhnd_share_mutex);
  5765. while ((lgtm_tblhnd_share = (SPIDER_LGTM_TBLHND_SHARE*) my_hash_element(
  5766. &spider_lgtm_tblhnd_share_hash, 0)))
  5767. {
  5768. spider_free_lgtm_tblhnd_share_alloc(lgtm_tblhnd_share, TRUE);
  5769. }
  5770. pthread_mutex_unlock(&spider_lgtm_tblhnd_share_mutex);
  5771. spider_free_mem_calc(spider_current_trx,
  5772. spider_mon_table_cache_id,
  5773. spider_mon_table_cache.max_element *
  5774. spider_mon_table_cache.size_of_element);
  5775. delete_dynamic(&spider_mon_table_cache);
  5776. spider_free_mem_calc(spider_current_trx,
  5777. spider_allocated_thds_id,
  5778. spider_allocated_thds.array.max_element *
  5779. spider_allocated_thds.array.size_of_element);
  5780. my_hash_free(&spider_allocated_thds);
  5781. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  5782. spider_free_mem_calc(spider_current_trx,
  5783. spider_hs_w_conn_hash_id,
  5784. spider_hs_w_conn_hash.array.max_element *
  5785. spider_hs_w_conn_hash.array.size_of_element);
  5786. my_hash_free(&spider_hs_w_conn_hash);
  5787. spider_free_mem_calc(spider_current_trx,
  5788. spider_hs_r_conn_hash_id,
  5789. spider_hs_r_conn_hash.array.max_element *
  5790. spider_hs_r_conn_hash.array.size_of_element);
  5791. my_hash_free(&spider_hs_r_conn_hash);
  5792. #endif
  5793. spider_free_mem_calc(spider_current_trx,
  5794. spider_open_connections_id,
  5795. spider_open_connections.array.max_element *
  5796. spider_open_connections.array.size_of_element);
  5797. my_hash_free(&spider_open_connections);
  5798. spider_free_mem_calc(spider_current_trx,
  5799. spider_lgtm_tblhnd_share_hash_id,
  5800. spider_lgtm_tblhnd_share_hash.array.max_element *
  5801. spider_lgtm_tblhnd_share_hash.array.size_of_element);
  5802. my_hash_free(&spider_lgtm_tblhnd_share_hash);
  5803. #ifdef WITH_PARTITION_STORAGE_ENGINE
  5804. spider_free_mem_calc(spider_current_trx,
  5805. spider_open_pt_share_id,
  5806. spider_open_pt_share.array.max_element *
  5807. spider_open_pt_share.array.size_of_element);
  5808. my_hash_free(&spider_open_pt_share);
  5809. #endif
  5810. pthread_mutex_lock(&spider_init_error_tbl_mutex);
  5811. while ((spider_init_error_table = (SPIDER_INIT_ERROR_TABLE*)
  5812. my_hash_element(&spider_init_error_tables, 0)))
  5813. {
  5814. #ifdef HASH_UPDATE_WITH_HASH_VALUE
  5815. my_hash_delete_with_hash_value(&spider_init_error_tables,
  5816. spider_init_error_table->table_name_hash_value,
  5817. (uchar*) spider_init_error_table);
  5818. #else
  5819. my_hash_delete(&spider_init_error_tables,
  5820. (uchar*) spider_init_error_table);
  5821. #endif
  5822. spider_free(NULL, spider_init_error_table, MYF(0));
  5823. }
  5824. pthread_mutex_unlock(&spider_init_error_tbl_mutex);
  5825. spider_free_mem_calc(spider_current_trx,
  5826. spider_init_error_tables_id,
  5827. spider_init_error_tables.array.max_element *
  5828. spider_init_error_tables.array.size_of_element);
  5829. my_hash_free(&spider_init_error_tables);
  5830. spider_free_mem_calc(spider_current_trx,
  5831. spider_open_tables_id,
  5832. spider_open_tables.array.max_element *
  5833. spider_open_tables.array.size_of_element);
  5834. my_hash_free(&spider_open_tables);
  5835. pthread_mutex_destroy(&spider_mem_calc_mutex);
  5836. pthread_mutex_destroy(&spider_mon_table_cache_mutex);
  5837. pthread_mutex_destroy(&spider_allocated_thds_mutex);
  5838. pthread_mutex_destroy(&spider_open_conn_mutex);
  5839. #ifndef WITHOUT_SPIDER_BG_SEARCH
  5840. pthread_mutex_destroy(&spider_global_trx_mutex);
  5841. #endif
  5842. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  5843. pthread_mutex_destroy(&spider_hs_w_conn_mutex);
  5844. pthread_mutex_destroy(&spider_hs_r_conn_mutex);
  5845. #endif
  5846. pthread_mutex_destroy(&spider_conn_mutex);
  5847. pthread_mutex_destroy(&spider_lgtm_tblhnd_share_mutex);
  5848. #ifdef WITH_PARTITION_STORAGE_ENGINE
  5849. pthread_mutex_destroy(&spider_pt_share_mutex);
  5850. #endif
  5851. pthread_mutex_destroy(&spider_init_error_tbl_mutex);
  5852. pthread_mutex_destroy(&spider_conn_id_mutex);
  5853. pthread_mutex_destroy(&spider_thread_id_mutex);
  5854. pthread_mutex_destroy(&spider_tbl_mutex);
  5855. #ifndef WITHOUT_SPIDER_BG_SEARCH
  5856. pthread_attr_destroy(&spider_pt_attr);
  5857. #endif
  5858. for (roop_count = 0; roop_count < SPIDER_MEM_CALC_LIST_NUM; roop_count++)
  5859. {
  5860. if (spider_alloc_func_name[roop_count])
  5861. DBUG_PRINT("info",("spider %d %s %s %lu %llu %lld %llu %llu %s",
  5862. roop_count,
  5863. spider_alloc_func_name[roop_count],
  5864. spider_alloc_file_name[roop_count],
  5865. spider_alloc_line_no[roop_count],
  5866. spider_total_alloc_mem[roop_count],
  5867. spider_current_alloc_mem[roop_count],
  5868. spider_alloc_mem_count[roop_count],
  5869. spider_free_mem_count[roop_count],
  5870. spider_current_alloc_mem[roop_count] ? "NG" : "OK"
  5871. ));
  5872. }
  5873. /*
  5874. DBUG_ASSERT(0);
  5875. */
  5876. DBUG_RETURN(0);
  5877. }
  5878. int spider_panic(
  5879. handlerton *hton,
  5880. ha_panic_function type
  5881. ) {
  5882. DBUG_ENTER("spider_panic");
  5883. DBUG_RETURN(0);
  5884. }
  5885. int spider_db_init(
  5886. void *p
  5887. ) {
  5888. int error_num, roop_count;
  5889. uint dbton_id = 0;
  5890. handlerton *spider_hton = (handlerton *)p;
  5891. DBUG_ENTER("spider_db_init");
  5892. spider_hton_ptr = spider_hton;
  5893. spider_hton->state = SHOW_OPTION_YES;
  5894. spider_hton->flags = HTON_NO_FLAGS;
  5895. /* spider_hton->db_type = DB_TYPE_SPIDER; */
  5896. /*
  5897. spider_hton->savepoint_offset;
  5898. spider_hton->savepoint_set = spider_savepoint_set;
  5899. spider_hton->savepoint_rollback = spider_savepoint_rollback;
  5900. spider_hton->savepoint_release = spider_savepoint_release;
  5901. spider_hton->create_cursor_read_view = spider_create_cursor_read_view;
  5902. spider_hton->set_cursor_read_view = spider_set_cursor_read_view;
  5903. spider_hton->close_cursor_read_view = spider_close_cursor_read_view;
  5904. */
  5905. spider_hton->panic = spider_panic;
  5906. spider_hton->close_connection = spider_close_connection;
  5907. spider_hton->start_consistent_snapshot = spider_start_consistent_snapshot;
  5908. spider_hton->flush_logs = spider_flush_logs;
  5909. spider_hton->commit = spider_commit;
  5910. spider_hton->rollback = spider_rollback;
  5911. #ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE
  5912. spider_hton->discover_table_structure = spider_discover_table_structure;
  5913. #endif
  5914. if (spider_param_support_xa())
  5915. {
  5916. spider_hton->prepare = spider_xa_prepare;
  5917. spider_hton->recover = spider_xa_recover;
  5918. spider_hton->commit_by_xid = spider_xa_commit_by_xid;
  5919. spider_hton->rollback_by_xid = spider_xa_rollback_by_xid;
  5920. }
  5921. spider_hton->create = spider_create_handler;
  5922. spider_hton->drop_database = spider_drop_database;
  5923. spider_hton->show_status = spider_show_status;
  5924. memset(&spider_alloc_func_name, 0, sizeof(spider_alloc_func_name));
  5925. memset(&spider_alloc_file_name, 0, sizeof(spider_alloc_file_name));
  5926. memset(&spider_alloc_line_no, 0, sizeof(spider_alloc_line_no));
  5927. memset(&spider_total_alloc_mem, 0, sizeof(spider_total_alloc_mem));
  5928. memset(&spider_current_alloc_mem, 0, sizeof(spider_current_alloc_mem));
  5929. memset(&spider_alloc_mem_count, 0, sizeof(spider_alloc_mem_count));
  5930. memset(&spider_free_mem_count, 0, sizeof(spider_free_mem_count));
  5931. #ifdef _WIN32
  5932. HMODULE current_module = GetModuleHandle(NULL);
  5933. spd_db_att_thread_id = (ulong *)
  5934. GetProcAddress(current_module, "?thread_id@@3KA");
  5935. #ifdef XID_CACHE_IS_SPLITTED
  5936. spd_db_att_xid_cache_split_num = (uint *)
  5937. GetProcAddress(current_module,
  5938. "?opt_xid_cache_split_num@@3IA");
  5939. spd_db_att_LOCK_xid_cache = *((pthread_mutex_t **)
  5940. GetProcAddress(current_module,
  5941. "?LOCK_xid_cache@@3PAUst_mysql_mutex@@A"));
  5942. spd_db_att_xid_cache = *((HASH **)
  5943. GetProcAddress(current_module, "?xid_cache@@3PAUst_hash@@A"));
  5944. #else
  5945. spd_db_att_LOCK_xid_cache = (pthread_mutex_t *)
  5946. #if MYSQL_VERSION_ID < 50500
  5947. GetProcAddress(current_module,
  5948. "?LOCK_xid_cache@@3U_RTL_CRITICAL_SECTION@@A");
  5949. #else
  5950. GetProcAddress(current_module,
  5951. "?LOCK_xid_cache@@3Ust_mysql_mutex@@A");
  5952. #endif
  5953. spd_db_att_xid_cache = (HASH *)
  5954. GetProcAddress(current_module, "?xid_cache@@3Ust_hash@@A");
  5955. #endif
  5956. spd_charset_utf8_bin = (struct charset_info_st *)
  5957. GetProcAddress(current_module, "my_charset_utf8_bin");
  5958. spd_defaults_extra_file = (const char **)
  5959. GetProcAddress(current_module, "my_defaults_extra_file");
  5960. spd_defaults_file = (const char **)
  5961. GetProcAddress(current_module, "my_defaults_file");
  5962. spd_abort_loop = (bool volatile *)
  5963. GetProcAddress(current_module, "?abort_loop@@3_NC");
  5964. #else
  5965. spd_db_att_thread_id = &thread_id;
  5966. #ifdef XID_CACHE_IS_SPLITTED
  5967. spd_db_att_xid_cache_split_num = &opt_xid_cache_split_num;
  5968. spd_db_att_LOCK_xid_cache = LOCK_xid_cache;
  5969. spd_db_att_xid_cache = xid_cache;
  5970. #else
  5971. spd_db_att_LOCK_xid_cache = &LOCK_xid_cache;
  5972. spd_db_att_xid_cache = &xid_cache;
  5973. #endif
  5974. spd_charset_utf8_bin = &my_charset_utf8_bin;
  5975. spd_defaults_extra_file = &my_defaults_extra_file;
  5976. spd_defaults_file = &my_defaults_file;
  5977. spd_abort_loop = &abort_loop;
  5978. #endif
  5979. #ifdef HAVE_PSI_INTERFACE
  5980. init_spider_psi_keys();
  5981. #endif
  5982. #ifndef WITHOUT_SPIDER_BG_SEARCH
  5983. if (pthread_attr_init(&spider_pt_attr))
  5984. {
  5985. error_num = HA_ERR_OUT_OF_MEM;
  5986. goto error_pt_attr_init;
  5987. }
  5988. /*
  5989. if (pthread_attr_setdetachstate(&spider_pt_attr, PTHREAD_CREATE_DETACHED))
  5990. {
  5991. error_num = HA_ERR_OUT_OF_MEM;
  5992. goto error_pt_attr_setstate;
  5993. }
  5994. */
  5995. #endif
  5996. #if MYSQL_VERSION_ID < 50500
  5997. if (pthread_mutex_init(&spider_tbl_mutex, MY_MUTEX_INIT_FAST))
  5998. #else
  5999. if (mysql_mutex_init(spd_key_mutex_tbl,
  6000. &spider_tbl_mutex, MY_MUTEX_INIT_FAST))
  6001. #endif
  6002. {
  6003. error_num = HA_ERR_OUT_OF_MEM;
  6004. goto error_tbl_mutex_init;
  6005. }
  6006. #if MYSQL_VERSION_ID < 50500
  6007. if (pthread_mutex_init(&spider_thread_id_mutex, MY_MUTEX_INIT_FAST))
  6008. #else
  6009. if (mysql_mutex_init(spd_key_thread_id,
  6010. &spider_thread_id_mutex, MY_MUTEX_INIT_FAST))
  6011. #endif
  6012. {
  6013. error_num = HA_ERR_OUT_OF_MEM;
  6014. goto error_thread_id_mutex_init;
  6015. }
  6016. #if MYSQL_VERSION_ID < 50500
  6017. if (pthread_mutex_init(&spider_conn_id_mutex, MY_MUTEX_INIT_FAST))
  6018. #else
  6019. if (mysql_mutex_init(spd_key_conn_id,
  6020. &spider_conn_id_mutex, MY_MUTEX_INIT_FAST))
  6021. #endif
  6022. {
  6023. error_num = HA_ERR_OUT_OF_MEM;
  6024. goto error_conn_id_mutex_init;
  6025. }
  6026. #if MYSQL_VERSION_ID < 50500
  6027. if (pthread_mutex_init(&spider_init_error_tbl_mutex, MY_MUTEX_INIT_FAST))
  6028. #else
  6029. if (mysql_mutex_init(spd_key_mutex_init_error_tbl,
  6030. &spider_init_error_tbl_mutex, MY_MUTEX_INIT_FAST))
  6031. #endif
  6032. {
  6033. error_num = HA_ERR_OUT_OF_MEM;
  6034. goto error_init_error_tbl_mutex_init;
  6035. }
  6036. #ifdef WITH_PARTITION_STORAGE_ENGINE
  6037. #if MYSQL_VERSION_ID < 50500
  6038. if (pthread_mutex_init(&spider_pt_share_mutex, MY_MUTEX_INIT_FAST))
  6039. #else
  6040. if (mysql_mutex_init(spd_key_mutex_pt_share,
  6041. &spider_pt_share_mutex, MY_MUTEX_INIT_FAST))
  6042. #endif
  6043. {
  6044. error_num = HA_ERR_OUT_OF_MEM;
  6045. goto error_pt_share_mutex_init;
  6046. }
  6047. #endif
  6048. #if MYSQL_VERSION_ID < 50500
  6049. if (pthread_mutex_init(&spider_lgtm_tblhnd_share_mutex, MY_MUTEX_INIT_FAST))
  6050. #else
  6051. if (mysql_mutex_init(spd_key_mutex_lgtm_tblhnd_share,
  6052. &spider_lgtm_tblhnd_share_mutex, MY_MUTEX_INIT_FAST))
  6053. #endif
  6054. {
  6055. error_num = HA_ERR_OUT_OF_MEM;
  6056. goto error_lgtm_tblhnd_share_mutex_init;
  6057. }
  6058. #if MYSQL_VERSION_ID < 50500
  6059. if (pthread_mutex_init(&spider_conn_mutex, MY_MUTEX_INIT_FAST))
  6060. #else
  6061. if (mysql_mutex_init(spd_key_mutex_conn,
  6062. &spider_conn_mutex, MY_MUTEX_INIT_FAST))
  6063. #endif
  6064. {
  6065. error_num = HA_ERR_OUT_OF_MEM;
  6066. goto error_conn_mutex_init;
  6067. }
  6068. #ifndef WITHOUT_SPIDER_BG_SEARCH
  6069. #if MYSQL_VERSION_ID < 50500
  6070. if (pthread_mutex_init(&spider_global_trx_mutex, MY_MUTEX_INIT_FAST))
  6071. #else
  6072. if (mysql_mutex_init(spd_key_mutex_global_trx,
  6073. &spider_global_trx_mutex, MY_MUTEX_INIT_FAST))
  6074. #endif
  6075. {
  6076. error_num = HA_ERR_OUT_OF_MEM;
  6077. goto error_global_trx_mutex_init;
  6078. }
  6079. #endif
  6080. #if MYSQL_VERSION_ID < 50500
  6081. if (pthread_mutex_init(&spider_open_conn_mutex, MY_MUTEX_INIT_FAST))
  6082. #else
  6083. if (mysql_mutex_init(spd_key_mutex_open_conn,
  6084. &spider_open_conn_mutex, MY_MUTEX_INIT_FAST))
  6085. #endif
  6086. {
  6087. error_num = HA_ERR_OUT_OF_MEM;
  6088. goto error_open_conn_mutex_init;
  6089. }
  6090. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  6091. #if MYSQL_VERSION_ID < 50500
  6092. if (pthread_mutex_init(&spider_hs_r_conn_mutex, MY_MUTEX_INIT_FAST))
  6093. #else
  6094. if (mysql_mutex_init(spd_key_mutex_hs_r_conn,
  6095. &spider_hs_r_conn_mutex, MY_MUTEX_INIT_FAST))
  6096. #endif
  6097. {
  6098. error_num = HA_ERR_OUT_OF_MEM;
  6099. goto error_hs_r_conn_mutex_init;
  6100. }
  6101. #if MYSQL_VERSION_ID < 50500
  6102. if (pthread_mutex_init(&spider_hs_w_conn_mutex, MY_MUTEX_INIT_FAST))
  6103. #else
  6104. if (mysql_mutex_init(spd_key_mutex_hs_w_conn,
  6105. &spider_hs_w_conn_mutex, MY_MUTEX_INIT_FAST))
  6106. #endif
  6107. {
  6108. error_num = HA_ERR_OUT_OF_MEM;
  6109. goto error_hs_w_conn_mutex_init;
  6110. }
  6111. #endif
  6112. #if MYSQL_VERSION_ID < 50500
  6113. if (pthread_mutex_init(&spider_allocated_thds_mutex, MY_MUTEX_INIT_FAST))
  6114. #else
  6115. if (mysql_mutex_init(spd_key_mutex_allocated_thds,
  6116. &spider_allocated_thds_mutex, MY_MUTEX_INIT_FAST))
  6117. #endif
  6118. {
  6119. error_num = HA_ERR_OUT_OF_MEM;
  6120. goto error_allocated_thds_mutex_init;
  6121. }
  6122. #if MYSQL_VERSION_ID < 50500
  6123. if (pthread_mutex_init(&spider_mon_table_cache_mutex, MY_MUTEX_INIT_FAST))
  6124. #else
  6125. if (mysql_mutex_init(spd_key_mutex_mon_table_cache,
  6126. &spider_mon_table_cache_mutex, MY_MUTEX_INIT_FAST))
  6127. #endif
  6128. {
  6129. error_num = HA_ERR_OUT_OF_MEM;
  6130. goto error_mon_table_cache_mutex_init;
  6131. }
  6132. #if MYSQL_VERSION_ID < 50500
  6133. if (pthread_mutex_init(&spider_mem_calc_mutex, MY_MUTEX_INIT_FAST))
  6134. #else
  6135. if (mysql_mutex_init(spd_key_mutex_mem_calc,
  6136. &spider_mem_calc_mutex, MY_MUTEX_INIT_FAST))
  6137. #endif
  6138. {
  6139. error_num = HA_ERR_OUT_OF_MEM;
  6140. goto error_mem_calc_mutex_init;
  6141. }
  6142. if(
  6143. my_hash_init(&spider_open_tables, spd_charset_utf8_bin, 32, 0, 0,
  6144. (my_hash_get_key) spider_tbl_get_key, 0, 0)
  6145. ) {
  6146. error_num = HA_ERR_OUT_OF_MEM;
  6147. goto error_open_tables_hash_init;
  6148. }
  6149. spider_alloc_calc_mem_init(spider_open_tables, 143);
  6150. spider_alloc_calc_mem(NULL,
  6151. spider_open_tables,
  6152. spider_open_tables.array.max_element *
  6153. spider_open_tables.array.size_of_element);
  6154. if(
  6155. my_hash_init(&spider_init_error_tables, spd_charset_utf8_bin, 32, 0, 0,
  6156. (my_hash_get_key) spider_tbl_get_key, 0, 0)
  6157. ) {
  6158. error_num = HA_ERR_OUT_OF_MEM;
  6159. goto error_init_error_tables_hash_init;
  6160. }
  6161. spider_alloc_calc_mem_init(spider_init_error_tables, 144);
  6162. spider_alloc_calc_mem(NULL,
  6163. spider_init_error_tables,
  6164. spider_init_error_tables.array.max_element *
  6165. spider_init_error_tables.array.size_of_element);
  6166. #ifdef WITH_PARTITION_STORAGE_ENGINE
  6167. if(
  6168. my_hash_init(&spider_open_pt_share, spd_charset_utf8_bin, 32, 0, 0,
  6169. (my_hash_get_key) spider_pt_share_get_key, 0, 0)
  6170. ) {
  6171. error_num = HA_ERR_OUT_OF_MEM;
  6172. goto error_open_pt_share_hash_init;
  6173. }
  6174. spider_alloc_calc_mem_init(spider_open_pt_share, 145);
  6175. spider_alloc_calc_mem(NULL,
  6176. spider_open_pt_share,
  6177. spider_open_pt_share.array.max_element *
  6178. spider_open_pt_share.array.size_of_element);
  6179. #endif
  6180. if(
  6181. my_hash_init(&spider_lgtm_tblhnd_share_hash, spd_charset_utf8_bin,
  6182. 32, 0, 0,
  6183. (my_hash_get_key) spider_lgtm_tblhnd_share_hash_get_key, 0, 0)
  6184. ) {
  6185. error_num = HA_ERR_OUT_OF_MEM;
  6186. goto error_lgtm_tblhnd_share_hash_init;
  6187. }
  6188. spider_alloc_calc_mem_init(spider_lgtm_tblhnd_share_hash, 245);
  6189. spider_alloc_calc_mem(NULL,
  6190. spider_lgtm_tblhnd_share_hash,
  6191. spider_lgtm_tblhnd_share_hash.array.max_element *
  6192. spider_lgtm_tblhnd_share_hash.array.size_of_element);
  6193. if(
  6194. my_hash_init(&spider_open_connections, spd_charset_utf8_bin, 32, 0, 0,
  6195. (my_hash_get_key) spider_conn_get_key, 0, 0)
  6196. ) {
  6197. error_num = HA_ERR_OUT_OF_MEM;
  6198. goto error_open_connections_hash_init;
  6199. }
  6200. spider_alloc_calc_mem_init(spider_open_connections, 146);
  6201. spider_alloc_calc_mem(NULL,
  6202. spider_open_connections,
  6203. spider_open_connections.array.max_element *
  6204. spider_open_connections.array.size_of_element);
  6205. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  6206. if(
  6207. my_hash_init(&spider_hs_r_conn_hash, spd_charset_utf8_bin, 32, 0, 0,
  6208. (my_hash_get_key) spider_conn_get_key, 0, 0)
  6209. ) {
  6210. error_num = HA_ERR_OUT_OF_MEM;
  6211. goto error_hs_r_conn_hash_init;
  6212. }
  6213. spider_alloc_calc_mem_init(spider_hs_r_conn_hash, 147);
  6214. spider_alloc_calc_mem(NULL,
  6215. spider_hs_r_conn_hash,
  6216. spider_hs_r_conn_hash.array.max_element *
  6217. spider_hs_r_conn_hash.array.size_of_element);
  6218. if(
  6219. my_hash_init(&spider_hs_w_conn_hash, spd_charset_utf8_bin, 32, 0, 0,
  6220. (my_hash_get_key) spider_conn_get_key, 0, 0)
  6221. ) {
  6222. error_num = HA_ERR_OUT_OF_MEM;
  6223. goto error_hs_w_conn_hash_init;
  6224. }
  6225. spider_alloc_calc_mem_init(spider_hs_w_conn_hash, 148);
  6226. spider_alloc_calc_mem(NULL,
  6227. spider_hs_w_conn_hash,
  6228. spider_hs_w_conn_hash.array.max_element *
  6229. spider_hs_w_conn_hash.array.size_of_element);
  6230. #endif
  6231. if(
  6232. my_hash_init(&spider_allocated_thds, spd_charset_utf8_bin, 32, 0, 0,
  6233. (my_hash_get_key) spider_allocated_thds_get_key, 0, 0)
  6234. ) {
  6235. error_num = HA_ERR_OUT_OF_MEM;
  6236. goto error_allocated_thds_hash_init;
  6237. }
  6238. spider_alloc_calc_mem_init(spider_allocated_thds, 149);
  6239. spider_alloc_calc_mem(NULL,
  6240. spider_allocated_thds,
  6241. spider_allocated_thds.array.max_element *
  6242. spider_allocated_thds.array.size_of_element);
  6243. if(
  6244. SPD_INIT_DYNAMIC_ARRAY2(&spider_mon_table_cache, sizeof(SPIDER_MON_KEY),
  6245. NULL, 64, 64, MYF(MY_WME))
  6246. ) {
  6247. error_num = HA_ERR_OUT_OF_MEM;
  6248. goto error_mon_table_cache_array_init;
  6249. }
  6250. spider_alloc_calc_mem_init(spider_mon_table_cache, 165);
  6251. spider_alloc_calc_mem(NULL,
  6252. spider_mon_table_cache,
  6253. spider_mon_table_cache.max_element *
  6254. spider_mon_table_cache.size_of_element);
  6255. if (!(spider_udf_table_mon_mutexes = (pthread_mutex_t *)
  6256. spider_bulk_malloc(NULL, 53, MYF(MY_WME | MY_ZEROFILL),
  6257. &spider_udf_table_mon_mutexes, sizeof(pthread_mutex_t) *
  6258. spider_param_udf_table_mon_mutex_count(),
  6259. &spider_udf_table_mon_conds, sizeof(pthread_cond_t) *
  6260. spider_param_udf_table_mon_mutex_count(),
  6261. &spider_udf_table_mon_list_hash, sizeof(HASH) *
  6262. spider_param_udf_table_mon_mutex_count(),
  6263. NullS))
  6264. )
  6265. goto error_alloc_mon_mutxes;
  6266. for (roop_count = 0;
  6267. roop_count < (int) spider_param_udf_table_mon_mutex_count();
  6268. roop_count++)
  6269. {
  6270. #if MYSQL_VERSION_ID < 50500
  6271. if (pthread_mutex_init(&spider_udf_table_mon_mutexes[roop_count],
  6272. MY_MUTEX_INIT_FAST))
  6273. #else
  6274. if (mysql_mutex_init(spd_key_mutex_udf_table_mon,
  6275. &spider_udf_table_mon_mutexes[roop_count], MY_MUTEX_INIT_FAST))
  6276. #endif
  6277. {
  6278. error_num = HA_ERR_OUT_OF_MEM;
  6279. goto error_init_udf_table_mon_mutex;
  6280. }
  6281. }
  6282. for (roop_count = 0;
  6283. roop_count < (int) spider_param_udf_table_mon_mutex_count();
  6284. roop_count++)
  6285. {
  6286. #if MYSQL_VERSION_ID < 50500
  6287. if (pthread_cond_init(&spider_udf_table_mon_conds[roop_count], NULL))
  6288. #else
  6289. if (mysql_cond_init(spd_key_cond_udf_table_mon,
  6290. &spider_udf_table_mon_conds[roop_count], NULL))
  6291. #endif
  6292. {
  6293. error_num = HA_ERR_OUT_OF_MEM;
  6294. goto error_init_udf_table_mon_cond;
  6295. }
  6296. }
  6297. for (roop_count = 0;
  6298. roop_count < (int) spider_param_udf_table_mon_mutex_count();
  6299. roop_count++)
  6300. {
  6301. if (my_hash_init(&spider_udf_table_mon_list_hash[roop_count],
  6302. spd_charset_utf8_bin, 32, 0, 0,
  6303. (my_hash_get_key) spider_udf_tbl_mon_list_key, 0, 0))
  6304. {
  6305. error_num = HA_ERR_OUT_OF_MEM;
  6306. goto error_init_udf_table_mon_list_hash;
  6307. }
  6308. spider_alloc_calc_mem_init(spider_udf_table_mon_list_hash, 150);
  6309. spider_alloc_calc_mem(NULL,
  6310. spider_udf_table_mon_list_hash,
  6311. spider_udf_table_mon_list_hash[roop_count].array.max_element *
  6312. spider_udf_table_mon_list_hash[roop_count].array.size_of_element);
  6313. }
  6314. spider_dbton_mysql.dbton_id = dbton_id;
  6315. spider_dbton[dbton_id] = spider_dbton_mysql;
  6316. ++dbton_id;
  6317. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  6318. spider_dbton_handlersocket.dbton_id = dbton_id;
  6319. spider_dbton[dbton_id] = spider_dbton_handlersocket;
  6320. ++dbton_id;
  6321. #endif
  6322. #ifdef HAVE_ORACLE_OCI
  6323. spider_dbton_oracle.dbton_id = dbton_id;
  6324. spider_dbton[dbton_id] = spider_dbton_oracle;
  6325. ++dbton_id;
  6326. #endif
  6327. for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++)
  6328. {
  6329. if (spider_dbton[roop_count].init)
  6330. {
  6331. if ((error_num = spider_dbton[roop_count].init()))
  6332. {
  6333. goto error_init_dbton;
  6334. }
  6335. }
  6336. }
  6337. #ifndef WITHOUT_SPIDER_BG_SEARCH
  6338. if (!(spider_global_trx = spider_get_trx(NULL, FALSE, &error_num)))
  6339. goto error;
  6340. #endif
  6341. DBUG_RETURN(0);
  6342. #ifndef WITHOUT_SPIDER_BG_SEARCH
  6343. error:
  6344. roop_count = SPIDER_DBTON_SIZE;
  6345. error_init_dbton:
  6346. for (roop_count--; roop_count >= 0; roop_count--)
  6347. {
  6348. if (spider_dbton[roop_count].deinit)
  6349. {
  6350. spider_dbton[roop_count].deinit();
  6351. }
  6352. }
  6353. roop_count = spider_param_udf_table_mon_mutex_count() - 1;
  6354. #endif
  6355. error_init_udf_table_mon_list_hash:
  6356. for (; roop_count >= 0; roop_count--)
  6357. {
  6358. spider_free_mem_calc(NULL,
  6359. spider_udf_table_mon_list_hash_id,
  6360. spider_udf_table_mon_list_hash[roop_count].array.max_element *
  6361. spider_udf_table_mon_list_hash[roop_count].array.size_of_element);
  6362. my_hash_free(&spider_udf_table_mon_list_hash[roop_count]);
  6363. }
  6364. roop_count = spider_param_udf_table_mon_mutex_count() - 1;
  6365. error_init_udf_table_mon_cond:
  6366. for (; roop_count >= 0; roop_count--)
  6367. pthread_cond_destroy(&spider_udf_table_mon_conds[roop_count]);
  6368. roop_count = spider_param_udf_table_mon_mutex_count() - 1;
  6369. error_init_udf_table_mon_mutex:
  6370. for (; roop_count >= 0; roop_count--)
  6371. pthread_mutex_destroy(&spider_udf_table_mon_mutexes[roop_count]);
  6372. spider_free(NULL, spider_udf_table_mon_mutexes, MYF(0));
  6373. error_alloc_mon_mutxes:
  6374. spider_free_mem_calc(NULL,
  6375. spider_mon_table_cache_id,
  6376. spider_mon_table_cache.max_element *
  6377. spider_mon_table_cache.size_of_element);
  6378. delete_dynamic(&spider_mon_table_cache);
  6379. error_mon_table_cache_array_init:
  6380. spider_free_mem_calc(NULL,
  6381. spider_allocated_thds_id,
  6382. spider_allocated_thds.array.max_element *
  6383. spider_allocated_thds.array.size_of_element);
  6384. my_hash_free(&spider_allocated_thds);
  6385. error_allocated_thds_hash_init:
  6386. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  6387. spider_free_mem_calc(NULL,
  6388. spider_hs_w_conn_hash_id,
  6389. spider_hs_w_conn_hash.array.max_element *
  6390. spider_hs_w_conn_hash.array.size_of_element);
  6391. my_hash_free(&spider_hs_w_conn_hash);
  6392. error_hs_w_conn_hash_init:
  6393. spider_free_mem_calc(NULL,
  6394. spider_hs_r_conn_hash_id,
  6395. spider_hs_r_conn_hash.array.max_element *
  6396. spider_hs_r_conn_hash.array.size_of_element);
  6397. my_hash_free(&spider_hs_r_conn_hash);
  6398. error_hs_r_conn_hash_init:
  6399. #endif
  6400. spider_free_mem_calc(NULL,
  6401. spider_open_connections_id,
  6402. spider_open_connections.array.max_element *
  6403. spider_open_connections.array.size_of_element);
  6404. my_hash_free(&spider_open_connections);
  6405. error_open_connections_hash_init:
  6406. spider_free_mem_calc(NULL,
  6407. spider_lgtm_tblhnd_share_hash_id,
  6408. spider_lgtm_tblhnd_share_hash.array.max_element *
  6409. spider_lgtm_tblhnd_share_hash.array.size_of_element);
  6410. my_hash_free(&spider_lgtm_tblhnd_share_hash);
  6411. error_lgtm_tblhnd_share_hash_init:
  6412. #ifdef WITH_PARTITION_STORAGE_ENGINE
  6413. spider_free_mem_calc(NULL,
  6414. spider_open_pt_share_id,
  6415. spider_open_pt_share.array.max_element *
  6416. spider_open_pt_share.array.size_of_element);
  6417. my_hash_free(&spider_open_pt_share);
  6418. error_open_pt_share_hash_init:
  6419. #endif
  6420. spider_free_mem_calc(NULL,
  6421. spider_init_error_tables_id,
  6422. spider_init_error_tables.array.max_element *
  6423. spider_init_error_tables.array.size_of_element);
  6424. my_hash_free(&spider_init_error_tables);
  6425. error_init_error_tables_hash_init:
  6426. spider_free_mem_calc(NULL,
  6427. spider_open_tables_id,
  6428. spider_open_tables.array.max_element *
  6429. spider_open_tables.array.size_of_element);
  6430. my_hash_free(&spider_open_tables);
  6431. error_open_tables_hash_init:
  6432. pthread_mutex_destroy(&spider_mem_calc_mutex);
  6433. error_mem_calc_mutex_init:
  6434. pthread_mutex_destroy(&spider_mon_table_cache_mutex);
  6435. error_mon_table_cache_mutex_init:
  6436. pthread_mutex_destroy(&spider_allocated_thds_mutex);
  6437. error_allocated_thds_mutex_init:
  6438. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  6439. pthread_mutex_destroy(&spider_hs_w_conn_mutex);
  6440. error_hs_w_conn_mutex_init:
  6441. pthread_mutex_destroy(&spider_hs_r_conn_mutex);
  6442. error_hs_r_conn_mutex_init:
  6443. #endif
  6444. pthread_mutex_destroy(&spider_open_conn_mutex);
  6445. error_open_conn_mutex_init:
  6446. #ifndef WITHOUT_SPIDER_BG_SEARCH
  6447. pthread_mutex_destroy(&spider_global_trx_mutex);
  6448. error_global_trx_mutex_init:
  6449. #endif
  6450. pthread_mutex_destroy(&spider_conn_mutex);
  6451. error_conn_mutex_init:
  6452. pthread_mutex_destroy(&spider_lgtm_tblhnd_share_mutex);
  6453. error_lgtm_tblhnd_share_mutex_init:
  6454. #ifdef WITH_PARTITION_STORAGE_ENGINE
  6455. pthread_mutex_destroy(&spider_pt_share_mutex);
  6456. error_pt_share_mutex_init:
  6457. #endif
  6458. pthread_mutex_destroy(&spider_init_error_tbl_mutex);
  6459. error_init_error_tbl_mutex_init:
  6460. pthread_mutex_destroy(&spider_conn_id_mutex);
  6461. error_conn_id_mutex_init:
  6462. pthread_mutex_destroy(&spider_thread_id_mutex);
  6463. error_thread_id_mutex_init:
  6464. pthread_mutex_destroy(&spider_tbl_mutex);
  6465. error_tbl_mutex_init:
  6466. #ifndef WITHOUT_SPIDER_BG_SEARCH
  6467. /*
  6468. error_pt_attr_setstate:
  6469. */
  6470. pthread_attr_destroy(&spider_pt_attr);
  6471. error_pt_attr_init:
  6472. #endif
  6473. DBUG_RETURN(error_num);
  6474. }
  6475. char *spider_create_string(
  6476. const char *str,
  6477. uint length
  6478. ) {
  6479. char *res;
  6480. DBUG_ENTER("spider_create_string");
  6481. if (!(res = (char*) spider_malloc(spider_current_trx, 13, length + 1,
  6482. MYF(MY_WME))))
  6483. DBUG_RETURN(NULL);
  6484. memcpy(res, str, length);
  6485. res[length] = '\0';
  6486. DBUG_RETURN(res);
  6487. }
  6488. char *spider_create_table_name_string(
  6489. const char *table_name,
  6490. const char *part_name,
  6491. const char *sub_name
  6492. ) {
  6493. char *res, *tmp;
  6494. uint length = strlen(table_name);
  6495. DBUG_ENTER("spider_create_table_name_string");
  6496. if (part_name)
  6497. {
  6498. length += sizeof("#P#") - 1 + strlen(part_name);
  6499. if (sub_name)
  6500. length += sizeof("#SP#") - 1 + strlen(sub_name);
  6501. }
  6502. if (!(res = (char*) spider_malloc(spider_current_trx, 14, length + 1,
  6503. MYF(MY_WME))))
  6504. DBUG_RETURN(NULL);
  6505. tmp = strmov(res, table_name);
  6506. if (part_name)
  6507. {
  6508. tmp = strmov(tmp, "#P#");
  6509. tmp = strmov(tmp, part_name);
  6510. if (sub_name)
  6511. {
  6512. tmp = strmov(tmp, "#SP#");
  6513. tmp = strmov(tmp, sub_name);
  6514. }
  6515. }
  6516. DBUG_RETURN(res);
  6517. }
  6518. #ifdef WITH_PARTITION_STORAGE_ENGINE
  6519. void spider_get_partition_info(
  6520. const char *table_name,
  6521. uint table_name_length,
  6522. const TABLE_SHARE *table_share,
  6523. partition_info *part_info,
  6524. partition_element **part_elem,
  6525. partition_element **sub_elem
  6526. ) {
  6527. char tmp_name[FN_LEN];
  6528. partition_element *tmp_part_elem = NULL, *tmp_sub_elem = NULL;
  6529. bool tmp_flg = FALSE, tmp_find_flg = FALSE;
  6530. DBUG_ENTER("spider_get_partition_info");
  6531. *part_elem = NULL;
  6532. *sub_elem = NULL;
  6533. if (!part_info)
  6534. DBUG_VOID_RETURN;
  6535. if (!memcmp(table_name + table_name_length - 5, "#TMP#", 5))
  6536. tmp_flg = TRUE;
  6537. DBUG_PRINT("info",("spider table_name=%s", table_name));
  6538. List_iterator<partition_element> part_it(part_info->partitions);
  6539. while ((*part_elem = part_it++))
  6540. {
  6541. if ((*part_elem)->subpartitions.elements)
  6542. {
  6543. List_iterator<partition_element> sub_it((*part_elem)->subpartitions);
  6544. while ((*sub_elem = sub_it++))
  6545. {
  6546. create_subpartition_name(tmp_name, table_share->path.str,
  6547. (*part_elem)->partition_name, (*sub_elem)->partition_name,
  6548. NORMAL_PART_NAME);
  6549. DBUG_PRINT("info",("spider tmp_name=%s", tmp_name));
  6550. if (!memcmp(table_name, tmp_name, table_name_length + 1))
  6551. DBUG_VOID_RETURN;
  6552. if (
  6553. tmp_flg &&
  6554. *(tmp_name + table_name_length - 5) == '\0' &&
  6555. !memcmp(table_name, tmp_name, table_name_length - 5)
  6556. ) {
  6557. tmp_part_elem = *part_elem;
  6558. tmp_sub_elem = *sub_elem;
  6559. tmp_flg = FALSE;
  6560. tmp_find_flg = TRUE;
  6561. }
  6562. }
  6563. } else {
  6564. create_partition_name(tmp_name, table_share->path.str,
  6565. (*part_elem)->partition_name, NORMAL_PART_NAME, TRUE);
  6566. DBUG_PRINT("info",("spider tmp_name=%s", tmp_name));
  6567. if (!memcmp(table_name, tmp_name, table_name_length + 1))
  6568. DBUG_VOID_RETURN;
  6569. if (
  6570. tmp_flg &&
  6571. *(tmp_name + table_name_length - 5) == '\0' &&
  6572. !memcmp(table_name, tmp_name, table_name_length - 5)
  6573. ) {
  6574. tmp_part_elem = *part_elem;
  6575. tmp_flg = FALSE;
  6576. tmp_find_flg = TRUE;
  6577. }
  6578. }
  6579. }
  6580. if (tmp_find_flg)
  6581. {
  6582. *part_elem = tmp_part_elem;
  6583. *sub_elem = tmp_sub_elem;
  6584. DBUG_PRINT("info",("spider tmp find"));
  6585. DBUG_VOID_RETURN;
  6586. }
  6587. *part_elem = NULL;
  6588. *sub_elem = NULL;
  6589. DBUG_PRINT("info",("spider no hit"));
  6590. DBUG_VOID_RETURN;
  6591. }
  6592. #endif
  6593. int spider_get_sts(
  6594. SPIDER_SHARE *share,
  6595. int link_idx,
  6596. time_t tmp_time,
  6597. ha_spider *spider,
  6598. double sts_interval,
  6599. int sts_mode,
  6600. #ifdef WITH_PARTITION_STORAGE_ENGINE
  6601. int sts_sync,
  6602. #endif
  6603. int sts_sync_level,
  6604. uint flag
  6605. ) {
  6606. int get_type;
  6607. int error_num = 0;
  6608. DBUG_ENTER("spider_get_sts");
  6609. #ifdef WITH_PARTITION_STORAGE_ENGINE
  6610. if (
  6611. sts_sync == 0
  6612. ) {
  6613. #endif
  6614. /* get */
  6615. get_type = 1;
  6616. #ifdef WITH_PARTITION_STORAGE_ENGINE
  6617. } else if (
  6618. !share->partition_share->sts_init
  6619. ) {
  6620. pthread_mutex_lock(&share->partition_share->sts_mutex);
  6621. if (!share->partition_share->sts_init)
  6622. {
  6623. /* get after mutex_lock */
  6624. get_type = 2;
  6625. } else {
  6626. pthread_mutex_unlock(&share->partition_share->sts_mutex);
  6627. /* copy */
  6628. get_type = 0;
  6629. }
  6630. } else if (
  6631. difftime(share->sts_get_time, share->partition_share->sts_get_time) <
  6632. sts_interval
  6633. ) {
  6634. /* copy */
  6635. get_type = 0;
  6636. } else if (
  6637. !pthread_mutex_trylock(&share->partition_share->sts_mutex)
  6638. ) {
  6639. /* get after mutex_trylock */
  6640. get_type = 3;
  6641. } else {
  6642. /* copy */
  6643. get_type = 0;
  6644. }
  6645. if (get_type == 0)
  6646. spider_copy_sts_to_share(share, share->partition_share);
  6647. else
  6648. #endif
  6649. error_num = spider_db_show_table_status(spider, link_idx, sts_mode, flag);
  6650. #ifdef WITH_PARTITION_STORAGE_ENGINE
  6651. if (get_type >= 2)
  6652. pthread_mutex_unlock(&share->partition_share->sts_mutex);
  6653. #endif
  6654. if (error_num)
  6655. {
  6656. #ifdef WITH_PARTITION_STORAGE_ENGINE
  6657. SPIDER_PARTITION_HANDLER_SHARE *partition_handler_share =
  6658. spider->partition_handler_share;
  6659. if (
  6660. !share->partition_share->sts_init &&
  6661. sts_sync >= sts_sync_level &&
  6662. get_type > 1 &&
  6663. partition_handler_share &&
  6664. partition_handler_share->handlers &&
  6665. partition_handler_share->handlers[0] == spider
  6666. ) {
  6667. int roop_count;
  6668. ha_spider *tmp_spider;
  6669. SPIDER_SHARE *tmp_share;
  6670. double tmp_sts_interval;
  6671. int tmp_sts_mode;
  6672. int tmp_sts_sync;
  6673. THD *thd = spider->trx->thd;
  6674. for (roop_count = 1;
  6675. roop_count < (int) partition_handler_share->use_count;
  6676. roop_count++)
  6677. {
  6678. tmp_spider =
  6679. (ha_spider *) partition_handler_share->handlers[roop_count];
  6680. tmp_share = tmp_spider->share;
  6681. tmp_sts_interval = spider_param_sts_interval(thd, share->sts_interval);
  6682. tmp_sts_mode = spider_param_sts_mode(thd, share->sts_mode);
  6683. tmp_sts_sync = spider_param_sts_sync(thd, share->sts_sync);
  6684. spider_get_sts(tmp_share, tmp_spider->search_link_idx,
  6685. tmp_time, tmp_spider, tmp_sts_interval, tmp_sts_mode, tmp_sts_sync,
  6686. 1, flag);
  6687. if (share->partition_share->sts_init)
  6688. {
  6689. error_num = 0;
  6690. thd->clear_error();
  6691. get_type = 0;
  6692. spider_copy_sts_to_share(share, share->partition_share);
  6693. break;
  6694. }
  6695. }
  6696. }
  6697. if (error_num)
  6698. #endif
  6699. DBUG_RETURN(error_num);
  6700. }
  6701. #ifdef WITH_PARTITION_STORAGE_ENGINE
  6702. if (sts_sync >= sts_sync_level && get_type > 0)
  6703. {
  6704. spider_copy_sts_to_pt_share(share->partition_share, share);
  6705. share->partition_share->sts_get_time = tmp_time;
  6706. share->partition_share->sts_init = TRUE;
  6707. }
  6708. #endif
  6709. share->sts_get_time = tmp_time;
  6710. share->sts_init = TRUE;
  6711. DBUG_RETURN(0);
  6712. }
  6713. int spider_get_crd(
  6714. SPIDER_SHARE *share,
  6715. int link_idx,
  6716. time_t tmp_time,
  6717. ha_spider *spider,
  6718. TABLE *table,
  6719. double crd_interval,
  6720. int crd_mode,
  6721. #ifdef WITH_PARTITION_STORAGE_ENGINE
  6722. int crd_sync,
  6723. #endif
  6724. int crd_sync_level
  6725. ) {
  6726. int get_type;
  6727. int error_num = 0;
  6728. DBUG_ENTER("spider_get_crd");
  6729. #ifdef WITH_PARTITION_STORAGE_ENGINE
  6730. if (
  6731. crd_sync == 0
  6732. ) {
  6733. #endif
  6734. /* get */
  6735. get_type = 1;
  6736. #ifdef WITH_PARTITION_STORAGE_ENGINE
  6737. } else if (
  6738. !share->partition_share->crd_init
  6739. ) {
  6740. pthread_mutex_lock(&share->partition_share->crd_mutex);
  6741. if (!share->partition_share->crd_init)
  6742. {
  6743. /* get after mutex_lock */
  6744. get_type = 2;
  6745. } else {
  6746. pthread_mutex_unlock(&share->partition_share->crd_mutex);
  6747. /* copy */
  6748. get_type = 0;
  6749. }
  6750. } else if (
  6751. difftime(share->crd_get_time, share->partition_share->crd_get_time) <
  6752. crd_interval
  6753. ) {
  6754. /* copy */
  6755. get_type = 0;
  6756. } else if (
  6757. !pthread_mutex_trylock(&share->partition_share->crd_mutex)
  6758. ) {
  6759. /* get after mutex_trylock */
  6760. get_type = 3;
  6761. } else {
  6762. /* copy */
  6763. get_type = 0;
  6764. }
  6765. if (get_type == 0)
  6766. spider_copy_crd_to_share(share, share->partition_share,
  6767. table->s->fields);
  6768. else
  6769. #endif
  6770. error_num = spider_db_show_index(spider, link_idx, table, crd_mode);
  6771. #ifdef WITH_PARTITION_STORAGE_ENGINE
  6772. if (get_type >= 2)
  6773. pthread_mutex_unlock(&share->partition_share->crd_mutex);
  6774. #endif
  6775. if (error_num)
  6776. {
  6777. #ifdef WITH_PARTITION_STORAGE_ENGINE
  6778. SPIDER_PARTITION_HANDLER_SHARE *partition_handler_share =
  6779. spider->partition_handler_share;
  6780. if (
  6781. !share->partition_share->crd_init &&
  6782. crd_sync >= crd_sync_level &&
  6783. get_type > 1 &&
  6784. partition_handler_share &&
  6785. partition_handler_share->handlers &&
  6786. partition_handler_share->handlers[0] == spider
  6787. ) {
  6788. int roop_count;
  6789. ha_spider *tmp_spider;
  6790. SPIDER_SHARE *tmp_share;
  6791. double tmp_crd_interval;
  6792. int tmp_crd_mode;
  6793. int tmp_crd_sync;
  6794. THD *thd = spider->trx->thd;
  6795. for (roop_count = 1;
  6796. roop_count < (int) partition_handler_share->use_count;
  6797. roop_count++)
  6798. {
  6799. tmp_spider =
  6800. (ha_spider *) partition_handler_share->handlers[roop_count];
  6801. tmp_share = tmp_spider->share;
  6802. tmp_crd_interval = spider_param_crd_interval(thd, share->crd_interval);
  6803. tmp_crd_mode = spider_param_crd_mode(thd, share->crd_mode);
  6804. tmp_crd_sync = spider_param_crd_sync(thd, share->crd_sync);
  6805. spider_get_crd(tmp_share, tmp_spider->search_link_idx,
  6806. tmp_time, tmp_spider, table, tmp_crd_interval, tmp_crd_mode,
  6807. tmp_crd_sync, 1);
  6808. if (share->partition_share->crd_init)
  6809. {
  6810. error_num = 0;
  6811. thd->clear_error();
  6812. get_type = 0;
  6813. spider_copy_crd_to_share(share, share->partition_share,
  6814. table->s->fields);
  6815. break;
  6816. }
  6817. }
  6818. }
  6819. if (error_num)
  6820. #endif
  6821. DBUG_RETURN(error_num);
  6822. }
  6823. #ifdef WITH_PARTITION_STORAGE_ENGINE
  6824. if (crd_sync >= crd_sync_level && get_type > 0)
  6825. {
  6826. spider_copy_crd_to_pt_share(share->partition_share, share,
  6827. table->s->fields);
  6828. share->partition_share->crd_get_time = tmp_time;
  6829. share->partition_share->crd_init = TRUE;
  6830. }
  6831. #endif
  6832. share->crd_get_time = tmp_time;
  6833. share->crd_init = TRUE;
  6834. DBUG_RETURN(0);
  6835. }
  6836. void spider_set_result_list_param(
  6837. ha_spider *spider
  6838. ) {
  6839. SPIDER_RESULT_LIST *result_list = &spider->result_list;
  6840. SPIDER_SHARE *share = spider->share;
  6841. THD *thd = spider->trx->thd;
  6842. DBUG_ENTER("spider_set_result_list_param");
  6843. result_list->internal_offset =
  6844. spider_param_internal_offset(thd, share->internal_offset);
  6845. result_list->internal_limit =
  6846. #ifdef INFO_KIND_FORCE_LIMIT_BEGIN
  6847. spider->info_limit < 9223372036854775807LL ?
  6848. spider->info_limit :
  6849. #endif
  6850. spider_param_internal_limit(thd, share->internal_limit);
  6851. result_list->split_read = spider_split_read_param(spider);
  6852. if (spider->support_multi_split_read_sql())
  6853. {
  6854. result_list->multi_split_read =
  6855. spider_param_multi_split_read(thd, share->multi_split_read);
  6856. } else {
  6857. result_list->multi_split_read = 1;
  6858. }
  6859. result_list->max_order =
  6860. spider_param_max_order(thd, share->max_order);
  6861. result_list->quick_mode =
  6862. spider_param_quick_mode(thd, share->quick_mode);
  6863. result_list->quick_page_size =
  6864. spider_param_quick_page_size(thd, share->quick_page_size);
  6865. result_list->low_mem_read =
  6866. spider_param_low_mem_read(thd, share->low_mem_read);
  6867. DBUG_VOID_RETURN;
  6868. }
  6869. SPIDER_INIT_ERROR_TABLE *spider_get_init_error_table(
  6870. SPIDER_TRX *trx,
  6871. SPIDER_SHARE *share,
  6872. bool create
  6873. ) {
  6874. SPIDER_INIT_ERROR_TABLE *spider_init_error_table;
  6875. char *tmp_name;
  6876. DBUG_ENTER("spider_get_init_error_table");
  6877. pthread_mutex_lock(&spider_init_error_tbl_mutex);
  6878. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  6879. if (!(spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *)
  6880. my_hash_search_using_hash_value(
  6881. &spider_init_error_tables, share->table_name_hash_value,
  6882. (uchar*) share->table_name, share->table_name_length)))
  6883. #else
  6884. if (!(spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *) my_hash_search(
  6885. &spider_init_error_tables,
  6886. (uchar*) share->table_name, share->table_name_length)))
  6887. #endif
  6888. {
  6889. if (!create)
  6890. {
  6891. pthread_mutex_unlock(&spider_init_error_tbl_mutex);
  6892. DBUG_RETURN(NULL);
  6893. }
  6894. if (!(spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *)
  6895. spider_bulk_malloc(spider_current_trx, 54, MYF(MY_WME | MY_ZEROFILL),
  6896. &spider_init_error_table, sizeof(*spider_init_error_table),
  6897. &tmp_name, share->table_name_length + 1,
  6898. NullS))
  6899. ) {
  6900. pthread_mutex_unlock(&spider_init_error_tbl_mutex);
  6901. DBUG_RETURN(NULL);
  6902. }
  6903. memcpy(tmp_name, share->table_name, share->table_name_length);
  6904. spider_init_error_table->table_name = tmp_name;
  6905. spider_init_error_table->table_name_length = share->table_name_length;
  6906. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  6907. spider_init_error_table->table_name_hash_value =
  6908. share->table_name_hash_value;
  6909. #endif
  6910. uint old_elements = spider_init_error_tables.array.max_element;
  6911. #ifdef HASH_UPDATE_WITH_HASH_VALUE
  6912. if (my_hash_insert_with_hash_value(&spider_init_error_tables,
  6913. share->table_name_hash_value, (uchar*) spider_init_error_table))
  6914. #else
  6915. if (my_hash_insert(&spider_init_error_tables,
  6916. (uchar*) spider_init_error_table))
  6917. #endif
  6918. {
  6919. spider_free(trx, spider_init_error_table, MYF(0));
  6920. pthread_mutex_unlock(&spider_init_error_tbl_mutex);
  6921. DBUG_RETURN(NULL);
  6922. }
  6923. if (spider_init_error_tables.array.max_element > old_elements)
  6924. {
  6925. spider_alloc_calc_mem(spider_current_trx,
  6926. spider_init_error_tables,
  6927. (spider_init_error_tables.array.max_element - old_elements) *
  6928. spider_init_error_tables.array.size_of_element);
  6929. }
  6930. }
  6931. pthread_mutex_unlock(&spider_init_error_tbl_mutex);
  6932. DBUG_RETURN(spider_init_error_table);
  6933. }
  6934. void spider_delete_init_error_table(
  6935. const char *name
  6936. ) {
  6937. SPIDER_INIT_ERROR_TABLE *spider_init_error_table;
  6938. uint length = strlen(name);
  6939. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  6940. my_hash_value_type hash_value = my_calc_hash(&spider_open_tables,
  6941. (uchar*) name, length);
  6942. #endif
  6943. DBUG_ENTER("spider_delete_init_error_table");
  6944. pthread_mutex_lock(&spider_init_error_tbl_mutex);
  6945. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  6946. if ((spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *)
  6947. my_hash_search_using_hash_value(&spider_init_error_tables, hash_value,
  6948. (uchar*) name, length)))
  6949. #else
  6950. if ((spider_init_error_table = (SPIDER_INIT_ERROR_TABLE *) my_hash_search(
  6951. &spider_init_error_tables, (uchar*) name, length)))
  6952. #endif
  6953. {
  6954. #ifdef HASH_UPDATE_WITH_HASH_VALUE
  6955. my_hash_delete_with_hash_value(&spider_init_error_tables,
  6956. spider_init_error_table->table_name_hash_value,
  6957. (uchar*) spider_init_error_table);
  6958. #else
  6959. my_hash_delete(&spider_init_error_tables,
  6960. (uchar*) spider_init_error_table);
  6961. #endif
  6962. spider_free(spider_current_trx, spider_init_error_table, MYF(0));
  6963. }
  6964. pthread_mutex_unlock(&spider_init_error_tbl_mutex);
  6965. DBUG_VOID_RETURN;
  6966. }
  6967. bool spider_check_pk_update(
  6968. TABLE *table
  6969. ) {
  6970. int roop_count;
  6971. TABLE_SHARE *table_share = table->s;
  6972. KEY *key_info;
  6973. KEY_PART_INFO *key_part;
  6974. DBUG_ENTER("spider_check_pk_update");
  6975. if (table_share->primary_key == MAX_KEY)
  6976. DBUG_RETURN(FALSE);
  6977. key_info = &table_share->key_info[table_share->primary_key];
  6978. key_part = key_info->key_part;
  6979. for (roop_count = 0;
  6980. roop_count < (int) spider_user_defined_key_parts(key_info); roop_count++)
  6981. {
  6982. if (bitmap_is_set(table->write_set,
  6983. key_part[roop_count].field->field_index))
  6984. DBUG_RETURN(TRUE);
  6985. }
  6986. DBUG_RETURN(FALSE);
  6987. }
  6988. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  6989. #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
  6990. bool spider_check_hs_pk_update(
  6991. ha_spider *spider,
  6992. key_range *key
  6993. ) {
  6994. uint roop_count, field_index, set_count = 0;
  6995. TABLE *table = spider->get_table();
  6996. TABLE_SHARE *table_share = table->s;
  6997. SPIDER_SHARE *share = spider->share;
  6998. KEY *key_info;
  6999. KEY_PART_INFO *key_part;
  7000. char buf[MAX_FIELD_WIDTH], buf2[MAX_FIELD_WIDTH];
  7001. spider_string tmp_str(buf, MAX_FIELD_WIDTH, &my_charset_bin),
  7002. tmp_str2(buf2, MAX_FIELD_WIDTH, &my_charset_bin);
  7003. String *str, *str2;
  7004. DBUG_ENTER("spider_check_hs_pk_update");
  7005. tmp_str.init_calc_mem(137);
  7006. if (table_share->primary_key == MAX_KEY)
  7007. DBUG_RETURN(FALSE);
  7008. memset(spider->tmp_column_bitmap, 0, sizeof(uchar) * share->bitmap_size);
  7009. key_info = &table->key_info[table_share->primary_key];
  7010. key_part = key_info->key_part;
  7011. for (roop_count = 0; roop_count < spider_user_defined_key_parts(key_info);
  7012. roop_count++)
  7013. {
  7014. field_index = key_part[roop_count].field->field_index;
  7015. if (bitmap_is_set(table->write_set, field_index))
  7016. {
  7017. DBUG_PRINT("info", ("spider set key_part=%u field_index=%u",
  7018. roop_count, field_index));
  7019. spider_set_bit(spider->tmp_column_bitmap, field_index);
  7020. set_count++;
  7021. }
  7022. }
  7023. DBUG_PRINT("info", ("spider set_count=%u", set_count));
  7024. Field *field;
  7025. uint store_length, length, var_len;
  7026. const uchar *ptr;
  7027. bool key_eq;
  7028. key_part_map tgt_key_part_map = key->keypart_map;
  7029. key_info = &table->key_info[spider->active_index];
  7030. for (
  7031. key_part = key_info->key_part,
  7032. length = 0;
  7033. tgt_key_part_map;
  7034. length += store_length,
  7035. tgt_key_part_map >>= 1,
  7036. key_part++
  7037. ) {
  7038. store_length = key_part->store_length;
  7039. field = key_part->field;
  7040. field_index = field->field_index;
  7041. if (spider_bit_is_set(spider->tmp_column_bitmap, field_index))
  7042. {
  7043. ptr = key->key + length;
  7044. key_eq = (tgt_key_part_map > 1);
  7045. if (key_part->null_bit && *ptr++)
  7046. {
  7047. if (key->flag != HA_READ_KEY_EXACT || !field->is_null())
  7048. {
  7049. DBUG_PRINT("info", ("spider flag=%u is_null=%s",
  7050. key->flag, field->is_null() ? "TRUE" : "FALSE"));
  7051. DBUG_RETURN(TRUE);
  7052. }
  7053. } else {
  7054. if (
  7055. field->type() == MYSQL_TYPE_BLOB ||
  7056. field->real_type() == MYSQL_TYPE_VARCHAR ||
  7057. field->type() == MYSQL_TYPE_GEOMETRY
  7058. ) {
  7059. var_len = uint2korr(ptr);
  7060. tmp_str.set_quick((char *) ptr + HA_KEY_BLOB_LENGTH, var_len,
  7061. &my_charset_bin);
  7062. str = tmp_str.get_str();
  7063. } else {
  7064. str = field->val_str(tmp_str.get_str(), ptr);
  7065. tmp_str.mem_calc();
  7066. }
  7067. str2 = field->val_str(tmp_str2.get_str());
  7068. tmp_str2.mem_calc();
  7069. if (
  7070. str->length() != str2->length() ||
  7071. memcmp(str->ptr(), str2->ptr(), str->length())
  7072. ) {
  7073. DBUG_PRINT("info", ("spider length=%u %u",
  7074. str->length(), str2->length()));
  7075. DBUG_PRINT("info", ("spider length=%s %s",
  7076. str->c_ptr_safe(), str2->c_ptr_safe()));
  7077. DBUG_RETURN(TRUE);
  7078. }
  7079. }
  7080. set_count--;
  7081. }
  7082. }
  7083. DBUG_PRINT("info", ("spider set_count=%u", set_count));
  7084. if (set_count)
  7085. {
  7086. DBUG_RETURN(TRUE);
  7087. }
  7088. DBUG_RETURN(FALSE);
  7089. }
  7090. #endif
  7091. #endif
  7092. void spider_set_tmp_share_pointer(
  7093. SPIDER_SHARE *tmp_share,
  7094. char **tmp_connect_info,
  7095. uint *tmp_connect_info_length,
  7096. long *tmp_long,
  7097. longlong *tmp_longlong
  7098. ) {
  7099. DBUG_ENTER("spider_set_tmp_share_pointer");
  7100. tmp_share->link_count = 1;
  7101. tmp_share->all_link_count = 1;
  7102. tmp_share->server_names = &tmp_connect_info[0];
  7103. tmp_share->tgt_table_names = &tmp_connect_info[1];
  7104. tmp_share->tgt_dbs = &tmp_connect_info[2];
  7105. tmp_share->tgt_hosts = &tmp_connect_info[3];
  7106. tmp_share->tgt_usernames = &tmp_connect_info[4];
  7107. tmp_share->tgt_passwords = &tmp_connect_info[5];
  7108. tmp_share->tgt_sockets = &tmp_connect_info[6];
  7109. tmp_share->tgt_wrappers = &tmp_connect_info[7];
  7110. tmp_share->tgt_ssl_cas = &tmp_connect_info[8];
  7111. tmp_share->tgt_ssl_capaths = &tmp_connect_info[9];
  7112. tmp_share->tgt_ssl_certs = &tmp_connect_info[10];
  7113. tmp_share->tgt_ssl_ciphers = &tmp_connect_info[11];
  7114. tmp_share->tgt_ssl_keys = &tmp_connect_info[12];
  7115. tmp_share->tgt_default_files = &tmp_connect_info[13];
  7116. tmp_share->tgt_default_groups = &tmp_connect_info[14];
  7117. tmp_share->tgt_pk_names = &tmp_connect_info[15];
  7118. tmp_share->tgt_sequence_names = &tmp_connect_info[16];
  7119. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  7120. tmp_share->hs_read_socks = &tmp_connect_info[17];
  7121. tmp_share->hs_write_socks = &tmp_connect_info[18];
  7122. #endif
  7123. tmp_share->tgt_ports = &tmp_long[0];
  7124. tmp_share->tgt_ssl_vscs = &tmp_long[1];
  7125. tmp_share->link_statuses = &tmp_long[2];
  7126. tmp_share->monitoring_kind = &tmp_long[3];
  7127. #ifndef WITHOUT_SPIDER_BG_SEARCH
  7128. tmp_share->monitoring_bg_kind = &tmp_long[4];
  7129. #endif
  7130. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  7131. tmp_share->use_hs_reads = &tmp_long[5];
  7132. tmp_share->use_hs_writes = &tmp_long[6];
  7133. tmp_share->hs_read_ports = &tmp_long[7];
  7134. tmp_share->hs_write_ports = &tmp_long[8];
  7135. tmp_share->hs_write_to_reads = &tmp_long[9];
  7136. #endif
  7137. tmp_share->use_handlers = &tmp_long[10];
  7138. tmp_share->connect_timeouts = &tmp_long[11];
  7139. tmp_long[11] = -1;
  7140. tmp_share->net_read_timeouts = &tmp_long[12];
  7141. tmp_long[12] = -1;
  7142. tmp_share->net_write_timeouts = &tmp_long[13];
  7143. tmp_long[13] = -1;
  7144. tmp_share->access_balances = &tmp_long[14];
  7145. tmp_share->monitoring_limit = &tmp_longlong[0];
  7146. tmp_share->monitoring_sid = &tmp_longlong[1];
  7147. #ifndef WITHOUT_SPIDER_BG_SEARCH
  7148. tmp_share->monitoring_bg_interval = &tmp_longlong[2];
  7149. #endif
  7150. tmp_share->server_names_lengths = &tmp_connect_info_length[0];
  7151. tmp_share->tgt_table_names_lengths = &tmp_connect_info_length[1];
  7152. tmp_share->tgt_dbs_lengths = &tmp_connect_info_length[2];
  7153. tmp_share->tgt_hosts_lengths = &tmp_connect_info_length[3];
  7154. tmp_share->tgt_usernames_lengths = &tmp_connect_info_length[4];
  7155. tmp_share->tgt_passwords_lengths = &tmp_connect_info_length[5];
  7156. tmp_share->tgt_sockets_lengths = &tmp_connect_info_length[6];
  7157. tmp_share->tgt_wrappers_lengths = &tmp_connect_info_length[7];
  7158. tmp_share->tgt_ssl_cas_lengths = &tmp_connect_info_length[8];
  7159. tmp_share->tgt_ssl_capaths_lengths = &tmp_connect_info_length[9];
  7160. tmp_share->tgt_ssl_certs_lengths = &tmp_connect_info_length[10];
  7161. tmp_share->tgt_ssl_ciphers_lengths = &tmp_connect_info_length[11];
  7162. tmp_share->tgt_ssl_keys_lengths = &tmp_connect_info_length[12];
  7163. tmp_share->tgt_default_files_lengths = &tmp_connect_info_length[13];
  7164. tmp_share->tgt_default_groups_lengths = &tmp_connect_info_length[14];
  7165. tmp_share->tgt_pk_names_lengths = &tmp_connect_info_length[15];
  7166. tmp_share->tgt_sequence_names_lengths = &tmp_connect_info_length[16];
  7167. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  7168. tmp_share->hs_read_socks_lengths = &tmp_connect_info_length[17];
  7169. tmp_share->hs_write_socks_lengths = &tmp_connect_info_length[18];
  7170. #endif
  7171. tmp_share->server_names_length = 1;
  7172. tmp_share->tgt_table_names_length = 1;
  7173. tmp_share->tgt_dbs_length = 1;
  7174. tmp_share->tgt_hosts_length = 1;
  7175. tmp_share->tgt_usernames_length = 1;
  7176. tmp_share->tgt_passwords_length = 1;
  7177. tmp_share->tgt_sockets_length = 1;
  7178. tmp_share->tgt_wrappers_length = 1;
  7179. tmp_share->tgt_ssl_cas_length = 1;
  7180. tmp_share->tgt_ssl_capaths_length = 1;
  7181. tmp_share->tgt_ssl_certs_length = 1;
  7182. tmp_share->tgt_ssl_ciphers_length = 1;
  7183. tmp_share->tgt_ssl_keys_length = 1;
  7184. tmp_share->tgt_default_files_length = 1;
  7185. tmp_share->tgt_default_groups_length = 1;
  7186. tmp_share->tgt_pk_names_length = 1;
  7187. tmp_share->tgt_sequence_names_length = 1;
  7188. tmp_share->tgt_ports_length = 1;
  7189. tmp_share->tgt_ssl_vscs_length = 1;
  7190. tmp_share->link_statuses_length = 1;
  7191. tmp_share->monitoring_kind_length = 1;
  7192. #ifndef WITHOUT_SPIDER_BG_SEARCH
  7193. tmp_share->monitoring_bg_kind_length = 1;
  7194. #endif
  7195. tmp_share->monitoring_limit_length = 1;
  7196. tmp_share->monitoring_sid_length = 1;
  7197. #ifndef WITHOUT_SPIDER_BG_SEARCH
  7198. tmp_share->monitoring_bg_interval_length = 1;
  7199. #endif
  7200. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  7201. tmp_share->hs_read_socks_length = 1;
  7202. tmp_share->hs_write_socks_length = 1;
  7203. tmp_share->use_hs_reads_length = 1;
  7204. tmp_share->use_hs_writes_length = 1;
  7205. tmp_share->hs_read_ports_length = 1;
  7206. tmp_share->hs_write_ports_length = 1;
  7207. tmp_share->hs_write_to_reads_length = 1;
  7208. #endif
  7209. tmp_share->use_handlers_length = 1;
  7210. tmp_share->connect_timeouts_length = 1;
  7211. tmp_share->net_read_timeouts_length = 1;
  7212. tmp_share->net_write_timeouts_length = 1;
  7213. tmp_share->access_balances_length = 1;
  7214. #ifndef WITHOUT_SPIDER_BG_SEARCH
  7215. tmp_share->monitoring_bg_kind[0] = -1;
  7216. #endif
  7217. tmp_share->monitoring_kind[0] = -1;
  7218. #ifndef WITHOUT_SPIDER_BG_SEARCH
  7219. tmp_share->monitoring_bg_interval[0] = -1;
  7220. #endif
  7221. tmp_share->monitoring_limit[0] = -1;
  7222. tmp_share->monitoring_sid[0] = -1;
  7223. tmp_share->bka_engine = NULL;
  7224. tmp_share->use_dbton_count = 0;
  7225. #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
  7226. tmp_share->use_hs_dbton_count = 0;
  7227. #endif
  7228. DBUG_VOID_RETURN;
  7229. }
  7230. int spider_create_tmp_dbton_share(
  7231. SPIDER_SHARE *tmp_share
  7232. ) {
  7233. int error_num;
  7234. uint dbton_id = tmp_share->use_dbton_ids[0];
  7235. DBUG_ENTER("spider_create_tmp_dbton_share");
  7236. if (!(tmp_share->dbton_share[dbton_id] =
  7237. spider_dbton[dbton_id].create_db_share(tmp_share)))
  7238. {
  7239. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  7240. }
  7241. if ((error_num = tmp_share->dbton_share[dbton_id]->init()))
  7242. {
  7243. delete tmp_share->dbton_share[dbton_id];
  7244. tmp_share->dbton_share[dbton_id] = NULL;
  7245. DBUG_RETURN(error_num);
  7246. }
  7247. DBUG_RETURN(0);
  7248. }
  7249. void spider_free_tmp_dbton_share(
  7250. SPIDER_SHARE *tmp_share
  7251. ) {
  7252. uint dbton_id = tmp_share->use_dbton_ids[0];
  7253. DBUG_ENTER("spider_free_tmp_dbton_share");
  7254. if (tmp_share->dbton_share[dbton_id])
  7255. {
  7256. delete tmp_share->dbton_share[dbton_id];
  7257. tmp_share->dbton_share[dbton_id] = NULL;
  7258. }
  7259. DBUG_VOID_RETURN;
  7260. }
  7261. int spider_create_tmp_dbton_handler(
  7262. ha_spider *tmp_spider
  7263. ) {
  7264. int error_num;
  7265. SPIDER_SHARE *tmp_share = tmp_spider->share;
  7266. uint dbton_id = tmp_share->use_dbton_ids[0];
  7267. DBUG_ENTER("spider_create_tmp_dbton_handler");
  7268. if (!(tmp_spider->dbton_handler[dbton_id] =
  7269. spider_dbton[dbton_id].create_db_handler(tmp_spider,
  7270. tmp_share->dbton_share[dbton_id])))
  7271. {
  7272. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  7273. }
  7274. if ((error_num = tmp_spider->dbton_handler[dbton_id]->init()))
  7275. {
  7276. delete tmp_spider->dbton_handler[dbton_id];
  7277. tmp_spider->dbton_handler[dbton_id] = NULL;
  7278. DBUG_RETURN(error_num);
  7279. }
  7280. DBUG_RETURN(0);
  7281. }
  7282. void spider_free_tmp_dbton_handler(
  7283. ha_spider *tmp_spider
  7284. ) {
  7285. SPIDER_SHARE *tmp_share = tmp_spider->share;
  7286. uint dbton_id = tmp_share->use_dbton_ids[0];
  7287. DBUG_ENTER("spider_create_tmp_dbton_handler");
  7288. if (tmp_spider->dbton_handler[dbton_id])
  7289. {
  7290. delete tmp_spider->dbton_handler[dbton_id];
  7291. tmp_spider->dbton_handler[dbton_id] = NULL;
  7292. }
  7293. DBUG_VOID_RETURN;
  7294. }
  7295. TABLE_LIST *spider_get_parent_table_list(
  7296. ha_spider *spider
  7297. ) {
  7298. TABLE *table = spider->get_table();
  7299. TABLE_LIST *table_list = table->pos_in_table_list;
  7300. DBUG_ENTER("spider_get_parent_table_list");
  7301. if (table_list)
  7302. {
  7303. while (table_list->parent_l)
  7304. table_list = table_list->parent_l;
  7305. DBUG_RETURN(table_list);
  7306. }
  7307. DBUG_RETURN(NULL);
  7308. }
  7309. st_select_lex *spider_get_select_lex(
  7310. ha_spider *spider
  7311. ) {
  7312. TABLE_LIST *table_list = spider_get_parent_table_list(spider);
  7313. DBUG_ENTER("spider_get_select_lex");
  7314. if (table_list)
  7315. {
  7316. DBUG_RETURN(table_list->select_lex);
  7317. }
  7318. DBUG_RETURN(NULL);
  7319. }
  7320. void spider_get_select_limit(
  7321. ha_spider *spider,
  7322. st_select_lex **select_lex,
  7323. longlong *select_limit,
  7324. longlong *offset_limit
  7325. ) {
  7326. DBUG_ENTER("spider_get_select_limit");
  7327. *select_lex = spider_get_select_lex(spider);
  7328. *select_limit = 9223372036854775807LL;
  7329. *offset_limit = 0;
  7330. if (*select_lex && (*select_lex)->explicit_limit)
  7331. {
  7332. *select_limit = (*select_lex)->select_limit ?
  7333. (*select_lex)->select_limit->val_int() : 0;
  7334. *offset_limit = (*select_lex)->offset_limit ?
  7335. (*select_lex)->offset_limit->val_int() : 0;
  7336. }
  7337. DBUG_VOID_RETURN;
  7338. }
  7339. longlong spider_split_read_param(
  7340. ha_spider *spider
  7341. ) {
  7342. SPIDER_SHARE *share = spider->share;
  7343. SPIDER_RESULT_LIST *result_list = &spider->result_list;
  7344. THD *thd = spider->trx->thd;
  7345. st_select_lex *select_lex;
  7346. longlong select_limit;
  7347. longlong offset_limit;
  7348. double semi_split_read;
  7349. longlong split_read;
  7350. DBUG_ENTER("spider_split_read_param");
  7351. result_list->set_split_read_count = 1;
  7352. #ifdef INFO_KIND_FORCE_LIMIT_BEGIN
  7353. if (spider->info_limit < 9223372036854775807LL)
  7354. {
  7355. DBUG_PRINT("info",("spider info_limit=%lld", spider->info_limit));
  7356. longlong info_limit = spider->info_limit;
  7357. result_list->split_read_base = info_limit;
  7358. result_list->semi_split_read = 0;
  7359. result_list->first_read = info_limit;
  7360. result_list->second_read = info_limit;
  7361. result_list->semi_split_read_base = 0;
  7362. result_list->set_split_read = FALSE;
  7363. DBUG_RETURN(info_limit);
  7364. }
  7365. #endif
  7366. if (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER)
  7367. {
  7368. DBUG_RETURN(result_list->semi_split_read_base);
  7369. }
  7370. spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit);
  7371. if (!result_list->set_split_read)
  7372. {
  7373. int bulk_update_mode = spider_param_bulk_update_mode(thd,
  7374. share->bulk_update_mode);
  7375. DBUG_PRINT("info",("spider sql_command=%u", spider->sql_command));
  7376. DBUG_PRINT("info",("spider bulk_update_mode=%d", bulk_update_mode));
  7377. DBUG_PRINT("info",("spider support_bulk_update_sql=%s",
  7378. spider->support_bulk_update_sql() ? "TRUE" : "FALSE"));
  7379. bool updating =
  7380. (
  7381. #ifdef HS_HAS_SQLCOM
  7382. spider->sql_command == SQLCOM_HS_UPDATE ||
  7383. #endif
  7384. spider->sql_command == SQLCOM_UPDATE ||
  7385. spider->sql_command == SQLCOM_UPDATE_MULTI
  7386. );
  7387. bool deleting =
  7388. (
  7389. #ifdef HS_HAS_SQLCOM
  7390. spider->sql_command == SQLCOM_HS_DELETE ||
  7391. #endif
  7392. spider->sql_command == SQLCOM_DELETE ||
  7393. spider->sql_command == SQLCOM_DELETE_MULTI
  7394. );
  7395. bool replacing =
  7396. (
  7397. spider->sql_command == SQLCOM_REPLACE ||
  7398. spider->sql_command == SQLCOM_REPLACE_SELECT
  7399. );
  7400. DBUG_PRINT("info",("spider updating=%s", updating ? "TRUE" : "FALSE"));
  7401. DBUG_PRINT("info",("spider deleting=%s", deleting ? "TRUE" : "FALSE"));
  7402. DBUG_PRINT("info",("spider replacing=%s", replacing ? "TRUE" : "FALSE"));
  7403. TABLE *table = spider->get_table();
  7404. if (
  7405. replacing ||
  7406. (
  7407. (
  7408. updating ||
  7409. deleting
  7410. ) &&
  7411. (
  7412. bulk_update_mode != 2 ||
  7413. !spider->support_bulk_update_sql() ||
  7414. (
  7415. updating &&
  7416. table->triggers &&
  7417. #ifdef HA_CAN_FORCE_BULK_UPDATE
  7418. !(table->file->ha_table_flags() & HA_CAN_FORCE_BULK_UPDATE) &&
  7419. #endif
  7420. table->triggers->has_triggers(TRG_EVENT_UPDATE, TRG_ACTION_AFTER)
  7421. ) ||
  7422. (
  7423. deleting &&
  7424. table->triggers &&
  7425. #ifdef HA_CAN_FORCE_BULK_DELETE
  7426. !(table->file->ha_table_flags() & HA_CAN_FORCE_BULK_DELETE) &&
  7427. #endif
  7428. table->triggers->has_triggers(TRG_EVENT_DELETE, TRG_ACTION_AFTER)
  7429. )
  7430. )
  7431. )
  7432. ) {
  7433. /* This case must select by one shot */
  7434. DBUG_PRINT("info",("spider cancel split read"));
  7435. result_list->split_read_base = 9223372036854775807LL;
  7436. result_list->semi_split_read = 0;
  7437. result_list->semi_split_read_limit = 9223372036854775807LL;
  7438. result_list->first_read = 9223372036854775807LL;
  7439. result_list->second_read = 9223372036854775807LL;
  7440. result_list->semi_split_read_base = 0;
  7441. result_list->set_split_read = TRUE;
  7442. DBUG_RETURN(9223372036854775807LL);
  7443. }
  7444. result_list->split_read_base =
  7445. spider_param_split_read(thd, share->split_read);
  7446. result_list->semi_split_read =
  7447. spider_param_semi_split_read(thd, share->semi_split_read);
  7448. result_list->semi_split_read_limit =
  7449. spider_param_semi_split_read_limit(thd, share->semi_split_read_limit);
  7450. result_list->first_read =
  7451. spider_param_first_read(thd, share->first_read);
  7452. result_list->second_read =
  7453. spider_param_second_read(thd, share->second_read);
  7454. result_list->semi_split_read_base = 0;
  7455. result_list->set_split_read = TRUE;
  7456. }
  7457. if (
  7458. result_list->semi_split_read > 0 &&
  7459. select_lex && select_lex->explicit_limit &&
  7460. !(select_lex->options & OPTION_FOUND_ROWS) &&
  7461. !select_lex->group_list.elements &&
  7462. !select_lex->with_sum_func
  7463. ) {
  7464. semi_split_read = result_list->semi_split_read *
  7465. (select_limit + offset_limit);
  7466. DBUG_PRINT("info",("spider semi_split_read=%f", semi_split_read));
  7467. if (semi_split_read >= result_list->semi_split_read_limit)
  7468. {
  7469. result_list->semi_split_read_base = result_list->semi_split_read_limit;
  7470. DBUG_RETURN(result_list->semi_split_read_limit);
  7471. } else {
  7472. split_read = (longlong) semi_split_read;
  7473. if (split_read < 0)
  7474. {
  7475. result_list->semi_split_read_base = result_list->semi_split_read_limit;
  7476. DBUG_RETURN(result_list->semi_split_read_limit);
  7477. } else if (split_read == 0)
  7478. {
  7479. result_list->semi_split_read_base = 1;
  7480. DBUG_RETURN(1);
  7481. } else {
  7482. result_list->semi_split_read_base = split_read;
  7483. DBUG_RETURN(split_read);
  7484. }
  7485. }
  7486. } else if (result_list->first_read > 0)
  7487. DBUG_RETURN(result_list->first_read);
  7488. DBUG_RETURN(result_list->split_read_base);
  7489. }
  7490. longlong spider_bg_split_read_param(
  7491. ha_spider *spider
  7492. ) {
  7493. SPIDER_RESULT_LIST *result_list = &spider->result_list;
  7494. DBUG_ENTER("spider_bg_split_read_param");
  7495. if (result_list->semi_split_read_base)
  7496. DBUG_RETURN(result_list->semi_split_read_base);
  7497. DBUG_RETURN(result_list->split_read_base);
  7498. }
  7499. void spider_first_split_read_param(
  7500. ha_spider *spider
  7501. ) {
  7502. SPIDER_RESULT_LIST *result_list = &spider->result_list;
  7503. DBUG_ENTER("spider_first_split_read_param");
  7504. if (result_list->semi_split_read_base)
  7505. result_list->split_read = result_list->semi_split_read_base;
  7506. else if (result_list->second_read > 0)
  7507. result_list->split_read = result_list->first_read;
  7508. else
  7509. result_list->split_read = result_list->split_read_base;
  7510. result_list->set_split_read_count = 1;
  7511. DBUG_VOID_RETURN;
  7512. }
  7513. void spider_next_split_read_param(
  7514. ha_spider *spider
  7515. ) {
  7516. SPIDER_RESULT_LIST *result_list = &spider->result_list;
  7517. DBUG_ENTER("spider_next_split_read_param");
  7518. if (result_list->semi_split_read_base)
  7519. result_list->split_read = result_list->semi_split_read_base;
  7520. else if (
  7521. result_list->set_split_read_count == 1 &&
  7522. result_list->second_read > 0
  7523. )
  7524. result_list->split_read = result_list->second_read;
  7525. else
  7526. result_list->split_read = result_list->split_read_base;
  7527. result_list->set_split_read_count++;
  7528. DBUG_VOID_RETURN;
  7529. }
  7530. bool spider_check_direct_order_limit(
  7531. ha_spider *spider
  7532. ) {
  7533. THD *thd = spider->trx->thd;
  7534. SPIDER_SHARE *share = spider->share;
  7535. st_select_lex *select_lex;
  7536. longlong select_limit;
  7537. longlong offset_limit;
  7538. DBUG_ENTER("spider_check_direct_order_limit");
  7539. DBUG_PRINT("info",("spider SQLCOM_HA_READ=%s",
  7540. (spider->sql_command == SQLCOM_HA_READ) ? "TRUE" : "FALSE"));
  7541. DBUG_PRINT("info",("spider sql_kinds with SPIDER_SQL_KIND_HANDLER=%s",
  7542. (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER) ? "TRUE" : "FALSE"));
  7543. DBUG_PRINT("info",("spider has_clone_for_merge=%s",
  7544. spider->has_clone_for_merge ? "TRUE" : "FALSE"));
  7545. DBUG_PRINT("info",("spider is_clone=%s",
  7546. spider->is_clone ? "TRUE" : "FALSE"));
  7547. #ifdef HA_CAN_BULK_ACCESS
  7548. DBUG_PRINT("info",("spider is_bulk_access_clone=%s",
  7549. spider->is_bulk_access_clone ? "TRUE" : "FALSE"));
  7550. #endif
  7551. if (
  7552. spider->sql_command != SQLCOM_HA_READ &&
  7553. !spider->has_clone_for_merge &&
  7554. #ifdef HA_CAN_BULK_ACCESS
  7555. (!spider->is_clone || spider->is_bulk_access_clone)
  7556. #else
  7557. !spider->is_clone
  7558. #endif
  7559. ) {
  7560. spider_get_select_limit(spider, &select_lex, &select_limit, &offset_limit);
  7561. bool first_check = TRUE;
  7562. DBUG_PRINT("info",("spider select_lex=%p", select_lex));
  7563. #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
  7564. DBUG_PRINT("info",("spider leaf_tables.elements=%u",
  7565. select_lex->leaf_tables.elements));
  7566. #endif
  7567. #ifdef HANDLER_HAS_DIRECT_AGGREGATE
  7568. spider->result_list.direct_aggregate = TRUE;
  7569. #endif
  7570. DBUG_PRINT("info",("spider select_limit=%lld", select_limit));
  7571. DBUG_PRINT("info",("spider offset_limit=%lld", offset_limit));
  7572. if (
  7573. !select_lex ||
  7574. #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
  7575. select_lex->leaf_tables.elements != 1 ||
  7576. #endif
  7577. select_lex->table_list.elements != 1
  7578. ) {
  7579. DBUG_PRINT("info",("spider first_check is FALSE"));
  7580. first_check = FALSE;
  7581. #ifdef HANDLER_HAS_DIRECT_AGGREGATE
  7582. spider->result_list.direct_aggregate = FALSE;
  7583. #endif
  7584. } else if (spider_db_append_condition(spider, NULL, 0, TRUE))
  7585. {
  7586. DBUG_PRINT("info",("spider FALSE by condition"));
  7587. first_check = FALSE;
  7588. #ifdef HANDLER_HAS_DIRECT_AGGREGATE
  7589. spider->result_list.direct_aggregate = FALSE;
  7590. } else if (
  7591. !select_lex->group_list.elements &&
  7592. !select_lex->with_sum_func
  7593. ) {
  7594. DBUG_PRINT("info",("spider this SQL is not aggregate SQL"));
  7595. spider->result_list.direct_aggregate = FALSE;
  7596. } else if (spider->sql_kinds & SPIDER_SQL_KIND_HANDLER)
  7597. {
  7598. DBUG_PRINT("info",("spider sql_kinds with SPIDER_SQL_KIND_HANDLER"));
  7599. spider->result_list.direct_aggregate = FALSE;
  7600. } else {
  7601. ORDER *group;
  7602. for (group = (ORDER *) select_lex->group_list.first; group;
  7603. group = group->next)
  7604. {
  7605. if (spider->print_item_type((*group->item), NULL, NULL, 0))
  7606. {
  7607. DBUG_PRINT("info",("spider aggregate FALSE by group"));
  7608. spider->result_list.direct_aggregate = FALSE;
  7609. break;
  7610. }
  7611. }
  7612. JOIN *join = select_lex->join;
  7613. Item_sum **item_sum_ptr;
  7614. for (item_sum_ptr = join->sum_funcs; *item_sum_ptr; ++item_sum_ptr)
  7615. {
  7616. if (spider->print_item_type(*item_sum_ptr, NULL, NULL, 0))
  7617. {
  7618. DBUG_PRINT("info",("spider aggregate FALSE by not supported"));
  7619. spider->result_list.direct_aggregate = FALSE;
  7620. break;
  7621. }
  7622. }
  7623. #endif
  7624. }
  7625. longlong direct_order_limit = spider_param_direct_order_limit(thd,
  7626. share->direct_order_limit);
  7627. DBUG_PRINT("info",("spider direct_order_limit=%lld", direct_order_limit));
  7628. if (direct_order_limit)
  7629. {
  7630. DBUG_PRINT("info",("spider first_check=%s",
  7631. first_check ? "TRUE" : "FALSE"));
  7632. DBUG_PRINT("info",("spider (select_lex->options & OPTION_FOUND_ROWS)=%s",
  7633. (select_lex->options & OPTION_FOUND_ROWS) ? "TRUE" : "FALSE"));
  7634. #ifdef HANDLER_HAS_DIRECT_AGGREGATE
  7635. DBUG_PRINT("info",("spider direct_aggregate=%s",
  7636. spider->result_list.direct_aggregate ? "TRUE" : "FALSE"));
  7637. #endif
  7638. DBUG_PRINT("info",("spider select_lex->group_list.elements=%u",
  7639. select_lex->group_list.elements));
  7640. DBUG_PRINT("info",("spider select_lex->with_sum_func=%s",
  7641. select_lex->with_sum_func ? "TRUE" : "FALSE"));
  7642. DBUG_PRINT("info",("spider select_lex->having=%s",
  7643. select_lex->having ? "TRUE" : "FALSE"));
  7644. DBUG_PRINT("info",("spider select_lex->order_list.elements=%u",
  7645. select_lex->order_list.elements));
  7646. if (
  7647. !first_check ||
  7648. !select_lex->explicit_limit ||
  7649. (select_lex->options & OPTION_FOUND_ROWS) ||
  7650. (
  7651. #ifdef HANDLER_HAS_DIRECT_AGGREGATE
  7652. !spider->result_list.direct_aggregate &&
  7653. #endif
  7654. (
  7655. select_lex->group_list.elements ||
  7656. select_lex->with_sum_func
  7657. )
  7658. ) ||
  7659. select_lex->having ||
  7660. !select_lex->order_list.elements ||
  7661. select_limit > direct_order_limit - offset_limit
  7662. ) {
  7663. DBUG_PRINT("info",("spider FALSE by select_lex"));
  7664. DBUG_RETURN(FALSE);
  7665. }
  7666. ORDER *order;
  7667. for (order = (ORDER *) select_lex->order_list.first; order;
  7668. order = order->next)
  7669. {
  7670. if (spider->print_item_type((*order->item), NULL, NULL, 0))
  7671. {
  7672. DBUG_PRINT("info",("spider FALSE by order"));
  7673. DBUG_RETURN(FALSE);
  7674. }
  7675. }
  7676. DBUG_PRINT("info",("spider TRUE"));
  7677. spider->result_list.internal_limit = select_limit + offset_limit;
  7678. spider->result_list.split_read = select_limit + offset_limit;
  7679. spider->trx->direct_order_limit_count++;
  7680. DBUG_RETURN(TRUE);
  7681. }
  7682. }
  7683. DBUG_PRINT("info",("spider FALSE by parameter"));
  7684. DBUG_RETURN(FALSE);
  7685. }
  7686. int spider_compare_for_sort(
  7687. SPIDER_SORT *a,
  7688. SPIDER_SORT *b
  7689. ) {
  7690. DBUG_ENTER("spider_compare_for_sort");
  7691. if (a->sort > b->sort)
  7692. DBUG_RETURN(-1);
  7693. if (a->sort < b->sort)
  7694. DBUG_RETURN(1);
  7695. DBUG_RETURN(0);
  7696. }
  7697. ulong spider_calc_for_sort(
  7698. uint count,
  7699. ...
  7700. ) {
  7701. ulong sort = 0;
  7702. va_list args;
  7703. va_start(args, count);
  7704. DBUG_ENTER("spider_calc_for_sort");
  7705. while (count--)
  7706. {
  7707. char *start = va_arg(args, char *), *str;
  7708. uint wild_pos = 0;
  7709. if ((str = start))
  7710. {
  7711. wild_pos = 128;
  7712. for (; *str; str++)
  7713. {
  7714. if (*str == spider_wild_prefix && str[1])
  7715. str++;
  7716. else if (*str == spider_wild_many || *str == spider_wild_one)
  7717. {
  7718. wild_pos = (uint) (str - start) + 1;
  7719. if (wild_pos > 127)
  7720. wild_pos = 127;
  7721. break;
  7722. }
  7723. }
  7724. }
  7725. sort = (sort << 8) + wild_pos;
  7726. }
  7727. va_end(args);
  7728. DBUG_RETURN(sort);
  7729. }
  7730. double spider_rand(
  7731. uint32 rand_source
  7732. ) {
  7733. #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
  7734. struct my_rnd_struct rand;
  7735. #else
  7736. struct rand_struct rand;
  7737. #endif
  7738. DBUG_ENTER("spider_rand");
  7739. /* generate same as rand function for applications */
  7740. #if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000
  7741. my_rnd_init(&rand, (uint32) (rand_source * 65537L + 55555555L),
  7742. (uint32) (rand_source * 268435457L));
  7743. #else
  7744. randominit(&rand, (uint32) (rand_source * 65537L + 55555555L),
  7745. (uint32) (rand_source * 268435457L));
  7746. #endif
  7747. DBUG_RETURN(my_rnd(&rand));
  7748. }
  7749. #ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE
  7750. int spider_discover_table_structure_internal(
  7751. SPIDER_TRX *trx,
  7752. SPIDER_SHARE *spider_share,
  7753. spider_string *str
  7754. ) {
  7755. int error_num = 0, roop_count;
  7756. DBUG_ENTER("spider_discover_table_structure_internal");
  7757. for (roop_count = 0; roop_count < SPIDER_DBTON_SIZE; roop_count++)
  7758. {
  7759. if (spider_bit_is_set(spider_share->dbton_bitmap, roop_count))
  7760. {
  7761. if ((error_num = spider_share->dbton_share[roop_count]->
  7762. discover_table_structure(trx, spider_share, str)))
  7763. {
  7764. continue;
  7765. }
  7766. break;
  7767. }
  7768. }
  7769. DBUG_RETURN(error_num);
  7770. }
  7771. int spider_discover_table_structure(
  7772. handlerton *hton,
  7773. THD* thd,
  7774. TABLE_SHARE *share,
  7775. HA_CREATE_INFO *info
  7776. ) {
  7777. int error_num = HA_ERR_WRONG_COMMAND;
  7778. SPIDER_SHARE *spider_share;
  7779. const char *table_name = share->path.str;
  7780. uint table_name_length = (uint) strlen(table_name);
  7781. SPIDER_TRX *trx;
  7782. #ifdef WITH_PARTITION_STORAGE_ENGINE
  7783. partition_info *part_info = thd->work_part_info;
  7784. #endif
  7785. uint str_len;
  7786. char buf[MAX_FIELD_WIDTH];
  7787. spider_string str(buf, sizeof(buf), system_charset_info);
  7788. DBUG_ENTER("spider_discover_table_structure");
  7789. str.init_calc_mem(229);
  7790. str.length(0);
  7791. if (str.reserve(
  7792. SPIDER_SQL_CREATE_TABLE_LEN + share->db.length +
  7793. SPIDER_SQL_DOT_LEN + share->table_name.length +
  7794. /* SPIDER_SQL_LCL_NAME_QUOTE_LEN */ 4 + SPIDER_SQL_OPEN_PAREN_LEN
  7795. )) {
  7796. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  7797. }
  7798. str.q_append(SPIDER_SQL_CREATE_TABLE_STR, SPIDER_SQL_CREATE_TABLE_LEN);
  7799. str.q_append(SPIDER_SQL_LCL_NAME_QUOTE_STR, SPIDER_SQL_LCL_NAME_QUOTE_LEN);
  7800. str.q_append(share->db.str, share->db.length);
  7801. str.q_append(SPIDER_SQL_LCL_NAME_QUOTE_STR, SPIDER_SQL_LCL_NAME_QUOTE_LEN);
  7802. str.q_append(SPIDER_SQL_DOT_STR, SPIDER_SQL_DOT_LEN);
  7803. str.q_append(SPIDER_SQL_LCL_NAME_QUOTE_STR, SPIDER_SQL_LCL_NAME_QUOTE_LEN);
  7804. str.q_append(share->table_name.str, share->table_name.length);
  7805. str.q_append(SPIDER_SQL_LCL_NAME_QUOTE_STR, SPIDER_SQL_LCL_NAME_QUOTE_LEN);
  7806. str.q_append(SPIDER_SQL_OPEN_PAREN_STR, SPIDER_SQL_OPEN_PAREN_LEN);
  7807. str_len = str.length();
  7808. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  7809. my_hash_value_type hash_value = my_calc_hash(&spider_open_tables,
  7810. (uchar*) table_name, table_name_length);
  7811. #endif
  7812. if (!(trx = spider_get_trx(thd, TRUE, &error_num)))
  7813. {
  7814. DBUG_PRINT("info",("spider spider_get_trx error"));
  7815. my_error(error_num, MYF(0));
  7816. DBUG_RETURN(error_num);
  7817. }
  7818. share->table_charset = info->default_table_charset;
  7819. share->comment = info->comment;
  7820. #ifdef WITH_PARTITION_STORAGE_ENGINE
  7821. if (!part_info)
  7822. {
  7823. #endif
  7824. if (!(spider_share = spider_create_share(table_name, share,
  7825. #ifdef WITH_PARTITION_STORAGE_ENGINE
  7826. NULL,
  7827. #endif
  7828. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  7829. hash_value,
  7830. #endif
  7831. &error_num
  7832. ))) {
  7833. DBUG_RETURN(error_num);
  7834. }
  7835. error_num = spider_discover_table_structure_internal(trx, spider_share, &str);
  7836. if (!error_num)
  7837. {
  7838. Open_tables_backup open_tables_backup;
  7839. TABLE *table_tables;
  7840. if (
  7841. (table_tables = spider_open_sys_table(
  7842. thd, SPIDER_SYS_TABLES_TABLE_NAME_STR,
  7843. SPIDER_SYS_TABLES_TABLE_NAME_LEN, TRUE, &open_tables_backup, FALSE,
  7844. &error_num))
  7845. ) {
  7846. error_num = spider_insert_tables(table_tables, spider_share);
  7847. spider_close_sys_table(thd, table_tables,
  7848. &open_tables_backup, FALSE);
  7849. }
  7850. }
  7851. spider_free_share_resource_only(spider_share);
  7852. #ifdef WITH_PARTITION_STORAGE_ENGINE
  7853. } else {
  7854. char tmp_name[FN_LEN];
  7855. List_iterator<partition_element> part_it(part_info->partitions);
  7856. partition_element *part_elem, *sub_elem;
  7857. while ((part_elem = part_it++))
  7858. {
  7859. if ((part_elem)->subpartitions.elements)
  7860. {
  7861. List_iterator<partition_element> sub_it((part_elem)->subpartitions);
  7862. while ((sub_elem = sub_it++))
  7863. {
  7864. str.length(str_len);
  7865. create_subpartition_name(tmp_name, table_name,
  7866. (part_elem)->partition_name, (sub_elem)->partition_name,
  7867. NORMAL_PART_NAME);
  7868. DBUG_PRINT("info",("spider tmp_name=%s", tmp_name));
  7869. if (!(spider_share = spider_create_share(table_name, share,
  7870. part_info,
  7871. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  7872. hash_value,
  7873. #endif
  7874. &error_num
  7875. ))) {
  7876. continue;
  7877. }
  7878. error_num = spider_discover_table_structure_internal(
  7879. trx, spider_share, &str);
  7880. spider_free_share_resource_only(spider_share);
  7881. if (!error_num)
  7882. break;
  7883. }
  7884. if (!error_num)
  7885. break;
  7886. } else {
  7887. str.length(str_len);
  7888. create_partition_name(tmp_name, table_name,
  7889. (part_elem)->partition_name, NORMAL_PART_NAME, TRUE);
  7890. DBUG_PRINT("info",("spider tmp_name=%s", tmp_name));
  7891. if (!(spider_share = spider_create_share(table_name, share,
  7892. part_info,
  7893. #ifdef SPIDER_HAS_HASH_VALUE_TYPE
  7894. hash_value,
  7895. #endif
  7896. &error_num
  7897. ))) {
  7898. continue;
  7899. }
  7900. error_num = spider_discover_table_structure_internal(
  7901. trx, spider_share, &str);
  7902. spider_free_share_resource_only(spider_share);
  7903. if (!error_num)
  7904. break;
  7905. }
  7906. }
  7907. }
  7908. #endif
  7909. if (!error_num)
  7910. thd->clear_error();
  7911. else
  7912. DBUG_RETURN(error_num);
  7913. str.length(str.length() - SPIDER_SQL_COMMA_LEN);
  7914. CHARSET_INFO *table_charset;
  7915. if (share->table_charset)
  7916. {
  7917. table_charset = share->table_charset;
  7918. } else {
  7919. table_charset = system_charset_info;
  7920. }
  7921. uint csnamelen = strlen(table_charset->csname);
  7922. uint collatelen = strlen(table_charset->name);
  7923. if (str.reserve(SPIDER_SQL_CLOSE_PAREN_LEN + SPIDER_SQL_DEFAULT_CHARSET_LEN +
  7924. csnamelen + SPIDER_SQL_COLLATE_LEN + collatelen +
  7925. SPIDER_SQL_CONNECTION_LEN + SPIDER_SQL_VALUE_QUOTE_LEN
  7926. )) {
  7927. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  7928. }
  7929. str.q_append(SPIDER_SQL_CLOSE_PAREN_STR, SPIDER_SQL_CLOSE_PAREN_LEN);
  7930. str.q_append(SPIDER_SQL_DEFAULT_CHARSET_STR, SPIDER_SQL_DEFAULT_CHARSET_LEN);
  7931. str.q_append(table_charset->csname, csnamelen);
  7932. str.q_append(SPIDER_SQL_COLLATE_STR, SPIDER_SQL_COLLATE_LEN);
  7933. str.q_append(table_charset->name, collatelen);
  7934. str.q_append(SPIDER_SQL_COMMENT_STR, SPIDER_SQL_COMMENT_LEN);
  7935. str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
  7936. if (str.append_for_single_quote(share->comment.str, share->comment.length))
  7937. {
  7938. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  7939. }
  7940. if (str.reserve(SPIDER_SQL_CONNECTION_LEN +
  7941. (SPIDER_SQL_VALUE_QUOTE_LEN * 2)))
  7942. {
  7943. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  7944. }
  7945. str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
  7946. str.q_append(SPIDER_SQL_CONNECTION_STR, SPIDER_SQL_CONNECTION_LEN);
  7947. str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
  7948. if (str.append_for_single_quote(share->connect_string.str,
  7949. share->connect_string.length))
  7950. {
  7951. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  7952. }
  7953. if (str.reserve(SPIDER_SQL_VALUE_QUOTE_LEN))
  7954. {
  7955. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  7956. }
  7957. str.q_append(SPIDER_SQL_VALUE_QUOTE_STR, SPIDER_SQL_VALUE_QUOTE_LEN);
  7958. #ifdef WITH_PARTITION_STORAGE_ENGINE
  7959. DBUG_PRINT("info",("spider part_info=%p", part_info));
  7960. if (part_info)
  7961. {
  7962. uint part_syntax_len;
  7963. char *part_syntax;
  7964. List_iterator<partition_element> part_it(part_info->partitions);
  7965. partition_element *part_elem, *sub_elem;
  7966. while ((part_elem = part_it++))
  7967. {
  7968. part_elem->engine_type = hton;
  7969. if ((part_elem)->subpartitions.elements)
  7970. {
  7971. List_iterator<partition_element> sub_it((part_elem)->subpartitions);
  7972. while ((sub_elem = sub_it++))
  7973. {
  7974. sub_elem->engine_type = hton;
  7975. }
  7976. }
  7977. }
  7978. if (part_info->fix_parser_data(thd))
  7979. {
  7980. DBUG_RETURN(ER_SPIDER_UNKNOWN_NUM);
  7981. }
  7982. #ifdef SPIDER_HAS_DISCOVER_TABLE_STRUCTURE_COMMENT
  7983. if (!(part_syntax = generate_partition_syntax(part_info, &part_syntax_len,
  7984. FALSE, TRUE, info, NULL, NULL)))
  7985. #else
  7986. if (!(part_syntax = generate_partition_syntax(part_info, &part_syntax_len,
  7987. FALSE, TRUE, info, NULL)))
  7988. #endif
  7989. {
  7990. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  7991. }
  7992. if (str.reserve(part_syntax_len))
  7993. {
  7994. DBUG_RETURN(HA_ERR_OUT_OF_MEM);
  7995. }
  7996. str.q_append(part_syntax, part_syntax_len);
  7997. my_free(part_syntax, MYF(0));
  7998. }
  7999. #endif
  8000. DBUG_PRINT("info",("spider str=%s", str.c_ptr_safe()));
  8001. error_num = share->init_from_sql_statement_string(thd, TRUE, str.ptr(),
  8002. str.length());
  8003. DBUG_RETURN(error_num);
  8004. }
  8005. #endif