Commit 459c64d
committed
Fix concurrent locking of tuple update chain
If several sessions are concurrently locking a tuple update chain with
nonconflicting lock modes using an old snapshot, and they all succeed,
it may happen that some of them fail because of restarting the loop (due
to a concurrent Xmax change) and getting an error in the subsequent pass
while trying to obtain a tuple lock that they already have in some tuple
version.
This can only happen with very high concurrency (where a row is being
both updated and FK-checked by multiple transactions concurrently), but
it's been observed in the field and can have unpleasant consequences
such as an FK check failing to see a tuple that definitely exists:
ERROR: insert or update on table "child_table" violates foreign key constraint "fk_constraint_name"
DETAIL: Key (keyid)=(123456) is not present in table "parent_table".
(where the key is observably present in the table).
Discussion: https://postgr.es/m/20170714210011.r25mrff4nxjhmf3g@alvherre.pgsql1 parent c28e4f4 commit 459c64d
1 file changed
+37
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5524 | 5524 | | |
5525 | 5525 | | |
5526 | 5526 | | |
5527 | | - | |
5528 | | - | |
| 5527 | + | |
| 5528 | + | |
| 5529 | + | |
| 5530 | + | |
5529 | 5531 | | |
5530 | 5532 | | |
5531 | 5533 | | |
| |||
5548 | 5550 | | |
5549 | 5551 | | |
5550 | 5552 | | |
5551 | | - | |
5552 | | - | |
| 5553 | + | |
| 5554 | + | |
| 5555 | + | |
5553 | 5556 | | |
5554 | 5557 | | |
5555 | 5558 | | |
| |||
5748 | 5751 | | |
5749 | 5752 | | |
5750 | 5753 | | |
| 5754 | + | |
| 5755 | + | |
| 5756 | + | |
| 5757 | + | |
| 5758 | + | |
| 5759 | + | |
| 5760 | + | |
| 5761 | + | |
| 5762 | + | |
| 5763 | + | |
| 5764 | + | |
| 5765 | + | |
| 5766 | + | |
| 5767 | + | |
| 5768 | + | |
| 5769 | + | |
5751 | 5770 | | |
5752 | 5771 | | |
5753 | 5772 | | |
| |||
5808 | 5827 | | |
5809 | 5828 | | |
5810 | 5829 | | |
| 5830 | + | |
| 5831 | + | |
| 5832 | + | |
| 5833 | + | |
| 5834 | + | |
| 5835 | + | |
| 5836 | + | |
| 5837 | + | |
| 5838 | + | |
| 5839 | + | |
| 5840 | + | |
| 5841 | + | |
| 5842 | + | |
5811 | 5843 | | |
5812 | 5844 | | |
5813 | 5845 | | |
| |||
5868 | 5900 | | |
5869 | 5901 | | |
5870 | 5902 | | |
| 5903 | + | |
5871 | 5904 | | |
5872 | 5905 | | |
5873 | 5906 | | |
| |||
0 commit comments