From 9204f7b629e034b404a48fd014aa6855d8a7c4e9 Mon Sep 17 00:00:00 2001 From: John Sully Date: Thu, 4 Jun 2020 22:18:03 -0400 Subject: [PATCH] Fix race when we free an item before we finish writing to disk making it temporarily unavailable Former-commit-id: 6139cfee295261d0210f2af6217c2a23eeaf52b8 --- src/IStorage.h | 3 +++ src/db.cpp | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/IStorage.h b/src/IStorage.h index 3ac6d9c59..16526e80d 100644 --- a/src/IStorage.h +++ b/src/IStorage.h @@ -29,6 +29,9 @@ public: virtual void beginWriteBatch() {} // NOP virtual void endWriteBatch() {} // NOP + virtual void batch_lock() {} // NOP + virtual void batch_unlock() {} // NOP + virtual void flush() = 0; /* This is permitted to be a shallow clone */ diff --git a/src/db.cpp b/src/db.cpp index b866948fa..4c7867bd7 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -2514,12 +2514,19 @@ bool redisDbPersistentData::removeCachedValue(const char *key) { serverAssert(m_spstorage != nullptr); // First ensure its not a pending key + if (m_spstorage != nullptr) + m_spstorage->batch_lock(); + auto itr = m_setchanged.find(key); if (itr != m_setchanged.end()) return false; // can't evict // since we write ASAP the database already has a valid copy so safe to delete dictDelete(m_pdict, key); + + if (m_spstorage != nullptr) + m_spstorage->batch_unlock(); + return true; }