Cache: Take MXS_EXCEPTION_GUARD into use

This commit is contained in:
Johan Wikman
2016-12-09 09:57:04 +02:00
parent ce94170eae
commit bf35577941
2 changed files with 42 additions and 205 deletions

View File

@ -12,6 +12,7 @@
*/ */
#define MXS_MODULE_NAME "storage_inmemory" #define MXS_MODULE_NAME "storage_inmemory"
#include <maxscale/cppdefs.hh>
#include <inttypes.h> #include <inttypes.h>
#include "../../cache_storage_api.h" #include "../../cache_storage_api.h"
#include "inmemorystoragest.hh" #include "inmemorystoragest.hh"
@ -37,8 +38,6 @@ CACHE_STORAGE* createInstance(cache_thread_model_t model,
{ {
ss_dassert(zname); ss_dassert(zname);
CACHE_STORAGE* pStorage = 0;
if (max_count != 0) if (max_count != 0)
{ {
MXS_WARNING("A maximum item count of %u specified, although 'storage_inMemory' " 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); "does not enforce such a limit.", (unsigned long)max_size);
} }
try InMemoryStorage* pStorage = NULL;
{
switch (model) switch (model)
{ {
case CACHE_THREAD_MODEL_ST: case CACHE_THREAD_MODEL_ST:
pStorage = reinterpret_cast<CACHE_STORAGE*>(InMemoryStorageST::create(zname, ttl, argc, argv)); MXS_EXCEPTION_GUARD(pStorage = InMemoryStorageST::create(zname, ttl, argc, argv));
break; break;
default: default:
ss_dassert(!true);
MXS_ERROR("Unknown thread model %d, creating multi-thread aware storage.", (int)model); MXS_ERROR("Unknown thread model %d, creating multi-thread aware storage.", (int)model);
case CACHE_THREAD_MODEL_MT: case CACHE_THREAD_MODEL_MT:
pStorage = reinterpret_cast<CACHE_STORAGE*>(InMemoryStorageST::create(zname, ttl, argc, argv)); MXS_EXCEPTION_GUARD(pStorage = InMemoryStorageST::create(zname, ttl, argc, argv));
break;
} }
if (pStorage)
{
MXS_NOTICE("Storage module created."); 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<CACHE_STORAGE*>(pStorage);
} }
void freeInstance(CACHE_STORAGE* pinstance) void freeInstance(CACHE_STORAGE* pinstance)
@ -88,7 +79,6 @@ void freeInstance(CACHE_STORAGE* pinstance)
delete reinterpret_cast<InMemoryStorage*>(pinstance); delete reinterpret_cast<InMemoryStorage*>(pinstance);
} }
cache_result_t getInfo(CACHE_STORAGE* pStorage, cache_result_t getInfo(CACHE_STORAGE* pStorage,
uint32_t what, uint32_t what,
json_t** ppInfo) json_t** ppInfo)
@ -97,22 +87,7 @@ cache_result_t getInfo(CACHE_STORAGE* pStorage,
cache_result_t result = CACHE_RESULT_ERROR; cache_result_t result = CACHE_RESULT_ERROR;
try MXS_EXCEPTION_GUARD(result = reinterpret_cast<InMemoryStorage*>(pStorage)->get_info(what, ppInfo));
{
result = reinterpret_cast<InMemoryStorage*>(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.");
}
return result; return result;
} }
@ -129,22 +104,9 @@ cache_result_t getKey(CACHE_STORAGE* pstorage,
cache_result_t result = CACHE_RESULT_ERROR; cache_result_t result = CACHE_RESULT_ERROR;
try MXS_EXCEPTION_GUARD(result = reinterpret_cast<InMemoryStorage*>(pstorage)->get_key(zdefault_db,
{ pquery,
result = reinterpret_cast<InMemoryStorage*>(pstorage)->get_key(zdefault_db, pquery, pkey); 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; return result;
} }
@ -160,22 +122,9 @@ cache_result_t getValue(CACHE_STORAGE* pstorage,
cache_result_t result = CACHE_RESULT_ERROR; cache_result_t result = CACHE_RESULT_ERROR;
try MXS_EXCEPTION_GUARD(result = reinterpret_cast<InMemoryStorage*>(pstorage)->get_value(*pkey,
{ flags,
result = reinterpret_cast<InMemoryStorage*>(pstorage)->get_value(*pkey, flags, ppresult); 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.");
}
return result; return result;
} }
@ -190,22 +139,7 @@ cache_result_t putValue(CACHE_STORAGE* pstorage,
cache_result_t result = CACHE_RESULT_ERROR; cache_result_t result = CACHE_RESULT_ERROR;
try MXS_EXCEPTION_GUARD(result = reinterpret_cast<InMemoryStorage*>(pstorage)->put_value(*pkey, pvalue));
{
result = reinterpret_cast<InMemoryStorage*>(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.");
}
return result; return result;
} }
@ -218,22 +152,7 @@ cache_result_t delValue(CACHE_STORAGE* pstorage,
cache_result_t result = CACHE_RESULT_ERROR; cache_result_t result = CACHE_RESULT_ERROR;
try MXS_EXCEPTION_GUARD(result = reinterpret_cast<InMemoryStorage*>(pstorage)->del_value(*pkey));
{
result = reinterpret_cast<InMemoryStorage*>(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.");
}
return result; return result;
} }

View File

@ -12,6 +12,7 @@
*/ */
#define MXS_MODULE_NAME "storage_rocksdb" #define MXS_MODULE_NAME "storage_rocksdb"
#include <maxscale/cppdefs.hh>
#include <inttypes.h> #include <inttypes.h>
#include "../../cache_storage_api.h" #include "../../cache_storage_api.h"
#include "rocksdbstorage.hh" #include "rocksdbstorage.hh"
@ -35,8 +36,6 @@ CACHE_STORAGE* createInstance(cache_thread_model_t, // Ignored, RocksDB always M
{ {
ss_dassert(zName); ss_dassert(zName);
CACHE_STORAGE* pStorage = 0;
if (maxCount != 0) if (maxCount != 0)
{ {
MXS_WARNING("A maximum item count of %u specifed, although 'storage_rocksdb' " 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); "does not enforce such a limit.", (unsigned long)maxSize);
} }
try RocksDBStorage* pStorage = NULL;
{
pStorage = reinterpret_cast<CACHE_STORAGE*>(RocksDBStorage::Create(zName, ttl, argc, argv));
MXS_EXCEPTION_GUARD(pStorage = RocksDBStorage::Create(zName, ttl, argc, argv));
if (pStorage)
{
MXS_NOTICE("Storage module created."); 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<CACHE_STORAGE*>(pStorage);
} }
void freeInstance(CACHE_STORAGE* pInstance) void freeInstance(CACHE_STORAGE* pInstance)
@ -84,22 +73,7 @@ cache_result_t getInfo(CACHE_STORAGE* pStorage,
cache_result_t result = CACHE_RESULT_ERROR; cache_result_t result = CACHE_RESULT_ERROR;
try MXS_EXCEPTION_GUARD(result = reinterpret_cast<RocksDBStorage*>(pStorage)->getInfo(what, ppInfo));
{
result = reinterpret_cast<RocksDBStorage*>(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.");
}
return result; return result;
} }
@ -116,22 +90,9 @@ cache_result_t getKey(CACHE_STORAGE* pStorage,
cache_result_t result = CACHE_RESULT_ERROR; cache_result_t result = CACHE_RESULT_ERROR;
try MXS_EXCEPTION_GUARD(result = reinterpret_cast<RocksDBStorage*>(pStorage)->getKey(zDefaultDB,
{ pQuery,
result = reinterpret_cast<RocksDBStorage*>(pStorage)->getKey(zDefaultDB, pQuery, pKey); 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; return result;
} }
@ -147,22 +108,9 @@ cache_result_t getValue(CACHE_STORAGE* pStorage,
cache_result_t result = CACHE_RESULT_ERROR; cache_result_t result = CACHE_RESULT_ERROR;
try MXS_EXCEPTION_GUARD(result = reinterpret_cast<RocksDBStorage*>(pStorage)->getValue(pKey,
{ flags,
result = reinterpret_cast<RocksDBStorage*>(pStorage)->getValue(pKey, flags, ppResult); 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.");
}
return result; return result;
} }
@ -177,22 +125,7 @@ cache_result_t putValue(CACHE_STORAGE* pStorage,
cache_result_t result = CACHE_RESULT_ERROR; cache_result_t result = CACHE_RESULT_ERROR;
try MXS_EXCEPTION_GUARD(result = reinterpret_cast<RocksDBStorage*>(pStorage)->putValue(pKey, pValue));
{
result = reinterpret_cast<RocksDBStorage*>(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.");
}
return result; return result;
} }
@ -205,22 +138,7 @@ cache_result_t delValue(CACHE_STORAGE* pStorage,
cache_result_t result = CACHE_RESULT_ERROR; cache_result_t result = CACHE_RESULT_ERROR;
try MXS_EXCEPTION_GUARD(result = reinterpret_cast<RocksDBStorage*>(pStorage)->delValue(pKey));
{
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; return result;
} }