From 9f5dcef077a3db2f6c791e403e5036f6464c9576 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Thu, 27 Jun 2024 13:27:06 +0200 Subject: Pass StorageConfig and Storage to LocalApi --- src/buildtool/execution_api/local/local_api.hpp | 53 ++++++++++++++----------- 1 file changed, 30 insertions(+), 23 deletions(-) (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 f9eefb64..6f43dd44 100644 --- a/src/buildtool/execution_api/local/local_api.hpp +++ b/src/buildtool/execution_api/local/local_api.hpp @@ -48,13 +48,18 @@ #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/logging/log_level.hpp" #include "src/buildtool/logging/logger.hpp" +#include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/storage.hpp" /// \brief API for local execution. class LocalApi final : public IExecutionApi { public: - explicit LocalApi(RepositoryConfig const* repo_config = nullptr) noexcept - : repo_config_{repo_config} {} + explicit LocalApi(gsl::not_null const& storage_config, + gsl::not_null const& storage, + RepositoryConfig const* repo_config = nullptr) noexcept + : storage_config_{*storage_config}, + storage_{*storage}, + repo_config_{repo_config} {} [[nodiscard]] auto CreateAction( ArtifactDigest const& root_digest, @@ -64,7 +69,8 @@ class LocalApi final : public IExecutionApi { std::map const& env_vars, std::map const& properties) const noexcept -> IExecutionAction::Ptr final { - return IExecutionAction::Ptr{new LocalAction{storage_, + return IExecutionAction::Ptr{new LocalAction{&storage_config_, + &storage_, root_digest, command, output_files, @@ -89,7 +95,7 @@ class LocalApi final : public IExecutionApi { auto const& info = artifacts_info[i]; if (IsTreeObject(info.type)) { // read object infos from sub tree and call retrieve recursively - auto reader = TreeReader{storage_->CAS()}; + auto reader = TreeReader{storage_.CAS()}; auto const result = reader.RecursivelyReadTreeLeafs( info.digest, output_paths[i]); if (not result) { @@ -109,7 +115,7 @@ class LocalApi final : public IExecutionApi { } } else { - auto const blob_path = storage_->CAS().BlobPath( + auto const blob_path = storage_.CAS().BlobPath( info.digest, IsExecutableObject(info.type)); if (not blob_path) { if (Compatibility::IsCompatible()) { @@ -143,7 +149,7 @@ class LocalApi final : public IExecutionApi { std::vector const& artifacts_info, std::vector const& fds, bool raw_tree) const noexcept -> bool final { - auto dumper = StreamDumper{storage_->CAS()}; + auto dumper = StreamDumper{storage_.CAS()}; return CommonRetrieveToFds( artifacts_info, fds, @@ -196,7 +202,7 @@ class LocalApi final : public IExecutionApi { auto const& info = missing_artifacts_info->back_map[dgst]; // Recursively process trees. if (IsTreeObject(info.type)) { - auto reader = TreeReader{storage_->CAS()}; + auto reader = TreeReader{storage_.CAS()}; auto const& result = reader.ReadDirectTreeEntries( info.digest, std::filesystem::path{}); if (not result or not RetrieveToCas(result->infos, api)) { @@ -207,9 +213,9 @@ class LocalApi final : public IExecutionApi { // Determine artifact path. auto const& path = IsTreeObject(info.type) - ? storage_->CAS().TreePath(info.digest) - : storage_->CAS().BlobPath(info.digest, - IsExecutableObject(info.type)); + ? storage_.CAS().TreePath(info.digest) + : storage_.CAS().BlobPath(info.digest, + IsExecutableObject(info.type)); if (not path) { return false; } @@ -221,7 +227,7 @@ class LocalApi final : public IExecutionApi { } // Regenerate digest since object infos read by - // storage_->ReadTreeInfos() will contain 0 as size. + // storage_.ReadTreeInfos() will contain 0 as size. ArtifactDigest digest = IsTreeObject(info.type) ? ArtifactDigest::Create(*content) @@ -251,10 +257,10 @@ class LocalApi final : public IExecutionApi { -> std::optional override { std::optional location{}; if (IsTreeObject(artifact_info.type)) { - location = storage_->CAS().TreePath(artifact_info.digest); + location = storage_.CAS().TreePath(artifact_info.digest); } else { - location = storage_->CAS().BlobPath( + location = storage_.CAS().BlobPath( artifact_info.digest, IsExecutableObject(artifact_info.type)); } std::optional content = std::nullopt; @@ -274,8 +280,8 @@ class LocalApi final : public IExecutionApi { auto const is_tree = NativeSupport::IsTree( static_cast(blob.digest).hash()); auto cas_digest = - is_tree ? storage_->CAS().StoreTree(*blob.data) - : storage_->CAS().StoreBlob(*blob.data, blob.is_exec); + is_tree ? storage_.CAS().StoreTree(*blob.data) + : storage_.CAS().StoreBlob(*blob.data, blob.is_exec); if (not cas_digest or not std::equal_to{}( *cas_digest, blob.digest)) { return false; @@ -298,7 +304,7 @@ class LocalApi final : public IExecutionApi { return CommonUploadTreeCompatible( *this, *build_root, - [&cas = storage_->CAS()]( + [&cas = storage_.CAS()]( std::vector const& digests, std::vector* targets) { targets->reserve(digests.size()); @@ -317,8 +323,8 @@ class LocalApi final : public IExecutionApi { -> bool final { return static_cast( NativeSupport::IsTree(static_cast(digest).hash()) - ? storage_->CAS().TreePath(digest) - : storage_->CAS().BlobPath(digest, false)); + ? storage_.CAS().TreePath(digest) + : storage_.CAS().BlobPath(digest, false)); } [[nodiscard]] auto IsAvailable(std::vector const& digests) @@ -327,8 +333,8 @@ class LocalApi final : public IExecutionApi { for (auto const& digest : digests) { auto const& path = NativeSupport::IsTree( static_cast(digest).hash()) - ? storage_->CAS().TreePath(digest) - : storage_->CAS().BlobPath(digest, false); + ? storage_.CAS().TreePath(digest) + : storage_.CAS().BlobPath(digest, false); if (not path) { result.push_back(digest); } @@ -340,7 +346,7 @@ class LocalApi final : public IExecutionApi { const noexcept -> std::optional> final { Logger::Log(LogLevel::Debug, "SplitBlob({})", blob_digest.hash()); auto split_result = CASUtils::SplitBlobFastCDC( - static_cast(blob_digest), *storage_); + static_cast(blob_digest), storage_); if (not split_result) { Logger::Log(LogLevel::Error, split_result.error().error_message()); return std::nullopt; @@ -390,7 +396,7 @@ class LocalApi final : public IExecutionApi { return static_cast(artifact_digest); }); auto splice_result = CASUtils::SpliceBlob( - static_cast(blob_digest), digests, *storage_); + static_cast(blob_digest), digests, storage_); if (not splice_result) { Logger::Log(LogLevel::Error, splice_result.error().error_message()); return std::nullopt; @@ -403,8 +409,9 @@ class LocalApi final : public IExecutionApi { } private: + StorageConfig const& storage_config_; + Storage const& storage_; RepositoryConfig const* const repo_config_ = nullptr; - gsl::not_null storage_ = &Storage::Instance(); }; #endif // INCLUDED_SRC_BUILDTOOL_EXECUTION_API_LOCAL_LOCAL_API_HPP -- cgit v1.2.3