Cache: Add options for choose sharing mode

Now possible to use same cache for all threads or separate cache
for each.
This commit is contained in:
Johan Wikman
2016-11-27 21:47:07 +02:00
parent 933e09d245
commit a2daacd465
3 changed files with 68 additions and 16 deletions

View File

@ -19,6 +19,7 @@
#include <maxscale/filter.h>
#include <maxscale/gwdirs.h>
#include "cachemt.h"
#include "cachept.h"
#include "sessioncache.h"
static char VERSION_STRING[] = "V1.0.0";
@ -33,7 +34,8 @@ static const CACHE_CONFIG DEFAULT_CONFIG =
NULL,
0,
CACHE_DEFAULT_TTL,
CACHE_DEFAULT_DEBUG
CACHE_DEFAULT_DEBUG,
CACHE_DEFAULT_THREAD_MODEL,
};
typedef struct cache_filter
@ -143,15 +145,29 @@ static FILTER *createInstance(const char* zName, char** pzOptions, FILTER_PARAME
{
if (process_params(pzOptions, ppParams, pFilter->config))
{
CPP_GUARD(pFilter->pCache = CacheMT::Create(zName, &pFilter->config));
if (!pFilter->pCache)
switch (pFilter->config.thread_model)
{
cache_config_finish(pFilter->config);
delete pFilter;
pFilter = NULL;
case CACHE_THREAD_MODEL_MT:
MXS_NOTICE("Creating shared cache.");
CPP_GUARD(pFilter->pCache = CacheMT::Create(zName, &pFilter->config));
break;
case CACHE_THREAD_MODEL_ST:
MXS_NOTICE("Creating thread specific cache.");
CPP_GUARD(pFilter->pCache = CachePT::Create(zName, &pFilter->config));
break;
default:
ss_dassert(!true);
}
}
if (!pFilter->pCache)
{
cache_config_finish(pFilter->config);
delete pFilter;
pFilter = NULL;
}
}
return reinterpret_cast<FILTER*>(pFilter);
@ -450,6 +466,23 @@ static bool process_params(char **pzOptions, FILTER_PARAMETER **ppParams, CACHE_
error = true;
}
}
else if (strcmp(pParam->name, "cached_data") == 0)
{
if (strcmp(pParam->value, "shared") == 0)
{
config.thread_model = CACHE_THREAD_MODEL_MT;
}
else if (strcmp(pParam->value, "thread_specific") == 0)
{
config.thread_model = CACHE_THREAD_MODEL_ST;
}
else
{
MXS_ERROR("The value of the configuration entry '%s' must "
"be either 'shared' or 'thread_specific'.", pParam->name);
error = true;
}
}
else if (!filter_standard_parameter(pParam->name))
{
MXS_ERROR("Unknown configuration entry '%s'.", pParam->name);

View File

@ -20,6 +20,7 @@
#include <maxscale/hashtable.h>
#include <maxscale/spinlock.h>
#include "rules.h"
#include "cache_storage_api.h"
class Storage;
class StorageFactory;
@ -44,18 +45,21 @@ class StorageFactory;
#define CACHE_DEFAULT_TTL 10
// Integer value
#define CACHE_DEFAULT_DEBUG 0
// Thread model
#define CACHE_DEFAULT_THREAD_MODEL CACHE_THREAD_MODEL_MT
typedef struct cache_config
{
uint32_t max_resultset_rows;
uint32_t max_resultset_size;
char* rules;
char* storage;
char* storage_options;
char** storage_argv;
int storage_argc;
uint32_t ttl;
uint32_t debug;
uint32_t max_resultset_rows; /**< The maximum number of rows of a resultset for it to be cached. */
uint32_t max_resultset_size; /**< The maximum size of a resultset for it to be cached. */
char* rules; /**< Name of rules file. */
char* storage; /**< Name of storage module. */
char* storage_options; /**< Raw options for storage module. */
char** storage_argv; /**< Cooked options for storage module. */
int storage_argc; /**< Number of cooked options. */
uint32_t ttl; /**< Time to live. */
uint32_t debug; /**< Debug settings. */
cache_thread_model_t thread_model; /**< Thread model. */
} CACHE_CONFIG;
void cache_config_finish(CACHE_CONFIG& config);