1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-12-12 11:01:17 +03:00

Fixed a race in Cache usage during delete & truncate ops.

An object could be flushed between the existence check & the delete
done by delete() & truncate().  Made it atomic within Cache.
This commit is contained in:
Patrick LeBlanc
2019-05-17 09:07:49 -05:00
parent 886acd8b08
commit eb3608bf70
4 changed files with 44 additions and 34 deletions

View File

@@ -453,6 +453,34 @@ void Cache::rename(const string &oldKey, const string &newKey, ssize_t sizediff)
currentCacheSize += sizediff;
}
int Cache::ifExistsThenDelete(const string &key)
{
bf::path cachedPath = prefix / key;
bf::path journalPath = journalPrefix / (key + ".journal");
boost::unique_lock<boost::recursive_mutex> s(lru_mutex);
bool objectExists = false;
bool journalExists = bf::exists(journalPath);
auto it = m_lru.find(key);
if (it != m_lru.end())
{
objectExists = true;
lru.erase(it->lit);
m_lru.erase(it);
}
assert(objectExists == bf::exists(cachedPath));
size_t objectSize = (objectExists ? bf::file_size(cachedPath) : 0);
//size_t objectSize = (objectExists ? MetadataFile::getLengthFromKey(key) : 0);
size_t journalSize = (journalExists ? bf::file_size(journalPath) : 0);
currentCacheSize -= (objectSize + journalSize);
//assert(!objectExists || objectSize == bf::file_size(cachedPath));
return (objectExists ? 1 : 0) | (journalExists ? 2 : 0);
}
size_t Cache::getCurrentCacheSize() const
{
return currentCacheSize;