Refactor checking whether we've reached the recovery target.
Refactor checking whether we've reached the recovery target.

Makes the replay loop slightly more readable, by separating the concerns of
whether to stop and whether to delay, and how to extract the timestamp from
a record.

This has the user-visible change that the timestamp of the last applied
record is now updated after actually applying it. Before, it was updated
just before applying it. That meant that pg_last_xact_replay_timestamp()
could return the timestamp of a commit record that is in process of being
replayed, but not yet applied. Normally the difference is small, but if
min_recovery_apply_delay is set, there could be a significant delay between
reading a record and applying it.

Another behavioral change is that if you recover to a restore point, we stop
after the restore point record, not before it. It makes no difference as far
as running queries on the server is concerned, as applying a restore point
record changes nothing, but if examine the timeline history you will see
that the new timeline branched off just after the restore point record, not
before it. One practical consequence is that if you do PITR to the new
timeline, and set recovery target to the same named restore point again, it
will find and stop recovery at the same restore point. Conceptually, I think
it makes more sense to consider the restore point as part of the new
timeline's history than not.

In principle, setting the last-replayed timestamp before actually applying
the record was a bug all along, but it doesn't seem worth the risk to
backpatch, since min_recovery_apply_delay was only added in 9.4.

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