aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/cache/structuredcachestore.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-05-09 15:33:38 +0200
committerStefan Boberg <[email protected]>2023-05-09 15:33:38 +0200
commit15f361ad8549a4c0909d164943f9ddd8a714756c (patch)
treee3e4f37778015ea12a14b610039906a66377d3a4 /src/zenserver/cache/structuredcachestore.cpp
parentmake logging tests run as part of zencore-test (diff)
parentLow disk space detector (#277) (diff)
downloadzen-15f361ad8549a4c0909d164943f9ddd8a714756c.tar.xz
zen-15f361ad8549a4c0909d164943f9ddd8a714756c.zip
Merge branch 'main' of https://github.com/EpicGames/zen
Diffstat (limited to 'src/zenserver/cache/structuredcachestore.cpp')
-rw-r--r--src/zenserver/cache/structuredcachestore.cpp48
1 files changed, 44 insertions, 4 deletions
diff --git a/src/zenserver/cache/structuredcachestore.cpp b/src/zenserver/cache/structuredcachestore.cpp
index 26e970073..99ca23407 100644
--- a/src/zenserver/cache/structuredcachestore.cpp
+++ b/src/zenserver/cache/structuredcachestore.cpp
@@ -1002,6 +1002,11 @@ ZenCacheDiskLayer::CacheBucket::OpenLog(const bool IsNew)
fs::remove_all(m_BlocksBasePath);
}
+ CreateDirectories(m_BucketDir);
+
+ std::unordered_map<uint32_t, uint64_t> BlockSizes =
+ m_BlockStore.Initialize(m_BlocksBasePath, MaxBlockSize, BlockStoreDiskLocation::MaxBlockIndex + 1);
+
uint64_t LogEntryCount = 0;
{
uint32_t IndexVersion = 0;
@@ -1023,12 +1028,11 @@ ZenCacheDiskLayer::CacheBucket::OpenLog(const bool IsNew)
}
}
- CreateDirectories(m_BucketDir);
-
m_SlogFile.Open(LogPath, CasLogFile::Mode::kWrite);
std::vector<BlockStoreLocation> KnownLocations;
KnownLocations.reserve(m_Index.size());
+ std::vector<DiskIndexEntry> BadEntries;
for (const auto& Entry : m_Index)
{
size_t EntryIndex = Entry.second;
@@ -1041,10 +1045,46 @@ ZenCacheDiskLayer::CacheBucket::OpenLog(const bool IsNew)
continue;
}
const BlockStoreLocation& BlockLocation = Location.GetBlockLocation(m_PayloadAlignment);
- KnownLocations.push_back(BlockLocation);
+
+ auto BlockIt = BlockSizes.find(BlockLocation.BlockIndex);
+ if (BlockIt == BlockSizes.end())
+ {
+ ZEN_WARN("Unknown block {} for entry {}", BlockLocation.BlockIndex, Entry.first.ToHexString());
+ }
+ else
+ {
+ uint64_t BlockSize = BlockIt->second;
+ if (BlockLocation.Offset + BlockLocation.Size > BlockSize)
+ {
+ ZEN_WARN("Range is outside of block {} for entry {}", BlockLocation.BlockIndex, Entry.first.ToHexString());
+ }
+ else
+ {
+ KnownLocations.push_back(BlockLocation);
+ continue;
+ }
+ }
+
+ DiskLocation NewLocation = Payload.Location;
+ NewLocation.Flags |= DiskLocation::kTombStone;
+ BadEntries.push_back(DiskIndexEntry{.Key = Entry.first, .Location = NewLocation});
}
- m_BlockStore.Initialize(m_BlocksBasePath, MaxBlockSize, BlockStoreDiskLocation::MaxBlockIndex + 1, KnownLocations);
+ if (!BadEntries.empty())
+ {
+ m_SlogFile.Append(BadEntries);
+ m_SlogFile.Flush();
+
+ LogEntryCount += BadEntries.size();
+
+ for (const DiskIndexEntry& BadEntry : BadEntries)
+ {
+ m_Index.erase(BadEntry.Key);
+ }
+ }
+
+ m_BlockStore.Prune(KnownLocations);
+
if (IsNew || LogEntryCount > 0)
{
MakeIndexSnapshot();