Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit649dd1b

Browse files
committed
Avoid serializability errors when locking a tuple with a committed update
When key-share locking a tuple that has been not-key-updated, and theupdate is a committed transaction, in some cases we raisedserializability errors: ERROR: could not serialize access due to concurrent updateBecause the key-share doesn't conflict with the update, the error isunnecessary and inconsistent with the case that the update hasn'tcommitted yet. This causes problems for some usage patterns, even if itcan be claimed that it's sufficient to retry the aborted transaction:given a steady stream of updating transactions and a long lockingtransaction, the long transaction can be starved indefinitely despitemultiple retries.To fix, we recognize that HeapTupleSatisfiesUpdate can returnHeapTupleUpdated when an updating transaction has committed, and that weneed to deal with that case exactly as if it were a non-committedupdate: verify whether the two operations conflict, and if not, carry onnormally. If they do conflict, however, there is a difference: in theHeapTupleBeingUpdated case we can just sleep until the concurrenttransaction is gone, while in the HeapTupleUpdated case this is notpossible and we must raise an error instead.Per trouble report from Olivier Dony.In addition to a couple of test cases that verify the changed behavior,I added a test case to verify the behavior that remains unchanged,namely that errors are raised when a update that modifies the key isused. That must still generate serializability errors. Onepre-existing test case changes behavior; per discussion, the newbehavior is actually the desired one.Discussion:https://www.postgresql.org/message-id/560AA479.4080807@odoo.comhttps://www.postgresql.org/message-id/20151014164844.3019.25750@wrigleys.postgresql.orgBackpatch to 9.3, where the problem appeared.
1 parent3246135 commit649dd1b

File tree

9 files changed

+1401
-4
lines changed

9 files changed

+1401
-4
lines changed

‎src/backend/access/heap/heapam.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4317,7 +4317,7 @@ heap_lock_tuple(Relation relation, HeapTuple tuple,
43174317
*/
43184318
returnHeapTupleInvisible;
43194319
}
4320-
elseif (result==HeapTupleBeingUpdated)
4320+
elseif (result==HeapTupleBeingUpdated||result==HeapTupleUpdated)
43214321
{
43224322
TransactionIdxwait;
43234323
uint16infomask;
@@ -4577,12 +4577,22 @@ heap_lock_tuple(Relation relation, HeapTuple tuple,
45774577
}
45784578

45794579
/*
4580+
* Time to sleep on the other transaction/multixact, if necessary.
4581+
*
4582+
* If the other transaction is an update that's already committed,
4583+
* then sleeping cannot possibly do any good: if we're required to
4584+
* sleep, get out to raise an error instead.
4585+
*
45804586
* By here, we either have already acquired the buffer exclusive lock,
45814587
* or we must wait for the locking transaction or multixact; so below
45824588
* we ensure that we grab buffer lock after the sleep.
45834589
*/
4584-
4585-
if (require_sleep)
4590+
if (require_sleep&&result==HeapTupleUpdated)
4591+
{
4592+
LockBuffer(*buffer,BUFFER_LOCK_EXCLUSIVE);
4593+
gotofailed;
4594+
}
4595+
elseif (require_sleep)
45864596
{
45874597
/*
45884598
* Acquire tuple lock to establish our priority for the tuple, or

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp