~maria-captains/maria/mysql-6.0-backup

« back to all changes in this revision

Viewing changes to mysql-test/suite/rpl/t/rpl_slow_query_log.test

  • Committer: Thava Alagu
  • Date: 2010-03-11 19:18:17 UTC
  • mfrom: (3719.14.62 mysql-6.0-codebase)
  • Revision ID: thavamuni.alagu@sun.com-20100311191817-5nigmq884xo9fuut
Merge from mysql-6.0-codebase

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# BUG#23300: Slow query log on slave does not log slow replicated statements
3
 
#
4
 
# Description:
5
 
#   The slave should log slow queries replicated from master when
6
 
#   --log-slow-slave-statements is used.
7
 
#
8
 
#   Test is implemented as follows:
9
 
#      i) stop slave
10
 
#     ii) On slave, set long_query_time to a small value.
11
 
#     ii) start slave so that long_query_time variable is picked by sql thread
12
 
#    iii) On master, do one short time query and one long time query, on slave
13
 
#         and check that slow query is logged to slow query log but fast query 
14
 
#         is not.
15
 
#     iv) On slave, check that slow queries go into the slow log and fast dont,
16
 
#         when issued through a regular client connection
17
 
#      v) On slave, check that slow queries go into the slow log and fast dont
18
 
#         when we use SET TIMESTAMP= 1 on a regular client connection.
19
 
#     vi) check that when setting slow_query_log= OFF in a connection 'extra2'
20
 
#         prevents logging slow queries in a connection 'extra'
21
 
#
22
 
# OBS: 
23
 
#   This test only runs for statement binlogging format because on row format
24
 
#   slow queries do not get slow query logged. 
25
 
#   Note that due to the sleep() command the insert is written to the binary
26
 
#   log in row format.
27
 
 
28
 
source include/master-slave.inc;
29
 
source include/have_binlog_format_statement.inc;
30
 
 
31
 
CALL mtr.add_suppression("Unsafe statement binlogged in statement format since BINLOG_FORMAT = STATEMENT");
32
 
 
33
 
# Prepare slave for different long_query_time we need to stop the slave 
34
 
# and restart it as long_query_time variable is dynamic and, after 
35
 
# setting it, it only takes effect on new connections. 
36
 
#
37
 
# Reference: 
38
 
#   http://dev.mysql.com/doc/refman/6.0/en/set-option.html
39
 
connection slave;
40
 
 
41
 
source include/stop_slave.inc;
42
 
 
43
 
SET @old_log_output= @@log_output;
44
 
SET GLOBAL log_output= 'TABLE';
45
 
SET @old_long_query_time= @@long_query_time;
46
 
SET GLOBAL long_query_time= 2;
47
 
TRUNCATE mysql.slow_log;
48
 
 
49
 
source include/start_slave.inc;
50
 
 
51
 
connection master;
52
 
CREATE TABLE t1 (a int, b int); 
53
 
 
54
 
# test:
55
 
#   check that slave logs the slow query to the slow log, but not the fast one.
56
 
 
57
 
let $slow_query= INSERT INTO t1 values(1, sleep(3));
58
 
let $fast_query= INSERT INTO t1 values(1, 1);
59
 
 
60
 
eval $fast_query;
61
 
--disable_warnings
62
 
eval $slow_query;
63
 
--enable_warnings
64
 
sync_slave_with_master;
65
 
 
66
 
let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
67
 
let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
68
 
 
69
 
if ($found_fast_query)
70
 
{
71
 
  SELECT * FROM mysql.slow_log;
72
 
  die "Assertion failed! Fast query FOUND in slow query log. Bailing out!";
73
 
}
74
 
 
75
 
if (!$found_slow_query)
76
 
{
77
 
  SELECT * FROM mysql.slow_log;
78
 
  die "Assertion failed! Slow query NOT FOUND in slow query log. Bailing out!";
79
 
}
80
 
TRUNCATE mysql.slow_log;
81
 
 
82
 
# regular checks for slow query log (using a new connection - 'extra' - to slave)
83
 
 
84
 
# test: 
85
 
#   when using direct connections to the slave, check that slow query is logged 
86
 
#   but not the fast one.
87
 
 
88
 
connect(extra,127.0.0.1,root,,test,$SLAVE_MYPORT);
89
 
connection extra;
90
 
 
91
 
let $fast_query= SELECT 1;
92
 
let $slow_query= SELECT 1, sleep(3);
93
 
 
94
 
eval $slow_query;
95
 
eval $fast_query;
96
 
 
97
 
let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
98
 
let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
99
 
 
100
 
if ($found_fast_query)
101
 
{
102
 
  SELECT * FROM mysql.slow_log;
103
 
  die "Assertion failed! Fast query FOUND in slow query log. Bailing out!";
104
 
}
105
 
 
106
 
if (!$found_slow_query)
107
 
{
108
 
  SELECT * FROM mysql.slow_log;
109
 
  die "Assertion failed! Slow query NOT FOUND in slow query log. Bailing out!";
110
 
}
111
 
TRUNCATE mysql.slow_log;
112
 
 
113
 
# test:
114
 
#   when using direct connections to the slave, check that when setting timestamp to 1 the 
115
 
#   slow query is logged but the fast one is not.
116
 
 
117
 
let $fast_query= SELECT 2;
118
 
let $slow_query= SELECT 2, sleep(3);
119
 
 
120
 
SET TIMESTAMP= 1;
121
 
eval $slow_query;
122
 
eval $fast_query;
123
 
 
124
 
let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
125
 
let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
126
 
 
127
 
if ($found_fast_query)
128
 
{
129
 
  SELECT * FROM mysql.slow_log;
130
 
  die "Assertion failed! Fast query FOUND in slow query log. Bailing out!";
131
 
}
132
 
 
133
 
if (!$found_slow_query)
134
 
{
135
 
  SELECT * FROM mysql.slow_log;
136
 
  die "Assertion failed! Slow query NOT FOUND in slow query log. Bailing out!";
137
 
}
138
 
TRUNCATE mysql.slow_log;
139
 
 
140
 
# test: 
141
 
#   check that when setting the slow_query_log= OFF on connection 'extra2'
142
 
#   prevents connection 'extra' from logging to slow query log.
143
 
 
144
 
let $fast_query= SELECT 3;
145
 
let $slow_query= SELECT 3, sleep(3);
146
 
 
147
 
connect(extra2,127.0.0.1,root,,test,$SLAVE_MYPORT);
148
 
connection extra2;
149
 
 
150
 
SET @old_slow_query_log= @@slow_query_log;
151
 
SET GLOBAL slow_query_log= 'OFF';
152
 
 
153
 
connection extra;
154
 
 
155
 
eval $slow_query;
156
 
eval $fast_query;
157
 
 
158
 
let $found_fast_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$fast_query'`;
159
 
let $found_slow_query= `SELECT count(*) = 1 FROM mysql.slow_log WHERE sql_text like '$slow_query'`;
160
 
 
161
 
if ($found_fast_query)
162
 
{
163
 
  SELECT * FROM mysql.slow_log;
164
 
  die "Assertion failed! Fast query FOUND in slow query log when slow_query_log= OFF. Bailing out!";
165
 
}
166
 
 
167
 
if ($found_slow_query)
168
 
{
169
 
  SELECT * FROM mysql.slow_log;
170
 
  die "Assertion failed! Slow query FOUND in slow query log when slow_query_log= OFF. Bailing out!";
171
 
}
172
 
TRUNCATE mysql.slow_log;
173
 
 
174
 
# clean up: drop tables, reset the variables back to the previous value,
175
 
#           disconnect extra connections
176
 
connection extra2;
177
 
 
178
 
SET GLOBAL slow_query_log= @old_slow_query_log;
179
 
 
180
 
connection master;
181
 
DROP TABLE t1;
182
 
sync_slave_with_master;
183
 
 
184
 
source include/stop_slave.inc;
185
 
 
186
 
SET GLOBAL long_query_time= @old_long_query_time;
187
 
SET GLOBAL log_output= @old_log_output;
188
 
 
189
 
source include/start_slave.inc;
190
 
 
191
 
disconnect extra;
192
 
disconnect extra2;