Commit e954d9de authored by Kentoku SHIBA's avatar Kentoku SHIBA

MDEV-19002 Spider performance optimization with partition

Change the following function for batch call instead of each partition
- store_lock
- external_lock
- start_stmt
- extra
- cond_push
- info_push
- top_table
parent 8e6e5ace
...@@ -473,6 +473,10 @@ class ha_partition :public handler ...@@ -473,6 +473,10 @@ class ha_partition :public handler
{ {
return m_file; return m_file;
} }
ha_partition *get_clone_source()
{
return m_is_clone_of;
}
virtual part_id_range *get_part_spec() virtual part_id_range *get_part_spec()
{ {
return &m_part_spec; return &m_part_spec;
......
This diff is collapsed.
...@@ -52,9 +52,7 @@ struct st_spider_ft_info ...@@ -52,9 +52,7 @@ struct st_spider_ft_info
class ha_spider: public handler class ha_spider: public handler
{ {
public: public:
THR_LOCK_DATA lock;
SPIDER_SHARE *share; SPIDER_SHARE *share;
SPIDER_TRX *trx;
ulonglong spider_thread_id; ulonglong spider_thread_id;
ulonglong trx_conn_adjustment; ulonglong trx_conn_adjustment;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
...@@ -90,18 +88,16 @@ class ha_spider: public handler ...@@ -90,18 +88,16 @@ class ha_spider: public handler
int search_link_idx; int search_link_idx;
int result_link_idx; int result_link_idx;
SPIDER_RESULT_LIST result_list; SPIDER_RESULT_LIST result_list;
SPIDER_CONDITION *condition;
spider_string *blob_buff; spider_string *blob_buff;
uchar *searched_bitmap;
uchar *ft_discard_bitmap;
bool position_bitmap_init;
uchar *position_bitmap;
SPIDER_POSITION *pushed_pos; SPIDER_POSITION *pushed_pos;
SPIDER_POSITION pushed_pos_buf; SPIDER_POSITION pushed_pos_buf;
#ifdef WITH_PARTITION_STORAGE_ENGINE #ifdef WITH_PARTITION_STORAGE_ENGINE
bool pt_handler_share_owner = FALSE;
SPIDER_PARTITION_HANDLER_SHARE *partition_handler_share; SPIDER_PARTITION_HANDLER_SHARE *partition_handler_share;
ha_spider *pt_handler_share_creator;
#endif #endif
bool wide_handler_owner = FALSE;
SPIDER_WIDE_HANDLER *wide_handler = NULL;
#ifdef HA_CAN_BULK_ACCESS #ifdef HA_CAN_BULK_ACCESS
int pre_direct_init_result; int pre_direct_init_result;
bool is_bulk_access_clone; bool is_bulk_access_clone;
...@@ -116,10 +112,8 @@ class ha_spider: public handler ...@@ -116,10 +112,8 @@ class ha_spider: public handler
bool init_ha_mem_root; bool init_ha_mem_root;
MEM_ROOT ha_mem_root; MEM_ROOT ha_mem_root;
*/ */
ulonglong external_lock_cnt;
#endif #endif
bool is_clone; bool is_clone;
bool clone_bitmap_init;
ha_spider *pt_clone_source_handler; ha_spider *pt_clone_source_handler;
ha_spider *pt_clone_last_searcher; ha_spider *pt_clone_last_searcher;
bool use_index_merge; bool use_index_merge;
...@@ -161,22 +155,11 @@ class ha_spider: public handler ...@@ -161,22 +155,11 @@ class ha_spider: public handler
ha_spider *next; ha_spider *next;
bool dml_inited;
bool rnd_scan_and_first; bool rnd_scan_and_first;
bool quick_mode;
bool keyread;
bool ignore_dup_key;
bool write_can_replace;
bool insert_with_update;
bool low_priority;
bool high_priority;
bool insert_delayed;
bool use_pre_call; bool use_pre_call;
bool use_pre_action; bool use_pre_action;
bool pre_bitmap_checked; bool pre_bitmap_checked;
enum thr_lock_type lock_type;
int lock_mode;
uint sql_command;
int selupd_lock_mode;
bool bulk_insert; bool bulk_insert;
#ifdef HANDLER_HAS_NEED_INFO_FOR_AUTO_INC #ifdef HANDLER_HAS_NEED_INFO_FOR_AUTO_INC
bool info_auto_called; bool info_auto_called;
...@@ -189,12 +172,9 @@ class ha_spider: public handler ...@@ -189,12 +172,9 @@ class ha_spider: public handler
int store_error_num; int store_error_num;
uint dup_key_idx; uint dup_key_idx;
int select_column_mode; int select_column_mode;
bool update_request;
bool pk_update; bool pk_update;
bool force_auto_increment; bool force_auto_increment;
int bka_mode; int bka_mode;
bool cond_check;
int cond_check_error;
int error_mode; int error_mode;
ulonglong store_last_insert_id; ulonglong store_last_insert_id;
...@@ -216,14 +196,7 @@ class ha_spider: public handler ...@@ -216,14 +196,7 @@ class ha_spider: public handler
uint32 **hs_w_ret_fields; uint32 **hs_w_ret_fields;
size_t *hs_r_ret_fields_num; size_t *hs_r_ret_fields_num;
size_t *hs_w_ret_fields_num; size_t *hs_w_ret_fields_num;
uint32 *hs_pushed_ret_fields;
size_t hs_pushed_ret_fields_num;
size_t hs_pushed_ret_fields_size;
size_t hs_pushed_lcl_fields_num;
uchar *tmp_column_bitmap; uchar *tmp_column_bitmap;
bool hs_increment;
bool hs_decrement;
uint32 hs_pushed_strref_num;
#endif #endif
#endif #endif
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS #ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
...@@ -232,11 +205,6 @@ class ha_spider: public handler ...@@ -232,11 +205,6 @@ class ha_spider: public handler
bool maybe_do_hs_direct_update; bool maybe_do_hs_direct_update;
#endif #endif
uint direct_update_kinds; uint direct_update_kinds;
List<Item> *direct_update_fields;
List<Item> *direct_update_values;
#endif
#ifdef INFO_KIND_FORCE_LIMIT_BEGIN
longlong info_limit;
#endif #endif
spider_index_rnd_init prev_index_rnd_init; spider_index_rnd_init prev_index_rnd_init;
#ifdef HANDLER_HAS_DIRECT_AGGREGATE #ifdef HANDLER_HAS_DIRECT_AGGREGATE
...@@ -283,10 +251,13 @@ class ha_spider: public handler ...@@ -283,10 +251,13 @@ class ha_spider: public handler
uint test_if_locked uint test_if_locked
); );
int close(); int close();
int check_access_kind( int check_access_kind_for_connection(
THD *thd, THD *thd,
bool write_request bool write_request
); );
void check_access_kind(
THD *thd
);
#ifdef HA_CAN_BULK_ACCESS #ifdef HA_CAN_BULK_ACCESS
int additional_lock( int additional_lock(
THD *thd, THD *thd,
...@@ -302,6 +273,10 @@ class ha_spider: public handler ...@@ -302,6 +273,10 @@ class ha_spider: public handler
THD *thd, THD *thd,
int lock_type int lock_type
); );
int start_stmt(
THD *thd,
thr_lock_type lock_type
);
int reset(); int reset();
int extra( int extra(
enum ha_extra_function operation enum ha_extra_function operation
...@@ -525,6 +500,7 @@ class ha_spider: public handler ...@@ -525,6 +500,7 @@ class ha_spider: public handler
#endif #endif
const char *table_type() const; const char *table_type() const;
ulonglong table_flags() const; ulonglong table_flags() const;
ulong table_flags_for_partition();
const char *index_type( const char *index_type(
uint key_number uint key_number
); );
...@@ -869,6 +845,12 @@ class ha_spider: public handler ...@@ -869,6 +845,12 @@ class ha_spider: public handler
int error_num, int error_num,
uint flags uint flags
); );
int set_top_table_and_fields(
TABLE *top_table,
Field **top_table_field,
uint top_table_fields
);
void clear_top_table_fields();
Field *get_top_table_field( Field *get_top_table_field(
uint16 field_index uint16 field_index
); );
...@@ -1255,4 +1237,15 @@ class ha_spider: public handler ...@@ -1255,4 +1237,15 @@ class ha_spider: public handler
#endif #endif
int init_union_table_name_pos_sql(); int init_union_table_name_pos_sql();
int set_union_table_name_pos_sql(); int set_union_table_name_pos_sql();
int lock_tables();
int dml_init();
#ifdef HA_CAN_BULK_ACCESS
int bulk_access_begin(
void *info
);
int bulk_access_current(
void *info
);
void bulk_access_end();
#endif
}; };
--connection master_1
set session spider_direct_dup_insert= @old_spider_direct_dup_insert;
--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP
--let $MASTER_1_COMMENT_2_1_2= $MASTER_1_COMMENT_2_1_2_BACKUP
--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP
--let $CHILD2_1_DROP_TABLES2= $CHILD2_1_DROP_TABLES2_BACKUP
--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP
--let $CHILD2_1_CREATE_TABLES2= $CHILD2_1_CREATE_TABLES2_BACKUP
--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP
--disable_warnings
--disable_query_log
--disable_result_log
--source ../t/test_deinit.inc
--enable_result_log
--enable_query_log
--enable_warnings
--disable_warnings
--disable_query_log
--disable_result_log
--source ../t/test_init.inc
--enable_result_log
--enable_query_log
--enable_warnings
--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1
let $MASTER_1_COMMENT_2_1=
COMMENT='table "tbl_a", srv "s_2_1"';
--let $MASTER_1_COMMENT_2_1_2_BACKUP= $MASTER_1_COMMENT_2_1_2
let $MASTER_1_COMMENT_2_1_2=
COMMENT='table "tbl_b", srv "s_2_1"';
--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES
let $CHILD2_1_DROP_TABLES=
DROP TABLE IF EXISTS tbl_a;
--let $CHILD2_1_DROP_TABLES2_BACKUP= $CHILD2_1_DROP_TABLES2
let $CHILD2_1_DROP_TABLES2=
DROP TABLE IF EXISTS tbl_b;
--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES
let $CHILD2_1_CREATE_TABLES=
CREATE TABLE tbl_a (
skey int NOT NULL,
dt date NOT NULL,
tm time NOT NULL,
KEY idx1 (skey,dt,tm)
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
--let $CHILD2_1_CREATE_TABLES2_BACKUP= $CHILD2_1_CREATE_TABLES2
let $CHILD2_1_CREATE_TABLES2=
CREATE TABLE tbl_b (
pkey int NOT NULL,
dt datetime NOT NULL,
PRIMARY KEY (pkey),
KEY idx1 (dt)
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES
let $CHILD2_1_SELECT_TABLES=
SELECT pkey, dt FROM tbl_b ORDER BY pkey;
let $CHILD2_1_SELECT_ARGUMENT1=
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
--connection master_1
set @old_spider_direct_dup_insert= @@spider_direct_dup_insert;
set session spider_direct_dup_insert= 1;
!include include/default_mysqld.cnf
!include ../my_1_1.cnf
!include ../my_2_1.cnf
--source ../include/insert_select_init.inc
--echo
--echo this test is for MDEV-16399
--echo
--echo drop and create databases
--connection master_1
--disable_warnings
CREATE DATABASE auto_test_local;
USE auto_test_local;
--connection child2_1
SET @old_log_output = @@global.log_output;
SET GLOBAL log_output = 'TABLE,FILE';
CREATE DATABASE auto_test_remote;
USE auto_test_remote;
--enable_warnings
--echo
--echo create table and insert
--connection child2_1
--disable_query_log
echo CHILD2_1_CREATE_TABLES;
eval $CHILD2_1_CREATE_TABLES;
echo CHILD2_1_CREATE_TABLES2;
eval $CHILD2_1_CREATE_TABLES2;
--enable_query_log
TRUNCATE TABLE mysql.general_log;
--connection master_1
--disable_query_log
echo CREATE TABLE tbl_a (
skey int NOT NULL,
dt date NOT NULL,
tm time NOT NULL,
KEY idx1 (skey,dt,tm)
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1;
eval CREATE TABLE tbl_a (
skey int NOT NULL,
dt date NOT NULL,
tm time NOT NULL,
KEY idx1 (skey,dt,tm)
) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1;
echo CREATE TABLE tbl_b (
pkey int NOT NULL,
dt datetime NOT NULL,
PRIMARY KEY (pkey),
KEY idx1 (dt)
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1_2;
eval CREATE TABLE tbl_b (
pkey int NOT NULL,
dt datetime NOT NULL,
PRIMARY KEY (pkey),
KEY idx1 (dt)
) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1_2;
--enable_query_log
INSERT INTO tbl_a (skey, dt, tm) VALUES (0, '2012-01-01', '12:00:00'),(1, '2012-02-01', '12:00:00'),(2, '2012-03-01', '12:00:00'),(3, '2012-04-01', '12:00:00'),(4, '2012-05-01', '12:00:00'),(5, '2012-06-01', '12:00:00'),(6, '2012-07-01', '12:00:00'),(7, '2012-08-01', '12:00:00'),(8, '2012-09-01', '12:00:00'),(9, '2012-10-01', '12:00:00');
INSERT INTO tbl_a (skey, dt, tm) VALUES (0, '2013-01-01', '13:00:00'),(1, '2013-02-01', '13:00:00'),(2, '2013-03-01', '13:00:00'),(3, '2013-04-01', '13:00:00'),(4, '2013-05-01', '13:00:00'),(5, '2013-06-01', '13:00:00'),(6, '2013-07-01', '13:00:00'),(7, '2013-08-01', '13:00:00'),(8, '2013-09-01', '13:00:00'),(9, '2013-10-01', '13:00:00');
INSERT INTO tbl_a (skey, dt, tm) VALUES (0, '2012-11-01', '11:00:00'),(1, '2012-12-01', '11:00:00'),(2, '2012-11-30', '11:00:00'),(3, '2012-11-29', '11:00:00'),(4, '2012-11-28', '11:00:00'),(5, '2012-11-27', '11:00:00'),(6, '2012-11-26', '11:00:00'),(7, '2012-11-25', '11:00:00'),(8, '2012-11-24', '11:00:00'),(9, '2012-11-23', '11:00:00');
FLUSH TABLES;
--echo
--echo select test 1
--connection child2_1
TRUNCATE TABLE mysql.general_log;
--connection master_1
INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 4 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY));
INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 3 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY));
INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 2 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY));
INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 1 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY));
INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 0 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY));
INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 9 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY));
INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 8 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY));
INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 7 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY));
INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 6 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY));
INSERT IGNORE INTO tbl_b (SELECT skey, CAST(CONCAT(dt, ' ', tm) AS datetime) FROM tbl_a WHERE skey = 5 AND dt > DATE_ADD('2012-12-01', INTERVAL -10 DAY));
--connection child2_1
eval $CHILD2_1_SELECT_ARGUMENT1;
eval $CHILD2_1_SELECT_TABLES;
--echo
--echo deinit
--disable_warnings
--connection master_1
DROP DATABASE IF EXISTS auto_test_local;
--connection child2_1
DROP DATABASE IF EXISTS auto_test_remote;
SET GLOBAL log_output = @old_log_output;
--enable_warnings
--source ../include/insert_select_deinit.inc
--echo
--echo end of test
...@@ -312,6 +312,10 @@ void spider_free_conn_from_trx( ...@@ -312,6 +312,10 @@ void spider_free_conn_from_trx(
} }
} else { } else {
/* conn_recycle_mode == 0 */ /* conn_recycle_mode == 0 */
if (conn->quick_target)
{
spider_db_free_result((ha_spider *) conn->quick_target, TRUE);
}
spider_free_conn(conn); spider_free_conn(conn);
} }
} else if (roop_count) } else if (roop_count)
...@@ -1283,7 +1287,7 @@ int spider_check_and_get_casual_read_conn( ...@@ -1283,7 +1287,7 @@ int spider_check_and_get_casual_read_conn(
if ( if (
!(spider->conns[link_idx] = !(spider->conns[link_idx] =
spider_get_conn(spider->share, link_idx, spider_get_conn(spider->share, link_idx,
spider->conn_keys[link_idx], spider->trx, spider->conn_keys[link_idx], spider->wide_handler->trx,
spider, FALSE, TRUE, SPIDER_CONN_KIND_MYSQL, spider, FALSE, TRUE, SPIDER_CONN_KIND_MYSQL,
&error_num)) &error_num))
) { ) {
...@@ -1745,7 +1749,8 @@ int spider_set_conn_bg_param( ...@@ -1745,7 +1749,8 @@ int spider_set_conn_bg_param(
int error_num, roop_count, bgs_mode; int error_num, roop_count, bgs_mode;
SPIDER_SHARE *share = spider->share; SPIDER_SHARE *share = spider->share;
SPIDER_RESULT_LIST *result_list = &spider->result_list; SPIDER_RESULT_LIST *result_list = &spider->result_list;
THD *thd = spider->trx->thd; SPIDER_WIDE_HANDLER *wide_handler = spider->wide_handler;
THD *thd = wide_handler->trx->thd;
DBUG_ENTER("spider_set_conn_bg_param"); DBUG_ENTER("spider_set_conn_bg_param");
DBUG_PRINT("info",("spider spider=%p", spider)); DBUG_PRINT("info",("spider spider=%p", spider));
bgs_mode = bgs_mode =
...@@ -1754,10 +1759,11 @@ int spider_set_conn_bg_param( ...@@ -1754,10 +1759,11 @@ int spider_set_conn_bg_param(
result_list->bgs_phase = 0; result_list->bgs_phase = 0;
else if ( else if (
bgs_mode <= 2 && bgs_mode <= 2 &&
(result_list->lock_type == F_WRLCK || spider->lock_mode == 2) (wide_handler->external_lock_type == F_WRLCK ||
wide_handler->lock_mode == 2)
) )
result_list->bgs_phase = 0; result_list->bgs_phase = 0;
else if (bgs_mode <= 1 && spider->lock_mode == 1) else if (bgs_mode <= 1 && wide_handler->lock_mode == 1)
result_list->bgs_phase = 0; result_list->bgs_phase = 0;
else { else {
result_list->bgs_phase = 1; result_list->bgs_phase = 1;
...@@ -1804,12 +1810,12 @@ int spider_set_conn_bg_param( ...@@ -1804,12 +1810,12 @@ int spider_set_conn_bg_param(
for ( for (
roop_count = spider_conn_link_idx_next(share->link_statuses, roop_count = spider_conn_link_idx_next(share->link_statuses,
spider->conn_link_idx, -1, share->link_count, spider->conn_link_idx, -1, share->link_count,
spider->lock_mode ? spider->wide_handler->lock_mode ?
SPIDER_LINK_STATUS_RECOVERY : SPIDER_LINK_STATUS_OK); SPIDER_LINK_STATUS_RECOVERY : SPIDER_LINK_STATUS_OK);
roop_count < (int) share->link_count; roop_count < (int) share->link_count;
roop_count = spider_conn_link_idx_next(share->link_statuses, roop_count = spider_conn_link_idx_next(share->link_statuses,
spider->conn_link_idx, roop_count, share->link_count, spider->conn_link_idx, roop_count, share->link_count,
spider->lock_mode ? spider->wide_handler->lock_mode ?
SPIDER_LINK_STATUS_RECOVERY : SPIDER_LINK_STATUS_OK) SPIDER_LINK_STATUS_RECOVERY : SPIDER_LINK_STATUS_OK)
) { ) {
if ((error_num = spider_create_conn_thread(spider->conns[roop_count]))) if ((error_num = spider_create_conn_thread(spider->conns[roop_count])))
...@@ -2688,7 +2694,7 @@ void *spider_bg_conn_action( ...@@ -2688,7 +2694,7 @@ void *spider_bg_conn_action(
conn->link_idx); conn->link_idx);
result_list->tmp_tables_created = TRUE; result_list->tmp_tables_created = TRUE;
spider_conn_set_timeout_from_share(conn, conn->link_idx, spider_conn_set_timeout_from_share(conn, conn->link_idx,
spider->trx->thd, share); spider->wide_handler->trx->thd, share);
if (dbton_handler->execute_sql( if (dbton_handler->execute_sql(
SPIDER_SQL_TYPE_TMP_SQL, SPIDER_SQL_TYPE_TMP_SQL,
conn, conn,
...@@ -2706,7 +2712,7 @@ void *spider_bg_conn_action( ...@@ -2706,7 +2712,7 @@ void *spider_bg_conn_action(
if (!result_list->bgs_error) if (!result_list->bgs_error)
{ {
spider_conn_set_timeout_from_share(conn, conn->link_idx, spider_conn_set_timeout_from_share(conn, conn->link_idx,
spider->trx->thd, share); spider->wide_handler->trx->thd, share);
if (dbton_handler->execute_sql( if (dbton_handler->execute_sql(
sql_type, sql_type,
conn, conn,
...@@ -2949,6 +2955,7 @@ void *spider_bg_sts_action( ...@@ -2949,6 +2955,7 @@ void *spider_bg_sts_action(
SPIDER_TRX *trx; SPIDER_TRX *trx;
int error_num = 0, roop_count; int error_num = 0, roop_count;
ha_spider spider; ha_spider spider;
SPIDER_WIDE_HANDLER wide_handler;
int *need_mons; int *need_mons;
SPIDER_CONN **conns; SPIDER_CONN **conns;
uint *conn_link_idx; uint *conn_link_idx;
...@@ -3042,7 +3049,8 @@ void *spider_bg_sts_action( ...@@ -3042,7 +3049,8 @@ void *spider_bg_sts_action(
DBUG_RETURN(NULL); DBUG_RETURN(NULL);
} }
share->bg_sts_thd = thd; share->bg_sts_thd = thd;
spider.trx = trx; spider.wide_handler = &wide_handler;
wide_handler.trx = trx;
spider.share = share; spider.share = share;
spider.conns = conns; spider.conns = conns;
spider.conn_link_idx = conn_link_idx; spider.conn_link_idx = conn_link_idx;
...@@ -3314,6 +3322,7 @@ void *spider_bg_crd_action( ...@@ -3314,6 +3322,7 @@ void *spider_bg_crd_action(
SPIDER_TRX *trx; SPIDER_TRX *trx;
int error_num = 0, roop_count; int error_num = 0, roop_count;
ha_spider spider; ha_spider spider;
SPIDER_WIDE_HANDLER wide_handler;
TABLE table; TABLE table;
int *need_mons; int *need_mons;
SPIDER_CONN **conns; SPIDER_CONN **conns;
...@@ -3411,7 +3420,8 @@ void *spider_bg_crd_action( ...@@ -3411,7 +3420,8 @@ void *spider_bg_crd_action(
table.s = share->table_share; table.s = share->table_share;
table.field = share->table_share->field; table.field = share->table_share->field;
table.key_info = share->table_share->key_info; table.key_info = share->table_share->key_info;
spider.trx = trx; spider.wide_handler = &wide_handler;
wide_handler.trx = trx;
spider.change_table_ptr(&table, share->table_share); spider.change_table_ptr(&table, share->table_share);
spider.share = share; spider.share = share;
spider.conns = conns; spider.conns = conns;
...@@ -4097,11 +4107,12 @@ int spider_conn_get_link_status( ...@@ -4097,11 +4107,12 @@ int spider_conn_get_link_status(
int spider_conn_lock_mode( int spider_conn_lock_mode(
ha_spider *spider ha_spider *spider
) { ) {
SPIDER_RESULT_LIST *result_list = &spider->result_list; SPIDER_WIDE_HANDLER *wide_handler = spider->wide_handler;
DBUG_ENTER("spider_conn_lock_mode"); DBUG_ENTER("spider_conn_lock_mode");
if (result_list->lock_type == F_WRLCK || spider->lock_mode == 2) if (wide_handler->external_lock_type == F_WRLCK ||
wide_handler->lock_mode == 2)
DBUG_RETURN(SPIDER_LOCK_MODE_EXCLUSIVE); DBUG_RETURN(SPIDER_LOCK_MODE_EXCLUSIVE);
else if (spider->lock_mode == 1) else if (wide_handler->lock_mode == 1)
DBUG_RETURN(SPIDER_LOCK_MODE_SHARED); DBUG_RETURN(SPIDER_LOCK_MODE_SHARED);
DBUG_RETURN(SPIDER_LOCK_MODE_NO_LOCK); DBUG_RETURN(SPIDER_LOCK_MODE_NO_LOCK);
} }
...@@ -4124,7 +4135,7 @@ bool spider_conn_use_handler( ...@@ -4124,7 +4135,7 @@ bool spider_conn_use_handler(
int lock_mode, int lock_mode,
int link_idx int link_idx
) { ) {
THD *thd = spider->trx->thd; THD *thd = spider->wide_handler->trx->thd;
int use_handler = spider_param_use_handler(thd, int use_handler = spider_param_use_handler(thd,
spider->share->use_handlers[link_idx]); spider->share->use_handlers[link_idx]);
DBUG_ENTER("spider_conn_use_handler"); DBUG_ENTER("spider_conn_use_handler");
...@@ -4197,7 +4208,7 @@ bool spider_conn_use_handler( ...@@ -4197,7 +4208,7 @@ bool spider_conn_use_handler(
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
} }
if ( if (
spider->sql_command == SQLCOM_HA_READ && spider->wide_handler->sql_command == SQLCOM_HA_READ &&
( (
!(use_handler & 2) || !(use_handler & 2) ||
( (
...@@ -4212,7 +4223,7 @@ bool spider_conn_use_handler( ...@@ -4212,7 +4223,7 @@ bool spider_conn_use_handler(
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
if ( if (
spider->sql_command != SQLCOM_HA_READ && spider->wide_handler->sql_command != SQLCOM_HA_READ &&
lock_mode == SPIDER_LOCK_MODE_NO_LOCK && lock_mode == SPIDER_LOCK_MODE_NO_LOCK &&
spider_param_sync_trx_isolation(thd) && spider_param_sync_trx_isolation(thd) &&
thd_tx_isolation(thd) != ISO_SERIALIZABLE && thd_tx_isolation(thd) != ISO_SERIALIZABLE &&
......
/* Copyright (C) 2009-2018 Kentoku Shiba /* Copyright (C) 2009-2019 Kentoku Shiba
Copyright (C) 2019 MariaDB corp
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -839,6 +840,7 @@ long long spider_copy_tables_body( ...@@ -839,6 +840,7 @@ long long spider_copy_tables_body(
spider_string *tmp_sql = NULL; spider_string *tmp_sql = NULL;
SPIDER_COPY_TABLE_CONN *table_conn, *src_tbl_conn, *dst_tbl_conn; SPIDER_COPY_TABLE_CONN *table_conn, *src_tbl_conn, *dst_tbl_conn;
SPIDER_CONN *tmp_conn; SPIDER_CONN *tmp_conn;
SPIDER_WIDE_HANDLER *wide_handler;
spider_db_copy_table *select_ct, *insert_ct; spider_db_copy_table *select_ct, *insert_ct;
MEM_ROOT mem_root; MEM_ROOT mem_root;
longlong bulk_insert_rows; longlong bulk_insert_rows;
...@@ -1128,13 +1130,15 @@ long long spider_copy_tables_body( ...@@ -1128,13 +1130,15 @@ long long spider_copy_tables_body(
__func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL),
&tmp_spider->dbton_handler, &tmp_spider->dbton_handler,
sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE, sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE,
&wide_handler, sizeof(SPIDER_WIDE_HANDLER),
NullS)) NullS))
) { ) {
my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
goto error; goto error;
} }
tmp_spider->share = table_conn->share; tmp_spider->share = table_conn->share;
tmp_spider->trx = copy_tables->trx; tmp_spider->wide_handler = wide_handler;
wide_handler->trx = copy_tables->trx;
/* /*
if (spider_db_append_set_names(table_conn->share)) if (spider_db_append_set_names(table_conn->share))
{ {
...@@ -1147,7 +1151,7 @@ long long spider_copy_tables_body( ...@@ -1147,7 +1151,7 @@ long long spider_copy_tables_body(
tmp_sql[roop_count].set_charset(copy_tables->access_charset); tmp_sql[roop_count].set_charset(copy_tables->access_charset);
tmp_spider->result_list.sqls = &tmp_sql[roop_count]; tmp_spider->result_list.sqls = &tmp_sql[roop_count];
tmp_spider->need_mons = &table_conn->need_mon; tmp_spider->need_mons = &table_conn->need_mon;
tmp_spider->lock_type = TL_READ; tmp_spider->wide_handler->lock_type = TL_READ;
tmp_spider->conn_link_idx = &tmp_conn_link_idx; tmp_spider->conn_link_idx = &tmp_conn_link_idx;
uint dbton_id = tmp_spider->share->use_dbton_ids[0]; uint dbton_id = tmp_spider->share->use_dbton_ids[0];
if (!(tmp_spider->dbton_handler[dbton_id] = if (!(tmp_spider->dbton_handler[dbton_id] =
...@@ -1172,13 +1176,15 @@ long long spider_copy_tables_body( ...@@ -1172,13 +1176,15 @@ long long spider_copy_tables_body(
__func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL), __func__, __FILE__, __LINE__, MYF(MY_WME | MY_ZEROFILL),
&tmp_spider->dbton_handler, &tmp_spider->dbton_handler,
sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE, sizeof(spider_db_handler *) * SPIDER_DBTON_SIZE,
&wide_handler, sizeof(SPIDER_WIDE_HANDLER),
NullS)) NullS))
) { ) {
my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM); my_error(ER_OUT_OF_RESOURCES, MYF(0), HA_ERR_OUT_OF_MEM);
goto error; goto error;
} }
tmp_spider->share = table_conn->share; tmp_spider->share = table_conn->share;
tmp_spider->trx = copy_tables->trx; tmp_spider->wide_handler = wide_handler;
wide_handler->trx = copy_tables->trx;
/* /*
if (spider_db_append_set_names(table_conn->share)) if (spider_db_append_set_names(table_conn->share))
{ {
...@@ -1191,7 +1197,7 @@ long long spider_copy_tables_body( ...@@ -1191,7 +1197,7 @@ long long spider_copy_tables_body(
tmp_sql[roop_count].set_charset(copy_tables->access_charset); tmp_sql[roop_count].set_charset(copy_tables->access_charset);
tmp_spider->result_list.sqls = &tmp_sql[roop_count]; tmp_spider->result_list.sqls = &tmp_sql[roop_count];
tmp_spider->need_mons = &table_conn->need_mon; tmp_spider->need_mons = &table_conn->need_mon;
tmp_spider->lock_type = TL_WRITE; tmp_spider->wide_handler->lock_type = TL_WRITE;
tmp_spider->conn_link_idx = &tmp_conn_link_idx; tmp_spider->conn_link_idx = &tmp_conn_link_idx;
uint dbton_id = tmp_spider->share->use_dbton_ids[0]; uint dbton_id = tmp_spider->share->use_dbton_ids[0];
if (!(tmp_spider->dbton_handler[dbton_id] = if (!(tmp_spider->dbton_handler[dbton_id] =
......
This diff is collapsed.
...@@ -2045,7 +2045,6 @@ typedef struct st_spider_result_list ...@@ -2045,7 +2045,6 @@ typedef struct st_spider_result_list
#endif #endif
int quick_phase; int quick_phase;
bool keyread; bool keyread;
int lock_type;
TABLE *table; TABLE *table;
#ifndef WITHOUT_SPIDER_BG_SEARCH #ifndef WITHOUT_SPIDER_BG_SEARCH
volatile int bgs_error; volatile int bgs_error;
......
This diff is collapsed.
This diff is collapsed.
...@@ -795,7 +795,7 @@ void spider_fields::choose_a_conn( ...@@ -795,7 +795,7 @@ void spider_fields::choose_a_conn(
SPIDER_CONN_HOLDER *conn_holder; SPIDER_CONN_HOLDER *conn_holder;
longlong balance_total = 0, balance_val; longlong balance_total = 0, balance_val;
double rand_val; double rand_val;
THD *thd = table_holder[0].spider->trx->thd; THD *thd = table_holder[0].spider->wide_handler->trx->thd;
DBUG_ENTER("spider_fields::choose_a_conn"); DBUG_ENTER("spider_fields::choose_a_conn");
DBUG_PRINT("info",("spider this=%p", this)); DBUG_PRINT("info",("spider this=%p", this));
for (current_conn_holder = first_conn_holder; current_conn_holder; for (current_conn_holder = first_conn_holder; current_conn_holder;
...@@ -1147,8 +1147,8 @@ int spider_fields::ping_table_mon_from_table( ...@@ -1147,8 +1147,8 @@ int spider_fields::ping_table_mon_from_table(
if (tmp_share->monitoring_kind[tmp_link_idx]) if (tmp_share->monitoring_kind[tmp_link_idx])
{ {
error_num_buf = spider_ping_table_mon_from_table( error_num_buf = spider_ping_table_mon_from_table(
tmp_spider->trx, tmp_spider->wide_handler->trx,
tmp_spider->trx->thd, tmp_spider->wide_handler->trx->thd,
tmp_share, tmp_share,
tmp_link_idx, tmp_link_idx,
(uint32) tmp_share->monitoring_sid[tmp_link_idx], (uint32) tmp_share->monitoring_sid[tmp_link_idx],
...@@ -1181,7 +1181,7 @@ spider_group_by_handler::spider_group_by_handler( ...@@ -1181,7 +1181,7 @@ spider_group_by_handler::spider_group_by_handler(
fields->set_pos_to_first_table_holder(); fields->set_pos_to_first_table_holder();
SPIDER_TABLE_HOLDER *table_holder = fields->get_next_table_holder(); SPIDER_TABLE_HOLDER *table_holder = fields->get_next_table_holder();
spider = table_holder->spider; spider = table_holder->spider;
trx = spider->trx; trx = spider->wide_handler->trx;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -1924,6 +1924,12 @@ group_by_handler *spider_create_group_by_handler( ...@@ -1924,6 +1924,12 @@ group_by_handler *spider_create_group_by_handler(
delete fields; delete fields;
DBUG_RETURN(NULL); DBUG_RETURN(NULL);
} }
if (spider->dml_init())
{
DBUG_PRINT("info",("spider can not init for dml"));
delete fields;
DBUG_RETURN(NULL);
}
for ( for (
roop_count = spider_conn_link_idx_next(share->link_statuses, roop_count = spider_conn_link_idx_next(share->link_statuses,
spider->conn_link_idx, -1, share->link_count, spider->conn_link_idx, -1, share->link_count,
...@@ -2006,6 +2012,12 @@ group_by_handler *spider_create_group_by_handler( ...@@ -2006,6 +2012,12 @@ group_by_handler *spider_create_group_by_handler(
} }
DBUG_PRINT("info",("spider s->db=%s", from->table->s->db.str)); DBUG_PRINT("info",("spider s->db=%s", from->table->s->db.str));
DBUG_PRINT("info",("spider s->table_name=%s", from->table->s->table_name.str)); DBUG_PRINT("info",("spider s->table_name=%s", from->table->s->table_name.str));
if (spider->dml_init())
{
DBUG_PRINT("info",("spider can not init for dml"));
delete fields;
DBUG_RETURN(NULL);
}
for ( for (
roop_count = spider_conn_link_idx_next(share->link_statuses, roop_count = spider_conn_link_idx_next(share->link_statuses,
spider->conn_link_idx, -1, share->link_count, spider->conn_link_idx, -1, share->link_count,
......
...@@ -621,26 +621,19 @@ typedef struct st_spider_lgtm_tblhnd_share ...@@ -621,26 +621,19 @@ typedef struct st_spider_lgtm_tblhnd_share
#ifdef WITH_PARTITION_STORAGE_ENGINE #ifdef WITH_PARTITION_STORAGE_ENGINE
typedef struct st_spider_patition_handler_share typedef struct st_spider_patition_handler_share
{ {
uint use_count; bool clone_bitmap_init;
TABLE *table;
#ifdef SPIDER_HAS_HASH_VALUE_TYPE #ifdef SPIDER_HAS_HASH_VALUE_TYPE
my_hash_value_type table_hash_value; my_hash_value_type table_hash_value;
#endif #endif
void *creator;
void **handlers;
uchar *searched_bitmap;
uchar *ft_discard_bitmap;
uchar *idx_read_bitmap;
uchar *idx_write_bitmap;
uchar *rnd_read_bitmap;
uchar *rnd_write_bitmap;
bool between_flg;
bool idx_bitmap_is_set;
bool rnd_bitmap_is_set;
query_id_t parallel_search_query_id; query_id_t parallel_search_query_id;
uint no_parts;
TABLE *table;
ha_spider *owner;
ha_spider **handlers;
} SPIDER_PARTITION_HANDLER_SHARE; } SPIDER_PARTITION_HANDLER_SHARE;
#endif
typedef struct st_spider_patition_share typedef struct st_spider_wide_share
{ {
char *table_name; char *table_name;
uint table_name_length; uint table_name_length;
...@@ -648,6 +641,7 @@ typedef struct st_spider_patition_share ...@@ -648,6 +641,7 @@ typedef struct st_spider_patition_share
my_hash_value_type table_path_hash_value; my_hash_value_type table_path_hash_value;
#endif #endif
uint use_count; uint use_count;
THR_LOCK lock;
pthread_mutex_t sts_mutex; pthread_mutex_t sts_mutex;
pthread_mutex_t crd_mutex; pthread_mutex_t crd_mutex;
pthread_mutex_t pt_handler_mutex; pthread_mutex_t pt_handler_mutex;
...@@ -664,11 +658,103 @@ typedef struct st_spider_patition_share ...@@ -664,11 +658,103 @@ typedef struct st_spider_patition_share
ha_statistics stat; ha_statistics stat;
longlong *cardinality; longlong *cardinality;
/* } SPIDER_WIDE_SHARE;
volatile SPIDER_PARTITION_HANDLER_SHARE *partition_handler_share;
*/ enum spider_hnd_stage {
} SPIDER_PARTITION_SHARE; SPD_HND_STAGE_NONE,
SPD_HND_STAGE_STORE_LOCK,
SPD_HND_STAGE_EXTERNAL_LOCK,
SPD_HND_STAGE_START_STMT,
SPD_HND_STAGE_EXTRA,
SPD_HND_STAGE_COND_PUSH,
SPD_HND_STAGE_COND_POP,
SPD_HND_STAGE_INFO_PUSH,
SPD_HND_STAGE_SET_TOP_TABLE_AND_FIELDS,
SPD_HND_STAGE_CLEAR_TOP_TABLE_FIELDS
};
typedef struct st_spider_wide_handler
{
spider_hnd_stage stage;
handler *stage_executor;
THR_LOCK_DATA lock;
SPIDER_TRX *trx;
uchar *searched_bitmap;
uchar *ft_discard_bitmap;
uchar *position_bitmap;
uchar *idx_read_bitmap;
uchar *idx_write_bitmap;
uchar *rnd_read_bitmap;
uchar *rnd_write_bitmap;
SPIDER_CONDITION *condition;
void *owner;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
uint32 *hs_pushed_ret_fields;
#endif #endif
#endif
#ifdef WITH_PARTITION_STORAGE_ENGINE
SPIDER_PARTITION_HANDLER_SHARE *partition_handler_share;
#endif
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
List<Item> *direct_update_fields;
List<Item> *direct_update_values;
#endif
TABLE *top_table;
Field **top_table_field;
enum thr_lock_type lock_type;
uchar lock_table_type;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
uint32 hs_pushed_strref_num;
#endif
#endif
int lock_mode;
int external_lock_type;
int cond_check_error;
uint sql_command;
uint top_table_fields;
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
#ifdef INFO_KIND_FORCE_LIMIT_BEGIN
longlong info_limit;
#endif
#endif
#ifdef HA_CAN_BULK_ACCESS
ulonglong external_lock_cnt;
#endif
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
size_t hs_pushed_ret_fields_num;
size_t hs_pushed_ret_fields_size;
size_t hs_pushed_lcl_fields_num;
#endif
#endif
bool between_flg;
bool idx_bitmap_is_set;
bool rnd_bitmap_is_set;
bool position_bitmap_init;
bool semi_trx_isolation_chk;
bool semi_trx_chk;
bool low_priority;
bool high_priority;
bool insert_delayed;
bool consistent_snapshot;
bool quick_mode;
bool keyread;
bool update_request;
bool ignore_dup_key;
bool write_can_replace;
bool insert_with_update;
bool cond_check;
bool set_top_table_fields;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
#ifdef HANDLER_HAS_DIRECT_UPDATE_ROWS
bool hs_increment;
bool hs_decrement;
#endif
#endif
bool semi_table_lock;
} SPIDER_WIDE_HANDLER;
typedef struct st_spider_transaction typedef struct st_spider_transaction
{ {
...@@ -805,7 +891,6 @@ typedef struct st_spider_share ...@@ -805,7 +891,6 @@ typedef struct st_spider_share
/* /*
pthread_mutex_t auto_increment_mutex; pthread_mutex_t auto_increment_mutex;
*/ */
THR_LOCK lock;
TABLE_SHARE *table_share; TABLE_SHARE *table_share;
SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share; SPIDER_LGTM_TBLHND_SHARE *lgtm_tblhnd_share;
#ifdef SPIDER_HAS_HASH_VALUE_TYPE #ifdef SPIDER_HAS_HASH_VALUE_TYPE
...@@ -1177,9 +1262,7 @@ typedef struct st_spider_share ...@@ -1177,9 +1262,7 @@ typedef struct st_spider_share
#endif #endif
SPIDER_ALTER_TABLE alter_table; SPIDER_ALTER_TABLE alter_table;
#ifdef WITH_PARTITION_STORAGE_ENGINE SPIDER_WIDE_SHARE *wide_share;
SPIDER_PARTITION_SHARE *partition_share;
#endif
} SPIDER_SHARE; } SPIDER_SHARE;
typedef struct st_spider_link_pack typedef struct st_spider_link_pack
......
This diff is collapsed.
...@@ -224,13 +224,13 @@ uchar *spider_tbl_get_key( ...@@ -224,13 +224,13 @@ uchar *spider_tbl_get_key(
my_bool not_used __attribute__ ((unused)) my_bool not_used __attribute__ ((unused))
); );
#ifdef WITH_PARTITION_STORAGE_ENGINE uchar *spider_wide_share_get_key(
uchar *spider_pt_share_get_key( SPIDER_WIDE_SHARE *share,
SPIDER_PARTITION_SHARE *share,
size_t *length, size_t *length,
my_bool not_used __attribute__ ((unused)) my_bool not_used __attribute__ ((unused))
); );
#ifdef WITH_PARTITION_STORAGE_ENGINE
uchar *spider_pt_handler_share_get_key( uchar *spider_pt_handler_share_get_key(
SPIDER_PARTITION_HANDLER_SHARE *share, SPIDER_PARTITION_HANDLER_SHARE *share,
size_t *length, size_t *length,
...@@ -420,39 +420,37 @@ void spider_update_link_status_for_share( ...@@ -420,39 +420,37 @@ void spider_update_link_status_for_share(
long link_status long link_status
); );
#ifdef WITH_PARTITION_STORAGE_ENGINE SPIDER_WIDE_SHARE *spider_get_wide_share(
SPIDER_PARTITION_SHARE *spider_get_pt_share(
SPIDER_SHARE *share, SPIDER_SHARE *share,
TABLE_SHARE *table_share, TABLE_SHARE *table_share,
int *error_num int *error_num
); );
int spider_free_pt_share( int spider_free_wide_share(
SPIDER_PARTITION_SHARE *partition_share SPIDER_WIDE_SHARE *wide_share
); );
void spider_copy_sts_to_pt_share( void spider_copy_sts_to_wide_share(
SPIDER_PARTITION_SHARE *partition_share, SPIDER_WIDE_SHARE *wide_share,
SPIDER_SHARE *share SPIDER_SHARE *share
); );
void spider_copy_sts_to_share( void spider_copy_sts_to_share(
SPIDER_SHARE *share, SPIDER_SHARE *share,
SPIDER_PARTITION_SHARE *partition_share SPIDER_WIDE_SHARE *wide_share
); );
void spider_copy_crd_to_pt_share( void spider_copy_crd_to_wide_share(
SPIDER_PARTITION_SHARE *partition_share, SPIDER_WIDE_SHARE *wide_share,
SPIDER_SHARE *share, SPIDER_SHARE *share,
int fields int fields
); );
void spider_copy_crd_to_share( void spider_copy_crd_to_share(
SPIDER_SHARE *share, SPIDER_SHARE *share,
SPIDER_PARTITION_SHARE *partition_share, SPIDER_WIDE_SHARE *wide_share,
int fields int fields
); );
#endif
int spider_open_all_tables( int spider_open_all_tables(
SPIDER_TRX *trx, SPIDER_TRX *trx,
......
...@@ -247,6 +247,7 @@ int spider_trx_another_lock_tables( ...@@ -247,6 +247,7 @@ int spider_trx_another_lock_tables(
SPIDER_CONN *conn; SPIDER_CONN *conn;
ha_spider tmp_spider; ha_spider tmp_spider;
SPIDER_SHARE tmp_share; SPIDER_SHARE tmp_share;
SPIDER_WIDE_HANDLER tmp_wide_handler;
char sql_buf[MAX_FIELD_WIDTH]; char sql_buf[MAX_FIELD_WIDTH];
spider_string sql_str(sql_buf, sizeof(sql_buf), system_charset_info); spider_string sql_str(sql_buf, sizeof(sql_buf), system_charset_info);
DBUG_ENTER("spider_trx_another_lock_tables"); DBUG_ENTER("spider_trx_another_lock_tables");
...@@ -255,13 +256,11 @@ int spider_trx_another_lock_tables( ...@@ -255,13 +256,11 @@ int spider_trx_another_lock_tables(
sql_str.length(0); sql_str.length(0);
memset((void*)&tmp_spider, 0, sizeof(ha_spider)); memset((void*)&tmp_spider, 0, sizeof(ha_spider));
memset((void*)&tmp_share, 0, sizeof(SPIDER_SHARE)); memset((void*)&tmp_share, 0, sizeof(SPIDER_SHARE));
memset((void*)&tmp_wide_handler, 0, sizeof(SPIDER_WIDE_HANDLER));
tmp_spider.share = &tmp_share; tmp_spider.share = &tmp_share;
tmp_spider.trx = trx; tmp_spider.wide_handler = &tmp_wide_handler;
tmp_wide_handler.trx = trx;
tmp_share.access_charset = system_charset_info; tmp_share.access_charset = system_charset_info;
/*
if ((error_num = spider_db_append_set_names(&tmp_share)))
DBUG_RETURN(error_num);
*/
tmp_spider.conns = &conn; tmp_spider.conns = &conn;
tmp_spider.result_list.sqls = &sql_str; tmp_spider.result_list.sqls = &sql_str;
tmp_spider.need_mons = &need_mon; tmp_spider.need_mons = &need_mon;
...@@ -273,17 +272,11 @@ int spider_trx_another_lock_tables( ...@@ -273,17 +272,11 @@ int spider_trx_another_lock_tables(
SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM; SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM;
if (error_num) if (error_num)
{ {
/*
spider_db_free_set_names(&tmp_share);
*/
DBUG_RETURN(error_num); DBUG_RETURN(error_num);
} }
} }
roop_count++; roop_count++;
} }
/*
spider_db_free_set_names(&tmp_share);
*/
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -387,10 +380,13 @@ int spider_trx_all_start_trx( ...@@ -387,10 +380,13 @@ int spider_trx_all_start_trx(
THD *thd = trx->thd; THD *thd = trx->thd;
SPIDER_CONN *conn; SPIDER_CONN *conn;
ha_spider tmp_spider; ha_spider tmp_spider;
SPIDER_WIDE_HANDLER tmp_wide_handler;
DBUG_ENTER("spider_trx_all_start_trx"); DBUG_ENTER("spider_trx_all_start_trx");
SPIDER_BACKUP_DASTATUS; SPIDER_BACKUP_DASTATUS;
memset((void*)&tmp_spider, 0, sizeof(ha_spider)); memset((void*)&tmp_spider, 0, sizeof(ha_spider));
tmp_spider.trx = trx; memset(&tmp_wide_handler, 0, sizeof(SPIDER_WIDE_HANDLER));
tmp_spider.wide_handler = &tmp_wide_handler;
tmp_wide_handler.trx = trx;
tmp_spider.need_mons = &need_mon; tmp_spider.need_mons = &need_mon;
while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_conn_hash, while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_conn_hash,
roop_count))) roop_count)))
...@@ -398,7 +394,8 @@ int spider_trx_all_start_trx( ...@@ -398,7 +394,8 @@ int spider_trx_all_start_trx(
if ( if (
(spider_param_sync_trx_isolation(trx->thd) && (spider_param_sync_trx_isolation(trx->thd) &&
(error_num = spider_check_and_set_trx_isolation(conn, &need_mon))) || (error_num = spider_check_and_set_trx_isolation(conn, &need_mon))) ||
(error_num = spider_internal_start_trx(&tmp_spider, conn, 0)) (error_num = spider_internal_start_trx_for_connection(&tmp_spider,
conn, 0))
) { ) {
SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM; SPIDER_CONN_RESTORE_DASTATUS_AND_RESET_ERROR_NUM;
if (error_num) if (error_num)
...@@ -418,6 +415,7 @@ int spider_trx_all_flush_logs( ...@@ -418,6 +415,7 @@ int spider_trx_all_flush_logs(
SPIDER_CONN *conn; SPIDER_CONN *conn;
ha_spider tmp_spider; ha_spider tmp_spider;
SPIDER_SHARE tmp_share; SPIDER_SHARE tmp_share;
SPIDER_WIDE_HANDLER tmp_wide_handler;
long tmp_link_statuses = SPIDER_LINK_STATUS_OK; long tmp_link_statuses = SPIDER_LINK_STATUS_OK;
uint conn_link_idx = 0; uint conn_link_idx = 0;
long net_read_timeout = 600; long net_read_timeout = 600;
...@@ -425,6 +423,7 @@ int spider_trx_all_flush_logs( ...@@ -425,6 +423,7 @@ int spider_trx_all_flush_logs(
DBUG_ENTER("spider_trx_all_flush_logs"); DBUG_ENTER("spider_trx_all_flush_logs");
SPIDER_BACKUP_DASTATUS; SPIDER_BACKUP_DASTATUS;
memset((void*)&tmp_spider, 0, sizeof(ha_spider)); memset((void*)&tmp_spider, 0, sizeof(ha_spider));
memset(&tmp_wide_handler, 0, sizeof(SPIDER_WIDE_HANDLER));
tmp_share.link_count = 1; tmp_share.link_count = 1;
tmp_share.all_link_count = 1; tmp_share.all_link_count = 1;
tmp_share.link_statuses = &tmp_link_statuses; tmp_share.link_statuses = &tmp_link_statuses;
...@@ -437,7 +436,8 @@ int spider_trx_all_flush_logs( ...@@ -437,7 +436,8 @@ int spider_trx_all_flush_logs(
tmp_spider.conns = &conn; tmp_spider.conns = &conn;
tmp_spider.need_mons = &need_mon; tmp_spider.need_mons = &need_mon;
tmp_spider.conn_link_idx = &conn_link_idx; tmp_spider.conn_link_idx = &conn_link_idx;
tmp_spider.trx = trx; tmp_spider.wide_handler = &tmp_wide_handler;
tmp_wide_handler.trx = trx;
while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_conn_hash, while ((conn = (SPIDER_CONN*) my_hash_element(&trx->trx_conn_hash,
roop_count))) roop_count)))
{ {
...@@ -1200,6 +1200,7 @@ SPIDER_TRX *spider_get_trx( ...@@ -1200,6 +1200,7 @@ SPIDER_TRX *spider_get_trx(
int roop_count = 0, roop_count2; int roop_count = 0, roop_count2;
SPIDER_TRX *trx; SPIDER_TRX *trx;
SPIDER_SHARE *tmp_share; SPIDER_SHARE *tmp_share;
SPIDER_WIDE_HANDLER *tmp_wide_handler;
pthread_mutex_t *udf_table_mutexes; pthread_mutex_t *udf_table_mutexes;
DBUG_ENTER("spider_get_trx"); DBUG_ENTER("spider_get_trx");
...@@ -1212,6 +1213,7 @@ SPIDER_TRX *spider_get_trx( ...@@ -1212,6 +1213,7 @@ SPIDER_TRX *spider_get_trx(
spider_bulk_malloc(NULL, 56, MYF(MY_WME | MY_ZEROFILL), spider_bulk_malloc(NULL, 56, MYF(MY_WME | MY_ZEROFILL),
&trx, (uint) (sizeof(*trx)), &trx, (uint) (sizeof(*trx)),
&tmp_share, (uint) (sizeof(SPIDER_SHARE)), &tmp_share, (uint) (sizeof(SPIDER_SHARE)),
&tmp_wide_handler, (uint) sizeof(SPIDER_WIDE_HANDLER),
&udf_table_mutexes, (uint) (sizeof(pthread_mutex_t) * &udf_table_mutexes, (uint) (sizeof(pthread_mutex_t) *
spider_param_udf_table_lock_mutex_count()), spider_param_udf_table_lock_mutex_count()),
NullS)) NullS))
...@@ -1387,7 +1389,8 @@ SPIDER_TRX *spider_get_trx( ...@@ -1387,7 +1389,8 @@ SPIDER_TRX *spider_get_trx(
} }
trx->tmp_spider->need_mons = &trx->tmp_need_mon; trx->tmp_spider->need_mons = &trx->tmp_need_mon;
trx->tmp_spider->share = trx->tmp_share; trx->tmp_spider->share = trx->tmp_share;
trx->tmp_spider->trx = trx; trx->tmp_spider->wide_handler = tmp_wide_handler;
tmp_wide_handler->trx = trx;
trx->tmp_spider->dbton_handler = trx->tmp_dbton_handler; trx->tmp_spider->dbton_handler = trx->tmp_dbton_handler;
if (!(trx->tmp_spider->result_list.sqls = if (!(trx->tmp_spider->result_list.sqls =
new spider_string[trx->tmp_share->link_count])) new spider_string[trx->tmp_share->link_count]))
...@@ -1875,27 +1878,14 @@ int spider_start_internal_consistent_snapshot( ...@@ -1875,27 +1878,14 @@ int spider_start_internal_consistent_snapshot(
} }
int spider_internal_start_trx( int spider_internal_start_trx(
ha_spider *spider, ha_spider *spider
SPIDER_CONN *conn,
int link_idx
) { ) {
int error_num; int error_num;
SPIDER_TRX *trx = spider->trx; SPIDER_TRX *trx = spider->wide_handler->trx;
THD *thd = trx->thd; THD *thd = trx->thd;
bool sync_autocommit = spider_param_sync_autocommit(thd);
double ping_interval_at_trx_start =
spider_param_ping_interval_at_trx_start(thd);
bool xa_lock = FALSE; bool xa_lock = FALSE;
time_t tmp_time = (time_t) time((time_t*) 0);
DBUG_ENTER("spider_internal_start_trx"); DBUG_ENTER("spider_internal_start_trx");
if (
conn->server_lost ||
difftime(tmp_time, conn->ping_time) >= ping_interval_at_trx_start
) {
spider_conn_queue_ping(spider, conn, link_idx);
}
conn->disable_reconnect = TRUE;
if (!trx->trx_start) if (!trx->trx_start)
{ {
if (!trx->trx_consistent_snapshot) if (!trx->trx_consistent_snapshot)
...@@ -1906,19 +1896,7 @@ int spider_internal_start_trx( ...@@ -1906,19 +1896,7 @@ int spider_internal_start_trx(
trx->internal_xa_snapshot = spider_param_internal_xa_snapshot(thd); trx->internal_xa_snapshot = spider_param_internal_xa_snapshot(thd);
} }
} }
if ( spider->wide_handler->consistent_snapshot = FALSE;
(error_num = spider_check_and_set_sql_log_off(thd, conn,
&spider->need_mons[link_idx])) ||
(error_num = spider_check_and_set_wait_timeout(thd, conn,
&spider->need_mons[link_idx])) ||
(spider_param_sync_sql_mode(thd) &&
(error_num = spider_check_and_set_sql_mode(thd, conn,
&spider->need_mons[link_idx]))) ||
(sync_autocommit &&
(error_num = spider_check_and_set_autocommit(thd, conn,
&spider->need_mons[link_idx])))
)
goto error;
if (trx->trx_consistent_snapshot) if (trx->trx_consistent_snapshot)
{ {
if (trx->internal_xa && trx->internal_xa_snapshot < 2) if (trx->internal_xa && trx->internal_xa_snapshot < 2)
...@@ -1929,9 +1907,7 @@ int spider_internal_start_trx( ...@@ -1929,9 +1907,7 @@ int spider_internal_start_trx(
goto error; goto error;
} else if (!trx->internal_xa || trx->internal_xa_snapshot == 2) } else if (!trx->internal_xa || trx->internal_xa_snapshot == 2)
{ {
if ((error_num = spider_start_internal_consistent_snapshot(trx, conn, spider->wide_handler->consistent_snapshot = TRUE;
&spider->need_mons[link_idx])))
goto error;
} }
} }
DBUG_PRINT("info",("spider trx->trx_start= %s", DBUG_PRINT("info",("spider trx->trx_start= %s",
...@@ -1950,7 +1926,7 @@ int spider_internal_start_trx( ...@@ -1950,7 +1926,7 @@ int spider_internal_start_trx(
!trx->trx_xa && !trx->trx_xa &&
trx->internal_xa && trx->internal_xa &&
(!trx->trx_consistent_snapshot || trx->internal_xa_snapshot == 3) && (!trx->trx_consistent_snapshot || trx->internal_xa_snapshot == 3) &&
spider->sql_command != SQLCOM_LOCK_TABLES spider->wide_handler->sql_command != SQLCOM_LOCK_TABLES
) { ) {
trx->trx_xa = TRUE; trx->trx_xa = TRUE;
trx->xid.formatID = 1; trx->xid.formatID = 1;
...@@ -2003,6 +1979,54 @@ int spider_internal_start_trx( ...@@ -2003,6 +1979,54 @@ int spider_internal_start_trx(
trx->updated_in_this_trx = FALSE; trx->updated_in_this_trx = FALSE;
DBUG_PRINT("info",("spider trx->updated_in_this_trx=FALSE")); DBUG_PRINT("info",("spider trx->updated_in_this_trx=FALSE"));
} }
DBUG_RETURN(0);
error:
if (xa_lock)
spider_xa_unlock(&trx->internal_xid_state);
DBUG_RETURN(error_num);
}
int spider_internal_start_trx_for_connection(
ha_spider *spider,
SPIDER_CONN *conn,
int link_idx
) {
int error_num;
SPIDER_TRX *trx = spider->wide_handler->trx;
THD *thd = trx->thd;
bool sync_autocommit = spider_param_sync_autocommit(thd);
double ping_interval_at_trx_start =
spider_param_ping_interval_at_trx_start(thd);
time_t tmp_time = (time_t) time((time_t*) 0);
DBUG_ENTER("spider_internal_start_trx_for_connection");
if (
conn->server_lost ||
difftime(tmp_time, conn->ping_time) >= ping_interval_at_trx_start
) {
spider_conn_queue_ping(spider, conn, link_idx);
}
conn->disable_reconnect = TRUE;
if (
(error_num = spider_check_and_set_sql_log_off(thd, conn,
&spider->need_mons[link_idx])) ||
(error_num = spider_check_and_set_wait_timeout(thd, conn,
&spider->need_mons[link_idx])) ||
(spider_param_sync_sql_mode(thd) &&
(error_num = spider_check_and_set_sql_mode(thd, conn,
&spider->need_mons[link_idx]))) ||
(sync_autocommit &&
(error_num = spider_check_and_set_autocommit(thd, conn,
&spider->need_mons[link_idx])))
)
goto error;
if (spider->wide_handler->consistent_snapshot)
{
if ((error_num = spider_start_internal_consistent_snapshot(trx, conn,
&spider->need_mons[link_idx])))
goto error;
}
DBUG_PRINT("info",("spider sync_autocommit = %d", sync_autocommit)); DBUG_PRINT("info",("spider sync_autocommit = %d", sync_autocommit));
DBUG_PRINT("info",("spider conn->semi_trx_chk = %d", conn->semi_trx_chk)); DBUG_PRINT("info",("spider conn->semi_trx_chk = %d", conn->semi_trx_chk));
...@@ -2068,8 +2092,6 @@ int spider_internal_start_trx( ...@@ -2068,8 +2092,6 @@ int spider_internal_start_trx(
DBUG_RETURN(0); DBUG_RETURN(0);
error: error:
if (xa_lock)
spider_xa_unlock(&trx->internal_xid_state);
DBUG_RETURN(error_num); DBUG_RETURN(error_num);
} }
...@@ -3750,11 +3772,11 @@ int spider_check_trx_and_get_conn( ...@@ -3750,11 +3772,11 @@ int spider_check_trx_and_get_conn(
DBUG_PRINT("info",("spider get trx error")); DBUG_PRINT("info",("spider get trx error"));
DBUG_RETURN(error_num); DBUG_RETURN(error_num);
} }
spider->trx = trx; spider->wide_handler->trx = trx;
spider->set_error_mode(); spider->set_error_mode();
if ( if (
spider->sql_command != SQLCOM_DROP_TABLE && spider->wide_handler->sql_command != SQLCOM_DROP_TABLE &&
spider->sql_command != SQLCOM_ALTER_TABLE spider->wide_handler->sql_command != SQLCOM_ALTER_TABLE
) { ) {
SPIDER_TRX_HA *trx_ha = spider_check_trx_ha(trx, spider); SPIDER_TRX_HA *trx_ha = spider_check_trx_ha(trx, spider);
if (!trx_ha || trx_ha->wait_for_reusing) if (!trx_ha || trx_ha->wait_for_reusing)
...@@ -3810,9 +3832,9 @@ int spider_check_trx_and_get_conn( ...@@ -3810,9 +3832,9 @@ int spider_check_trx_and_get_conn(
SPIDER_LINK_STATUS_NG SPIDER_LINK_STATUS_NG
) { ) {
DBUG_PRINT("info",(first_byte != *spider->conn_keys[0] ? DBUG_PRINT("info",(first_byte != *spider->conn_keys[0] ?
"spider change conn type" : trx != spider->trx ? "spider change thd" : "spider change conn type" : trx != spider->wide_handler->trx ?
"spider next trx")); "spider change thd" : "spider next trx"));
spider->trx = trx; spider->wide_handler->trx = trx;
spider->trx_conn_adjustment = trx->trx_conn_adjustment; spider->trx_conn_adjustment = trx->trx_conn_adjustment;
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
if (use_conn_kind) if (use_conn_kind)
......
...@@ -126,6 +126,10 @@ int spider_start_internal_consistent_snapshot( ...@@ -126,6 +126,10 @@ int spider_start_internal_consistent_snapshot(
); );
int spider_internal_start_trx( int spider_internal_start_trx(
ha_spider *spider
);
int spider_internal_start_trx_for_connection(
ha_spider *spider, ha_spider *spider,
SPIDER_CONN *conn, SPIDER_CONN *conn,
int link_idx int link_idx
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment