- Notifications
You must be signed in to change notification settings - Fork28
Commitde87a08
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 parent3c8f8f6 commitde87a08
File tree
5 files changed
+281
-21
lines changed- src
- backend/access/heap
- test/isolation
- expected
- specs
5 files changed
+281
-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: 63 additions & 21 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
95 | 95 |
| |
96 | 96 |
| |
97 | 97 |
| |
98 |
| - | |
| 98 | + | |
99 | 99 |
| |
100 | 100 |
| |
101 | 101 |
| |
| |||
2547 | 2547 |
| |
2548 | 2548 |
| |
2549 | 2549 |
| |
2550 |
| - | |
| 2550 | + | |
| 2551 | + | |
2551 | 2552 |
| |
2552 |
| - | |
| 2553 | + | |
2553 | 2554 |
| |
2554 | 2555 |
| |
2555 | 2556 |
| |
2556 |
| - | |
2557 |
| - | |
2558 |
| - | |
| 2557 | + | |
| 2558 | + | |
| 2559 | + | |
| 2560 | + | |
| 2561 | + | |
| 2562 | + | |
| 2563 | + | |
2559 | 2564 |
| |
2560 | 2565 |
| |
2561 | 2566 |
| |
| |||
3126 | 3131 |
| |
3127 | 3132 |
| |
3128 | 3133 |
| |
| 3134 | + | |
3129 | 3135 |
| |
3130 | 3136 |
| |
3131 |
| - | |
| 3137 | + | |
3132 | 3138 |
| |
3133 | 3139 |
| |
3134 | 3140 |
| |
3135 |
| - | |
3136 |
| - | |
3137 |
| - | |
| 3141 | + | |
| 3142 | + | |
| 3143 | + | |
| 3144 | + | |
| 3145 | + | |
| 3146 | + | |
| 3147 | + | |
3138 | 3148 |
| |
3139 | 3149 |
| |
3140 | 3150 |
| |
| |||
4028 | 4038 |
| |
4029 | 4039 |
| |
4030 | 4040 |
| |
| 4041 | + | |
4031 | 4042 |
| |
4032 | 4043 |
| |
4033 | 4044 |
| |
| |||
4053 | 4064 |
| |
4054 | 4065 |
| |
4055 | 4066 |
| |
| 4067 | + | |
4056 | 4068 |
| |
4057 | 4069 |
| |
4058 | 4070 |
| |
| |||
4081 | 4093 |
| |
4082 | 4094 |
| |
4083 | 4095 |
| |
| 4096 | + | |
| 4097 | + | |
| 4098 | + | |
| 4099 | + | |
| 4100 | + | |
| 4101 | + | |
| 4102 | + | |
| 4103 | + | |
| 4104 | + | |
| 4105 | + | |
| 4106 | + | |
| 4107 | + | |
| 4108 | + | |
| 4109 | + | |
| 4110 | + | |
4084 | 4111 |
| |
4085 | 4112 |
| |
4086 | 4113 |
| |
| |||
4235 | 4262 |
| |
4236 | 4263 |
| |
4237 | 4264 |
| |
4238 |
| - | |
| 4265 | + | |
4239 | 4266 |
| |
4240 | 4267 |
| |
4241 | 4268 |
| |
| |||
4312 | 4339 |
| |
4313 | 4340 |
| |
4314 | 4341 |
| |
4315 |
| - | |
| 4342 | + | |
| 4343 | + | |
4316 | 4344 |
| |
4317 | 4345 |
| |
4318 | 4346 |
| |
4319 | 4347 |
| |
4320 | 4348 |
| |
4321 |
| - | |
| 4349 | + | |
| 4350 | + | |
4322 | 4351 |
| |
4323 | 4352 |
| |
4324 | 4353 |
| |
| |||
6516 | 6545 |
| |
6517 | 6546 |
| |
6518 | 6547 |
| |
| 6548 | + | |
| 6549 | + | |
| 6550 | + | |
6519 | 6551 |
| |
6520 | 6552 |
| |
6521 | 6553 |
| |
6522 |
| - | |
| 6554 | + | |
6523 | 6555 |
| |
6524 | 6556 |
| |
6525 | 6557 |
| |
| |||
6540 | 6572 |
| |
6541 | 6573 |
| |
6542 | 6574 |
| |
6543 |
| - | |
| 6575 | + | |
| 6576 | + | |
6544 | 6577 |
| |
6545 |
| - | |
6546 |
| - | |
6547 |
| - | |
| 6578 | + | |
6548 | 6579 |
| |
6549 |
| - | |
| 6580 | + | |
6550 | 6581 |
| |
6551 | 6582 |
| |
| 6583 | + | |
| 6584 | + | |
| 6585 | + | |
| 6586 | + | |
| 6587 | + | |
| 6588 | + | |
| 6589 | + | |
| 6590 | + | |
| 6591 | + | |
| 6592 | + | |
6552 | 6593 |
| |
6553 | 6594 |
| |
6554 | 6595 |
| |
| |||
6567 | 6608 |
| |
6568 | 6609 |
| |
6569 | 6610 |
| |
6570 |
| - | |
| 6611 | + | |
| 6612 | + | |
| 6613 | + | |
6571 | 6614 |
| |
6572 | 6615 |
| |
6573 |
| - | |
6574 | 6616 |
| |
6575 | 6617 |
| |
6576 | 6618 |
| |
|
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 | + |
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
49 | 49 |
| |
50 | 50 |
| |
51 | 51 |
| |
| 52 | + | |
52 | 53 |
| |
53 | 54 |
| |
54 | 55 |
| |
|
0 commit comments
Comments
(0)