Commit 2d54bdb
committed
Bug#37486661 ndb_metadata thread can deadlock with truncate table
Summary: Prevent errors through lock corruption during TRUNCATE by not closing and reopening the NDB shared table handler while the table is recreated. Problem: When running continuous TRUNCATE SQL commands, while concurrently performing a NDB Backup, the MySQL Server could hang or ultimately crash. The hang and crash occurred around the same code point, at thr_lock(..), respectively with `wait_for_lock` and `has_old_lock`. Analysis: The order of operations of the TRUNCATE command, at the NDB plugin layer, can be narrowed to three main operations: 1. CLOSE table (ha_ndbcluster::close) 2. CREATE TABLE (TRUNCATE <=> DROP AND CREATE with ha_ndbcluster::create) 3. OPEN table (ha_ndbcluster::open) By observing the patterns, it is seen that if the Table undergoing TRUNCATE is still under BACKUP then the DROP fails and thus step (2) returns early. This causes the NDB_SHARE, a similar table handle as TABLE_SHARE, to continue to exist. On a success case, DROP would cause NDB_SHARE to be marked as dropped (ref count = 0) and CREATE would create a new NDB_SHARE. On a failed DROP case, the original NDB_SHARE is not marked as dropped. At this point, the OPEN step (3) is run and one of the operations is to initialize the thr_lock data for the handler, linking it with the NDB_SHARE thr_lock, and setting it into TL_UNLOCK. But, the NDB_SHARE and the handler's thr_lock data was LOCK'ed (specifically TL_WRITE_ALLOW_WRITE) therefore the aforementioned operation (set to TL_UNLOCK) effectively tramples the current lock data. The result is a badly cleaned and "unlocked" lock. The subsequent operations on that Table that require SQL locks might find the two problematic scenarios: 1. Found old lock with an owner and will wait thus, but that owner has already exited and trampled the lock 2. Will find old lock with some bad data and will SIGSEGV when reading the owner. Solution: Going back the call trace for the TRUNCATE command, the following list is an approximate order of operations: - OPEN table (SQL code) - LOCK table (1) (SQL code) - CLOSE table (NDB code) - TRUNCATE table, i.e., DROP/CREATE (2) (NDB code) - OPEN table (3) (NDB code) - UNLOCK table (4) (SQL code) - CLOSE TABLE (SQL code) The Table is already opened before TRUNCATE of SE is called. Therefore, if CLOSE and OPEN around TRUNCATE (ha_ndbcluster::create) can be ignored, then the LOCK structure remains untouched. The Table is already CLOSED when UNLOCKED, so it is expected that the resources the HANDLER has established when OPEN (buffers, etc) are to be freed. More specifically: On success: - DROP will mark the existing (locked) NDB_SHARE as Dropped (not yet physically released as the session has a reference to it) - OPEN will create a new NDB_SHARE (2 shares will exist) - UNLOCK will remove locks from old NDB_SHARE - CLOSE will reduce ref count on old NDB_SHARE decrementing to zero + freeing it (1 share exists) On failure: - DROP will do nothing - UNLOCK will remove locks from old NDB_SHARE - CLOSE will reduce ref count on old NDB_SHARE, but it will be retained (1 share exists) Change-Id: Ib2cbb3cf49ceac6ad2717e000b5b89beb026e4e41 parent 4c1fdd1 commit 2d54bdb
File tree
5 files changed
+322
-9
lines changed- mysql-test/suite/ndb
- r
- t
- storage/ndb/plugin
5 files changed
+322
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9388 | 9388 | | |
9389 | 9389 | | |
9390 | 9390 | | |
9391 | | - | |
| 9391 | + | |
| 9392 | + | |
| 9393 | + | |
| 9394 | + | |
| 9395 | + | |
| 9396 | + | |
9392 | 9397 | | |
9393 | 9398 | | |
9394 | 9399 | | |
| |||
10386 | 10391 | | |
10387 | 10392 | | |
10388 | 10393 | | |
10389 | | - | |
10390 | | - | |
10391 | | - | |
| 10394 | + | |
| 10395 | + | |
| 10396 | + | |
10392 | 10397 | | |
10393 | 10398 | | |
10394 | 10399 | | |
10395 | 10400 | | |
10396 | 10401 | | |
10397 | 10402 | | |
10398 | | - | |
10399 | | - | |
10400 | | - | |
| 10403 | + | |
| 10404 | + | |
| 10405 | + | |
| 10406 | + | |
| 10407 | + | |
| 10408 | + | |
| 10409 | + | |
| 10410 | + | |
| 10411 | + | |
| 10412 | + | |
| 10413 | + | |
| 10414 | + | |
| 10415 | + | |
| 10416 | + | |
| 10417 | + | |
| 10418 | + | |
| 10419 | + | |
| 10420 | + | |
| 10421 | + | |
| 10422 | + | |
| 10423 | + | |
| 10424 | + | |
| 10425 | + | |
10401 | 10426 | | |
10402 | | - | |
10403 | | - | |
| 10427 | + | |
10404 | 10428 | | |
10405 | 10429 | | |
10406 | 10430 | | |
| |||
11120 | 11144 | | |
11121 | 11145 | | |
11122 | 11146 | | |
| 11147 | + | |
| 11148 | + | |
| 11149 | + | |
| 11150 | + | |
| 11151 | + | |
11123 | 11152 | | |
11124 | 11153 | | |
11125 | 11154 | | |
| |||
11232 | 11261 | | |
11233 | 11262 | | |
11234 | 11263 | | |
| 11264 | + | |
| 11265 | + | |
| 11266 | + | |
| 11267 | + | |
| 11268 | + | |
11235 | 11269 | | |
11236 | 11270 | | |
11237 | 11271 | | |
| |||
11548 | 11582 | | |
11549 | 11583 | | |
11550 | 11584 | | |
| 11585 | + | |
11551 | 11586 | | |
11552 | 11587 | | |
11553 | 11588 | | |
| |||
11864 | 11899 | | |
11865 | 11900 | | |
11866 | 11901 | | |
| 11902 | + | |
| 11903 | + | |
| 11904 | + | |
| 11905 | + | |
| 11906 | + | |
| 11907 | + | |
| 11908 | + | |
| 11909 | + | |
| 11910 | + | |
| 11911 | + | |
| 11912 | + | |
| 11913 | + | |
| 11914 | + | |
| 11915 | + | |
| 11916 | + | |
| 11917 | + | |
| 11918 | + | |
11867 | 11919 | | |
11868 | 11920 | | |
11869 | 11921 | | |
| |||
11887 | 11939 | | |
11888 | 11940 | | |
11889 | 11941 | | |
| 11942 | + | |
| 11943 | + | |
11890 | 11944 | | |
11891 | 11945 | | |
11892 | 11946 | | |
| |||
0 commit comments