At Fri, 01 Jul 2022 11:56:14 +0900 (JST), Kyotaro Horiguchi <horikyota....@gmail.com> wrote in > At Fri, 01 Jul 2022 11:46:53 +0900 (JST), Kyotaro Horiguchi > <horikyota....@gmail.com> wrote in > > Please find the attached. > > Mmm. It forgot the duplicate-call prevention and query-cancel > handling... The first one is the same as you posted but the second one > is still a problem..
So this is the first cut of that. regards. -- Kyotaro Horiguchi NTT Open Source Software Center
>From b160b89eda94213c5355174c30655bc447bff8da Mon Sep 17 00:00:00 2001 From: Kyotaro Horiguchi <horikyota....@gmail.com> Date: Fri, 1 Jul 2022 11:38:34 +0900 Subject: [PATCH v2] Use permanent backup-abort call back in perform_base_backup --- src/backend/replication/basebackup.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c index 95440013c0..6f8fb78212 100644 --- a/src/backend/replication/basebackup.c +++ b/src/backend/replication/basebackup.c @@ -234,6 +234,11 @@ perform_base_backup(basebackup_options *opt, bbsink *sink) StringInfo tblspc_map_file; backup_manifest_info manifest; + if (get_backup_status() == SESSION_BACKUP_RUNNING) + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("a backup is already in progress in this session"))); + /* Initial backup state, insofar as we know it now. */ state.tablespaces = NIL; state.tablespace_num = 0; @@ -255,19 +260,15 @@ perform_base_backup(basebackup_options *opt, bbsink *sink) total_checksum_failures = 0; basebackup_progress_wait_checkpoint(); + + register_persistent_abort_backup_handler(); + state.startptr = do_pg_backup_start(opt->label, opt->fastcheckpoint, &state.starttli, labelfile, &state.tablespaces, tblspc_map_file); - /* - * Once do_pg_backup_start has been called, ensure that any failure causes - * us to abort the backup so we don't "leak" a backup counter. For this - * reason, *all* functionality between do_pg_backup_start() and the end of - * do_pg_backup_stop() should be inside the error cleanup block! - */ - - PG_ENSURE_ERROR_CLEANUP(do_pg_abort_backup, BoolGetDatum(false)); + PG_TRY(); { ListCell *lc; tablespaceinfo *ti; @@ -373,10 +374,12 @@ perform_base_backup(basebackup_options *opt, bbsink *sink) } basebackup_progress_wait_wal_archive(&state); + } + PG_FINALLY(); + { endptr = do_pg_backup_stop(labelfile->data, !opt->nowait, &endtli); } - PG_END_ENSURE_ERROR_CLEANUP(do_pg_abort_backup, BoolGetDatum(false)); - + PG_END_TRY(); if (opt->includewal) { -- 2.31.1