From dc589650427f2ab444a7ebf78fb59ee751a4c2c8 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Mon, 2 May 2022 10:53:41 +0200 Subject: use std::vector> instead of map --- zenserver/cache/structuredcachestore.cpp | 22 ++-------------------- zenstore/blockstore.cpp | 8 ++++---- zenstore/compactcas.cpp | 20 ++------------------ zenstore/include/zenstore/blockstore.h | 8 ++++---- 4 files changed, 12 insertions(+), 46 deletions(-) diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index e9c051f88..9cfb5fbf3 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -156,24 +156,6 @@ namespace { return BucketDir / (std::string("zen") + LegacyDataExtension); } - std::vector MakeDiskIndexEntries(const std::unordered_map& MovedChunks, - const std::vector& DeletedChunks) - { - std::vector result; - result.reserve(MovedChunks.size()); - for (const auto& MovedEntry : MovedChunks) - { - result.push_back({.Key = MovedEntry.first, .Location = MovedEntry.second}); - } - for (const IoHash& ChunkHash : DeletedChunks) - { - DiskLocation Location; - Location.Flags |= DiskLocation::kTombStone; - result.push_back({.Key = ChunkHash, .Location = Location}); - } - return result; - } - bool ValidateLegacyEntry(const LegacyDiskIndexEntry& Entry, std::string& OutReason) { if (Entry.Key == IoHash::Zero) @@ -1659,8 +1641,8 @@ ZenCacheDiskLayer::CacheBucket::CollectGarbage(GcContext& GcCtx) m_PayloadAlignment, false, [this, &DeletedChunks, &ChunkIndexToChunkHash, &Index, &ReadBlockTimeUs, &ReadBlockLongestTimeUs]( - const std::unordered_map& MovedChunks, - const std::vector& RemovedChunks) { + const std::vector>& MovedChunks, + const std::vector& RemovedChunks) { std::vector LogEntries; LogEntries.reserve(MovedChunks.size() + RemovedChunks.size()); for (const auto& Entry : MovedChunks) diff --git a/zenstore/blockstore.cpp b/zenstore/blockstore.cpp index 3358075ec..593ccc529 100644 --- a/zenstore/blockstore.cpp +++ b/zenstore/blockstore.cpp @@ -459,8 +459,8 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot, continue; } - std::unordered_map MovedChunks; - std::vector Chunk; + std::vector> MovedChunks; + std::vector Chunk; for (const size_t& ChunkIndex : KeepMap) { const BlockStoreLocation ChunkLocation = ChunkLocations[ChunkIndex]; @@ -541,8 +541,8 @@ BlockStore::ReclaimSpace(const ReclaimSnapshotState& Snapshot, } NewBlockFile->Write(Chunk.data(), Chunk.size(), WriteOffset); - MovedChunks[ChunkIndex] = {.BlockIndex = NewBlockIndex, .Offset = WriteOffset, .Size = Chunk.size()}; - WriteOffset = RoundUp(WriteOffset + Chunk.size(), PayloadAlignment); + MovedChunks.push_back({ChunkIndex, {.BlockIndex = NewBlockIndex, .Offset = WriteOffset, .Size = Chunk.size()}}); + WriteOffset = RoundUp(WriteOffset + Chunk.size(), PayloadAlignment); } Chunk.clear(); if (NewBlockFile) diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index 8d90ba186..6a9cba817 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -48,22 +48,6 @@ struct CasDiskIndexHeader static_assert(sizeof(CasDiskIndexHeader) == 32); namespace { - std::vector MakeCasDiskEntries(const std::unordered_map& MovedChunks, - const std::vector& DeletedChunks) - { - std::vector result; - result.reserve(MovedChunks.size()); - for (const auto& MovedEntry : MovedChunks) - { - result.push_back({.Key = MovedEntry.first, .Location = MovedEntry.second}); - } - for (const IoHash& ChunkHash : DeletedChunks) - { - result.push_back({.Key = ChunkHash, .Flags = CasDiskIndexEntry::kTombstone}); - } - return result; - } - const char* IndexExtension = ".uidx"; const char* LogExtension = ".ulog"; @@ -493,8 +477,8 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx) m_PayloadAlignment, false, [this, &DeletedChunks, &ChunkIndexToChunkHash, &LocationMap, &ReadBlockTimeUs, &ReadBlockLongestTimeUs]( - const std::unordered_map& MovedChunks, - const std::vector& RemovedChunks) { + const std::vector>& MovedChunks, + const std::vector& RemovedChunks) { std::vector LogEntries; LogEntries.reserve(MovedChunks.size() + RemovedChunks.size()); for (const auto& Entry : MovedChunks) diff --git a/zenstore/include/zenstore/blockstore.h b/zenstore/include/zenstore/blockstore.h index 0cef7600f..17f4e090e 100644 --- a/zenstore/include/zenstore/blockstore.h +++ b/zenstore/include/zenstore/blockstore.h @@ -117,13 +117,13 @@ public: std::unordered_set ExcludeBlockIndexes; size_t BlockCount; }; - typedef std::function& MovedChunks, const std::vector& RemovedChunks)> + typedef std::function>& MovedChunks, + const std::vector& RemovedChunks)> ReclaimCallback; typedef std::function WriteChunkCallback; typedef std::function IterateChunksSmallSizeCallback; typedef std::function IterateChunksLargeSizeCallback; - - typedef std::function>& MovedChunks)> SplitCallback; + typedef std::function>& MovedChunks)> SplitCallback; void Initialize(const std::filesystem::path& BlocksBasePath, uint64_t MaxBlockSize, @@ -144,7 +144,7 @@ public: const std::vector& KeepChunkIndexes, uint64_t PayloadAlignment, bool DryRun, - const ReclaimCallback& Callback = [](const std::unordered_map&, const std::vector&) {}); + const ReclaimCallback& Callback = [](const std::vector>&, const std::vector&) {}); void IterateChunks(const std::vector& ChunkLocations, IterateChunksSmallSizeCallback SmallSizeCallback, IterateChunksLargeSizeCallback LargeSizeCallback); -- cgit v1.2.3