From bf3557794116b1e872c30218ba4c74bf6901006f Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Fri, 9 Dec 2016 09:57:04 +0200 Subject: [PATCH] Cache: Take MXS_EXCEPTION_GUARD into use --- .../storage_inmemory/storage_inmemory.cc | 133 ++++-------------- .../storage_rocksdb/storage_rocksdb.cc | 114 +++------------ 2 files changed, 42 insertions(+), 205 deletions(-) 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 ac5f5b0eb..755556f5c 100644 --- a/server/modules/filter/cache/storage/storage_inmemory/storage_inmemory.cc +++ b/server/modules/filter/cache/storage/storage_inmemory/storage_inmemory.cc @@ -12,6 +12,7 @@ */ #define MXS_MODULE_NAME "storage_inmemory" +#include #include #include "../../cache_storage_api.h" #include "inmemorystoragest.hh" @@ -37,8 +38,6 @@ CACHE_STORAGE* createInstance(cache_thread_model_t model, { ss_dassert(zname); - CACHE_STORAGE* pStorage = 0; - if (max_count != 0) { MXS_WARNING("A maximum item count of %u specified, although 'storage_inMemory' " @@ -51,36 +50,28 @@ CACHE_STORAGE* createInstance(cache_thread_model_t model, "does not enforce such a limit.", (unsigned long)max_size); } - try + InMemoryStorage* pStorage = NULL; + + switch (model) { - switch (model) - { - case CACHE_THREAD_MODEL_ST: - pStorage = reinterpret_cast(InMemoryStorageST::create(zname, ttl, argc, argv)); - break; + case CACHE_THREAD_MODEL_ST: + MXS_EXCEPTION_GUARD(pStorage = InMemoryStorageST::create(zname, ttl, argc, argv)); + break; - default: - MXS_ERROR("Unknown thread model %d, creating multi-thread aware storage.", (int)model); - case CACHE_THREAD_MODEL_MT: - pStorage = reinterpret_cast(InMemoryStorageST::create(zname, ttl, argc, argv)); - } + default: + ss_dassert(!true); + MXS_ERROR("Unknown thread model %d, creating multi-thread aware storage.", (int)model); + case CACHE_THREAD_MODEL_MT: + MXS_EXCEPTION_GUARD(pStorage = InMemoryStorageST::create(zname, ttl, argc, argv)); + break; + } + if (pStorage) + { MXS_NOTICE("Storage module created."); } - 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 pStorage; + return reinterpret_cast(pStorage); } void freeInstance(CACHE_STORAGE* pinstance) @@ -88,7 +79,6 @@ void freeInstance(CACHE_STORAGE* pinstance) delete reinterpret_cast(pinstance); } - cache_result_t getInfo(CACHE_STORAGE* pStorage, uint32_t what, json_t** ppInfo) @@ -97,22 +87,7 @@ cache_result_t getInfo(CACHE_STORAGE* pStorage, cache_result_t result = CACHE_RESULT_ERROR; - try - { - result = reinterpret_cast(pStorage)->get_info(what, ppInfo); - } - 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."); - } + MXS_EXCEPTION_GUARD(result = reinterpret_cast(pStorage)->get_info(what, ppInfo)); return result; } @@ -129,22 +104,9 @@ cache_result_t getKey(CACHE_STORAGE* pstorage, cache_result_t result = CACHE_RESULT_ERROR; - try - { - result = reinterpret_cast(pstorage)->get_key(zdefault_db, pquery, 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."); - } + MXS_EXCEPTION_GUARD(result = reinterpret_cast(pstorage)->get_key(zdefault_db, + pquery, + pkey)); return result; } @@ -160,22 +122,9 @@ cache_result_t getValue(CACHE_STORAGE* pstorage, cache_result_t result = CACHE_RESULT_ERROR; - try - { - result = reinterpret_cast(pstorage)->get_value(*pkey, flags, ppresult); - } - 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."); - } + MXS_EXCEPTION_GUARD(result = reinterpret_cast(pstorage)->get_value(*pkey, + flags, + ppresult)); return result; } @@ -190,22 +139,7 @@ cache_result_t putValue(CACHE_STORAGE* pstorage, cache_result_t result = CACHE_RESULT_ERROR; - try - { - result = reinterpret_cast(pstorage)->put_value(*pkey, pvalue); - } - 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."); - } + MXS_EXCEPTION_GUARD(result = reinterpret_cast(pstorage)->put_value(*pkey, pvalue)); return result; } @@ -218,22 +152,7 @@ cache_result_t delValue(CACHE_STORAGE* pstorage, cache_result_t result = CACHE_RESULT_ERROR; - try - { - result = reinterpret_cast(pstorage)->del_value(*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."); - } + MXS_EXCEPTION_GUARD(result = reinterpret_cast(pstorage)->del_value(*pkey)); return result; } 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 1ae132221..ef0756058 100644 --- a/server/modules/filter/cache/storage/storage_rocksdb/storage_rocksdb.cc +++ b/server/modules/filter/cache/storage/storage_rocksdb/storage_rocksdb.cc @@ -12,6 +12,7 @@ */ #define MXS_MODULE_NAME "storage_rocksdb" +#include #include #include "../../cache_storage_api.h" #include "rocksdbstorage.hh" @@ -35,8 +36,6 @@ CACHE_STORAGE* createInstance(cache_thread_model_t, // Ignored, RocksDB always M { ss_dassert(zName); - CACHE_STORAGE* pStorage = 0; - if (maxCount != 0) { MXS_WARNING("A maximum item count of %u specifed, although 'storage_rocksdb' " @@ -49,26 +48,16 @@ CACHE_STORAGE* createInstance(cache_thread_model_t, // Ignored, RocksDB always M "does not enforce such a limit.", (unsigned long)maxSize); } - try - { - pStorage = reinterpret_cast(RocksDBStorage::Create(zName, ttl, argc, argv)); + RocksDBStorage* pStorage = NULL; + MXS_EXCEPTION_GUARD(pStorage = RocksDBStorage::Create(zName, ttl, argc, argv)); + + if (pStorage) + { MXS_NOTICE("Storage module created."); } - 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 pStorage; + return reinterpret_cast(pStorage); } void freeInstance(CACHE_STORAGE* pInstance) @@ -84,22 +73,7 @@ cache_result_t getInfo(CACHE_STORAGE* pStorage, cache_result_t result = CACHE_RESULT_ERROR; - try - { - result = reinterpret_cast(pStorage)->getInfo(what, ppInfo); - } - 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."); - } + MXS_EXCEPTION_GUARD(result = reinterpret_cast(pStorage)->getInfo(what, ppInfo)); return result; } @@ -116,22 +90,9 @@ cache_result_t getKey(CACHE_STORAGE* pStorage, cache_result_t result = CACHE_RESULT_ERROR; - try - { - result = reinterpret_cast(pStorage)->getKey(zDefaultDB, pQuery, 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."); - } + MXS_EXCEPTION_GUARD(result = reinterpret_cast(pStorage)->getKey(zDefaultDB, + pQuery, + pKey)); return result; } @@ -147,22 +108,9 @@ cache_result_t getValue(CACHE_STORAGE* pStorage, cache_result_t result = CACHE_RESULT_ERROR; - try - { - result = reinterpret_cast(pStorage)->getValue(pKey, flags, ppResult); - } - 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."); - } + MXS_EXCEPTION_GUARD(result = reinterpret_cast(pStorage)->getValue(pKey, + flags, + ppResult)); return result; } @@ -177,22 +125,7 @@ cache_result_t putValue(CACHE_STORAGE* pStorage, cache_result_t result = CACHE_RESULT_ERROR; - try - { - result = reinterpret_cast(pStorage)->putValue(pKey, pValue); - } - 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."); - } + MXS_EXCEPTION_GUARD(result = reinterpret_cast(pStorage)->putValue(pKey, pValue)); return result; } @@ -205,22 +138,7 @@ cache_result_t delValue(CACHE_STORAGE* pStorage, cache_result_t result = CACHE_RESULT_ERROR; - try - { - result = reinterpret_cast(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."); - } + MXS_EXCEPTION_GUARD(result = reinterpret_cast(pStorage)->delValue(pKey)); return result; }