Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfecfc2b

Browse files
committed
In WAL replay, restore GIN metapage unconditionally to avoid torn page.
We don't take a full-page image of the GIN metapage; instead, the WAL recordcontains all the information required to reconstruct it from scratch. Butto avoid torn page hazards, we must re-initialize it from the WAL recordevery time, even if it already has a greater LSN, similar to how normal fullpage images are restored.This was highly unlikely to cause any problems in practice, because the GINmetapage is small. We rely on an update smaller than a 512 byte disk sectorto be atomic elsewhere, at least in pg_control. But better safe than sorry,and this would be easy to overlook if more fields are added to the metapageso that it's no longer small.Reported by Noah Misch. Backpatch to all supported versions.
1 parente85a5ff commitfecfc2b

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

‎src/backend/access/gin/ginxlog.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -564,17 +564,19 @@ ginRedoUpdateMetapage(XLogRecPtr lsn, XLogRecord *record)
564564
Pagemetapage;
565565
Bufferbuffer;
566566

567+
/*
568+
* Restore the metapage. This is essentially the same as a full-page image,
569+
* so restore the metapage unconditionally without looking at the LSN, to
570+
* avoid torn page hazards.
571+
*/
567572
metabuffer=XLogReadBuffer(data->node,GIN_METAPAGE_BLKNO, false);
568573
if (!BufferIsValid(metabuffer))
569574
return;/* assume index was deleted, nothing to do */
570575
metapage=BufferGetPage(metabuffer);
571576

572-
if (lsn>PageGetLSN(metapage))
573-
{
574-
memcpy(GinPageGetMeta(metapage),&data->metadata,sizeof(GinMetaPageData));
575-
PageSetLSN(metapage,lsn);
576-
MarkBufferDirty(metabuffer);
577-
}
577+
memcpy(GinPageGetMeta(metapage),&data->metadata,sizeof(GinMetaPageData));
578+
PageSetLSN(metapage,lsn);
579+
MarkBufferDirty(metabuffer);
578580

579581
if (data->ntuples>0)
580582
{
@@ -724,12 +726,9 @@ ginRedoDeleteListPages(XLogRecPtr lsn, XLogRecord *record)
724726
return;/* assume index was deleted, nothing to do */
725727
metapage=BufferGetPage(metabuffer);
726728

727-
if (lsn>PageGetLSN(metapage))
728-
{
729-
memcpy(GinPageGetMeta(metapage),&data->metadata,sizeof(GinMetaPageData));
730-
PageSetLSN(metapage,lsn);
731-
MarkBufferDirty(metabuffer);
732-
}
729+
memcpy(GinPageGetMeta(metapage),&data->metadata,sizeof(GinMetaPageData));
730+
PageSetLSN(metapage,lsn);
731+
MarkBufferDirty(metabuffer);
733732

734733
/*
735734
* In normal operation, shiftList() takes exclusive lock on all the

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp