From 07bd1db152e95a44722c1fd23572dfeaf8e07eaf Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Mon, 4 Jun 2007 15:59:20 +0000 Subject: Fix bundle bugs of GIN: - Fix possible deadlock between UPDATE and VACUUM queries. Bug never was observed in 8.2, but it still exist there. HEAD is more sensitive to bug after recent "ring" of buffer improvements. - Fix WAL creation: if parent page is stored as is after split then incomplete split isn't removed during replay. This happens rather rare, only on large tables with a lot of updates/inserts. - Fix WAL replay: there was wrong test of XLR_BKP_BLOCK_* for left page after deletion of page. That causes wrong rightlink field: it pointed to deleted page. - add checking of match of clearing incomplete split - cleanup incomplete split list after proceeding All of this chages doesn't change on-disk storage, so backpatch... But second point may be an issue for replaying logs from previous version. --- src/backend/access/gin/ginentrypage.c | 43 +++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'src/backend/access/gin/ginentrypage.c') diff --git a/src/backend/access/gin/ginentrypage.c b/src/backend/access/gin/ginentrypage.c index 5dc3ac57b31..ca409666030 100644 --- a/src/backend/access/gin/ginentrypage.c +++ b/src/backend/access/gin/ginentrypage.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/gin/ginentrypage.c,v 1.5 2006/11/12 06:55:53 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/access/gin/ginentrypage.c,v 1.5.2.1 2007/06/04 15:59:19 teodor Exp $ *------------------------------------------------------------------------- */ @@ -354,6 +354,7 @@ entryPlaceToPage(GinBtree btree, Buffer buf, OffsetNumber off, XLogRecData **prd static XLogRecData rdata[3]; OffsetNumber placed; static ginxlogInsert data; + int cnt=0; *prdata = rdata; data.updateBlkno = entryPreparePage(btree, page, off); @@ -371,21 +372,33 @@ entryPlaceToPage(GinBtree btree, Buffer buf, OffsetNumber off, XLogRecData **prd data.isData = false; data.isLeaf = GinPageIsLeaf(page) ? TRUE : FALSE; - rdata[0].buffer = buf; - rdata[0].buffer_std = TRUE; - rdata[0].data = NULL; - rdata[0].len = 0; - rdata[0].next = &rdata[1]; + /* + * Prevent full page write if child's split occurs. That is needed + * to remove incomplete splits while replaying WAL + * + * data.updateBlkno contains new block number (of newly created right page) + * for recently splited page. + */ + if ( data.updateBlkno == InvalidBlockNumber ) + { + rdata[0].buffer = buf; + rdata[0].buffer_std = TRUE; + rdata[0].data = NULL; + rdata[0].len = 0; + rdata[0].next = &rdata[1]; + cnt++; + } - rdata[1].buffer = InvalidBuffer; - rdata[1].data = (char *) &data; - rdata[1].len = sizeof(ginxlogInsert); - rdata[1].next = &rdata[2]; - - rdata[2].buffer = InvalidBuffer; - rdata[2].data = (char *) btree->entry; - rdata[2].len = IndexTupleSize(btree->entry); - rdata[2].next = NULL; + rdata[cnt].buffer = InvalidBuffer; + rdata[cnt].data = (char *) &data; + rdata[cnt].len = sizeof(ginxlogInsert); + rdata[cnt].next = &rdata[cnt+1]; + cnt++; + + rdata[cnt].buffer = InvalidBuffer; + rdata[cnt].data = (char *) btree->entry; + rdata[cnt].len = IndexTupleSize(btree->entry); + rdata[cnt].next = NULL; btree->entry = NULL; } -- cgit v1.2.3