diff --git a/src/Disks/DiskObjectStorage/MetadataStorages/ContentAddressed/Formats/CasPartManifestFormat.h b/src/Disks/DiskObjectStorage/MetadataStorages/ContentAddressed/Formats/CasPartManifestFormat.h index 8e6bad5c3e97..13cb67883310 100644 --- a/src/Disks/DiskObjectStorage/MetadataStorages/ContentAddressed/Formats/CasPartManifestFormat.h +++ b/src/Disks/DiskObjectStorage/MetadataStorages/ContentAddressed/Formats/CasPartManifestFormat.h @@ -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 diff --git a/src/Disks/DiskObjectStorage/MetadataStorages/ContentAddressed/Parts/PartFolderAccess.cpp b/src/Disks/DiskObjectStorage/MetadataStorages/ContentAddressed/Parts/PartFolderAccess.cpp index a4497837b0b8..6d14a17d81c1 100644 --- a/src/Disks/DiskObjectStorage/MetadataStorages/ContentAddressed/Parts/PartFolderAccess.cpp +++ b/src/Disks/DiskObjectStorage/MetadataStorages/ContentAddressed/Parts/PartFolderAccess.cpp @@ -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(256 + manifest_size, decodedPartManifestWeight(*manifest_body)); } CachedPartFolderAccess::CachedPartFolderAccess(Cas::PoolPtr store_) diff --git a/src/Disks/DiskObjectStorage/MetadataStorages/ContentAddressed/Pool/CasManifestReader.h b/src/Disks/DiskObjectStorage/MetadataStorages/ContentAddressed/Pool/CasManifestReader.h index 383e4aa03596..79694c398f97 100644 --- a/src/Disks/DiskObjectStorage/MetadataStorages/ContentAddressed/Pool/CasManifestReader.h +++ b/src/Disks/DiskObjectStorage/MetadataStorages/ContentAddressed/Pool/CasManifestReader.h @@ -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, PartManifestWeight>; diff --git a/src/Disks/tests/gtest_cas_part_folder_view.cpp b/src/Disks/tests/gtest_cas_part_folder_view.cpp index 5bd2ab8b7c43..2aa8e0c09ee0 100644 --- a/src/Disks/tests/gtest_cas_part_folder_view.cpp +++ b/src/Disks/tests/gtest_cas_part_folder_view.cpp @@ -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::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( + 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); +}