Skip to content

Commit 235bebe

Browse files
Daniele SciasciaNirbhay Choubey
authored andcommitted
- Eliminates code duplication in query cache patch - Reduces the number of iterations in mysql-wsrep#201.test to shorten the execution time - Adds a new test case that exercises more scenarios
1 parent 17ac959 commit 235bebe

File tree

5 files changed

+148
-12
lines changed

5 files changed

+148
-12
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
CREATE TABLE t1 (id INT PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB;
2+
INSERT INTO t1 VALUES (1);
3+
SET GLOBAL wsrep_provider_options = "repl.causal_read_timeout=PT1S";
4+
SET GLOBAL DEBUG = "d,sync.wsrep_apply_cb";
5+
SET SESSION wsrep_sync_wait = 7;
6+
SELECT MAX(id) FROM t1;
7+
MAX(id)
8+
1
9+
INSERT INTO t1 VALUES (2);
10+
SELECT MAX(id) FROM t1;
11+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
12+
SET GLOBAL DEBUG = "";
13+
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb";
14+
FLUSH QUERY CACHE;
15+
SET SESSION wsrep_sync_wait = 7;
16+
SET GLOBAL DEBUG = "d,sync.wsrep_apply_cb";
17+
INSERT INTO t1 VALUES (3);
18+
SELECT MAX(id) FROM t1;
19+
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
20+
SET GLOBAL DEBUG = "";
21+
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb";
22+
INSERT INTO t1 VALUES (4);
23+
SET SESSION wsrep_sync_wait = 7;
24+
SELECT MAX(id) FROM t1;
25+
MAX(id)
26+
4
27+
SET SESSION wsrep_sync_wait = 7;
28+
FLUSH STATUS;
29+
SELECT MAX(id) FROM t1;
30+
MAX(id)
31+
4
32+
SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME = 'Qcache_hits';
33+
VARIABLE_VALUE = 1
34+
1
35+
SET GLOBAL DEBUG = "d,sync.wsrep_apply_cb";
36+
INSERT INTO t1 VALUES (5);
37+
SET SESSION wsrep_sync_wait = 7;
38+
SELECT MAX(id) FROM t1 ;
39+
SET GLOBAL DEBUG = "";
40+
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb";
41+
MAX(id)
42+
5
43+
SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME = 'Qcache_hits';
44+
VARIABLE_VALUE = 1
45+
1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--query_cache_type=1
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
--source include/galera_cluster.inc
2+
--source include/have_innodb.inc
3+
--source include/have_debug_sync.inc
4+
--source include/have_query_cache.inc
5+
6+
CREATE TABLE t1 (id INT PRIMARY KEY AUTO_INCREMENT) ENGINE=InnoDB;
7+
INSERT INTO t1 VALUES (1);
8+
9+
--connection node_2
10+
--let $wsrep_provider_options_orig = `SELECT @@wsrep_provider_options`
11+
SET GLOBAL wsrep_provider_options = "repl.causal_read_timeout=PT1S";
12+
SET GLOBAL DEBUG = "d,sync.wsrep_apply_cb";
13+
SET SESSION wsrep_sync_wait = 7;
14+
SELECT MAX(id) FROM t1; # first lookup miss
15+
16+
#
17+
# Query cache hit, wait timeout
18+
#
19+
20+
--connection node_1
21+
INSERT INTO t1 VALUES (2);
22+
23+
--connection node_2
24+
--error ER_LOCK_WAIT_TIMEOUT
25+
SELECT MAX(id) FROM t1;
26+
SET GLOBAL DEBUG = "";
27+
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb";
28+
29+
FLUSH QUERY CACHE;
30+
SET SESSION wsrep_sync_wait = 7;
31+
SET GLOBAL DEBUG = "d,sync.wsrep_apply_cb";
32+
33+
#
34+
# Query cache miss, wait timeout
35+
#
36+
37+
--connection node_1
38+
INSERT INTO t1 VALUES (3);
39+
40+
--connection node_2
41+
--error ER_LOCK_WAIT_TIMEOUT
42+
SELECT MAX(id) FROM t1;
43+
SET GLOBAL DEBUG = "";
44+
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb";
45+
46+
#
47+
# Query cache miss
48+
#
49+
50+
--connection node_1
51+
INSERT INTO t1 VALUES (4);
52+
53+
--connection node_2
54+
SET SESSION wsrep_sync_wait = 7;
55+
SELECT MAX(id) FROM t1;
56+
SET SESSION wsrep_sync_wait = 7;
57+
58+
#
59+
# Query cache hit
60+
#
61+
62+
FLUSH STATUS;
63+
SELECT MAX(id) FROM t1;
64+
SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME = 'Qcache_hits';
65+
SET GLOBAL DEBUG = "d,sync.wsrep_apply_cb";
66+
67+
#
68+
# Query cache invalidated
69+
#
70+
71+
--connection node_1
72+
INSERT INTO t1 VALUES (5);
73+
74+
--connection node_2
75+
SET SESSION wsrep_sync_wait = 7;
76+
--send SELECT MAX(id) FROM t1
77+
78+
--connect node_2a, 127.0.0.1, root, , test, $NODE_MYPORT_2
79+
--connection node_2a
80+
SET GLOBAL DEBUG = "";
81+
SET DEBUG_SYNC = "now SIGNAL signal.wsrep_apply_cb";
82+
83+
--connection node_2
84+
--reap
85+
SELECT VARIABLE_VALUE = 1 FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME = 'Qcache_hits';
86+
87+
88+
--disable_query_log
89+
--eval SET GLOBAL wsrep_provider_options = "$wsrep_provider_options_orig"
90+
DROP TABLE t1;

mysql-test/suite/galera/t/mysql-wsrep#201.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SET SESSION wsrep_sync_wait = 7;
1212

1313
--disable_query_log
1414

15-
--let $count = 10000
15+
--let $count = 500
1616
while ($count)
1717
{
1818
--connection node_1

sql/sql_cache.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,7 +1846,6 @@ Query_cache::send_result_to_client(THD *thd, char *org_sql, uint query_length)
18461846
goto err;
18471847
}
18481848
}
1849-
18501849
/*
18511850
Try to obtain an exclusive lock on the query cache. If the cache is
18521851
disabled or if a full cache flush is in progress, the attempt to
@@ -1946,6 +1945,13 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
19461945
(int)flags.autocommit));
19471946
memcpy((uchar *)(sql + (tot_length - QUERY_CACHE_FLAGS_SIZE)),
19481947
(uchar*) &flags, QUERY_CACHE_FLAGS_SIZE);
1948+
1949+
#ifdef WITH_WSREP
1950+
bool once_more;
1951+
once_more= true;
1952+
lookup:
1953+
#endif /* WITH_WSREP */
1954+
19491955
query_block = (Query_cache_block *) my_hash_search(&queries, (uchar*) sql,
19501956
tot_length);
19511957
/* Quick abort on unlocked data */
@@ -1959,21 +1965,15 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
19591965
DBUG_PRINT("qcache", ("Query in query hash 0x%lx", (ulong)query_block));
19601966

19611967
#ifdef WITH_WSREP
1962-
if (WSREP_CLIENT(thd) && wsrep_must_sync_wait(thd)) {
1968+
if (once_more && WSREP_CLIENT(thd) && wsrep_must_sync_wait(thd))
1969+
{
19631970
unlock();
19641971
if (wsrep_sync_wait(thd))
19651972
goto err;
19661973
if (try_lock(thd, Query_cache::TIMEOUT))
19671974
goto err;
1968-
query_block = (Query_cache_block *) my_hash_search(&queries,
1969-
(uchar*) sql,
1970-
tot_length);
1971-
if (query_block == 0 ||
1972-
query_block->query()->result() == 0 ||
1973-
query_block->query()->result()->type != Query_cache_block::RESULT)
1974-
{
1975-
goto err_unlock;
1976-
}
1975+
once_more= false;
1976+
goto lookup;
19771977
}
19781978
#endif /* WITH_WSREP */
19791979

0 commit comments

Comments
 (0)