summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-09-11 17:30:45 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-09-13 14:41:00 +0200
commit6fcaec9c6106e10b1f3129cfe0e539a461a87767 (patch)
tree08c570655a4a75921916609536c9c84ce732a263
parent3dba6aebaa9a7a367190563adea07f0278868998 (diff)
downloadjustbuild-6fcaec9c6106e10b1f3129cfe0e539a461a87767.tar.gz
Pass HashFunction to BazelCasClient
...to determine whether splitting-splicing functionality is supported.
-rw-r--r--src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp33
-rw-r--r--src/buildtool/execution_api/remote/bazel/bazel_cas_client.hpp11
-rw-r--r--src/buildtool/execution_api/remote/bazel/bazel_network.cpp9
3 files changed, 34 insertions, 19 deletions
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp b/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp
index 3d08825e..1516ea0c 100644
--- a/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp
+++ b/src/buildtool/execution_api/remote/bazel/bazel_cas_client.cpp
@@ -28,7 +28,6 @@
#include "src/buildtool/common/remote/client_common.hpp"
#include "src/buildtool/common/remote/retry.hpp"
#include "src/buildtool/common/remote/retry_config.hpp"
-#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/execution_api/common/execution_common.hpp"
#include "src/buildtool/execution_api/common/message_limits.hpp"
#include "src/buildtool/file_system/object_type.hpp"
@@ -49,14 +48,12 @@ namespace {
// execution protocol. Then, the ordinary way to determine server capabilities
// can be employed by using the capabilities service.
[[nodiscard]] auto BlobSplitSupport(
+ HashFunction hash_function,
std::string const& instance_name,
std::unique_ptr<bazel_re::ContentAddressableStorage::Stub> const&
stub) noexcept -> bool {
// Create empty blob.
std::string empty_str{};
- HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible()
- ? HashFunction::Type::PlainSHA256
- : HashFunction::Type::GitSHA1};
auto const digest = BazelDigestFactory::HashDataAs<ObjectType::File>(
hash_function, empty_str);
@@ -87,6 +84,7 @@ namespace {
// Cached version of blob-split support request.
[[nodiscard]] auto BlobSplitSupportCached(
+ HashFunction hash_function,
std::string const& instance_name,
std::unique_ptr<bazel_re::ContentAddressableStorage::Stub> const& stub,
Logger const* logger) noexcept -> bool {
@@ -99,7 +97,7 @@ namespace {
return blob_split_support_map[instance_name];
}
}
- auto supported = ::BlobSplitSupport(instance_name, stub);
+ auto supported = ::BlobSplitSupport(hash_function, instance_name, stub);
logger->Emit(LogLevel::Debug,
"Blob split support for \"{}\": {}",
instance_name,
@@ -115,14 +113,12 @@ namespace {
// remote execution protocol. Then, the ordinary way to determine server
// capabilities can be employed by using the capabilities service.
[[nodiscard]] auto BlobSpliceSupport(
+ HashFunction hash_function,
std::string const& instance_name,
std::unique_ptr<bazel_re::ContentAddressableStorage::Stub> const&
stub) noexcept -> bool {
// Create empty blob.
std::string empty_str{};
- HashFunction const hash_function{ProtocolTraits::Instance().IsCompatible()
- ? HashFunction::Type::PlainSHA256
- : HashFunction::Type::GitSHA1};
auto const digest = BazelDigestFactory::HashDataAs<ObjectType::File>(
hash_function, empty_str);
@@ -154,6 +150,7 @@ namespace {
// Cached version of blob-splice support request.
[[nodiscard]] auto BlobSpliceSupportCached(
+ HashFunction hash_function,
std::string const& instance_name,
std::unique_ptr<bazel_re::ContentAddressableStorage::Stub> const& stub,
Logger const* logger) noexcept -> bool {
@@ -166,7 +163,7 @@ namespace {
return blob_splice_support_map[instance_name];
}
}
- auto supported = ::BlobSpliceSupport(instance_name, stub);
+ auto supported = ::BlobSpliceSupport(hash_function, instance_name, stub);
logger->Emit(LogLevel::Debug,
"Blob splice support for \"{}\": {}",
instance_name,
@@ -356,10 +353,12 @@ auto BazelCasClient::ReadSingleBlob(
return std::nullopt;
}
-auto BazelCasClient::SplitBlob(std::string const& instance_name,
+auto BazelCasClient::SplitBlob(HashFunction hash_function,
+ std::string const& instance_name,
bazel_re::Digest const& blob_digest)
const noexcept -> std::optional<std::vector<bazel_re::Digest>> {
- if (not BlobSplitSupportCached(instance_name, stub_, &logger_)) {
+ if (not BlobSplitSupportCached(
+ hash_function, instance_name, stub_, &logger_)) {
return std::nullopt;
}
bazel_re::SplitBlobRequest request{};
@@ -383,11 +382,13 @@ auto BazelCasClient::SplitBlob(std::string const& instance_name,
}
auto BazelCasClient::SpliceBlob(
+ HashFunction hash_function,
std::string const& instance_name,
bazel_re::Digest const& blob_digest,
std::vector<bazel_re::Digest> const& chunk_digests) const noexcept
-> std::optional<bazel_re::Digest> {
- if (not BlobSpliceSupportCached(instance_name, stub_, &logger_)) {
+ if (not BlobSpliceSupportCached(
+ hash_function, instance_name, stub_, &logger_)) {
return std::nullopt;
}
bazel_re::SpliceBlobRequest request{};
@@ -415,13 +416,17 @@ auto BazelCasClient::SpliceBlob(
}
auto BazelCasClient::BlobSplitSupport(
+ HashFunction hash_function,
std::string const& instance_name) const noexcept -> bool {
- return ::BlobSplitSupportCached(instance_name, stub_, &logger_);
+ return ::BlobSplitSupportCached(
+ hash_function, instance_name, stub_, &logger_);
}
auto BazelCasClient::BlobSpliceSupport(
+ HashFunction hash_function,
std::string const& instance_name) const noexcept -> bool {
- return ::BlobSpliceSupportCached(instance_name, stub_, &logger_);
+ return ::BlobSpliceSupportCached(
+ hash_function, instance_name, stub_, &logger_);
}
template <class T_ForwardIter>
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_cas_client.hpp b/src/buildtool/execution_api/remote/bazel/bazel_cas_client.hpp
index 225ae05d..8378dd70 100644
--- a/src/buildtool/execution_api/remote/bazel/bazel_cas_client.hpp
+++ b/src/buildtool/execution_api/remote/bazel/bazel_cas_client.hpp
@@ -29,6 +29,7 @@
#include "src/buildtool/common/bazel_types.hpp"
#include "src/buildtool/common/remote/port.hpp"
#include "src/buildtool/common/remote/retry_config.hpp"
+#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/execution_api/bazel_msg/bazel_blob_container.hpp"
#include "src/buildtool/execution_api/bazel_msg/bazel_common.hpp"
#include "src/buildtool/execution_api/remote/bazel/bytestream_client.hpp"
@@ -118,28 +119,36 @@ class BazelCasClient {
const noexcept -> std::optional<BazelBlob>;
/// @brief Split single blob into chunks
+ /// @param[in] hash_function Hash function to be used for creation of
+ /// an empty blob.
/// @param[in] instance_name Name of the CAS instance
/// @param[in] blob_digest Blob digest to be splitted
/// @return The chunk digests of the splitted blob
- [[nodiscard]] auto SplitBlob(std::string const& instance_name,
+ [[nodiscard]] auto SplitBlob(HashFunction hash_function,
+ std::string const& instance_name,
bazel_re::Digest const& blob_digest)
const noexcept -> std::optional<std::vector<bazel_re::Digest>>;
/// @brief Splice blob from chunks at the remote side
+ /// @param[in] hash_function Hash function to be used for creation of
+ /// an empty blob.
/// @param[in] instance_name Name of the CAS instance
/// @param[in] blob_digest Expected digest of the spliced blob
/// @param[in] chunk_digests The chunk digests of the splitted blob
/// @return Whether the splice call was successful
[[nodiscard]] auto SpliceBlob(
+ HashFunction hash_function,
std::string const& instance_name,
bazel_re::Digest const& blob_digest,
std::vector<bazel_re::Digest> const& chunk_digests) const noexcept
-> std::optional<bazel_re::Digest>;
[[nodiscard]] auto BlobSplitSupport(
+ HashFunction hash_function,
std::string const& instance_name) const noexcept -> bool;
[[nodiscard]] auto BlobSpliceSupport(
+ HashFunction hash_function,
std::string const& instance_name) const noexcept -> bool;
private:
diff --git a/src/buildtool/execution_api/remote/bazel/bazel_network.cpp b/src/buildtool/execution_api/remote/bazel/bazel_network.cpp
index 5fff6305..edf18249 100644
--- a/src/buildtool/execution_api/remote/bazel/bazel_network.cpp
+++ b/src/buildtool/execution_api/remote/bazel/bazel_network.cpp
@@ -54,22 +54,23 @@ auto BazelNetwork::IsAvailable(std::vector<bazel_re::Digest> const& digests)
auto BazelNetwork::SplitBlob(bazel_re::Digest const& blob_digest) const noexcept
-> std::optional<std::vector<bazel_re::Digest>> {
- return cas_->SplitBlob(instance_name_, blob_digest);
+ return cas_->SplitBlob(hash_function_, instance_name_, blob_digest);
}
auto BazelNetwork::SpliceBlob(
bazel_re::Digest const& blob_digest,
std::vector<bazel_re::Digest> const& chunk_digests) const noexcept
-> std::optional<bazel_re::Digest> {
- return cas_->SpliceBlob(instance_name_, blob_digest, chunk_digests);
+ return cas_->SpliceBlob(
+ hash_function_, instance_name_, blob_digest, chunk_digests);
}
auto BazelNetwork::BlobSplitSupport() const noexcept -> bool {
- return cas_->BlobSplitSupport(instance_name_);
+ return cas_->BlobSplitSupport(hash_function_, instance_name_);
}
auto BazelNetwork::BlobSpliceSupport() const noexcept -> bool {
- return cas_->BlobSpliceSupport(instance_name_);
+ return cas_->BlobSpliceSupport(hash_function_, instance_name_);
}
template <class T_Iter>