From b79bfa3b727e680eac848c5226a76122e9565827 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Wed, 30 Mar 2022 10:49:56 +0200 Subject: No need to take exclusive lock while gathering references --- zenserver/cache/structuredcachestore.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'zenserver/cache/structuredcachestore.cpp') diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index de5bccc3a..d5b892d06 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -757,7 +757,7 @@ ZenCacheDiskLayer::CacheBucket::GatherReferences(GcContext& GcCtx) const GcClock::Tick ExpireTicks = ExpireTime.time_since_epoch().count(); - RwLock::ExclusiveLockScope _(m_IndexLock); + RwLock::SharedLockScope _(m_IndexLock); std::vector ValidKeys; std::vector ExpiredKeys; -- cgit v1.2.3 From ddb2586b9e48003684a3cb88217bec04700730f0 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Wed, 30 Mar 2022 10:51:34 +0200 Subject: Fix bucket creation race condition in ZenCacheMemoryLayer::Put --- zenserver/cache/structuredcachestore.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'zenserver/cache/structuredcachestore.cpp') diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index d5b892d06..3d7fac13b 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -263,7 +263,15 @@ ZenCacheMemoryLayer::Put(std::string_view InBucket, const IoHash& HashKey, const RwLock::ExclusiveLockScope _(m_Lock); - Bucket = &m_Buckets[std::string(InBucket)]; + auto it = m_Buckets.find(std::string(InBucket)); + if (it != m_Buckets.end()) + { + Bucket = &it->second; + } + else + { + Bucket = &m_Buckets[std::string(InBucket)]; + } } // Note that since the underlying IoBuffer is retained, the content type is also -- cgit v1.2.3 From 8246081588870f7afcefacd9ea5fbcc44bfa4c47 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Wed, 30 Mar 2022 13:09:48 +0200 Subject: cleanup --- zenserver/cache/structuredcachestore.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'zenserver/cache/structuredcachestore.cpp') diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index 3d7fac13b..66240f0c6 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -249,11 +249,9 @@ ZenCacheMemoryLayer::Put(std::string_view InBucket, const IoHash& HashKey, const { RwLock::SharedLockScope _(m_Lock); - auto it = m_Buckets.find(std::string(InBucket)); - - if (it != m_Buckets.end()) + if (auto It = m_Buckets.find(std::string(InBucket)); It != m_Buckets.end()) { - Bucket = &it->second; + Bucket = &It->second; } } @@ -263,10 +261,9 @@ ZenCacheMemoryLayer::Put(std::string_view InBucket, const IoHash& HashKey, const RwLock::ExclusiveLockScope _(m_Lock); - auto it = m_Buckets.find(std::string(InBucket)); - if (it != m_Buckets.end()) + if (auto It = m_Buckets.find(std::string(InBucket)); It != m_Buckets.end()) { - Bucket = &it->second; + Bucket = &It->second; } else { -- cgit v1.2.3