1 /* Copyright (C) 2008-2018 Kentoku Shiba 2 3 This program is free software; you can redistribute it and/or modify 4 it under the terms of the GNU General Public License as published by 5 the Free Software Foundation; version 2 of the License. 6 7 This program is distributed in the hope that it will be useful, 8 but WITHOUT ANY WARRANTY; without even the implied warranty of 9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 GNU General Public License for more details. 11 12 You should have received a copy of the GNU General Public License 13 along with this program; if not, write to the Free Software 14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ 15 16 #define SPIDER_LOCK_MODE_NO_LOCK 0 17 #define SPIDER_LOCK_MODE_SHARED 1 18 #define SPIDER_LOCK_MODE_EXCLUSIVE 2 19 20 #define SPIDER_BG_SIMPLE_NO_ACTION 0 21 #define SPIDER_BG_SIMPLE_CONNECT 1 22 #define SPIDER_BG_SIMPLE_DISCONNECT 2 23 #define SPIDER_BG_SIMPLE_RECORDS 3 24 25 uchar *spider_conn_get_key( 26 SPIDER_CONN *conn, 27 size_t *length, 28 my_bool not_used __attribute__ ((unused)) 29 ); 30 31 uchar *spider_ipport_conn_get_key( 32 SPIDER_IP_PORT_CONN *ip_port, 33 size_t *length, 34 my_bool not_used __attribute__ ((unused)) 35 ); 36 37 int spider_reset_conn_setted_parameter( 38 SPIDER_CONN *conn, 39 THD *thd 40 ); 41 42 int spider_free_conn_alloc( 43 SPIDER_CONN *conn 44 ); 45 46 void spider_free_conn_from_trx( 47 SPIDER_TRX *trx, 48 SPIDER_CONN *conn, 49 bool another, 50 bool trx_free, 51 int *roop_count 52 ); 53 54 SPIDER_CONN *spider_create_conn( 55 SPIDER_SHARE *share, 56 ha_spider *spider, 57 int link_id, 58 int base_link_id, 59 uint conn_kind, 60 int *error_num 61 ); 62 63 SPIDER_CONN *spider_get_conn( 64 SPIDER_SHARE *share, 65 int link_idx, 66 char *conn_key, 67 SPIDER_TRX *trx, 68 ha_spider *spider, 69 bool another, 70 bool thd_chg, 71 uint conn_kind, 72 int *error_num 73 ); 74 75 int spider_free_conn( 76 SPIDER_CONN *conn 77 ); 78 79 int spider_check_and_get_casual_read_conn( 80 THD *thd, 81 ha_spider *spider, 82 int link_idx 83 ); 84 85 int spider_check_and_init_casual_read( 86 THD *thd, 87 ha_spider *spider, 88 int link_idx 89 ); 90 91 void spider_conn_queue_connect( 92 SPIDER_SHARE *share, 93 SPIDER_CONN *conn, 94 int link_idx 95 ); 96 97 void spider_conn_queue_connect_rewrite( 98 SPIDER_SHARE *share, 99 SPIDER_CONN *conn, 100 int link_idx 101 ); 102 103 void spider_conn_queue_ping( 104 ha_spider *spider, 105 SPIDER_CONN *conn, 106 int link_idx 107 ); 108 109 void spider_conn_queue_ping_rewrite( 110 ha_spider *spider, 111 SPIDER_CONN *conn, 112 int link_idx 113 ); 114 115 void spider_conn_queue_trx_isolation( 116 SPIDER_CONN *conn, 117 int trx_isolation 118 ); 119 120 void spider_conn_queue_semi_trx_isolation( 121 SPIDER_CONN *conn, 122 int trx_isolation 123 ); 124 125 void spider_conn_queue_autocommit( 126 SPIDER_CONN *conn, 127 bool autocommit 128 ); 129 130 void spider_conn_queue_sql_log_off( 131 SPIDER_CONN *conn, 132 bool sql_log_off 133 ); 134 135 void spider_conn_queue_time_zone( 136 SPIDER_CONN *conn, 137 Time_zone *time_zone 138 ); 139 140 void spider_conn_queue_UTC_time_zone( 141 SPIDER_CONN *conn 142 ); 143 144 void spider_conn_queue_start_transaction( 145 SPIDER_CONN *conn 146 ); 147 148 void spider_conn_queue_xa_start( 149 SPIDER_CONN *conn, 150 XID *xid 151 ); 152 153 void spider_conn_clear_queue( 154 SPIDER_CONN *conn 155 ); 156 157 void spider_conn_clear_queue_at_commit( 158 SPIDER_CONN *conn 159 ); 160 161 void spider_conn_set_timeout( 162 SPIDER_CONN *conn, 163 uint net_read_timeout, 164 uint net_write_timeout 165 ); 166 167 void spider_conn_set_timeout_from_share( 168 SPIDER_CONN *conn, 169 int link_idx, 170 THD *thd, 171 SPIDER_SHARE *share 172 ); 173 174 void spider_conn_set_timeout_from_direct_sql( 175 SPIDER_CONN *conn, 176 THD *thd, 177 SPIDER_DIRECT_SQL *direct_sql 178 ); 179 180 void spider_tree_insert( 181 SPIDER_CONN *top, 182 SPIDER_CONN *conn 183 ); 184 185 SPIDER_CONN *spider_tree_first( 186 SPIDER_CONN *top 187 ); 188 189 SPIDER_CONN *spider_tree_last( 190 SPIDER_CONN *top 191 ); 192 193 SPIDER_CONN *spider_tree_next( 194 SPIDER_CONN *current 195 ); 196 197 SPIDER_CONN *spider_tree_delete( 198 SPIDER_CONN *conn, 199 SPIDER_CONN *top 200 ); 201 202 #ifndef WITHOUT_SPIDER_BG_SEARCH 203 int spider_set_conn_bg_param( 204 ha_spider *spider 205 ); 206 207 int spider_create_conn_thread( 208 SPIDER_CONN *conn 209 ); 210 211 void spider_free_conn_thread( 212 SPIDER_CONN *conn 213 ); 214 215 void spider_bg_conn_wait( 216 SPIDER_CONN *conn 217 ); 218 219 void spider_bg_all_conn_wait( 220 ha_spider *spider 221 ); 222 223 int spider_bg_all_conn_pre_next( 224 ha_spider *spider, 225 int link_idx 226 ); 227 228 void spider_bg_conn_break( 229 SPIDER_CONN *conn, 230 ha_spider *spider 231 ); 232 233 void spider_bg_all_conn_break( 234 ha_spider *spider 235 ); 236 237 bool spider_bg_conn_get_job( 238 SPIDER_CONN *conn 239 ); 240 241 int spider_bg_conn_search( 242 ha_spider *spider, 243 int link_idx, 244 int first_link_idx, 245 bool first, 246 bool pre_next, 247 bool discard_result 248 ); 249 250 void spider_bg_conn_simple_action( 251 SPIDER_CONN *conn, 252 uint simple_action, 253 bool caller_wait, 254 void *target, 255 uint link_idx, 256 int *error_num 257 ); 258 259 void *spider_bg_conn_action( 260 void *arg 261 ); 262 263 int spider_create_sts_thread( 264 SPIDER_SHARE *share 265 ); 266 267 void spider_free_sts_thread( 268 SPIDER_SHARE *share 269 ); 270 271 void *spider_bg_sts_action( 272 void *arg 273 ); 274 275 int spider_create_crd_thread( 276 SPIDER_SHARE *share 277 ); 278 279 void spider_free_crd_thread( 280 SPIDER_SHARE *share 281 ); 282 283 void *spider_bg_crd_action( 284 void *arg 285 ); 286 287 int spider_create_mon_threads( 288 SPIDER_TRX *trx, 289 SPIDER_SHARE *share 290 ); 291 292 void spider_free_mon_threads( 293 SPIDER_SHARE *share 294 ); 295 296 void *spider_bg_mon_action( 297 void *arg 298 ); 299 #endif 300 301 int spider_conn_first_link_idx( 302 THD *thd, 303 long *link_statuses, 304 long *access_balances, 305 uint *conn_link_idx, 306 int link_count, 307 int link_status 308 ); 309 310 int spider_conn_next_link_idx( 311 THD *thd, 312 long *link_statuses, 313 long *access_balances, 314 uint *conn_link_idx, 315 int link_idx, 316 int link_count, 317 int link_status 318 ); 319 320 int spider_conn_link_idx_next( 321 long *link_statuses, 322 uint *conn_link_idx, 323 int link_idx, 324 int link_count, 325 int link_status 326 ); 327 328 int spider_conn_get_link_status( 329 long *link_statuses, 330 uint *conn_link_idx, 331 int link_idx 332 ); 333 334 int spider_conn_lock_mode( 335 ha_spider *spider 336 ); 337 338 bool spider_conn_check_recovery_link( 339 SPIDER_SHARE *share 340 ); 341 342 bool spider_conn_use_handler( 343 ha_spider *spider, 344 int lock_mode, 345 int link_idx 346 ); 347 348 bool spider_conn_need_open_handler( 349 ha_spider *spider, 350 uint idx, 351 int link_idx 352 ); 353 354 SPIDER_IP_PORT_CONN *spider_create_ipport_conn(SPIDER_CONN *conn); 355 SPIDER_CONN* spider_get_conn_from_idle_connection 356 ( 357 SPIDER_SHARE *share, 358 int link_idx, 359 char *conn_key, 360 ha_spider *spider, 361 uint conn_kind, 362 int base_link_idx, 363 int *error_num 364 ); 365 void spider_free_ipport_conn(void *info); 366