Skip to content

Commit 5db4534

Browse files
[CASDB] OnDiskCAS should not create LeafNode when node has refs
Fix a bug that OnDiskCAS drops all the references when the data is large and a leaf node is created. Leaf node should only be used when there are no refs.
1 parent 732fa1e commit 5db4534

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

llvm/lib/CAS/OnDiskCAS.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ Expected<NodeHandle> OnDiskCAS::storeNodeImpl(ArrayRef<uint8_t> ComputedHash,
19031903
}
19041904

19051905
// Big leaf nodes.
1906-
if (Data.size() > TrieRecord::MaxEmbeddedSize)
1906+
if (Refs.empty() && Data.size() > TrieRecord::MaxEmbeddedSize)
19071907
return createStandaloneLeaf(I, Data);
19081908

19091909
// TODO: Check whether it's worth checking the index for an already existing

llvm/unittests/CAS/CASDBTest.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,21 @@ TEST_P(CASDBTest, NodesBig) {
400400
if (Storage.size() < SizeE)
401401
Storage.resize(SizeE, '\01');
402402

403+
SmallVector<CASID, 4> CreatedNodes;
403404
// Avoid checking every size because this is an expensive test. Just check
404-
// for data that is 8B-word-aligned, and one less.
405+
// for data that is 8B-word-aligned, and one less. Also appending the created
406+
// nodes as the references in the next block to check references are created
407+
// correctly.
405408
for (size_t Size = SizeB; Size < SizeE; Size += WordSize) {
406409
for (bool IsAligned : {false, true}) {
407410
StringRef Data(Storage.data(), Size - (IsAligned ? 0 : 1));
408411
Optional<NodeProxy> Node;
409-
ASSERT_THAT_ERROR(CAS->createNode(None, Data).moveInto(Node), Succeeded());
412+
ASSERT_THAT_ERROR(CAS->createNode(CreatedNodes, Data).moveInto(Node),
413+
Succeeded());
410414
ASSERT_EQ(Data, Node->getData());
411415
ASSERT_EQ(0, Node->getData().end()[0]);
416+
ASSERT_EQ(Node->getNumReferences(), CreatedNodes.size());
417+
CreatedNodes.emplace_back(Node->getID());
412418
}
413419
}
414420
}

0 commit comments

Comments
 (0)