Skip to content

[llvm/CAS] UnifiedOnDiskCache::getStorageSize() should include the size of the chained DB #8050

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

Merged
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
3 changes: 3 additions & 0 deletions llvm/include/llvm/CAS/UnifiedOnDiskCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ class UnifiedOnDiskCache {
Expected<std::optional<ObjectID>>
faultInFromUpstreamKV(ArrayRef<uint8_t> Key);

/// \returns the storage size of the primary directory.
uint64_t getPrimaryStorageSize() const;

std::string RootPath;
std::atomic<uint64_t> SizeLimit;

Expand Down
11 changes: 10 additions & 1 deletion llvm/lib/CAS/UnifiedOnDiskCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ void UnifiedOnDiskCache::setSizeLimit(std::optional<uint64_t> SizeLimit) {
}

uint64_t UnifiedOnDiskCache::getStorageSize() const {
uint64_t TotalSize = getPrimaryStorageSize();
if (UpstreamGraphDB)
TotalSize += UpstreamGraphDB->getStorageSize();
if (UpstreamKVDB)
TotalSize += UpstreamKVDB->getStorageSize();
return TotalSize;
}

uint64_t UnifiedOnDiskCache::getPrimaryStorageSize() const {
return PrimaryGraphDB->getStorageSize() + PrimaryKVDB->getStorageSize();
}

Expand All @@ -268,7 +277,7 @@ bool UnifiedOnDiskCache::hasExceededSizeLimit() const {
// the primary has reached its own limit. Essentially in such situation we
// prefer reclaiming the storage later in order to have more consistent cache
// hits behavior.
return (CurSizeLimit / 2) < getStorageSize();
return (CurSizeLimit / 2) < getPrimaryStorageSize();
}

Error UnifiedOnDiskCache::close(bool CheckSizeLimit) {
Expand Down
1 change: 1 addition & 0 deletions llvm/unittests/CAS/UnifiedOnDiskCacheTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ TEST(UnifiedOnDiskCacheTest, Basic) {
while (!UniDB->hasExceededSizeLimit()) {
storeBigObject(Index++);
}
PrevStoreSize = UniDB->getStorageSize();
ASSERT_THAT_ERROR(UniDB->close(), Succeeded());
EXPECT_TRUE(UniDB->needsGarbaseCollection());

Expand Down