In WAL replay, restore GIN metapage unconditionally to avoid torn page.
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.

ovr/postgres-xl,adam8157/gpdb,greenplum-db/gpdb,jmcatamney/gpdb,jmcatamney/gpdb,Postgres-XL/Postgres-XL,xinzweb/gpdb,yazun/postgres-xl,lisakowen/gpdb,jmcatamney/gpdb,zeroae/postgres-xl,greenplum-db/gpdb,yazun/postgres-xl,xinzweb/gpdb,ashwinstar/gpdb,jmcatamney/gpdb,Postgres-XL/Postgres-XL,zeroae/postgres-xl,techdragon/Postgres-XL,adam8157/gpdb,oberstet/postgres-xl,50wu/gpdb,adam8157/gpdb,zeroae/postgres-xl,greenplum-db/gpdb,pavanvd/postgres-xl,Postgres-XL/Postgres-XL,jmcatamney/gpdb,zeroae/postgres-xl,jmcatamney/gpdb,xinzweb/gpdb,ovr/postgres-xl,greenplum-db/gpdb,ashwinstar/gpdb,oberstet/postgres-xl,techdragon/Postgres-XL,greenplum-db/gpdb,lisakowen/gpdb,adam8157/gpdb,techdragon/Postgres-XL,techdragon/Postgres-XL,ashwinstar/gpdb,ovr/postgres-xl,yazun/postgres-xl,xinzweb/gpdb,zeroae/postgres-xl,ovr/postgres-xl,ashwinstar/gpdb,pavanvd/postgres-xl,Postgres-XL/Postgres-XL,oberstet/postgres-xl,pavanvd/postgres-xl,Postgres-XL/Postgres-XL,xinzweb/gpdb,jmcatamney/gpdb,lisakowen/gpdb,greenplum-db/gpdb,lisakowen/gpdb,greenplum-db/gpdb,xinzweb/gpdb,pavanvd/postgres-xl,ashwinstar/gpdb,ovr/postgres-xl,xinzweb/gpdb,adam8157/gpdb,50wu/gpdb,oberstet/postgres-xl,adam8157/gpdb,ashwinstar/gpdb,pavanvd/postgres-xl,50wu/gpdb,xinzweb/gpdb,oberstet/postgres-xl,adam8157/gpdb,lisakowen/gpdb,ashwinstar/gpdb,50wu/gpdb,50wu/gpdb,ashwinstar/gpdb,adam8157/gpdb,lisakowen/gpdb,techdragon/Postgres-XL,50wu/gpdb,yazun/postgres-xl,lisakowen/gpdb,greenplum-db/gpdb,50wu/gpdb,50wu/gpdb,lisakowen/gpdb,jmcatamney/gpdb,yazun/postgres-xl