forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit85600b7
committed
Avoid spurious deadlocks when upgrading a tuple lock
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 XZ: 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 XT1: 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 X 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 X 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.com1 parent07accce commit85600b7
File tree
5 files changed
+281
-21
lines changed- src
- backend/access/heap
- test/isolation
- expected
- specs
5 files changed
+281
-21
lines changed| 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 | | |
| |||
| 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 | | |
| |||
4746 | 4756 | | |
4747 | 4757 | | |
4748 | 4758 | | |
| 4759 | + | |
4749 | 4760 | | |
4750 | 4761 | | |
4751 | 4762 | | |
| |||
4771 | 4782 | | |
4772 | 4783 | | |
4773 | 4784 | | |
| 4785 | + | |
4774 | 4786 | | |
4775 | 4787 | | |
4776 | 4788 | | |
| |||
4799 | 4811 | | |
4800 | 4812 | | |
4801 | 4813 | | |
| 4814 | + | |
| 4815 | + | |
| 4816 | + | |
| 4817 | + | |
| 4818 | + | |
| 4819 | + | |
| 4820 | + | |
| 4821 | + | |
| 4822 | + | |
| 4823 | + | |
| 4824 | + | |
| 4825 | + | |
| 4826 | + | |
| 4827 | + | |
| 4828 | + | |
4802 | 4829 | | |
4803 | 4830 | | |
4804 | 4831 | | |
| |||
4953 | 4980 | | |
4954 | 4981 | | |
4955 | 4982 | | |
4956 | | - | |
| 4983 | + | |
4957 | 4984 | | |
4958 | 4985 | | |
4959 | 4986 | | |
| |||
5030 | 5057 | | |
5031 | 5058 | | |
5032 | 5059 | | |
5033 | | - | |
| 5060 | + | |
| 5061 | + | |
5034 | 5062 | | |
5035 | 5063 | | |
5036 | 5064 | | |
5037 | 5065 | | |
5038 | 5066 | | |
5039 | | - | |
| 5067 | + | |
| 5068 | + | |
5040 | 5069 | | |
5041 | 5070 | | |
5042 | 5071 | | |
| |||
7214 | 7243 | | |
7215 | 7244 | | |
7216 | 7245 | | |
| 7246 | + | |
| 7247 | + | |
| 7248 | + | |
7217 | 7249 | | |
7218 | 7250 | | |
7219 | 7251 | | |
7220 | | - | |
| 7252 | + | |
7221 | 7253 | | |
7222 | 7254 | | |
7223 | 7255 | | |
| |||
7238 | 7270 | | |
7239 | 7271 | | |
7240 | 7272 | | |
7241 | | - | |
| 7273 | + | |
| 7274 | + | |
7242 | 7275 | | |
7243 | | - | |
7244 | | - | |
7245 | | - | |
| 7276 | + | |
7246 | 7277 | | |
7247 | | - | |
| 7278 | + | |
7248 | 7279 | | |
7249 | 7280 | | |
| 7281 | + | |
| 7282 | + | |
| 7283 | + | |
| 7284 | + | |
| 7285 | + | |
| 7286 | + | |
| 7287 | + | |
| 7288 | + | |
| 7289 | + | |
| 7290 | + | |
7250 | 7291 | | |
7251 | 7292 | | |
7252 | 7293 | | |
| |||
7265 | 7306 | | |
7266 | 7307 | | |
7267 | 7308 | | |
7268 | | - | |
| 7309 | + | |
| 7310 | + | |
| 7311 | + | |
7269 | 7312 | | |
7270 | 7313 | | |
7271 | | - | |
7272 | 7314 | | |
7273 | 7315 | | |
7274 | 7316 | | |
| |||
Lines changed: 150 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 | + | |
| 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)