mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-16 19:32:07 +00:00
Add some logging to restoring access entities.
This commit is contained in:
parent
3c4d6509f3
commit
91a91be172
@ -200,6 +200,7 @@ AccessRestorerFromBackup::AccessRestorerFromBackup(
|
|||||||
: backup(backup_)
|
: backup(backup_)
|
||||||
, creation_mode(restore_settings_.create_access)
|
, creation_mode(restore_settings_.create_access)
|
||||||
, skip_unresolved_dependencies(restore_settings_.allow_unresolved_access_dependencies)
|
, skip_unresolved_dependencies(restore_settings_.allow_unresolved_access_dependencies)
|
||||||
|
, log(getLogger("AccessRestorerFromBackup"))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,6 +379,7 @@ void AccessRestorerFromBackup::generateRandomIDsAndResolveDependencies(const Acc
|
|||||||
if (entity_info.restore && (creation_mode == RestoreAccessCreationMode::kReplace))
|
if (entity_info.restore && (creation_mode == RestoreAccessCreationMode::kReplace))
|
||||||
{
|
{
|
||||||
entity_info.new_id = UUIDHelpers::generateV4();
|
entity_info.new_id = UUIDHelpers::generateV4();
|
||||||
|
LOG_TRACE(log, "{}: Generated new UUID {}", AccessEntityTypeInfo::get(type).formatEntityNameWithType(name), *entity_info.new_id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,8 +390,11 @@ void AccessRestorerFromBackup::generateRandomIDsAndResolveDependencies(const Acc
|
|||||||
throw Exception(ErrorCodes::ACCESS_ENTITY_ALREADY_EXISTS, "Cannot restore {} because it already exists",
|
throw Exception(ErrorCodes::ACCESS_ENTITY_ALREADY_EXISTS, "Cannot restore {} because it already exists",
|
||||||
AccessEntityTypeInfo::get(type).formatEntityNameWithType(name));
|
AccessEntityTypeInfo::get(type).formatEntityNameWithType(name));
|
||||||
}
|
}
|
||||||
|
bool was_going_to_restore = entity_info.restore;
|
||||||
entity_info.new_id = *existing_id;
|
entity_info.new_id = *existing_id;
|
||||||
entity_info.restore = false;
|
entity_info.restore = false;
|
||||||
|
LOG_TRACE(log, "{}: Found with UUID {}{}", AccessEntityTypeInfo::get(type).formatEntityNameWithType(name), *existing_id,
|
||||||
|
(was_going_to_restore ? ", will not restore" : ""));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -399,7 +404,14 @@ void AccessRestorerFromBackup::generateRandomIDsAndResolveDependencies(const Acc
|
|||||||
AccessEntityTypeInfo::get(type).formatEntityNameWithType(name));
|
AccessEntityTypeInfo::get(type).formatEntityNameWithType(name));
|
||||||
}
|
}
|
||||||
if (entity_info.restore)
|
if (entity_info.restore)
|
||||||
|
{
|
||||||
entity_info.new_id = UUIDHelpers::generateV4();
|
entity_info.new_id = UUIDHelpers::generateV4();
|
||||||
|
LOG_TRACE(log, "{}: Generated new UUID {}", AccessEntityTypeInfo::get(type).formatEntityNameWithType(name), *entity_info.new_id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG_TRACE(log, "{}: Not found, ignoring", AccessEntityTypeInfo::get(type).formatEntityNameWithType(name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,6 +471,8 @@ void restoreAccessEntitiesFromBackup(
|
|||||||
if (entities.empty())
|
if (entities.empty())
|
||||||
return; /// Nothing to restore.
|
return; /// Nothing to restore.
|
||||||
|
|
||||||
|
auto log = getLogger("AccessRestorerFromBackup");
|
||||||
|
|
||||||
bool replace_if_exists = (restore_settings.create_access == RestoreAccessCreationMode::kReplace);
|
bool replace_if_exists = (restore_settings.create_access == RestoreAccessCreationMode::kReplace);
|
||||||
bool throw_if_exists = (restore_settings.create_access == RestoreAccessCreationMode::kCreate);
|
bool throw_if_exists = (restore_settings.create_access == RestoreAccessCreationMode::kCreate);
|
||||||
|
|
||||||
@ -467,14 +481,20 @@ void restoreAccessEntitiesFromBackup(
|
|||||||
|
|
||||||
for (const auto & [id, entity] : entities)
|
for (const auto & [id, entity] : entities)
|
||||||
{
|
{
|
||||||
|
const String & name = entity->getName();
|
||||||
|
auto type = entity->getType();
|
||||||
|
LOG_TRACE(log, "{}: Adding with UUID {}", AccessEntityTypeInfo::get(type).formatEntityNameWithType(name), id);
|
||||||
|
|
||||||
UUID existing_id;
|
UUID existing_id;
|
||||||
if (destination_access_storage.insert(id, entity, replace_if_exists, throw_if_exists, &existing_id))
|
if (destination_access_storage.insert(id, entity, replace_if_exists, throw_if_exists, &existing_id))
|
||||||
{
|
{
|
||||||
|
LOG_TRACE(log, "{}: Added successfully", AccessEntityTypeInfo::get(type).formatEntityNameWithType(name));
|
||||||
restored_ids.emplace(id);
|
restored_ids.emplace(id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/// Couldn't insert `entity` because there is an existing entity with the same name.
|
/// Couldn't insert `entity` because there is an existing entity with the same name.
|
||||||
|
LOG_TRACE(log, "{}: Not added because already exists with UUID {}", AccessEntityTypeInfo::get(type).formatEntityNameWithType(name), existing_id);
|
||||||
new_to_existing_ids[id] = existing_id;
|
new_to_existing_ids[id] = existing_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -494,6 +514,7 @@ void restoreAccessEntitiesFromBackup(
|
|||||||
{
|
{
|
||||||
if (!entity->hasDependencies(new_ids))
|
if (!entity->hasDependencies(new_ids))
|
||||||
return entity;
|
return entity;
|
||||||
|
LOG_TRACE(log, "{}: Updating dependencies", entity->formatTypeWithName());
|
||||||
auto res = entity->clone();
|
auto res = entity->clone();
|
||||||
res->replaceDependencies(new_to_existing_ids);
|
res->replaceDependencies(new_to_existing_ids);
|
||||||
return res;
|
return res;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <Common/Logger.h>
|
||||||
#include <Core/UUID.h>
|
#include <Core/UUID.h>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
@ -63,6 +64,7 @@ private:
|
|||||||
const BackupPtr backup;
|
const BackupPtr backup;
|
||||||
const RestoreAccessCreationMode creation_mode;
|
const RestoreAccessCreationMode creation_mode;
|
||||||
const bool skip_unresolved_dependencies;
|
const bool skip_unresolved_dependencies;
|
||||||
|
const LoggerPtr log;
|
||||||
|
|
||||||
/// Whether loadFromBackup() finished.
|
/// Whether loadFromBackup() finished.
|
||||||
bool loaded = false;
|
bool loaded = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user