diff --git a/server/modules/filter/cache/cache_storage_api.h b/server/modules/filter/cache/cache_storage_api.h index cc6012ae5..1ba51d96a 100644 --- a/server/modules/filter/cache/cache_storage_api.h +++ b/server/modules/filter/cache/cache_storage_api.h @@ -143,6 +143,18 @@ typedef struct cache_storage_api uint64_t max_size, int argc, char* argv[]); + /** + * Create a key for a GWBUF. + * + * @param query An SQL query. Must be one contiguous buffer. + * @param key Pointer to key. + * + * @return CACHE_RESULT_OK if a key was created, otherwise some error code. + */ + cache_result_t (*getKey)(const char* default_db, + const GWBUF* query, + CACHE_KEY* key); + /** * Frees an CACHE_STORAGE instance earlier created with createInstance. * @@ -164,20 +176,6 @@ typedef struct cache_storage_api cache_result_t (*getInfo)(CACHE_STORAGE* storage, uint32_t what, json_t** info); - /** - * Create a key for a GWBUF. - * - * @param storage Pointer to a CACHE_STORAGE. - * @param query An SQL query. Must be one contiguous buffer. - * @param key Pointer to key. - * - * @return CACHE_RESULT_OK if a key was created, otherwise some error code. - */ - cache_result_t (*getKey)(CACHE_STORAGE* storage, - const char* default_db, - const GWBUF* query, - CACHE_KEY* key); - /** * Get a value from the cache. * diff --git a/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.cc b/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.cc index 6227d97d4..9cf6a154e 100644 --- a/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.cc +++ b/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.cc @@ -46,6 +46,7 @@ InMemoryStorage::~InMemoryStorage() { } +// static cache_result_t InMemoryStorage::get_key(const char* zdefault_db, const GWBUF* pquery, CACHE_KEY* pkey) { ss_dassert(GWBUF_IS_CONTIGUOUS(pquery)); diff --git a/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.hh b/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.hh index 7a40213fa..02cc6232d 100644 --- a/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.hh +++ b/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.hh @@ -24,7 +24,7 @@ class InMemoryStorage public: virtual ~InMemoryStorage(); - cache_result_t get_key(const char* zdefault_db, const GWBUF* pquery, CACHE_KEY* pkey); + static cache_result_t get_key(const char* zdefault_db, const GWBUF* pquery, CACHE_KEY* pkey); virtual cache_result_t get_info(uint32_t what, json_t** ppInfo) const = 0; virtual cache_result_t get_value(const CACHE_KEY& key, uint32_t flags, GWBUF** ppresult) = 0; diff --git a/server/modules/filter/cache/storage/storage_inmemory/storage_inmemory.cc b/server/modules/filter/cache/storage/storage_inmemory/storage_inmemory.cc index ecf8d85ed..a790e37b0 100644 --- a/server/modules/filter/cache/storage/storage_inmemory/storage_inmemory.cc +++ b/server/modules/filter/cache/storage/storage_inmemory/storage_inmemory.cc @@ -76,6 +76,21 @@ CACHE_STORAGE* createInstance(cache_thread_model_t model, return reinterpret_cast(sStorage.release()); } +cache_result_t getKey(const char* zdefault_db, + const GWBUF* pquery, + CACHE_KEY* pkey) +{ + // zdefault_db may be NULL. + ss_dassert(pquery); + ss_dassert(pkey); + + cache_result_t result = CACHE_RESULT_ERROR; + + MXS_EXCEPTION_GUARD(result = InMemoryStorage::get_key(zdefault_db, pquery, pkey)); + + return result; +} + void freeInstance(CACHE_STORAGE* pinstance) { MXS_EXCEPTION_GUARD(delete reinterpret_cast(pinstance)); @@ -94,25 +109,6 @@ cache_result_t getInfo(CACHE_STORAGE* pStorage, return result; } -cache_result_t getKey(CACHE_STORAGE* pstorage, - const char* zdefault_db, - const GWBUF* pquery, - CACHE_KEY* pkey) -{ - ss_dassert(pstorage); - // zdefault_db may be NULL. - ss_dassert(pquery); - ss_dassert(pkey); - - cache_result_t result = CACHE_RESULT_ERROR; - - MXS_EXCEPTION_GUARD(result = reinterpret_cast(pstorage)->get_key(zdefault_db, - pquery, - pkey)); - - return result; -} - cache_result_t getValue(CACHE_STORAGE* pstorage, const CACHE_KEY* pkey, uint32_t flags, @@ -221,9 +217,9 @@ CACHE_STORAGE_API* CacheGetStorageAPI() { initialize, createInstance, + getKey, freeInstance, getInfo, - getKey, getValue, putValue, delValue, diff --git a/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.cc b/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.cc index be654f370..c5db5b7ad 100644 --- a/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.cc +++ b/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.cc @@ -361,32 +361,8 @@ unique_ptr RocksDBStorage::Create(const string& storageDirectory return sStorage; } -cache_result_t RocksDBStorage::getInfo(uint32_t what, json_t** ppInfo) const -{ - json_t* pInfo = json_object(); - - if (pInfo) - { - auto sStatistics = m_sDb->GetOptions().statistics; - - for_each(rocksdb::TickersNameMap.begin(), rocksdb::TickersNameMap.end(), - [pInfo, sStatistics](const std::pair& tickerName) { - json_t* pValue = json_integer(sStatistics->getTickerCount(tickerName.first)); - - if (pValue) - { - json_object_set(pInfo, tickerName.second.c_str(), pValue); - json_decref(pValue); - } - }); - - *ppInfo = pInfo; - } - - return pInfo ? CACHE_RESULT_OK : CACHE_RESULT_OUT_OF_RESOURCES; -} - -cache_result_t RocksDBStorage::getKey(const char* zDefaultDB, const GWBUF* pQuery, CACHE_KEY* pKey) +// static +cache_result_t RocksDBStorage::GetKey(const char* zDefaultDB, const GWBUF* pQuery, CACHE_KEY* pKey) { ss_dassert(GWBUF_IS_CONTIGUOUS(pQuery)); @@ -444,6 +420,31 @@ cache_result_t RocksDBStorage::getKey(const char* zDefaultDB, const GWBUF* pQuer return CACHE_RESULT_OK; } +cache_result_t RocksDBStorage::getInfo(uint32_t what, json_t** ppInfo) const +{ + json_t* pInfo = json_object(); + + if (pInfo) + { + auto sStatistics = m_sDb->GetOptions().statistics; + + for_each(rocksdb::TickersNameMap.begin(), rocksdb::TickersNameMap.end(), + [pInfo, sStatistics](const std::pair& tickerName) { + json_t* pValue = json_integer(sStatistics->getTickerCount(tickerName.first)); + + if (pValue) + { + json_object_set(pInfo, tickerName.second.c_str(), pValue); + json_decref(pValue); + } + }); + + *ppInfo = pInfo; + } + + return pInfo ? CACHE_RESULT_OK : CACHE_RESULT_OUT_OF_RESOURCES; +} + cache_result_t RocksDBStorage::getValue(const CACHE_KEY* pKey, uint32_t flags, GWBUF** ppResult) { // Use the root DB so that we get the value *with* the timestamp at the end. diff --git a/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.hh b/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.hh index eb0a3ab60..8a8a2dcb4 100644 --- a/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.hh +++ b/server/modules/filter/cache/storage/storage_rocksdb/rocksdbstorage.hh @@ -28,8 +28,9 @@ public: static SRocksDBStorage Create(const char* zName, uint32_t ttl, int argc, char* argv[]); ~RocksDBStorage(); + static cache_result_t GetKey(const char* zDefaultDB, const GWBUF* pQuery, CACHE_KEY* pKey); + cache_result_t getInfo(uint32_t flags, json_t** ppInfo) const; - cache_result_t getKey(const char* zDefaultDB, const GWBUF* pQuery, CACHE_KEY* pKey); cache_result_t getValue(const CACHE_KEY* pKey, uint32_t flags, GWBUF** ppResult); cache_result_t putValue(const CACHE_KEY* pKey, const GWBUF* pValue); cache_result_t delValue(const CACHE_KEY* pKey); diff --git a/server/modules/filter/cache/storage/storage_rocksdb/storage_rocksdb.cc b/server/modules/filter/cache/storage/storage_rocksdb/storage_rocksdb.cc index 366b6cbf8..d5f01b170 100644 --- a/server/modules/filter/cache/storage/storage_rocksdb/storage_rocksdb.cc +++ b/server/modules/filter/cache/storage/storage_rocksdb/storage_rocksdb.cc @@ -80,21 +80,17 @@ cache_result_t getInfo(CACHE_STORAGE* pStorage, return result; } -cache_result_t getKey(CACHE_STORAGE* pStorage, - const char* zDefaultDB, +cache_result_t getKey(const char* zDefaultDB, const GWBUF* pQuery, CACHE_KEY* pKey) { - ss_dassert(pStorage); // zDefaultDB may be NULL. ss_dassert(pQuery); ss_dassert(pKey); cache_result_t result = CACHE_RESULT_ERROR; - MXS_EXCEPTION_GUARD(result = reinterpret_cast(pStorage)->getKey(zDefaultDB, - pQuery, - pKey)); + MXS_EXCEPTION_GUARD(result = RocksDBStorage::GetKey(zDefaultDB, pQuery, pKey)); return result; } @@ -206,9 +202,9 @@ CACHE_STORAGE_API* CacheGetStorageAPI() { initialize, createInstance, + getKey, freeInstance, getInfo, - getKey, getValue, putValue, delValue, diff --git a/server/modules/filter/cache/storagefactory.cc b/server/modules/filter/cache/storagefactory.cc index 644c9f71a..4e129ff77 100644 --- a/server/modules/filter/cache/storagefactory.cc +++ b/server/modules/filter/cache/storagefactory.cc @@ -238,3 +238,11 @@ Storage* StorageFactory::createRawStorage(cache_thread_model_t model, return pStorage; } + +cache_result_t StorageFactory::get_key(const char* zDefaultDb, + const GWBUF* pQuery, + CACHE_KEY* pKey) const +{ + return m_pApi->getKey(zDefaultDb, pQuery, pKey); +} + diff --git a/server/modules/filter/cache/storagefactory.hh b/server/modules/filter/cache/storagefactory.hh index f9b2f41af..984e920d0 100644 --- a/server/modules/filter/cache/storagefactory.hh +++ b/server/modules/filter/cache/storagefactory.hh @@ -95,6 +95,19 @@ public: uint64_t max_size, int argc, char* argv[]); + /** + * Create a key for a GWBUF. + * + * @param zDefaultDb The default DB or NULL. + * @param query An SQL query. Must be one contiguous buffer. + * @param pKey Pointer to object where key will be stored. + * + * @return CACHE_RESULT_OK if a key was created, otherwise some error code. + */ + cache_result_t get_key(const char* zDefaultDb, + const GWBUF* pQuery, + CACHE_KEY* pKey) const; + private: StorageFactory(void* handle, CACHE_STORAGE_API* pApi, uint32_t capabilities); diff --git a/server/modules/filter/cache/storagereal.cc b/server/modules/filter/cache/storagereal.cc index c04325f29..e80d395aa 100644 --- a/server/modules/filter/cache/storagereal.cc +++ b/server/modules/filter/cache/storagereal.cc @@ -37,7 +37,7 @@ cache_result_t StorageReal::get_key(const char* zDefaultDb, const GWBUF* pQuery, CACHE_KEY* pKey) const { - return m_pApi->getKey(m_pStorage, zDefaultDb, pQuery, pKey); + return m_pApi->getKey(zDefaultDb, pQuery, pKey); } cache_result_t StorageReal::get_value(const CACHE_KEY& key,