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

Commit370bc77

Browse files
committed
Unpin buffer before inplace update waits for an XID to end.
Commita07e03f changed inplace updatesto wait for heap_update() commands like GRANT TABLE and GRANT DATABASE.By keeping the pin during that wait, a sequence of autovacuum workersand an uncommitted GRANT starved one foreground LockBufferForCleanup()for six minutes, on buildfarm member sarus. Prevent, at the cost of abit of complexity. Back-patch to v12, like the earlier commit. Thatcommit and heap_inplace_lock() have not yet appeared in any release.Discussion:https://postgr.es/m/20241026184936.ae.nmisch@google.com
1 parenta0c8d60 commit370bc77

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6023,8 +6023,8 @@ heap_abort_speculative(Relation relation, ItemPointer tid)
60236023
* transaction. If compatible, return true with the buffer exclusive-locked,
60246024
* and the caller must release that by calling
60256025
* heap_inplace_update_and_unlock(), calling heap_inplace_unlock(), or raising
6026-
* an error. Otherwise,return false after blocking transactions, if any,
6027-
*have ended.
6026+
* an error. Otherwise,call release_callback(arg), wait for blocking
6027+
*transactions to end, and return false.
60286028
*
60296029
* Since this is intended for system catalogs and SERIALIZABLE doesn't cover
60306030
* DDL, this doesn't guarantee any particular predicate locking.
@@ -6058,7 +6058,8 @@ heap_abort_speculative(Relation relation, ItemPointer tid)
60586058
*/
60596059
bool
60606060
heap_inplace_lock(Relationrelation,
6061-
HeapTupleoldtup_ptr,Bufferbuffer)
6061+
HeapTupleoldtup_ptr,Bufferbuffer,
6062+
void (*release_callback) (void*),void*arg)
60626063
{
60636064
HeapTupleDataoldtup=*oldtup_ptr;/* minimize diff vs. heap_update() */
60646065
TM_Resultresult;
@@ -6123,6 +6124,7 @@ heap_inplace_lock(Relation relation,
61236124
lockmode,NULL))
61246125
{
61256126
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
6127+
release_callback(arg);
61266128
ret= false;
61276129
MultiXactIdWait((MultiXactId)xwait,mxact_status,infomask,
61286130
relation,&oldtup.t_self,XLTW_Update,
@@ -6138,6 +6140,7 @@ heap_inplace_lock(Relation relation,
61386140
else
61396141
{
61406142
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
6143+
release_callback(arg);
61416144
ret= false;
61426145
XactLockTableWait(xwait,relation,&oldtup.t_self,
61436146
XLTW_Update);
@@ -6149,6 +6152,7 @@ heap_inplace_lock(Relation relation,
61496152
if (!ret)
61506153
{
61516154
LockBuffer(buffer,BUFFER_LOCK_UNLOCK);
6155+
release_callback(arg);
61526156
}
61536157
}
61546158

‎src/backend/access/index/genam.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ systable_inplace_update_begin(Relation relation,
805805
intretries=0;
806806
SysScanDescscan;
807807
HeapTupleoldtup;
808+
BufferHeapTupleTableSlot*bslot;
808809

809810
/*
810811
* For now, we don't allow parallel updates. Unlike a regular update,
@@ -826,10 +827,9 @@ systable_inplace_update_begin(Relation relation,
826827
Assert(IsInplaceUpdateRelation(relation)|| !IsSystemRelation(relation));
827828

828829
/* Loop for an exclusive-locked buffer of a non-updated tuple. */
829-
for (;;)
830+
do
830831
{
831832
TupleTableSlot*slot;
832-
BufferHeapTupleTableSlot*bslot;
833833

834834
CHECK_FOR_INTERRUPTS();
835835

@@ -855,11 +855,9 @@ systable_inplace_update_begin(Relation relation,
855855
slot=scan->slot;
856856
Assert(TTS_IS_BUFFERTUPLE(slot));
857857
bslot= (BufferHeapTupleTableSlot*)slot;
858-
if (heap_inplace_lock(scan->heap_rel,
859-
bslot->base.tuple,bslot->buffer))
860-
break;
861-
systable_endscan(scan);
862-
};
858+
}while (!heap_inplace_lock(scan->heap_rel,
859+
bslot->base.tuple,bslot->buffer,
860+
(void (*) (void*))systable_endscan,scan));
863861

864862
*oldtupcopy=heap_copytuple(oldtup);
865863
*state=scan;

‎src/include/access/heapam.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ extern TM_Result heap_lock_tuple(Relation relation, HeapTuple tuple,
257257
Buffer*buffer,structTM_FailureData*tmfd);
258258

259259
externboolheap_inplace_lock(Relationrelation,
260-
HeapTupleoldtup_ptr,Bufferbuffer);
260+
HeapTupleoldtup_ptr,Bufferbuffer,
261+
void (*release_callback) (void*),void*arg);
261262
externvoidheap_inplace_update_and_unlock(Relationrelation,
262263
HeapTupleoldtup,HeapTupletuple,
263264
Bufferbuffer);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp