From 140e8c993b9d5d4490c1f657affced2d48abf4af Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Thu, 10 Apr 2025 17:02:38 +0200 Subject: Drop unused directory map The BazelNetworkReader contains an optimization for reading directories in case the remote execution (in compatible mode) supports the GetTree request. This is, however not the case for many remote exeuciton services, including our own single-node execution service. So the code is basically untested and rarely used, if at all. Moreover, justbuild is usually used in native mode and using compatibility mode is expected to handle tree operations less efficient. Therefore, remove this basically dead code and decrease complexity this way. --- .../execution_api/remote/bazel/bazel_api.cpp | 7 +--- .../remote/bazel/bazel_network_reader.cpp | 46 ---------------------- .../remote/bazel/bazel_network_reader.hpp | 13 ------ 3 files changed, 2 insertions(+), 64 deletions(-) (limited to 'src/buildtool/execution_api/remote/bazel') diff --git a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp index fe6ad757..f15d421d 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp @@ -191,11 +191,8 @@ auto BazelApi::CreateAction( else { if (IsTreeObject(info.type)) { // read object infos from sub tree and call retrieve recursively - auto request_remote_tree = alternative != nullptr - ? std::make_optional(info.digest) - : std::nullopt; - auto reader = TreeReader{ - network_->CreateReader(), std::move(request_remote_tree)}; + auto reader = + TreeReader{network_->CreateReader()}; auto const result = reader.RecursivelyReadTreeLeafs( info.digest, output_paths[i]); if (not result or diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp index 6f125d67..4580cf22 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.cpp @@ -21,11 +21,8 @@ #include #include -#include "src/buildtool/common/artifact_digest_factory.hpp" #include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/execution_api/bazel_msg/bazel_msg_factory.hpp" -#include "src/buildtool/execution_api/common/message_limits.hpp" -#include "src/buildtool/file_system/object_type.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" #include "src/utils/cpp/back_map.hpp" @@ -40,32 +37,8 @@ BazelNetworkReader::BazelNetworkReader( cas_{*cas}, hash_function_{hash_function} {} -BazelNetworkReader::BazelNetworkReader( - BazelNetworkReader&& other, - std::optional request_remote_tree) noexcept - : instance_name_{other.instance_name_}, - cas_{other.cas_}, - hash_function_{other.hash_function_} { - if (not IsNativeProtocol() and request_remote_tree) { - // Query full tree from remote CAS. Note that this is currently not - // supported by Buildbarn revision c3c06bbe2a. - auto full_tree = - cas_.GetTree(instance_name_, - ArtifactDigestFactory::ToBazel(*request_remote_tree), - MessageLimits::kMaxGrpcLength); - auxiliary_map_ = MakeAuxiliaryMap(std::move(full_tree)); - } -} - auto BazelNetworkReader::ReadDirectory(ArtifactDigest const& digest) const noexcept -> std::optional { - if (auxiliary_map_) { - auto it = auxiliary_map_->find(digest); - if (it != auxiliary_map_->end()) { - return it->second; - } - } - if (auto blob = ReadSingleBlob(digest)) { if (auto const content = blob->ReadContent()) { return BazelMsgFactory::MessageFromString( @@ -152,25 +125,6 @@ auto BazelNetworkReader::IsNativeProtocol() const noexcept -> bool { return ProtocolTraits::IsNative(hash_function_.GetType()); } -auto BazelNetworkReader::MakeAuxiliaryMap( - std::vector&& full_tree) const noexcept - -> std::optional { - ExpectsAudit(not IsNativeProtocol()); - - DirectoryMap result; - result.reserve(full_tree.size()); - for (auto& dir : full_tree) { - try { - result.emplace(ArtifactDigestFactory::HashDataAs( - hash_function_, dir.SerializeAsString()), - std::move(dir)); - } catch (...) { - return std::nullopt; - } - } - return result; -} - auto BazelNetworkReader::ReadSingleBlob(ArtifactDigest const& digest) const noexcept -> std::optional { return cas_.ReadSingleBlob(instance_name_, digest); diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp index f7915446..fb138844 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_network_reader.hpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include @@ -42,10 +41,6 @@ class BazelNetworkReader final { gsl::not_null const& cas, HashFunction hash_function) noexcept; - BazelNetworkReader( - BazelNetworkReader&& other, - std::optional request_remote_tree) noexcept; - [[nodiscard]] auto ReadDirectory(ArtifactDigest const& digest) const noexcept -> std::optional; @@ -79,17 +74,9 @@ class BazelNetworkReader final { const noexcept -> std::vector; private: - using DirectoryMap = - std::unordered_map; - std::string const instance_name_; BazelCasClient const& cas_; HashFunction hash_function_; - std::optional auxiliary_map_; - - [[nodiscard]] auto MakeAuxiliaryMap( - std::vector&& full_tree) const noexcept - -> std::optional; }; #endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_REMOTE_BAZEL_BAZEL_TREE_READER_HPP -- cgit v1.2.3