Fix assorted bugs in GIN's WAL replay logic.
Fix assorted bugs in GIN's WAL replay logic.

The original coding was quite sloppy about handling the case where
XLogReadBuffer fails (because the page has since been deleted).  This
would result in either "bad buffer id: 0" or an Assert failure during
replay, if indeed the page were no longer there.  In a couple of places
it also neglected to check whether the change had already been applied,
which would probably result in corrupted index contents.  I believe that
bug #5703 is an instance of the first problem.  These issues could show up
without replication, but only if you were unfortunate enough to crash
between modification of a GIN index and the next checkpoint.

Back-patch to 8.2, which is as far back as GIN has WAL support.

ashwinstar/gpdb,greenplum-db/gpdb,xinzweb/gpdb,postmind-net/postgres-xl,pavanvd/postgres-xl,zeroae/postgres-xl,snaga/postgres-xl,lisakowen/gpdb,pavanvd/postgres-xl,ashwinstar/gpdb,50wu/gpdb,ashwinstar/gpdb,jmcatamney/gpdb,lisakowen/gpdb,yazun/postgres-xl,ashwinstar/gpdb,ovr/postgres-xl,jmcatamney/gpdb,greenplum-db/gpdb,tpostgres-projects/tPostgres,adam8157/gpdb,greenplum-db/gpdb,adam8157/gpdb,ovr/postgres-xl,tpostgres-projects/tPostgres,greenplum-db/gpdb,50wu/gpdb,zeroae/postgres-xl,arcivanov/postgres-xl,oberstet/postgres-xl,jmcatamney/gpdb,50wu/gpdb,Postgres-XL/Postgres-XL,50wu/gpdb,kmjungersen/PostgresXL,tpostgres-projects/tPostgres,greenplum-db/gpdb,postmind-net/postgres-xl,50wu/gpdb,xinzweb/gpdb,adam8157/gpdb,lisakowen/gpdb,kmjungersen/PostgresXL,techdragon/Postgres-XL,arcivanov/postgres-xl,xinzweb/gpdb,postmind-net/postgres-xl,xinzweb/gpdb,adam8157/gpdb,zeroae/postgres-xl,oberstet/postgres-xl,adam8157/gpdb,zeroae/postgres-xl,zeroae/postgres-xl,techdragon/Postgres-XL,oberstet/postgres-xl,oberstet/postgres-xl,kmjungersen/PostgresXL,kmjungersen/PostgresXL,tpostgres-projects/tPostgres,arcivanov/postgres-xl,tpostgres-projects/tPostgres,snaga/postgres-xl,ovr/postgres-xl,pavanvd/postgres-xl,xinzweb/gpdb,pavanvd/postgres-xl,50wu/gpdb,ovr/postgres-xl,ashwinstar/gpdb,arcivanov/postgres-xl,greenplum-db/gpdb,jmcatamney/gpdb,yazun/postgres-xl,ovr/postgres-xl,jmcatamney/gpdb,arcivanov/postgres-xl,adam8157/gpdb,yazun/postgres-xl,adam8157/gpdb,snaga/postgres-xl,Postgres-XL/Postgres-XL,oberstet/postgres-xl,ashwinstar/gpdb,techdragon/Postgres-XL,xinzweb/gpdb,lisakowen/gpdb,greenplum-db/gpdb,Postgres-XL/Postgres-XL,adam8157/gpdb,xinzweb/gpdb,ashwinstar/gpdb,techdragon/Postgres-XL,jmcatamney/gpdb,lisakowen/gpdb,Postgres-XL/Postgres-XL,yazun/postgres-xl,kmjungersen/PostgresXL,yazun/postgres-xl,lisakowen/gpdb,greenplum-db/gpdb,pavanvd/postgres-xl,lisakowen/gpdb,postmind-net/postgres-xl,50wu/gpdb,snaga/postgres-xl,jmcatamney/gpdb,Postgres-XL/Postgres-XL,jmcatamney/gpdb,ashwinstar/gpdb,snaga/postgres-xl,xinzweb/gpdb,techdragon/Postgres-XL,lisakowen/gpdb,postmind-net/postgres-xl,50wu/gpdb,arcivanov/postgres-xl