diff options
author | Sascha Roloff <sascha.roloff@huawei.com> | 2024-02-23 09:32:54 +0100 |
---|---|---|
committer | Sascha Roloff <sascha.roloff@huawei.com> | 2024-02-26 17:16:21 +0100 |
commit | d83c997ad5a866f4fbb38d4a81e7edf70a491db2 (patch) | |
tree | 7331b4d58d2c56adecb6e9879862cf354129d6af /src/buildtool/execution_api/local | |
parent | 4ae3f068372041f949538fb273113a4a1c665a0f (diff) | |
download | justbuild-d83c997ad5a866f4fbb38d4a81e7edf70a491db2.tar.gz |
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.
Diffstat (limited to 'src/buildtool/execution_api/local')
-rw-r--r-- | src/buildtool/execution_api/local/TARGETS | 2 | ||||
-rw-r--r-- | src/buildtool/execution_api/local/local_api.hpp | 37 |
2 files changed, 39 insertions, 0 deletions
diff --git a/src/buildtool/execution_api/local/TARGETS b/src/buildtool/execution_api/local/TARGETS index c8895c20..f4cfde76 100644 --- a/src/buildtool/execution_api/local/TARGETS +++ b/src/buildtool/execution_api/local/TARGETS @@ -26,6 +26,7 @@ , "deps": [ ["@", "fmt", "", "fmt"] , ["@", "gsl", "", "gsl"] + , ["@", "grpc", "", "grpc++"] , ["src/buildtool/common", "config"] , ["src/buildtool/storage", "storage"] , ["src/buildtool/execution_api/common", "common"] @@ -36,6 +37,7 @@ , ["src/buildtool/compatibility", "compatibility"] , ["src/buildtool/execution_api/bazel_msg", "bazel_msg"] , ["src/buildtool/logging", "logging"] + , ["src/buildtool/execution_api/execution_service", "cas_utils"] ] , "stage": ["src", "buildtool", "execution_api", "local"] , "private-deps": 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 <iterator> #include <map> #include <memory> #include <optional> +#include <sstream> #include <string> #include <unordered_map> +#include <variant> #include <vector> #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<ArtifactDigest> const& chunk_digests) const noexcept + -> std::optional<ArtifactDigest> final { + Logger::Log(LogLevel::Debug, + "SpliceBlob({}, {} chunks)", + blob_digest.hash(), + chunk_digests.size()); + auto digests = std::vector<bazel_re::Digest>{}; + digests.reserve(chunk_digests.size()); + std::transform( + chunk_digests.cbegin(), + chunk_digests.cend(), + std::back_inserter(digests), + [](auto const& artifact_digest) { + return static_cast<bazel_re::Digest>(artifact_digest); + }); + auto splice_result = CASUtils::SpliceBlob( + static_cast<bazel_re::Digest>(blob_digest), digests, *storage_); + if (std::holds_alternative<grpc::Status>(splice_result)) { + auto* status = std::get_if<grpc::Status>(&splice_result); + Logger::Log(LogLevel::Error, status->error_message()); + return std::nullopt; + } + auto* digest = std::get_if<bazel_re::Digest>(&splice_result); + return ArtifactDigest{*digest}; + } + + [[nodiscard]] auto BlobSpliceSupport() const noexcept -> bool final { + return true; + } + private: std::optional<gsl::not_null<RepositoryConfig*>> repo_config_{}; gsl::not_null<Storage const*> storage_ = &Storage::Instance(); |