diff options
| author | Dan Engelbrecht <[email protected]> | 2023-10-05 14:58:42 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-10-05 14:58:42 +0200 |
| commit | 45c7f6c6987fd24ed4f444dac34b13216bab108a (patch) | |
| tree | 068a10ae56a52787ee3ed83d245613fb21ff88ee /src/zenstore/blockstore.cpp | |
| parent | Merge branch 'main' of https://github.com/EpicGames/zen (diff) | |
| download | zen-45c7f6c6987fd24ed4f444dac34b13216bab108a.tar.xz zen-45c7f6c6987fd24ed4f444dac34b13216bab108a.zip | |
Fix curruption of disk cache bucket index on GC (#448)
* make sure we hold the index lock when reading payload data in reclaim space
* don't use index snapshot when updating index in reclaim space
* check that things have not moved under our feet
* don't touch m_Payloads without a lock
* start write block index on the highest block index
* we don't need to bump writeblockindex when stopping write to a block, we will bump appropriately when we start a new block
* changelog
Diffstat (limited to 'src/zenstore/blockstore.cpp')
| -rw-r--r-- | src/zenstore/blockstore.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/zenstore/blockstore.cpp b/src/zenstore/blockstore.cpp index f99b0bc4a..968e919d6 100644 --- a/src/zenstore/blockstore.cpp +++ b/src/zenstore/blockstore.cpp @@ -171,6 +171,7 @@ BlockStore::Initialize(const std::filesystem::path& BlocksBasePath, uint64_t Max if (std::filesystem::is_directory(m_BlocksBasePath)) { + uint32_t NextBlockIndex = 0; std::vector<std::filesystem::path> FoldersToScan; FoldersToScan.push_back(m_BlocksBasePath); size_t FolderOffset = 0; @@ -202,10 +203,15 @@ BlockStore::Initialize(const std::filesystem::path& BlocksBasePath, uint64_t Max m_TotalSize.fetch_add(BlockFile->FileSize(), std::memory_order::relaxed); m_ChunkBlocks[BlockIndex] = BlockFile; FoundBlocks[BlockIndex] = BlockFile->FileSize(); + if (BlockIndex >= NextBlockIndex) + { + NextBlockIndex = (BlockIndex + 1) & (m_MaxBlockCount - 1); + } } } ++FolderOffset; } + m_WriteBlockIndex.store(NextBlockIndex, std::memory_order_release); } else { @@ -363,14 +369,11 @@ BlockStore::Flush(bool ForceNewBlock) RwLock::ExclusiveLockScope _(m_InsertLock); if (m_CurrentInsertOffset > 0) { - uint32_t WriteBlockIndex = m_WriteBlockIndex.load(std::memory_order_acquire); - WriteBlockIndex = (WriteBlockIndex + 1) & (m_MaxBlockCount - 1); if (m_WriteBlock) { m_WriteBlock->Flush(); } - m_WriteBlock = nullptr; - m_WriteBlockIndex.store(WriteBlockIndex, std::memory_order_release); + m_WriteBlock = nullptr; m_CurrentInsertOffset = 0; } return; |