~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysql-test/suite/ndb/t/ndb_cache_multi2.test

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-- source include/have_query_cache.inc
 
2
-- source include/have_multi_ndb.inc
 
3
-- source include/not_embedded.inc
 
4
 
 
5
--disable_warnings
 
6
drop table if exists t1, t2;
 
7
--enable_warnings
 
8
 
 
9
 
 
10
# Turn on and reset query cache on server1
 
11
connection server1;
 
12
echo == Connected to server1 ==;
 
13
set GLOBAL query_cache_type=on;
 
14
set GLOBAL query_cache_size=1355776;
 
15
set GLOBAL ndb_cache_check_time=1;
 
16
reset query cache;
 
17
flush status;
 
18
 
 
19
# Turn on and reset query cache on server2
 
20
connection server2;
 
21
echo == Connected to server2 ==;
 
22
set GLOBAL query_cache_type=on;
 
23
set GLOBAL query_cache_size=1355776;
 
24
set GLOBAL ndb_cache_check_time=1;
 
25
reset query cache;
 
26
flush status;
 
27
 
 
28
# Create test tables in NDB and load them into cache
 
29
# on server1
 
30
connection server1;
 
31
echo == Connected to server1 ==;
 
32
create table t1 (a int) engine=ndbcluster;
 
33
create table t2 (a int) engine=ndbcluster;
 
34
insert into t1 value (2);
 
35
insert into t2 value (3);
 
36
select * from t1;
 
37
# Run the check query once to load it into qc on server1
 
38
# See at the end of this test why we need to disable ps-protocol for
 
39
# this query (*)
 
40
--disable_ps_protocol
 
41
select a != 3 from t1;
 
42
--enable_ps_protocol
 
43
select * from t2;
 
44
show status like "Qcache_queries_in_cache";
 
45
show status like "Qcache_inserts";
 
46
show status like "Qcache_hits";
 
47
 
 
48
 
 
49
# Connect server2, load table in to cache, then update the table
 
50
connection server2;
 
51
echo == Connected to server2 ==;
 
52
show status like "Qcache_queries_in_cache";
 
53
show status like "Qcache_inserts";
 
54
show status like "Qcache_hits";
 
55
select * from t1;
 
56
show status like "Qcache_queries_in_cache";
 
57
show status like "Qcache_inserts";
 
58
show status like "Qcache_hits";
 
59
update t1 set a=3 where a=2;
 
60
 
 
61
# Connect to server1 and check that cache is invalidated
 
62
# and correct data is returned
 
63
connection server1;
 
64
echo == Connected to server1 ==;
 
65
 
 
66
# Loop and wait for max 10 seconds until query cache thread
 
67
# has invalidated the cache and the column a in t1 is equal to 3
 
68
let $retries=20;
 
69
while (`select a != 3 from t1`)
 
70
{
 
71
  dec $retries;
 
72
  if (!$retries)
 
73
  {
 
74
     The query_cache thread failed to invalidate query_cache in 10 seconds;
 
75
  }
 
76
  sleep 0.5;
 
77
}
 
78
 
 
79
# Select from t1 one last time for the result file
 
80
# Column a should be 3
 
81
select * from t1;
 
82
 
 
83
# There should now be three queries in the cache
 
84
show status like "Qcache_queries_in_cache";
 
85
 
 
86
drop table t1, t2;
 
87
 
 
88
# Turn off and reset query cache on server1 and server2
 
89
connection server1;
 
90
set GLOBAL query_cache_size=0;
 
91
set GLOBAL ndb_cache_check_time=0;
 
92
reset query cache;
 
93
flush status;
 
94
connection server2;
 
95
set GLOBAL query_cache_size=0;
 
96
set GLOBAL ndb_cache_check_time=0;
 
97
reset query cache;
 
98
flush status;
 
99
 
 
100
# (*) Why we need to execute the query in non-ps mode.
 
101
# The principle of this test is: two mysqlds connected to one cluster,
 
102
# both using their query cache. Queries are cached in server1
 
103
# ("select a!=3 from t1", "select * from t1"),
 
104
# table t1 is modified in server2, we want to see that this invalidates
 
105
# the query cache of server1. Invalidation with NDB works like this:
 
106
# when a query is found in the query cache, NDB is asked if the tables
 
107
# have changed. In this test, ha_ndbcluster calls NDB every millisecond
 
108
# to collect change information about tables.
 
109
# Due to this millisecond delay, there is need for a loop ("while...")
 
110
# in this test, which waits until a query1 ("select a!=3 from t1") is
 
111
# invalidated (which is equivalent to it returning
 
112
# up-to-date results), and then expects query2 ("select * from t1")
 
113
# to have been invalidated (see up-to-date results).
 
114
# But when enabling --ps-protocol in this test, the logic breaks,
 
115
# because query1 is still done via mysql_real_query() (see mysqltest.c:
 
116
# eval_expr() always uses mysql_real_query()). So, query1 returning
 
117
# up-to-date results is not a sign of it being invalidated in the cache,
 
118
# because it was NOT in the cache ("select a!=3 from t1" on line 39
 
119
# was done with prep stmts, while `select a!=3 from t1` is not,
 
120
# thus the second does not see the first in the cache). Thus, we may run
 
121
# query2 when cache still has not been invalidated.
 
122
# The solution is to make the initial "select a!=3 from t1" run
 
123
# as a normal query, this repairs the broken logic.
 
124
# But note, "select * from t1" is still using prepared statements
 
125
# which was the goal of this test with --ps-protocol.