forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit14a91a8
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 parent945ae92 commit14a91a8
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 | |
---|---|---|---|
| |||
115 | 115 |
| |
116 | 116 |
| |
117 | 117 |
| |
118 |
| - | |
| 118 | + | |
119 | 119 |
| |
120 | 120 |
| |
121 | 121 |
| |
| |||
3112 | 3112 |
| |
3113 | 3113 |
| |
3114 | 3114 |
| |
3115 |
| - | |
| 3115 | + | |
| 3116 | + | |
3116 | 3117 |
| |
3117 |
| - | |
| 3118 | + | |
3118 | 3119 |
| |
3119 | 3120 |
| |
3120 | 3121 |
| |
3121 |
| - | |
3122 |
| - | |
3123 |
| - | |
| 3122 | + | |
| 3123 | + | |
| 3124 | + | |
| 3125 | + | |
| 3126 | + | |
| 3127 | + | |
| 3128 | + | |
3124 | 3129 |
| |
3125 | 3130 |
| |
3126 | 3131 |
| |
| |||
3710 | 3715 |
| |
3711 | 3716 |
| |
3712 | 3717 |
| |
| 3718 | + | |
3713 | 3719 |
| |
3714 | 3720 |
| |
3715 |
| - | |
| 3721 | + | |
3716 | 3722 |
| |
3717 | 3723 |
| |
3718 | 3724 |
| |
3719 |
| - | |
3720 |
| - | |
3721 |
| - | |
| 3725 | + | |
| 3726 | + | |
| 3727 | + | |
| 3728 | + | |
| 3729 | + | |
| 3730 | + | |
| 3731 | + | |
3722 | 3732 |
| |
3723 | 3733 |
| |
3724 | 3734 |
| |
| |||
4600 | 4610 |
| |
4601 | 4611 |
| |
4602 | 4612 |
| |
| 4613 | + | |
4603 | 4614 |
| |
4604 | 4615 |
| |
4605 | 4616 |
| |
| |||
4625 | 4636 |
| |
4626 | 4637 |
| |
4627 | 4638 |
| |
| 4639 | + | |
4628 | 4640 |
| |
4629 | 4641 |
| |
4630 | 4642 |
| |
| |||
4653 | 4665 |
| |
4654 | 4666 |
| |
4655 | 4667 |
| |
| 4668 | + | |
| 4669 | + | |
| 4670 | + | |
| 4671 | + | |
| 4672 | + | |
| 4673 | + | |
| 4674 | + | |
| 4675 | + | |
| 4676 | + | |
| 4677 | + | |
| 4678 | + | |
| 4679 | + | |
| 4680 | + | |
| 4681 | + | |
| 4682 | + | |
4656 | 4683 |
| |
4657 | 4684 |
| |
4658 | 4685 |
| |
| |||
4807 | 4834 |
| |
4808 | 4835 |
| |
4809 | 4836 |
| |
4810 |
| - | |
| 4837 | + | |
4811 | 4838 |
| |
4812 | 4839 |
| |
4813 | 4840 |
| |
| |||
4884 | 4911 |
| |
4885 | 4912 |
| |
4886 | 4913 |
| |
4887 |
| - | |
| 4914 | + | |
| 4915 | + | |
4888 | 4916 |
| |
4889 | 4917 |
| |
4890 | 4918 |
| |
4891 | 4919 |
| |
4892 | 4920 |
| |
4893 |
| - | |
| 4921 | + | |
| 4922 | + | |
4894 | 4923 |
| |
4895 | 4924 |
| |
4896 | 4925 |
| |
| |||
7062 | 7091 |
| |
7063 | 7092 |
| |
7064 | 7093 |
| |
| 7094 | + | |
| 7095 | + | |
| 7096 | + | |
7065 | 7097 |
| |
7066 | 7098 |
| |
7067 | 7099 |
| |
7068 |
| - | |
| 7100 | + | |
7069 | 7101 |
| |
7070 | 7102 |
| |
7071 | 7103 |
| |
| |||
7086 | 7118 |
| |
7087 | 7119 |
| |
7088 | 7120 |
| |
7089 |
| - | |
| 7121 | + | |
| 7122 | + | |
7090 | 7123 |
| |
7091 |
| - | |
7092 |
| - | |
7093 |
| - | |
| 7124 | + | |
7094 | 7125 |
| |
7095 |
| - | |
| 7126 | + | |
7096 | 7127 |
| |
7097 | 7128 |
| |
| 7129 | + | |
| 7130 | + | |
| 7131 | + | |
| 7132 | + | |
| 7133 | + | |
| 7134 | + | |
| 7135 | + | |
| 7136 | + | |
| 7137 | + | |
| 7138 | + | |
7098 | 7139 |
| |
7099 | 7140 |
| |
7100 | 7141 |
| |
| |||
7113 | 7154 |
| |
7114 | 7155 |
| |
7115 | 7156 |
| |
7116 |
| - | |
| 7157 | + | |
| 7158 | + | |
| 7159 | + | |
7117 | 7160 |
| |
7118 | 7161 |
| |
7119 |
| - | |
7120 | 7162 |
| |
7121 | 7163 |
| |
7122 | 7164 |
| |
|
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 | |
---|---|---|---|
| |||
46 | 46 |
| |
47 | 47 |
| |
48 | 48 |
| |
| 49 | + | |
49 | 50 |
| |
50 | 51 |
| |
51 | 52 |
| |
|
0 commit comments
Comments
(0)