Skip to content

Commit 07b26e3

Browse files
authored
Merge pull request #8050 from akyrtzi/akyrtzi/pr/stable-cas-storage-size
[llvm/CAS] `UnifiedOnDiskCache::getStorageSize()` should include the size of the chained DB
2 parents b53c166 + e772c0a commit 07b26e3

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

llvm/include/llvm/CAS/UnifiedOnDiskCache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ class UnifiedOnDiskCache {
129129
Expected<std::optional<ObjectID>>
130130
faultInFromUpstreamKV(ArrayRef<uint8_t> Key);
131131

132+
/// \returns the storage size of the primary directory.
133+
uint64_t getPrimaryStorageSize() const;
134+
132135
std::string RootPath;
133136
std::atomic<uint64_t> SizeLimit;
134137

llvm/lib/CAS/UnifiedOnDiskCache.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,15 @@ void UnifiedOnDiskCache::setSizeLimit(std::optional<uint64_t> SizeLimit) {
251251
}
252252

253253
uint64_t UnifiedOnDiskCache::getStorageSize() const {
254+
uint64_t TotalSize = getPrimaryStorageSize();
255+
if (UpstreamGraphDB)
256+
TotalSize += UpstreamGraphDB->getStorageSize();
257+
if (UpstreamKVDB)
258+
TotalSize += UpstreamKVDB->getStorageSize();
259+
return TotalSize;
260+
}
261+
262+
uint64_t UnifiedOnDiskCache::getPrimaryStorageSize() const {
254263
return PrimaryGraphDB->getStorageSize() + PrimaryKVDB->getStorageSize();
255264
}
256265

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

274283
Error UnifiedOnDiskCache::close(bool CheckSizeLimit) {

llvm/unittests/CAS/UnifiedOnDiskCacheTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ TEST(UnifiedOnDiskCacheTest, Basic) {
151151
while (!UniDB->hasExceededSizeLimit()) {
152152
storeBigObject(Index++);
153153
}
154+
PrevStoreSize = UniDB->getStorageSize();
154155
ASSERT_THAT_ERROR(UniDB->close(), Succeeded());
155156
EXPECT_TRUE(UniDB->needsGarbaseCollection());
156157

0 commit comments

Comments
 (0)