diff options
| author | Dan Engelbrecht <[email protected]> | 2022-03-23 00:03:22 +0100 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-03-31 11:29:27 +0200 |
| commit | 9d63e798d72823a49579e73612ae9fc028f013d9 (patch) | |
| tree | 0afb4620890266acabc5714b0820fe7f2fb4fd1b /zenstore/compactcas.cpp | |
| parent | Use simpler locking for ChunkFile (diff) | |
| download | zen-9d63e798d72823a49579e73612ae9fc028f013d9.tar.xz zen-9d63e798d72823a49579e73612ae9fc028f013d9.zip | |
Reduce lock scope while fetching a chunk
Diffstat (limited to 'zenstore/compactcas.cpp')
| -rw-r--r-- | zenstore/compactcas.cpp | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index c49bfc8bf..63e5168c7 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -311,25 +311,24 @@ CasContainerStrategy::InsertChunk(IoBuffer Chunk, const IoHash& ChunkHash) IoBuffer CasContainerStrategy::FindChunk(const IoHash& ChunkHash) { - RwLock::SharedLockScope _(m_LocationMapLock); - - if (auto KeyIt = m_LocationMap.find(ChunkHash); KeyIt != m_LocationMap.end()) + std::shared_ptr<ChunkBlock> ChunkBlock; + CasLocation Location; { - CasLocation Location = KeyIt->second.Get(m_PayloadAlignment); - - if (auto BlockIt = m_ChunkBlocks.find(Location.BlockIndex); BlockIt != m_ChunkBlocks.end()) + RwLock::SharedLockScope _(m_LocationMapLock); + auto KeyIt = m_LocationMap.find(ChunkHash); + if (KeyIt == m_LocationMap.end()) { - if (BlockIt->second) // This happens if the data associated with the block is not found - ie the ucas file is deleted but - // the index not updated - { - return BlockIt->second->GetChunk(Location.Offset, Location.Size); - } + return IoBuffer(); } + Location = KeyIt->second.Get(m_PayloadAlignment); + auto BlockIt = m_ChunkBlocks.find(Location.BlockIndex); + if (BlockIt == m_ChunkBlocks.end()) + { + return IoBuffer(); + } + ChunkBlock = BlockIt->second; } - - // Not found - - return IoBuffer(); + return ChunkBlock->GetChunk(Location.Offset, Location.Size); } bool |