2022-04-25 14:33:25 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-04-17 12:11:43 +00:00
|
|
|
#include <Backups/IBackupCoordination.h>
|
2022-07-06 09:09:31 +00:00
|
|
|
#include <Backups/BackupCoordinationReplicatedAccess.h>
|
|
|
|
#include <Backups/BackupCoordinationReplicatedTables.h>
|
2022-07-20 19:44:51 +00:00
|
|
|
#include <Backups/BackupCoordinationStageSync.h>
|
2022-04-17 12:11:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2022-07-06 09:09:31 +00:00
|
|
|
/// Implementation of the IBackupCoordination interface performing coordination via ZooKeeper. It's necessary for "BACKUP ON CLUSTER".
|
|
|
|
class BackupCoordinationRemote : public IBackupCoordination
|
2022-04-17 12:11:43 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-07-20 19:44:51 +00:00
|
|
|
BackupCoordinationRemote(const String & zookeeper_path_, zkutil::GetZooKeeper get_zookeeper_, bool remove_zk_nodes_in_destructor_);
|
2022-07-06 09:09:31 +00:00
|
|
|
~BackupCoordinationRemote() override;
|
2022-04-17 12:11:43 +00:00
|
|
|
|
2022-07-20 19:44:51 +00:00
|
|
|
void setStage(const String & current_host, const String & new_stage, const String & message) override;
|
|
|
|
void setError(const String & current_host, const Exception & exception) override;
|
|
|
|
Strings waitForStage(const Strings & all_hosts, const String & stage_to_wait) override;
|
|
|
|
Strings waitForStage(const Strings & all_hosts, const String & stage_to_wait, std::chrono::milliseconds timeout) override;
|
2022-05-31 09:33:23 +00:00
|
|
|
|
2022-05-23 12:05:35 +00:00
|
|
|
void addReplicatedPartNames(
|
2022-06-24 19:29:38 +00:00
|
|
|
const String & table_shared_id,
|
2022-05-29 19:53:56 +00:00
|
|
|
const String & table_name_for_logs,
|
|
|
|
const String & replica_name,
|
|
|
|
const std::vector<PartNameAndChecksum> & part_names_and_checksums) override;
|
2022-05-23 12:05:35 +00:00
|
|
|
|
2022-06-24 19:29:38 +00:00
|
|
|
Strings getReplicatedPartNames(const String & table_shared_id, const String & replica_name) const override;
|
2022-05-23 12:05:35 +00:00
|
|
|
|
2022-07-05 07:39:52 +00:00
|
|
|
void addReplicatedMutations(
|
|
|
|
const String & table_shared_id,
|
|
|
|
const String & table_name_for_logs,
|
|
|
|
const String & replica_name,
|
|
|
|
const std::vector<MutationInfo> & mutations) override;
|
2022-07-06 10:03:10 +00:00
|
|
|
|
2022-07-05 07:39:52 +00:00
|
|
|
std::vector<MutationInfo> getReplicatedMutations(const String & table_shared_id, const String & replica_name) const override;
|
|
|
|
|
2022-06-24 19:29:38 +00:00
|
|
|
void addReplicatedDataPath(const String & table_shared_id, const String & data_path) override;
|
|
|
|
Strings getReplicatedDataPaths(const String & table_shared_id) const override;
|
2022-05-08 21:41:49 +00:00
|
|
|
|
2022-07-05 18:57:01 +00:00
|
|
|
void addReplicatedAccessFilePath(const String & access_zk_path, AccessEntityType access_entity_type, const String & host_id, const String & file_path) override;
|
|
|
|
Strings getReplicatedAccessFilePaths(const String & access_zk_path, AccessEntityType access_entity_type, const String & host_id) const override;
|
2022-06-29 20:44:05 +00:00
|
|
|
|
2022-04-19 09:02:34 +00:00
|
|
|
void addFileInfo(const FileInfo & file_info, bool & is_data_file_required) override;
|
2022-04-17 12:11:43 +00:00
|
|
|
void updateFileInfo(const FileInfo & file_info) override;
|
|
|
|
|
2022-04-19 18:15:27 +00:00
|
|
|
std::vector<FileInfo> getAllFileInfos() const override;
|
2022-06-19 13:48:52 +00:00
|
|
|
Strings listFiles(const String & directory, bool recursive) const override;
|
2022-06-06 09:50:20 +00:00
|
|
|
bool hasFiles(const String & directory) const override;
|
2022-04-19 18:15:27 +00:00
|
|
|
std::optional<FileInfo> getFileInfo(const String & file_name) const override;
|
|
|
|
std::optional<FileInfo> getFileInfo(const SizeAndChecksum & size_and_checksum) const override;
|
|
|
|
std::optional<SizeAndChecksum> getFileSizeAndChecksum(const String & file_name) const override;
|
2022-04-17 12:11:43 +00:00
|
|
|
|
|
|
|
String getNextArchiveSuffix() override;
|
2022-04-19 18:15:27 +00:00
|
|
|
Strings getAllArchiveSuffixes() const override;
|
2022-04-17 12:11:43 +00:00
|
|
|
|
|
|
|
private:
|
2022-07-26 11:15:34 +00:00
|
|
|
zkutil::ZooKeeperPtr getZooKeeper() const;
|
|
|
|
zkutil::ZooKeeperPtr getZooKeeperNoLock() const;
|
2022-04-17 12:11:43 +00:00
|
|
|
void createRootNodes();
|
|
|
|
void removeAllNodes();
|
2022-07-06 09:09:31 +00:00
|
|
|
void prepareReplicatedTables() const;
|
2022-07-05 18:57:01 +00:00
|
|
|
void prepareReplicatedAccess() const;
|
2022-04-17 12:11:43 +00:00
|
|
|
|
2022-04-19 18:15:27 +00:00
|
|
|
const String zookeeper_path;
|
|
|
|
const zkutil::GetZooKeeper get_zookeeper;
|
2022-07-20 19:44:51 +00:00
|
|
|
const bool remove_zk_nodes_in_destructor;
|
2022-05-31 09:33:23 +00:00
|
|
|
|
2022-07-26 11:15:34 +00:00
|
|
|
std::optional<BackupCoordinationStageSync> stage_sync;
|
2022-05-31 09:33:23 +00:00
|
|
|
|
|
|
|
mutable std::mutex mutex;
|
2022-07-26 11:15:34 +00:00
|
|
|
mutable zkutil::ZooKeeperPtr zookeeper;
|
2022-07-06 09:09:31 +00:00
|
|
|
mutable std::optional<BackupCoordinationReplicatedTables> replicated_tables;
|
2022-07-05 18:57:01 +00:00
|
|
|
mutable std::optional<BackupCoordinationReplicatedAccess> replicated_access;
|
2022-04-17 12:11:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|