Fix race when we free an item before we finish writing to disk making it temporarily unavailable

Former-commit-id: 6139cfee295261d0210f2af6217c2a23eeaf52b8
This commit is contained in:
John Sully 2020-06-04 22:18:03 -04:00
parent e522540e2f
commit 9204f7b629
2 changed files with 10 additions and 0 deletions

View File

@ -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 */

View File

@ -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;
}