aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/cache/cachedisklayer.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-10-20 13:31:09 +0200
committerGitHub <[email protected]>2023-10-20 13:31:09 +0200
commit7cdafe520216f01f27094dc4a353256071510922 (patch)
tree341e3f79cb5419c3bcb235773790d36aaff572bc /src/zenserver/cache/cachedisklayer.cpp
parentCache (rpc) activitity recording improvements (#482) (diff)
downloadzen-7cdafe520216f01f27094dc4a353256071510922.tar.xz
zen-7cdafe520216f01f27094dc4a353256071510922.zip
Don't prune block locations due to missing blocks a startup (#487)
* Don't prune block locations due to missing blocks a startup This makes the behaviour consistent with FileCas - you can have an index that is not fully backed by data. Asking for a location that is not backed by data results in getting an empty result back Also, don't try to GC blocks that are unknown to the block store at the time of snapshot (to avoid removing data that comes in after GatherReferences in GC)
Diffstat (limited to 'src/zenserver/cache/cachedisklayer.cpp')
-rw-r--r--src/zenserver/cache/cachedisklayer.cpp60
1 files changed, 3 insertions, 57 deletions
diff --git a/src/zenserver/cache/cachedisklayer.cpp b/src/zenserver/cache/cachedisklayer.cpp
index ebefa2e54..3cd725a27 100644
--- a/src/zenserver/cache/cachedisklayer.cpp
+++ b/src/zenserver/cache/cachedisklayer.cpp
@@ -604,8 +604,7 @@ ZenCacheDiskLayer::CacheBucket::OpenLog(const bool IsNew)
CreateDirectories(m_BucketDir);
- std::unordered_map<uint32_t, uint64_t> BlockSizes =
- m_BlockStore.Initialize(m_BlocksBasePath, MaxBlockSize, BlockStoreDiskLocation::MaxBlockIndex + 1);
+ m_BlockStore.Initialize(m_BlocksBasePath, MaxBlockSize, BlockStoreDiskLocation::MaxBlockIndex + 1);
if (std::filesystem::is_regular_file(IndexPath))
{
@@ -636,7 +635,6 @@ ZenCacheDiskLayer::CacheBucket::OpenLog(const bool IsNew)
std::vector<BlockStoreLocation> KnownLocations;
KnownLocations.reserve(m_Index.size());
- std::vector<DiskIndexEntry> BadEntries;
for (const auto& Entry : m_Index)
{
size_t EntryIndex = Entry.second;
@@ -649,48 +647,10 @@ ZenCacheDiskLayer::CacheBucket::OpenLog(const bool IsNew)
continue;
}
const BlockStoreLocation& BlockLocation = Location.GetBlockLocation(m_PayloadAlignment);
-
- auto BlockIt = BlockSizes.find(BlockLocation.BlockIndex);
- if (BlockIt == BlockSizes.end())
- {
- ZEN_WARN("Unknown block {} for entry {} in '{}'", BlockLocation.BlockIndex, Entry.first.ToHexString(), m_BucketDir);
- }
- else
- {
- uint64_t BlockSize = BlockIt->second;
- if (BlockLocation.Offset + BlockLocation.Size > BlockSize)
- {
- ZEN_WARN("Range is outside of block {} for entry {} in '{}'",
- BlockLocation.BlockIndex,
- Entry.first.ToHexString(),
- m_BucketDir);
- }
- else
- {
- KnownLocations.push_back(BlockLocation);
- continue;
- }
- }
-
- DiskLocation NewLocation = Payload.Location;
- NewLocation.Flags |= DiskLocation::kTombStone;
- BadEntries.push_back(DiskIndexEntry{.Key = Entry.first, .Location = NewLocation});
+ KnownLocations.push_back(BlockLocation);
}
- if (!BadEntries.empty())
- {
- m_SlogFile.Append(BadEntries);
- m_SlogFile.Flush();
-
- LogEntryCount += BadEntries.size();
-
- for (const DiskIndexEntry& BadEntry : BadEntries)
- {
- m_Index.erase(BadEntry.Key);
- }
- }
-
- m_BlockStore.Prune(KnownLocations);
+ m_BlockStore.CreateMissingBlocks(KnownLocations);
if (IsNew || LogEntryCount > 0)
{
@@ -1558,11 +1518,6 @@ ZenCacheDiskLayer::CacheBucket::CollectGarbage(GcContext& GcCtx)
}
DeleteCacheKeys.push_back(ChunkHash);
});
- if (DeleteCacheKeys.empty())
- {
- ZEN_DEBUG("garbage collect SKIPPED, for '{}', no expired cache keys found", m_BucketDir);
- return;
- }
auto __ = MakeGuard([&]() {
if (!DeletedChunks.empty())
@@ -1638,11 +1593,6 @@ ZenCacheDiskLayer::CacheBucket::CollectGarbage(GcContext& GcCtx)
WriteBlockTimeUs += ElapsedUs;
WriteBlockLongestTimeUs = std::max(ElapsedUs, WriteBlockLongestTimeUs);
});
- if (m_Index.empty())
- {
- ZEN_DEBUG("garbage collect SKIPPED, for '{}', container is empty", m_BucketDir);
- return;
- }
BlockStoreState = m_BlockStore.GetReclaimSnapshotState();
@@ -1769,10 +1719,6 @@ ZenCacheDiskLayer::CacheBucket::CollectGarbage(GcContext& GcCtx)
}
}
- if (TotalChunkHashes.empty())
- {
- return;
- }
TotalChunkCount = TotalChunkHashes.size();
std::vector<BlockStoreLocation> ChunkLocations;