| 1 |
# Bug#13721257 RACE CONDITION IN UPDATES OR INSERTS OF WIDE RECORDS |
| 2 |
# Test what happens when a record is inserted or updated so that some |
| 3 |
# columns are stored off-page. |
| 4 |
|
| 5 |
--source include/have_innodb.inc |
| 6 |
# The 7000 in this test is a bit less than half the innodb_page_size. |
| 7 |
--source include/have_innodb_16k.inc |
| 8 |
|
| 9 |
--source include/have_debug.inc |
| 10 |
--source include/have_debug_sync.inc |
| 11 |
|
| 12 |
# Embedded server does not support restarting |
| 13 |
--source include/not_embedded.inc |
| 14 |
|
| 15 |
FLUSH TABLES; |
| 16 |
|
| 17 |
CREATE TABLE t1 (a INT PRIMARY KEY, b TEXT) ENGINE=InnoDB; |
| 18 |
CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB; |
| 19 |
CREATE TABLE t3 (a INT PRIMARY KEY, b TEXT, c TEXT) ENGINE=InnoDB; |
| 20 |
|
| 21 |
INSERT INTO t1 VALUES (1,REPEAT('a',30000)),(2,REPEAT('b',40000)); |
| 22 |
SET DEBUG_SYNC='before_row_upd_extern SIGNAL have_latch WAIT_FOR go1'; |
| 23 |
BEGIN; |
| 24 |
# This will not block, because it will not store new BLOBs. |
| 25 |
UPDATE t1 SET a=a+2; |
| 26 |
ROLLBACK; |
| 27 |
BEGIN; |
| 28 |
--send |
| 29 |
UPDATE t1 SET b=CONCAT(b,'foo'); |
| 30 |
|
| 31 |
connect (con1,localhost,root,,); |
| 32 |
SET DEBUG_SYNC='now WAIT_FOR have_latch'; |
| 33 |
|
| 34 |
# this one should block due to the clustered index tree and leaf page latches |
| 35 |
--send |
| 36 |
SELECT a, RIGHT(b,20) FROM t1; |
| 37 |
|
| 38 |
connect (con2,localhost,root,,); |
| 39 |
|
| 40 |
# Check that the above SELECT is blocked |
| 41 |
let $wait_condition= |
| 42 |
select count(*) = 1 from information_schema.processlist |
| 43 |
where state in ('Sending data', 'Opening tables') and |
| 44 |
info = 'SELECT a, RIGHT(b,20) FROM t1'; |
| 45 |
--source include/wait_condition.inc |
| 46 |
|
| 47 |
SET DEBUG_SYNC='now SIGNAL go1'; |
| 48 |
|
| 49 |
connection con1; |
| 50 |
reap; |
| 51 |
connection default; |
| 52 |
reap; |
| 53 |
SET DEBUG_DBUG='+d,row_ins_extern_checkpoint'; |
| 54 |
SET DEBUG_SYNC='before_row_ins_extern_latch SIGNAL rec_not_blob WAIT_FOR crash'; |
| 55 |
ROLLBACK; |
| 56 |
BEGIN; |
| 57 |
--send |
| 58 |
INSERT INTO t1 VALUES (3,REPEAT('c',50000)); |
| 59 |
|
| 60 |
connection con1; |
| 61 |
SET DEBUG_SYNC='now WAIT_FOR rec_not_blob'; |
| 62 |
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; |
| 63 |
SELECT @@transaction_isolation; |
| 64 |
|
| 65 |
# this one should see (3,NULL_BLOB) |
| 66 |
SELECT a, RIGHT(b,20) FROM t1; |
| 67 |
SELECT a FROM t1; |
| 68 |
|
| 69 |
# Request a crash, and restart the server. |
| 70 |
BEGIN; |
| 71 |
INSERT INTO t2 VALUES (42); |
| 72 |
|
| 73 |
--let $shutdown_timeout=0 |
| 74 |
--source include/restart_mysqld.inc |
| 75 |
|
| 76 |
disconnect con1; |
| 77 |
disconnect con2; |
| 78 |
connection default; |
| 79 |
# This connection should notice the crash as well. |
| 80 |
--error 2013 |
| 81 |
reap; |
| 82 |
|
| 83 |
--enable_reconnect |
| 84 |
--source include/wait_until_connected_again.inc |
| 85 |
--disable_reconnect |
| 86 |
|
| 87 |
CHECK TABLE t1; |
| 88 |
|
| 89 |
INSERT INTO t3 VALUES |
| 90 |
(1,REPEAT('d',7000),REPEAT('e',100)), |
| 91 |
(2,REPEAT('g',7000),REPEAT('h',100)); |
| 92 |
SET DEBUG_SYNC='blob_write_middle SIGNAL go_sel WAIT_FOR go_upd'; |
| 93 |
# This should move column b off-page. |
| 94 |
--send |
| 95 |
UPDATE t3 SET c=REPEAT('f',3000) WHERE a=1; |
| 96 |
|
| 97 |
--echo # Connection con1: |
| 98 |
connect (con1,localhost,root,,); |
| 99 |
SET DEBUG_SYNC='now WAIT_FOR go_sel'; |
| 100 |
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; |
| 101 |
SELECT @@transaction_isolation; |
| 102 |
SELECT a, RIGHT(b,20), RIGHT(c,20) FROM t3; |
| 103 |
set debug_sync='now SIGNAL go_upd'; |
| 104 |
|
| 105 |
--echo # Connection default: |
| 106 |
connection default; |
| 107 |
--echo # reap UPDATE t3 SET c=REPEAT('f',3000) WHERE a=1; |
| 108 |
reap; |
| 109 |
|
| 110 |
--echo # Connection con1: |
| 111 |
connection con1; |
| 112 |
SELECT a, RIGHT(b,20), RIGHT(c,20) FROM t3; |
| 113 |
|
| 114 |
disconnect con1; |
| 115 |
|
| 116 |
connection default; |
| 117 |
CHECK TABLE t1,t2,t3; |
| 118 |
|
| 119 |
connect (con2,localhost,root,,); |
| 120 |
BEGIN; |
| 121 |
INSERT INTO t2 VALUES (347); |
| 122 |
connection default; |
| 123 |
|
| 124 |
# The row_upd_extern_checkpoint was removed in Bug#13721257, |
| 125 |
# because the mini-transaction of the B-tree modification would |
| 126 |
# remain open while we are writing the off-page columns and are |
| 127 |
# stuck in the DEBUG_SYNC. A checkpoint involves a flush, which |
| 128 |
# would wait for the buffer-fix to cease. |
| 129 |
SET DEBUG_DBUG='+d,row_upd_extern_checkpoint'; |
| 130 |
SET DEBUG_SYNC='before_row_upd_extern SIGNAL have_latch WAIT_FOR crash'; |
| 131 |
# This should move column b off-page. |
| 132 |
--send |
| 133 |
UPDATE t3 SET c=REPEAT('i',3000) WHERE a=2; |
| 134 |
|
| 135 |
connection con2; |
| 136 |
SET DEBUG_SYNC='now WAIT_FOR have_latch'; |
| 137 |
|
| 138 |
# Check that the above UPDATE is blocked |
| 139 |
SELECT info FROM information_schema.processlist |
| 140 |
WHERE state = 'debug sync point: before_row_upd_extern'; |
| 141 |
|
| 142 |
connect (con3,localhost,root,,); |
| 143 |
SET GLOBAL innodb_flush_log_at_trx_commit=1; |
| 144 |
DELETE FROM t1; |
| 145 |
ROLLBACK; |
| 146 |
disconnect con3; |
| 147 |
|
| 148 |
connection con2; |
| 149 |
|
| 150 |
--let $shutdown_timeout=0 |
| 151 |
--source include/restart_mysqld.inc |
| 152 |
|
| 153 |
disconnect con2; |
| 154 |
connection default; |
| 155 |
# This connection should notice the crash as well. |
| 156 |
--error 2013 |
| 157 |
reap; |
| 158 |
|
| 159 |
--enable_reconnect |
| 160 |
--source include/wait_until_connected_again.inc |
| 161 |
--disable_reconnect |
| 162 |
|
| 163 |
CHECK TABLE t1,t2,t3; |
| 164 |
SELECT a, RIGHT(b,20), RIGHT(c,20) FROM t3; |
| 165 |
SELECT a FROM t3; |
| 166 |
|
| 167 |
connect (con2,localhost,root,,); |
| 168 |
BEGIN; |
| 169 |
INSERT INTO t2 VALUES (33101); |
| 170 |
connection default; |
| 171 |
|
| 172 |
# The row_upd_extern_checkpoint was removed in Bug#13721257, |
| 173 |
# because the mini-transaction of the B-tree modification would |
| 174 |
# remain open while we are writing the off-page columns and are |
| 175 |
# stuck in the DEBUG_SYNC. A checkpoint involves a flush, which |
| 176 |
# would wait for the buffer-fix to cease. |
| 177 |
SET DEBUG_DBUG='+d,row_upd_extern_checkpoint'; |
| 178 |
SET DEBUG_SYNC='after_row_upd_extern SIGNAL have_latch WAIT_FOR crash'; |
| 179 |
# This should move column b off-page. |
| 180 |
--send |
| 181 |
UPDATE t3 SET c=REPEAT('j',3000) WHERE a=2; |
| 182 |
|
| 183 |
connection con2; |
| 184 |
SET DEBUG_SYNC='now WAIT_FOR have_latch'; |
| 185 |
|
| 186 |
# Check that the above UPDATE is blocked |
| 187 |
SELECT info FROM information_schema.processlist |
| 188 |
WHERE state = 'debug sync point: after_row_upd_extern'; |
| 189 |
|
| 190 |
--let $shutdown_timeout=0 |
| 191 |
--source include/restart_mysqld.inc |
| 192 |
|
| 193 |
disconnect con2; |
| 194 |
connection default; |
| 195 |
# This connection should notice the crash as well. |
| 196 |
--error 2013 |
| 197 |
reap; |
| 198 |
|
| 199 |
--enable_reconnect |
| 200 |
--source include/wait_until_connected_again.inc |
| 201 |
--disable_reconnect |
| 202 |
CHECK TABLE t1,t2,t3; |
| 203 |
SELECT a, RIGHT(b,20), RIGHT(c,20) FROM t3; |
| 204 |
SELECT a FROM t3; |
| 205 |
|
| 206 |
SELECT * FROM t2; |
| 207 |
|
| 208 |
DROP TABLE t1,t2,t3; |
| 209 |
|
| 210 |
CREATE TABLE t1(f1 INT PRIMARY KEY, f2 TEXT)ENGINE=InnoDB |
| 211 |
ROW_FORMAT=REDUNDANT; |
| 212 |
SET @fill_amount = (@@innodb_page_size / 2 ) + 1 ; |
| 213 |
INSERT INTO t1 VALUES(1, REPEAT(2, @fill_amount)); |
| 214 |
UPDATE t1 SET f1 = 2; |
| 215 |
DROP TABLE t1; |