From fc9f622cba6b6671f5b5f0371de9bf31ae75c7d1 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Wed, 22 Jan 2025 11:55:59 +0100 Subject: Git CAS access: reduce log level Trying to access a git object return a recoverable failure, hence the failure to find the object in the git object database should be logged at warning level at most. Moreover, in some cases we should log that event at an even lower level, e.g., if we're just checking the presence of the object in the local git cas to avoid unnecessary network access. --- src/buildtool/common/repository_config.hpp | 9 ++++++--- src/buildtool/execution_api/git/git_api.hpp | 3 ++- src/buildtool/file_system/git_cas.cpp | 6 ++++-- src/buildtool/file_system/git_cas.hpp | 10 +++++++--- 4 files changed, 19 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/buildtool/common/repository_config.hpp b/src/buildtool/common/repository_config.hpp index 7e9ba88f..61eb4b7c 100644 --- a/src/buildtool/common/repository_config.hpp +++ b/src/buildtool/common/repository_config.hpp @@ -82,9 +82,12 @@ class RepositoryConfig { return nullptr; } - [[nodiscard]] auto ReadBlobFromGitCAS(std::string const& hex_id) - const noexcept -> std::optional { - return git_cas_ ? git_cas_->ReadObject(hex_id, /*is_hex_id=*/true) + [[nodiscard]] auto ReadBlobFromGitCAS( + std::string const& hex_id, + LogLevel log_failure = LogLevel::Warning) const noexcept + -> std::optional { + return git_cas_ ? git_cas_->ReadObject( + hex_id, /*is_hex_id=*/true, log_failure) : std::nullopt; } diff --git a/src/buildtool/execution_api/git/git_api.hpp b/src/buildtool/execution_api/git/git_api.hpp index 64e3bd16..a6ad4196 100644 --- a/src/buildtool/execution_api/git/git_api.hpp +++ b/src/buildtool/execution_api/git/git_api.hpp @@ -323,7 +323,8 @@ class GitApi final : public IExecutionApi { [[nodiscard]] auto IsAvailable(ArtifactDigest const& digest) const noexcept -> bool override { - return repo_config_->ReadBlobFromGitCAS(digest.hash()).has_value(); + return repo_config_->ReadBlobFromGitCAS(digest.hash(), LogLevel::Trace) + .has_value(); } [[nodiscard]] auto IsAvailable(std::vector const& digests) diff --git a/src/buildtool/file_system/git_cas.cpp b/src/buildtool/file_system/git_cas.cpp index 295b5783..1af1dde2 100644 --- a/src/buildtool/file_system/git_cas.cpp +++ b/src/buildtool/file_system/git_cas.cpp @@ -134,7 +134,9 @@ auto GitCAS::CreateEmpty() noexcept -> GitCASPtr { #endif } -auto GitCAS::ReadObject(std::string const& id, bool is_hex_id) const noexcept +auto GitCAS::ReadObject(std::string const& id, + bool is_hex_id, + LogLevel log_failure) const noexcept -> std::optional { #ifdef BOOTSTRAP_BUILD_TOOL return std::nullopt; @@ -150,7 +152,7 @@ auto GitCAS::ReadObject(std::string const& id, bool is_hex_id) const noexcept git_odb_object* obj = nullptr; if (git_odb_read(&obj, odb_.get(), &oid.value()) != 0) { - Logger::Log(LogLevel::Error, + Logger::Log(log_failure, "reading git object {} from database failed with:\n{}", is_hex_id ? id : ToHexString(id), GitLastError()); diff --git a/src/buildtool/file_system/git_cas.hpp b/src/buildtool/file_system/git_cas.hpp index f63fd543..5c5a3f31 100644 --- a/src/buildtool/file_system/git_cas.hpp +++ b/src/buildtool/file_system/git_cas.hpp @@ -63,9 +63,13 @@ class GitCAS { } /// \brief Read object from CAS. - /// \param id The object id. - /// \param is_hex_id Specify whether `id` is hex string or raw. - [[nodiscard]] auto ReadObject(std::string const& id, bool is_hex_id = false) + /// \param id The object id. + /// \param is_hex_id Specify whether `id` is hex string or raw. + /// \param log_failure Log level at which to log failures accessing the + /// object. + [[nodiscard]] auto ReadObject(std::string const& id, + bool is_hex_id = false, + LogLevel log_failure = LogLevel::Warning) const noexcept -> std::optional; /// \brief Read object header from CAS. -- cgit v1.2.3