2022-04-17 12:11:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-03-05 15:15:03 +00:00
|
|
|
#include <Core/Types.h>
|
2022-04-17 12:11:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2022-07-08 20:13:27 +00:00
|
|
|
class Exception;
|
2023-03-29 13:19:40 +00:00
|
|
|
struct BackupFileInfo;
|
|
|
|
using BackupFileInfos = std::vector<BackupFileInfo>;
|
2022-07-05 18:57:01 +00:00
|
|
|
enum class AccessEntityType;
|
2023-02-06 15:52:39 +00:00
|
|
|
enum class UserDefinedSQLObjectType;
|
2022-07-05 07:39:52 +00:00
|
|
|
|
2022-07-06 09:09:31 +00:00
|
|
|
/// Replicas use this class to coordinate what they're writing to a backup while executing BACKUP ON CLUSTER.
|
|
|
|
/// There are two implementation of this interface: BackupCoordinationLocal and BackupCoordinationRemote.
|
|
|
|
/// BackupCoordinationLocal is used while executing BACKUP without ON CLUSTER and performs coordination in memory.
|
|
|
|
/// BackupCoordinationRemote is used while executing BACKUP with ON CLUSTER and performs coordination via ZooKeeper.
|
2022-04-17 12:11:43 +00:00
|
|
|
class IBackupCoordination
|
|
|
|
{
|
|
|
|
public:
|
2022-05-01 13:36:32 +00:00
|
|
|
virtual ~IBackupCoordination() = default;
|
|
|
|
|
2022-07-20 19:44:51 +00:00
|
|
|
/// Sets the current stage and waits for other hosts to come to this stage too.
|
2023-03-24 16:38:19 +00:00
|
|
|
virtual void setStage(const String & new_stage, const String & message) = 0;
|
|
|
|
virtual void setError(const Exception & exception) = 0;
|
|
|
|
virtual Strings waitForStage(const String & stage_to_wait) = 0;
|
|
|
|
virtual Strings waitForStage(const String & stage_to_wait, std::chrono::milliseconds timeout) = 0;
|
2022-07-06 09:09:31 +00:00
|
|
|
|
2022-05-08 21:41:49 +00:00
|
|
|
struct PartNameAndChecksum
|
|
|
|
{
|
|
|
|
String part_name;
|
|
|
|
UInt128 checksum;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Adds part names which a specified replica of a replicated table is going to put to the backup.
|
|
|
|
/// Multiple replicas of the replicated table call this function and then the added part names can be returned by call of the function
|
2022-05-23 12:05:35 +00:00
|
|
|
/// getReplicatedPartNames().
|
2022-05-08 21:41:49 +00:00
|
|
|
/// Checksums are used only to control that parts under the same names on different replicas are the same.
|
2022-06-24 19:29:38 +00:00
|
|
|
virtual void addReplicatedPartNames(const String & table_shared_id, const String & table_name_for_logs, const String & replica_name,
|
2022-05-29 19:53:56 +00:00
|
|
|
const std::vector<PartNameAndChecksum> & part_names_and_checksums) = 0;
|
2022-05-08 21:41:49 +00:00
|
|
|
|
2022-05-29 19:53:56 +00:00
|
|
|
/// Returns the names of the parts which a specified replica of a replicated table should put to the backup.
|
|
|
|
/// This is the same list as it was added by call of the function addReplicatedPartNames() but without duplications and without
|
|
|
|
/// parts covered by another parts.
|
2022-06-24 19:29:38 +00:00
|
|
|
virtual Strings getReplicatedPartNames(const String & table_shared_id, const String & replica_name) const = 0;
|
2022-05-23 12:05:35 +00:00
|
|
|
|
2022-07-05 07:39:52 +00:00
|
|
|
struct MutationInfo
|
|
|
|
{
|
|
|
|
String id;
|
|
|
|
String entry;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Adds information about mutations of a replicated table.
|
|
|
|
virtual void addReplicatedMutations(const String & table_shared_id, const String & table_name_for_logs, const String & replica_name, const std::vector<MutationInfo> & mutations) = 0;
|
|
|
|
|
2022-07-06 10:03:10 +00:00
|
|
|
/// Returns all mutations of a replicated table which are not finished for some data parts added by addReplicatedPartNames().
|
|
|
|
virtual std::vector<MutationInfo> getReplicatedMutations(const String & table_shared_id, const String & replica_name) const = 0;
|
2022-07-05 07:39:52 +00:00
|
|
|
|
2023-11-08 10:22:44 +00:00
|
|
|
/// Adds information about KeeperMap tables
|
|
|
|
virtual void addKeeperMapTable(const String & table_zookeeper_root_path, const String & table_id, const String & data_path_in_backup) = 0;
|
|
|
|
|
|
|
|
/// KeeperMap tables use shared storage without local data so only one table should backup the data
|
|
|
|
virtual String getKeeperMapDataPath(const String & table_zookeeper_root_path) const = 0;
|
|
|
|
|
2022-05-23 12:05:35 +00:00
|
|
|
/// Adds a data path in backup for a replicated table.
|
|
|
|
/// Multiple replicas of the replicated table call this function and then all the added paths can be returned by call of the function
|
2022-05-29 19:53:56 +00:00
|
|
|
/// getReplicatedDataPaths().
|
2022-06-24 19:29:38 +00:00
|
|
|
virtual void addReplicatedDataPath(const String & table_shared_id, const String & data_path) = 0;
|
2022-05-29 19:53:56 +00:00
|
|
|
|
|
|
|
/// Returns all the data paths in backup added for a replicated table (see also addReplicatedDataPath()).
|
2022-06-24 19:29:38 +00:00
|
|
|
virtual Strings getReplicatedDataPaths(const String & table_shared_id) const = 0;
|
2022-05-23 12:05:35 +00:00
|
|
|
|
2022-06-29 20:44:05 +00:00
|
|
|
/// Adds a path to access.txt file keeping access entities of a ReplicatedAccessStorage.
|
2023-03-24 16:38:19 +00:00
|
|
|
virtual void addReplicatedAccessFilePath(const String & access_zk_path, AccessEntityType access_entity_type, const String & file_path) = 0;
|
|
|
|
virtual Strings getReplicatedAccessFilePaths(const String & access_zk_path, AccessEntityType access_entity_type) const = 0;
|
2022-07-06 10:03:10 +00:00
|
|
|
|
2023-02-06 15:52:39 +00:00
|
|
|
/// Adds a path to a directory with user-defined SQL objects inside the backup.
|
2023-03-24 16:38:19 +00:00
|
|
|
virtual void addReplicatedSQLObjectsDir(const String & loader_zk_path, UserDefinedSQLObjectType object_type, const String & dir_path) = 0;
|
|
|
|
virtual Strings getReplicatedSQLObjectsDirs(const String & loader_zk_path, UserDefinedSQLObjectType object_type) const = 0;
|
2023-02-06 15:52:39 +00:00
|
|
|
|
2022-04-17 12:11:43 +00:00
|
|
|
/// Adds file information.
|
2022-04-19 09:02:34 +00:00
|
|
|
/// If specified checksum+size are new for this IBackupContentsInfo the function sets `is_data_file_required`.
|
2023-03-29 13:19:40 +00:00
|
|
|
virtual void addFileInfos(BackupFileInfos && file_infos) = 0;
|
|
|
|
virtual BackupFileInfos getFileInfos() const = 0;
|
|
|
|
virtual BackupFileInfos getFileInfosForAllHosts() const = 0;
|
2022-04-17 12:11:43 +00:00
|
|
|
|
2023-03-29 13:19:40 +00:00
|
|
|
/// Starts writing a specified file, the function returns false if that file is already being written concurrently.
|
|
|
|
virtual bool startWritingFile(size_t data_file_index) = 0;
|
2023-02-10 11:04:05 +00:00
|
|
|
|
|
|
|
/// This function is used to check if concurrent backups are running
|
|
|
|
/// other than the backup passed to the function
|
2023-02-16 08:30:27 +00:00
|
|
|
virtual bool hasConcurrentBackups(const std::atomic<size_t> & num_active_backups) const = 0;
|
2022-04-17 12:11:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|