Cache: Make storage_rocksdb exception safe
Now RocksDBStorage is exception safe in its own right, so exception guards are only needed at the C/C++ boundary.
This commit is contained in:
parent
bf35577941
commit
16fad9c2cd
@ -223,7 +223,9 @@ bool RocksDBStorage::Initialize()
|
||||
}
|
||||
|
||||
//static
|
||||
RocksDBStorage* RocksDBStorage::Create(const char* zName, uint32_t ttl, int argc, char* argv[])
|
||||
unique_ptr<RocksDBStorage> RocksDBStorage::Create(const char* zName,
|
||||
uint32_t ttl,
|
||||
int argc, char* argv[])
|
||||
{
|
||||
ss_dassert(zName);
|
||||
|
||||
@ -278,12 +280,12 @@ RocksDBStorage* RocksDBStorage::Create(const char* zName, uint32_t ttl, int argc
|
||||
}
|
||||
|
||||
// static
|
||||
RocksDBStorage* RocksDBStorage::Create(const string& storageDirectory,
|
||||
const char* zName,
|
||||
uint32_t ttl,
|
||||
bool collectStatistics)
|
||||
unique_ptr<RocksDBStorage> RocksDBStorage::Create(const string& storageDirectory,
|
||||
const char* zName,
|
||||
uint32_t ttl,
|
||||
bool collectStatistics)
|
||||
{
|
||||
RocksDBStorage* pStorage = nullptr;
|
||||
unique_ptr<RocksDBStorage> sStorage;
|
||||
|
||||
if (mkdir(storageDirectory.c_str(), S_IRWXU) == 0)
|
||||
{
|
||||
@ -341,7 +343,7 @@ RocksDBStorage* RocksDBStorage::Create(const string& storageDirectory,
|
||||
|
||||
unique_ptr<rocksdb::DBWithTTL> sDb(pDb);
|
||||
|
||||
pStorage = new RocksDBStorage(sDb, zName, path, ttl);
|
||||
sStorage = unique_ptr<RocksDBStorage>(new RocksDBStorage(sDb, zName, path, ttl));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -356,7 +358,7 @@ RocksDBStorage* RocksDBStorage::Create(const string& storageDirectory,
|
||||
}
|
||||
}
|
||||
|
||||
return pStorage;
|
||||
return sStorage;
|
||||
}
|
||||
|
||||
cache_result_t RocksDBStorage::getInfo(uint32_t what, json_t** ppInfo) const
|
||||
|
@ -21,9 +21,11 @@
|
||||
class RocksDBStorage
|
||||
{
|
||||
public:
|
||||
typedef std::unique_ptr<RocksDBStorage> SRocksDBStorage;
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static RocksDBStorage* Create(const char* zName, uint32_t ttl, int argc, char* argv[]);
|
||||
static SRocksDBStorage Create(const char* zName, uint32_t ttl, int argc, char* argv[]);
|
||||
~RocksDBStorage();
|
||||
|
||||
cache_result_t getInfo(uint32_t flags, json_t** ppInfo) const;
|
||||
@ -41,7 +43,7 @@ private:
|
||||
RocksDBStorage(const RocksDBStorage&) = delete;
|
||||
RocksDBStorage& operator = (const RocksDBStorage&) = delete;
|
||||
|
||||
static RocksDBStorage* Create(const std::string& storageDirectory,
|
||||
static SRocksDBStorage Create(const std::string& storageDirectory,
|
||||
const char* zName,
|
||||
uint32_t ttl,
|
||||
bool collectStatistics);
|
||||
|
@ -17,6 +17,8 @@
|
||||
#include "../../cache_storage_api.h"
|
||||
#include "rocksdbstorage.hh"
|
||||
|
||||
using std::unique_ptr;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@ -48,21 +50,21 @@ CACHE_STORAGE* createInstance(cache_thread_model_t, // Ignored, RocksDB always M
|
||||
"does not enforce such a limit.", (unsigned long)maxSize);
|
||||
}
|
||||
|
||||
RocksDBStorage* pStorage = NULL;
|
||||
unique_ptr<RocksDBStorage> sStorage;
|
||||
|
||||
MXS_EXCEPTION_GUARD(pStorage = RocksDBStorage::Create(zName, ttl, argc, argv));
|
||||
MXS_EXCEPTION_GUARD(sStorage = RocksDBStorage::Create(zName, ttl, argc, argv));
|
||||
|
||||
if (pStorage)
|
||||
if (sStorage)
|
||||
{
|
||||
MXS_NOTICE("Storage module created.");
|
||||
}
|
||||
|
||||
return reinterpret_cast<CACHE_STORAGE*>(pStorage);
|
||||
return reinterpret_cast<CACHE_STORAGE*>(sStorage.release());
|
||||
}
|
||||
|
||||
void freeInstance(CACHE_STORAGE* pInstance)
|
||||
{
|
||||
delete reinterpret_cast<RocksDBStorage*>(pInstance);
|
||||
MXS_EXCEPTION_GUARD(delete reinterpret_cast<RocksDBStorage*>(pInstance));
|
||||
}
|
||||
|
||||
cache_result_t getInfo(CACHE_STORAGE* pStorage,
|
||||
|
Loading…
x
Reference in New Issue
Block a user