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

Commit4738cc3

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 parentf64f4c3 commit4738cc3

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
@@ -502,17 +502,19 @@ ginRedoUpdateMetapage(XLogRecPtr lsn, XLogRecord *record)
502502
Pagemetapage;
503503
Bufferbuffer;
504504

505+
/*
506+
* Restore the metapage. This is essentially the same as a full-page image,
507+
* so restore the metapage unconditionally without looking at the LSN, to
508+
* avoid torn page hazards.
509+
*/
505510
metabuffer=XLogReadBuffer(data->node,GIN_METAPAGE_BLKNO, false);
506511
if (!BufferIsValid(metabuffer))
507512
return;/* assume index was deleted, nothing to do */
508513
metapage=BufferGetPage(metabuffer);
509514

510-
if (lsn>PageGetLSN(metapage))
511-
{
512-
memcpy(GinPageGetMeta(metapage),&data->metadata,sizeof(GinMetaPageData));
513-
PageSetLSN(metapage,lsn);
514-
MarkBufferDirty(metabuffer);
515-
}
515+
memcpy(GinPageGetMeta(metapage),&data->metadata,sizeof(GinMetaPageData));
516+
PageSetLSN(metapage,lsn);
517+
MarkBufferDirty(metabuffer);
516518

517519
if (data->ntuples>0)
518520
{
@@ -662,12 +664,9 @@ ginRedoDeleteListPages(XLogRecPtr lsn, XLogRecord *record)
662664
return;/* assume index was deleted, nothing to do */
663665
metapage=BufferGetPage(metabuffer);
664666

665-
if (lsn>PageGetLSN(metapage))
666-
{
667-
memcpy(GinPageGetMeta(metapage),&data->metadata,sizeof(GinMetaPageData));
668-
PageSetLSN(metapage,lsn);
669-
MarkBufferDirty(metabuffer);
670-
}
667+
memcpy(GinPageGetMeta(metapage),&data->metadata,sizeof(GinMetaPageData));
668+
PageSetLSN(metapage,lsn);
669+
MarkBufferDirty(metabuffer);
671670

672671
/*
673672
* In normal operation, shiftList() takes exclusive lock on all the

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp