-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support empty digests in stores (#507)
remote_execution.proto specification allows for uploading and fetching of empty digests regardless if they have been uploaded before a fetch. Expectation is the requests should always respond successfully. This can be an optimized path in cases but violates expectations in native link underlying storage consistencies.
- Loading branch information
1 parent
5a6b182
commit 41a85fb
Showing
12 changed files
with
466 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2023 The Native Link Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use nativelink_util::common::DigestInfo; | ||
|
||
const ZERO_BYTE_DIGESTS: [DigestInfo; 2] = [ | ||
// Sha256 hash of zero bytes. | ||
DigestInfo::new( | ||
[ | ||
0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, | ||
0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55, | ||
], | ||
0, | ||
), | ||
// Blake3 hash of zero bytes. | ||
DigestInfo::new( | ||
[ | ||
0xaf, 0x13, 0x49, 0xb9, 0xf5, 0xf9, 0xa1, 0xa6, 0xa0, 0x40, 0x4d, 0xea, 0x36, 0xdc, 0xc9, 0x49, 0x9b, 0xcb, | ||
0x25, 0xc9, 0xad, 0xc1, 0x12, 0xb7, 0xcc, 0x9a, 0x93, 0xca, 0xe4, 0x1f, 0x32, 0x62, | ||
], | ||
0, | ||
), | ||
]; | ||
|
||
#[inline] | ||
pub fn is_zero_digest(digest: &DigestInfo) -> bool { | ||
digest.size_bytes == 0 && ZERO_BYTE_DIGESTS.contains(digest) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2023 The Native Link Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#[cfg(test)] | ||
mod cas_utils_tests { | ||
use blake3::Hasher as Blake3; | ||
use nativelink_store::cas_utils::is_zero_digest; | ||
use nativelink_util::common::DigestInfo; | ||
use sha2::{Digest, Sha256}; | ||
|
||
#[test] | ||
fn sha256_is_zero_digest() { | ||
let digest = DigestInfo { | ||
packed_hash: Sha256::new().finalize().into(), | ||
size_bytes: 0, | ||
}; | ||
assert_eq!(is_zero_digest(&digest), true); | ||
} | ||
|
||
#[test] | ||
fn sha256_is_non_zero_digest() { | ||
let mut hasher = Sha256::new(); | ||
hasher.update(b"a"); | ||
let digest = DigestInfo { | ||
packed_hash: hasher.finalize().into(), | ||
size_bytes: 1, | ||
}; | ||
assert_eq!(is_zero_digest(&digest), false); | ||
} | ||
|
||
#[test] | ||
fn blake_is_zero_digest() { | ||
let digest = DigestInfo { | ||
packed_hash: Blake3::new().finalize().into(), | ||
size_bytes: 0, | ||
}; | ||
assert_eq!(is_zero_digest(&digest), true); | ||
} | ||
|
||
#[test] | ||
fn blake_is_non_zero_digest() { | ||
let mut hasher = Blake3::new(); | ||
hasher.update(b"a"); | ||
let digest = DigestInfo { | ||
packed_hash: hasher.finalize().into(), | ||
size_bytes: 1, | ||
}; | ||
assert_eq!(is_zero_digest(&digest), false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.