summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier2022-10-26 00:41:31 +0000
committerMichael Paquier2022-10-26 00:41:31 +0000
commitb02fc7df193b2c71f359cc2b42e21515311ab188 (patch)
tree3ad6aff3dd00ea1460af43db71612054b4cdfd45
parentba58266eb8dbe56f5dd48dc584816104343ffe85 (diff)
Fix ordering issue with WAL operations in GIN fast insert path
Contrary to what is documented in src/backend/access/transam/README, ginHeapTupleFastInsert() had a few ordering issues with the way it does its WAL operations when inserting items in its fast path. First, when using a separate list, XLogBeginInsert() was being always called before START_CRIT_SECTION(), and in this case a second thing was wrong when merging lists, as an exclusive lock was taken on the tail page *before* calling XLogBeginInsert(). Finally, when inserting items into a tail page, the order of XLogBeginInsert() and START_CRIT_SECTION() was reversed. This commit addresses all these issues by moving the calls of XLogBeginInsert() after all the pages logged are locked and pinned, within a critical section. This has been applied first only on HEAD as of 56b6625, but as per discussion with Tom Lane and Álvaro Herrera, a backpatch is preferred to keep all the branches consistent and to respect the transam's README where we can. Author: Matthias van de Meent, Zhang Mingli Discussion: https://postgr.es/m/CAEze2WhL8uLMqynnnCu1LAPwxD5RKEo0nHV+eXGg_N6ELU88HQ@mail.gmail.com Backpatch-through: 10
-rw-r--r--src/backend/access/gin/ginfast.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/backend/access/gin/ginfast.c b/src/backend/access/gin/ginfast.c
index 144ca8b8e77..ae82b06c8de 100644
--- a/src/backend/access/gin/ginfast.c
+++ b/src/backend/access/gin/ginfast.c
@@ -276,9 +276,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
*/
@@ -298,6 +295,9 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector)
metadata->nPendingPages = sublist.nPendingPages;
metadata->nPendingHeapTuples = sublist.nPendingHeapTuples;
+
+ if (needWal)
+ XLogBeginInsert();
}
else
{
@@ -326,7 +326,10 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector)
metadata->nPendingHeapTuples += sublist.nPendingHeapTuples;
if (needWal)
+ {
+ XLogBeginInsert();
XLogRegisterBuffer(1, buffer, REGBUF_STANDARD);
+ }
}
}
else
@@ -352,11 +355,11 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector)
data.ntuples = collector->ntuples;
+ START_CRIT_SECTION();
+
if (needWal)
XLogBeginInsert();
- START_CRIT_SECTION();
-
/*
* Increase counter of heap tuples
*/