Change the order that pg_xlog and WAL archive are polled for WAL segments.
Change the order that pg_xlog and WAL archive are polled for WAL segments.

If there is a WAL segment with same ID but different TLI present in both
the WAL archive and pg_xlog, prefer the one with higher TLI. Before this
patch, the archive was polled first, for all expected TLIs, and only if no
file was found was pg_xlog scanned. This was a change in behavior from 9.3,
which first scanned archive and pg_xlog for the highest TLI, then archive
and pg_xlog for the next highest TLI and so forth. This patch reverts the
behavior back to what it was in 9.2.

The reason for this is that if for example you try to do archive recovery
to timeline 2, which branched off timeline 1, but the WAL for timeline 2 is
not archived yet, we would replay past the timeline switch point on
timeline 1 using the archived files, before even looking timeline 2's files
in pg_xlog

Report and patch by Kyotaro Horiguchi. Backpatch to 9.3 where the behavior
was changed.

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