diff options
| author | Dan Engelbrecht <[email protected]> | 2023-04-26 16:13:36 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-04-26 16:13:36 +0200 |
| commit | e6c9601ee1a9a9d762ca03507dbeca90d4c8647a (patch) | |
| tree | 4af019136d16a73144e94e2d5abc042ce956b199 /zenstore/blockstore.cpp | |
| parent | only strip accept type suffix if it can be parsed to a known type (#258) (diff) | |
| download | zen-e6c9601ee1a9a9d762ca03507dbeca90d4c8647a.tar.xz zen-e6c9601ee1a9a9d762ca03507dbeca90d4c8647a.zip | |
Safely handle missing blocks when doing garbage collection in block store data (#259)
Diffstat (limited to 'zenstore/blockstore.cpp')
| -rw-r--r-- | zenstore/blockstore.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/zenstore/blockstore.cpp b/zenstore/blockstore.cpp index 5e47d061f..2894244fe 100644 --- a/zenstore/blockstore.cpp +++ b/zenstore/blockstore.cpp @@ -452,7 +452,15 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot, WriteBlockLongestTimeUs = std::max(ElapsedUs, WriteBlockLongestTimeUs); }); OldBlockFile = m_ChunkBlocks[BlockIndex]; - ZEN_ASSERT(OldBlockFile); + } + + if (!OldBlockFile) + { + // If the block file pointed to does not exist, move them all to deleted list + BlockDeleteChunks[ChunkMapIndex].insert(BlockDeleteChunks[ChunkMapIndex].end(), + BlockKeepChunks[ChunkMapIndex].begin(), + BlockKeepChunks[ChunkMapIndex].end()); + BlockKeepChunks[ChunkMapIndex].clear(); } const ChunkIndexArray& KeepMap = BlockKeepChunks[ChunkMapIndex]; @@ -473,14 +481,19 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot, ReadBlockTimeUs += ElapsedUs; ReadBlockLongestTimeUs = std::max(ElapsedUs, ReadBlockLongestTimeUs); }); - m_ChunkBlocks[BlockIndex] = nullptr; - ZEN_DEBUG("marking cas block store file '{}' for delete, block #{}", OldBlockFile->GetPath(), BlockIndex); - m_TotalSize.fetch_sub(OldBlockFile->FileSize(), std::memory_order::relaxed); - OldBlockFile->MarkAsDeleteOnClose(); + if (OldBlockFile != nullptr) + { + m_ChunkBlocks[BlockIndex] = nullptr; + ZEN_DEBUG("marking cas block store file '{}' for delete, block #{}", OldBlockFile->GetPath(), BlockIndex); + m_TotalSize.fetch_sub(OldBlockFile->FileSize(), std::memory_order::relaxed); + OldBlockFile->MarkAsDeleteOnClose(); + } } continue; } + ZEN_ASSERT(OldBlockFile); + MovedChunksArray MovedChunks; std::vector<uint8_t> Chunk; for (const size_t& ChunkIndex : KeepMap) |