aboutsummaryrefslogtreecommitdiff
path: root/src/zenstore/blockstore.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zenstore/blockstore.cpp')
-rw-r--r--src/zenstore/blockstore.cpp31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/zenstore/blockstore.cpp b/src/zenstore/blockstore.cpp
index 918f464ac..71e306eca 100644
--- a/src/zenstore/blockstore.cpp
+++ b/src/zenstore/blockstore.cpp
@@ -282,10 +282,10 @@ BlockStore::SyncExistingBlocksOnDisk(const BlockIndexSet& KnownLocations)
}
}
-std::vector<uint32_t>
-BlockStore::GetBlocksToCompact(const std::unordered_map<uint32_t, uint64_t>& BlockUsage, uint32_t BlockUsageThresholdPercent)
+BlockStore::BlockEntryCountMap
+BlockStore::GetBlocksToCompact(const BlockUsageMap& BlockUsage, uint32_t BlockUsageThresholdPercent)
{
- std::unordered_set<uint32_t> Result;
+ BlockEntryCountMap Result;
{
RwLock::SharedLockScope InsertLock(m_InsertLock);
for (const auto& It : m_ChunkBlocks)
@@ -299,31 +299,34 @@ BlockStore::GetBlocksToCompact(const std::unordered_map<uint32_t, uint64_t>& Blo
{
continue;
}
- uint64_t BlockSize = It.second ? It.second->FileSize() : 0u;
- if (BlockSize == 0)
+
+ uint64_t UsedSize = 0;
+ uint32_t UsedCount = 0;
+ if (auto UsageIt = BlockUsage.find(BlockIndex); UsageIt != BlockUsage.end())
{
- Result.insert(BlockIndex);
- continue;
+ UsedSize = UsageIt->second.DiskUsage;
+ UsedCount = UsageIt->second.EntryCount;
}
- uint64_t UsedSize = 0;
- if (auto UsageIt = BlockUsage.find(BlockIndex); UsageIt != BlockUsage.end())
+ uint64_t BlockSize = It.second ? It.second->FileSize() : 0u;
+ if (BlockSize == 0)
{
- UsedSize = UsageIt->second;
+ Result.insert_or_assign(BlockIndex, UsedCount);
+ continue;
}
if (BlockUsageThresholdPercent == 100)
{
if (UsedSize < BlockSize)
{
- Result.insert(BlockIndex);
+ Result.insert_or_assign(BlockIndex, UsedCount);
}
}
else if (BlockUsageThresholdPercent == 0)
{
if (UsedSize == 0)
{
- Result.insert(BlockIndex);
+ Result.insert_or_assign(BlockIndex, UsedCount);
}
}
else
@@ -331,12 +334,12 @@ BlockStore::GetBlocksToCompact(const std::unordered_map<uint32_t, uint64_t>& Blo
const uint32_t UsedPercent = UsedSize < BlockSize ? gsl::narrow<uint32_t>((100 * UsedSize) / BlockSize) : 100u;
if (UsedPercent < BlockUsageThresholdPercent)
{
- Result.insert(BlockIndex);
+ Result.insert_or_assign(BlockIndex, UsedCount);
}
}
}
}
- return std::vector<uint32_t>(Result.begin(), Result.end());
+ return Result;
}
void