~percona-dev/percona-server/5.5.11-fix-bug-764152

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# name       : show_slave_status_nolock.patch
# introduced : 12
# maintainer : Oleg
#
#!!! notice !!!
# Any small change to this file in the main branch
# should be done or reviewed by the maintainer!
diff -ruN /dev/null b/patch_info/show_slave_status_nolock.patch
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ b/patch_info/show_slave_status_nolock.patch	2011-04-10 11:29:06.000000000 +0400
@@ -0,0 +1,6 @@
+File=show_slave_status_nolock.patch
+Name= SHOW SLAVE STATUS NOLOCK
+Version=1.0
+Author=Percona <info@percona.com>
+License=GPL
+Comment= Implement SHOW SLAVE STATUS without lock (STOP SLAVE lock the same mutex what lock SHOW SLAVE STATUS)
diff -ruN a/sql/lex.h b/sql/lex.h
--- a/sql/lex.h	2011-04-10 11:29:05.000000000 +0400
+++ b/sql/lex.h	2011-04-10 11:29:06.000000000 +0400
@@ -378,6 +378,7 @@
   { "NONE",		SYM(NONE_SYM)},
   { "NOT",		SYM(NOT_SYM)},
   { "NO_WRITE_TO_BINLOG",  SYM(NO_WRITE_TO_BINLOG)},
+  { "NOLOCK",           SYM(NOLOCK_SYM)},
   { "NULL",		SYM(NULL_SYM)},
   { "NUMERIC",		SYM(NUMERIC_SYM)},
   { "NVARCHAR",		SYM(NVARCHAR_SYM)},
diff -ruN a/sql/mysqld.cc b/sql/mysqld.cc
--- a/sql/mysqld.cc	2011-04-10 11:29:05.000000000 +0400
+++ b/sql/mysqld.cc	2011-04-10 11:29:06.000000000 +0400
@@ -3075,6 +3075,7 @@
   {"show_relaylog_events", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_RELAYLOG_EVENTS]), SHOW_LONG_STATUS},
   {"show_slave_hosts",     (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_SLAVE_HOSTS]), SHOW_LONG_STATUS},
   {"show_slave_status",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_SLAVE_STAT]), SHOW_LONG_STATUS},
+  {"show_slave_status_nolock", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_SLAVE_NOLOCK_STAT]), SHOW_LONG_STATUS},
   {"show_status",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_STATUS]), SHOW_LONG_STATUS},
   {"show_storage_engines", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_STORAGE_ENGINES]), SHOW_LONG_STATUS},
   {"show_table_status",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TABLE_STATUS]), SHOW_LONG_STATUS},
diff -ruN a/sql/sql_lex.h b/sql/sql_lex.h
--- a/sql/sql_lex.h	2011-04-10 11:29:05.000000000 +0400
+++ b/sql/sql_lex.h	2011-04-10 11:29:06.000000000 +0400
@@ -190,6 +190,8 @@
   SQLCOM_SHOW_PROFILE, SQLCOM_SHOW_PROFILES,
   SQLCOM_SIGNAL, SQLCOM_RESIGNAL,
   SQLCOM_SHOW_RELAYLOG_EVENTS, 
+  /* SHOW SLAVE STATUS NOLOCK */
+  SQLCOM_SHOW_SLAVE_NOLOCK_STAT,
   /*
     When a command is added here, be sure it's also added in mysqld.cc
     in "struct show_var_st status_vars[]= {" ...
diff -ruN a/sql/sql_parse.cc b/sql/sql_parse.cc
--- a/sql/sql_parse.cc	2011-04-10 11:28:51.000000000 +0400
+++ b/sql/sql_parse.cc	2011-04-10 11:29:06.000000000 +0400
@@ -335,6 +335,7 @@
   sql_command_flags[SQLCOM_SHOW_CREATE]=  CF_STATUS_COMMAND;
   sql_command_flags[SQLCOM_SHOW_MASTER_STAT]= CF_STATUS_COMMAND;
   sql_command_flags[SQLCOM_SHOW_SLAVE_STAT]=  CF_STATUS_COMMAND;
+  sql_command_flags[SQLCOM_SHOW_SLAVE_NOLOCK_STAT]=  CF_STATUS_COMMAND;
   sql_command_flags[SQLCOM_SHOW_CREATE_PROC]= CF_STATUS_COMMAND;
   sql_command_flags[SQLCOM_SHOW_CREATE_FUNC]= CF_STATUS_COMMAND;
   sql_command_flags[SQLCOM_SHOW_CREATE_TRIGGER]=  CF_STATUS_COMMAND;
@@ -2293,12 +2294,16 @@
     mysql_mutex_unlock(&LOCK_active_mi);
     break;
   }
+  case SQLCOM_SHOW_SLAVE_NOLOCK_STAT:
   case SQLCOM_SHOW_SLAVE_STAT:
   {
     /* Accept one of two privileges */
     if (check_global_access(thd, SUPER_ACL | REPL_CLIENT_ACL))
       goto error;
-    mysql_mutex_lock(&LOCK_active_mi);
+    if(SQLCOM_SHOW_SLAVE_NOLOCK_STAT != lex->sql_command)
+    {
+      mysql_mutex_lock(&LOCK_active_mi);
+    }
     if (active_mi != NULL)
     {
       res = show_master_info(thd, active_mi);
@@ -2309,7 +2314,10 @@
                    WARN_NO_MASTER_INFO, ER(WARN_NO_MASTER_INFO));
       my_ok(thd);
     }
-    mysql_mutex_unlock(&LOCK_active_mi);
+    if(SQLCOM_SHOW_SLAVE_NOLOCK_STAT != lex->sql_command)
+    {
+      mysql_mutex_unlock(&LOCK_active_mi);
+    }
     break;
   }
   case SQLCOM_SHOW_MASTER_STAT:
diff -ruN a/sql/sql_yacc.yy b/sql/sql_yacc.yy
--- a/sql/sql_yacc.yy	2011-04-10 11:29:05.000000000 +0400
+++ b/sql/sql_yacc.yy	2011-04-10 11:29:06.000000000 +0400
@@ -1292,6 +1292,7 @@
 %token  STARTS_SYM
 %token  START_SYM                     /* SQL-2003-R */
 %token  STATUS_SYM
+%token  NOLOCK_SYM                    /* SHOW SLAVE STATUS NOLOCK */
 %token  STDDEV_SAMP_SYM               /* SQL-2003-N */
 %token  STD_SYM
 %token  STOP_SYM
@@ -11082,6 +11083,10 @@
           {
             Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
           }
+        | SLAVE STATUS_SYM NOLOCK_SYM
+          {
+	    Lex->sql_command = SQLCOM_SHOW_SLAVE_NOLOCK_STAT; //SQLCOM_SHOW_SLAVE_NOLOCK_STAT;
+          }
         | QUERY_RESPONSE_TIME_SYM wild_and_where
          {
 #ifdef HAVE_RESPONSE_TIME_DISTRIBUTION