Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8328a15

Browse files
committed
Fix recently added incorrect assertion
Commit df3737a added an incorrect assertion about the preconditions for invoking the backup cleanup callback: it misfires at session end in case a backup completes successfully. Fix it, using coding from Michaël Paquier. Also add some tests for the various cases. Reported by Kyotaro Horiguchi <horikyota.ntt@gmail.com> Discussion: https://postgr.es/m/20221021.161038.1277961198945653224.horikyota.ntt@gmail.com
1 parent 2e0d80c commit 8328a15

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/backend/access/transam/xlog.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -8841,9 +8841,8 @@ do_pg_abort_backup(int code, Datum arg)
88418841
{
88428842
bool during_backup_start = DatumGetBool(arg);
88438843

8844-
/* Only one of these conditions can be true */
8845-
Assert(during_backup_start ^
8846-
(sessionBackupState == SESSION_BACKUP_RUNNING));
8844+
/* If called during backup start, there shouldn't be one already running */
8845+
Assert(!during_backup_start || sessionBackupState == SESSION_BACKUP_NONE);
88478846

88488847
if (during_backup_start || sessionBackupState != SESSION_BACKUP_NONE)
88498848
{

src/test/recovery/t/020_archive_status.pl

+14
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,18 @@
248248
ok( $logfile =~ qr/archiver process shutting down/,
249249
'check shutdown callback of shell archive module');
250250

251+
# Test that we can enter and leave backup mode without crashes
252+
my ($stderr, $cmdret);
253+
$cmdret = $primary->psql(
254+
'postgres',
255+
"SELECT pg_backup_start('onebackup'); "
256+
. "SELECT pg_backup_stop();"
257+
. "SELECT pg_backup_start(repeat('x', 1026))",
258+
stderr => \$stderr);
259+
is($cmdret, 3, "psql fails correctly");
260+
like($stderr, qr/backup label too long/, "pg_backup_start fails gracefully");
261+
$primary->safe_psql('postgres',
262+
"SELECT pg_backup_start('onebackup'); SELECT pg_backup_stop();");
263+
$primary->safe_psql('postgres', "SELECT pg_backup_start('twobackup')");
264+
251265
done_testing();

0 commit comments

Comments
 (0)