MXS-2346 Update cache filter
As a proof of concept, the cache filter has been updated to use the new configuration mechanism.
This commit is contained in:
parent
09702ab0a0
commit
17aa494c87
1
server/modules/filter/cache/CMakeLists.txt
vendored
1
server/modules/filter/cache/CMakeLists.txt
vendored
@ -1,6 +1,7 @@
|
||||
if (JANSSON_FOUND)
|
||||
add_library(cache SHARED
|
||||
cache.cc
|
||||
cacheconfig.cc
|
||||
cachefilter.cc
|
||||
cachefiltersession.cc
|
||||
cache_storage_api.cc
|
||||
|
14
server/modules/filter/cache/cache.cc
vendored
14
server/modules/filter/cache/cache.cc
vendored
@ -28,7 +28,7 @@
|
||||
using namespace std;
|
||||
|
||||
Cache::Cache(const std::string& name,
|
||||
const CACHE_CONFIG* pConfig,
|
||||
const CacheConfig* pConfig,
|
||||
const std::vector<SCacheRules>& rules,
|
||||
SStorageFactory sFactory)
|
||||
: m_name(name)
|
||||
@ -43,7 +43,7 @@ Cache::~Cache()
|
||||
}
|
||||
|
||||
// static
|
||||
bool Cache::Create(const CACHE_CONFIG& config,
|
||||
bool Cache::Create(const CacheConfig& config,
|
||||
std::vector<SCacheRules>* pRules,
|
||||
StorageFactory** ppFactory)
|
||||
{
|
||||
@ -52,13 +52,13 @@ bool Cache::Create(const CACHE_CONFIG& config,
|
||||
|
||||
bool rv = false;
|
||||
|
||||
if (config.rules)
|
||||
if (!config.rules.empty())
|
||||
{
|
||||
rv = CacheRules::load(config.rules, config.debug, &rules);
|
||||
rv = CacheRules::load(config.rules.get(), config.debug.get(), &rules);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto_ptr<CacheRules> sRules(CacheRules::create(config.debug));
|
||||
auto_ptr<CacheRules> sRules(CacheRules::create(config.debug.get()));
|
||||
|
||||
if (sRules.get())
|
||||
{
|
||||
@ -69,7 +69,7 @@ bool Cache::Create(const CACHE_CONFIG& config,
|
||||
|
||||
if (rv)
|
||||
{
|
||||
pFactory = StorageFactory::Open(config.storage);
|
||||
pFactory = StorageFactory::Open(config.storage.get());
|
||||
|
||||
if (pFactory)
|
||||
{
|
||||
@ -78,7 +78,7 @@ bool Cache::Create(const CACHE_CONFIG& config,
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_ERROR("Could not open storage factory '%s'.", config.storage);
|
||||
MXS_ERROR("Could not open storage factory '%s'.", config.storage.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
71
server/modules/filter/cache/cache.hh
vendored
71
server/modules/filter/cache/cache.hh
vendored
@ -22,6 +22,7 @@
|
||||
|
||||
#include "rules.hh"
|
||||
#include "cache_storage_api.hh"
|
||||
#include "cacheconfig.hh"
|
||||
|
||||
class CacheFilterSession;
|
||||
class StorageFactory;
|
||||
@ -46,68 +47,6 @@ class StorageFactory;
|
||||
#define UINT64_MAX (18446744073709551615UL)
|
||||
#endif
|
||||
|
||||
typedef enum cache_selects
|
||||
{
|
||||
CACHE_SELECTS_ASSUME_CACHEABLE,
|
||||
CACHE_SELECTS_VERIFY_CACHEABLE,
|
||||
} cache_selects_t;
|
||||
|
||||
// Count
|
||||
#define CACHE_ZDEFAULT_MAX_RESULTSET_ROWS "0"
|
||||
// Bytes
|
||||
#define CACHE_ZDEFAULT_MAX_RESULTSET_SIZE "0"
|
||||
// Duration
|
||||
#define CACHE_ZDEFAULT_HARD_TTL "0s"
|
||||
// Duration
|
||||
#define CACHE_ZDEFAULT_SOFT_TTL "0s"
|
||||
// Integer value
|
||||
#define CACHE_ZDEFAULT_DEBUG "0"
|
||||
// Positive integer
|
||||
#define CACHE_ZDEFAULT_MAX_COUNT "0"
|
||||
// Positive integer
|
||||
#define CACHE_ZDEFAULT_MAX_SIZE "0"
|
||||
// Thread model
|
||||
#define CACHE_ZDEFAULT_THREAD_MODEL "thread_specific"
|
||||
const cache_thread_model CACHE_DEFAULT_THREAD_MODEL = CACHE_THREAD_MODEL_ST;
|
||||
// Cacheable selects
|
||||
#define CACHE_ZDEFAULT_SELECTS "assume_cacheable"
|
||||
const cache_selects_t CACHE_DEFAULT_SELECTS = CACHE_SELECTS_ASSUME_CACHEABLE;
|
||||
// Storage
|
||||
#define CACHE_ZDEFAULT_STORAGE "storage_inmemory"
|
||||
// Transaction behaviour
|
||||
#define CACHE_ZDEFAULT_CACHE_IN_TRXS "all_transactions"
|
||||
// Enabled
|
||||
#define CACHE_ZDEFAULT_ENABLED "true"
|
||||
|
||||
typedef enum cache_in_trxs
|
||||
{
|
||||
// Do NOT change the order. Code relies upon NEVER < READ_ONLY < ALL.
|
||||
CACHE_IN_TRXS_NEVER,
|
||||
CACHE_IN_TRXS_READ_ONLY,
|
||||
CACHE_IN_TRXS_ALL,
|
||||
} cache_in_trxs_t;
|
||||
|
||||
typedef struct cache_config
|
||||
{
|
||||
uint64_t max_resultset_rows; /**< The maximum number of rows of a resultset for it to be
|
||||
* cached. */
|
||||
uint64_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 hard_ttl; /**< Hard time to live. */
|
||||
uint32_t soft_ttl; /**< Soft time to live. */
|
||||
uint64_t max_count; /**< Maximum number of entries in the cache.*/
|
||||
uint64_t max_size; /**< Maximum size of the cache.*/
|
||||
uint32_t debug; /**< Debug settings. */
|
||||
cache_thread_model_t thread_model; /**< Thread model. */
|
||||
cache_selects_t selects; /**< Assume/verify that selects are cacheable. */
|
||||
cache_in_trxs_t cache_in_trxs; /**< To cache or not to cache inside transactions. */
|
||||
bool enabled; /**< Whether the cache is enabled or not. */
|
||||
} CACHE_CONFIG;
|
||||
|
||||
class Cache
|
||||
{
|
||||
public:
|
||||
@ -127,7 +66,7 @@ public:
|
||||
void show(DCB* pDcb) const;
|
||||
json_t* show_json() const;
|
||||
|
||||
const CACHE_CONFIG& config() const
|
||||
const CacheConfig& config() const
|
||||
{
|
||||
return m_config;
|
||||
}
|
||||
@ -218,11 +157,11 @@ public:
|
||||
|
||||
protected:
|
||||
Cache(const std::string& name,
|
||||
const CACHE_CONFIG* pConfig,
|
||||
const CacheConfig* pConfig,
|
||||
const std::vector<SCacheRules>& rules,
|
||||
SStorageFactory sFactory);
|
||||
|
||||
static bool Create(const CACHE_CONFIG& config,
|
||||
static bool Create(const CacheConfig& config,
|
||||
std::vector<SCacheRules>* pRules,
|
||||
StorageFactory** ppFactory);
|
||||
|
||||
@ -234,7 +173,7 @@ private:
|
||||
|
||||
protected:
|
||||
const std::string m_name; // The name of the instance; the section name in the config.
|
||||
const CACHE_CONFIG& m_config; // The configuration of the cache instance.
|
||||
const CacheConfig& m_config; // The configuration of the cache instance.
|
||||
std::vector<SCacheRules> m_rules; // The rules of the cache instance.
|
||||
SStorageFactory m_sFactory;// The storage factory.
|
||||
};
|
||||
|
255
server/modules/filter/cache/cacheconfig.cc
vendored
Normal file
255
server/modules/filter/cache/cacheconfig.cc
vendored
Normal file
@ -0,0 +1,255 @@
|
||||
/*
|
||||
* Copyright (c) 2018 MariaDB Corporation Ab
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
||||
*
|
||||
* Change Date: 2022-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2 or later of the General
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#define MXS_MODULE_NAME "cache"
|
||||
#include "cacheconfig.hh"
|
||||
#include "cache.hh"
|
||||
|
||||
#define CACHE_ZDEFAULT_STORAGE "\"storage_inmemory\""
|
||||
|
||||
config::Specification CacheConfig::s_specification(MXS_MODULE_NAME);
|
||||
|
||||
config::ParamString CacheConfig::s_storage(
|
||||
&s_specification,
|
||||
"storage",
|
||||
"The name of the module that provides the storage implementation for the cache.",
|
||||
CACHE_ZDEFAULT_STORAGE
|
||||
);
|
||||
|
||||
config::ParamString CacheConfig::s_storage_options(
|
||||
&s_specification,
|
||||
"storage_options",
|
||||
"A comma separated list of arguments to be provided to the storage module "
|
||||
"specified with 'storage'.",
|
||||
"\"\""
|
||||
);
|
||||
|
||||
config::ParamDuration<std::chrono::seconds> CacheConfig::s_hard_ttl(
|
||||
&s_specification,
|
||||
"hard_ttl",
|
||||
"Hard time to live; the maximum amount of time the cached result is "
|
||||
"used before it is discarded and the result is fetched from the backend. "
|
||||
"See also 'soft_ttl'.",
|
||||
mxs::config::INTERPRET_AS_SECONDS,
|
||||
std::chrono::seconds { 0 }
|
||||
);
|
||||
|
||||
config::ParamDuration<std::chrono::seconds> CacheConfig::s_soft_ttl(
|
||||
&s_specification,
|
||||
"soft_ttl",
|
||||
"Soft time to live; the maximum amount of time the cached result is "
|
||||
"used before the first client querying for the result is used for refreshing "
|
||||
"the cached data from the backend. See also 'hard_ttl'.",
|
||||
mxs::config::INTERPRET_AS_SECONDS,
|
||||
std::chrono::seconds { 0 }
|
||||
);
|
||||
|
||||
config::ParamCount CacheConfig::s_max_resultset_rows(
|
||||
&s_specification,
|
||||
"max_resultset_rows",
|
||||
"Specifies the maximum number of rows a resultset can have in order to be "
|
||||
"stored in the cache. A resultset larger than this, will not be stored.",
|
||||
0
|
||||
);
|
||||
|
||||
config::ParamSize CacheConfig::s_max_resultset_size(
|
||||
&s_specification,
|
||||
"max_resultset_size",
|
||||
"Specifies the maximum size of a resultset, for it to be stored in the cache. "
|
||||
"A resultset larger than this, will not be stored.",
|
||||
0
|
||||
);
|
||||
|
||||
config::ParamCount CacheConfig::s_max_count(
|
||||
&s_specification,
|
||||
"max_count",
|
||||
"The maximum number of items the cache may contain. If the limit has been "
|
||||
"reached and a new item should be stored, then an older item will be evicted.",
|
||||
0
|
||||
);
|
||||
|
||||
config::ParamSize CacheConfig::s_max_size(
|
||||
&s_specification,
|
||||
"max_size",
|
||||
"The maximum size the cache may occupy. If the limit has been reached and a new "
|
||||
"item should be stored, then some older item(s) will be evicted to make space.",
|
||||
0
|
||||
);
|
||||
|
||||
config::ParamPath CacheConfig::s_rules(
|
||||
&s_specification,
|
||||
"rules",
|
||||
"Specifies the path of the file where the caching rules are stored. A relative "
|
||||
"path is interpreted relative to the data directory of MariaDB MaxScale.",
|
||||
0,
|
||||
""
|
||||
);
|
||||
|
||||
config::ParamBitMask CacheConfig::s_debug(
|
||||
&s_specification,
|
||||
"debug",
|
||||
"An integer value, using which the level of debug logging made by the cache "
|
||||
"can be controlled.",
|
||||
0
|
||||
);
|
||||
|
||||
config::ParamEnum<cache_thread_model_t> CacheConfig::s_thread_model(
|
||||
&s_specification,
|
||||
"cached_data",
|
||||
"An enumeration option specifying how data is shared between threads.",
|
||||
{
|
||||
{ CACHE_THREAD_MODEL_MT, "shared" },
|
||||
{ CACHE_THREAD_MODEL_ST, "thread_specific" }
|
||||
},
|
||||
CACHE_THREAD_MODEL_ST
|
||||
);
|
||||
|
||||
config::ParamEnum<cache_selects_t> CacheConfig::s_selects(
|
||||
&s_specification,
|
||||
"selects",
|
||||
"An enumeration option specifying what approach the cache should take with "
|
||||
"respect to SELECT statements.",
|
||||
{
|
||||
{ CACHE_SELECTS_ASSUME_CACHEABLE, "assume_cacheable" },
|
||||
{ CACHE_SELECTS_VERIFY_CACHEABLE, "verify_cacheable" }
|
||||
},
|
||||
CACHE_SELECTS_ASSUME_CACHEABLE
|
||||
);
|
||||
|
||||
config::ParamEnum<cache_in_trxs_t> CacheConfig::s_cache_in_trxs(
|
||||
&s_specification,
|
||||
"cache_in_transactions",
|
||||
"An enumeration option specifying how the cache should behave when there "
|
||||
"are active transactions.",
|
||||
{
|
||||
{ CACHE_IN_TRXS_NEVER, "never" },
|
||||
{ CACHE_IN_TRXS_READ_ONLY, "read_only_transactions" },
|
||||
{ CACHE_IN_TRXS_ALL, "all_transactions" }
|
||||
},
|
||||
CACHE_IN_TRXS_ALL
|
||||
);
|
||||
|
||||
config::ParamBool CacheConfig::s_enabled(
|
||||
&s_specification,
|
||||
"enabled",
|
||||
"Specifies whether the cache is initially enabled or disabled.",
|
||||
true
|
||||
);
|
||||
|
||||
CacheConfig::CacheConfig()
|
||||
: config::Configuration(&s_specification)
|
||||
, storage(this, &s_storage)
|
||||
, storage_options(this, &s_storage_options)
|
||||
, hard_ttl(this, &s_hard_ttl)
|
||||
, soft_ttl(this, &s_soft_ttl)
|
||||
, max_resultset_rows(this, &s_max_resultset_rows)
|
||||
, max_resultset_size(this, &s_max_resultset_size)
|
||||
, max_count(this, &s_max_count)
|
||||
, max_size(this, &s_max_size)
|
||||
, rules(this, &s_rules)
|
||||
, debug(this, &s_debug)
|
||||
, thread_model(this, &s_thread_model)
|
||||
, selects(this, &s_selects)
|
||||
, cache_in_trxs(this, &s_cache_in_trxs)
|
||||
, enabled(this, &s_enabled)
|
||||
{
|
||||
}
|
||||
|
||||
CacheConfig::~CacheConfig()
|
||||
{
|
||||
for (int i = 0; i < this->storage_argc; ++i)
|
||||
{
|
||||
MXS_FREE(this->storage_argv[i]);
|
||||
}
|
||||
|
||||
MXS_FREE(this->storage_argv);
|
||||
MXS_FREE(this->zStorage_options);
|
||||
}
|
||||
|
||||
bool CacheConfig::configure()
|
||||
{
|
||||
bool configured = true;
|
||||
|
||||
if ((this->debug < CACHE_DEBUG_MIN) || (this->debug > CACHE_DEBUG_MAX))
|
||||
{
|
||||
MXS_ERROR("The value of the configuration entry 'debug' must "
|
||||
"be between %d and %d, inclusive.",
|
||||
CACHE_DEBUG_MIN,
|
||||
CACHE_DEBUG_MAX);
|
||||
configured = false;
|
||||
}
|
||||
|
||||
if (!this->storage_options.empty())
|
||||
{
|
||||
this->zStorage_options = MXS_STRDUP_A(this->storage_options.c_str());
|
||||
|
||||
int argc = 1;
|
||||
char* zArg = this->zStorage_options;
|
||||
|
||||
while ((zArg = strchr(zArg, ',')))
|
||||
{
|
||||
zArg = zArg + 1;
|
||||
++argc;
|
||||
}
|
||||
|
||||
this->storage_argv = (char**) MXS_MALLOC((argc + 1) * sizeof(char*));
|
||||
mxb_assert(this->storage_argv);
|
||||
|
||||
this->storage_argc = argc;
|
||||
|
||||
int i = 0;
|
||||
zArg = this->zStorage_options;
|
||||
this->storage_argv[i++] = zArg;
|
||||
|
||||
while ((zArg = strchr(this->zStorage_options, ',')))
|
||||
{
|
||||
*zArg = 0;
|
||||
++zArg;
|
||||
this->storage_argv[i++] = zArg;
|
||||
}
|
||||
|
||||
this->storage_argv[i] = NULL;
|
||||
}
|
||||
|
||||
if (this->soft_ttl > this->hard_ttl)
|
||||
{
|
||||
MXS_WARNING("The value of 'soft_ttl' must be less than or equal to that of 'hard_ttl'. "
|
||||
"Setting 'soft_ttl' to the same value as 'hard_ttl'.");
|
||||
this->soft_ttl = this->hard_ttl;
|
||||
}
|
||||
|
||||
if (this->max_resultset_size == 0)
|
||||
{
|
||||
if (this->max_size != 0)
|
||||
{
|
||||
// If a specific size has been configured for 'max_size' but 'max_resultset_size'
|
||||
// has not been specifically set, then we silently set it to the same as 'max_size'.
|
||||
this->max_resultset_size = this->max_size;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((this->max_size != 0) && (this->max_resultset_size > this->max_size))
|
||||
{
|
||||
MXS_WARNING("The value of 'max_resultset_size' %ld should not be larger than "
|
||||
"the value of 'max_size' %ld. Adjusting the value of 'max_resultset_size' "
|
||||
"down to %ld.",
|
||||
this->max_resultset_size.get(),
|
||||
this->max_size.get(),
|
||||
this->max_size.get());
|
||||
this->max_resultset_size = this->max_size;
|
||||
}
|
||||
}
|
||||
|
||||
return configured;
|
||||
}
|
273
server/modules/filter/cache/cachefilter.cc
vendored
273
server/modules/filter/cache/cachefilter.cc
vendored
@ -20,6 +20,7 @@
|
||||
#include <maxscale/paths.h>
|
||||
#include <maxscale/utils.h>
|
||||
|
||||
#include "cacheconfig.hh"
|
||||
#include "cachemt.hh"
|
||||
#include "cachept.hh"
|
||||
|
||||
@ -31,59 +32,6 @@ namespace
|
||||
|
||||
static char VERSION_STRING[] = "V1.0.0";
|
||||
|
||||
/**
|
||||
* Frees all data of a config object, but not the object itself
|
||||
*
|
||||
* @param pConfig Pointer to a config object.
|
||||
*/
|
||||
void cache_config_finish(CACHE_CONFIG& config)
|
||||
{
|
||||
MXS_FREE(config.rules);
|
||||
MXS_FREE(config.storage);
|
||||
MXS_FREE(config.storage_options);
|
||||
MXS_FREE(config.storage_argv); // The items need not be freed, they point into storage_options.
|
||||
|
||||
config.max_resultset_rows = 0;
|
||||
config.max_resultset_size = 0;
|
||||
config.rules = NULL;
|
||||
config.storage = NULL;
|
||||
config.storage_options = NULL;
|
||||
config.storage_argc = 0;
|
||||
config.storage_argv = NULL;
|
||||
config.hard_ttl = 0;
|
||||
config.soft_ttl = 0;
|
||||
config.debug = 0;
|
||||
config.thread_model = CACHE_DEFAULT_THREAD_MODEL;
|
||||
config.selects = CACHE_DEFAULT_SELECTS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees all data of a config object, and the object itself
|
||||
*
|
||||
* @param pConfig Pointer to a config object.
|
||||
*/
|
||||
void cache_config_free(CACHE_CONFIG* pConfig)
|
||||
{
|
||||
if (pConfig)
|
||||
{
|
||||
cache_config_finish(*pConfig);
|
||||
MXS_FREE(pConfig);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the data without freeing anything.
|
||||
*
|
||||
* @param config Reference to a config object.
|
||||
*/
|
||||
void cache_config_reset(CACHE_CONFIG& config)
|
||||
{
|
||||
memset(&config, 0, sizeof(config));
|
||||
|
||||
config.thread_model = CACHE_DEFAULT_THREAD_MODEL;
|
||||
config.selects = CACHE_DEFAULT_SELECTS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement "call command cache show ..."
|
||||
*
|
||||
@ -179,85 +127,16 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE()
|
||||
NULL, /* Process finish. */
|
||||
NULL, /* Thread init. */
|
||||
NULL, /* Thread finish. */
|
||||
{
|
||||
{
|
||||
"storage",
|
||||
MXS_MODULE_PARAM_STRING,
|
||||
CACHE_ZDEFAULT_STORAGE
|
||||
},
|
||||
{
|
||||
"storage_options",
|
||||
MXS_MODULE_PARAM_STRING
|
||||
},
|
||||
{
|
||||
"hard_ttl",
|
||||
MXS_MODULE_PARAM_DURATION,
|
||||
CACHE_ZDEFAULT_HARD_TTL
|
||||
},
|
||||
{
|
||||
"soft_ttl",
|
||||
MXS_MODULE_PARAM_DURATION,
|
||||
CACHE_ZDEFAULT_SOFT_TTL
|
||||
},
|
||||
{
|
||||
"max_resultset_rows",
|
||||
MXS_MODULE_PARAM_COUNT,
|
||||
CACHE_ZDEFAULT_MAX_RESULTSET_ROWS
|
||||
},
|
||||
{
|
||||
"max_resultset_size",
|
||||
MXS_MODULE_PARAM_SIZE,
|
||||
CACHE_ZDEFAULT_MAX_RESULTSET_SIZE
|
||||
},
|
||||
{
|
||||
"max_count",
|
||||
MXS_MODULE_PARAM_COUNT,
|
||||
CACHE_ZDEFAULT_MAX_COUNT
|
||||
},
|
||||
{
|
||||
"max_size",
|
||||
MXS_MODULE_PARAM_SIZE,
|
||||
CACHE_ZDEFAULT_MAX_SIZE
|
||||
},
|
||||
{
|
||||
"rules",
|
||||
MXS_MODULE_PARAM_PATH
|
||||
},
|
||||
{
|
||||
"debug",
|
||||
MXS_MODULE_PARAM_COUNT,
|
||||
CACHE_ZDEFAULT_DEBUG
|
||||
},
|
||||
{
|
||||
"cached_data",
|
||||
MXS_MODULE_PARAM_ENUM,
|
||||
CACHE_ZDEFAULT_THREAD_MODEL,
|
||||
MXS_MODULE_OPT_NONE,
|
||||
parameter_cached_data_values
|
||||
},
|
||||
{
|
||||
"selects",
|
||||
MXS_MODULE_PARAM_ENUM,
|
||||
CACHE_ZDEFAULT_SELECTS,
|
||||
MXS_MODULE_OPT_NONE,
|
||||
parameter_selects_values
|
||||
},
|
||||
{
|
||||
"cache_in_transactions",
|
||||
MXS_MODULE_PARAM_ENUM,
|
||||
CACHE_ZDEFAULT_CACHE_IN_TRXS,
|
||||
MXS_MODULE_OPT_NONE,
|
||||
parameter_cache_in_trxs_values
|
||||
},
|
||||
{
|
||||
"enabled",
|
||||
MXS_MODULE_PARAM_BOOL,
|
||||
CACHE_ZDEFAULT_ENABLED
|
||||
},
|
||||
{MXS_END_MODULE_PARAMS}
|
||||
}
|
||||
};
|
||||
|
||||
static bool populated = false;
|
||||
|
||||
if (!populated)
|
||||
{
|
||||
CacheConfig::specification().populate(info);
|
||||
populated = true;
|
||||
}
|
||||
|
||||
return &info;
|
||||
}
|
||||
|
||||
@ -267,12 +146,10 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE()
|
||||
|
||||
CacheFilter::CacheFilter()
|
||||
{
|
||||
cache_config_reset(m_config);
|
||||
}
|
||||
|
||||
CacheFilter::~CacheFilter()
|
||||
{
|
||||
cache_config_finish(m_config);
|
||||
}
|
||||
|
||||
// static
|
||||
@ -284,9 +161,9 @@ CacheFilter* CacheFilter::create(const char* zName, MXS_CONFIG_PARAMETER* ppPara
|
||||
{
|
||||
Cache* pCache = NULL;
|
||||
|
||||
if (process_params(ppParams, pFilter->m_config))
|
||||
if (CacheConfig::specification().configure(pFilter->m_config, *ppParams))
|
||||
{
|
||||
switch (pFilter->m_config.thread_model)
|
||||
switch (pFilter->m_config.thread_model.get())
|
||||
{
|
||||
case CACHE_THREAD_MODEL_MT:
|
||||
MXS_NOTICE("Creating shared cache.");
|
||||
@ -309,7 +186,6 @@ CacheFilter* CacheFilter::create(const char* zName, MXS_CONFIG_PARAMETER* ppPara
|
||||
}
|
||||
else
|
||||
{
|
||||
cache_config_finish(pFilter->m_config);
|
||||
delete pFilter;
|
||||
pFilter = NULL;
|
||||
}
|
||||
@ -339,130 +215,3 @@ uint64_t CacheFilter::getCapabilities()
|
||||
{
|
||||
return RCAP_TYPE_NONE;
|
||||
}
|
||||
|
||||
// static
|
||||
bool CacheFilter::process_params(MXS_CONFIG_PARAMETER* ppParams, CACHE_CONFIG& config)
|
||||
{
|
||||
bool error = false;
|
||||
|
||||
config.debug = ppParams->get_integer("debug");
|
||||
config.hard_ttl = ppParams->get_duration("hard_ttl", mxs::config::INTERPRET_AS_SECONDS).count();
|
||||
config.soft_ttl = ppParams->get_duration("soft_ttl", mxs::config::INTERPRET_AS_SECONDS).count();
|
||||
config.max_size = ppParams->get_size("max_size");
|
||||
config.max_count = ppParams->get_integer("max_count");
|
||||
config.storage = ppParams->get_c_str_copy("storage");
|
||||
config.max_resultset_rows = ppParams->get_integer("max_resultset_rows");
|
||||
config.max_resultset_size = ppParams->get_size("max_resultset_size");
|
||||
config.thread_model = static_cast<cache_thread_model_t>(ppParams->get_enum("cached_data",
|
||||
parameter_cached_data_values));
|
||||
config.selects = static_cast<cache_selects_t>(ppParams->get_enum("selects",
|
||||
parameter_selects_values));
|
||||
config.cache_in_trxs = static_cast<cache_in_trxs_t>(ppParams->get_enum("cache_in_transactions",
|
||||
parameter_cache_in_trxs_values));
|
||||
config.enabled = ppParams->get_bool("enabled");
|
||||
|
||||
if (!config.storage)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
|
||||
if ((config.debug < CACHE_DEBUG_MIN) || (config.debug > CACHE_DEBUG_MAX))
|
||||
{
|
||||
MXS_ERROR("The value of the configuration entry 'debug' must "
|
||||
"be between %d and %d, inclusive.",
|
||||
CACHE_DEBUG_MIN,
|
||||
CACHE_DEBUG_MAX);
|
||||
error = true;
|
||||
}
|
||||
|
||||
config.rules = ppParams->get_c_str_copy("rules");
|
||||
|
||||
string storage_options = ppParams->get_string("storage_options");
|
||||
if (!storage_options.empty())
|
||||
{
|
||||
config.storage_options = MXS_STRDUP(storage_options.c_str());
|
||||
|
||||
if (config.storage_options)
|
||||
{
|
||||
int argc = 1;
|
||||
char* arg = config.storage_options;
|
||||
|
||||
while ((arg = strchr(arg, ',')))
|
||||
{
|
||||
arg = arg + 1;
|
||||
++argc;
|
||||
}
|
||||
|
||||
config.storage_argv = (char**) MXS_MALLOC((argc + 1) * sizeof(char*));
|
||||
|
||||
if (config.storage_argv)
|
||||
{
|
||||
config.storage_argc = argc;
|
||||
|
||||
int i = 0;
|
||||
arg = config.storage_options;
|
||||
config.storage_argv[i++] = arg;
|
||||
|
||||
while ((arg = strchr(config.storage_options, ',')))
|
||||
{
|
||||
*arg = 0;
|
||||
++arg;
|
||||
config.storage_argv[i++] = arg;
|
||||
}
|
||||
|
||||
config.storage_argv[i] = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_FREE(config.storage_options);
|
||||
config.storage_options = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!error)
|
||||
{
|
||||
if (config.soft_ttl > config.hard_ttl)
|
||||
{
|
||||
MXS_WARNING("The value of 'soft_ttl' must be less than or equal to that of 'hard_ttl'. "
|
||||
"Setting 'soft_ttl' to the same value as 'hard_ttl'.");
|
||||
config.soft_ttl = config.hard_ttl;
|
||||
}
|
||||
|
||||
if (config.max_resultset_size == 0)
|
||||
{
|
||||
if (config.max_size != 0)
|
||||
{
|
||||
// If a specific size has been configured for 'max_size' but 'max_resultset_size'
|
||||
// has not been specifically set, then we silently set it to the same as 'max_size'.
|
||||
config.max_resultset_size = config.max_size;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mxb_assert(config.max_resultset_size != 0);
|
||||
|
||||
if ((config.max_size != 0) && (config.max_resultset_size > config.max_size))
|
||||
{
|
||||
MXS_WARNING("The value of 'max_resultset_size' %ld should not be larger than "
|
||||
"the value of 'max_size' %ld. Adjusting the value of 'max_resultset_size' "
|
||||
"down to %ld.",
|
||||
config.max_resultset_size,
|
||||
config.max_size,
|
||||
config.max_size);
|
||||
config.max_resultset_size = config.max_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (error)
|
||||
{
|
||||
cache_config_finish(config);
|
||||
}
|
||||
|
||||
return !error;
|
||||
}
|
||||
|
7
server/modules/filter/cache/cachefilter.hh
vendored
7
server/modules/filter/cache/cachefilter.hh
vendored
@ -14,10 +14,12 @@
|
||||
|
||||
#include <maxscale/ccdefs.hh>
|
||||
#include <limits.h>
|
||||
#include <maxscale/config2.hh>
|
||||
#include <maxscale/filter.hh>
|
||||
#include "rules.hh"
|
||||
#include "cache.hh"
|
||||
#include "cachefiltersession.hh"
|
||||
#include "cacheconfig.hh"
|
||||
|
||||
|
||||
class CacheFilter : public maxscale::Filter<CacheFilter, CacheFilterSession>
|
||||
@ -45,15 +47,14 @@ public:
|
||||
|
||||
uint64_t getCapabilities();
|
||||
|
||||
|
||||
private:
|
||||
CacheFilter();
|
||||
|
||||
CacheFilter(const CacheFilter&);
|
||||
CacheFilter& operator=(const CacheFilter&);
|
||||
|
||||
static bool process_params(MXS_CONFIG_PARAMETER* ppParams, CACHE_CONFIG& config);
|
||||
|
||||
private:
|
||||
CACHE_CONFIG m_config;
|
||||
CacheConfig m_config;
|
||||
std::auto_ptr<Cache> m_sCache;
|
||||
};
|
||||
|
@ -23,12 +23,12 @@
|
||||
namespace
|
||||
{
|
||||
|
||||
inline bool cache_max_resultset_rows_exceeded(const CACHE_CONFIG& config, uint64_t rows)
|
||||
inline bool cache_max_resultset_rows_exceeded(const CacheConfig& config, uint64_t rows)
|
||||
{
|
||||
return config.max_resultset_rows == 0 ? false : rows > config.max_resultset_rows;
|
||||
}
|
||||
|
||||
inline bool cache_max_resultset_size_exceeded(const CACHE_CONFIG& config, uint64_t size)
|
||||
inline bool cache_max_resultset_size_exceeded(const CacheConfig& config, uint64_t size)
|
||||
{
|
||||
return config.max_resultset_size == 0 ? false : size > config.max_resultset_size;
|
||||
}
|
||||
@ -189,8 +189,8 @@ CacheFilterSession::CacheFilterSession(MXS_SESSION* pSession, Cache* pCache, cha
|
||||
, m_is_read_only(true)
|
||||
, m_use(pCache->config().enabled)
|
||||
, m_populate(pCache->config().enabled)
|
||||
, m_soft_ttl(pCache->config().soft_ttl)
|
||||
, m_hard_ttl(pCache->config().hard_ttl)
|
||||
, m_soft_ttl(pCache->config().soft_ttl.count())
|
||||
, m_hard_ttl(pCache->config().hard_ttl.count())
|
||||
{
|
||||
m_key.data = 0;
|
||||
|
||||
@ -808,7 +808,7 @@ CacheFilterSession::cache_action_t CacheFilterSession::get_cache_action(GWBUF* p
|
||||
|
||||
const char* zPrimary_reason = NULL;
|
||||
const char* zSecondary_reason = "";
|
||||
const CACHE_CONFIG& config = m_pCache->config();
|
||||
const CacheConfig& config = m_pCache->config();
|
||||
|
||||
if (qc_query_is_type(type_mask, QUERY_TYPE_BEGIN_TRX))
|
||||
{
|
||||
|
@ -109,7 +109,7 @@ private:
|
||||
|
||||
bool log_decisions() const
|
||||
{
|
||||
return m_pCache->config().debug & CACHE_DEBUG_DECISIONS ? true : false;
|
||||
return m_pCache->config().debug.is_set(CACHE_DEBUG_DECISIONS);
|
||||
}
|
||||
|
||||
void store_result();
|
||||
|
14
server/modules/filter/cache/cachemt.cc
vendored
14
server/modules/filter/cache/cachemt.cc
vendored
@ -19,7 +19,7 @@
|
||||
using std::shared_ptr;
|
||||
|
||||
CacheMT::CacheMT(const std::string& name,
|
||||
const CACHE_CONFIG* pConfig,
|
||||
const CacheConfig* pConfig,
|
||||
const std::vector<SCacheRules>& rules,
|
||||
SStorageFactory sFactory,
|
||||
Storage* pStorage)
|
||||
@ -32,7 +32,7 @@ CacheMT::~CacheMT()
|
||||
{
|
||||
}
|
||||
|
||||
CacheMT* CacheMT::Create(const std::string& name, const CACHE_CONFIG* pConfig)
|
||||
CacheMT* CacheMT::Create(const std::string& name, const CacheConfig* pConfig)
|
||||
{
|
||||
mxb_assert(pConfig);
|
||||
|
||||
@ -74,17 +74,17 @@ void CacheMT::refreshed(const CACHE_KEY& key, const CacheFilterSession* pSession
|
||||
|
||||
// static
|
||||
CacheMT* CacheMT::Create(const std::string& name,
|
||||
const CACHE_CONFIG* pConfig,
|
||||
const CacheConfig* pConfig,
|
||||
const std::vector<SCacheRules>& rules,
|
||||
SStorageFactory sFactory)
|
||||
{
|
||||
CacheMT* pCache = NULL;
|
||||
|
||||
CacheStorageConfig storage_config(CACHE_THREAD_MODEL_MT,
|
||||
pConfig->hard_ttl,
|
||||
pConfig->soft_ttl,
|
||||
pConfig->max_count,
|
||||
pConfig->max_size);
|
||||
pConfig->hard_ttl.count(),
|
||||
pConfig->soft_ttl.count(),
|
||||
pConfig->max_count.get(),
|
||||
pConfig->max_size.get());
|
||||
|
||||
int argc = pConfig->storage_argc;
|
||||
char** argv = pConfig->storage_argv;
|
||||
|
6
server/modules/filter/cache/cachemt.hh
vendored
6
server/modules/filter/cache/cachemt.hh
vendored
@ -23,7 +23,7 @@ class CacheMT : public CacheSimple
|
||||
public:
|
||||
~CacheMT();
|
||||
|
||||
static CacheMT* Create(const std::string& name, const CACHE_CONFIG* pConfig);
|
||||
static CacheMT* Create(const std::string& name, const CacheConfig* pConfig);
|
||||
|
||||
json_t* get_info(uint32_t what) const;
|
||||
|
||||
@ -33,13 +33,13 @@ public:
|
||||
|
||||
private:
|
||||
CacheMT(const std::string& name,
|
||||
const CACHE_CONFIG* pConfig,
|
||||
const CacheConfig* pConfig,
|
||||
const std::vector<SCacheRules>& rules,
|
||||
SStorageFactory sFactory,
|
||||
Storage* pStorage);
|
||||
|
||||
static CacheMT* Create(const std::string& name,
|
||||
const CACHE_CONFIG* pConfig,
|
||||
const CacheConfig* pConfig,
|
||||
const std::vector<SCacheRules>& rules,
|
||||
SStorageFactory sFactory);
|
||||
|
||||
|
6
server/modules/filter/cache/cachept.cc
vendored
6
server/modules/filter/cache/cachept.cc
vendored
@ -47,7 +47,7 @@ inline int thread_index()
|
||||
}
|
||||
|
||||
CachePT::CachePT(const std::string& name,
|
||||
const CACHE_CONFIG* pConfig,
|
||||
const CacheConfig* pConfig,
|
||||
const std::vector<SCacheRules>& rules,
|
||||
SStorageFactory sFactory,
|
||||
const Caches& caches)
|
||||
@ -62,7 +62,7 @@ CachePT::~CachePT()
|
||||
}
|
||||
|
||||
// static
|
||||
CachePT* CachePT::Create(const std::string& name, const CACHE_CONFIG* pConfig)
|
||||
CachePT* CachePT::Create(const std::string& name, const CacheConfig* pConfig)
|
||||
{
|
||||
mxb_assert(pConfig);
|
||||
|
||||
@ -148,7 +148,7 @@ cache_result_t CachePT::del_value(const CACHE_KEY& key)
|
||||
|
||||
// static
|
||||
CachePT* CachePT::Create(const std::string& name,
|
||||
const CACHE_CONFIG* pConfig,
|
||||
const CacheConfig* pConfig,
|
||||
const std::vector<SCacheRules>& rules,
|
||||
SStorageFactory sFactory)
|
||||
{
|
||||
|
6
server/modules/filter/cache/cachept.hh
vendored
6
server/modules/filter/cache/cachept.hh
vendored
@ -22,7 +22,7 @@ class CachePT : public Cache
|
||||
public:
|
||||
~CachePT();
|
||||
|
||||
static CachePT* Create(const std::string& name, const CACHE_CONFIG* pConfig);
|
||||
static CachePT* Create(const std::string& name, const CacheConfig* pConfig);
|
||||
|
||||
bool must_refresh(const CACHE_KEY& key, const CacheFilterSession* pSession);
|
||||
|
||||
@ -47,13 +47,13 @@ private:
|
||||
typedef std::vector<SCache> Caches;
|
||||
|
||||
CachePT(const std::string& name,
|
||||
const CACHE_CONFIG* pConfig,
|
||||
const CacheConfig* pConfig,
|
||||
const std::vector<SCacheRules>& rules,
|
||||
SStorageFactory sFactory,
|
||||
const Caches& caches);
|
||||
|
||||
static CachePT* Create(const std::string& name,
|
||||
const CACHE_CONFIG* pConfig,
|
||||
const CacheConfig* pConfig,
|
||||
const std::vector<SCacheRules>& rules,
|
||||
SStorageFactory sFactory);
|
||||
|
||||
|
4
server/modules/filter/cache/cachesimple.cc
vendored
4
server/modules/filter/cache/cachesimple.cc
vendored
@ -17,7 +17,7 @@
|
||||
#include "storagefactory.hh"
|
||||
|
||||
CacheSimple::CacheSimple(const std::string& name,
|
||||
const CACHE_CONFIG* pConfig,
|
||||
const CacheConfig* pConfig,
|
||||
const std::vector<SCacheRules>& rules,
|
||||
SStorageFactory sFactory,
|
||||
Storage* pStorage)
|
||||
@ -32,7 +32,7 @@ CacheSimple::~CacheSimple()
|
||||
}
|
||||
|
||||
// static
|
||||
bool CacheSimple::Create(const CACHE_CONFIG& config,
|
||||
bool CacheSimple::Create(const CacheConfig& config,
|
||||
std::vector<SCacheRules>* pRules,
|
||||
StorageFactory** ppFactory)
|
||||
{
|
||||
|
4
server/modules/filter/cache/cachesimple.hh
vendored
4
server/modules/filter/cache/cachesimple.hh
vendored
@ -36,12 +36,12 @@ public:
|
||||
|
||||
protected:
|
||||
CacheSimple(const std::string& name,
|
||||
const CACHE_CONFIG* pConfig,
|
||||
const CacheConfig* pConfig,
|
||||
const std::vector<SCacheRules>& Rules,
|
||||
SStorageFactory sFactory,
|
||||
Storage* pStorage);
|
||||
|
||||
static bool Create(const CACHE_CONFIG& config,
|
||||
static bool Create(const CacheConfig& config,
|
||||
std::vector<SCacheRules>* pRules,
|
||||
StorageFactory** ppFactory);
|
||||
|
||||
|
16
server/modules/filter/cache/cachest.cc
vendored
16
server/modules/filter/cache/cachest.cc
vendored
@ -19,7 +19,7 @@
|
||||
using std::shared_ptr;
|
||||
|
||||
CacheST::CacheST(const std::string& name,
|
||||
const CACHE_CONFIG* pConfig,
|
||||
const CacheConfig* pConfig,
|
||||
const std::vector<SCacheRules>& rules,
|
||||
SStorageFactory sFactory,
|
||||
Storage* pStorage)
|
||||
@ -32,7 +32,7 @@ CacheST::~CacheST()
|
||||
{
|
||||
}
|
||||
|
||||
CacheST* CacheST::Create(const std::string& name, const CACHE_CONFIG* pConfig)
|
||||
CacheST* CacheST::Create(const std::string& name, const CacheConfig* pConfig)
|
||||
{
|
||||
mxb_assert(pConfig);
|
||||
|
||||
@ -55,7 +55,7 @@ CacheST* CacheST::Create(const std::string& name, const CACHE_CONFIG* pConfig)
|
||||
CacheST* CacheST::Create(const std::string& name,
|
||||
const std::vector<SCacheRules>& rules,
|
||||
SStorageFactory sFactory,
|
||||
const CACHE_CONFIG* pConfig)
|
||||
const CacheConfig* pConfig)
|
||||
{
|
||||
mxb_assert(sFactory.get());
|
||||
mxb_assert(pConfig);
|
||||
@ -80,17 +80,17 @@ void CacheST::refreshed(const CACHE_KEY& key, const CacheFilterSession* pSession
|
||||
|
||||
// static
|
||||
CacheST* CacheST::Create(const std::string& name,
|
||||
const CACHE_CONFIG* pConfig,
|
||||
const CacheConfig* pConfig,
|
||||
const std::vector<SCacheRules>& rules,
|
||||
SStorageFactory sFactory)
|
||||
{
|
||||
CacheST* pCache = NULL;
|
||||
|
||||
CacheStorageConfig storage_config(CACHE_THREAD_MODEL_ST,
|
||||
pConfig->hard_ttl,
|
||||
pConfig->soft_ttl,
|
||||
pConfig->max_count,
|
||||
pConfig->max_size);
|
||||
pConfig->hard_ttl.count(),
|
||||
pConfig->soft_ttl.count(),
|
||||
pConfig->max_count.get(),
|
||||
pConfig->max_size.get());
|
||||
|
||||
int argc = pConfig->storage_argc;
|
||||
char** argv = pConfig->storage_argv;
|
||||
|
8
server/modules/filter/cache/cachest.hh
vendored
8
server/modules/filter/cache/cachest.hh
vendored
@ -20,11 +20,11 @@ class CacheST : public CacheSimple
|
||||
public:
|
||||
~CacheST();
|
||||
|
||||
static CacheST* Create(const std::string& name, const CACHE_CONFIG* pConfig);
|
||||
static CacheST* Create(const std::string& name, const CacheConfig* pConfig);
|
||||
static CacheST* Create(const std::string& name,
|
||||
const std::vector<SCacheRules>& rules,
|
||||
SStorageFactory sFactory,
|
||||
const CACHE_CONFIG* pConfig);
|
||||
const CacheConfig* pConfig);
|
||||
|
||||
json_t* get_info(uint32_t what) const;
|
||||
|
||||
@ -34,13 +34,13 @@ public:
|
||||
|
||||
private:
|
||||
CacheST(const std::string& name,
|
||||
const CACHE_CONFIG* pConfig,
|
||||
const CacheConfig* pConfig,
|
||||
const std::vector<SCacheRules>& rules,
|
||||
SStorageFactory sFactory,
|
||||
Storage* pStorage);
|
||||
|
||||
static CacheST* Create(const std::string& name,
|
||||
const CACHE_CONFIG* pConfig,
|
||||
const CacheConfig* pConfig,
|
||||
const std::vector<SCacheRules>& rules,
|
||||
SStorageFactory sFactory);
|
||||
private:
|
||||
|
4
server/modules/filter/cache/rules.hh
vendored
4
server/modules/filter/cache/rules.hh
vendored
@ -226,6 +226,10 @@ public:
|
||||
* @return True, if the rules could be loaded, false otherwise.
|
||||
*/
|
||||
static bool load(const char* zPath, uint32_t debug, std::vector<SCacheRules>* pRules);
|
||||
static bool load(const std::string& path, uint32_t debug, std::vector<SCacheRules>* pRules)
|
||||
{
|
||||
return load(path.c_str(), debug, pRules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the json rules object.
|
||||
|
@ -23,6 +23,10 @@ public:
|
||||
~StorageFactory();
|
||||
|
||||
static StorageFactory* Open(const char* zName);
|
||||
static StorageFactory* Open(const std::string& name)
|
||||
{
|
||||
return Open(name.c_str());
|
||||
}
|
||||
|
||||
/**
|
||||
* The capabilities of storages created using this factory.
|
||||
|
@ -29,10 +29,10 @@ namespace mock = maxscale::mock;
|
||||
namespace
|
||||
{
|
||||
|
||||
struct CONFIG
|
||||
struct SETTINGS
|
||||
{
|
||||
bool stop_at_first_error;
|
||||
} config =
|
||||
} settings =
|
||||
{
|
||||
true, // stop_at_first_error
|
||||
};
|
||||
@ -366,7 +366,7 @@ int run()
|
||||
|
||||
cout << endl;
|
||||
|
||||
if ((rv != 0) && config.stop_at_first_error)
|
||||
if ((rv != 0) && settings.stop_at_first_error)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -414,7 +414,7 @@ int main(int argc, char* argv[])
|
||||
switch (c)
|
||||
{
|
||||
case 'd':
|
||||
config.stop_at_first_error = false;
|
||||
settings.stop_at_first_error = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user