mirror of
https://github.com/postgres/postgres.git
synced 2025-06-29 10:41:53 +03:00
Fix backup canceling
Assert-enabled build crashes but without asserts it works by wrong way: it may not reset forcing full page write and preventing from starting exclusive backup with the same name as cancelled. Patch replaces pair of booleans nonexclusive_backup_running/exclusive_backup_running to single enum to correctly describe backup state. Backpatch to 9.6 where bug was introduced Reported-by: David Steele Authors: Michael Paquier, David Steele Reviewed-by: Anastasia Lubennikova https://commitfest.postgresql.org/13/1068/
This commit is contained in:
@ -503,6 +503,12 @@ typedef enum ExclusiveBackupState
|
||||
EXCLUSIVE_BACKUP_STOPPING
|
||||
} ExclusiveBackupState;
|
||||
|
||||
/*
|
||||
* Session status of running backup, used for sanity checks in SQL-callable
|
||||
* functions to start and stop backups.
|
||||
*/
|
||||
static SessionBackupState sessionBackupState = SESSION_BACKUP_NONE;
|
||||
|
||||
/*
|
||||
* Shared state data for WAL insertion.
|
||||
*/
|
||||
@ -10566,13 +10572,17 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
|
||||
|
||||
/*
|
||||
* Mark that start phase has correctly finished for an exclusive backup.
|
||||
* Session-level locks are updated as well to reflect that state.
|
||||
*/
|
||||
if (exclusive)
|
||||
{
|
||||
WALInsertLockAcquireExclusive();
|
||||
XLogCtl->Insert.exclusiveBackupState = EXCLUSIVE_BACKUP_IN_PROGRESS;
|
||||
WALInsertLockRelease();
|
||||
sessionBackupState = SESSION_BACKUP_EXCLUSIVE;
|
||||
}
|
||||
else
|
||||
sessionBackupState = SESSION_BACKUP_NON_EXCLUSIVE;
|
||||
|
||||
/*
|
||||
* We're done. As a convenience, return the starting WAL location.
|
||||
@ -10627,6 +10637,15 @@ pg_stop_backup_callback(int code, Datum arg)
|
||||
WALInsertLockRelease();
|
||||
}
|
||||
|
||||
/*
|
||||
* Utility routine to fetch the session-level status of a backup running.
|
||||
*/
|
||||
SessionBackupState
|
||||
get_backup_status(void)
|
||||
{
|
||||
return sessionBackupState;
|
||||
}
|
||||
|
||||
/*
|
||||
* do_pg_stop_backup is the workhorse of the user-visible pg_stop_backup()
|
||||
* function.
|
||||
@ -10794,6 +10813,9 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p)
|
||||
}
|
||||
WALInsertLockRelease();
|
||||
|
||||
/* Clean up session-level lock */
|
||||
sessionBackupState = SESSION_BACKUP_NONE;
|
||||
|
||||
/*
|
||||
* Read and parse the START WAL LOCATION line (this code is pretty crude,
|
||||
* but we are not expecting any variability in the file format).
|
||||
|
Reference in New Issue
Block a user