Skip to content

Conversation

@cachemeifyoucan
Copy link
Collaborator

@cachemeifyoucan cachemeifyoucan commented Oct 29, 2024

Add a new abstraction layer UnifiedOnDiskCache that adds new functions
of disk space management and data validation that builds on top of
OnDiskGraphDB and OnDiskKeyValueDB.

Build upon UnifiedOnDiskCache, it is OnDiskCAS that implements
ObjectStore and ActionCache interface for LLVM tools to interact with
CAS storage.

Add OnDiskCAS abstraction, that implements ObjectStore and ActionCache
interface using OnDiskGraphDB and OnDiskKeyValueDB.

Reviewers: 

Pull Request: #114103
@cachemeifyoucan cachemeifyoucan changed the base branch from users/cachemeifyoucan/spr/main.cas-add-ondiskcas to main October 22, 2025 19:51
@cachemeifyoucan cachemeifyoucan force-pushed the users/cachemeifyoucan/spr/cas-add-ondiskcas branch from 94172a6 to 4b951ef Compare October 22, 2025 19:51
@cachemeifyoucan cachemeifyoucan changed the title [CAS] Add OnDiskCAS [CAS] Add UnifiedOnDiskCache and OnDiskCAS Oct 22, 2025
Created using spr 1.3.7
Created using spr 1.3.7
Error validate() const final;

private:
std::shared_ptr<ondisk::UnifiedOnDiskCache> UniDB;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing it, but why does this need to be a shared_ptr? I don't see obvious uses where we're really relying on the refcount here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just extending the lifetime of the wrapped UnifiedOnDiskCache to make sure it is not deleted when ActionCache is still in use.

Alternatively, we can leave this as a raw pointer and left the life-time management to user, but since this is not really a ref-count that is being updated often, this safe guard is pretty safe to keep.

Created using spr 1.3.7
Copy link
Collaborator

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate how well-documented the interface is!

Created using spr 1.3.7
@cachemeifyoucan cachemeifyoucan merged commit 6747ea0 into main Nov 3, 2025
10 checks passed
@cachemeifyoucan cachemeifyoucan deleted the users/cachemeifyoucan/spr/cas-add-ondiskcas branch November 3, 2025 17:50
@llvm-ci
Copy link
Collaborator

llvm-ci commented Nov 4, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-expensive-checks-win running on as-worker-93 while building llvm at step 7 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/14/builds/4601

Here is the relevant piece of the build log for the reference
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM-Unit :: CAS/./CASTests.exe/31/36' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:C:\a\llvm-clang-x86_64-expensive-checks-win\build\unittests\CAS\.\CASTests.exe-LLVM-Unit-14840-31-36.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=36 GTEST_SHARD_INDEX=31 C:\a\llvm-clang-x86_64-expensive-checks-win\build\unittests\CAS\.\CASTests.exe
--

Script:
--
C:\a\llvm-clang-x86_64-expensive-checks-win\build\unittests\CAS\.\CASTests.exe --gtest_filter=OnDiskCAS/CASTest.BlobsBigParallel/0
--
C:\a\llvm-clang-x86_64-expensive-checks-win\llvm-project\llvm\unittests\CAS\ObjectStoreTest.cpp(315): error: Value of: llvm::detail::TakeError(CAS->getProxy(*ID).moveInto(Node))
Expected: succeeded
  Actual: failed  ('C:\Users\Buildbot\AppData\Local\Temp\lit-tmp-myr7yuce\on-disk-cas-1cec22\leaf+0.13304.v1': no such file or directory)

C:\a\llvm-clang-x86_64-expensive-checks-win\llvm-project\llvm\unittests\CAS\ObjectStoreTest.cpp(315): error: Value of: llvm::detail::TakeError(CAS->getProxy(*ID).moveInto(Node))
Expected: succeeded
  Actual: failed  ('C:\Users\Buildbot\AppData\Local\Temp\lit-tmp-myr7yuce\on-disk-cas-1cec22\leaf+0.13184.v1': no such file or directory)


C:\a\llvm-clang-x86_64-expensive-checks-win\llvm-project\llvm\unittests\CAS\ObjectStoreTest.cpp:315
Value of: llvm::detail::TakeError(CAS->getProxy(*ID).moveInto(Node))
Expected: succeeded
  Actual: failed  ('C:\Users\Buildbot\AppData\Local\Temp\lit-tmp-myr7yuce\on-disk-cas-1cec22\leaf+0.13304.v1': no such file or directory)

C:\a\llvm-clang-x86_64-expensive-checks-win\llvm-project\llvm\unittests\CAS\ObjectStoreTest.cpp:315
Value of: llvm::detail::TakeError(CAS->getProxy(*ID).moveInto(Node))
Expected: succeeded
  Actual: failed  ('C:\Users\Buildbot\AppData\Local\Temp\lit-tmp-myr7yuce\on-disk-cas-1cec22\leaf+0.13184.v1': no such file or directory)



********************


@mikaelholmen
Copy link
Collaborator

Hi @cachemeifyoucan

I saw two new test failures with this patch when I build with EXPENSIVE_CHECKS.
I used gcc 13.2.

******************** TEST 'LLVM-Unit :: CAS/./CASTests/10/39' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests-LLVM-Unit-2667138-10-39.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=39 GTEST_SHARD_INDEX=10 /repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests
--

Note: This is test shard 11 of 39.
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from OnDiskCASTest
[ RUN      ] OnDiskCASTest.UnifiedOnDiskCacheTest
/app/gcc/13.2.0/include/c++/13.2.0/bits/stl_algo.h:4892:
In function:
    void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter =
    getAllDBDirs(llvm::StringRef, bool)::DBDir*; _Compare =
    getAllDBDirs(llvm::StringRef, bool)::<lambda(const
    getAllDBDirs(llvm::StringRef, bool)::DBDir&, const
    getAllDBDirs(llvm::StringRef, bool)::DBDir&)>]

Error: comparison doesn't meet irreflexive requirements, assert(!(a < a)).

Objects involved in the operation:
    instance "functor" @ 0x7ffc5c37012f {
    }
    iterator::value_type "ordered type"  {
    }
 #0 0x00000000004ba2ee llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x4ba2ee)
 #1 0x00000000004b70fb llvm::sys::RunSignalHandlers() (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x4b70fb)
 #2 0x00000000004b723e SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007fd6bff4b990 __restore_rt (/lib64/libpthread.so.0+0x12990)
 #4 0x00007fd6bd8e352f raise (/lib64/libc.so.6+0x4e52f)
 #5 0x00007fd6bd8b6e65 abort (/lib64/libc.so.6+0x21e65)
 #6 0x000000000040baeb (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x40baeb)
 #7 0x000000000052955b getAllDBDirs(llvm::StringRef, bool) UnifiedOnDiskCache.cpp:0:0
 #8 0x000000000052aea5 llvm::cas::ondisk::UnifiedOnDiskCache::open(llvm::StringRef, std::optional<unsigned long>, llvm::StringRef, unsigned int, llvm::cas::ondisk::OnDiskGraphDB::FaultInPolicy) (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x52aea5)
 #9 0x000000000046accb OnDiskCASTest_UnifiedOnDiskCacheTest_Test::TestBody()::'lambda'()::operator()() const UnifiedOnDiskCacheTest.cpp:0:0
#10 0x000000000046e2ff OnDiskCASTest_UnifiedOnDiskCacheTest_Test::TestBody() (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x46e2ff)
#11 0x000000000054de9f testing::Test::Run() (.part.0) gtest-all.cc:0:0
#12 0x000000000054e1e2 testing::TestInfo::Run() (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x54e1e2)
#13 0x000000000056a83c testing::TestSuite::Run() (.part.0) gtest-all.cc:0:0
#14 0x0000000000573bd8 testing::internal::UnitTestImpl::RunAllTests() (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x573bd8)
#15 0x000000000054da3c testing::UnitTest::Run() (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x54da3c)
#16 0x000000000040edb4 main (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x40edb4)
#17 0x00007fd6bd8cf7e5 __libc_start_main (/lib64/libc.so.6+0x3a7e5)
#18 0x000000000040f3ce _start (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x40f3ce)

--
exit: -6
--
shard JSON output does not exist: /repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests-LLVM-Unit-2667138-10-39.json
********************
FAIL: LLVM-Unit :: CAS/./CASTests/3/39 (84482 of 91334)
******************** TEST 'LLVM-Unit :: CAS/./CASTests/3/39' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests-LLVM-Unit-2667138-3-39.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=39 GTEST_SHARD_INDEX=3 /repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests
--

Note: This is test shard 4 of 39.
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from OnDiskCASTest
[ RUN      ] OnDiskCASTest.UnifiedCASMaterializationCheckPreventsGarbageCollection
/app/gcc/13.2.0/include/c++/13.2.0/bits/stl_algo.h:4892:
In function:
    void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter =
    getAllDBDirs(llvm::StringRef, bool)::DBDir*; _Compare =
    getAllDBDirs(llvm::StringRef, bool)::<lambda(const
    getAllDBDirs(llvm::StringRef, bool)::DBDir&, const
    getAllDBDirs(llvm::StringRef, bool)::DBDir&)>]

Error: comparison doesn't meet irreflexive requirements, assert(!(a < a)).

Objects involved in the operation:
    instance "functor" @ 0x7ffe670855df {
    }
    iterator::value_type "ordered type"  {
    }
 #0 0x00000000004ba2ee llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x4ba2ee)
 #1 0x00000000004b70fb llvm::sys::RunSignalHandlers() (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x4b70fb)
 #2 0x00000000004b723e SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007f160c324990 __restore_rt (/lib64/libpthread.so.0+0x12990)
 #4 0x00007f1609cbc52f raise (/lib64/libc.so.6+0x4e52f)
 #5 0x00007f1609c8fe65 abort (/lib64/libc.so.6+0x21e65)
 #6 0x000000000040baeb (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x40baeb)
 #7 0x000000000052955b getAllDBDirs(llvm::StringRef, bool) UnifiedOnDiskCache.cpp:0:0
 #8 0x000000000052aea5 llvm::cas::ondisk::UnifiedOnDiskCache::open(llvm::StringRef, std::optional<unsigned long>, llvm::StringRef, unsigned int, llvm::cas::ondisk::OnDiskGraphDB::FaultInPolicy) (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x52aea5)
 #9 0x0000000000502e55 llvm::cas::builtin::createBuiltinUnifiedOnDiskCache(llvm::StringRef) (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x502e55)
#10 0x00000000005043de llvm::cas::createOnDiskUnifiedCASDatabases(llvm::StringRef) (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x5043de)
#11 0x000000000043c1bf OnDiskCASTest_UnifiedCASMaterializationCheckPreventsGarbageCollection_Test::TestBody() (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x43c1bf)
#12 0x000000000054de9f testing::Test::Run() (.part.0) gtest-all.cc:0:0
#13 0x000000000054e1e2 testing::TestInfo::Run() (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x54e1e2)
#14 0x000000000056a83c testing::TestSuite::Run() (.part.0) gtest-all.cc:0:0
#15 0x0000000000573bd8 testing::internal::UnitTestImpl::RunAllTests() (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x573bd8)
#16 0x000000000054da3c testing::UnitTest::Run() (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x54da3c)
#17 0x000000000040edb4 main (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x40edb4)
#18 0x00007f1609ca87e5 __libc_start_main (/lib64/libc.so.6+0x3a7e5)
#19 0x000000000040f3ce _start (/repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests+0x40f3ce)

--
exit: -6
--
shard JSON output does not exist: /repo/llvm/build-all-gcc132-expensive/unittests/CAS/./CASTests-LLVM-Unit-2667138-3-39.json

And with later compiler/header versions I saw it explicitly pointing out UnifiedOnDiskCache.cpp:176:

In function:
    void std::sort(_RandomAccessIterator, _RandomAccessIterator, _Compare)
    [_RandomAccessIterator = DBDir *, _Compare = (lambda at
    ../lib/CAS/UnifiedOnDiskCache.cpp:176:27)]

Error: comparison doesn't meet irreflexive requirements, assert(!(a < a)).

@cachemeifyoucan
Copy link
Collaborator Author

That is a bug in the compare function. Fix here: #166963

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants