2022-04-19 18:15:27 +00:00
|
|
|
#include <Backups/BackupCoordinationLocal.h>
|
2022-05-08 21:41:49 +00:00
|
|
|
#include <Common/Exception.h>
|
|
|
|
#include <Common/logger_useful.h>
|
2023-03-29 13:19:40 +00:00
|
|
|
#include <Common/quoteString.h>
|
2022-04-17 12:11:43 +00:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2022-05-08 21:41:49 +00:00
|
|
|
|
2023-03-29 13:19:40 +00:00
|
|
|
BackupCoordinationLocal::BackupCoordinationLocal(bool plain_backup_) : file_infos(plain_backup_)
|
|
|
|
{
|
|
|
|
}
|
2022-04-17 12:11:43 +00:00
|
|
|
|
2022-05-31 09:33:23 +00:00
|
|
|
BackupCoordinationLocal::~BackupCoordinationLocal() = default;
|
|
|
|
|
2023-03-24 16:38:19 +00:00
|
|
|
void BackupCoordinationLocal::setStage(const String &, const String &)
|
2022-05-08 21:41:49 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-03-24 16:38:19 +00:00
|
|
|
void BackupCoordinationLocal::setError(const Exception &)
|
2022-07-08 20:13:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-03-24 16:38:19 +00:00
|
|
|
Strings BackupCoordinationLocal::waitForStage(const String &)
|
2022-06-23 17:45:36 +00:00
|
|
|
{
|
2022-06-23 18:49:44 +00:00
|
|
|
return {};
|
2022-06-23 17:45:36 +00:00
|
|
|
}
|
|
|
|
|
2023-03-24 16:38:19 +00:00
|
|
|
Strings BackupCoordinationLocal::waitForStage(const String &, std::chrono::milliseconds)
|
2022-05-31 09:33:23 +00:00
|
|
|
{
|
2022-06-23 18:49:44 +00:00
|
|
|
return {};
|
2022-05-31 09:33:23 +00:00
|
|
|
}
|
2022-04-17 12:11:43 +00:00
|
|
|
|
2022-06-24 19:29:38 +00:00
|
|
|
void BackupCoordinationLocal::addReplicatedPartNames(const String & table_shared_id, const String & table_name_for_logs, const String & replica_name, const std::vector<PartNameAndChecksum> & part_names_and_checksums)
|
2022-05-08 21:41:49 +00:00
|
|
|
{
|
2023-03-29 13:19:40 +00:00
|
|
|
std::lock_guard lock{replicated_tables_mutex};
|
2022-07-06 09:09:31 +00:00
|
|
|
replicated_tables.addPartNames(table_shared_id, table_name_for_logs, replica_name, part_names_and_checksums);
|
2022-05-08 21:41:49 +00:00
|
|
|
}
|
|
|
|
|
2022-06-24 19:29:38 +00:00
|
|
|
Strings BackupCoordinationLocal::getReplicatedPartNames(const String & table_shared_id, const String & replica_name) const
|
2022-05-08 21:41:49 +00:00
|
|
|
{
|
2023-03-29 13:19:40 +00:00
|
|
|
std::lock_guard lock{replicated_tables_mutex};
|
2022-07-06 09:09:31 +00:00
|
|
|
return replicated_tables.getPartNames(table_shared_id, replica_name);
|
2022-07-05 07:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BackupCoordinationLocal::addReplicatedMutations(const String & table_shared_id, const String & table_name_for_logs, const String & replica_name, const std::vector<MutationInfo> & mutations)
|
|
|
|
{
|
2023-03-29 13:19:40 +00:00
|
|
|
std::lock_guard lock{replicated_tables_mutex};
|
2022-07-06 09:09:31 +00:00
|
|
|
replicated_tables.addMutations(table_shared_id, table_name_for_logs, replica_name, mutations);
|
2022-07-05 07:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<IBackupCoordination::MutationInfo> BackupCoordinationLocal::getReplicatedMutations(const String & table_shared_id, const String & replica_name) const
|
|
|
|
{
|
2023-03-29 13:19:40 +00:00
|
|
|
std::lock_guard lock{replicated_tables_mutex};
|
2022-07-06 09:09:31 +00:00
|
|
|
return replicated_tables.getMutations(table_shared_id, replica_name);
|
2022-05-23 12:05:35 +00:00
|
|
|
}
|
|
|
|
|
2022-05-29 19:53:56 +00:00
|
|
|
|
2022-06-24 19:29:38 +00:00
|
|
|
void BackupCoordinationLocal::addReplicatedDataPath(const String & table_shared_id, const String & data_path)
|
2022-05-23 12:05:35 +00:00
|
|
|
{
|
2023-03-29 13:19:40 +00:00
|
|
|
std::lock_guard lock{replicated_tables_mutex};
|
2022-07-06 09:09:31 +00:00
|
|
|
replicated_tables.addDataPath(table_shared_id, data_path);
|
2022-05-08 21:41:49 +00:00
|
|
|
}
|
|
|
|
|
2022-06-24 19:29:38 +00:00
|
|
|
Strings BackupCoordinationLocal::getReplicatedDataPaths(const String & table_shared_id) const
|
2022-05-08 21:41:49 +00:00
|
|
|
{
|
2023-03-29 13:19:40 +00:00
|
|
|
std::lock_guard lock{replicated_tables_mutex};
|
2022-07-06 09:09:31 +00:00
|
|
|
return replicated_tables.getDataPaths(table_shared_id);
|
2022-05-08 21:41:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-24 16:38:19 +00:00
|
|
|
void BackupCoordinationLocal::addReplicatedAccessFilePath(const String & access_zk_path, AccessEntityType access_entity_type, const String & file_path)
|
2022-06-29 20:44:05 +00:00
|
|
|
{
|
2023-03-29 13:19:40 +00:00
|
|
|
std::lock_guard lock{replicated_access_mutex};
|
2023-03-24 16:38:19 +00:00
|
|
|
replicated_access.addFilePath(access_zk_path, access_entity_type, "", file_path);
|
2022-06-29 20:44:05 +00:00
|
|
|
}
|
|
|
|
|
2023-03-24 16:38:19 +00:00
|
|
|
Strings BackupCoordinationLocal::getReplicatedAccessFilePaths(const String & access_zk_path, AccessEntityType access_entity_type) const
|
2022-06-29 20:44:05 +00:00
|
|
|
{
|
2023-03-29 13:19:40 +00:00
|
|
|
std::lock_guard lock{replicated_access_mutex};
|
2023-03-24 16:38:19 +00:00
|
|
|
return replicated_access.getFilePaths(access_zk_path, access_entity_type, "");
|
2022-06-29 20:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-24 16:38:19 +00:00
|
|
|
void BackupCoordinationLocal::addReplicatedSQLObjectsDir(const String & loader_zk_path, UserDefinedSQLObjectType object_type, const String & dir_path)
|
2023-02-06 15:52:39 +00:00
|
|
|
{
|
2023-03-29 13:19:40 +00:00
|
|
|
std::lock_guard lock{replicated_sql_objects_mutex};
|
2023-03-24 16:38:19 +00:00
|
|
|
replicated_sql_objects.addDirectory(loader_zk_path, object_type, "", dir_path);
|
2023-02-06 15:52:39 +00:00
|
|
|
}
|
|
|
|
|
2023-03-24 16:38:19 +00:00
|
|
|
Strings BackupCoordinationLocal::getReplicatedSQLObjectsDirs(const String & loader_zk_path, UserDefinedSQLObjectType object_type) const
|
2023-02-06 15:52:39 +00:00
|
|
|
{
|
2023-03-29 13:19:40 +00:00
|
|
|
std::lock_guard lock{replicated_sql_objects_mutex};
|
2023-03-24 16:38:19 +00:00
|
|
|
return replicated_sql_objects.getDirectories(loader_zk_path, object_type, "");
|
2023-02-06 15:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-29 13:19:40 +00:00
|
|
|
void BackupCoordinationLocal::addFileInfos(BackupFileInfos && file_infos_)
|
2022-04-17 12:11:43 +00:00
|
|
|
{
|
2023-03-29 13:19:40 +00:00
|
|
|
std::lock_guard lock{file_infos_mutex};
|
|
|
|
file_infos.addFileInfos(std::move(file_infos_), "");
|
2022-04-17 12:11:43 +00:00
|
|
|
}
|
|
|
|
|
2023-03-29 13:19:40 +00:00
|
|
|
BackupFileInfos BackupCoordinationLocal::getFileInfos() const
|
2022-04-17 12:11:43 +00:00
|
|
|
{
|
2023-03-29 13:19:40 +00:00
|
|
|
std::lock_guard lock{file_infos_mutex};
|
|
|
|
return file_infos.getFileInfos("");
|
2022-04-17 12:11:43 +00:00
|
|
|
}
|
|
|
|
|
2023-03-29 13:19:40 +00:00
|
|
|
BackupFileInfos BackupCoordinationLocal::getFileInfosForAllHosts() const
|
2022-04-17 12:11:43 +00:00
|
|
|
{
|
2023-03-29 13:19:40 +00:00
|
|
|
std::lock_guard lock{file_infos_mutex};
|
|
|
|
return file_infos.getFileInfosForAllHosts();
|
2022-04-17 12:11:43 +00:00
|
|
|
}
|
|
|
|
|
2023-03-29 13:19:40 +00:00
|
|
|
bool BackupCoordinationLocal::startWritingFile(size_t data_file_index)
|
2022-04-17 12:11:43 +00:00
|
|
|
{
|
2023-03-29 13:19:40 +00:00
|
|
|
std::lock_guard lock{writing_files_mutex};
|
|
|
|
/// Return false if this function was already called with this `data_file_index`.
|
|
|
|
return writing_files.emplace(data_file_index).second;
|
2022-04-17 12:11:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-16 08:30:27 +00:00
|
|
|
bool BackupCoordinationLocal::hasConcurrentBackups(const std::atomic<size_t> & num_active_backups) const
|
2023-02-10 11:04:05 +00:00
|
|
|
{
|
|
|
|
return (num_active_backups > 1);
|
|
|
|
}
|
|
|
|
|
2022-04-17 12:11:43 +00:00
|
|
|
}
|