summaryrefslogtreecommitdiff
path: root/src/backend/access/index/genam.c
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2024-10-29 09:39:55 -0700
committerNoah Misch <noah@leadboat.com>2024-10-29 09:39:58 -0700
commit9aef6f19ac27a607f0c557d19934d5ce96ed5f1a (patch)
tree69a15987ed16c0ba6776c75f420be7104db8f3aa /src/backend/access/index/genam.c
parentcad65907ee42be80bea475b9fe8c02c22cb6ce0c (diff)
Unpin buffer before inplace update waits for an XID to end.
Commit a07e03fd8fa7daf4d1356f7cb501ffe784ea6257 changed inplace updates to wait for heap_update() commands like GRANT TABLE and GRANT DATABASE. By keeping the pin during that wait, a sequence of autovacuum workers and an uncommitted GRANT starved one foreground LockBufferForCleanup() for six minutes, on buildfarm member sarus. Prevent, at the cost of a bit of complexity. Back-patch to v12, like the earlier commit. That commit and heap_inplace_lock() have not yet appeared in any release. Discussion: https://postgr.es/m/20241026184936.ae.nmisch@google.com
Diffstat (limited to 'src/backend/access/index/genam.c')
-rw-r--r--src/backend/access/index/genam.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/backend/access/index/genam.c b/src/backend/access/index/genam.c
index 58f33555f97..b123acc5a60 100644
--- a/src/backend/access/index/genam.c
+++ b/src/backend/access/index/genam.c
@@ -804,6 +804,7 @@ systable_inplace_update_begin(Relation relation,
int retries = 0;
SysScanDesc scan;
HeapTuple oldtup;
+ BufferHeapTupleTableSlot *bslot;
/*
* For now, we don't allow parallel updates. Unlike a regular update,
@@ -825,10 +826,9 @@ systable_inplace_update_begin(Relation relation,
Assert(IsInplaceUpdateRelation(relation) || !IsSystemRelation(relation));
/* Loop for an exclusive-locked buffer of a non-updated tuple. */
- for (;;)
+ do
{
TupleTableSlot *slot;
- BufferHeapTupleTableSlot *bslot;
CHECK_FOR_INTERRUPTS();
@@ -855,11 +855,9 @@ systable_inplace_update_begin(Relation relation,
slot = scan->slot;
Assert(TTS_IS_BUFFERTUPLE(slot));
bslot = (BufferHeapTupleTableSlot *) slot;
- if (heap_inplace_lock(scan->heap_rel,
- bslot->base.tuple, bslot->buffer))
- break;
- systable_endscan(scan);
- };
+ } while (!heap_inplace_lock(scan->heap_rel,
+ bslot->base.tuple, bslot->buffer,
+ (void (*) (void *)) systable_endscan, scan));
*oldtupcopy = heap_copytuple(oldtup);
*state = scan;