Addressed review comments and renamed function to hasConcurrentBackups/Restores - Updated backup/restore status when concurrent backups & restores are not allowed

This commit is contained in:
Smita Kulkarni 2023-01-24 16:20:12 +01:00
parent d387835774
commit 6be7d1c24a
2 changed files with 14 additions and 12 deletions

View File

@ -173,8 +173,9 @@ OperationID BackupsWorker::startMakingBackup(const ASTPtr & query, const Context
String backup_name_for_logging = backup_info.toStringForLogging();
try
{
if (!checkConcurrentBackups(backup_settings))
if (!allow_concurrent_backups && hasConcurrentBackups(backup_settings))
{
/// addInfo is called here to record the failed backup details
addInfo(backup_id, backup_name_for_logging, backup_settings.internal, BackupStatus::BACKUP_FAILED);
throw Exception(ErrorCodes::CONCURRENT_ACCESS_NOT_SUPPORTED, "Concurrent backups not supported, turn on setting 'allow_concurrent_backups'");
}
@ -405,8 +406,9 @@ OperationID BackupsWorker::startRestoring(const ASTPtr & query, ContextMutablePt
auto backup_info = BackupInfo::fromAST(*restore_query->backup_name);
String backup_name_for_logging = backup_info.toStringForLogging();
if (!checkConcurrentRestores(restore_settings))
if (!allow_concurrent_restores && hasConcurrentRestores(restore_settings))
{
/// addInfo is called here to record the failed restore details
addInfo(restore_id, backup_name_for_logging, restore_settings.internal, BackupStatus::RESTORING);
throw Exception(ErrorCodes::CONCURRENT_ACCESS_NOT_SUPPORTED, "Concurrent restores not supported, turn on setting 'allow_concurrent_restores'");
}
@ -731,32 +733,32 @@ std::vector<BackupsWorker::Info> BackupsWorker::getAllActiveRestoreInfos() const
return res_infos;
}
bool BackupsWorker::checkConcurrentBackups(const BackupSettings & backup_settings) const
bool BackupsWorker::hasConcurrentBackups(const BackupSettings & backup_settings) const
{
/// Check if there are no concurrent backups
if (!allow_concurrent_backups && num_active_backups)
if (num_active_backups)
{
/// If its an internal backup and we currently have 1 active backup, it could be the original query, validate using backup_uuid
if (!(num_active_backups == 1 && backup_settings.internal && getAllActiveBackupInfos().at(0).id == toString(*backup_settings.backup_uuid)))
{
return false;
return true;
}
}
return true;
return false;
}
bool BackupsWorker::checkConcurrentRestores(const RestoreSettings & restore_settings) const
bool BackupsWorker::hasConcurrentRestores(const RestoreSettings & restore_settings) const
{
/// Check if there are no concurrent restores
if (!allow_concurrent_restores && num_active_restores)
if (num_active_restores)
{
/// If its an internal restore and we currently have 1 active restore, it could be the original query, validate using iz
if (!(num_active_restores == 1 && restore_settings.internal && getAllActiveRestoreInfos().at(0).id == toString(*restore_settings.restore_uuid)))
{
return false;
return true;
}
}
return true;
return false;
}
void BackupsWorker::shutdown()

View File

@ -105,8 +105,8 @@ private:
void setNumFilesAndSize(const OperationID & id, size_t num_files, UInt64 uncompressed_size, UInt64 compressed_size);
std::vector<Info> getAllActiveBackupInfos() const;
std::vector<Info> getAllActiveRestoreInfos() const;
bool checkConcurrentBackups(const BackupSettings & backup_settings) const;
bool checkConcurrentRestores(const RestoreSettings & restore_settings) const;
bool hasConcurrentBackups(const BackupSettings & backup_settings) const;
bool hasConcurrentRestores(const RestoreSettings & restore_settings) const;
ThreadPool backups_thread_pool;
ThreadPool restores_thread_pool;