~percona-dev/percona-server/5.1.57-fix_bug_785564

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
115
116
# 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 a/patch_info/show_slave_status_nolock.patch b/patch_info/show_slave_status_nolock.patch
--- a/patch_info/show_slave_status_nolock.patch	1970-01-01 05:00:00.000000000 +0500
+++ b/patch_info/show_slave_status_nolock.patch	2010-10-29 14:44:13.000000000 +0600
@@ -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	2010-10-29 14:39:13.000000000 +0600
+++ b/sql/lex.h	2010-10-29 14:41:48.000000000 +0600
@@ -367,6 +367,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	2010-11-17 18:45:47.000000000 +0300
+++ b/sql/mysqld.cc	2010-11-17 18:46:55.000000000 +0300
@@ -3263,6 +3263,7 @@
   {"show_profiles",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_PROFILES]), 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_statistics",(char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TABLE_STATS]), SHOW_LONG_STATUS},
diff -ruN a/sql/sql_lex.h b/sql/sql_lex.h
--- a/sql/sql_lex.h	2010-10-29 14:39:13.000000000 +0600
+++ b/sql/sql_lex.h	2010-10-29 14:41:56.000000000 +0600
@@ -119,7 +119,8 @@
   SQLCOM_ALTER_DB_UPGRADE, SQLCOM_SHOW_TEMPORARY_TABLES,
   SQLCOM_SHOW_PROFILE, SQLCOM_SHOW_PROFILES,
   SQLCOM_SHOW_PATCHES,
-
+  /* 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	2010-10-29 14:39:13.000000000 +0600
+++ b/sql/sql_parse.cc	2010-10-29 14:42:03.000000000 +0600
@@ -327,6 +327,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;
@@ -2560,12 +2561,16 @@
     pthread_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;
-    pthread_mutex_lock(&LOCK_active_mi);
+    if(SQLCOM_SHOW_SLAVE_NOLOCK_STAT != lex->sql_command)
+    {
+      pthread_mutex_lock(&LOCK_active_mi);
+    }
     if (active_mi != NULL)
     {
       res = show_master_info(thd, active_mi);
@@ -2576,7 +2581,10 @@
                    WARN_NO_MASTER_INFO, ER(WARN_NO_MASTER_INFO));
       my_ok(thd);
     }
-    pthread_mutex_unlock(&LOCK_active_mi);
+    if(SQLCOM_SHOW_SLAVE_NOLOCK_STAT != lex->sql_command)
+    {
+      pthread_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	2010-10-29 14:39:13.000000000 +0600
+++ b/sql/sql_yacc.yy	2010-10-29 14:41:39.000000000 +0600
@@ -1173,6 +1173,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
@@ -10367,6 +10368,11 @@
           {
             Lex->sql_command = SQLCOM_SHOW_SLAVE_STAT;
           }
+	/* SHOW SLAVE STATUS NOLOCK */
+        | SLAVE STATUS_SYM NOLOCK_SYM
+          {
+	    Lex->sql_command = SQLCOM_SHOW_SLAVE_NOLOCK_STAT; //SQLCOM_SHOW_SLAVE_NOLOCK_STAT;
+          }
         | CLIENT_STATS_SYM wild_and_where 
           {
            LEX *lex= Lex;