Fix ERRORDATA_STACK_SIZE exceeded bug. Refactor.

A well-placed FlushErrorState() call within
RelationGetNumberOfBlocksInForkIfExists prevents this scenario.

In passing, tighten up LWLock Acquisition, rename and otherwise tweak some
things, and save last_state for future client functions.