aboutsummaryrefslogtreecommitdiff
path: root/zenstore/blockstore.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-05-01 22:55:43 +0200
committerDan Engelbrecht <[email protected]>2022-05-01 22:55:43 +0200
commit6e6035499b3fe40b22e1be5aee9ac3a9675d27b0 (patch)
treedba08d49e0c7f9f02654917ea81a1d86c683a5bb /zenstore/blockstore.cpp
parentcollectgarbage for compactcas and structured cache uses shared implementation (diff)
downloadzen-6e6035499b3fe40b22e1be5aee9ac3a9675d27b0.tar.xz
zen-6e6035499b3fe40b22e1be5aee9ac3a9675d27b0.zip
remove m_TotalSize for blockstore
fix scrub logic in structured cache store
Diffstat (limited to 'zenstore/blockstore.cpp')
-rw-r--r--zenstore/blockstore.cpp44
1 files changed, 23 insertions, 21 deletions
diff --git a/zenstore/blockstore.cpp b/zenstore/blockstore.cpp
index 309c99d1e..b4aa0f7c3 100644
--- a/zenstore/blockstore.cpp
+++ b/zenstore/blockstore.cpp
@@ -124,13 +124,11 @@ BlockStore::Initialize(const std::filesystem::path& BlocksBasePath,
m_BlocksBasePath = BlocksBasePath;
m_MaxBlockSize = MaxBlockSize;
- m_TotalSize = 0;
m_ChunkBlocks.clear();
std::unordered_set<uint32_t> KnownBlocks;
for (const auto& Entry : KnownLocations)
{
- m_TotalSize.fetch_add(Entry.Size, std::memory_order_seq_cst);
KnownBlocks.insert(Entry.BlockIndex);
}
@@ -287,7 +285,8 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot,
uint64_t ReadBlockLongestTimeUs = 0;
uint64_t TotalChunkCount = ChunkLocations.size();
uint64_t DeletedSize = 0;
- uint64_t OldTotalSize = m_TotalSize.load(std::memory_order::relaxed);
+ uint64_t OldTotalSize = 0;
+ uint64_t NewTotalSize = 0;
uint64_t MovedCount = 0;
uint64_t DeletedCount = 0;
@@ -305,7 +304,7 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot,
&DeletedSize,
OldTotalSize] {
ZEN_INFO(
- "garbage collect for '{}' DONE after {}, write lock: {} ({}), read lock: {} ({}), collected {} bytes, deleted #{} and moved "
+ "reclaim space for '{}' DONE after {}, write lock: {} ({}), read lock: {} ({}), collected {} bytes, deleted #{} and moved "
"#{} "
"of #{} "
"chunks ({}).",
@@ -340,11 +339,11 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot,
BlockDeleteChunks.reserve(BlockCount);
size_t GuesstimateCountPerBlock = TotalChunkCount / BlockCount / 2;
- size_t DeleteCount = 0;
- uint64_t NewTotalSize = 0;
+ size_t DeleteCount = 0;
for (size_t Index = 0; Index < TotalChunkCount; ++Index)
{
const BlockStoreLocation& Location = ChunkLocations[Index];
+ OldTotalSize += Location.Size;
if (Snapshot.ExcludeBlockIndexes.contains(Location.BlockIndex))
{
continue;
@@ -394,13 +393,12 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot,
if (DryRun)
{
- uint64_t TotalSize = m_TotalSize.load(std::memory_order_relaxed);
ZEN_INFO("garbage collect for '{}' DISABLED, found #{} {} chunks of total #{} {}",
m_BlocksBasePath,
DeleteCount,
- NiceBytes(TotalSize - NewTotalSize),
+ NiceBytes(OldTotalSize - NewTotalSize),
TotalChunkCount,
- NiceBytes(TotalSize));
+ OldTotalSize);
return;
}
@@ -415,7 +413,13 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot,
Ref<BlockStoreFile> OldBlockFile;
{
RwLock::SharedLockScope _i(m_InsertLock);
- OldBlockFile = m_ChunkBlocks[BlockIndex];
+ Stopwatch Timer;
+ const auto __ = MakeGuard([&Timer, &WriteBlockTimeUs, &WriteBlockLongestTimeUs] {
+ uint64_t ElapsedUs = Timer.GetElapsedTimeUs();
+ WriteBlockTimeUs += ElapsedUs;
+ WriteBlockLongestTimeUs = std::max(ElapsedUs, WriteBlockLongestTimeUs);
+ });
+ OldBlockFile = m_ChunkBlocks[BlockIndex];
ZEN_ASSERT(OldBlockFile);
}
@@ -432,10 +436,10 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot,
{
RwLock::ExclusiveLockScope _i(m_InsertLock);
Stopwatch Timer;
- const auto __ = MakeGuard([&Timer, &WriteBlockTimeUs, &WriteBlockLongestTimeUs] {
+ const auto __ = MakeGuard([&Timer, &ReadBlockTimeUs, &ReadBlockLongestTimeUs] {
uint64_t ElapsedUs = Timer.GetElapsedTimeUs();
- WriteBlockTimeUs += ElapsedUs;
- WriteBlockLongestTimeUs = std::max(ElapsedUs, WriteBlockLongestTimeUs);
+ ReadBlockTimeUs += ElapsedUs;
+ ReadBlockLongestTimeUs = std::max(ElapsedUs, ReadBlockLongestTimeUs);
});
m_ChunkBlocks[BlockIndex] = nullptr;
}
@@ -472,10 +476,10 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot,
MovedChunks.clear();
RwLock::ExclusiveLockScope __(m_InsertLock);
Stopwatch Timer;
- const auto ___ = MakeGuard([&Timer, &WriteBlockTimeUs, &WriteBlockLongestTimeUs] {
+ const auto ___ = MakeGuard([&Timer, &ReadBlockTimeUs, &ReadBlockLongestTimeUs] {
uint64_t ElapsedUs = Timer.GetElapsedTimeUs();
- WriteBlockTimeUs += ElapsedUs;
- WriteBlockLongestTimeUs = std::max(ElapsedUs, WriteBlockLongestTimeUs);
+ ReadBlockTimeUs += ElapsedUs;
+ ReadBlockLongestTimeUs = std::max(ElapsedUs, ReadBlockLongestTimeUs);
});
if (m_ChunkBlocks.size() == m_MaxBlockCount)
{
@@ -511,10 +515,10 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot,
NiceBytes(Space.Free + ReclaimedSpace));
RwLock::ExclusiveLockScope _l(m_InsertLock);
Stopwatch Timer;
- const auto __ = MakeGuard([&Timer, &WriteBlockTimeUs, &WriteBlockLongestTimeUs] {
+ const auto __ = MakeGuard([&Timer, &ReadBlockTimeUs, &ReadBlockLongestTimeUs] {
uint64_t ElapsedUs = Timer.GetElapsedTimeUs();
- WriteBlockTimeUs += ElapsedUs;
- WriteBlockLongestTimeUs = std::max(ElapsedUs, WriteBlockLongestTimeUs);
+ ReadBlockTimeUs += ElapsedUs;
+ ReadBlockLongestTimeUs = std::max(ElapsedUs, ReadBlockLongestTimeUs);
});
m_ChunkBlocks.erase(NextBlockIndex);
return;
@@ -571,8 +575,6 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot,
}
OldBlockFile = nullptr;
}
-
- return;
}
const char*