Cache: Make it possible to specify thread model for storage

This commit is contained in:
Johan Wikman 2016-11-25 15:06:01 +02:00
parent 7a0d6307fe
commit c1c447985d
6 changed files with 23 additions and 8 deletions

View File

@ -37,6 +37,12 @@ typedef enum cache_flags
CACHE_FLAGS_INCLUDE_STALE = 0x01,
} cache_flags_t;
typedef enum cache_thread_model
{
CACHE_THREAD_MODEL_ST = 0x1,
CACHE_THREAD_MODEL_MT = 0x2,
} cache_thread_model_t;
typedef void* CACHE_STORAGE;
enum
@ -58,6 +64,10 @@ typedef struct cache_storage_api
* create the actual storage, initialize it and prepare to put and get
* cache items.
*
* @param model Whether the storage will be used in a single thread or
* multi thread context. In the latter case the storage must
* perform thread synchronization as appropriate, in the former
* case it need not.
* @param name The name of the cache instance.
* @param ttl Time to live; number of seconds the value is valid.
* @param argc The number of elements in the argv array.
@ -66,7 +76,8 @@ typedef struct cache_storage_api
* @return A new cache instance, or NULL if the instance could not be
* created.
*/
CACHE_STORAGE* (*createInstance)(const char *name,
CACHE_STORAGE* (*createInstance)(cache_thread_model_t model,
const char *name,
uint32_t ttl,
int argc, char* argv[]);

View File

@ -16,6 +16,7 @@
#include <maxscale/cdefs.h>
#include <limits.h>
#include <exception>
#include <maxscale/hashtable.h>
#include <maxscale/spinlock.h>
#include "rules.h"

View File

@ -12,8 +12,6 @@
*/
#include "cachemt.h"
#include <new>
#include <maxscale/spinlock.h>
#include "storage.h"
#include "storagefactory.h"
@ -46,7 +44,7 @@ CacheMT* CacheMT::Create(const char* zName, CACHE_CONFIG& config)
int argc = config.storage_argc;
char** argv = config.storage_argv;
Storage* pStorage = pFactory->createStorage(zName, ttl, argc, argv);
Storage* pStorage = pFactory->createStorage(CACHE_THREAD_MODEL_MT, zName, ttl, argc, argv);
if (pStorage)
{

View File

@ -23,7 +23,10 @@ bool initialize()
return RocksDBStorage::Initialize();
}
CACHE_STORAGE* createInstance(const char* zName, uint32_t ttl, int argc, char* argv[])
CACHE_STORAGE* createInstance(cache_thread_model_t, // Ignored, RocksDB always MT safe.
const char* zName,
uint32_t ttl,
int argc, char* argv[])
{
ss_dassert(zName);

View File

@ -131,7 +131,8 @@ StorageFactory* StorageFactory::Open(const char* zName)
return pFactory;
}
Storage* StorageFactory::createStorage(const char* zName,
Storage* StorageFactory::createStorage(cache_thread_model_t model,
const char* zName,
uint32_t ttl,
int argc, char* argv[])
{
@ -139,7 +140,7 @@ Storage* StorageFactory::createStorage(const char* zName,
ss_dassert(m_pApi);
Storage* pStorage = 0;
CACHE_STORAGE* pRawStorage = m_pApi->createInstance(zName, ttl, argc, argv);
CACHE_STORAGE* pRawStorage = m_pApi->createInstance(model, zName, ttl, argc, argv);
if (pRawStorage)
{

View File

@ -26,7 +26,8 @@ public:
static StorageFactory* Open(const char* zName);
Storage* createStorage(const char* zName,
Storage* createStorage(cache_thread_model_t model,
const char* zName,
uint32_t ttl,
int argc, char* argv[]);