Debian Codegraph @

mysql-test/suite/memcached/t/memc256_lock_table_write.test

raw
1 source include/not_valgrind.inc;
2 source include/have_memcached_plugin.inc;
3 source include/not_windows.inc;
4
5 # Save the initial number of concurrent sessions
6 --source include/count_sessions.inc
7
8 --disable_query_log
9 CALL mtr.add_suppression("daemon-memcached-w-batch-size': unsigned");
10 CALL mtr.add_suppression("Could not obtain server's UPN to be used as target service name");
11 CALL mtr.add_suppression("Warning: MySQL is trying to drop");
12 --enable_query_log
13
14 --enable_connect_log
15 SET @old_innodb_api_trx_level = @@global.innodb_api_trx_level;
16
17 # Create the memcached tables
18 --disable_query_log
19 source include/memcache_config.inc;
20 --enable_query_log
21
22 INSERT INTO cache_policies VALUES("cache_policy", "innodb_only",
23 "innodb_only", "innodb_only", "innodb_only");
24
25 INSERT INTO config_options VALUES("separator", "|");
26
27 # describe table for memcache
28 INSERT INTO containers VALUES ("desc_t1", "test", "t1",
29 "c1", "c2", "c3", "c4", "c5", "PRIMARY");
30
31 --connect (c_diag,localhost, root,,)
32 --connection default
33
34 --let $innodb_api_trx_level = 0
35 while($innodb_api_trx_level < 4)
36 {
37
38 --echo #
39 --echo # Testing the scenario with innodb_api_trx_level = $innodb_api_trx_level
40 --echo #
41
42 --eval SET @@global.innodb_api_trx_level = $innodb_api_trx_level
43
44 USE test;
45
46 --disable_warnings
47 DROP TABLE IF EXISTS t1;
48 --enable_warnings
49 CREATE TABLE t1 (c1 VARCHAR(32),
50 c2 VARCHAR(1024),
51 c3 INT, c4 BIGINT UNSIGNED, c5 INT, primary key(c1))
52 ENGINE = INNODB;
53
54 INSERT INTO t1 VALUES ('D', 'Darmstadt', 0, 0, 0);
55 INSERT INTO t1 VALUES ('B', 'Berlin', 0, 0, 0);
56 INSERT INTO t1 VALUES ('C', 'Cottbus', 0, 0 ,0);
57 INSERT INTO t1 VALUES ('H', 'Hamburg', 0, 0, 0);
58
59 # Tables must exist before plugin can be started!
60 --let $memcached_address=127.0.0.1:11256
61 --source ../include/load_daemon_memcached_expecting_success.inc
62
63 SET autocommit=0;
64 LOCK TABLES t1 WRITE;
65
66 perl;
67
68 use DBI;
69 use Cache::Memcached;
70 use Time::HiRes qw(time);
71 use POSIX qw(strftime);
72
73 $| = 1;
74
75
76 my $memd = new Cache::Memcached {
77 'servers' => [ "127.0.0.1:11256" ],
78 'connect_timeout' => 20,
79 'select_timeout' => 5
80 };
81
82 # It currently depends on innodb_api_trx_level if the get will fail.
83 # It only fails in the SERIALIZABLE (3) level.
84 $key="D";
85 print "Get $key...\n";
86 $val = $memd->get($key);
87 print "Get has returned $val\n";
88
89 # sets should always fail as they always acquire InnoDB table lock
90 $val="new value";
91
92 print "Set $key to $val\n";
93 my $set_res=$memd->set($key,$val);
94 print "Set returned $set_res\n";
95
96 print "Get $key...\n";
97 $val = $memd->get($key);
98 print "Get has returned $val\n";
99
100 $memd->disconnect_all;
101 EOF
102
103 # We still haven't commited nor relased the MDL, so the set operation from
104 # memcached has to wait. Current implementation of memcached does not care
105 # much about MDL, but it honours InnoDB table locks, so it will wait until
106 # COMMIT.
107 --connection c_diag
108 # There should be X GRANTED to 'default' visible here
109 # and an IX generated by set operation WAITING behind it.
110 # In case of SERIALIZABLE (3) there should also be 2 WAITING IS locks of gets
111 --sorted_result
112 SELECT lock_mode,lock_status FROM performance_schema.data_locks
113 WHERE object_schema='test' AND object_name='t1' AND lock_type='TABLE';
114
115 # There should be a metadata lock granted to 'default'
116 --sorted_result
117 SELECT lock_type,lock_duration,lock_status FROM performance_schema.metadata_locks
118 WHERE object_schema='test' AND object_name='t1' AND object_type='TABLE';
119
120 --connection default
121 SELECT c2 FROM t1 WHERE c1='D';
122
123 COMMIT;
124 SET autocommit=1;
125 # We have commited, so InnoDB's table locks are released, and the set
126 # operation from memcached can proceed even though we still hold MDL lock.
127 # The set is reported to client as timed out (select_timeout=5), but its
128 # transaction's thread actually should eventually finish the operation.
129 # We wait here until c2 becomes "new value".
130 --let wait_condition=SELECT COUNT(*) FROM t1 WHERE c1='D' AND c2='new value'
131 --source include/wait_condition.inc
132
133 SELECT c2 FROM t1 WHERE c1='D';
134 --connection c_diag
135 # There should be no InnoDB table locks any more
136 --sorted_result
137 SELECT lock_mode,lock_status FROM performance_schema.data_locks
138 WHERE object_schema='test' AND object_name='t1' AND lock_type='TABLE';
139 # There should still be a metadata lock
140 --sorted_result
141 SELECT lock_type,lock_duration,lock_status FROM performance_schema.metadata_locks
142 WHERE object_schema='test' AND object_name='t1' AND object_type='TABLE';
143
144 --connection default
145 UNLOCK TABLES;
146
147 --connection c_diag
148 # There should be no locks
149 --sorted_result
150 SELECT lock_mode,lock_status FROM performance_schema.data_locks
151 WHERE object_schema='test' AND object_name='t1' AND lock_type='TABLE';
152 # There should be no metadata locks
153 --sorted_result
154 SELECT lock_type,lock_duration,lock_status FROM performance_schema.metadata_locks
155 WHERE object_schema='test' AND object_name='t1' AND object_type='TABLE';
156
157 SELECT c2 FROM t1 WHERE c1='D';
158
159 --connection default
160 # Stop plugin before innodb_memcached configuration
161 UNINSTALL PLUGIN daemon_memcached;
162
163 DROP TABLE t1;
164 --inc $innodb_api_trx_level
165 }
166 --disconnect c_diag
167
168 DROP DATABASE innodb_memcache;
169
170 SET @@global.innodb_api_trx_level = @old_innodb_api_trx_level;
171
172 # Wait till all disconnects are completed.
173 --source include/wait_until_count_sessions.inc