1 # name : show_slave_status_nolock.patch
6 # Any small change to this file in the main branch
7 # should be done or reviewed by the maintainer!
9 +++ b/patch_info/show_slave_status_nolock.patch
11 +File=show_slave_status_nolock.patch
12 +Name= SHOW SLAVE STATUS NOLOCK
14 +Author=Percona <info@percona.com>
16 +Comment= Implement SHOW SLAVE STATUS without lock (STOP SLAVE lock the same mutex what lock SHOW SLAVE STATUS)
20 { "NONE", SYM(NONE_SYM)},
21 { "NOT", SYM(NOT_SYM)},
22 { "NO_WRITE_TO_BINLOG", SYM(NO_WRITE_TO_BINLOG)},
23 + { "NOLOCK", SYM(NOLOCK_SYM)},
24 { "NULL", SYM(NULL_SYM)},
25 { "NUMERIC", SYM(NUMERIC_SYM)},
26 { "NVARCHAR", SYM(NVARCHAR_SYM)},
30 {"show_relaylog_events", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_RELAYLOG_EVENTS]), SHOW_LONG_STATUS},
31 {"show_slave_hosts", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_SLAVE_HOSTS]), SHOW_LONG_STATUS},
32 {"show_slave_status", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_SLAVE_STAT]), SHOW_LONG_STATUS},
33 + {"show_slave_status_nolock", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_SLAVE_NOLOCK_STAT]), SHOW_LONG_STATUS},
34 {"show_status", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_STATUS]), SHOW_LONG_STATUS},
35 {"show_storage_engines", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_STORAGE_ENGINES]), SHOW_LONG_STATUS},
36 {"show_table_status", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TABLE_STATUS]), SHOW_LONG_STATUS},
40 SQLCOM_SHOW_PROFILE, SQLCOM_SHOW_PROFILES,
41 SQLCOM_SIGNAL, SQLCOM_RESIGNAL,
42 SQLCOM_SHOW_RELAYLOG_EVENTS,
43 + /* SHOW SLAVE STATUS NOLOCK */
44 + SQLCOM_SHOW_SLAVE_NOLOCK_STAT,
46 When a command is added here, be sure it's also added in mysqld.cc
47 in "struct show_var_st status_vars[]= {" ...
48 --- a/sql/sql_parse.cc
49 +++ b/sql/sql_parse.cc
51 sql_command_flags[SQLCOM_SHOW_CREATE]= CF_STATUS_COMMAND;
52 sql_command_flags[SQLCOM_SHOW_MASTER_STAT]= CF_STATUS_COMMAND;
53 sql_command_flags[SQLCOM_SHOW_SLAVE_STAT]= CF_STATUS_COMMAND;
54 + sql_command_flags[SQLCOM_SHOW_SLAVE_NOLOCK_STAT]= CF_STATUS_COMMAND;
55 sql_command_flags[SQLCOM_SHOW_CREATE_PROC]= CF_STATUS_COMMAND;
56 sql_command_flags[SQLCOM_SHOW_CREATE_FUNC]= CF_STATUS_COMMAND;
57 sql_command_flags[SQLCOM_SHOW_CREATE_TRIGGER]= CF_STATUS_COMMAND;
58 @@ -2359,12 +2360,16 @@
59 mysql_mutex_unlock(&LOCK_active_mi);
62 + case SQLCOM_SHOW_SLAVE_NOLOCK_STAT:
63 case SQLCOM_SHOW_SLAVE_STAT:
65 /* Accept one of two privileges */
66 if (check_global_access(thd, SUPER_ACL | REPL_CLIENT_ACL))
68 - mysql_mutex_lock(&LOCK_active_mi);
69 + if(SQLCOM_SHOW_SLAVE_NOLOCK_STAT != lex->sql_command)
71 + mysql_mutex_lock(&LOCK_active_mi);
73 if (active_mi != NULL)
75 res = show_master_info(thd, active_mi);
76 @@ -2375,7 +2380,10 @@
77 WARN_NO_MASTER_INFO, ER(WARN_NO_MASTER_INFO));
80 - mysql_mutex_unlock(&LOCK_active_mi);
81 + if(SQLCOM_SHOW_SLAVE_NOLOCK_STAT != lex->sql_command)
83 + mysql_mutex_unlock(&LOCK_active_mi);
87 case SQLCOM_SHOW_MASTER_STAT:
92 %token START_SYM /* SQL-2003-R */
94 +%token NOLOCK_SYM /* SHOW SLAVE STATUS NOLOCK */
95 %token STDDEV_SAMP_SYM /* SQL-2003-N */
98 @@ -11086,6 +11087,10 @@
100 Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
102 + | SLAVE STATUS_SYM NOLOCK_SYM
104 + Lex->sql_command = SQLCOM_SHOW_SLAVE_NOLOCK_STAT; //SQLCOM_SHOW_SLAVE_NOLOCK_STAT;
106 | QUERY_RESPONSE_TIME_SYM wild_and_where
108 #ifdef HAVE_RESPONSE_TIME_DISTRIBUTION
110 +++ b/mysql-test/r/percona_show_slave_status_nolock.result
112 +include/master-slave.inc
114 +DROP TABLE IF EXISTS t;
115 +CREATE TABLE t(id INT);
116 +INSERT INTO t SELECT SLEEP(10);
119 +Note 1592 Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave.
124 +SHOW SLAVE STATUS NOLOCK;
125 +include/wait_for_slave_to_stop.inc
127 +include/wait_for_slave_to_start.inc
132 +include/wait_for_slave_to_stop.inc
134 +++ b/mysql-test/t/percona_show_slave_status_nolock.test
136 +--source include/master-slave.inc
137 +--source include/have_binlog_format_statement.inc
139 +call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a system function that may return a different value on the slave. Statement:");
140 +call mtr.add_suppression("Slave SQL.*Request to stop slave SQL Thread received while applying a group that has non-transactional changes; waiting for completion of the group");
144 + DROP TABLE IF EXISTS t;
146 + CREATE TABLE t(id INT);
147 + sync_slave_with_master;
150 + send INSERT INTO t SELECT SLEEP(10);
159 + --disable_query_log
160 + select "master",count(*) from t;
164 + --disable_query_log
165 + select "slave",count(*) from t;
168 + --disable_result_log
169 + SHOW SLAVE STATUS NOLOCK;
170 + --enable_result_log
175 + --source include/wait_for_slave_to_stop.inc
177 + --source include/wait_for_slave_to_start.inc
179 + --disable_query_log
180 + select "slave",count(*) from t;
185 +sync_slave_with_master;
187 +--source include/wait_for_slave_to_stop.inc
189 \ No newline at end of file