From b335dd7cccd20a539e165145e7e89b2b2e185ab4 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Thu, 27 May 2021 18:14:44 +0200 Subject: Added locks to protect against races in parallel oplog updates --- zenserver/projectstore.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'zenserver/projectstore.cpp') diff --git a/zenserver/projectstore.cpp b/zenserver/projectstore.cpp index c94a8fe35..6cf5dc161 100644 --- a/zenserver/projectstore.cpp +++ b/zenserver/projectstore.cpp @@ -269,13 +269,19 @@ ProjectStore::Oplog::ReplayLog() IoBuffer ProjectStore::Oplog::FindChunk(Oid ChunkId) { + RwLock::SharedLockScope _(m_OplogLock); + if (auto ChunkIt = m_ChunkMap.find(ChunkId); ChunkIt != m_ChunkMap.end()) { + _.ReleaseNow(); + return m_CasStore.FindChunk(ChunkIt->second); } if (auto FileIt = m_FileMap.find(ChunkId); FileIt != m_FileMap.end()) { + _.ReleaseNow(); + std::filesystem::path FilePath = m_OuterProject->RootDir / FileIt->second.ServerPath; return IoBufferBuilder::MakeFromFile(FilePath.native().c_str()); @@ -283,6 +289,8 @@ ProjectStore::Oplog::FindChunk(Oid ChunkId) if (auto MetaIt = m_MetaMap.find(ChunkId); MetaIt != m_MetaMap.end()) { + _.ReleaseNow(); + return m_CasStore.FindChunk(MetaIt->second); } @@ -292,6 +300,8 @@ ProjectStore::Oplog::FindChunk(Oid ChunkId) void ProjectStore::Oplog::IterateFileMap(std::function&& Fn) { + RwLock::SharedLockScope _(m_OplogLock); + for (const auto& Kv : m_FileMap) { Fn(Kv.first, Kv.second.ClientPath); @@ -301,6 +311,8 @@ ProjectStore::Oplog::IterateFileMap(std::function