- Notifications
You must be signed in to change notification settings - Fork5
Commit1a917ae
committed
Fix race when updating a tuple concurrently locked by another process
If a tuple is locked, and this lock is later upgraded either to anupdate or to a stronger lock, and in the meantime some other processtries to lock, update or delete the same tuple, it (the tuple) could endup being updated twice, or having conflicting locks held.The reason for this is that the second updater checks for a change inXmax value, or in the HEAP_XMAX_IS_MULTI infomask bit, after noticingthe first lock; and if there's a change, it restarts and re-evaluatesits ability to update the tuple. But it neglected to check for changesin lock strength or in lock-vs-update status when those two propertiesstayed the same. This would lead it to take the wrong decision andcontinue with its own update, when in reality it shouldn't do so butinstead restart from the top.This could lead to either an assertion failure much later (when amultixact containing multiple updates is detected), or duplicate copiesof tuples.To fix, make sure to compare the other relevant infomask bits alongsidethe Xmax value and HEAP_XMAX_IS_MULTI bit, and restart from the top ifnecessary.Also, in the belt-and-suspenders spirit, add a check toMultiXactCreateFromMembers that a multixact being created does not havetwo or more members that are claimed to be updates. This should protectagainst other bugs that might cause similar bogus situations.Backpatch to 9.3, where the possibility of multixacts containing updateswas introduced. (In prior versions it was possible to have the tuplelock upgraded from shared to exclusive, and an update would not restartfrom the top; yet we're protected against a bug there because there'salways a sleep to wait for the locking transaction to complete beforecontinuing to do anything. Really, the fact that tuple locks alwaysconflicted with concurrent updates is what protected against bugs here.)Per report from Andrew Dunstan and Josh Berkus in thread athttp://www.postgresql.org/message-id/534C8B33.9050807@pgexperts.comBug analysis by Andres Freund.1 parentd19bd29 commit1a917ae
File tree
3 files changed
+51
-13
lines changed- src
- backend/access
- heap
- transam
- include/access
3 files changed
+51
-13
lines changedLines changed: 30 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
190 | 190 |
| |
191 | 191 |
| |
192 | 192 |
| |
193 |
| - | |
194 |
| - | |
195 |
| - | |
196 | 193 |
| |
197 | 194 |
| |
198 | 195 |
| |
| |||
2588 | 2585 |
| |
2589 | 2586 |
| |
2590 | 2587 |
| |
| 2588 | + | |
| 2589 | + | |
| 2590 | + | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
2591 | 2609 |
| |
2592 | 2610 |
| |
2593 | 2611 |
| |
| |||
2725 | 2743 |
| |
2726 | 2744 |
| |
2727 | 2745 |
| |
2728 |
| - | |
| 2746 | + | |
2729 | 2747 |
| |
2730 | 2748 |
| |
2731 | 2749 |
| |
| |||
2751 | 2769 |
| |
2752 | 2770 |
| |
2753 | 2771 |
| |
2754 |
| - | |
| 2772 | + | |
2755 | 2773 |
| |
2756 | 2774 |
| |
2757 | 2775 |
| |
| |||
3278 | 3296 |
| |
3279 | 3297 |
| |
3280 | 3298 |
| |
3281 |
| - | |
| 3299 | + | |
3282 | 3300 |
| |
3283 | 3301 |
| |
3284 | 3302 |
| |
| |||
3332 | 3350 |
| |
3333 | 3351 |
| |
3334 | 3352 |
| |
3335 |
| - | |
| 3353 | + | |
3336 | 3354 |
| |
3337 | 3355 |
| |
3338 | 3356 |
| |
| |||
3353 | 3371 |
| |
3354 | 3372 |
| |
3355 | 3373 |
| |
3356 |
| - | |
| 3374 | + | |
3357 | 3375 |
| |
3358 | 3376 |
| |
3359 | 3377 |
| |
| |||
4357 | 4375 |
| |
4358 | 4376 |
| |
4359 | 4377 |
| |
4360 |
| - | |
| 4378 | + | |
4361 | 4379 |
| |
4362 | 4380 |
| |
4363 | 4381 |
| |
| |||
4376 | 4394 |
| |
4377 | 4395 |
| |
4378 | 4396 |
| |
4379 |
| - | |
| 4397 | + | |
4380 | 4398 |
| |
4381 | 4399 |
| |
4382 | 4400 |
| |
| |||
4444 | 4462 |
| |
4445 | 4463 |
| |
4446 | 4464 |
| |
4447 |
| - | |
| 4465 | + | |
4448 | 4466 |
| |
4449 | 4467 |
| |
4450 | 4468 |
| |
| |||
4500 | 4518 |
| |
4501 | 4519 |
| |
4502 | 4520 |
| |
4503 |
| - | |
| 4521 | + | |
4504 | 4522 |
| |
4505 | 4523 |
| |
4506 | 4524 |
| |
|
Lines changed: 17 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
457 | 457 |
| |
458 | 458 |
| |
459 | 459 |
| |
460 |
| - | |
| 460 | + | |
461 | 461 |
| |
462 | 462 |
| |
463 | 463 |
| |
| |||
713 | 713 |
| |
714 | 714 |
| |
715 | 715 |
| |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
716 | 732 |
| |
717 | 733 |
| |
718 | 734 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
48 | 48 |
| |
49 | 49 |
| |
50 | 50 |
| |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
51 | 55 |
| |
52 | 56 |
| |
53 | 57 |
| |
|
0 commit comments
Comments
(0)