aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-05-12 13:14:55 +0200
committerGitHub <[email protected]>2023-05-12 13:14:55 +0200
commit76e822752a1818d3b3fcbe17d7639d712f149c02 (patch)
tree3d3b44b2ef584f05b57171a280a00fbc22093485
parentGracefully exit if Ctrl-C is pressed (#293) (diff)
downloadzen-76e822752a1818d3b3fcbe17d7639d712f149c02.tar.xz
zen-76e822752a1818d3b3fcbe17d7639d712f149c02.zip
fix logic for old blocks in blockstore gc (#295)
* fix logic for old blocks in blockstore gc If we will remove all entries in a block and keep nothing we can't expect for the block to exist. If we want to keep entries in a block, the block must exist, if not error and move entries to delete list. Don't reset output block between blocks we are reading from, keep using it until it exceeds the max limit. * changelog
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/zenstore/blockstore.cpp45
2 files changed, 25 insertions, 21 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6d64fd347..97b0c0502 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
- Feature: Gracefully exit if Ctrl-C is pressed
- Bugfix: Return error code on exit as set by application
- Bugfix: Fix crash at startup if dead process handles are detected in ZenServerState
+- Bugfix: Fixed assert/error when running block store GC and a block to GC does not exist
## 0.2.10
- Feature: zenserver now writes a state_marker file in the root of the data directory. Deleting this file will cause zenserver to exit. This is used to detect if user is deleting the data folder while zenserver is running
diff --git a/src/zenstore/blockstore.cpp b/src/zenstore/blockstore.cpp
index 0593ff06b..f9e74fb0b 100644
--- a/src/zenstore/blockstore.cpp
+++ b/src/zenstore/blockstore.cpp
@@ -478,20 +478,7 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot,
}
}
- if (!OldBlockFile)
- {
- // If the block file pointed to does not exist, move them all to deleted list
- ChunkIndexArray& KeepMap = BlockKeepChunks[ChunkMapIndex];
- ZEN_ERROR("Expected to find block {} in {} - this should never happen, marking {} entries as deleted.",
- BlockIndex,
- m_BlocksBasePath,
- KeepMap.size());
-
- BlockDeleteChunks[ChunkMapIndex].insert(BlockDeleteChunks[ChunkMapIndex].end(), KeepMap.begin(), KeepMap.end());
- KeepMap.clear();
- }
-
- const ChunkIndexArray& KeepMap = BlockKeepChunks[ChunkMapIndex];
+ ChunkIndexArray& KeepMap = BlockKeepChunks[ChunkMapIndex];
if (KeepMap.empty())
{
const ChunkIndexArray& DeleteMap = BlockDeleteChunks[ChunkMapIndex];
@@ -520,8 +507,17 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot,
}
continue;
}
+ else if (!OldBlockFile)
+ {
+ // If the block file pointed to does not exist, move any keep chunk them to deleted list
+ ZEN_ERROR("Expected to find block {} in {} - this should never happen, marking {} entries as deleted.",
+ BlockIndex,
+ m_BlocksBasePath,
+ KeepMap.size());
- ZEN_ASSERT(OldBlockFile);
+ BlockDeleteChunks[ChunkMapIndex].insert(BlockDeleteChunks[ChunkMapIndex].end(), KeepMap.begin(), KeepMap.end());
+ KeepMap.clear();
+ }
MovedChunksArray MovedChunks;
std::vector<uint8_t> Chunk;
@@ -616,7 +612,6 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot,
if (NewBlockFile)
{
NewBlockFile->Flush();
- NewBlockFile = nullptr;
}
const ChunkIndexArray& DeleteMap = BlockDeleteChunks[ChunkMapIndex];
@@ -637,13 +632,21 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot,
ReadBlockTimeUs += ElapsedUs;
ReadBlockLongestTimeUs = std::max(ElapsedUs, ReadBlockLongestTimeUs);
});
- ZEN_DEBUG("marking cas block store file '{}' for delete, block #{}", OldBlockFile->GetPath(), BlockIndex);
- ZEN_ASSERT(m_ChunkBlocks[BlockIndex] == OldBlockFile);
- m_ChunkBlocks.erase(BlockIndex);
- m_TotalSize.fetch_sub(OldBlockFile->FileSize(), std::memory_order::relaxed);
- OldBlockFile->MarkAsDeleteOnClose();
+ if (OldBlockFile)
+ {
+ ZEN_DEBUG("marking cas block store file '{}' for delete, block #{}", OldBlockFile->GetPath(), BlockIndex);
+ ZEN_ASSERT(m_ChunkBlocks[BlockIndex] == OldBlockFile);
+ m_ChunkBlocks.erase(BlockIndex);
+ m_TotalSize.fetch_sub(OldBlockFile->FileSize(), std::memory_order::relaxed);
+ OldBlockFile->MarkAsDeleteOnClose();
+ }
}
}
+ if (NewBlockFile)
+ {
+ NewBlockFile->Flush();
+ NewBlockFile = nullptr;
+ }
}
catch (std::exception& ex)
{