Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 85376c6

Browse files
committed
Fix coredump during replay WAL after crash. Change entrySplitPage() to prevent
usage of any information from system catalog, because it could be called during replay of WAL. Per bug report from Craig McElroy <craig.mcelroy@contegix.com>. Patch doesn't change on-disk storage.
1 parent 811be89 commit 85376c6

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

src/backend/access/gin/ginentrypage.c

+30-18
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/gin/ginentrypage.c,v 1.9 2007/09/20 17:56:30 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/gin/ginentrypage.c,v 1.10 2007/10/29 13:49:21 teodor Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414

@@ -403,6 +403,31 @@ entryPlaceToPage(GinBtree btree, Buffer buf, OffsetNumber off, XLogRecData **prd
403403
btree->entry = NULL;
404404
}
405405

406+
/*
407+
* Returns new tuple with copied value from source tuple.
408+
* New tuple will not store posting list
409+
*/
410+
static IndexTuple
411+
copyIndexTuple(IndexTuple itup, Page page)
412+
{
413+
IndexTuple nitup;
414+
415+
if (GinPageIsLeaf(page) && !GinIsPostingTree(itup))
416+
{
417+
nitup = (IndexTuple) palloc(MAXALIGN(GinGetOrigSizePosting(itup)));
418+
memcpy(nitup, itup, GinGetOrigSizePosting(itup));
419+
nitup->t_info &= ~INDEX_SIZE_MASK;
420+
nitup->t_info |= GinGetOrigSizePosting(itup);
421+
}
422+
else
423+
{
424+
nitup = (IndexTuple) palloc(MAXALIGN(IndexTupleSize(itup)));
425+
memcpy(nitup, itup, IndexTupleSize(itup));
426+
}
427+
428+
return nitup;
429+
}
430+
406431
/*
407432
* Place tuple and split page, original buffer(lbuf) leaves untouched,
408433
* returns shadow page of lbuf filled new data.
@@ -424,8 +449,6 @@ entrySplitPage(GinBtree btree, Buffer lbuf, Buffer rbuf, OffsetNumber off, XLogR
424449
IndexTuple itup,
425450
leftrightmost = NULL;
426451
static ginxlogSplit data;
427-
Datum value;
428-
bool isnull;
429452
Page page;
430453
Page lpage = GinPageGetCopyPage(BufferGetPage(lbuf));
431454
Page rpage = BufferGetPage(rbuf);
@@ -494,9 +517,9 @@ entrySplitPage(GinBtree btree, Buffer lbuf, Buffer rbuf, OffsetNumber off, XLogR
494517
ptr += MAXALIGN(IndexTupleSize(itup));
495518
}
496519

497-
value = index_getattr(leftrightmost, FirstOffsetNumber, btree->ginstate->tupdesc, &isnull);
498-
btree->entry = GinFormTuple(btree->ginstate, value, NULL, 0);
520+
btree->entry = copyIndexTuple(leftrightmost, lpage);
499521
ItemPointerSet(&(btree->entry)->t_tid, BufferGetBlockNumber(lbuf), InvalidOffsetNumber);
522+
500523
btree->rightblkno = BufferGetBlockNumber(rbuf);
501524

502525
data.node = btree->index->rd_node;
@@ -533,20 +556,9 @@ ginPageGetLinkItup(Buffer buf)
533556
Page page = BufferGetPage(buf);
534557

535558
itup = getRightMostTuple(page);
536-
if (GinPageIsLeaf(page) && !GinIsPostingTree(itup))
537-
{
538-
nitup = (IndexTuple) palloc(MAXALIGN(GinGetOrigSizePosting(itup)));
539-
memcpy(nitup, itup, GinGetOrigSizePosting(itup));
540-
nitup->t_info &= ~INDEX_SIZE_MASK;
541-
nitup->t_info |= GinGetOrigSizePosting(itup);
542-
}
543-
else
544-
{
545-
nitup = (IndexTuple) palloc(MAXALIGN(IndexTupleSize(itup)));
546-
memcpy(nitup, itup, IndexTupleSize(itup));
547-
}
548-
559+
nitup = copyIndexTuple(itup, page);
549560
ItemPointerSet(&nitup->t_tid, BufferGetBlockNumber(buf), InvalidOffsetNumber);
561+
550562
return nitup;
551563
}
552564

0 commit comments

Comments
 (0)