Skip to content

Commit 56b6625

Browse files
committed
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. Author: Matthias van de Meent, Zhang Mingli Discussion: https://postgr.es/m/CAEze2WhL8uLMqynnnCu1LAPwxD5RKEo0nHV+eXGg_N6ELU88HQ@mail.gmail.com
1 parent 63585b1 commit 56b6625

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/backend/access/gin/ginfast.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,6 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector)
285285
memset(&sublist, 0, sizeof(GinMetaPageData));
286286
makeSublist(index, collector->tuples, collector->ntuples, &sublist);
287287

288-
if (needWal)
289-
XLogBeginInsert();
290-
291288
/*
292289
* metapage was unlocked, see above
293290
*/
@@ -307,6 +304,9 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector)
307304

308305
metadata->nPendingPages = sublist.nPendingPages;
309306
metadata->nPendingHeapTuples = sublist.nPendingHeapTuples;
307+
308+
if (needWal)
309+
XLogBeginInsert();
310310
}
311311
else
312312
{
@@ -335,7 +335,10 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector)
335335
metadata->nPendingHeapTuples += sublist.nPendingHeapTuples;
336336

337337
if (needWal)
338+
{
339+
XLogBeginInsert();
338340
XLogRegisterBuffer(1, buffer, REGBUF_STANDARD);
341+
}
339342
}
340343
}
341344
else
@@ -361,11 +364,11 @@ ginHeapTupleFastInsert(GinState *ginstate, GinTupleCollector *collector)
361364

362365
data.ntuples = collector->ntuples;
363366

367+
START_CRIT_SECTION();
368+
364369
if (needWal)
365370
XLogBeginInsert();
366371

367-
START_CRIT_SECTION();
368-
369372
/*
370373
* Increase counter of heap tuples
371374
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy