From 5e87f49a4cfebb4d5d4b040d37ab98a0837a2284 Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Tue, 5 Jun 2007 12:48:21 +0000 Subject: [PATCH] Move call of MarkBufferDirty() before XLogInsert() as required. Many thanks to Heikki Linnakangas for his sharp eyes. --- src/backend/access/gin/ginbtree.c | 19 ++++++++++++------- src/backend/access/gin/gininsert.c | 8 +++++--- src/backend/access/gin/ginvacuum.c | 16 ++++++++-------- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/backend/access/gin/ginbtree.c b/src/backend/access/gin/ginbtree.c index aee72990bc..f0490581c5 100644 --- a/src/backend/access/gin/ginbtree.c +++ b/src/backend/access/gin/ginbtree.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/gin/ginbtree.c,v 1.6 2006/11/12 06:55:53 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/access/gin/ginbtree.c,v 1.6.2.1 2007/06/05 12:48:21 teodor Exp $ *------------------------------------------------------------------------- */ @@ -294,6 +294,8 @@ ginInsertValue(GinBtree btree, GinBtreeStack *stack) START_CRIT_SECTION(); btree->placeToPage(btree, stack->buffer, stack->off, &rdata); + MarkBufferDirty(stack->buffer); + if (!btree->index->rd_istemp) { XLogRecPtr recptr; @@ -303,7 +305,6 @@ ginInsertValue(GinBtree btree, GinBtreeStack *stack) PageSetTLI(page, ThisTimeLineID); } - MarkBufferDirty(stack->buffer); UnlockReleaseBuffer(stack->buffer); END_CRIT_SECTION(); @@ -351,6 +352,11 @@ ginInsertValue(GinBtree btree, GinBtreeStack *stack) GinInitBuffer(stack->buffer, GinPageGetOpaque(newlpage)->flags & ~GIN_LEAF); PageRestoreTempPage(newlpage, lpage); btree->fillRoot(btree, stack->buffer, lbuffer, rbuffer); + + MarkBufferDirty(rbuffer); + MarkBufferDirty(lbuffer); + MarkBufferDirty(stack->buffer); + if (!btree->index->rd_istemp) { XLogRecPtr recptr; @@ -364,11 +370,8 @@ ginInsertValue(GinBtree btree, GinBtreeStack *stack) PageSetTLI(rpage, ThisTimeLineID); } - MarkBufferDirty(rbuffer); UnlockReleaseBuffer(rbuffer); - MarkBufferDirty(lbuffer); UnlockReleaseBuffer(lbuffer); - MarkBufferDirty(stack->buffer); UnlockReleaseBuffer(stack->buffer); END_CRIT_SECTION(); @@ -389,6 +392,10 @@ ginInsertValue(GinBtree btree, GinBtreeStack *stack) START_CRIT_SECTION(); PageRestoreTempPage(newlpage, lpage); + + MarkBufferDirty(rbuffer); + MarkBufferDirty(stack->buffer); + if (!btree->index->rd_istemp) { XLogRecPtr recptr; @@ -399,9 +406,7 @@ ginInsertValue(GinBtree btree, GinBtreeStack *stack) PageSetLSN(rpage, recptr); PageSetTLI(rpage, ThisTimeLineID); } - MarkBufferDirty(rbuffer); UnlockReleaseBuffer(rbuffer); - MarkBufferDirty(stack->buffer); END_CRIT_SECTION(); } } diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c index e4f87e720d..ed79a8f3de 100644 --- a/src/backend/access/gin/gininsert.c +++ b/src/backend/access/gin/gininsert.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/gin/gininsert.c,v 1.5 2006/10/04 00:29:47 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/access/gin/gininsert.c,v 1.5.2.1 2007/06/05 12:48:21 teodor Exp $ *------------------------------------------------------------------------- */ @@ -48,6 +48,8 @@ createPostingTree(Relation index, ItemPointerData *items, uint32 nitems) memcpy(GinDataPageGetData(page), items, sizeof(ItemPointerData) * nitems); GinPageGetOpaque(page)->maxoff = nitems; + MarkBufferDirty(buffer); + if (!index->rd_istemp) { XLogRecPtr recptr; @@ -76,7 +78,6 @@ createPostingTree(Relation index, ItemPointerData *items, uint32 nitems) } - MarkBufferDirty(buffer); UnlockReleaseBuffer(buffer); END_CRIT_SECTION(); @@ -281,6 +282,8 @@ ginbuild(PG_FUNCTION_ARGS) buffer = GinNewBuffer(index); START_CRIT_SECTION(); GinInitBuffer(buffer, GIN_LEAF); + MarkBufferDirty(buffer); + if (!index->rd_istemp) { XLogRecPtr recptr; @@ -301,7 +304,6 @@ ginbuild(PG_FUNCTION_ARGS) } - MarkBufferDirty(buffer); UnlockReleaseBuffer(buffer); END_CRIT_SECTION(); diff --git a/src/backend/access/gin/ginvacuum.c b/src/backend/access/gin/ginvacuum.c index cf643ac9c8..0659a320cc 100644 --- a/src/backend/access/gin/ginvacuum.c +++ b/src/backend/access/gin/ginvacuum.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/gin/ginvacuum.c,v 1.9.2.1 2007/06/04 15:59:19 teodor Exp $ + * $PostgreSQL: pgsql/src/backend/access/gin/ginvacuum.c,v 1.9.2.2 2007/06/05 12:48:21 teodor Exp $ *------------------------------------------------------------------------- */ @@ -190,9 +190,9 @@ ginVacuumPostingTreeLeaves(GinVacuumState *gvs, BlockNumber blkno, bool isRoot, pfree(cleaned); GinPageGetOpaque(page)->maxoff = newMaxOff; + MarkBufferDirty(buffer); xlogVacuumPage(gvs->index, buffer); - MarkBufferDirty(buffer); END_CRIT_SECTION(); /* if root is a leaf page, we don't desire further processing */ @@ -280,6 +280,11 @@ ginDeletePage(GinVacuumState *gvs, BlockNumber deleteBlkno, BlockNumber leftBlkn */ GinPageGetOpaque(page)->flags = GIN_DELETED; + MarkBufferDirty(pBuffer); + if (leftBlkno != InvalidBlockNumber) + MarkBufferDirty(lBuffer); + MarkBufferDirty(dBuffer); + if (!gvs->index->rd_istemp) { XLogRecPtr recptr; @@ -337,18 +342,13 @@ ginDeletePage(GinVacuumState *gvs, BlockNumber deleteBlkno, BlockNumber leftBlkn } } - MarkBufferDirty(pBuffer); if (!isParentRoot) LockBuffer(pBuffer, GIN_UNLOCK); ReleaseBuffer(pBuffer); if (leftBlkno != InvalidBlockNumber) - { - MarkBufferDirty(lBuffer); UnlockReleaseBuffer(lBuffer); - } - MarkBufferDirty(dBuffer); UnlockReleaseBuffer(dBuffer); END_CRIT_SECTION(); @@ -633,8 +633,8 @@ ginbulkdelete(PG_FUNCTION_ARGS) { START_CRIT_SECTION(); PageRestoreTempPage(resPage, page); - xlogVacuumPage(gvs.index, buffer); MarkBufferDirty(buffer); + xlogVacuumPage(gvs.index, buffer); UnlockReleaseBuffer(buffer); END_CRIT_SECTION(); }