In WAL replay, restore GIN metapage unconditionally to avoid torn page.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 12 Mar 2014 07:59:49 +0000 (09:59 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 12 Mar 2014 08:09:22 +0000 (10:09 +0200)
commit63e59c25961f14763d86a44d8e2eccafaa337d75
treeb9cc4e11568e17cd0dac0c97449d9e72897599a7
parent080ad9120d79933e5aed545986885058f8aa7385
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 record
contains all the information required to reconstruct it from scratch. But
to avoid torn page hazards, we must re-initialize it from the WAL record
every time, even if it already has a greater LSN, similar to how normal full
page images are restored.

This was highly unlikely to cause any problems in practice, because the GIN
metapage is small. We rely on an update smaller than a 512 byte disk sector
to 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 metapage
so that it's no longer small.

Reported by Noah Misch. Backpatch to all supported versions.
src/backend/access/gin/ginxlog.c