v1-0001-Fix-GIN-fast-path-XLogBeginInsert-and-Read-LockBu.patch
application/octet-stream
Filename: v1-0001-Fix-GIN-fast-path-XLogBeginInsert-and-Read-LockBu.patch
Type: application/octet-stream
Part: 0
Patch
Format: format-patch
Series: patch v1-0001
Subject: Fix GIN fast-path XLogBeginInsert() and Read/LockBuffer ordering issue
| File | + | − |
|---|---|---|
| src/backend/access/gin/ginfast.c | 6 | 3 |
From 05d0b9209ec5636e8b017b2d1050767517a96cd7 Mon Sep 17 00:00:00 2001
From: Matthias van de Meent <boekewurm+postgres@gmail.com>
Date: Thu, 8 Sep 2022 12:38:15 +0200
Subject: [PATCH v1] Fix GIN fast-path XLogBeginInsert() and Read/LockBuffer
ordering issue
XLogBeginInsert() should be called only after the caller has locked all
relevant buffers, and starting a critical section (where and when
applicable), according to the XLog Manual in access/transam/README,
section "Write-Ahead Log Coding".
---
src/backend/access/gin/ginfast.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/src/backend/access/gin/ginfast.c b/src/backend/access/gin/ginfast.c
index 6c677447a9..5784c365bf 100644
--- a/src/backend/access/gin/ginfast.c
+++ b/src/backend/access/gin/ginfast.c
@@ -285,9 +285,6 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector)
memset(&sublist, 0, sizeof(GinMetaPageData));
makeSublist(index, collector->tuples, collector->ntuples, &sublist);
- if (needWal)
- XLogBeginInsert();
-
/*
* metapage was unlocked, see above
*/
@@ -307,6 +304,9 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector)
metadata->nPendingPages = sublist.nPendingPages;
metadata->nPendingHeapTuples = sublist.nPendingHeapTuples;
+
+ if (needWal)
+ XLogBeginInsert();
}
else
{
@@ -335,7 +335,10 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector)
metadata->nPendingHeapTuples += sublist.nPendingHeapTuples;
if (needWal)
+ {
+ XLogBeginInsert();
XLogRegisterBuffer(1, buffer, REGBUF_STANDARD);
+ }
}
}
else
--
2.30.2