From 1b3dc66e3117a09c95a00be2f649b975fdb25e2e Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 28 Jun 2013 15:19:30 +0200 Subject: MDEV-4506: Parallel replication: Intermediate commit. First step of splitting out part of Relay_log_info, so that different event groups being applied in parallel can each use their own copy. --- sql/rpl_gtid.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'sql/rpl_gtid.cc') diff --git a/sql/rpl_gtid.cc b/sql/rpl_gtid.cc index 71b18e64842..54d3b704a2c 100644 --- a/sql/rpl_gtid.cc +++ b/sql/rpl_gtid.cc @@ -65,17 +65,18 @@ int rpl_slave_state::record_and_update_gtid(THD *thd, Relay_log_info *rli) { uint64 sub_id; + struct rpl_group_info *rgi; /* Update the GTID position, if we have it and did not already update it in a GTID transaction. */ - if ((sub_id= rli->gtid_sub_id)) + if ((rgi= rli->group_info) && (sub_id= rgi->gtid_sub_id)) { - rli->gtid_sub_id= 0; - if (record_gtid(thd, &rli->current_gtid, sub_id, false, false)) + rgi->gtid_sub_id= 0; + if (record_gtid(thd, &rgi->current_gtid, sub_id, false, false)) return 1; - update_state_hash(sub_id, &rli->current_gtid); + update_state_hash(sub_id, &rgi->current_gtid); } return 0; } -- cgit v1.2.1 From 592e464a021747d7ac5b13222f5de1cd4250531c Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 3 Jul 2013 19:03:21 +0200 Subject: MDEV-4506: Parallel replication. Intermediate commit. Pass down rpl_group_info * to remove one instance of non-threadsafe use of rli->group_info. --- sql/rpl_gtid.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'sql/rpl_gtid.cc') diff --git a/sql/rpl_gtid.cc b/sql/rpl_gtid.cc index 54d3b704a2c..bc826e9bdb5 100644 --- a/sql/rpl_gtid.cc +++ b/sql/rpl_gtid.cc @@ -62,16 +62,15 @@ rpl_slave_state::update_state_hash(uint64 sub_id, rpl_gtid *gtid) int -rpl_slave_state::record_and_update_gtid(THD *thd, Relay_log_info *rli) +rpl_slave_state::record_and_update_gtid(THD *thd, struct rpl_group_info *rgi) { uint64 sub_id; - struct rpl_group_info *rgi; /* Update the GTID position, if we have it and did not already update it in a GTID transaction. */ - if ((rgi= rli->group_info) && (sub_id= rgi->gtid_sub_id)) + if ((sub_id= rgi->gtid_sub_id)) { rgi->gtid_sub_id= 0; if (record_gtid(thd, &rgi->current_gtid, sub_id, false, false)) -- cgit v1.2.1 From d107bdaa01ad34b1afb4542b981b9b19af499f7b Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Sep 2013 15:09:57 +0200 Subject: MDEV-4506, parallel replication. Some after-review fixes. --- sql/rpl_gtid.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/rpl_gtid.cc') diff --git a/sql/rpl_gtid.cc b/sql/rpl_gtid.cc index bc826e9bdb5..a1b14ad3255 100644 --- a/sql/rpl_gtid.cc +++ b/sql/rpl_gtid.cc @@ -62,7 +62,7 @@ rpl_slave_state::update_state_hash(uint64 sub_id, rpl_gtid *gtid) int -rpl_slave_state::record_and_update_gtid(THD *thd, struct rpl_group_info *rgi) +rpl_slave_state::record_and_update_gtid(THD *thd, rpl_group_info *rgi) { uint64 sub_id; -- cgit v1.2.1 From 2e100cc5a493b6a0f6f907e0483a734c7fee2087 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Mon, 14 Oct 2013 00:24:05 +0300 Subject: Fixes for parallel slave: - Made slaves temporary table multi-thread slave safe by adding mutex around save_temporary_table usage. - rli->save_temporary_tables is the active list of all used temporary tables - This is copied to THD->temporary_tables when temporary tables are opened and updated when temporary tables are closed - Added THD->lock_temporary_tables() and THD->unlock_temporary_tables() to simplify this. - Relay_log_info->sql_thd renamed to Relay_log_info->sql_driver_thd to avoid wrong usage for merged code. - Added is_part_of_group() to mark functions that are part of the next function. This replaces setting IN_STMT when events are executed. - Added is_begin(), is_commit() and is_rollback() functions to Query_log_event to simplify code. - If slave_skip_counter is set run things in single threaded mode. This simplifies code for skipping events. - Updating state of relay log (IN_STMT and IN_TRANSACTION) is moved to one single function: update_state_of_relay_log() We can't use OPTION_BEGIN to check for the state anymore as the sql_driver and sql execution threads may be different. Clear IN_STMT and IN_TRANSACTION in init_relay_log_pos() and Relay_log_info::cleanup_context() to ensure the flags doesn't survive slave restarts is_in_group() is now independent of state of executed transaction. - Reset thd->transaction.all.modified_non_trans_table() if we did set it for single table row events. This was mainly for keeping the flag as documented. - Changed slave_open_temp_tables to uint32 to be able to use atomic operators on it. - Relay_log_info::sleep_lock -> rpl_group_info::sleep_lock - Relay_log_info::sleep_cond -> rpl_group_info::sleep_cond - Changed some functions to take rpl_group_info instead of Relay_log_info to make them multi-slave safe and to simplify usage - do_shall_skip() - continue_group() - sql_slave_killed() - next_event() - Simplifed arguments to io_salve_killed(), check_io_slave_killed() and sql_slave_killed(); No reason to supply THD as this is part of the given structure. - set_thd_in_use_temporary_tables() removed as in_use is set on usage - Added information to thd_proc_info() which thread is waiting for slave mutex to exit. - In open_table() reuse code from find_temporary_table() Other things: - More DBUG statements - Fixed the rpl_incident.test can be run with --debug - More comments - Disabled not used function rpl_connect_master() mysql-test/suite/perfschema/r/all_instances.result: Moved sleep_lock and sleep_cond to rpl_group_info mysql-test/suite/rpl/r/rpl_incident.result: Updated result mysql-test/suite/rpl/t/rpl_incident-master.opt: Not needed anymore mysql-test/suite/rpl/t/rpl_incident.test: Fixed that test can be run with --debug sql/handler.cc: More DBUG_PRINT sql/log.cc: More comments sql/log_event.cc: Added DBUG statements do_shall_skip(), continue_group() now takes rpl_group_info param Use is_begin(), is_commit() and is_rollback() functions instead of inspecting query string We don't have set slaves temporary tables 'in_use' as this is now done when tables are opened. Removed IN_STMT flag setting. This is now done in update_state_of_relay_log() Use IN_TRANSACTION flag to test state of relay log. In rows_event_stmt_cleanup() reset thd->transaction.all.modified_non_trans_table if we had set this before. sql/log_event.h: do_shall_skip(), continue_group() now takes rpl_group_info param Added is_part_of_group() to mark events that are part of the next event. This replaces setting IN_STMT when events are executed. Added is_begin(), is_commit() and is_rollback() functions to Query_log_event to simplify code. sql/log_event_old.cc: Removed IN_STMT flag setting. This is now done in update_state_of_relay_log() do_shall_skip(), continue_group() now takes rpl_group_info param sql/log_event_old.h: Added is_part_of_group() to mark events that are part of the next event. do_shall_skip(), continue_group() now takes rpl_group_info param sql/mysqld.cc: Changed slave_open_temp_tables to uint32 to be able to use atomic operators on it. Relay_log_info::sleep_lock -> Rpl_group_info::sleep_lock Relay_log_info::sleep_cond -> Rpl_group_info::sleep_cond sql/mysqld.h: Updated types and names sql/rpl_gtid.cc: More DBUG sql/rpl_parallel.cc: Updated TODO section Set thd for event that is execution Use new is_begin(), is_commit() and is_rollback() functions. More comments sql/rpl_rli.cc: sql_thd -> sql_driver_thd Relay_log_info::sleep_lock -> rpl_group_info::sleep_lock Relay_log_info::sleep_cond -> rpl_group_info::sleep_cond Clear IN_STMT and IN_TRANSACTION in init_relay_log_pos() and Relay_log_info::cleanup_context() to ensure the flags doesn't survive slave restarts. Reset table->in_use for temporary tables as the table may have been used by another THD. Use IN_TRANSACTION instead of OPTION_BEGIN to check state of relay log. Removed IN_STMT flag setting. This is now done in update_state_of_relay_log() sql/rpl_rli.h: Changed relay log state flags to bit masks instead of bit positions (most other code we have uses bit masks) Added IN_TRANSACTION to mark if we are in a BEGIN ... COMMIT section. save_temporary_tables is now thread safe Relay_log_info::sleep_lock -> rpl_group_info::sleep_lock Relay_log_info::sleep_cond -> rpl_group_info::sleep_cond Relay_log_info->sql_thd renamed to Relay_log_info->sql_driver_thd to avoid wrong usage for merged code is_in_group() is now independent of state of executed transaction. sql/slave.cc: Simplifed arguments to io_salve_killed(), sql_slave_killed() and check_io_slave_killed(); No reason to supply THD as this is part of the given structure. set_thd_in_use_temporary_tables() removed as in_use is set on usage in sql_base.cc sql_thd -> sql_driver_thd More DBUG Added update_state_of_relay_log() which will calculate the IN_STMT and IN_TRANSACTION state of the relay log after the current element is executed. If slave_skip_counter is set run things in single threaded mode. Simplifed arguments to io_salve_killed(), check_io_slave_killed() and sql_slave_killed(); No reason to supply THD as this is part of the given structure. Added information to thd_proc_info() which thread is waiting for slave mutex to exit. Disabled not used function rpl_connect_master() Updated argument to next_event() sql/sql_base.cc: Added mutex around usage of slave's temporary tables. The active list is always kept up to date in sql->rgi_slave->save_temporary_tables. Clear thd->temporary_tables after query (safety) More DBUG When using temporary table, set table->in_use to current thd as the THD may be different for slave threads. Some code is ifdef:ed with REMOVE_AFTER_MERGE_WITH_10 as the given code in 10.0 is not yet in this tree. In open_table() reuse code from find_temporary_table() sql/sql_binlog.cc: rli->sql_thd -> rli->sql_driver_thd Remove duplicate setting of rgi->rli sql/sql_class.cc: Added helper functions rgi_lock_temporary_tables() and rgi_unlock_temporary_tables() Would have been nicer to have these inline, but there was no easy way to do that sql/sql_class.h: Added functions to protect slaves temporary tables sql/sql_parse.cc: Added DBUG_PRINT sql/transaction.cc: Added comment --- sql/rpl_gtid.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'sql/rpl_gtid.cc') diff --git a/sql/rpl_gtid.cc b/sql/rpl_gtid.cc index a1b14ad3255..1e393eab502 100644 --- a/sql/rpl_gtid.cc +++ b/sql/rpl_gtid.cc @@ -65,6 +65,7 @@ int rpl_slave_state::record_and_update_gtid(THD *thd, rpl_group_info *rgi) { uint64 sub_id; + DBUG_ENTER("rpl_slave_state::record_and_update_gtid"); /* Update the GTID position, if we have it and did not already update @@ -74,10 +75,10 @@ rpl_slave_state::record_and_update_gtid(THD *thd, rpl_group_info *rgi) { rgi->gtid_sub_id= 0; if (record_gtid(thd, &rgi->current_gtid, sub_id, false, false)) - return 1; + DBUG_RETURN(1); update_state_hash(sub_id, &rgi->current_gtid); } - return 0; + DBUG_RETURN(0); } @@ -310,6 +311,7 @@ rpl_slave_state::record_gtid(THD *thd, const rpl_gtid *gtid, uint64 sub_id, element *elem; ulonglong thd_saved_option= thd->variables.option_bits; Query_tables_list lex_backup; + DBUG_ENTER("record_gtid"); if (unlikely(!loaded)) { @@ -320,7 +322,7 @@ rpl_slave_state::record_gtid(THD *thd, const rpl_gtid *gtid, uint64 sub_id, We already complained loudly about this, but we can try to continue until the DBA fixes it. */ - return 0; + DBUG_RETURN(0); } if (!in_statement) @@ -329,7 +331,7 @@ rpl_slave_state::record_gtid(THD *thd, const rpl_gtid *gtid, uint64 sub_id, DBUG_EXECUTE_IF("gtid_inject_record_gtid", { my_error(ER_CANNOT_UPDATE_GTID_STATE, MYF(0)); - return 1; + DBUG_RETURN(1); } ); thd->lex->reset_n_backup_query_tables_list(&lex_backup); @@ -347,8 +349,11 @@ rpl_slave_state::record_gtid(THD *thd, const rpl_gtid *gtid, uint64 sub_id, table->no_replicate= 1; if (!in_transaction) + { + DBUG_PRINT("info", ("resetting OPTION_BEGIN")); thd->variables.option_bits&= ~(ulonglong)(OPTION_NOT_AUTOCOMMIT|OPTION_BEGIN); + } bitmap_set_all(table->write_set); @@ -457,7 +462,7 @@ end: } thd->lex->restore_backup_query_tables_list(&lex_backup); thd->variables.option_bits= thd_saved_option; - return err; + DBUG_RETURN(err); } -- cgit v1.2.1 From 6a38b594759c41bd3d45ad89379ff38864bd4ba4 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 25 Oct 2013 21:17:14 +0200 Subject: MDEV-5189: Incorrect parallel apply in parallel replication Two problems were fixed: 1. When not in GTID mode (master_use_gtid=no), then we must not apply events in different domains in parallel (in non-GTID mode we are not capable of restarting at different points in different domains). 2. When transactions B and C group commit together, but after and separate from A, we can apply B and C in parallel, but both B and C must not start until A has committed. Fix sub_id to be globally increasing (not just per-domain increasing) so that this wait (which is based on sub_id) can be done correctly. --- sql/rpl_gtid.cc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'sql/rpl_gtid.cc') diff --git a/sql/rpl_gtid.cc b/sql/rpl_gtid.cc index 1e393eab502..da90dcf641a 100644 --- a/sql/rpl_gtid.cc +++ b/sql/rpl_gtid.cc @@ -83,7 +83,7 @@ rpl_slave_state::record_and_update_gtid(THD *thd, rpl_group_info *rgi) rpl_slave_state::rpl_slave_state() - : inited(false), loaded(false) + : last_sub_id(0), inited(false), loaded(false) { my_hash_init(&hash, &my_charset_bin, 32, offsetof(element, domain_id), sizeof(uint32), NULL, my_free, HASH_UNIQUE); @@ -153,6 +153,9 @@ rpl_slave_state::update(uint32 domain_id, uint32 server_id, uint64 sub_id, list_elem->seq_no= seq_no; elem->add(list_elem); + if (last_sub_id < sub_id) + last_sub_id= sub_id; + return 0; } @@ -169,7 +172,6 @@ rpl_slave_state::get_element(uint32 domain_id) if (!(elem= (element *)my_malloc(sizeof(*elem), MYF(MY_WME)))) return NULL; elem->list= NULL; - elem->last_sub_id= 0; elem->domain_id= domain_id; if (my_hash_insert(&hash, (uchar *)elem)) { @@ -469,13 +471,10 @@ end: uint64 rpl_slave_state::next_subid(uint32 domain_id) { - uint32 sub_id= 0; - element *elem; + uint32 sub_id; lock(); - elem= get_element(domain_id); - if (elem) - sub_id= ++elem->last_sub_id; + sub_id= ++last_sub_id; unlock(); return sub_id; -- cgit v1.2.1