aboutsummaryrefslogtreecommitdiff
path: root/src/zenstore/blockstore.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2024-04-15 09:09:46 +0200
committerGitHub Enterprise <[email protected]>2024-04-15 09:09:46 +0200
commit6ff0ea81285ffbe2e5708948d7345eb7af9f22f3 (patch)
treedd8ef30c0e8f17e6160c0eef185a796059065f71 /src/zenstore/blockstore.cpp
parentValidate input buffer size when trying to parse package message (#47) (diff)
downloadzen-6ff0ea81285ffbe2e5708948d7345eb7af9f22f3.tar.xz
zen-6ff0ea81285ffbe2e5708948d7345eb7af9f22f3.zip
gc v2 disk freed space fix and oplog stats report improvement (#45)
- Bugfix: Correctly calculate size freed/data moved from blocks in GCv2 - Improvement: Reduced details in remote store stats for oplog export/import to user - Improvement: Transfer speed for oplog export/import is now an overall number rather than average of speed per single request
Diffstat (limited to 'src/zenstore/blockstore.cpp')
-rw-r--r--src/zenstore/blockstore.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/zenstore/blockstore.cpp b/src/zenstore/blockstore.cpp
index a576ff022..644ddf7b4 100644
--- a/src/zenstore/blockstore.cpp
+++ b/src/zenstore/blockstore.cpp
@@ -1093,7 +1093,6 @@ BlockStore::CompactBlocks(const BlockStoreCompactState& CompactState,
NiceBytes(MovedSize));
});
- uint64_t WriteOffset = m_MaxBlockSize + 1u; // Force detect a new block
uint32_t NewBlockIndex = 0;
MovedChunksArray MovedChunks;
@@ -1188,8 +1187,11 @@ BlockStore::CompactBlocks(const BlockStoreCompactState& CompactState,
std::sort(SortedChunkIndexes.begin(), SortedChunkIndexes.end(), [&ChunkLocations](size_t Lhs, size_t Rhs) {
return ChunkLocations[Lhs].Offset < ChunkLocations[Rhs].Offset;
});
- BasicFileBuffer SourceFileBuffer(OldBlockFile->GetBasicFile(), Min(65536u, OldBlockSize));
- uint64_t MovedFromBlock = 0;
+ BasicFileBuffer SourceFileBuffer(OldBlockFile->GetBasicFile(), Min(65536u, OldBlockSize));
+
+ uint64_t WriteOffset = m_MaxBlockSize + 1u; // Force detect a new block
+ uint64_t WrittenBytesToBlock = 0;
+ uint64_t MovedFromBlock = 0;
std::vector<uint8_t> Chunk;
for (const size_t& ChunkIndex : SortedChunkIndexes)
{
@@ -1295,19 +1297,22 @@ BlockStore::CompactBlocks(const BlockStoreCompactState& CompactState,
NiceBytes(Space.Free + ReclaimedSpace));
}
NewBlockFile->Create(m_MaxBlockSize);
- NewBlockIndex = NextBlockIndex;
- WriteOffset = 0;
- TargetFileBuffer = std::make_unique<BasicFileWriter>(NewBlockFile->GetBasicFile(), Min(65536u, m_MaxBlockSize));
+ NewBlockIndex = NextBlockIndex;
+ WriteOffset = 0;
+ AddedSize += WrittenBytesToBlock;
+ WrittenBytesToBlock = 0;
+ TargetFileBuffer = std::make_unique<BasicFileWriter>(NewBlockFile->GetBasicFile(), Min(65536u, m_MaxBlockSize));
}
TargetFileBuffer->Write(Chunk.data(), ChunkLocation.Size, WriteOffset);
MovedChunks.push_back(
{ChunkIndex, {.BlockIndex = NewBlockIndex, .Offset = gsl::narrow<uint32_t>(WriteOffset), .Size = ChunkLocation.Size}});
- uint64_t WriteEndOffset = WriteOffset + ChunkLocation.Size;
- MovedFromBlock += (WriteEndOffset - WriteOffset);
- WriteOffset = RoundUp(WriteEndOffset, PayloadAlignment);
- AddedSize += Chunk.size();
+ WrittenBytesToBlock = WriteOffset + ChunkLocation.Size;
+
+ MovedFromBlock += RoundUp(ChunkLocation.Offset + ChunkLocation.Size, PayloadAlignment) - ChunkLocation.Offset;
+ WriteOffset = RoundUp(WriteOffset + ChunkLocation.Size, PayloadAlignment);
}
+ AddedSize += WrittenBytesToBlock;
ZEN_INFO("{}moved {} chunks ({}) from '{}' to new block, freeing {}",
LogPrefix,
KeepChunkIndexes.size(),