From 1c0ddc112a6c18d411f1f3ae6d236ecc2bedcfaa Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Wed, 24 Apr 2024 13:53:54 +0200 Subject: iterate cas chunks (#59) - Improvement: Reworked GetChunkInfos in oplog store to reduce disk thrashing and improve performance --- src/zenstore/filecas.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/zenstore/filecas.cpp') diff --git a/src/zenstore/filecas.cpp b/src/zenstore/filecas.cpp index 7fbc2b9ad..88d64eb45 100644 --- a/src/zenstore/filecas.cpp +++ b/src/zenstore/filecas.cpp @@ -809,6 +809,37 @@ FileCasStrategy::FilterChunks(HashKeySet& InOutChunks) InOutChunks.RemoveHashesIf([&](const IoHash& Hash) { return HaveChunk(Hash); }); } +bool +FileCasStrategy::IterateChunks(std::span ChunkHashes, const std::function& Callback) +{ + std::vector FoundChunkIndexes; + { + RwLock::SharedLockScope _(m_Lock); + for (size_t ChunkIndex = 0; ChunkIndex < ChunkHashes.size(); ChunkIndex++) + { + if (auto KeyIt = m_Index.find(ChunkHashes[ChunkIndex]); KeyIt != m_Index.end()) + { + FoundChunkIndexes.push_back(ChunkIndex); + } + } + } + bool Continue = true; + for (size_t ChunkIndex : FoundChunkIndexes) + { + ShardingHelper Name(m_RootDirectory.c_str(), ChunkHashes[ChunkIndex]); + IoBuffer Payload = IoBufferBuilder::MakeFromFile(Name.ShardedPath.c_str()); + if (Payload) + { + Continue = Callback(ChunkIndex, std::move(Payload)); + if (!Continue) + { + break; + } + } + } + return Continue; +} + void FileCasStrategy::IterateChunks(std::function&& Callback) { -- cgit v1.2.3