diff options
| author | Stefan Boberg <[email protected]> | 2024-12-05 12:44:27 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-12-05 12:44:27 +0100 |
| commit | 7ca7e683224918808a3a0dd8cd0a6953cc79cb4c (patch) | |
| tree | a2d92895843e37292945e673642a338341f3a036 /src/zenstore/cache/cachedisklayer.cpp | |
| parent | enable LTO / optimize for speed (#256) (diff) | |
| download | zen-7ca7e683224918808a3a0dd8cd0a6953cc79cb4c.tar.xz zen-7ca7e683224918808a3a0dd8cd0a6953cc79cb4c.zip | |
Unity build fixes (#253)
some fixes to make everything build using unity build mode. Mostly moved code from anonymous namespaces into local impl namespace to avoid ambiguity in name resolution.
Diffstat (limited to 'src/zenstore/cache/cachedisklayer.cpp')
| -rw-r--r-- | src/zenstore/cache/cachedisklayer.cpp | 93 |
1 files changed, 52 insertions, 41 deletions
diff --git a/src/zenstore/cache/cachedisklayer.cpp b/src/zenstore/cache/cachedisklayer.cpp index a4f9fe78b..851b1d125 100644 --- a/src/zenstore/cache/cachedisklayer.cpp +++ b/src/zenstore/cache/cachedisklayer.cpp @@ -34,7 +34,7 @@ GetCacheDiskTag() return _; } -namespace { +namespace cache::impl { #pragma pack(push) #pragma pack(1) @@ -224,11 +224,15 @@ namespace { zen::Sleep(100); } while (true); } -} // namespace +} // namespace cache::impl namespace fs = std::filesystem; using namespace std::literals; +} // namespace zen + +namespace zen::cache::impl { + class BucketManifestSerializer { using MetaDataIndex = ZenCacheDiskLayer::CacheBucket::MetaDataIndex; @@ -571,7 +575,8 @@ BucketManifestSerializer::ReadSidecarFile(RwLock::ExclusiveLockScope& B if (Header.EntryCount > ExpectedEntryCount) { ZEN_WARN( - "Failed to read sidecar file '{}'. File is not large enough to hold expected entry count. Header count: {}, file size count: " + "Failed to read sidecar file '{}'. File is not large enough to hold expected entry count. Header count: {}, file size " + "count: " "{}", SidecarPath, Header.EntryCount, @@ -695,6 +700,12 @@ BucketManifestSerializer::WriteSidecarFile(RwLock::SharedLockScope&, static const float IndexMinLoadFactor = 0.2f; static const float IndexMaxLoadFactor = 0.7f; +} // namespace zen::cache::impl + +////////////////////////////////////////////////////////////////////////// + +namespace zen { + ZenCacheDiskLayer::CacheBucket::CacheBucket(GcManager& Gc, std::atomic_uint64_t& OuterCacheMemoryUsage, std::string BucketName, @@ -705,8 +716,8 @@ ZenCacheDiskLayer::CacheBucket::CacheBucket(GcManager& Gc, , m_Configuration(Config) , m_BucketId(Oid::Zero) { - m_Index.min_load_factor(IndexMinLoadFactor); - m_Index.max_load_factor(IndexMaxLoadFactor); + m_Index.min_load_factor(cache::impl::IndexMinLoadFactor); + m_Index.max_load_factor(cache::impl::IndexMaxLoadFactor); if (m_BucketName.starts_with(std::string_view("legacy")) || m_BucketName.ends_with(std::string_view("shadermap"))) { @@ -750,11 +761,11 @@ ZenCacheDiskLayer::CacheBucket::OpenOrCreate(std::filesystem::path BucketDir, bo CreateDirectories(m_BucketDir); - std::filesystem::path ManifestPath = GetManifestPath(m_BucketDir, m_BucketName); + std::filesystem::path ManifestPath = cache::impl::GetManifestPath(m_BucketDir, m_BucketName); bool IsNew = false; - BucketManifestSerializer ManifestReader; + cache::impl::BucketManifestSerializer ManifestReader; if (ManifestReader.Open(ManifestPath)) { @@ -770,7 +781,7 @@ ZenCacheDiskLayer::CacheBucket::OpenOrCreate(std::filesystem::path BucketDir, bo ZEN_INFO("Wiping bucket '{}', found version {}, required version {}", BucketDir, Version, - BucketManifestSerializer::CurrentDiskBucketVersion); + cache::impl::BucketManifestSerializer::CurrentDiskBucketVersion); IsNew = true; } } @@ -824,11 +835,11 @@ ZenCacheDiskLayer::CacheBucket::WriteIndexSnapshotLocked(bool FlushLockPosition, namespace fs = std::filesystem; - fs::path IndexPath = GetIndexPath(m_BucketDir, m_BucketName); + fs::path IndexPath = cache::impl::GetIndexPath(m_BucketDir, m_BucketName); try { - const uint64_t IndexSize = sizeof(CacheBucketIndexHeader) + EntryCount * sizeof(DiskIndexEntry); + const uint64_t IndexSize = sizeof(cache::impl::CacheBucketIndexHeader) + EntryCount * sizeof(DiskIndexEntry); std::error_code Error; DiskSpace Space = DiskSpaceInfo(m_BucketDir, Error); if (Error) @@ -862,14 +873,14 @@ ZenCacheDiskLayer::CacheBucket::WriteIndexSnapshotLocked(bool FlushLockPosition, // all data is written to the file BasicFileWriter IndexWriter(ObjectIndexFile, 128 * 1024); - CacheBucketIndexHeader Header = {.EntryCount = EntryCount, - .LogPosition = LogCount, - .PayloadAlignment = gsl::narrow<uint32_t>(m_Configuration.PayloadAlignment)}; + cache::impl::CacheBucketIndexHeader Header = {.EntryCount = EntryCount, + .LogPosition = LogCount, + .PayloadAlignment = gsl::narrow<uint32_t>(m_Configuration.PayloadAlignment)}; - Header.Checksum = CacheBucketIndexHeader::ComputeChecksum(Header); - IndexWriter.Write(&Header, sizeof(CacheBucketIndexHeader), 0); + Header.Checksum = cache::impl::CacheBucketIndexHeader::ComputeChecksum(Header); + IndexWriter.Write(&Header, sizeof(cache::impl::CacheBucketIndexHeader), 0); - uint64_t IndexWriteOffset = sizeof(CacheBucketIndexHeader); + uint64_t IndexWriteOffset = sizeof(cache::impl::CacheBucketIndexHeader); for (auto& Entry : m_Index) { @@ -896,7 +907,7 @@ ZenCacheDiskLayer::CacheBucket::WriteIndexSnapshotLocked(bool FlushLockPosition, // We must only update the log flush position once the snapshot write succeeds if (FlushLockPosition) { - std::filesystem::path LogPath = GetLogPath(m_BucketDir, m_BucketName); + std::filesystem::path LogPath = cache::impl::GetLogPath(m_BucketDir, m_BucketName); if (std::filesystem::is_regular_file(LogPath)) { @@ -938,12 +949,12 @@ ZenCacheDiskLayer::CacheBucket::ReadIndexFile(RwLock::ExclusiveLockScope&, const BasicFile ObjectIndexFile; ObjectIndexFile.Open(IndexPath, BasicFile::Mode::kRead); uint64_t FileSize = ObjectIndexFile.FileSize(); - if (FileSize < sizeof(CacheBucketIndexHeader)) + if (FileSize < sizeof(cache::impl::CacheBucketIndexHeader)) { return 0; } - CacheBucketIndexHeader Header; + cache::impl::CacheBucketIndexHeader Header; ObjectIndexFile.Read(&Header, sizeof(Header), 0); if (!Header.IsValid()) @@ -951,12 +962,12 @@ ZenCacheDiskLayer::CacheBucket::ReadIndexFile(RwLock::ExclusiveLockScope&, const return 0; } - if (Header.Version != CacheBucketIndexHeader::Version2) + if (Header.Version != cache::impl::CacheBucketIndexHeader::Version2) { return 0; } - const uint64_t ExpectedEntryCount = (FileSize - sizeof(sizeof(CacheBucketIndexHeader))) / sizeof(DiskIndexEntry); + const uint64_t ExpectedEntryCount = (FileSize - sizeof(sizeof(cache::impl::CacheBucketIndexHeader))) / sizeof(DiskIndexEntry); if (Header.EntryCount > ExpectedEntryCount) { return 0; @@ -977,7 +988,7 @@ ZenCacheDiskLayer::CacheBucket::ReadIndexFile(RwLock::ExclusiveLockScope&, const BasicFileBuffer FileBuffer(ObjectIndexFile, 128 * 1024); - uint64_t CurrentReadOffset = sizeof(CacheBucketIndexHeader); + uint64_t CurrentReadOffset = sizeof(cache::impl::CacheBucketIndexHeader); uint64_t RemainingEntryCount = Header.EntryCount; std::string InvalidEntryReason; @@ -986,7 +997,7 @@ ZenCacheDiskLayer::CacheBucket::ReadIndexFile(RwLock::ExclusiveLockScope&, const const DiskIndexEntry* Entry = FileBuffer.MakeView<DiskIndexEntry>(CurrentReadOffset); CurrentReadOffset += sizeof(DiskIndexEntry); - if (!ValidateCacheBucketIndexEntry(*Entry, InvalidEntryReason)) + if (!cache::impl::ValidateCacheBucketIndexEntry(*Entry, InvalidEntryReason)) { ZEN_WARN("skipping invalid entry in '{}', reason: '{}'", IndexPath, InvalidEntryReason); continue; @@ -1003,7 +1014,7 @@ ZenCacheDiskLayer::CacheBucket::ReadIndexFile(RwLock::ExclusiveLockScope&, const m_AccessTimes.resize(EntryCount, AccessTime(GcClock::TickCount())); - OutVersion = CacheBucketIndexHeader::Version2; + OutVersion = cache::impl::CacheBucketIndexHeader::Version2; return Header.LogPosition; } @@ -1050,7 +1061,7 @@ ZenCacheDiskLayer::CacheBucket::ReadLog(RwLock::ExclusiveLockScope&, const std:: return; } - if (!ValidateCacheBucketIndexEntry(Record, InvalidEntryReason)) + if (!cache::impl::ValidateCacheBucketIndexEntry(Record, InvalidEntryReason)) { ZEN_WARN("skipping invalid entry in '{}', reason: '{}'", LogPath, InvalidEntryReason); ++InvalidEntryCount; @@ -1087,8 +1098,8 @@ ZenCacheDiskLayer::CacheBucket::InitializeIndexFromDisk(RwLock::ExclusiveLockSco m_MemCachedPayloads.clear(); m_FreeMemCachedPayloads.clear(); - std::filesystem::path LogPath = GetLogPath(m_BucketDir, m_BucketName); - std::filesystem::path IndexPath = GetIndexPath(m_BucketDir, m_BucketName); + std::filesystem::path LogPath = cache::impl::GetLogPath(m_BucketDir, m_BucketName); + std::filesystem::path IndexPath = cache::impl::GetIndexPath(m_BucketDir, m_BucketName); if (IsNew) { @@ -1920,7 +1931,7 @@ ZenCacheDiskLayer::CacheBucket::Drop() m_BlockStore.Close(); m_SlogFile.Close(); - bool Deleted = MoveAndDeleteDirectory(m_BucketDir); + const bool Deleted = cache::impl::MoveAndDeleteDirectory(m_BucketDir); m_Index.clear(); m_Payloads.clear(); @@ -1970,8 +1981,8 @@ ZenCacheDiskLayer::CacheBucket::SaveSnapshot(const std::function<uint64_t()>& Cl { bool UseLegacyScheme = false; - IoBuffer Buffer; - BucketManifestSerializer ManifestWriter; + IoBuffer Buffer; + cache::impl::BucketManifestSerializer ManifestWriter; if (UseLegacyScheme) { @@ -2051,7 +2062,7 @@ ZenCacheDiskLayer::CacheBucket::SaveSnapshot(const std::function<uint64_t()>& Cl } ManifestWriter.WriteSidecarFile(IndexLock, - GetMetaPath(m_BucketDir, m_BucketName), + cache::impl::GetMetaPath(m_BucketDir, m_BucketName), m_LogFlushPosition, m_Index, m_AccessTimes, @@ -2059,7 +2070,7 @@ ZenCacheDiskLayer::CacheBucket::SaveSnapshot(const std::function<uint64_t()>& Cl m_MetaDatas); } - std::filesystem::path ManifestPath = GetManifestPath(m_BucketDir, m_BucketName); + const std::filesystem::path ManifestPath = cache::impl::GetManifestPath(m_BucketDir, m_BucketName); TemporaryFile::SafeWriteFile(ManifestPath, Buffer.GetView()); } catch (const std::exception& Err) @@ -2733,7 +2744,7 @@ public: Stopwatch Timer; const auto _ = MakeGuard([&] { - Reset(m_ExpiredStandaloneKeys); + cache::impl::Reset(m_ExpiredStandaloneKeys); if (!Ctx.Settings.Verbose) { return; @@ -3101,7 +3112,7 @@ ZenCacheDiskLayer::CacheBucket::ReadAttachmentsFromMetaData(uint32_t BlockI ZEN_TRACE_CPU("Z$::Bucket::GetAttachmentsFromMetaData"); return GetAttachmentsFromMetaData<IoHash, IoHash>( MetaDataPayload, - BlockMetaDataExpectedMagic, + cache::impl::BlockMetaDataExpectedMagic, [&](std::span<const IoHash> Keys, std::span<const uint32_t> AttachmentCounts, std::span<const IoHash> Attachments) { auto AttachmentReadIt = Attachments.begin(); OutReferences.resize(OutReferences.size() + Attachments.size()); @@ -3278,7 +3289,7 @@ ZenCacheDiskLayer::CacheBucket::GetReferences(const LoggerRef& Logger, ZEN_ASSERT(Keys.size() == AttachmentCounts.size()); IoBuffer MetaDataPayload = BuildReferenceMetaData<IoHash>( - BlockMetaDataExpectedMagic, + cache::impl::BlockMetaDataExpectedMagic, Keys, AttachmentCounts, std::span<const IoHash>(OutReferences) @@ -3485,8 +3496,8 @@ ZenCacheDiskLayer::CacheBucket::CompactState(RwLock::ExclusiveLockScope&, Payloads.reserve(EntryCount); AccessTimes.reserve(EntryCount); Index.reserve(EntryCount); - Index.min_load_factor(IndexMinLoadFactor); - Index.max_load_factor(IndexMaxLoadFactor); + Index.min_load_factor(cache::impl::IndexMinLoadFactor); + Index.max_load_factor(cache::impl::IndexMaxLoadFactor); for (auto It : m_Index) { PayloadIndex EntryIndex = PayloadIndex(Payloads.size()); @@ -3510,9 +3521,9 @@ ZenCacheDiskLayer::CacheBucket::CompactState(RwLock::ExclusiveLockScope&, m_Payloads.swap(Payloads); m_AccessTimes.swap(AccessTimes); m_MetaDatas.swap(MetaDatas); - Reset(m_FreeMetaDatas); + cache::impl::Reset(m_FreeMetaDatas); m_MemCachedPayloads.swap(MemCachedPayloads); - Reset(m_FreeMemCachedPayloads); + cache::impl::Reset(m_FreeMemCachedPayloads); } RwLock::SharedLockScope @@ -3963,7 +3974,7 @@ ZenCacheDiskLayer::DropBucket(std::string_view InBucket) // Make sure we remove the folder even if we don't know about the bucket std::filesystem::path BucketPath = m_RootDir; BucketPath /= std::string(InBucket); - return MoveAndDeleteDirectory(BucketPath); + return cache::impl::MoveAndDeleteDirectory(BucketPath); } bool @@ -3986,7 +3997,7 @@ ZenCacheDiskLayer::Drop() return false; } } - return MoveAndDeleteDirectory(m_RootDir); + return cache::impl::MoveAndDeleteDirectory(m_RootDir); } void |