diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-06-27 12:36:22 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-07-05 12:58:35 +0200 |
commit | 0d8a4ad15b93283cc31787b039051b9e9a285ba8 (patch) | |
tree | 40efbd2206659d6836ec0b3beec0811d2a01644f | |
parent | f82adab238f4b45d43049687c8e52bf7372ba053 (diff) | |
download | justbuild-0d8a4ad15b93283cc31787b039051b9e9a285ba8.tar.gz |
Pass StorageConfig and Storage to ServerImpl
15 files changed, 110 insertions, 71 deletions
diff --git a/src/buildtool/execution_api/execution_service/TARGETS b/src/buildtool/execution_api/execution_service/TARGETS index f0544913..caaf2b7d 100644 --- a/src/buildtool/execution_api/execution_service/TARGETS +++ b/src/buildtool/execution_api/execution_service/TARGETS @@ -11,10 +11,10 @@ , ["src/buildtool/logging", "logging"] , ["src/buildtool/common", "bazel_types"] , ["src/buildtool/storage", "storage"] + , ["src/buildtool/storage", "config"] ] , "private-deps": [ ["@", "fmt", "", "fmt"] - , ["src/buildtool/storage", "config"] , ["src/buildtool/file_system", "file_system_manager"] , ["src/buildtool/logging", "log_level"] , "operation_cache" @@ -35,12 +35,10 @@ , ["src/buildtool/logging", "logging"] , ["src/buildtool/common", "bazel_types"] , ["src/buildtool/storage", "storage"] + , ["src/buildtool/storage", "config"] ] , "private-deps": - [ ["src/buildtool/storage", "config"] - , ["src/buildtool/logging", "log_level"] - , ["src/utils/cpp", "verify_hash"] - ] + [["src/buildtool/logging", "log_level"], ["src/utils/cpp", "verify_hash"]] } , "cas_server": { "type": ["@", "rules", "CC", "library"] @@ -54,12 +52,12 @@ , ["src/buildtool/common", "bazel_types"] , ["src/buildtool/storage", "storage"] , ["@", "gsl", "", "gsl"] + , ["src/buildtool/storage", "config"] ] , "private-deps": [ ["src/buildtool/compatibility", "compatibility"] , ["src/buildtool/logging", "log_level"] , ["@", "fmt", "", "fmt"] - , ["src/buildtool/storage", "config"] , ["src/utils/cpp", "verify_hash"] , "cas_utils" ] @@ -70,7 +68,11 @@ , "hdrs": ["server_implementation.hpp"] , "srcs": ["server_implementation.cpp"] , "stage": ["src", "buildtool", "execution_api", "execution_service"] - , "deps": [["src/buildtool/execution_api/common", "api_bundle"]] + , "deps": + [ ["src/buildtool/execution_api/common", "api_bundle"] + , ["src/buildtool/storage", "config"] + , ["src/buildtool/storage", "storage"] + ] , "private-deps": [ "execution_server" , "ac_server" @@ -100,6 +102,7 @@ [ ["@", "gsl", "", "gsl"] , ["src/buildtool/logging", "logging"] , ["src/buildtool/storage", "storage"] + , ["src/buildtool/storage", "config"] ] , "private-deps": [ ["src/buildtool/compatibility", "compatibility"] @@ -107,7 +110,6 @@ , ["src/buildtool/logging", "log_level"] , ["src/utils/cpp", "tmp_dir"] , ["@", "fmt", "", "fmt"] - , ["src/buildtool/storage", "config"] , ["src/utils/cpp", "verify_hash"] ] } diff --git a/src/buildtool/execution_api/execution_service/ac_server.cpp b/src/buildtool/execution_api/execution_service/ac_server.cpp index 8b0a216e..83b95c7f 100644 --- a/src/buildtool/execution_api/execution_service/ac_server.cpp +++ b/src/buildtool/execution_api/execution_service/ac_server.cpp @@ -16,7 +16,6 @@ #include "fmt/core.h" #include "src/buildtool/logging/log_level.hpp" -#include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/garbage_collector.hpp" #include "src/utils/cpp/verify_hash.hpp" @@ -31,13 +30,13 @@ auto ActionCacheServiceImpl::GetActionResult( logger_.Emit(LogLevel::Trace, "GetActionResult: {}", request->action_digest().hash()); - auto lock = GarbageCollector::SharedLock(StorageConfig::Instance()); + auto lock = GarbageCollector::SharedLock(storage_config_); if (!lock) { auto str = fmt::format("Could not acquire SharedLock"); logger_.Emit(LogLevel::Error, str); return grpc::Status{grpc::StatusCode::INTERNAL, str}; } - auto x = storage_->ActionCache().CachedResult(request->action_digest()); + auto x = storage_.ActionCache().CachedResult(request->action_digest()); if (!x) { return grpc::Status{ grpc::StatusCode::NOT_FOUND, diff --git a/src/buildtool/execution_api/execution_service/ac_server.hpp b/src/buildtool/execution_api/execution_service/ac_server.hpp index d862c5da..3072c70a 100644 --- a/src/buildtool/execution_api/execution_service/ac_server.hpp +++ b/src/buildtool/execution_api/execution_service/ac_server.hpp @@ -19,10 +19,16 @@ #include "gsl/gsl" #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/logging/logger.hpp" +#include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/storage.hpp" class ActionCacheServiceImpl final : public bazel_re::ActionCache::Service { public: + explicit ActionCacheServiceImpl( + gsl::not_null<StorageConfig const*> const& storage_config, + gsl::not_null<Storage const*> const& storage) noexcept + : storage_config_{*storage_config}, storage_{*storage} {} + // Retrieve a cached execution result. // // Implementations SHOULD ensure that any blobs referenced from the @@ -61,7 +67,8 @@ class ActionCacheServiceImpl final : public bazel_re::ActionCache::Service { ::bazel_re::ActionResult* response) -> ::grpc::Status override; private: - gsl::not_null<Storage const*> storage_ = &Storage::Instance(); + StorageConfig const& storage_config_; + Storage const& storage_; Logger logger_{"execution-service"}; }; diff --git a/src/buildtool/execution_api/execution_service/bytestream_server.cpp b/src/buildtool/execution_api/execution_service/bytestream_server.cpp index 35ff221d..cc49591b 100644 --- a/src/buildtool/execution_api/execution_service/bytestream_server.cpp +++ b/src/buildtool/execution_api/execution_service/bytestream_server.cpp @@ -23,7 +23,6 @@ #include "src/buildtool/compatibility/native_support.hpp" #include "src/buildtool/execution_api/common/bytestream_common.hpp" #include "src/buildtool/logging/log_level.hpp" -#include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/garbage_collector.hpp" #include "src/utils/cpp/tmp_dir.hpp" #include "src/utils/cpp/verify_hash.hpp" @@ -62,7 +61,7 @@ auto BytestreamServiceImpl::Read( return ::grpc::Status{::grpc::StatusCode::INVALID_ARGUMENT, *error_msg}; } - auto lock = GarbageCollector::SharedLock(StorageConfig::Instance()); + auto lock = GarbageCollector::SharedLock(storage_config_); if (!lock) { auto str = fmt::format("Could not acquire SharedLock"); logger_.Emit(LogLevel::Error, str); @@ -73,12 +72,12 @@ auto BytestreamServiceImpl::Read( if (NativeSupport::IsTree(*hash)) { ArtifactDigest dgst{NativeSupport::Unprefix(*hash), 0, true}; - path = storage_->CAS().TreePath(static_cast<bazel_re::Digest>(dgst)); + path = storage_.CAS().TreePath(static_cast<bazel_re::Digest>(dgst)); } else { ArtifactDigest dgst{NativeSupport::Unprefix(*hash), 0, false}; - path = storage_->CAS().BlobPath(static_cast<bazel_re::Digest>(dgst), - false); + path = + storage_.CAS().BlobPath(static_cast<bazel_re::Digest>(dgst), false); } if (!path) { auto str = fmt::format("could not find {}", *hash); @@ -126,14 +125,13 @@ auto BytestreamServiceImpl::Write( *hash, request.write_offset(), request.finish_write()); - auto lock = GarbageCollector::SharedLock(StorageConfig::Instance()); + auto lock = GarbageCollector::SharedLock(storage_config_); if (!lock) { auto str = fmt::format("Could not acquire SharedLock"); logger_.Emit(LogLevel::Error, str); return grpc::Status{grpc::StatusCode::INTERNAL, str}; } - auto tmp_dir = - StorageConfig::Instance().CreateTypedTmpDir("execution-service"); + auto tmp_dir = storage_config_.CreateTypedTmpDir("execution-service"); if (!tmp_dir) { return ::grpc::Status{::grpc::StatusCode::INTERNAL, "could not create TmpDir"}; @@ -150,14 +148,14 @@ auto BytestreamServiceImpl::Write( static_cast<std::streamsize>(request.data().size())); } if (NativeSupport::IsTree(*hash)) { - if (not storage_->CAS().StoreTree</*kOwner=*/true>(tmp)) { + if (not storage_.CAS().StoreTree</*kOwner=*/true>(tmp)) { auto str = fmt::format("could not store tree {}", *hash); logger_.Emit(LogLevel::Error, "{}", str); return ::grpc::Status{::grpc::StatusCode::INVALID_ARGUMENT, str}; } } else { - if (not storage_->CAS().StoreBlob</*kOwner=*/true>( + if (not storage_.CAS().StoreBlob</*kOwner=*/true>( tmp, /*is_executable=*/false)) { auto str = fmt::format("could not store blob {}", *hash); logger_.Emit(LogLevel::Error, "{}", str); diff --git a/src/buildtool/execution_api/execution_service/bytestream_server.hpp b/src/buildtool/execution_api/execution_service/bytestream_server.hpp index 69a30713..870aed77 100644 --- a/src/buildtool/execution_api/execution_service/bytestream_server.hpp +++ b/src/buildtool/execution_api/execution_service/bytestream_server.hpp @@ -18,10 +18,16 @@ #include "google/bytestream/bytestream.grpc.pb.h" #include "gsl/gsl" #include "src/buildtool/logging/logger.hpp" +#include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/storage.hpp" class BytestreamServiceImpl : public ::google::bytestream::ByteStream::Service { public: + explicit BytestreamServiceImpl( + gsl::not_null<StorageConfig const*> const& storage_config, + gsl::not_null<Storage const*> const& storage) noexcept + : storage_config_{*storage_config}, storage_{*storage} {} + // `Read()` is used to retrieve the contents of a resource as a sequence // of bytes. The bytes are returned in a sequence of responses, and the // responses are delivered as the results of a server-side streaming RPC. @@ -76,7 +82,8 @@ class BytestreamServiceImpl : public ::google::bytestream::ByteStream::Service { -> ::grpc::Status override; private: - gsl::not_null<Storage const*> storage_ = &Storage::Instance(); + StorageConfig const& storage_config_; + Storage const& storage_; Logger logger_{"execution-service:bytestream"}; }; diff --git a/src/buildtool/execution_api/execution_service/cas_server.cpp b/src/buildtool/execution_api/execution_service/cas_server.cpp index 7d87ae75..67437be6 100644 --- a/src/buildtool/execution_api/execution_service/cas_server.cpp +++ b/src/buildtool/execution_api/execution_service/cas_server.cpp @@ -27,7 +27,6 @@ #include "src/buildtool/compatibility/native_support.hpp" #include "src/buildtool/execution_api/execution_service/cas_utils.hpp" #include "src/buildtool/logging/log_level.hpp" -#include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/garbage_collector.hpp" #include "src/utils/cpp/verify_hash.hpp" @@ -63,7 +62,7 @@ auto CASServiceImpl::FindMissingBlobs( ::grpc::ServerContext* /*context*/, const ::bazel_re::FindMissingBlobsRequest* request, ::bazel_re::FindMissingBlobsResponse* response) -> ::grpc::Status { - auto lock = GarbageCollector::SharedLock(StorageConfig::Instance()); + auto lock = GarbageCollector::SharedLock(storage_config_); if (!lock) { auto str = fmt::format("FindMissingBlobs: could not acquire SharedLock"); @@ -83,12 +82,12 @@ auto CASServiceImpl::FindMissingBlobs( } logger_.Emit(LogLevel::Trace, "FindMissingBlobs: {}", hash); if (NativeSupport::IsTree(hash)) { - if (!storage_->CAS().TreePath(x)) { + if (not storage_.CAS().TreePath(x)) { auto* d = response->add_missing_blob_digests(); d->CopyFrom(x); } } - else if (!storage_->CAS().BlobPath(x, false)) { + else if (not storage_.CAS().BlobPath(x, false)) { auto* d = response->add_missing_blob_digests(); d->CopyFrom(x); } @@ -120,7 +119,7 @@ auto CASServiceImpl::BatchUpdateBlobs( ::grpc::ServerContext* /*context*/, const ::bazel_re::BatchUpdateBlobsRequest* request, ::bazel_re::BatchUpdateBlobsResponse* response) -> ::grpc::Status { - auto lock = GarbageCollector::SharedLock(StorageConfig::Instance()); + auto lock = GarbageCollector::SharedLock(storage_config_); if (!lock) { auto str = fmt::format("BatchUpdateBlobs: could not acquire SharedLock"); @@ -143,13 +142,13 @@ auto CASServiceImpl::BatchUpdateBlobs( // In native mode: for trees, check whether the tree invariant holds // before storing the actual tree object. if (auto err = CASUtils::EnsureTreeInvariant( - x.digest(), x.data(), *storage_)) { + x.digest(), x.data(), storage_)) { auto str = fmt::format("BatchUpdateBlobs: {}", *err); logger_.Emit(LogLevel::Error, "{}", str); return ::grpc::Status{grpc::StatusCode::FAILED_PRECONDITION, str}; } - auto const& dgst = storage_->CAS().StoreTree(x.data()); + auto const& dgst = storage_.CAS().StoreTree(x.data()); if (!dgst) { auto const& str = fmt::format( "BatchUpdateBlobs: could not upload tree {}", hash); @@ -163,7 +162,7 @@ auto CASServiceImpl::BatchUpdateBlobs( } } else { - auto const& dgst = storage_->CAS().StoreBlob(x.data(), false); + auto const& dgst = storage_.CAS().StoreBlob(x.data(), false); if (!dgst) { auto const& str = fmt::format( "BatchUpdateBlobs: could not upload blob {}", hash); @@ -184,7 +183,7 @@ auto CASServiceImpl::BatchReadBlobs( ::grpc::ServerContext* /*context*/, const ::bazel_re::BatchReadBlobsRequest* request, ::bazel_re::BatchReadBlobsResponse* response) -> ::grpc::Status { - auto lock = GarbageCollector::SharedLock(StorageConfig::Instance()); + auto lock = GarbageCollector::SharedLock(storage_config_); if (!lock) { auto str = fmt::format("BatchReadBlobs: Could not acquire SharedLock"); logger_.Emit(LogLevel::Error, "{}", str); @@ -195,10 +194,10 @@ auto CASServiceImpl::BatchReadBlobs( r->mutable_digest()->CopyFrom(digest); std::optional<std::filesystem::path> path; if (NativeSupport::IsTree(digest.hash())) { - path = storage_->CAS().TreePath(digest); + path = storage_.CAS().TreePath(digest); } else { - path = storage_->CAS().BlobPath(digest, false); + path = storage_.CAS().BlobPath(digest, false); } if (!path) { google::rpc::Status status; @@ -266,7 +265,7 @@ auto CASServiceImpl::SplitBlob(::grpc::ServerContext* /*context*/, } // Acquire garbage collection lock. - auto lock = GarbageCollector::SharedLock(StorageConfig::Instance()); + auto lock = GarbageCollector::SharedLock(storage_config_); if (not lock) { auto str = fmt::format("SplitBlob: could not acquire garbage collection lock"); @@ -275,11 +274,11 @@ auto CASServiceImpl::SplitBlob(::grpc::ServerContext* /*context*/, } // Split blob into chunks. - auto split_result = - chunking_algorithm == ::bazel_re::ChunkingAlgorithm_Value:: - ChunkingAlgorithm_Value_IDENTITY - ? CASUtils::SplitBlobIdentity(blob_digest, *storage_) - : CASUtils::SplitBlobFastCDC(blob_digest, *storage_); + auto split_result = chunking_algorithm == + ::bazel_re::ChunkingAlgorithm_Value:: + ChunkingAlgorithm_Value_IDENTITY + ? CASUtils::SplitBlobIdentity(blob_digest, storage_) + : CASUtils::SplitBlobFastCDC(blob_digest, storage_); if (not split_result) { auto const& status = split_result.error(); @@ -332,7 +331,7 @@ auto CASServiceImpl::SpliceBlob(::grpc::ServerContext* /*context*/, request->chunk_digests().size()); // Acquire garbage collection lock. - auto lock = GarbageCollector::SharedLock(StorageConfig::Instance()); + auto lock = GarbageCollector::SharedLock(storage_config_); if (not lock) { auto str = fmt::format( "SpliceBlob: could not acquire garbage collection lock"); @@ -346,7 +345,7 @@ auto CASServiceImpl::SpliceBlob(::grpc::ServerContext* /*context*/, request->chunk_digests().cend(), std::back_inserter(chunk_digests)); auto splice_result = - CASUtils::SpliceBlob(blob_digest, chunk_digests, *storage_); + CASUtils::SpliceBlob(blob_digest, chunk_digests, storage_); if (not splice_result) { auto const& status = splice_result.error(); auto str = fmt::format("SpliceBlob: {}", status.error_message()); diff --git a/src/buildtool/execution_api/execution_service/cas_server.hpp b/src/buildtool/execution_api/execution_service/cas_server.hpp index 4a6b6092..5ad9e799 100644 --- a/src/buildtool/execution_api/execution_service/cas_server.hpp +++ b/src/buildtool/execution_api/execution_service/cas_server.hpp @@ -22,11 +22,17 @@ #include "gsl/gsl" #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/logging/logger.hpp" +#include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/storage.hpp" class CASServiceImpl final : public bazel_re::ContentAddressableStorage::Service { public: + explicit CASServiceImpl( + gsl::not_null<StorageConfig const*> const& storage_config, + gsl::not_null<Storage const*> const& storage) noexcept + : storage_config_{*storage_config}, storage_{*storage} {} + // Determine if blobs are present in the CAS. // // Clients can use this API before uploading blobs to determine which ones @@ -215,7 +221,8 @@ class CASServiceImpl final bazel_re::Digest const& computed) const noexcept -> std::optional<std::string>; - gsl::not_null<Storage const*> storage_ = &Storage::Instance(); + StorageConfig const& storage_config_; + Storage const& storage_; Logger logger_{"execution-service"}; }; #endif diff --git a/src/buildtool/execution_api/execution_service/execution_server.cpp b/src/buildtool/execution_api/execution_service/execution_server.cpp index ef00677e..62deaeea 100644 --- a/src/buildtool/execution_api/execution_service/execution_server.cpp +++ b/src/buildtool/execution_api/execution_service/execution_server.cpp @@ -25,7 +25,6 @@ #include "src/buildtool/execution_api/execution_service/operation_cache.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/logging/log_level.hpp" -#include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/garbage_collector.hpp" #include "src/utils/cpp/verify_hash.hpp" @@ -46,7 +45,7 @@ auto ExecutionServiceImpl::GetAction(::bazel_re::ExecuteRequest const* request) logger_.Emit(LogLevel::Error, "{}", *error_msg); return {std::nullopt, *error_msg}; } - auto path = storage_->CAS().BlobPath(request->action_digest(), false); + auto path = storage_.CAS().BlobPath(request->action_digest(), false); if (!path) { auto str = fmt::format("could not retrieve blob {} from cas", request->action_digest().hash()); @@ -69,8 +68,8 @@ auto ExecutionServiceImpl::GetAction(::bazel_re::ExecuteRequest const* request) return {std::nullopt, *error_msg}; } path = Compatibility::IsCompatible() - ? storage_->CAS().BlobPath(action.input_root_digest(), false) - : storage_->CAS().TreePath(action.input_root_digest()); + ? storage_.CAS().BlobPath(action.input_root_digest(), false) + : storage_.CAS().TreePath(action.input_root_digest()); if (!path) { auto str = fmt::format("could not retrieve input root {} from cas", @@ -88,7 +87,7 @@ auto ExecutionServiceImpl::GetCommand(::bazel_re::Action const& action) logger_.Emit(LogLevel::Error, "{}", *error_msg); return {std::nullopt, *error_msg}; } - auto path = storage_->CAS().BlobPath(action.command_digest(), false); + auto path = storage_.CAS().BlobPath(action.command_digest(), false); if (!path) { auto str = fmt::format("could not retrieve blob {} from cas", action.command_digest().hash()); @@ -355,7 +354,7 @@ auto ExecutionServiceImpl::AddResult( IExecutionResponse::Ptr const& i_execution_response, std::string const& action_hash) const noexcept -> std::optional<std::string> { - if (not AddOutputPaths(response, i_execution_response, *storage_)) { + if (not AddOutputPaths(response, i_execution_response, storage_)) { auto str = fmt::format("Error in creating output paths of action {}", action_hash); logger_.Emit(LogLevel::Error, "{}", str); @@ -364,8 +363,8 @@ auto ExecutionServiceImpl::AddResult( auto* result = response->mutable_result(); result->set_exit_code(i_execution_response->ExitCode()); if (i_execution_response->HasStdErr()) { - auto dgst = storage_->CAS().StoreBlob(i_execution_response->StdErr(), - /*is_executable=*/false); + auto dgst = storage_.CAS().StoreBlob(i_execution_response->StdErr(), + /*is_executable=*/false); if (!dgst) { auto str = fmt::format("Could not store stderr of action {}", action_hash); @@ -375,8 +374,8 @@ auto ExecutionServiceImpl::AddResult( result->mutable_stderr_digest()->CopyFrom(*dgst); } if (i_execution_response->HasStdOut()) { - auto dgst = storage_->CAS().StoreBlob(i_execution_response->StdOut(), - /*is_executable=*/false); + auto dgst = storage_.CAS().StoreBlob(i_execution_response->StdOut(), + /*is_executable=*/false); if (!dgst) { auto str = fmt::format("Could not store stdout of action {}", action_hash); @@ -418,9 +417,9 @@ auto ExecutionServiceImpl::StoreActionResult( ::bazel_re::ExecuteResponse const& execute_response, ::bazel_re::Action const& action) const noexcept -> std::optional<std::string> { - if (i_execution_response->ExitCode() == 0 && !action.do_not_cache() && - !storage_->ActionCache().StoreResult(request->action_digest(), - execute_response.result())) { + if (i_execution_response->ExitCode() == 0 and not action.do_not_cache() and + not storage_.ActionCache().StoreResult(request->action_digest(), + execute_response.result())) { auto str = fmt::format("Could not store action result for action {}", request->action_digest().hash()); logger_.Emit(LogLevel::Error, "{}", str); @@ -447,7 +446,7 @@ auto ExecutionServiceImpl::Execute( const ::bazel_re::ExecuteRequest* request, ::grpc::ServerWriter<::google::longrunning::Operation>* writer) -> ::grpc::Status { - auto lock = GarbageCollector::SharedLock(StorageConfig::Instance()); + auto lock = GarbageCollector::SharedLock(storage_config_); if (!lock) { auto str = fmt::format("Could not acquire SharedLock"); logger_.Emit(LogLevel::Error, str); diff --git a/src/buildtool/execution_api/execution_service/execution_server.hpp b/src/buildtool/execution_api/execution_service/execution_server.hpp index 98223938..cc72a1e3 100644 --- a/src/buildtool/execution_api/execution_service/execution_server.hpp +++ b/src/buildtool/execution_api/execution_service/execution_server.hpp @@ -20,13 +20,19 @@ #include "src/buildtool/common/bazel_types.hpp" #include "src/buildtool/execution_api/common/execution_api.hpp" #include "src/buildtool/logging/logger.hpp" +#include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/storage.hpp" class ExecutionServiceImpl final : public bazel_re::Execution::Service { public: explicit ExecutionServiceImpl( + gsl::not_null<StorageConfig const*> const& storage_config, + gsl::not_null<Storage const*> const& storage, gsl::not_null<IExecutionApi const*> const& local_api) noexcept - : api_{*local_api} {} + : storage_config_{*storage_config}, + storage_{*storage}, + api_{*local_api} {} + // Execute an action remotely. // // In order to execute an action, the client must first upload all of the @@ -110,7 +116,8 @@ class ExecutionServiceImpl final : public bazel_re::Execution::Service { -> ::grpc::Status override; private: - gsl::not_null<Storage const*> storage_ = &Storage::Instance(); + StorageConfig const& storage_config_; + Storage const& storage_; IExecutionApi const& api_; Logger logger_{"execution-service"}; diff --git a/src/buildtool/execution_api/execution_service/server_implementation.cpp b/src/buildtool/execution_api/execution_service/server_implementation.cpp index 676bd0a7..42cb6242 100644 --- a/src/buildtool/execution_api/execution_service/server_implementation.cpp +++ b/src/buildtool/execution_api/execution_service/server_implementation.cpp @@ -53,11 +53,13 @@ auto TryWrite(std::string const& file, T const& content) noexcept -> bool { } } // namespace -auto ServerImpl::Run(ApiBundle const& apis) -> bool { - ExecutionServiceImpl es{&*apis.local}; - ActionCacheServiceImpl ac{}; - CASServiceImpl cas{}; - BytestreamServiceImpl b{}; +auto ServerImpl::Run(StorageConfig const& storage_config, + Storage const& storage, + ApiBundle const& apis) -> bool { + ExecutionServiceImpl es{&storage_config, &storage, &*apis.local}; + ActionCacheServiceImpl ac{&storage_config, &storage}; + CASServiceImpl cas{&storage_config, &storage}; + BytestreamServiceImpl b{&storage_config, &storage}; CapabilitiesServiceImpl cap{}; OperarationsServiceImpl op{}; diff --git a/src/buildtool/execution_api/execution_service/server_implementation.hpp b/src/buildtool/execution_api/execution_service/server_implementation.hpp index 7df517ad..ecddb8bc 100644 --- a/src/buildtool/execution_api/execution_service/server_implementation.hpp +++ b/src/buildtool/execution_api/execution_service/server_implementation.hpp @@ -19,6 +19,8 @@ #include <string> #include "src/buildtool/execution_api/common/api_bundle.hpp" +#include "src/buildtool/storage/config.hpp" +#include "src/buildtool/storage/storage.hpp" class ServerImpl { public: @@ -47,7 +49,9 @@ class ServerImpl { ServerImpl(ServerImpl&&) noexcept = delete; auto operator=(ServerImpl&&) noexcept -> ServerImpl& = delete; - auto Run(ApiBundle const& apis) -> bool; + auto Run(StorageConfig const& storage_config, + Storage const& storage, + ApiBundle const& apis) -> bool; ~ServerImpl() = default; private: diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp index 39806c68..530244f2 100644 --- a/src/buildtool/main/main.cpp +++ b/src/buildtool/main/main.cpp @@ -797,7 +797,9 @@ auto main(int argc, char* argv[]) -> int { ApiBundle const exec_apis{/*repo_config=*/nullptr, &*auth_config, RemoteExecutionConfig::RemoteAddress()}; - if (!ServerImpl::Instance().Run(exec_apis)) { + if (not ServerImpl::Instance().Run(StorageConfig::Instance(), + Storage::Instance(), + exec_apis)) { return kExitFailure; } return kExitSuccess; diff --git a/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp b/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp index a6754c74..c71953d9 100644 --- a/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp +++ b/src/buildtool/serve_api/serve_service/serve_server_implementation.cpp @@ -123,10 +123,11 @@ auto ServeServerImpl::Run(RemoteServeConfig const& serve_config, // the user has not given any remote-execution endpoint // so we start a "just-execute instance" on the same process - [[maybe_unused]] ExecutionServiceImpl es{&*apis.local}; - [[maybe_unused]] ActionCacheServiceImpl ac{}; - [[maybe_unused]] CASServiceImpl cas{}; - [[maybe_unused]] BytestreamServiceImpl b{}; + [[maybe_unused]] ExecutionServiceImpl es{ + &storage_config, &storage, &*apis.local}; + [[maybe_unused]] ActionCacheServiceImpl ac{&storage_config, &storage}; + [[maybe_unused]] CASServiceImpl cas{&storage_config, &storage}; + [[maybe_unused]] BytestreamServiceImpl b{&storage_config, &storage}; [[maybe_unused]] CapabilitiesServiceImpl cap{}; [[maybe_unused]] OperarationsServiceImpl op{}; if (with_execute) { diff --git a/test/buildtool/execution_api/execution_service/TARGETS b/test/buildtool/execution_api/execution_service/TARGETS index 5fc60fa5..c14db85c 100644 --- a/test/buildtool/execution_api/execution_service/TARGETS +++ b/test/buildtool/execution_api/execution_service/TARGETS @@ -14,6 +14,8 @@ , ["@", "src", "src/buildtool/file_system", "git_repo"] , ["@", "src", "src/buildtool/file_system", "object_type"] , ["@", "src", "src/buildtool/common", "common"] + , ["@", "src", "src/buildtool/storage", "config"] + , ["@", "src", "src/buildtool/storage", "storage"] , ["@", "gsl", "", "gsl"] ] , "stage": ["test", "buildtool", "execution_api", "execution_service"] diff --git a/test/buildtool/execution_api/execution_service/cas_server.test.cpp b/test/buildtool/execution_api/execution_service/cas_server.test.cpp index 1cdb71f8..70a674ca 100644 --- a/test/buildtool/execution_api/execution_service/cas_server.test.cpp +++ b/test/buildtool/execution_api/execution_service/cas_server.test.cpp @@ -20,6 +20,8 @@ #include "src/buildtool/execution_api/execution_service/cas_server.hpp" #include "src/buildtool/file_system/git_repo.hpp" #include "src/buildtool/file_system/object_type.hpp" +#include "src/buildtool/storage/config.hpp" +#include "src/buildtool/storage/storage.hpp" #include "test/utils/hermeticity/local.hpp" namespace { @@ -42,7 +44,8 @@ namespace { TEST_CASE_METHOD(HermeticLocalTestFixture, "CAS Service: upload incomplete tree", "[execution_service]") { - auto cas_server = CASServiceImpl{}; + auto cas_server = + CASServiceImpl{&StorageConfig::Instance(), &Storage::Instance()}; auto instance_name = std::string{"remote-execution"}; // Create an empty tree. |