Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ struct PartManifest
bool operator==(const PartManifest &) const = default;
};

/// Approximate bytes retained in memory for one decoded manifest (fixed object overhead plus
/// per-entry path and inline-byte storage). Shared by `CasManifestReader`'s decode cache and
/// `PartFolderView::estimatedBytes()` so a retained part-folder view charges for the decoded
/// manifest it keeps alive even when `Resolved::manifest_size` is 0.
inline size_t decodedPartManifestWeight(const PartManifest & m)
{
size_t bytes = 256;
for (const auto & e : m.entries)
bytes += e.path.size() + e.inline_bytes.size() + 96;
return bytes;
}

/// Deterministic, streaming-capable encode. Entries are written in canonical path order (the encoder
/// sorts them). A bad or duplicate entry path, which no writer builds, throws `LOGICAL_ERROR`; a line
/// over the line cap, which an oversized legal input can produce, throws `LIMIT_EXCEEDED`. Byte output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ bool PartFolderView::hasDirectory(const String & dir_prefix) const

size_t PartFolderView::estimatedBytes() const
{
/// Conservative cache weight: fixed overhead plus `manifest_size`. This deliberately over-counts
/// the shared decode, which is safe because eviction should happen before the budget is exceeded.
return 256 + manifest_size;
/// Conservative cache weight: the larger of fixed overhead plus `manifest_size` and the
/// retained decoded-manifest weight (which accounts for inlined entry payloads when
/// `manifest_size` is 0 on a ref resolve).
return std::max<size_t>(256 + manifest_size, decodedPartManifestWeight(*manifest_body));
}

CachedPartFolderAccess::CachedPartFolderAccess(Cas::PoolPtr store_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ class CasManifestReader
/// Returns the approximate bytes retained for one decoded manifest by the cache.
size_t operator()(const PartManifest & m) const
{
size_t bytes = 256;
for (const auto & e : m.entries)
bytes += e.path.size() + e.inline_bytes.size() + 96;
return bytes;
return decodedPartManifestWeight(m);
}
};
using ManifestDecodeCache = CacheBase<ManifestId, PartManifest, std::hash<ManifestId>, PartManifestWeight>;
Expand Down
18 changes: 18 additions & 0 deletions src/Disks/tests/gtest_cas_part_folder_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,21 @@ TEST(CASPartFolderView, ProjectionDirPrefixRecognizer)
EXPECT_EQ(V::projectionDirPrefix("data.bin"), std::nullopt);
EXPECT_EQ(V::projectionDirPrefix(""), std::nullopt);
}

TEST(CASPartFolderView, EstimatedBytesReusesDecodedManifestWeightWhenManifestSizeZero)
{
auto manifest = std::make_shared<Cas::PartManifest>();
Cas::ManifestEntry e;
e.path = "primary.idx";
e.placement = Cas::EntryPlacement::Inline;
e.inline_bytes = String(4096, 'x');
manifest->entries.push_back(e);

auto v = std::make_shared<const Cas::PartFolderView>(
Cas::PartRefKey{Cas::RootNamespace{"srv/t"}, "part_1"},
Cas::ManifestId{Cas::RootNamespace{"srv/t"}, Cas::ManifestRef{1, 2, 3}},
/*manifest_size=*/0, manifest);

EXPECT_EQ(v->estimatedBytes(), Cas::decodedPartManifestWeight(*manifest));
EXPECT_GT(v->estimatedBytes(), 4096u);
}
Loading