Fix bug in determining when recovery has reached consistency.
Fix bug in determining when recovery has reached consistency.

When starting WAL replay from an online checkpoint, the last replayed WAL
record variable was initialized using the checkpoint record's location, even
though the records between the REDO location and the checkpoint record had
not been replayed yet. That was noted as "slightly confusing" but harmless
in the comment, but in some cases, it fooled CheckRecoveryConsistency to
incorrectly conclude that we had already reached a consistent state
immediately at the beginning of WAL replay. That caused the system to accept
read-only connections in hot standby mode too early, and also PANICs with
message "WAL contains references to invalid pages".

Fix by initializing the variables to the REDO location instead.

In 9.2 and above, change CheckRecoveryConsistency() to use
lastReplayedEndRecPtr variable when checking if backup end location has
been reached. It was inconsistently using EndRecPtr for that check, but
lastReplayedEndRecPtr when checking min recovery point. It made no
difference before this patch, because in all the places where
CheckRecoveryConsistency was called the two variables were the same, but
it was always an accident waiting to happen, and would have been wrong
after this patch anyway.

Report and analysis by Tomonari Katsumata, bug #8686. Backpatch to 9.0,
where hot standby was introduced.

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