Adjust for RocksDB behaviour

RocksDB returns success when deleting a non-existing key. To deal
with that the book-keeping of LRUStorage is used and the real
underlying storage is used only if LRUStorage thinks a particular
key exists.
This commit is contained in:
Johan Wikman
2016-12-15 10:33:57 +02:00
parent bb9b5a87c1
commit 2751640a02

View File

@ -75,35 +75,32 @@ cache_result_t LRUStorage::do_get_value(const CACHE_KEY& key,
uint32_t flags, uint32_t flags,
GWBUF** ppvalue) const GWBUF** ppvalue) const
{ {
cache_result_t result = CACHE_RESULT_NOT_FOUND;
NodesByKey::iterator i = nodes_by_key_.find(key); NodesByKey::iterator i = nodes_by_key_.find(key);
bool existed = (i != nodes_by_key_.end()); bool existed = (i != nodes_by_key_.end());
cache_result_t result = pstorage_->get_value(key, flags, ppvalue); if (existed)
if ((result == CACHE_RESULT_OK) || (result == CACHE_RESULT_STALE))
{ {
++stats_.hits; result = pstorage_->get_value(key, flags, ppvalue);
if (existed) if ((result == CACHE_RESULT_OK) || (result == CACHE_RESULT_STALE))
{ {
++stats_.hits;
move_to_head(i->second); move_to_head(i->second);
} }
else else if (result == CACHE_RESULT_NOT_FOUND)
{ {
ss_dassert(!true); ++stats_.misses;
MXS_ERROR("Item found in storage, but not in key mapping.");
// We'll assume this is because ttl has hit in. We need to remove
// the node and the mapping.
free_node(i);
} }
} }
else else
{ {
++stats_.misses; ++stats_.misses;
if (existed && (result == CACHE_RESULT_NOT_FOUND))
{
// We'll assume this is because ttl has hit in. We need to remove
// the node and the mapping.
free_node(i);
}
} }
return result; return result;
@ -165,34 +162,30 @@ cache_result_t LRUStorage::do_put_value(const CACHE_KEY& key, const GWBUF* pvalu
cache_result_t LRUStorage::do_del_value(const CACHE_KEY& key) cache_result_t LRUStorage::do_del_value(const CACHE_KEY& key)
{ {
cache_result_t result = CACHE_RESULT_NOT_FOUND;
NodesByKey::iterator i = nodes_by_key_.find(key); NodesByKey::iterator i = nodes_by_key_.find(key);
bool existed = (i != nodes_by_key_.end()); bool existed = (i != nodes_by_key_.end());
cache_result_t result = pstorage_->del_value(key); if (existed)
if (result == CACHE_RESULT_OK)
{ {
if (!existed) result = pstorage_->del_value(key);
if ((result == CACHE_RESULT_OK) || (result == CACHE_RESULT_NOT_FOUND))
{ {
ss_dassert(!true); // If it wasn't found, we'll assume it was because ttl has hit in.
MXS_ERROR("Key was found from storage, but not from LRU register."); ++stats_.deletes;
ss_dassert(stats_.size >= i->second->size());
ss_dassert(stats_.items > 0);
stats_.size -= i->second->size();
--stats_.items;
free_node(i);
} }
} }
if (existed && ((result == CACHE_RESULT_OK) || (result == CACHE_RESULT_NOT_FOUND)))
{
// If it wasn't found, we'll assume it was because ttl has hit in.
++stats_.deletes;
ss_dassert(stats_.size >= i->second->size());
ss_dassert(stats_.items > 0);
stats_.size -= i->second->size();
--stats_.items;
free_node(i);
}
return result; return result;
} }