Thread: pgsql: Revert refactoring of restore command code to shell_restore.c

pgsql: Revert refactoring of restore command code to shell_restore.c

From
Michael Paquier
Date:
Revert refactoring of restore command code to shell_restore.c

This reverts commits 24c35ec and 57169ad.  PreRestoreCommand() and
PostRestoreCommand() need to be put closer to the system() call calling
a restore_command, as they enable in_restore_command for the startup
process which would in turn trigger an immediate proc_exit() in the
SIGTERM handler.  Perhaps we could get rid of this behavior entirely,
but 24c35ec has made the window where the flag is enabled much larger
than it was, and any Postgres-like actions (palloc, etc.) taken by code
paths while the flag is enabled could lead to more severe issues in the
shutdown processing.

Note that curculio has showed that there are much more problems in this
area, unrelated to this change, actually, hence the issues related to
that had better be addressed first.  Keeping the code of HEAD in line
with the stable branches should make that a bit easier.

Per discussion with Andres Freund and Nathan Bossart.

Discussion: https://postgr.es/m/Y979NR3U5VnWrTwB@paquier.xyz

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/2f6e15ac93c58c1140e4a4affe61e78f7346497a

Modified Files
--------------
src/backend/access/transam/Makefile        |   1 -
src/backend/access/transam/meson.build     |   1 -
src/backend/access/transam/shell_restore.c | 171 -----------------------------
src/backend/access/transam/xlog.c          |  37 ++-----
src/backend/access/transam/xlogarchive.c   | 121 +++++++++++++++++++-
src/common/Makefile                        |   1 +
src/common/archive.c                       |  60 ++++++++++
src/common/meson.build                     |   1 +
src/fe_utils/archive.c                     |  11 +-
src/include/access/xlogarchive.h           |   7 +-
src/include/common/archive.h               |  21 ++++
src/tools/msvc/Mkvcbuild.pm                |   2 +-
12 files changed, 215 insertions(+), 219 deletions(-)