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
|
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`
|
#### `debug`
|
||||||
|
|
||||||
An integer value, using which the level of debug logging made by the cache
|
An integer value, using which the level of debug logging made by the cache
|
||||||
|
37
server/modules/filter/cache/cachefilter.cc
vendored
37
server/modules/filter/cache/cachefilter.cc
vendored
@ -19,6 +19,7 @@
|
|||||||
#include <maxscale/filter.h>
|
#include <maxscale/filter.h>
|
||||||
#include <maxscale/gwdirs.h>
|
#include <maxscale/gwdirs.h>
|
||||||
#include "cachemt.h"
|
#include "cachemt.h"
|
||||||
|
#include "cachept.h"
|
||||||
#include "sessioncache.h"
|
#include "sessioncache.h"
|
||||||
|
|
||||||
static char VERSION_STRING[] = "V1.0.0";
|
static char VERSION_STRING[] = "V1.0.0";
|
||||||
@ -33,7 +34,8 @@ static const CACHE_CONFIG DEFAULT_CONFIG =
|
|||||||
NULL,
|
NULL,
|
||||||
0,
|
0,
|
||||||
CACHE_DEFAULT_TTL,
|
CACHE_DEFAULT_TTL,
|
||||||
CACHE_DEFAULT_DEBUG
|
CACHE_DEFAULT_DEBUG,
|
||||||
|
CACHE_DEFAULT_THREAD_MODEL,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct cache_filter
|
typedef struct cache_filter
|
||||||
@ -143,7 +145,22 @@ static FILTER *createInstance(const char* zName, char** pzOptions, FILTER_PARAME
|
|||||||
{
|
{
|
||||||
if (process_params(pzOptions, ppParams, pFilter->config))
|
if (process_params(pzOptions, ppParams, pFilter->config))
|
||||||
{
|
{
|
||||||
|
switch (pFilter->config.thread_model)
|
||||||
|
{
|
||||||
|
case CACHE_THREAD_MODEL_MT:
|
||||||
|
MXS_NOTICE("Creating shared cache.");
|
||||||
CPP_GUARD(pFilter->pCache = CacheMT::Create(zName, &pFilter->config));
|
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)
|
if (!pFilter->pCache)
|
||||||
{
|
{
|
||||||
@ -152,7 +169,6 @@ static FILTER *createInstance(const char* zName, char** pzOptions, FILTER_PARAME
|
|||||||
pFilter = NULL;
|
pFilter = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return reinterpret_cast<FILTER*>(pFilter);
|
return reinterpret_cast<FILTER*>(pFilter);
|
||||||
}
|
}
|
||||||
@ -450,6 +466,23 @@ static bool process_params(char **pzOptions, FILTER_PARAMETER **ppParams, CACHE_
|
|||||||
error = true;
|
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))
|
else if (!filter_standard_parameter(pParam->name))
|
||||||
{
|
{
|
||||||
MXS_ERROR("Unknown configuration entry '%s'.", 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/hashtable.h>
|
||||||
#include <maxscale/spinlock.h>
|
#include <maxscale/spinlock.h>
|
||||||
#include "rules.h"
|
#include "rules.h"
|
||||||
|
#include "cache_storage_api.h"
|
||||||
|
|
||||||
class Storage;
|
class Storage;
|
||||||
class StorageFactory;
|
class StorageFactory;
|
||||||
@ -44,18 +45,21 @@ class StorageFactory;
|
|||||||
#define CACHE_DEFAULT_TTL 10
|
#define CACHE_DEFAULT_TTL 10
|
||||||
// Integer value
|
// Integer value
|
||||||
#define CACHE_DEFAULT_DEBUG 0
|
#define CACHE_DEFAULT_DEBUG 0
|
||||||
|
// Thread model
|
||||||
|
#define CACHE_DEFAULT_THREAD_MODEL CACHE_THREAD_MODEL_MT
|
||||||
|
|
||||||
typedef struct cache_config
|
typedef struct cache_config
|
||||||
{
|
{
|
||||||
uint32_t max_resultset_rows;
|
uint32_t max_resultset_rows; /**< The maximum number of rows of a resultset for it to be cached. */
|
||||||
uint32_t max_resultset_size;
|
uint32_t max_resultset_size; /**< The maximum size of a resultset for it to be cached. */
|
||||||
char* rules;
|
char* rules; /**< Name of rules file. */
|
||||||
char* storage;
|
char* storage; /**< Name of storage module. */
|
||||||
char* storage_options;
|
char* storage_options; /**< Raw options for storage module. */
|
||||||
char** storage_argv;
|
char** storage_argv; /**< Cooked options for storage module. */
|
||||||
int storage_argc;
|
int storage_argc; /**< Number of cooked options. */
|
||||||
uint32_t ttl;
|
uint32_t ttl; /**< Time to live. */
|
||||||
uint32_t debug;
|
uint32_t debug; /**< Debug settings. */
|
||||||
|
cache_thread_model_t thread_model; /**< Thread model. */
|
||||||
} CACHE_CONFIG;
|
} CACHE_CONFIG;
|
||||||
|
|
||||||
void cache_config_finish(CACHE_CONFIG& config);
|
void cache_config_finish(CACHE_CONFIG& config);
|
||||||
|
Reference in New Issue
Block a user