aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xlogfuncs.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2019-12-19 09:06:54 -0500
committerRobert Haas <rhaas@postgresql.org>2019-12-19 09:06:54 -0500
commit303640199d0436c5e7acdf50b837a027b5726594 (patch)
tree7e29adeaf572d6bb1ba0d44649b86f64520e109c /src/backend/access/transam/xlogfuncs.c
parente975c1a6026adb9e248a408fe3ca2629bc8c0084 (diff)
downloadpostgresql-303640199d0436c5e7acdf50b837a027b5726594.tar.gz
postgresql-303640199d0436c5e7acdf50b837a027b5726594.zip
Fix minor problems with non-exclusive backup cleanup.
The previous coding imagined that it could call before_shmem_exit() when a non-exclusive backup began and then remove the previously-added handler by calling cancel_before_shmem_exit() when that backup ended. However, this only works provided that nothing else in the system has registered a before_shmem_exit() hook in the interim, because cancel_before_shmem_exit() is documented to remove a callback only if it is the latest callback registered. It also only works if nothing can ERROR out between the time that sessionBackupState is reset and the time that cancel_before_shmem_exit(), which doesn't seem to be strictly true. To fix, leave the handler installed for the lifetime of the session, arrange to install it just once, and teach it to quietly do nothing if there isn't a non-exclusive backup in process. This is a bug, but for now I'm not going to back-patch, because the consequences are minor. It's possible to cause a spurious warning to be generated, but that doesn't really matter. It's also possible to trigger an assertion failure, but production builds shouldn't have assertions enabled. Patch by me, reviewed by Kyotaro Horiguchi, Michael Paquier (who preferred a different approach, but got outvoted), Fujii Masao, and Tom Lane, and with comments by various others. Discussion: http://postgr.es/m/CA+TgmobMjnyBfNhGTKQEDbqXYE3_rXWpc4CM63fhyerNCes3mA@mail.gmail.com
Diffstat (limited to 'src/backend/access/transam/xlogfuncs.c')
-rw-r--r--src/backend/access/transam/xlogfuncs.c17
1 files changed, 2 insertions, 15 deletions
diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c
index 1fccf29a36a..5fd12152b22 100644
--- a/src/backend/access/transam/xlogfuncs.c
+++ b/src/backend/access/transam/xlogfuncs.c
@@ -45,18 +45,6 @@ static StringInfo label_file;
static StringInfo tblspc_map_file;
/*
- * Called when the backend exits with a running non-exclusive base backup,
- * to clean up state.
- */
-static void
-nonexclusive_base_backup_cleanup(int code, Datum arg)
-{
- do_pg_abort_backup();
- ereport(WARNING,
- (errmsg("aborting backup due to backend exiting before pg_stop_backup was called")));
-}
-
-/*
* pg_start_backup: set up for taking an on-line backup dump
*
* Essentially what this does is to create a backup label file in $PGDATA,
@@ -103,10 +91,10 @@ pg_start_backup(PG_FUNCTION_ARGS)
tblspc_map_file = makeStringInfo();
MemoryContextSwitchTo(oldcontext);
+ register_persistent_abort_backup_handler();
+
startpoint = do_pg_start_backup(backupidstr, fast, NULL, label_file,
NULL, tblspc_map_file, false, true);
-
- before_shmem_exit(nonexclusive_base_backup_cleanup, (Datum) 0);
}
PG_RETURN_LSN(startpoint);
@@ -248,7 +236,6 @@ pg_stop_backup_v2(PG_FUNCTION_ARGS)
* and tablespace map so they can be written to disk by the caller.
*/
stoppoint = do_pg_stop_backup(label_file->data, waitforarchive, NULL);
- cancel_before_shmem_exit(nonexclusive_base_backup_cleanup, (Datum) 0);
values[1] = CStringGetTextDatum(label_file->data);
values[2] = CStringGetTextDatum(tblspc_map_file->data);