| 1 |
# |
| 2 |
# Test for Bug#30113362 : BTR_CUR_WILL_MODIFY_TREE() IS INSUFFICIENT FOR HIGHER TREE LEVEL |
| 3 |
# |
| 4 |
|
| 5 |
--source include/have_innodb.inc |
| 6 |
--source include/have_debug.inc |
| 7 |
--source include/have_debug_sync.inc |
| 8 |
--source include/have_innodb_16k.inc |
| 9 |
# debug sync points times out when using valgrind |
| 10 |
--source include/not_valgrind.inc |
| 11 |
|
| 12 |
--disable_query_log |
| 13 |
SET @old_innodb_limit_optimistic_insert_debug = @@innodb_limit_optimistic_insert_debug; |
| 14 |
SET @old_innodb_adaptive_hash_index = @@innodb_adaptive_hash_index; |
| 15 |
SET @old_innodb_stats_persistent = @@innodb_stats_persistent; |
| 16 |
--enable_query_log |
| 17 |
|
| 18 |
# Save the initial number of concurrent sessions |
| 19 |
--source include/count_sessions.inc |
| 20 |
|
| 21 |
SET GLOBAL innodb_adaptive_hash_index = false; |
| 22 |
SET GLOBAL innodb_stats_persistent = false; |
| 23 |
|
| 24 |
connect (purge_control,localhost,root,,); |
| 25 |
START TRANSACTION WITH CONSISTENT SNAPSHOT; |
| 26 |
|
| 27 |
--connect (con2,localhost,root,,) |
| 28 |
|
| 29 |
CREATE TABLE t1 ( |
| 30 |
a00 CHAR(255) NOT NULL DEFAULT 'a', |
| 31 |
a01 CHAR(255) NOT NULL DEFAULT 'a', |
| 32 |
a02 CHAR(255) NOT NULL DEFAULT 'a', |
| 33 |
b INT NOT NULL DEFAULT 0, |
| 34 |
PRIMARY KEY(a00, a01, a02) |
| 35 |
) charset latin1 ENGINE = InnoDB COMMENT='MERGE_THRESHOLD=45'; |
| 36 |
|
| 37 |
# |
| 38 |
# Prepare primary key index tree to be used for this test. |
| 39 |
# |
| 40 |
|
| 41 |
SET GLOBAL innodb_limit_optimistic_insert_debug = 3; |
| 42 |
|
| 43 |
delimiter |; |
| 44 |
CREATE PROCEDURE data_load_t1() |
| 45 |
BEGIN |
| 46 |
DECLARE c1 INT DEFAULT 97; |
| 47 |
DECLARE c2 INT DEFAULT 97; |
| 48 |
DECLARE c3 INT DEFAULT 97; |
| 49 |
|
| 50 |
WHILE c1 < 102 DO |
| 51 |
WHILE c2 < 123 DO |
| 52 |
WHILE c3 < 123 DO |
| 53 |
INSERT INTO t1 (a00) VALUES (CHAR(c1,c2,c3)); |
| 54 |
SET c3 = c3 + 1; |
| 55 |
END WHILE; |
| 56 |
SET c3 = 97; |
| 57 |
SET c2 = c2 + 1; |
| 58 |
END WHILE; |
| 59 |
SET c2 = 97; |
| 60 |
SET c1 = c1 + 1; |
| 61 |
END WHILE; |
| 62 |
END | |
| 63 |
delimiter ;| |
| 64 |
call data_load_t1(); |
| 65 |
DROP PROCEDURE data_load_t1; |
| 66 |
|
| 67 |
# all node pages are sparse (max 3 node_ptrs) |
| 68 |
ANALYZE TABLE t1; |
| 69 |
SELECT CLUST_INDEX_SIZE FROM information_schema.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1'; |
| 70 |
|
| 71 |
connection con2; |
| 72 |
DELETE FROM t1 WHERE a00 = 'cnm'; |
| 73 |
COMMIT; |
| 74 |
BEGIN; |
| 75 |
INSERT INTO t1 SET a00 = 'cnm'; |
| 76 |
# causes "domino falling" merges to upper level |
| 77 |
connection purge_control; |
| 78 |
COMMIT; |
| 79 |
connection con2; |
| 80 |
SET GLOBAL innodb_limit_optimistic_insert_debug = 0; |
| 81 |
ROLLBACK; |
| 82 |
|
| 83 |
# at this moment, in the tree, |
| 84 |
# ... |
| 85 |
# level 4: ...(ast,avw,ayz)(bcc,bff,bii,bll,boo,brr,buu,bxx,cba,ced,cqp,cts)(cwv,czy,ddb)... |
| 86 |
# ... |
| 87 |
|
| 88 |
--echo # Test start |
| 89 |
|
| 90 |
# (1) Similar case to the first reported corefile at bug#30113362 |
| 91 |
# - Deleting 'bii' causes "domino falling" merges and the node_ptr becomes left_most of level 4. |
| 92 |
# So, the operation needs upper level pages' X-latch, though doesn't cause merge more. |
| 93 |
|
| 94 |
connection purge_control; |
| 95 |
START TRANSACTION WITH CONSISTENT SNAPSHOT; |
| 96 |
connection con2; |
| 97 |
DELETE FROM t1 WHERE a00 = 'bii'; |
| 98 |
COMMIT; |
| 99 |
BEGIN; |
| 100 |
INSERT INTO t1 SET a00 = 'bii'; |
| 101 |
SET DEBUG_SYNC = 'rollback_undo_pk SIGNAL roll1_wait WAIT_FOR roll2'; |
| 102 |
SET DEBUG_SYNC = 'rollback_purge_clust SIGNAL rollback_waiting WAIT_FOR resume'; |
| 103 |
send ROLLBACK; |
| 104 |
|
| 105 |
connection purge_control; |
| 106 |
SET DEBUG_SYNC = 'now WAIT_FOR roll1_wait'; |
| 107 |
COMMIT; |
| 108 |
SET DEBUG_SYNC = 'now SIGNAL roll2'; |
| 109 |
|
| 110 |
connect (con1,localhost,root,,); |
| 111 |
# FIXME: This occasionally times out! |
| 112 |
--disable_warnings |
| 113 |
SET DEBUG_SYNC = 'now WAIT_FOR rollback_waiting TIMEOUT 1'; |
| 114 |
--enable_warnings |
| 115 |
SET DEBUG_SYNC = 'rw_s_lock_waiting SIGNAL lockwait1'; |
| 116 |
send SELECT a00 FROM t1 WHERE a00 = 'bii'; |
| 117 |
|
| 118 |
connection default; |
| 119 |
# FIXME: This occasionally times out! |
| 120 |
--disable_warnings |
| 121 |
SET DEBUG_SYNC = 'now WAIT_FOR lockwait1 TIMEOUT 1'; |
| 122 |
--enable_warnings |
| 123 |
# bug#30113362 caused deadlock |
| 124 |
SET DEBUG_SYNC = 'now SIGNAL resume'; |
| 125 |
|
| 126 |
connection con1; |
| 127 |
reap; |
| 128 |
connection con2; |
| 129 |
reap; |
| 130 |
connection default; |
| 131 |
|
| 132 |
ANALYZE TABLE t1; |
| 133 |
SELECT CLUST_INDEX_SIZE FROM information_schema.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1'; |
| 134 |
|
| 135 |
# (2) Confirm blocking domain caused by DELETE modify_tree for tall index tree |
| 136 |
|
| 137 |
# at this moment, in the tree, |
| 138 |
# ... |
| 139 |
# level 4: ...(ajk,amn,apq)(ast,avw,ayz,bll,boo,brr,buu,bxx,cba,ced,cqp,cts)(cwv,czy,ddb)(dge,djh,dmk)(dpn,dsq,dvt)(dyw,ebz,efc)... |
| 140 |
# ... |
| 141 |
|
| 142 |
# makes >17 records in level4 [(2^(4-1))*2 + 1]. (causes never left_most records) |
| 143 |
DELETE FROM t1 WHERE a00 = 'dpn'; |
| 144 |
COMMIT; |
| 145 |
INSERT INTO t1 SET a00 = 'dpn'; |
| 146 |
ROLLBACK; |
| 147 |
|
| 148 |
# at this moment, in the tree, |
| 149 |
# (* before "]" and after "[" records are treated as left_most possible records) |
| 150 |
# ... |
| 151 |
# level 4: ...(ajk,amn,apq)(ast,avw,ayz,bll,boo,brr,buu,bxx],cba,ced,[cqp,cts,cwv,czy,ddb,dge,dsq,dvt)(dyw,ebz,efc)... |
| 152 |
# level 3: ...(cba,ccb,cdc)(ced,cfe,cgf,chg],cih,cji,[ckj,clk,con,cpo)(cqp,crq,csr)... |
| 153 |
# level 2: ...(ckj,cks,clb)(clk,clt],cmc,cml,cmu,cnd,[cnv,coe)(con,cow,cpf)... |
| 154 |
# level 1: ...(cmu,cmx,cna)(cnd],cng,cnj,cnp,[cns)(cnv,cny,cob)... |
| 155 |
# level 0: ...(cnd,cne,cnf)(cng,cnh,cni)(cnj,cnk,cnl,cnn,cno)(cnp,cnq,cnr)... |
| 156 |
|
| 157 |
# deletes just 'ced' node_ptr only from level 4. doesn't cause merge and never left_most. |
| 158 |
# adjusts MERGE_THRESHOLD to do so. |
| 159 |
ALTER TABLE t1 COMMENT='MERGE_THRESHOLD=35'; |
| 160 |
|
| 161 |
connection purge_control; |
| 162 |
START TRANSACTION WITH CONSISTENT SNAPSHOT; |
| 163 |
|
| 164 |
connection con2; |
| 165 |
DELETE FROM t1 WHERE a00 = 'cnd'; |
| 166 |
COMMIT; |
| 167 |
BEGIN; |
| 168 |
INSERT INTO t1 SET a00 = 'cnd'; |
| 169 |
SET DEBUG_SYNC = 'rollback_undo_pk SIGNAL roll1_wait WAIT_FOR roll2'; |
| 170 |
SET DEBUG_SYNC = 'rollback_purge_clust SIGNAL rollback_waiting WAIT_FOR resume EXECUTE 2'; |
| 171 |
send ROLLBACK; |
| 172 |
|
| 173 |
connection purge_control; |
| 174 |
SET DEBUG_SYNC = 'now WAIT_FOR roll1_wait'; |
| 175 |
START TRANSACTION WITH CONSISTENT SNAPSHOT; |
| 176 |
SET DEBUG_SYNC = 'now SIGNAL roll2'; |
| 177 |
|
| 178 |
connection con1; |
| 179 |
# FIXME: For some reason, we will not always receive these signals! |
| 180 |
--disable_warnings |
| 181 |
# An optimistic row_undo_mod_remove_clust_low() will fail. |
| 182 |
SET DEBUG_SYNC = 'now WAIT_FOR rollback_waiting TIMEOUT 1'; |
| 183 |
SET DEBUG_SYNC = 'now SIGNAL resume'; |
| 184 |
# Wait for the pessimistic row_undo_mod_remove_clust_low() attempt. |
| 185 |
SET DEBUG_SYNC = 'now WAIT_FOR rollback_waiting TIMEOUT 1'; |
| 186 |
--enable_warnings |
| 187 |
disconnect purge_control; |
| 188 |
|
| 189 |
# The expectation should be... |
| 190 |
# level 0: (#cnd#,cne,cnf): causes merge |
| 191 |
# level 1: (#cnd#],cng,cnj,cnp,[cns): left_most |
| 192 |
# level 2: (clk,clt],cmc,cml,cmu,#cnd#,[cnv,coe): causes merge |
| 193 |
# level 3: (ced,cfe,cgf,chg],cih,cji,[ckj,#clk#,con,cpo): left_most possible (not cause merge) |
| 194 |
# level 4: (ast,avw,ayz,bll,boo,brr,buu,bxx],cba,#ced#,[cqp,cts,cwv,czy,ddb,dge,dsq,dvt): no merge, not left_most possible |
| 195 |
# So, the top X-latch page is at level4. (ast~dvt) |
| 196 |
|
| 197 |
# blocking domain based on whether its ancestor is latched or not. |
| 198 |
# (*[]: ancestor is X-latched) |
| 199 |
# level 0: ...(asq,asr,ass) [(ast,asu,asv)...(dyt,dyu,dyv)] (dyw,dyx,dyy)... |
| 200 |
|
| 201 |
# Not blocked searches |
| 202 |
## In MariaDB, both these will block, because we use different DEBUG_SYNC |
| 203 |
## instrumentation (in rollback, not purge) and the root page (number 3) |
| 204 |
## is being latched in row_undo_mod_remove_clust_low(). |
| 205 |
## SELECT a00 FROM t1 WHERE a00 = 'ass'; |
| 206 |
## SELECT a00 FROM t1 WHERE a00 = 'dyx'; |
| 207 |
|
| 208 |
## SET DEBUG_SYNC = 'rw_s_lock_waiting SIGNAL lockwait1'; |
| 209 |
## send SELECT a00 FROM t1 WHERE a00 = 'ast'; |
| 210 |
|
| 211 |
## connection con2; |
| 212 |
## SET DEBUG_SYNC = 'rw_s_lock_waiting SIGNAL lockwait2'; |
| 213 |
## send SELECT a00 FROM t1 WHERE a00 = 'dyw'; |
| 214 |
|
| 215 |
connection default; |
| 216 |
## SET DEBUG_SYNC = 'now WAIT_FOR lockwait1'; |
| 217 |
## SET DEBUG_SYNC = 'now WAIT_FOR lockwait2'; |
| 218 |
SET DEBUG_SYNC = 'now SIGNAL resume'; |
| 219 |
|
| 220 |
## connection con1; |
| 221 |
## reap; |
| 222 |
disconnect con1; |
| 223 |
|
| 224 |
connection con2; |
| 225 |
reap; |
| 226 |
disconnect con2; |
| 227 |
|
| 228 |
connection default; |
| 229 |
ANALYZE TABLE t1; |
| 230 |
SELECT CLUST_INDEX_SIZE FROM information_schema.INNODB_SYS_TABLESTATS WHERE NAME = 'test/t1'; |
| 231 |
|
| 232 |
|
| 233 |
# Cleanup |
| 234 |
SET DEBUG_SYNC = 'RESET'; |
| 235 |
|
| 236 |
DROP TABLE t1; |
| 237 |
|
| 238 |
--disable_query_log |
| 239 |
SET GLOBAL innodb_limit_optimistic_insert_debug = @old_innodb_limit_optimistic_insert_debug; |
| 240 |
SET GLOBAL innodb_adaptive_hash_index = @old_innodb_adaptive_hash_index; |
| 241 |
SET GLOBAL innodb_stats_persistent = @old_innodb_stats_persistent; |
| 242 |
--enable_query_log |
| 243 |
|
| 244 |
--source include/wait_until_count_sessions.inc |