Cache: Allow entries to be explicitly deleted
This commit is contained in:
11
server/modules/filter/cache/cache_storage_api.h
vendored
11
server/modules/filter/cache/cache_storage_api.h
vendored
@ -123,6 +123,17 @@ typedef struct cache_storage_api
|
|||||||
cache_result_t (*putValue)(CACHE_STORAGE* storage,
|
cache_result_t (*putValue)(CACHE_STORAGE* storage,
|
||||||
const char* key,
|
const char* key,
|
||||||
const GWBUF* value);
|
const GWBUF* value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a value from the cache.
|
||||||
|
*
|
||||||
|
* @param storage Pointer to a CACHE_STORAGE.
|
||||||
|
* @param key A key generated with getKey.
|
||||||
|
* @return CACHE_RESULT_OK if item was successfully deleted. Note that
|
||||||
|
* CACHE_RESULT_OK may be returned also if the entry was not present.
|
||||||
|
*/
|
||||||
|
cache_result_t (*delValue)(CACHE_STORAGE* storage,
|
||||||
|
const char* key);
|
||||||
} CACHE_STORAGE_API;
|
} CACHE_STORAGE_API;
|
||||||
|
|
||||||
#define CACHE_STORAGE_ENTRY_POINT "CacheGetStorageAPI"
|
#define CACHE_STORAGE_ENTRY_POINT "CacheGetStorageAPI"
|
||||||
|
@ -476,3 +476,14 @@ cache_result_t RocksDBStorage::putValue(const char* pKey, const GWBUF* pValue)
|
|||||||
|
|
||||||
return status.ok() ? CACHE_RESULT_OK : CACHE_RESULT_ERROR;
|
return status.ok() ? CACHE_RESULT_OK : CACHE_RESULT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cache_result_t RocksDBStorage::delValue(const char* pKey)
|
||||||
|
{
|
||||||
|
ss_dassert(pKey);
|
||||||
|
|
||||||
|
rocksdb::Slice key(pKey, ROCKSDB_KEY_LENGTH);
|
||||||
|
|
||||||
|
rocksdb::Status status = m_sDb->Delete(writeOptions(), key);
|
||||||
|
|
||||||
|
return status.ok() ? CACHE_RESULT_OK : CACHE_RESULT_ERROR;
|
||||||
|
}
|
||||||
|
@ -32,6 +32,7 @@ public:
|
|||||||
cache_result_t getKey(const char* zDefaultDB, const GWBUF* pQuery, char* pKey);
|
cache_result_t getKey(const char* zDefaultDB, const GWBUF* pQuery, char* pKey);
|
||||||
cache_result_t getValue(const char* pKey, uint32_t flags, GWBUF** ppResult);
|
cache_result_t getValue(const char* pKey, uint32_t flags, GWBUF** ppResult);
|
||||||
cache_result_t putValue(const char* pKey, const GWBUF* pValue);
|
cache_result_t putValue(const char* pKey, const GWBUF* pValue);
|
||||||
|
cache_result_t delValue(const char* pKey);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RocksDBStorage(std::unique_ptr<rocksdb::DBWithTTL>& sDb,
|
RocksDBStorage(std::unique_ptr<rocksdb::DBWithTTL>& sDb,
|
||||||
|
@ -147,6 +147,34 @@ cache_result_t putValue(CACHE_STORAGE* pStorage,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cache_result_t delValue(CACHE_STORAGE* pStorage,
|
||||||
|
const char* pKey)
|
||||||
|
{
|
||||||
|
ss_dassert(pStorage);
|
||||||
|
ss_dassert(pKey);
|
||||||
|
|
||||||
|
cache_result_t result = CACHE_RESULT_ERROR;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = reinterpret_cast<RocksDBStorage*>(pStorage)->delValue(pKey);
|
||||||
|
}
|
||||||
|
catch (const std::bad_alloc&)
|
||||||
|
{
|
||||||
|
MXS_OOM();
|
||||||
|
}
|
||||||
|
catch (const std::exception& x)
|
||||||
|
{
|
||||||
|
MXS_ERROR("Standard exception caught: %s", x.what());
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
MXS_ERROR("Unknown exception caught.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
@ -161,7 +189,8 @@ CACHE_STORAGE_API* CacheGetStorageAPI()
|
|||||||
freeInstance,
|
freeInstance,
|
||||||
getKey,
|
getKey,
|
||||||
getValue,
|
getValue,
|
||||||
putValue
|
putValue,
|
||||||
|
delValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
return &api;
|
return &api;
|
||||||
|
Reference in New Issue
Block a user