Skip to content

Commit d9a56c4

Browse files
CAS validation improvements (#10966)
* [CAS] Validate upstream CAS storage When asked to validate the CAS, also validate the upstream CAS if present. The entire upstream CAS is available as backup storage of the currently active CAS. If the upstream CAS is corrupted, it can propagate the error into downstream error, thus when upstream CAS is invalid, the entire UnifiedCAS should be invalid. * [CAS] Do not check if action cache value exists in the object store Fix a false positive/crash when validating action cache from unified data base by stop checking the cached value exists in the object store. First of all, there is a bug that the check is always done against primary object store, where the object can be missing. It is also possible that the CAS is in a state where the cache keys are fault in, but not the objects the cache pointed to. There is no good way to enforce it, thus the check is too strict. rdar://155231696 (cherry picked from commit 09bbceb)
1 parent 8835b75 commit d9a56c4

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

llvm/include/llvm/CAS/UnifiedOnDiskCache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ class UnifiedOnDiskCache {
155155

156156
Error validateActionCache();
157157

158+
OnDiskGraphDB *getUpstreamGraphDB() const { return UpstreamGraphDB; }
159+
158160
private:
159161
UnifiedOnDiskCache();
160162

llvm/lib/CAS/OnDiskCAS.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,19 @@ class OnDiskCAS : public BuiltinCAS {
9090

9191
void OnDiskCAS::print(raw_ostream &OS) const { DB->print(OS); }
9292
Error OnDiskCAS::validate(bool CheckHash) const {
93-
return DB->validate(CheckHash, [](ArrayRef<ArrayRef<uint8_t>> Refs,
94-
ArrayRef<char> Data,
95-
SmallVectorImpl<uint8_t> &Result) {
93+
auto Hasher = [](ArrayRef<ArrayRef<uint8_t>> Refs, ArrayRef<char> Data,
94+
SmallVectorImpl<uint8_t> &Result) {
9695
auto Hash = BuiltinObjectHasher<llvm::cas::builtin::HasherT>::hashObject(
9796
Refs, Data);
9897
Result.assign(Hash.begin(), Hash.end());
99-
});
98+
};
99+
100+
if (auto E = DB->validate(CheckHash, Hasher))
101+
return E;
102+
if (UniDB && UniDB->getUpstreamGraphDB())
103+
return UniDB->getUpstreamGraphDB()->validate(CheckHash, Hasher);
104+
105+
return Error::success();
100106
}
101107

102108
CASID OnDiskCAS::getID(ObjectRef Ref) const {

llvm/lib/CAS/UnifiedOnDiskCache.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ Error UnifiedOnDiskCache::validateActionCache() {
170170
};
171171
if (ID.getOpaqueData() == 0)
172172
return formatError("zero is not a valid ref");
173-
if (!PrimaryGraphDB->containsObject(ID))
174-
return formatError("cas does not contain ref");
175173
return Error::success();
176174
};
177175
if (Error E = PrimaryKVDB->validate(ValidateRef))

0 commit comments

Comments
 (0)