Cache: Make it possible to specify thread model for storage
This commit is contained in:
parent
7a0d6307fe
commit
c1c447985d
13
server/modules/filter/cache/cache_storage_api.h
vendored
13
server/modules/filter/cache/cache_storage_api.h
vendored
@ -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[]);
|
||||
|
||||
|
1
server/modules/filter/cache/cachefilter.h
vendored
1
server/modules/filter/cache/cachefilter.h
vendored
@ -16,6 +16,7 @@
|
||||
|
||||
#include <maxscale/cdefs.h>
|
||||
#include <limits.h>
|
||||
#include <exception>
|
||||
#include <maxscale/hashtable.h>
|
||||
#include <maxscale/spinlock.h>
|
||||
#include "rules.h"
|
||||
|
4
server/modules/filter/cache/cachemt.cc
vendored
4
server/modules/filter/cache/cachemt.cc
vendored
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
3
server/modules/filter/cache/storagefactory.h
vendored
3
server/modules/filter/cache/storagefactory.h
vendored
@ -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[]);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user