ClickHouse/src/Backups/BackupFactory.h

53 lines
1.3 KiB
C++
Raw Normal View History

2021-08-18 22:19:14 +00:00
#pragma once
#include <Backups/IBackup.h>
#include <Backups/BackupInfo.h>
2021-08-18 22:19:14 +00:00
#include <Core/Types.h>
#include <Parsers/IAST_fwd.h>
2021-08-18 22:19:14 +00:00
#include <boost/noncopyable.hpp>
#include <memory>
#include <optional>
#include <unordered_map>
2021-08-18 22:19:14 +00:00
namespace DB
{
class Context;
using ContextPtr = std::shared_ptr<const Context>;
2021-08-18 22:19:14 +00:00
/// Factory for implementations of the IBackup interface.
class BackupFactory : boost::noncopyable
{
public:
using OpenMode = IBackup::OpenMode;
2021-08-18 22:19:14 +00:00
struct CreateParams
{
OpenMode open_mode = OpenMode::WRITE;
2022-04-19 18:15:27 +00:00
std::optional<UUID> backup_uuid;
BackupInfo backup_info;
std::optional<BackupInfo> base_backup_info;
String compression_method;
int compression_level = -1;
String password;
ContextPtr context;
2022-04-19 18:15:27 +00:00
bool is_internal_backup = false;
String coordination_zk_path;
};
2021-08-18 22:19:14 +00:00
static BackupFactory & instance();
2021-08-18 22:19:14 +00:00
/// Creates a new backup or opens it.
BackupMutablePtr createBackup(const CreateParams & params) const;
using CreatorFn = std::function<BackupMutablePtr(const CreateParams & params)>;
void registerBackupEngine(const String & engine_name, const CreatorFn & creator_fn);
2021-08-18 22:19:14 +00:00
private:
BackupFactory();
std::unordered_map<String, CreatorFn> creators;
2021-08-18 22:19:14 +00:00
};
}