aboutsummaryrefslogtreecommitdiff
path: root/src/zenstore/blockstore.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2024-10-02 10:08:46 +0200
committerGitHub Enterprise <[email protected]>2024-10-02 10:08:46 +0200
commit0b86039ebbbce0138790f9039189dddb4b70b73a (patch)
treee3deda42d154cb779ff8ab3dd29d04a5dc4069f0 /src/zenstore/blockstore.cpp
parentPorject -> Project (diff)
downloadzen-0b86039ebbbce0138790f9039189dddb4b70b73a.tar.xz
zen-0b86039ebbbce0138790f9039189dddb4b70b73a.zip
gc block size target max size (#180)
* If a block is small (less than half max size) we add it to blocks to compact Sort blocks when iterating over them * do compact of block stores even if no new unused are found * do compact phase even if bucket is empty
Diffstat (limited to 'src/zenstore/blockstore.cpp')
-rw-r--r--src/zenstore/blockstore.cpp39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/zenstore/blockstore.cpp b/src/zenstore/blockstore.cpp
index 592d1c7fb..2ae51d627 100644
--- a/src/zenstore/blockstore.cpp
+++ b/src/zenstore/blockstore.cpp
@@ -383,6 +383,11 @@ BlockStore::GetBlocksToCompact(const BlockUsageMap& BlockUsage, uint32_t BlockUs
BlockEntryCountMap Result;
{
RwLock::SharedLockScope InsertLock(m_InsertLock);
+
+ const uint64_t SmallBlockLimit = m_MaxBlockSize / 2;
+
+ std::vector<uint32_t> SmallBlockIndexes;
+
for (const auto& It : m_ChunkBlocks)
{
uint32_t BlockIndex = It.first;
@@ -403,35 +408,53 @@ BlockStore::GetBlocksToCompact(const BlockUsageMap& BlockUsage, uint32_t BlockUs
UsedCount = UsageIt->second.EntryCount;
}
- uint64_t BlockSize = It.second ? It.second->FileSize() : 0u;
- if (BlockSize == 0)
+ uint64_t PhysicalSize = It.second ? It.second->FileSize() : 0u;
+ if (PhysicalSize == 0)
{
Result.insert_or_assign(BlockIndex, UsedCount);
continue;
}
+ bool IsBelowUnusedLimit = false;
+
if (BlockUsageThresholdPercent == 100)
{
- if (UsedSize < BlockSize)
+ if (UsedSize < PhysicalSize)
{
- Result.insert_or_assign(BlockIndex, UsedCount);
+ IsBelowUnusedLimit = true;
}
}
else if (BlockUsageThresholdPercent == 0)
{
if (UsedSize == 0)
{
- Result.insert_or_assign(BlockIndex, UsedCount);
+ IsBelowUnusedLimit = true;
}
}
else
{
- const uint32_t UsedPercent = UsedSize < BlockSize ? gsl::narrow<uint32_t>((100 * UsedSize) / BlockSize) : 100u;
+ const uint32_t UsedPercent = UsedSize < PhysicalSize ? gsl::narrow<uint32_t>((100 * UsedSize) / PhysicalSize) : 100u;
if (UsedPercent < BlockUsageThresholdPercent)
{
- Result.insert_or_assign(BlockIndex, UsedCount);
+ IsBelowUnusedLimit = true;
}
}
+
+ if (IsBelowUnusedLimit)
+ {
+ Result.insert_or_assign(BlockIndex, UsedCount);
+ }
+ else if (PhysicalSize < SmallBlockLimit)
+ {
+ Result.insert_or_assign(BlockIndex, UsedCount);
+ SmallBlockIndexes.push_back(BlockIndex);
+ }
+ }
+
+ // If we only find one small block to compact, let it be.
+ if (SmallBlockIndexes.size() == 1 && Result.size() == 1)
+ {
+ Result.erase(SmallBlockIndexes[0]);
}
}
return Result;
@@ -1569,7 +1592,7 @@ BlockStore::CompactBlocks(const BlockStoreCompactState& CompactState,
KeepChunkIndexes.size(),
NiceBytes(MovedFromBlock),
GetBlockPath(m_BlocksBasePath, BlockIndex).filename(),
- NiceBytes(OldBlockSize - MovedFromBlock));
+ OldBlockSize > MovedFromBlock ? NiceBytes(OldBlockSize - MovedFromBlock) : 0);
}
if (TargetFileBuffer)
{