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:
@ -100,6 +100,21 @@ path is interpreted relative to the _data directory_ of MariaDB MaxScale.
|
||||
rules=/path/to/rules-file
|
||||
```
|
||||
|
||||
#### `cached_data`
|
||||
|
||||
An enumeration option specifying how data is shared between threads. The
|
||||
allowed values are:
|
||||
|
||||
* `shared`: The cached data is shared between threads. On the one hand
|
||||
it implies that there will be synchronization between threads, on
|
||||
the other hand that all threads will use data fetched by any thread.
|
||||
* `thread_specific`: The cached data is specific to a thread. On the
|
||||
one hand it implies that no synchonization is needed between threads,
|
||||
on the other hand that the very same data may be fetched and stored
|
||||
multiple times.
|
||||
|
||||
Default is `shared`.
|
||||
|
||||
#### `debug`
|
||||
|
||||
An integer value, using which the level of debug logging made by the cache
|
||||
|
47
server/modules/filter/cache/cachefilter.cc
vendored
47
server/modules/filter/cache/cachefilter.cc
vendored
@ -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);
|
||||
|
22
server/modules/filter/cache/cachefilter.h
vendored
22
server/modules/filter/cache/cachefilter.h
vendored
@ -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);
|
||||
|
Reference in New Issue
Block a user