From d83c997ad5a866f4fbb38d4a81e7edf70a491db2 Mon Sep 17 00:00:00 2001 From: Sascha Roloff Date: Fri, 23 Feb 2024 09:32:54 +0100 Subject: Refactor split and splice implementations. Currently, the implementations of the split and splice operation are both hidden behind the Bazel API implementation. This was sufficient to implement splitting at the server and splicing at the client. In order to support the other direction of splitting at the client and splicing at the server while reusing their implementations, the code needs to be refactored. First, the functionality of split and splice are explicitly exposed at the general execution API interface and implemented in the sub APIs. Second, the implementations of split and splice are factored into a separate utils class. --- src/buildtool/execution_api/local/local_api.hpp | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/buildtool/execution_api/local/local_api.hpp') diff --git a/src/buildtool/execution_api/local/local_api.hpp b/src/buildtool/execution_api/local/local_api.hpp index 1e3de092..5880475e 100644 --- a/src/buildtool/execution_api/local/local_api.hpp +++ b/src/buildtool/execution_api/local/local_api.hpp @@ -15,14 +15,18 @@ #ifndef INCLUDED_SRC_BUILDTOOL_EXECUTION_API_LOCAL_LOCAL_API_HPP #define INCLUDED_SRC_BUILDTOOL_EXECUTION_API_LOCAL_LOCAL_API_HPP +#include #include #include #include +#include #include #include +#include #include #include "fmt/core.h" +#include "grpcpp/support/status.h" #include "gsl/gsl" #include "src/buildtool/common/repository_config.hpp" #include "src/buildtool/compatibility/compatibility.hpp" @@ -30,6 +34,7 @@ #include "src/buildtool/execution_api/bazel_msg/bazel_blob.hpp" #include "src/buildtool/execution_api/bazel_msg/blob_tree.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" +#include "src/buildtool/execution_api/execution_service/cas_utils.hpp" #include "src/buildtool/execution_api/git/git_api.hpp" #include "src/buildtool/execution_api/local/local_action.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" @@ -454,6 +459,38 @@ class LocalApi final : public IExecutionApi { return result; } + [[nodiscard]] auto SpliceBlob( + ArtifactDigest const& blob_digest, + std::vector const& chunk_digests) const noexcept + -> std::optional final { + Logger::Log(LogLevel::Debug, + "SpliceBlob({}, {} chunks)", + blob_digest.hash(), + chunk_digests.size()); + auto digests = std::vector{}; + digests.reserve(chunk_digests.size()); + std::transform( + chunk_digests.cbegin(), + chunk_digests.cend(), + std::back_inserter(digests), + [](auto const& artifact_digest) { + return static_cast(artifact_digest); + }); + auto splice_result = CASUtils::SpliceBlob( + static_cast(blob_digest), digests, *storage_); + if (std::holds_alternative(splice_result)) { + auto* status = std::get_if(&splice_result); + Logger::Log(LogLevel::Error, status->error_message()); + return std::nullopt; + } + auto* digest = std::get_if(&splice_result); + return ArtifactDigest{*digest}; + } + + [[nodiscard]] auto BlobSpliceSupport() const noexcept -> bool final { + return true; + } + private: std::optional> repo_config_{}; gsl::not_null storage_ = &Storage::Instance(); -- cgit v1.2.3