diff options
| author | Dan Engelbrecht <[email protected]> | 2022-05-02 10:53:41 +0200 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-05-02 10:53:41 +0200 |
| commit | dc589650427f2ab444a7ebf78fb59ee751a4c2c8 (patch) | |
| tree | bf3c37a143bd8707f6e2c0e2b8802f243f523d33 | |
| parent | refactor structured cache to use blockstore migrate (diff) | |
| download | zen-dc589650427f2ab444a7ebf78fb59ee751a4c2c8.tar.xz zen-dc589650427f2ab444a7ebf78fb59ee751a4c2c8.zip | |
use std::vector<std::pair>> instead of map
| -rw-r--r-- | zenserver/cache/structuredcachestore.cpp | 22 | ||||
| -rw-r--r-- | zenstore/blockstore.cpp | 8 | ||||
| -rw-r--r-- | zenstore/compactcas.cpp | 20 | ||||
| -rw-r--r-- | 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<DiskIndexEntry> MakeDiskIndexEntries(const std::unordered_map<IoHash, DiskLocation>& MovedChunks, - const std::vector<IoHash>& DeletedChunks) - { - std::vector<DiskIndexEntry> 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<size_t, BlockStoreLocation>& MovedChunks, - const std::vector<size_t>& RemovedChunks) { + const std::vector<std::pair<size_t, BlockStoreLocation>>& MovedChunks, + const std::vector<size_t>& RemovedChunks) { std::vector<DiskIndexEntry> 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<size_t, BlockStoreLocation> MovedChunks; - std::vector<uint8_t> Chunk; + std::vector<std::pair<size_t, BlockStoreLocation>> MovedChunks; + std::vector<uint8_t> 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<CasDiskIndexEntry> MakeCasDiskEntries(const std::unordered_map<IoHash, BlockStoreDiskLocation>& MovedChunks, - const std::vector<IoHash>& DeletedChunks) - { - std::vector<CasDiskIndexEntry> 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<size_t, BlockStoreLocation>& MovedChunks, - const std::vector<size_t>& RemovedChunks) { + const std::vector<std::pair<size_t, BlockStoreLocation>>& MovedChunks, + const std::vector<size_t>& RemovedChunks) { std::vector<CasDiskIndexEntry> 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<uint32_t> ExcludeBlockIndexes; size_t BlockCount; }; - typedef std::function<void(const std::unordered_map<size_t, BlockStoreLocation>& MovedChunks, const std::vector<size_t>& RemovedChunks)> + typedef std::function<void(const std::vector<std::pair<size_t, BlockStoreLocation>>& MovedChunks, + const std::vector<size_t>& RemovedChunks)> ReclaimCallback; typedef std::function<void(const BlockStoreLocation& Location)> WriteChunkCallback; typedef std::function<void(size_t ChunkIndex, const void* Data, uint64_t Size)> IterateChunksSmallSizeCallback; typedef std::function<void(size_t ChunkIndex, BasicFile& BlockFile, uint64_t Offset, uint64_t Size)> IterateChunksLargeSizeCallback; - - typedef std::function<void(const std::vector<std::pair<size_t, BlockStoreLocation>>& MovedChunks)> SplitCallback; + typedef std::function<void(const std::vector<std::pair<size_t, BlockStoreLocation>>& MovedChunks)> SplitCallback; void Initialize(const std::filesystem::path& BlocksBasePath, uint64_t MaxBlockSize, @@ -144,7 +144,7 @@ public: const std::vector<size_t>& KeepChunkIndexes, uint64_t PayloadAlignment, bool DryRun, - const ReclaimCallback& Callback = [](const std::unordered_map<size_t, BlockStoreLocation>&, const std::vector<size_t>&) {}); + const ReclaimCallback& Callback = [](const std::vector<std::pair<size_t, BlockStoreLocation>>&, const std::vector<size_t>&) {}); void IterateChunks(const std::vector<BlockStoreLocation>& ChunkLocations, IterateChunksSmallSizeCallback SmallSizeCallback, IterateChunksLargeSizeCallback LargeSizeCallback); |