diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-10-21 12:51:08 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2024-10-25 13:00:43 +0200 |
commit | 6242ef6fff52116398913a40634a71292616c126 (patch) | |
tree | 56da133aa074278c71f9489fd637d2aa5c4d1800 /src/buildtool/serve_api/serve_service/source_tree.cpp | |
parent | 0675a0daf093442860d117afb060e5456e37c7e2 (diff) | |
download | justbuild-6242ef6fff52116398913a40634a71292616c126.tar.gz |
just-mr and SourceTree: Use new Git execution api instance
In just-mr: to instantiate the new Git api instance, both storage
configs, as well as the compatible storage, need to be passed to
the maps. While there, use more explicit naming schemes for the
storage and CAS instances used.
In serve: also acquire gc locks for the local storages when needed
to instantiate the new Git api, which now has access to the CAS.
In all these instances we also pass, as needed, the local api, which
currently still operates only in native mode. This makes no
difference currently, but will ensure less changes needed when the
future compatible-aware local api will be used instead.
Diffstat (limited to 'src/buildtool/serve_api/serve_service/source_tree.cpp')
-rw-r--r-- | src/buildtool/serve_api/serve_service/source_tree.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/buildtool/serve_api/serve_service/source_tree.cpp b/src/buildtool/serve_api/serve_service/source_tree.cpp index 3099de77..8bc06c39 100644 --- a/src/buildtool/serve_api/serve_service/source_tree.cpp +++ b/src/buildtool/serve_api/serve_service/source_tree.cpp @@ -26,7 +26,7 @@ #include "src/buildtool/common/artifact_digest_factory.hpp" #include "src/buildtool/common/protocol_traits.hpp" #include "src/buildtool/crypto/hash_function.hpp" -#include "src/buildtool/execution_api/git/git_api.hpp" +#include "src/buildtool/execution_api/serve/mr_git_api.hpp" #include "src/buildtool/file_system/file_system_manager.hpp" #include "src/buildtool/file_system/git_repo.hpp" #include "src/buildtool/logging/log_level.hpp" @@ -288,6 +288,23 @@ auto SourceTreeService::SyncGitEntryToCas( std::string const& object_hash, std::filesystem::path const& repo_path) const noexcept -> std::remove_cvref_t<decltype(TResponse::OK)> { + // get gc locks for the local storages + auto native_lock = + GarbageCollector::SharedLock(*native_context_->storage_config); + if (not native_lock) { + logger_->Emit(LogLevel::Error, "Could not acquire gc SharedLock"); + return TResponse::INTERNAL_ERROR; + } + std::optional<LockFile> compat_lock = std::nullopt; + if (compat_context_ != nullptr) { + compat_lock = + GarbageCollector::SharedLock(*compat_context_->storage_config); + if (not compat_lock) { + logger_->Emit(LogLevel::Error, "Could not acquire gc SharedLock"); + return TResponse::INTERNAL_ERROR; + } + } + auto const hash_type = native_context_->storage_config->hash_function.GetType(); if (IsTreeObject(kType) and not ProtocolTraits::IsTreeAllowed(hash_type)) { @@ -308,11 +325,17 @@ auto SourceTreeService::SyncGitEntryToCas( auto const digest = ArtifactDigestFactory::Create( hash_type, object_hash, 0, IsTreeObject(kType)); if (not digest) { - logger_->Emit(LogLevel::Error, "{}", digest.error()); + logger_->Emit(LogLevel::Error, "SyncGitEntryToCas: {}", digest.error()); return TResponse::INTERNAL_ERROR; } - auto git_api = GitApi{&repo}; + auto const is_compat = compat_context_ != nullptr; + auto git_api = + MRGitApi{&repo, + native_context_->storage_config, + is_compat ? &*compat_context_->storage_config : nullptr, + is_compat ? &*compat_context_->storage : nullptr, + is_compat ? &*apis_.local : nullptr}; if (not git_api.RetrieveToCas( {Artifact::ObjectInfo{.digest = *digest, .type = kType}}, *apis_.remote)) { |