In B-tree page deletion, clean up properly after page deletion failure.
In B-tree page deletion, clean up properly after page deletion failure.

In _bt_unlink_halfdead_page(), we might fail to find an immediate left
sibling of the target page, perhaps because of corruption of the page
sibling links.  The code intends to cope with this by just abandoning
the deletion attempt; but what actually happens is that it fails outright
due to releasing the same buffer lock twice.  (And error recovery masks
a second problem, which is possible leakage of a pin on another page.)
Seems to have been introduced by careless refactoring in commit efada2b8e.
Since there are multiple cases to consider, let's make releasing the buffer
lock in the failure case the responsibility of _bt_unlink_halfdead_page()
not its caller.

Also, avoid fetching the leaf page's left-link again after we've dropped
lock on the page.  This is probably harmless, but it's not exactly good
coding practice.

Per report from Kyotaro Horiguchi.  Back-patch to 9.4 where the faulty code
was introduced.

Discussion: <db3ab593205aa7caa9d496f6373bfd43b0162014@lab.ntt.co.jp>

ashwinstar/gpdb,greenplum-db/gpdb,xinzweb/gpdb,adam8157/gpdb,jmcatamney/gpdb,50wu/gpdb,jmcatamney/gpdb,ashwinstar/gpdb,adam8157/gpdb,xinzweb/gpdb,xinzweb/gpdb,greenplum-db/gpdb,ashwinstar/gpdb,xinzweb/gpdb,xinzweb/gpdb,50wu/gpdb,ashwinstar/gpdb,lisakowen/gpdb,jmcatamney/gpdb,greenplum-db/gpdb,lisakowen/gpdb,xinzweb/gpdb,ashwinstar/gpdb,adam8157/gpdb,greenplum-db/gpdb,greenplum-db/gpdb,adam8157/gpdb,jmcatamney/gpdb,greenplum-db/gpdb,lisakowen/gpdb,ashwinstar/gpdb,jmcatamney/gpdb,jmcatamney/gpdb,lisakowen/gpdb,50wu/gpdb,50wu/gpdb,jmcatamney/gpdb,adam8157/gpdb,greenplum-db/gpdb,ashwinstar/gpdb,50wu/gpdb,xinzweb/gpdb,xinzweb/gpdb,lisakowen/gpdb,adam8157/gpdb,lisakowen/gpdb,lisakowen/gpdb,adam8157/gpdb,50wu/gpdb,adam8157/gpdb,50wu/gpdb,greenplum-db/gpdb,lisakowen/gpdb,ashwinstar/gpdb,jmcatamney/gpdb,50wu/gpdb