- Notifications
You must be signed in to change notification settings - Fork28
Commit5246d3e
committed
Avoid spurious deadlocks when upgrading a tuple lock
This puts back reverted commitde87a08, with some bug fixes.When two (or more) transactions are waiting for transaction T1 to release atuple-level lock, and transaction T1 upgrades its lock to a higher level, aspurious deadlock can be reported among the waiting transactions when T1finishes. The simplest example case seems to be:T1: select id from job where name = 'a' for key share;Y: select id from job where name = 'a' for update; -- starts waiting for T1Z: select id from job where name = 'a' for key share;T1: update job set name = 'b' where id = 1;Z: update job set name = 'c' where id = 1; -- starts waiting for T1T1: rollback;At this point, transaction Y is rolled back on account of a deadlock: Yholds the heavyweight tuple lock and is waiting for the Xmax to be released,while Z holds part of the multixact and tries to acquire the heavyweightlock (per protocol) and goes to sleep; once T1 releases its part of themultixact, Z is awakened only to be put back to sleep on the heavyweightlock that Y is holding while sleeping. Kaboom.This can be avoided by having Z skip the heavyweight lock acquisition. Asfar as I can see, the biggest downside is that if there are multiple Ztransactions, the order in which they resume after T1 finishes is notguaranteed.Backpatch to 9.6. The patch applies cleanly on 9.5, but the new tests don'twork there (because isolationtester is not smart enough), so I'm not goingto risk it.Author: Oleksii KliukinDiscussion:https://postgr.es/m/B9C9D7CD-EB94-4635-91B6-E558ACEC0EC3@hintbits.comDiscussion:https://postgr.es/m/2815.1560521451@sss.pgh.pa.us1 parent14d8b53 commit5246d3e
File tree
5 files changed
+340
-21
lines changed- src
- backend/access/heap
- test/isolation
- expected
- specs
5 files changed
+340
-21
lines changedLines changed: 10 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
36 | 36 |
| |
37 | 37 |
| |
38 | 38 |
| |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
39 | 49 |
| |
40 | 50 |
| |
41 | 51 |
| |
|
Lines changed: 62 additions & 21 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
120 | 120 |
| |
121 | 121 |
| |
122 | 122 |
| |
123 |
| - | |
| 123 | + | |
124 | 124 |
| |
125 | 125 |
| |
126 | 126 |
| |
| |||
3161 | 3161 |
| |
3162 | 3162 |
| |
3163 | 3163 |
| |
3164 |
| - | |
| 3164 | + | |
| 3165 | + | |
3165 | 3166 |
| |
3166 |
| - | |
| 3167 | + | |
3167 | 3168 |
| |
3168 | 3169 |
| |
3169 | 3170 |
| |
3170 |
| - | |
3171 |
| - | |
3172 |
| - | |
| 3171 | + | |
| 3172 | + | |
| 3173 | + | |
| 3174 | + | |
| 3175 | + | |
| 3176 | + | |
| 3177 | + | |
3173 | 3178 |
| |
3174 | 3179 |
| |
3175 | 3180 |
| |
| |||
3768 | 3773 |
| |
3769 | 3774 |
| |
3770 | 3775 |
| |
| 3776 | + | |
3771 | 3777 |
| |
3772 | 3778 |
| |
3773 |
| - | |
| 3779 | + | |
3774 | 3780 |
| |
3775 | 3781 |
| |
3776 | 3782 |
| |
3777 |
| - | |
3778 |
| - | |
3779 |
| - | |
| 3783 | + | |
| 3784 | + | |
| 3785 | + | |
| 3786 | + | |
| 3787 | + | |
| 3788 | + | |
| 3789 | + | |
3780 | 3790 |
| |
3781 | 3791 |
| |
3782 | 3792 |
| |
| |||
4701 | 4711 |
| |
4702 | 4712 |
| |
4703 | 4713 |
| |
| 4714 | + | |
4704 | 4715 |
| |
4705 | 4716 |
| |
4706 | 4717 |
| |
| |||
4799 | 4810 |
| |
4800 | 4811 |
| |
4801 | 4812 |
| |
| 4813 | + | |
| 4814 | + | |
| 4815 | + | |
| 4816 | + | |
| 4817 | + | |
| 4818 | + | |
| 4819 | + | |
| 4820 | + | |
| 4821 | + | |
| 4822 | + | |
| 4823 | + | |
| 4824 | + | |
| 4825 | + | |
| 4826 | + | |
| 4827 | + | |
4802 | 4828 |
| |
4803 | 4829 |
| |
4804 | 4830 |
| |
| |||
4953 | 4979 |
| |
4954 | 4980 |
| |
4955 | 4981 |
| |
4956 |
| - | |
| 4982 | + | |
4957 | 4983 |
| |
4958 | 4984 |
| |
4959 | 4985 |
| |
| |||
5030 | 5056 |
| |
5031 | 5057 |
| |
5032 | 5058 |
| |
5033 |
| - | |
| 5059 | + | |
| 5060 | + | |
5034 | 5061 |
| |
5035 | 5062 |
| |
5036 | 5063 |
| |
5037 | 5064 |
| |
5038 | 5065 |
| |
5039 |
| - | |
| 5066 | + | |
| 5067 | + | |
5040 | 5068 |
| |
5041 | 5069 |
| |
5042 | 5070 |
| |
| |||
7214 | 7242 |
| |
7215 | 7243 |
| |
7216 | 7244 |
| |
| 7245 | + | |
| 7246 | + | |
| 7247 | + | |
7217 | 7248 |
| |
7218 | 7249 |
| |
7219 | 7250 |
| |
7220 |
| - | |
| 7251 | + | |
7221 | 7252 |
| |
7222 | 7253 |
| |
7223 | 7254 |
| |
| |||
7238 | 7269 |
| |
7239 | 7270 |
| |
7240 | 7271 |
| |
7241 |
| - | |
| 7272 | + | |
| 7273 | + | |
7242 | 7274 |
| |
7243 |
| - | |
7244 |
| - | |
7245 |
| - | |
| 7275 | + | |
7246 | 7276 |
| |
7247 |
| - | |
| 7277 | + | |
7248 | 7278 |
| |
7249 | 7279 |
| |
| 7280 | + | |
| 7281 | + | |
| 7282 | + | |
| 7283 | + | |
| 7284 | + | |
| 7285 | + | |
| 7286 | + | |
| 7287 | + | |
| 7288 | + | |
| 7289 | + | |
7250 | 7290 |
| |
7251 | 7291 |
| |
7252 | 7292 |
| |
| |||
7265 | 7305 |
| |
7266 | 7306 |
| |
7267 | 7307 |
| |
7268 |
| - | |
| 7308 | + | |
| 7309 | + | |
| 7310 | + | |
7269 | 7311 |
| |
7270 | 7312 |
| |
7271 |
| - | |
7272 | 7313 |
| |
7273 | 7314 |
| |
7274 | 7315 |
| |
|
Lines changed: 195 additions & 0 deletions
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 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + |
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
46 | 46 |
| |
47 | 47 |
| |
48 | 48 |
| |
| 49 | + | |
49 | 50 |
| |
50 | 51 |
| |
51 | 52 |
| |
|
0 commit comments
Comments
(0)