~gl-az/percona-xtrabackup/2.1-bug1197644

« back to all changes in this revision

Viewing changes to test/t/kill_long_selects.sh

MergedĀ lp:~sergei.glushchenko/percona-xtrabackup/BT30559-kill-long-selects.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
############################################################################
 
2
# Test kill-long-queries and kill-long-queries-timeout optins
 
3
############################################################################
 
4
 
 
5
. inc/common.sh
 
6
 
 
7
function bg_run()
 
8
{
 
9
    local varname=$1
 
10
 
 
11
    shift
 
12
 
 
13
    ( for cmd in "$@"
 
14
      do
 
15
        eval "$cmd"
 
16
      done ) &
 
17
 
 
18
    local pid=$!
 
19
 
 
20
    eval "$varname=$pid"
 
21
 
 
22
}
 
23
 
 
24
function mysql_select()
 
25
{
 
26
    vlog "Run select query with duration $1 seconds"
 
27
    ${MYSQL} ${MYSQL_ARGS} -c test  2> /dev/null <<EOF
 
28
        /* Run background /*SELECT*\  */
 
29
        (
 
30
         SELECT SLEEP($1) FROM t1 FOR UPDATE
 
31
        ) UNION ALL
 
32
        (
 
33
         SELECT 1
 
34
        );
 
35
EOF
 
36
}
 
37
 
 
38
function mysql_update()
 
39
{
 
40
    vlog "Run update query with duration $1 seconds"
 
41
    ${MYSQL} ${MYSQL_ARGS} -c test 2> /dev/null <<EOF
 
42
        /* This is not SELECT but rather an /*UPDATE*\
 
43
        query  */
 
44
        UPDATE t1 SET a = SLEEP($1);
 
45
EOF
 
46
}
 
47
 
 
48
 
 
49
function bg_kill_ok()
 
50
{
 
51
    vlog "Killing $1, expecting it is alive"
 
52
    run_cmd kill $1
 
53
}
 
54
 
 
55
 
 
56
function bg_wait_ok()
 
57
{
 
58
    vlog "Waiting for $1, expecting it's success"
 
59
    run_cmd wait $1
 
60
}
 
61
 
 
62
 
 
63
function bg_wait_fail()
 
64
{
 
65
    vlog "Waiting for $1, expecting it would fail"
 
66
    run_cmd_expect_failure wait $1
 
67
}
 
68
 
 
69
function kill_all_queries()
 
70
{
 
71
  run_cmd $MYSQL $MYSQL_ARGS test <<EOF
 
72
  select concat('KILL ',id,';') from information_schema.processlist
 
73
  where user='root' and time > 2 into outfile '$MYSQLD_TMPDIR/killall.sql';
 
74
  source $MYSQLD_TMPDIR/killall.sql;
 
75
EOF
 
76
  rm -f $MYSQLD_TMPDIR/killall.sql
 
77
}
 
78
 
 
79
start_server --innodb_file_per_table
 
80
 
 
81
run_cmd $MYSQL $MYSQL_ARGS test <<EOF
 
82
CREATE TABLE t1(a INT) ENGINE=InnoDB;
 
83
INSERT INTO t1 VALUES (1);
 
84
EOF
 
85
 
 
86
mkdir $topdir/full
 
87
 
 
88
# ==============================================================
 
89
vlog "===================== case 1 ====================="
 
90
bg_run bg_select_pid "mysql_select 3"
 
91
bg_run bg_update_pid "sleep 1" "mysql_update 3"
 
92
 
 
93
innobackupex $topdir/full --kill-long-queries-timeout=5 \
 
94
                          --kill-long-query-type=all
 
95
 
 
96
bg_wait_ok $bg_select_pid
 
97
bg_wait_ok $bg_update_pid
 
98
kill_all_queries
 
99
 
 
100
 
 
101
# ==============================================================
 
102
vlog "===================== case 2 ====================="
 
103
bg_run bg_select_pid "mysql_select 200"
 
104
bg_run bg_update_pid "sleep 1" "mysql_update 5"
 
105
 
 
106
innobackupex $topdir/full --kill-long-queries-timeout=3 \
 
107
                          --kill-long-query-type=select
 
108
 
 
109
bg_wait_fail $bg_select_pid
 
110
bg_wait_ok $bg_update_pid
 
111
kill_all_queries
 
112
 
 
113
 
 
114
# ==============================================================
 
115
vlog "===================== case 3 ====================="
 
116
bg_run bg_select_pid "mysql_select 200"
 
117
bg_run bg_update_pid "mysql_update 200"
 
118
 
 
119
innobackupex $topdir/full --kill-long-queries-timeout=3 \
 
120
                          --kill-long-query-type=all
 
121
 
 
122
bg_wait_fail $bg_select_pid
 
123
bg_wait_fail $bg_update_pid
 
124
kill_all_queries
 
125
 
 
126
 
 
127
# ==============================================================
 
128
vlog "===================== case 4 ====================="
 
129
bg_run bg_select_pid "mysql_select 200"
 
130
bg_run bg_update_pid "mysql_update 200"
 
131
 
 
132
sleep 1
 
133
 
 
134
run_cmd_expect_failure ${IB_BIN} ${IB_ARGS} $topdir/full \
 
135
                          --lock-wait-timeout=3 \
 
136
                          --lock-wait-query-type=all \
 
137
                          --lock-wait-threshold=1 \
 
138
                          --kill-long-queries-timeout=1 \
 
139
                          --kill-long-query-type=all
 
140
 
 
141
bg_kill_ok $bg_select_pid
 
142
bg_kill_ok $bg_update_pid
 
143
kill_all_queries
 
144
 
 
145
 
 
146
# ==============================================================
 
147
vlog "===================== case 5 ====================="
 
148
bg_run bg_select_pid "mysql_select 200"
 
149
bg_run bg_update_pid "mysql_update 200"
 
150
 
 
151
sleep 2
 
152
 
 
153
run_cmd_expect_failure ${IB_BIN} ${IB_ARGS} $topdir/full \
 
154
                          --lock-wait-timeout=3 \
 
155
                          --lock-wait-query-type=update \
 
156
                          --lock-wait-threshold=2 \
 
157
                          --kill-long-queries-timeout=1 \
 
158
                          --kill-long-query-type=all
 
159
 
 
160
bg_kill_ok $bg_select_pid
 
161
bg_kill_ok $bg_update_pid
 
162
kill_all_queries
 
163
 
 
164
 
 
165
# ==============================================================
 
166
vlog "===================== case 6 ====================="
 
167
bg_run bg_update_pid "mysql_update 5"
 
168
bg_run bg_select_pid "sleep 1" "mysql_select 200"
 
169
 
 
170
sleep 2
 
171
 
 
172
innobackupex $topdir/full \
 
173
                          --lock-wait-timeout=6 \
 
174
                          --lock-wait-query-type=update \
 
175
                          --lock-wait-threshold=2 \
 
176
                          --kill-long-queries-timeout=1 \
 
177
                          --kill-long-query-type=all
 
178
 
 
179
bg_wait_fail $bg_select_pid
 
180
bg_wait_ok $bg_update_pid
 
181
kill_all_queries