summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/execution_api/execution_service/cas_server.cpp22
-rw-r--r--src/buildtool/execution_api/execution_service/execution_server.cpp25
-rw-r--r--src/buildtool/execution_api/execution_service/server_implementation.cpp12
3 files changed, 31 insertions, 28 deletions
diff --git a/src/buildtool/execution_api/execution_service/cas_server.cpp b/src/buildtool/execution_api/execution_service/cas_server.cpp
index 5394b985..87f2e92f 100644
--- a/src/buildtool/execution_api/execution_service/cas_server.cpp
+++ b/src/buildtool/execution_api/execution_service/cas_server.cpp
@@ -49,12 +49,13 @@ namespace {
}
[[nodiscard]] auto CheckDigestConsistency(
+ HashFunction::Type hash_type,
ArtifactDigest const& ref,
ArtifactDigest const& computed) noexcept -> std::optional<std::string> {
bool valid = ref.hash() == computed.hash();
if (valid) {
bool const check_sizes =
- ProtocolTraits::Instance().IsCompatible() or ref.size() != 0;
+ not ProtocolTraits::IsNative(hash_type) or ref.size() != 0;
if (check_sizes) {
valid = ref.size() == computed.size();
}
@@ -121,11 +122,12 @@ auto CASServiceImpl::BatchUpdateBlobs(
logger_.Emit(LogLevel::Error, "{}", str);
return grpc::Status{grpc::StatusCode::INTERNAL, str};
}
+ auto const hash_type = storage_config_.hash_function.GetType();
for (auto const& x : request->requests()) {
auto const& hash = x.digest().hash();
logger_.Emit(LogLevel::Trace, "BatchUpdateBlobs: {}", hash);
- auto const digest = ArtifactDigestFactory::FromBazel(
- storage_config_.hash_function.GetType(), x.digest());
+ auto const digest =
+ ArtifactDigestFactory::FromBazel(hash_type, x.digest());
if (not digest) {
auto const str =
fmt::format("BatchUpdateBlobs: unsupported digest {}", hash);
@@ -163,7 +165,8 @@ auto CASServiceImpl::BatchUpdateBlobs(
return ::grpc::Status{grpc::StatusCode::INTERNAL, str};
}
- if (auto err = CheckDigestConsistency(*digest, *cas_digest)) {
+ if (auto err =
+ CheckDigestConsistency(hash_type, *digest, *cas_digest)) {
auto const str =
fmt::format("BatchUpdateBlobs: {}", *std::move(err));
logger_.Emit(LogLevel::Error, "{}", str);
@@ -320,8 +323,9 @@ auto CASServiceImpl::SpliceBlob(::grpc::ServerContext* /*context*/,
return ::grpc::Status{grpc::StatusCode::INVALID_ARGUMENT, str};
}
- auto const blob_digest = ArtifactDigestFactory::FromBazel(
- storage_config_.hash_function.GetType(), request->blob_digest());
+ auto const hash_type = storage_config_.hash_function.GetType();
+ auto const blob_digest =
+ ArtifactDigestFactory::FromBazel(hash_type, request->blob_digest());
if (not blob_digest) {
auto const str = fmt::format("SpliceBlob: unsupported digest {}",
request->blob_digest().hash());
@@ -337,8 +341,7 @@ auto CASServiceImpl::SpliceBlob(::grpc::ServerContext* /*context*/,
auto chunk_digests = std::vector<ArtifactDigest>{};
chunk_digests.reserve(request->chunk_digests().size());
for (auto const& x : request->chunk_digests()) {
- auto chunk = ArtifactDigestFactory::FromBazel(
- storage_config_.hash_function.GetType(), x);
+ auto chunk = ArtifactDigestFactory::FromBazel(hash_type, x);
if (not chunk) {
auto const str =
fmt::format("SpliceBlob: unsupported digest {}", x.hash());
@@ -366,7 +369,8 @@ auto CASServiceImpl::SpliceBlob(::grpc::ServerContext* /*context*/,
logger_.Emit(LogLevel::Error, "{}", str);
return ::grpc::Status{status.error_code(), str};
}
- if (auto err = CheckDigestConsistency(*blob_digest, *splice_result)) {
+ if (auto err =
+ CheckDigestConsistency(hash_type, *blob_digest, *splice_result)) {
auto const str = fmt::format("SpliceBlob: {}", *std::move(err));
logger_.Emit(LogLevel::Error, "{}", str);
return ::grpc::Status{grpc::StatusCode::INVALID_ARGUMENT, str};
diff --git a/src/buildtool/execution_api/execution_service/execution_server.cpp b/src/buildtool/execution_api/execution_service/execution_server.cpp
index 6e3c77ab..2a1e8bca 100644
--- a/src/buildtool/execution_api/execution_service/execution_server.cpp
+++ b/src/buildtool/execution_api/execution_service/execution_server.cpp
@@ -276,7 +276,12 @@ namespace {
::bazel_re::OutputDirectory out_dir{};
*(out_dir.mutable_path()) = std::move(path);
- if (ProtocolTraits::Instance().IsCompatible()) {
+ if (ProtocolTraits::IsNative(storage.GetHashFunction().GetType())) {
+ // In native mode: Set the directory digest directly.
+ (*out_dir.mutable_tree_digest()) =
+ ArtifactDigestFactory::ToBazel(digest);
+ }
+ else {
// In compatible mode: Create a tree digest from directory
// digest on the fly and set tree digest.
LocalCasReader reader(&storage.CAS());
@@ -299,11 +304,6 @@ namespace {
(*out_dir.mutable_tree_digest()) =
ArtifactDigestFactory::ToBazel(*cas_digest);
}
- else {
- // In native mode: Set the directory digest directly.
- (*out_dir.mutable_tree_digest()) =
- ArtifactDigestFactory::ToBazel(digest);
- }
return std::move(out_dir);
}
@@ -404,16 +404,17 @@ namespace {
action_digest.hash())};
}
- auto const input_root_digest = ArtifactDigestFactory::FromBazel(
- storage.GetHashFunction().GetType(), action.input_root_digest());
+ auto const hash_type = storage.GetHashFunction().GetType();
+ auto const input_root_digest =
+ ArtifactDigestFactory::FromBazel(hash_type, action.input_root_digest());
if (not input_root_digest) {
return unexpected{input_root_digest.error()};
}
auto const input_root_path =
- ProtocolTraits::Instance().IsCompatible()
- ? storage.CAS().BlobPath(*input_root_digest,
- /*is_executable=*/false)
- : storage.CAS().TreePath(*input_root_digest);
+ ProtocolTraits::IsNative(hash_type)
+ ? storage.CAS().TreePath(*input_root_digest)
+ : storage.CAS().BlobPath(*input_root_digest,
+ /*is_executable=*/false);
if (not input_root_path) {
return unexpected{
diff --git a/src/buildtool/execution_api/execution_service/server_implementation.cpp b/src/buildtool/execution_api/execution_service/server_implementation.cpp
index 67633b69..0b921d6b 100644
--- a/src/buildtool/execution_api/execution_service/server_implementation.cpp
+++ b/src/buildtool/execution_api/execution_service/server_implementation.cpp
@@ -142,13 +142,11 @@ auto ServerImpl::Run(gsl::not_null<LocalContext const*> const& local_context,
}
}
- auto const& info_str = nlohmann::to_string(info);
- Logger::Log(
- LogLevel::Info,
- fmt::format(
- "{}execution service started: {}",
- ProtocolTraits::Instance().IsCompatible() ? "compatible " : "",
- info_str));
+ auto const info_str = nlohmann::to_string(info);
+ Logger::Log(LogLevel::Info,
+ "{}execution service started: {}",
+ ProtocolTraits::IsNative(hash_type) ? "" : "compatible ",
+ info_str);
if (not info_file_.empty()) {
if (not TryWrite(info_file_, info_str)) {