Skip to content

Commit 760606d

Browse files
committed
Fix full-page writes of internal GIN pages.
Insertion to a non-leaf GIN page didn't make a full-page image of the page, which is wrong. The code used to do it correctly, but was changed (commit 853d1c3) because the redo-routine didn't track incomplete splits correctly when the page was restored from a full page image. Of course, that was not right way to fix it, the redo routine should've been fixed instead. The redo-routine was surreptitiously fixed in 2010 (commit 4016bde), so all we need to do now is revert the code that creates the record to its original form. This doesn't change the format of the WAL record. Backpatch to all supported versions.
1 parent ad670a5 commit 760606d

File tree

2 files changed

+34
-50
lines changed

2 files changed

+34
-50
lines changed

src/backend/access/gin/gindatapage.c

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ dataPlaceToPage(GinBtree btree, Buffer buf, OffsetNumber off, XLogRecData **prda
375375
static XLogRecData rdata[3];
376376
int sizeofitem = GinSizeOfItem(page);
377377
static ginxlogInsert data;
378-
int cnt = 0;
379378

380379
*prdata = rdata;
381380
Assert(GinPageIsData(page));
@@ -391,32 +390,25 @@ dataPlaceToPage(GinBtree btree, Buffer buf, OffsetNumber off, XLogRecData **prda
391390
data.isLeaf = GinPageIsLeaf(page) ? TRUE : FALSE;
392391

393392
/*
394-
* Prevent full page write if child's split occurs. That is needed to
395-
* remove incomplete splits while replaying WAL
396-
*
397-
* data.updateBlkno contains new block number (of newly created right
398-
* page) for recently splited page.
393+
* For incomplete-split tracking, we need updateBlkno information and the
394+
* inserted item even when we make a full page image of the page, so put
395+
* the buffer reference in a separate XLogRecData entry.
399396
*/
400-
if (data.updateBlkno == InvalidBlockNumber)
401-
{
402-
rdata[0].buffer = buf;
403-
rdata[0].buffer_std = FALSE;
404-
rdata[0].data = NULL;
405-
rdata[0].len = 0;
406-
rdata[0].next = &rdata[1];
407-
cnt++;
408-
}
397+
rdata[0].buffer = buf;
398+
rdata[0].buffer_std = FALSE;
399+
rdata[0].data = NULL;
400+
rdata[0].len = 0;
401+
rdata[0].next = &rdata[1];
409402

410-
rdata[cnt].buffer = InvalidBuffer;
411-
rdata[cnt].data = (char *) &data;
412-
rdata[cnt].len = sizeof(ginxlogInsert);
413-
rdata[cnt].next = &rdata[cnt + 1];
414-
cnt++;
403+
rdata[1].buffer = InvalidBuffer;
404+
rdata[1].data = (char *) &data;
405+
rdata[1].len = sizeof(ginxlogInsert);
406+
rdata[1].next = &rdata[2];
415407

416-
rdata[cnt].buffer = InvalidBuffer;
417-
rdata[cnt].data = (GinPageIsLeaf(page)) ? ((char *) (btree->items + btree->curitem)) : ((char *) &(btree->pitem));
418-
rdata[cnt].len = sizeofitem;
419-
rdata[cnt].next = NULL;
408+
rdata[2].buffer = InvalidBuffer;
409+
rdata[2].data = (GinPageIsLeaf(page)) ? ((char *) (btree->items + btree->curitem)) : ((char *) &(btree->pitem));
410+
rdata[2].len = sizeofitem;
411+
rdata[2].next = NULL;
420412

421413
if (GinPageIsLeaf(page))
422414
{
@@ -432,7 +424,7 @@ dataPlaceToPage(GinBtree btree, Buffer buf, OffsetNumber off, XLogRecData **prda
432424
btree->curitem++;
433425
}
434426
data.nitem = btree->curitem - savedPos;
435-
rdata[cnt].len = sizeofitem * data.nitem;
427+
rdata[2].len = sizeofitem * data.nitem;
436428
}
437429
else
438430
{

src/backend/access/gin/ginentrypage.c

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,6 @@ entryPlaceToPage(GinBtree btree, Buffer buf, OffsetNumber off, XLogRecData **prd
423423
static XLogRecData rdata[3];
424424
OffsetNumber placed;
425425
static ginxlogInsert data;
426-
int cnt = 0;
427426

428427
*prdata = rdata;
429428
data.updateBlkno = entryPreparePage(btree, page, off);
@@ -442,32 +441,25 @@ entryPlaceToPage(GinBtree btree, Buffer buf, OffsetNumber off, XLogRecData **prd
442441
data.isLeaf = GinPageIsLeaf(page) ? TRUE : FALSE;
443442

444443
/*
445-
* Prevent full page write if child's split occurs. That is needed to
446-
* remove incomplete splits while replaying WAL
447-
*
448-
* data.updateBlkno contains new block number (of newly created right
449-
* page) for recently splited page.
444+
* For incomplete-split tracking, we need updateBlkno information and the
445+
* inserted item even when we make a full page image of the page, so put
446+
* the buffer reference in a separate XLogRecData entry.
450447
*/
451-
if (data.updateBlkno == InvalidBlockNumber)
452-
{
453-
rdata[0].buffer = buf;
454-
rdata[0].buffer_std = TRUE;
455-
rdata[0].data = NULL;
456-
rdata[0].len = 0;
457-
rdata[0].next = &rdata[1];
458-
cnt++;
459-
}
460-
461-
rdata[cnt].buffer = InvalidBuffer;
462-
rdata[cnt].data = (char *) &data;
463-
rdata[cnt].len = sizeof(ginxlogInsert);
464-
rdata[cnt].next = &rdata[cnt + 1];
465-
cnt++;
448+
rdata[0].buffer = buf;
449+
rdata[0].buffer_std = TRUE;
450+
rdata[0].data = NULL;
451+
rdata[0].len = 0;
452+
rdata[0].next = &rdata[1];
466453

467-
rdata[cnt].buffer = InvalidBuffer;
468-
rdata[cnt].data = (char *) btree->entry;
469-
rdata[cnt].len = IndexTupleSize(btree->entry);
470-
rdata[cnt].next = NULL;
454+
rdata[1].buffer = InvalidBuffer;
455+
rdata[1].data = (char *) &data;
456+
rdata[1].len = sizeof(ginxlogInsert);
457+
rdata[1].next = &rdata[2];
458+
459+
rdata[2].buffer = InvalidBuffer;
460+
rdata[2].data = (char *) btree->entry;
461+
rdata[2].len = IndexTupleSize(btree->entry);
462+
rdata[2].next = NULL;
471463

472464
btree->entry = NULL;
473465
}

0 commit comments

Comments
 (0)