Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use preferred digest hashing algorithm for action permission checker. #784

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use anyhow::Context;
use buck2_core::async_once_cell::AsyncOnceCell;
use buck2_core::execution_types::executor_config::RePlatformFields;
use buck2_core::execution_types::executor_config::RemoteExecutorUseCase;
use buck2_execute::digest_config::DigestConfig;
use buck2_execute::re::error::RemoteExecutionError;
use buck2_execute::re::manager::ManagedRemoteExecutionClient;
use dashmap::DashMap;
Expand Down Expand Up @@ -53,8 +54,9 @@ impl ActionCacheUploadPermissionChecker {
&self,
re_use_case: RemoteExecutorUseCase,
platform: &RePlatformFields,
digest_config: DigestConfig,
) -> anyhow::Result<Result<(), String>> {
let (action, action_result) = empty_action_result(platform)?;
let (action, action_result) = empty_action_result(platform, digest_config)?;

// This is CAS upload, if it fails, something is very broken.
self.re_client
Expand Down Expand Up @@ -107,11 +109,16 @@ impl ActionCacheUploadPermissionChecker {
&self,
re_use_case: RemoteExecutorUseCase,
platform: &RePlatformFields,
digest_config: DigestConfig,
) -> anyhow::Result<Result<(), String>> {
let cache_value = self.cache_value(re_use_case, platform);
cache_value
.has_permission_to_upload_to_cache
.get_or_try_init(self.do_has_permission_to_upload_to_cache(re_use_case, platform))
.get_or_try_init(self.do_has_permission_to_upload_to_cache(
re_use_case,
platform,
digest_config,
))
.await
.cloned()
.context("Upload for permission check")
Expand Down
11 changes: 7 additions & 4 deletions app/buck2_execute_impl/src/executors/caching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl CacheUploader {
}
}

if let Err(rejected) = self.check_upload_permission().await? {
if let Err(rejected) = self.check_upload_permission(info).await? {
return Ok(rejected);
}

Expand Down Expand Up @@ -227,7 +227,7 @@ impl CacheUploader {
DepFileReActionResultMissingError(remote_dep_file_key.clone()),
)?;

if let Err(rejected) = self.check_upload_permission().await? {
if let Err(rejected) = self.check_upload_permission(info).await? {
return Ok(rejected);
}
let remote_dep_file = dep_file_bundle
Expand Down Expand Up @@ -289,10 +289,13 @@ impl CacheUploader {
.await
}

async fn check_upload_permission(&self) -> anyhow::Result<Result<(), CacheUploadOutcome>> {
async fn check_upload_permission(
&self,
info: &CacheUploadInfo<'_>,
) -> anyhow::Result<Result<(), CacheUploadOutcome>> {
let outcome = if let Err(reason) = self
.cache_upload_permission_checker
.has_permission_to_upload_to_cache(self.re_use_case, &self.platform)
.has_permission_to_upload_to_cache(self.re_use_case, &self.platform, info.digest_config)
.await?
{
Err(CacheUploadOutcome::Rejected(
Expand Down
7 changes: 1 addition & 6 deletions app/buck2_execute_impl/src/executors/empty_action_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
* of this source tree.
*/

use buck2_common::cas_digest::DigestAlgorithm;
use buck2_core::execution_types::executor_config::RePlatformFields;
use buck2_execute::digest::CasDigestToReExt;
use buck2_execute::digest_config::DigestConfig;
use buck2_execute::execute::action_digest_and_blobs::ActionDigestAndBlobs;
use buck2_execute::execute::action_digest_and_blobs::ActionDigestAndBlobsBuilder;
use once_cell::sync::OnceCell;
use remote_execution as RE;
use remote_execution::TActionResult2;
use remote_execution::TExecutedActionMetadata;
Expand All @@ -23,11 +21,8 @@ use crate::executors::to_re_platform::RePlatformFieldsToRePlatform;
/// Create an empty action result for permission check.
pub(crate) fn empty_action_result(
platform: &RePlatformFields,
digest_config: DigestConfig,
) -> anyhow::Result<(ActionDigestAndBlobs, TActionResult2)> {
static DIGEST_CONFIG: OnceCell<DigestConfig> = OnceCell::new();
let digest_config = *DIGEST_CONFIG
.get_or_try_init(|| DigestConfig::leak_new(vec![DigestAlgorithm::Sha1], None))?;

let mut blobs = ActionDigestAndBlobsBuilder::new(digest_config);

let command = blobs.add_command(&RE::Command {
Expand Down