aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-10-27 12:09:53 +0200
committerGitHub <[email protected]>2023-10-27 12:09:53 +0200
commita1a30be7ea68ccd94cb02f2fba0a3435b616a455 (patch)
treec39c1ff07bbb2306fd3ffe6c481b94d816347ff1
parentblock sending error reports from sentry_sink to Sentry unless the log is actu... (diff)
downloadzen-a1a30be7ea68ccd94cb02f2fba0a3435b616a455.tar.xz
zen-a1a30be7ea68ccd94cb02f2fba0a3435b616a455.zip
fix CacheBucket::CollectGarbage removing standalone entries without an exclusive lock (#502)
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/zenserver/cache/cachedisklayer.cpp11
2 files changed, 8 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7f3a212ac..ff8f0a4e7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,6 @@
##
- Bugfix: Block sending error reports from sentry_sink to Sentry unless the log is actually an error log
+- Bugfix: Make sure we have an exclusive lock in CacheBucket::CollectGarbage when removing standalone entries from the index
## 0.2.29
- Feature: Add `skipdelete` parameter to `admin/gc` endpoint to do a dry run of GC
diff --git a/src/zenserver/cache/cachedisklayer.cpp b/src/zenserver/cache/cachedisklayer.cpp
index f755436e0..2efec1e66 100644
--- a/src/zenserver/cache/cachedisklayer.cpp
+++ b/src/zenserver/cache/cachedisklayer.cpp
@@ -1687,11 +1687,15 @@ ZenCacheDiskLayer::CacheBucket::CollectGarbage(GcContext& GcCtx, std::atomic_uin
}
if (GcCtx.IsDeletionMode())
{
+ IndexLock.ReleaseNow();
+ RwLock::ExclusiveLockScope __(m_IndexLock);
for (const auto& Entry : ExpiredStandaloneEntries)
{
- m_Index.erase(Entry.Key);
- m_StandaloneSize.fetch_sub(Entry.Location.Size(), std::memory_order::relaxed);
- DeletedChunks.insert(Entry.Key);
+ if (m_Index.erase(Entry.Key) == 1)
+ {
+ m_StandaloneSize.fetch_sub(Entry.Location.Size(), std::memory_order::relaxed);
+ DeletedChunks.insert(Entry.Key);
+ }
}
m_SlogFile.Append(ExpiredStandaloneEntries);
}
@@ -2875,7 +2879,6 @@ ZenCacheDiskLayer::MemCacheTrim()
std::vector<CacheBucket*> Buckets;
{
RwLock::SharedLockScope __(m_Lock);
- RwLock::SharedLockScope _(m_Lock);
Buckets.reserve(m_Buckets.size());
for (auto& Kv : m_Buckets)
{