aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--zenserver/cache/structuredcachestore.cpp21
-rw-r--r--zenstore/blockstore.cpp44
-rw-r--r--zenstore/include/zenstore/blockstore.h1
3 files changed, 35 insertions, 31 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp
index d313cd0c2..f26d599ab 100644
--- a/zenserver/cache/structuredcachestore.cpp
+++ b/zenserver/cache/structuredcachestore.cpp
@@ -1376,10 +1376,7 @@ ZenCacheDiskLayer::CacheBucket::Get(const IoHash& HashKey, ZenCacheValue& OutVal
{
return GetStandaloneCacheValue(Location, HashKey, OutValue);
}
- if (GetInlineCacheValue(Location, OutValue))
- {
- return true;
- }
+ return GetInlineCacheValue(Location, OutValue);
}
return false;
@@ -1463,16 +1460,16 @@ ZenCacheDiskLayer::CacheBucket::Scrub(ScrubContext& Ctx)
if (Loc.IsFlagSet(DiskLocation::kStandaloneFile))
{
- if (GetInlineCacheValue(Loc, Value))
+ if (GetStandaloneCacheValue(Loc, HashKey, Value))
{
- // Validate contents
+ // Note: we cannot currently validate contents since we don't
+ // have a content hash!
continue;
}
}
- else if (GetStandaloneCacheValue(Loc, HashKey, Value))
+ else if (GetInlineCacheValue(Loc, Value))
{
- // Note: we cannot currently validate contents since we don't
- // have a content hash!
+ // Validate contents
continue;
}
// Value not found
@@ -1724,6 +1721,12 @@ ZenCacheDiskLayer::CacheBucket::CollectGarbage(GcContext& GcCtx)
{
RwLock::SharedLockScope __(m_IndexLock);
+ Stopwatch Timer;
+ const auto ____ = MakeGuard([&Timer, &WriteBlockTimeUs, &WriteBlockLongestTimeUs] {
+ uint64_t ElapsedUs = Timer.GetElapsedTimeUs();
+ WriteBlockTimeUs += ElapsedUs;
+ WriteBlockLongestTimeUs = std::max(ElapsedUs, WriteBlockLongestTimeUs);
+ });
if (m_Index.contains(Key))
{
// Someone added it back, let the file on disk be
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*
diff --git a/zenstore/include/zenstore/blockstore.h b/zenstore/include/zenstore/blockstore.h
index 1eff46367..31d9145f9 100644
--- a/zenstore/include/zenstore/blockstore.h
+++ b/zenstore/include/zenstore/blockstore.h
@@ -158,7 +158,6 @@ private:
uint64_t m_MaxBlockSize = 1u << 28;
uint64_t m_MaxBlockCount = BlockStoreDiskLocation::MaxBlockIndex + 1;
std::filesystem::path m_BlocksBasePath;
- std::atomic_uint64_t m_TotalSize{};
};
void blockstore_forcelink();