1--source include/have_rocksdb.inc 2--source include/have_debug_sync.inc 3--source include/count_sessions.inc 4 5# For GitHub issue#167 -- Unique key check doesn't work 6 7connect (con1, localhost, root,,); 8connect (con2, localhost, root,,); 9connect (con3, localhost, root,,); 10connection default; 11 12create table t1 (id int, value int, primary key (id)) engine=rocksdb; 13create table t2 (id int, id2 int, value int, primary key (id), unique key (id2)) engine=rocksdb; 14 15# 1) second insert should be blocked at GetForUpdate(), then returning duplicate key error 16# after con1's commit 17connection con1; 18begin; 19insert into t1 values (1,1); 20 21connection con2; 22let $ID= `select connection_id()`; 23set session rocksdb_lock_wait_timeout=50; 24begin; 25send insert into t1 values (1,2); 26 27connection con1; 28let $wait_condition= select 1 from INFORMATION_SCHEMA.PROCESSLIST 29 where ID = $ID and STATE = "Waiting for row lock"; 30--source include/wait_condition.inc 31commit; 32 33connection con2; 34--error ER_DUP_ENTRY 35reap; 36commit; 37select * from t1; 38truncate table t1; 39 40# 2) same as 1) but using secondary unique key constraint 41connection con1; 42begin; 43insert into t2 values (1,1,1); 44 45connection con2; 46begin; 47send insert into t2 values (2,1,2); 48 49connection con1; 50--source include/wait_condition.inc 51commit; 52 53connection con2; 54--error ER_DUP_ENTRY 55reap; 56commit; 57select * from t2; 58truncate table t2; 59 60# 3) similar to 1),2) but rolled back 61connection con1; 62begin; 63insert into t1 values (1,1); 64 65connection con2; 66begin; 67send insert into t1 values (1,2); 68 69connection con1; 70--source include/wait_condition.inc 71rollback; 72 73connection con2; 74reap; 75commit; 76select * from t1; 77truncate table t1; 78 79connection con1; 80begin; 81insert into t2 values (1,1,1); 82 83connection con2; 84begin; 85send insert into t2 values (2,1,2); 86 87connection con1; 88--source include/wait_condition.inc 89rollback; 90 91connection con2; 92reap; 93commit; 94select * from t2; 95truncate table t2; 96 97 98# 4) simulating T1 GetForUpdate() -> T2 GetForUpdate(). T2 should fail with lock wait timeout. 99connection con1; 100set debug_sync='rocksdb.update_write_row_after_unique_check SIGNAL parked1 WAIT_FOR go1'; 101send insert into t1 values (1,1); 102 103connection con2; 104set debug_sync='rocksdb.update_write_row_after_unique_check SIGNAL parked2 WAIT_FOR go2'; 105send insert into t2 values (1,1,1); 106 107connection default; 108set debug_sync='now WAIT_FOR parked1'; 109set debug_sync='now WAIT_FOR parked2'; 110 111connection con3; 112set session rocksdb_lock_wait_timeout=1; 113--error ER_LOCK_WAIT_TIMEOUT 114insert into t1 values (1,2); 115--error ER_LOCK_WAIT_TIMEOUT 116insert into t2 values (2,1,2); 117 118connection default; 119set debug_sync='now SIGNAL go1'; 120set debug_sync='now SIGNAL go2'; 121 122connection con1; 123reap; 124 125connection con2; 126reap; 127 128connection default; 129--error ER_DUP_ENTRY 130insert into t1 values (1,2); 131--error ER_DUP_ENTRY 132insert into t2 values (2,1,2); 133select * from t1; 134select * from t2; 135# Cleanup 136connection default; 137set debug_sync='RESET'; 138disconnect con1; 139disconnect con2; 140disconnect con3; 141drop table t1, t2; 142 143# skip_unique checks should skip checks only for tables that don't have 144# secondary indexes 145 146# table with PK only 147create table t1 (id int, value int, primary key (id)) engine=rocksdb; 148# table with PK and SK 149create table t2 (id int, id2 int, value int, primary key (id), unique key (id2)) engine=rocksdb; 150# table with hidden PK 151create table t3 (id int, value int) engine=rocksdb; 152 153SET @old_val = @@session.unique_checks; 154set @@session.unique_checks = FALSE; 155 156insert into t1 values (1, 1), (1, 2); 157--error ER_DUP_ENTRY 158insert into t2 values (1, 1, 1), (1, 2, 1); 159insert into t3 values (1, 1), (1, 1); 160 161set @@session.unique_checks = @old_val; 162# cleanup 163drop table t1, t2, t3; 164 165--echo # 166--echo # Issue#1026: MyRocks may return "Can't find record" which is unexpected 167--echo # 168 169connect (con1, localhost, root,,); 170connection default; 171 172CREATE TABLE t1 ( 173 id bigint(20) unsigned NOT NULL AUTO_INCREMENT, 174 a varchar(36) NOT NULL , 175 b varchar(128) NOT NULL , 176 c varchar(10240) NOT NULL , 177 PRIMARY KEY (id), 178 UNIQUE KEY uniq_idx (a,b) 179) ENGINE=ROCKSDB; 180 181insert into t1 values (1,1,1,1), (2,2,2,2); 182 183## TRX A: 184begin; 185set debug_sync='rocksdb.after_unique_pk_check SIGNAL trx_a_sleep WAIT_FOR trx_a_cont'; 186send 187insert into t1(a,b,c) values (10,'file_type','trx-a') on duplicate key update c=values(c); 188 189connection con1; 190# TRX B: 191set debug_sync='now WAIT_FOR trx_a_sleep'; 192begin; 193insert into t1(a,b,c) values (10,'file_type','trx-b') on duplicate key update c=values(c); 194commit; 195set debug_sync='now SIGNAL trx_a_cont'; 196 197 198connection default; 199--error ER_LOCK_DEADLOCK 200reap; 201 202disconnect con1; 203rollback; 204drop table t1; 205 206set debug_sync='RESET'; 207 208--echo # 209--echo # Issue#1026, testcase #2 (with READ-COMMITTED). 210--echo # 211 212CREATE table t1 ( 213 pk0 int primary key auto_increment, 214 sk int, 215 val int default 0, 216 unique(sk) 217) engine=rocksdb; 218 219insert into t1 (sk) values (20), (30); 220 221connect (con1, localhost, root,,); 222 223connection con1; 224set transaction_isolation='READ-COMMITTED'; 225begin; 226set debug_sync='rocksdb.after_unique_sk_check SIGNAL here WAIT_FOR go'; 227send 228insert into t1 (sk) values (1), (2) on duplicate key update val = val + 1; 229 230connection default; 231set debug_sync='now WAIT_FOR here'; 232begin; 233insert into t1 (sk) values (2); 234commit; 235set debug_sync='now SIGNAL go'; 236 237connection con1; 238reap; 239commit; 240 241connection default; 242disconnect con1; 243 244select * from t1; 245 246drop table t1; 247 248set debug_sync='RESET'; 249 250--echo # 251--echo # Issue#1026, testcase #3 (with READ-COMMITTED and PK). 252--echo # 253 254CREATE table t1 ( 255 pk int primary key, 256 val int default 0 257) engine=rocksdb; 258 259insert into t1 (pk) values (20), (30); 260 261connect (con1, localhost, root,,); 262 263connection con1; 264set transaction_isolation='READ-COMMITTED'; 265begin; 266set debug_sync='rocksdb.after_unique_pk_check SIGNAL here WAIT_FOR go'; 267send 268insert into t1 (pk) values (1), (2) on duplicate key update val = val + 1; 269 270connection default; 271set debug_sync='now WAIT_FOR here'; 272begin; 273insert into t1 (pk) values (2); 274commit; 275set debug_sync='now SIGNAL go'; 276 277connection con1; 278reap; 279commit; 280 281connection default; 282disconnect con1; 283 284select * from t1; 285 286drop table t1; 287 288set debug_sync='RESET'; 289 290--source include/wait_until_count_sessions.inc 291