From 91a91be172c8124d5d7c6499a3870326bfefcbf0 Mon Sep 17 00:00:00 2001 From: Vitaly Baranov Date: Wed, 18 Sep 2024 19:52:24 +0200 Subject: [PATCH] Add some logging to restoring access entities. --- src/Access/AccessBackup.cpp | 21 +++++++++++++++++++++ src/Access/AccessBackup.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/Access/AccessBackup.cpp b/src/Access/AccessBackup.cpp index c2c37adffa8..1ac9a0d61e5 100644 --- a/src/Access/AccessBackup.cpp +++ b/src/Access/AccessBackup.cpp @@ -200,6 +200,7 @@ AccessRestorerFromBackup::AccessRestorerFromBackup( : backup(backup_) , creation_mode(restore_settings_.create_access) , 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)) { entity_info.new_id = UUIDHelpers::generateV4(); + LOG_TRACE(log, "{}: Generated new UUID {}", AccessEntityTypeInfo::get(type).formatEntityNameWithType(name), *entity_info.new_id); continue; } @@ -388,8 +390,11 @@ void AccessRestorerFromBackup::generateRandomIDsAndResolveDependencies(const Acc throw Exception(ErrorCodes::ACCESS_ENTITY_ALREADY_EXISTS, "Cannot restore {} because it already exists", AccessEntityTypeInfo::get(type).formatEntityNameWithType(name)); } + bool was_going_to_restore = entity_info.restore; entity_info.new_id = *existing_id; 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 { @@ -399,7 +404,14 @@ void AccessRestorerFromBackup::generateRandomIDsAndResolveDependencies(const Acc AccessEntityTypeInfo::get(type).formatEntityNameWithType(name)); } if (entity_info.restore) + { 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()) return; /// Nothing to restore. + auto log = getLogger("AccessRestorerFromBackup"); + bool replace_if_exists = (restore_settings.create_access == RestoreAccessCreationMode::kReplace); bool throw_if_exists = (restore_settings.create_access == RestoreAccessCreationMode::kCreate); @@ -467,14 +481,20 @@ void restoreAccessEntitiesFromBackup( 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; 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); } else { /// 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; } } @@ -494,6 +514,7 @@ void restoreAccessEntitiesFromBackup( { if (!entity->hasDependencies(new_ids)) return entity; + LOG_TRACE(log, "{}: Updating dependencies", entity->formatTypeWithName()); auto res = entity->clone(); res->replaceDependencies(new_to_existing_ids); return res; diff --git a/src/Access/AccessBackup.h b/src/Access/AccessBackup.h index c41184a0b7c..84dcf74a26e 100644 --- a/src/Access/AccessBackup.h +++ b/src/Access/AccessBackup.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -63,6 +64,7 @@ private: const BackupPtr backup; const RestoreAccessCreationMode creation_mode; const bool skip_unresolved_dependencies; + const LoggerPtr log; /// Whether loadFromBackup() finished. bool loaded = false;