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:
41
server/modules/filter/cache/lrustorage.cc
vendored
41
server/modules/filter/cache/lrustorage.cc
vendored
@ -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)
|
||||||
|
{
|
||||||
|
result = pstorage_->get_value(key, flags, ppvalue);
|
||||||
|
|
||||||
if ((result == CACHE_RESULT_OK) || (result == CACHE_RESULT_STALE))
|
if ((result == CACHE_RESULT_OK) || (result == CACHE_RESULT_STALE))
|
||||||
{
|
{
|
||||||
++stats_.hits;
|
++stats_.hits;
|
||||||
|
|
||||||
if (existed)
|
|
||||||
{
|
|
||||||
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,21 +162,16 @@ 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);
|
||||||
{
|
|
||||||
ss_dassert(!true);
|
|
||||||
MXS_ERROR("Key was found from storage, but not from LRU register.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (existed && ((result == CACHE_RESULT_OK) || (result == CACHE_RESULT_NOT_FOUND)))
|
if ((result == CACHE_RESULT_OK) || (result == CACHE_RESULT_NOT_FOUND))
|
||||||
{
|
{
|
||||||
// If it wasn't found, we'll assume it was because ttl has hit in.
|
// If it wasn't found, we'll assume it was because ttl has hit in.
|
||||||
++stats_.deletes;
|
++stats_.deletes;
|
||||||
@ -192,6 +184,7 @@ cache_result_t LRUStorage::do_del_value(const CACHE_KEY& key)
|
|||||||
|
|
||||||
free_node(i);
|
free_node(i);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user