#At file:///home/andrei/MySQL/BZR/2a-23May/WL/mysql-next-mr-wl5569/ based on revid:andrei.elkin@stripped
3280 Andrei Elkin 2011-05-25
WL#5569 MTS
WL#5754 Query event parallel applying
The current patch addresses concurrent updating slave_open_temp_tables
status counter.
The former declaration of the underlying server variable is changed from
ulong to int32. While that might affect (shrink) the actual range, there is
no specified range and now after the number of bits is the same on all platforms
the range cat be set to be
[0, max(int32)]
@ mysql-test/suite/rpl/r/rpl_parallel_temp_query.result
results got updated.
@ mysql-test/suite/rpl/t/rpl_parallel_temp_query.test
Adding logics to watch Slave_open_temp_tables in face of its concurrent updating.
@ sql/mysqld.cc
Turning slave_open_temp_tables from ulong to int32 and adding
atomic locks declaration for the counter updating.
@ sql/mysqld.h
Extern-lizing slave_open_temp_tables_lock;
@ sql/rpl_rli.cc
Initializing/destorying slave_open_temp_tables lock at the same time
with Workers.
@ sql/rpl_slave.cc
Adding info message to the error log;
improving comments.
@ sql/sql_base.cc
Replacing slave opened temp tables counter incr/decr with a function
perfoming atomic locking in case Worker runs it.
modified:
mysql-test/suite/rpl/r/rpl_parallel_temp_query.result
mysql-test/suite/rpl/t/rpl_parallel_temp_query.test
sql/mysqld.cc
sql/mysqld.h
sql/rpl_rli.cc
sql/rpl_slave.cc
sql/sql_base.cc
=== modified file 'mysql-test/suite/rpl/r/rpl_parallel_temp_query.result'
--- a/mysql-test/suite/rpl/r/rpl_parallel_temp_query.result 2011-02-27 17:35:25 +0000
+++ b/mysql-test/suite/rpl/r/rpl_parallel_temp_query.result 2011-05-25 07:35:49 +0000
@@ -1,6 +1,7 @@
include/master-slave.inc
[connection master]
call mtr.add_suppression('Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement accesses nontransactional table as well as transactional or temporary table.*');
+flush status;
include/stop_slave.inc
set @save.mts_slave_parallel_workers= @@global.mts_slave_parallel_workers;
set @@global.mts_slave_parallel_workers= 4;
=== modified file 'mysql-test/suite/rpl/t/rpl_parallel_temp_query.test'
--- a/mysql-test/suite/rpl/t/rpl_parallel_temp_query.test 2011-02-27 17:35:25 +0000
+++ b/mysql-test/suite/rpl/t/rpl_parallel_temp_query.test 2011-05-25 07:35:49 +0000
@@ -14,6 +14,8 @@ let $workers= 4;
connection slave;
+flush status; # to nullify Slave_open_temp_tables
+
# restart in Parallel
source include/stop_slave.inc;
set @save.mts_slave_parallel_workers= @@global.mts_slave_parallel_workers;
@@ -41,7 +43,8 @@ while ($n)
{
let $temp_rows= `select round(rand()*$temp_tables) + 1`;
let $k= $temp_rows;
- eval create temporary table tt_$i (a int auto_increment primary key);
+ # create makes a table in explicit db
+ eval create temporary table d$n1.tt_$i (a int auto_increment primary key);
while($k)
{
eval insert into tt_$i values (null);
@@ -74,6 +77,7 @@ while ($n)
{
let $temp_rows= `select round(rand()*$temp_tables) + 1`;
let $k= $temp_rows;
+ # create makes a table in the default db
eval create temporary table tt_$i (a int auto_increment primary key);
while($k)
{
@@ -93,6 +97,14 @@ while ($n)
sync_slave_with_master;
+if (`select variable_value - $workers*$temp_tables as must_be_zero from information_schema.global_status where variable_name like 'Slave_open_temp_tables'`)
+{
+ --let $actual_temps= `select variable_value from information_schema.global_status where variable_name like 'Slave_open_temp_tables'`
+ --let $exected= `select $workers*$temp_tables`
+ --echo *** Wrong value of Slave_open_temp_tables: got $actual_temps, expected $expected ***
+ --die
+}
+
#
# Consistency check
#
=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc 2011-02-27 17:35:25 +0000
+++ b/sql/mysqld.cc 2011-05-25 07:35:49 +0000
@@ -459,7 +459,8 @@ ulong thread_created;
ulong back_log, connect_timeout, concurrency, server_id;
ulong table_cache_size, table_def_size;
ulong what_to_log;
-ulong slow_launch_time, slave_open_temp_tables;
+ulong slow_launch_time;
+int32 slave_open_temp_tables;
ulong open_files_limit, max_binlog_size, max_relay_log_size;
ulong slave_trans_retries;
uint slave_net_timeout;
@@ -482,6 +483,7 @@ ulong refresh_version; /* Increments on
query_id_t global_query_id;
my_atomic_rwlock_t global_query_id_lock;
my_atomic_rwlock_t thread_running_lock;
+my_atomic_rwlock_t slave_open_temp_tables_lock;
ulong aborted_threads, aborted_connects;
ulong delayed_insert_timeout, delayed_insert_limit, delayed_queue_size;
ulong delayed_insert_threads, delayed_insert_writes, delayed_rows_in_use;
@@ -6734,7 +6736,7 @@ SHOW_VAR status_vars[]= {
{"Select_range", (char*) offsetof(STATUS_VAR, select_range_count), SHOW_LONG_STATUS},
{"Select_range_check", (char*) offsetof(STATUS_VAR, select_range_check_count), SHOW_LONG_STATUS},
{"Select_scan", (char*) offsetof(STATUS_VAR, select_scan_count), SHOW_LONG_STATUS},
- {"Slave_open_temp_tables", (char*) &slave_open_temp_tables, SHOW_LONG},
+ {"Slave_open_temp_tables", (char*) &slave_open_temp_tables, SHOW_INT},
#ifdef HAVE_REPLICATION
{"Slave_retried_transactions",(char*) &show_slave_retried_trans, SHOW_FUNC},
{"Slave_heartbeat_period", (char*) &show_heartbeat_period, SHOW_FUNC},
=== modified file 'sql/mysqld.h'
--- a/sql/mysqld.h 2011-02-27 17:35:25 +0000
+++ b/sql/mysqld.h 2011-05-25 07:35:49 +0000
@@ -168,7 +168,7 @@ extern ulong delayed_insert_timeout;
extern ulong delayed_insert_limit, delayed_queue_size;
extern ulong delayed_insert_threads, delayed_insert_writes;
extern ulong delayed_rows_in_use,delayed_insert_errors;
-extern ulong slave_open_temp_tables;
+extern int32 slave_open_temp_tables;
extern ulong query_cache_size, query_cache_min_res_unit;
extern ulong slow_launch_threads, slow_launch_time;
extern ulong table_cache_size, table_def_size;
@@ -360,6 +360,7 @@ extern mysql_cond_t COND_thread_count;
extern mysql_cond_t COND_manager;
extern int32 thread_running;
extern my_atomic_rwlock_t thread_running_lock;
+extern my_atomic_rwlock_t slave_open_temp_tables_lock;
extern char *opt_ssl_ca, *opt_ssl_capath, *opt_ssl_cert, *opt_ssl_cipher,
*opt_ssl_key;
=== modified file 'sql/rpl_rli.cc'
--- a/sql/rpl_rli.cc 2011-05-24 14:29:35 +0000
+++ b/sql/rpl_rli.cc 2011-05-25 07:35:49 +0000
@@ -135,6 +135,7 @@ void Relay_log_info::init_workers(ulong
mysql_mutex_init(key_mutex_mts_temp_tables_lock, &mts_temp_tables_lock,
MY_MUTEX_INIT_FAST);
my_init_dynamic_array(&workers, sizeof(Slave_worker *), slave_parallel_workers, 4);
+ my_atomic_rwlock_init(&slave_open_temp_tables_lock);
}
/**
@@ -147,6 +148,7 @@ void Relay_log_info::deinit_workers()
mysql_mutex_destroy(&mts_temp_tables_lock);
delete_dynamic(&workers);
+ my_atomic_rwlock_destroy(&slave_open_temp_tables_lock);
}
Relay_log_info::~Relay_log_info()
=== modified file 'sql/rpl_slave.cc'
--- a/sql/rpl_slave.cc 2011-05-24 14:29:35 +0000
+++ b/sql/rpl_slave.cc 2011-05-25 07:35:49 +0000
@@ -4345,7 +4345,11 @@ err:
}
/*
- Worker threads ends one-by-one with synch through rli->pending_jobs
+ Ending Worker threads.
+
+ Workers are notified with setting KILLED status
+ and waited for their acknowledgment as specified by
+ a "magic" (out-of-operational range) value of w->jobs.len.
*/
void slave_stop_workers(Relay_log_info *rli)
{
@@ -4368,6 +4372,7 @@ void slave_stop_workers(Relay_log_info *
continue;
}
mysql_mutex_unlock(&w->jobs_lock);
+ sql_print_information("Notifying Worker %lu to exit", w->id);
mysql_mutex_lock(&w->info_thd->LOCK_thd_data);
w->info_thd->awake(THD::KILL_QUERY);
=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc 2011-05-24 14:29:35 +0000
+++ b/sql/sql_base.cc 2011-05-25 07:35:49 +0000
@@ -125,6 +125,22 @@ static void init_tdc_psi_keys(void)
}
#endif /* HAVE_PSI_INTERFACE */
+static int32 incr_slave_open_temp_tables(THD *thd, int inc)
+{
+ int32 ret;
+
+ if (thd->system_thread == SYSTEM_THREAD_SLAVE_WORKER)
+ {
+ my_atomic_rwlock_wrlock(&slave_open_temp_tables_lock);
+ ret= my_atomic_add32(&slave_open_temp_tables, inc);
+ my_atomic_rwlock_wrlock(&slave_open_temp_tables_unlock);
+ ret += inc;
+ }
+ else
+ ret= (slave_open_temp_tables += inc);
+
+ return ret;
+}
/**
Total number of TABLE instances for tables in the table definition cache
@@ -2133,7 +2149,7 @@ void close_temporary_table(THD *thd, TAB
{
/* natural invariant of temporary_tables */
DBUG_ASSERT(slave_open_temp_tables || !thd->temporary_tables);
- slave_open_temp_tables--;
+ incr_slave_open_temp_tables(thd, -1);
}
close_temporary(table, free_share, delete_table);
DBUG_VOID_RETURN;
@@ -5858,7 +5874,7 @@ TABLE *open_table_uncached(THD *thd, con
thd->temporary_tables= tmp_table;
thd->temporary_tables->prev= 0;
if (thd->slave_thread)
- slave_open_temp_tables++;
+ incr_slave_open_temp_tables(thd, 1);
}
tmp_table->pos_in_table_list= 0;
DBUG_PRINT("tmptable", ("opened table: '%s'.'%s' 0x%lx", tmp_table->s->db.str,
Attachment: [text/bzr-bundle] bzr/andrei.elkin@oracle.com-20110525073549-ov7d8fdfs9x20rw3.bundle
| Thread |
|---|
| • bzr commit into mysql-next-mr-wl5569 branch (andrei.elkin:3280) WL#5569WL#5754 | Andrei Elkin | 25 May |