mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-15 02:41:59 +00:00
0f4c8144a6
Configuration values, such as disk names, backup engine names, etc, may give error message unintended sense, for example, if trying to backup to `disk` instead of `Disk`, the error message will be "Not found backup engine disk", which can be interpreted as "disk of backup engine not found". It might be not clear that the word "disk" comes from the query and is not part of the error message.
49 lines
1.2 KiB
C++
49 lines
1.2 KiB
C++
#include <Backups/BackupFactory.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
namespace ErrorCodes
|
|
{
|
|
extern const int BACKUP_ENGINE_NOT_FOUND;
|
|
extern const int LOGICAL_ERROR;
|
|
}
|
|
|
|
BackupFactory & BackupFactory::instance()
|
|
{
|
|
static BackupFactory the_instance;
|
|
return the_instance;
|
|
}
|
|
|
|
BackupMutablePtr BackupFactory::createBackup(const CreateParams & params) const
|
|
{
|
|
const String & engine_name = params.backup_info.backup_engine_name;
|
|
auto it = creators.find(engine_name);
|
|
if (it == creators.end())
|
|
throw Exception(ErrorCodes::BACKUP_ENGINE_NOT_FOUND, "Not found backup engine '{}'", engine_name);
|
|
return (it->second)(params);
|
|
}
|
|
|
|
void BackupFactory::registerBackupEngine(const String & engine_name, const CreatorFn & creator_fn)
|
|
{
|
|
if (creators.contains(engine_name))
|
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Backup engine '{}' was registered twice", engine_name);
|
|
creators[engine_name] = creator_fn;
|
|
}
|
|
|
|
void registerBackupEnginesFileAndDisk(BackupFactory &);
|
|
void registerBackupEngineS3(BackupFactory &);
|
|
|
|
void registerBackupEngines(BackupFactory & factory)
|
|
{
|
|
registerBackupEnginesFileAndDisk(factory);
|
|
registerBackupEngineS3(factory);
|
|
}
|
|
|
|
BackupFactory::BackupFactory()
|
|
{
|
|
registerBackupEngines(*this);
|
|
}
|
|
|
|
}
|