Do all-visible handling in lazy_vacuum_page() outside its critical section.
Do all-visible handling in lazy_vacuum_page() outside its critical section.

Since fdf9e21196a lazy_vacuum_page() rechecks the all-visible status
of pages in the second pass over the heap. It does so inside a
critical section, but both visibilitymap_test() and
heap_page_is_all_visible() perform operations that should not happen
inside one. The former potentially performs IO and both potentially do
memory allocations.

To fix, simply move all the all-visible handling outside the critical
section. Doing so means that the PD_ALL_VISIBLE on the page won't be
included in the full page image of the HEAP2_CLEAN record anymore. But
that's fine, the flag will be set by the HEAP2_VISIBLE logged later.

Backpatch to 9.3 where the problem was introduced. The bug only came
to light due to the assertion added in 4a170ee9 and isn't likely to
cause problems in production scenarios. The worst outcome is a
avoidable PANIC restart.

This also gets rid of the difference in the order of operations
between master and standby mentioned in 2a8e1ac5.

Per reports from David Leverton and Keith Fiske in bug #10533.

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