MXS-2556 Make config::Configuration aware of its object

The name of the object (i.e. the section name from the configuration
file), is now stored in the configuration object for that object.

That way, more contextual and hence morfe user friendly errors and
warnings can be generated.
This commit is contained in:
Johan Wikman
2019-06-11 11:05:15 +03:00
parent df5377f135
commit 04fdaf1fdb
11 changed files with 37 additions and 20 deletions

View File

@ -815,9 +815,15 @@ public:
/** /**
* Constructor * Constructor
* *
* @param name The object (i.e. section name) of this configuration.
* @param pSpecification The specification this instance is a configuration of. * @param pSpecification The specification this instance is a configuration of.
*/ */
Configuration(const Specification* pSpecification); Configuration(const std::string& name, const Specification* pSpecification);
/**
* @return The The object (i.e. section name) of this configuration.
*/
const std::string& name() const;
/** /**
* @return The specification of this configuration. * @return The specification of this configuration.
@ -880,6 +886,7 @@ private:
void remove(Type* pValue); void remove(Type* pValue);
private: private:
std::string m_name;
const Specification& m_specification; const Specification& m_specification;
ValuesByName m_values; ValuesByName m_values;
}; };

View File

@ -385,11 +385,17 @@ void Param::populate(MXS_MODULE_PARAM& param) const
/** /**
* class Configuration * class Configuration
*/ */
Configuration::Configuration(const config::Specification* pSpecification) Configuration::Configuration(const std::string& name, const config::Specification* pSpecification)
: m_specification(*pSpecification) : m_name(name)
, m_specification(*pSpecification)
{ {
} }
const std::string& Configuration::name() const
{
return m_name;
}
const config::Specification& Configuration::specification() const const config::Specification& Configuration::specification() const
{ {
return m_specification; return m_specification;

View File

@ -338,7 +338,7 @@ int main()
specification.document(cout); specification.document(cout);
config::Configuration configuration(&specification); config::Configuration configuration("test", &specification);
int nErrors = 0; int nErrors = 0;

View File

@ -146,8 +146,8 @@ config::ParamBool CacheConfig::s_enabled(
true true
); );
CacheConfig::CacheConfig() CacheConfig::CacheConfig(const std::string& name)
: config::Configuration(&s_specification) : config::Configuration(name, &s_specification)
, storage(this, &s_storage) , storage(this, &s_storage)
, storage_options(this, &s_storage_options) , storage_options(this, &s_storage_options)
, hard_ttl(this, &s_hard_ttl) , hard_ttl(this, &s_hard_ttl)

View File

@ -38,7 +38,7 @@ const cache_thread_model CACHE_DEFAULT_THREAD_MODEL = CACHE_THREAD_MODEL_ST;
class CacheConfig : public config::Configuration class CacheConfig : public config::Configuration
{ {
public: public:
CacheConfig(); CacheConfig(const std::string& name);
~CacheConfig(); ~CacheConfig();
CacheConfig(const CacheConfig&) = delete; CacheConfig(const CacheConfig&) = delete;

View File

@ -144,7 +144,8 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE()
// CacheFilter // CacheFilter
// //
CacheFilter::CacheFilter() CacheFilter::CacheFilter(const std::string& name)
: m_config(name)
{ {
} }
@ -155,7 +156,7 @@ CacheFilter::~CacheFilter()
// static // static
CacheFilter* CacheFilter::create(const char* zName, MXS_CONFIG_PARAMETER* ppParams) CacheFilter* CacheFilter::create(const char* zName, MXS_CONFIG_PARAMETER* ppParams)
{ {
CacheFilter* pFilter = new CacheFilter; CacheFilter* pFilter = new CacheFilter(zName);
if (pFilter) if (pFilter)
{ {

View File

@ -49,7 +49,7 @@ public:
private: private:
CacheFilter(); CacheFilter(const std::string& name);
CacheFilter(const CacheFilter&); CacheFilter(const CacheFilter&);
CacheFilter& operator=(const CacheFilter&); CacheFilter& operator=(const CacheFilter&);

View File

@ -190,8 +190,8 @@ sqlite3* open_or_create_db(const std::string& path)
} }
} }
ClustrixMonitor::Config::Config() ClustrixMonitor::Config::Config(const std::string& name)
: m_configuration(&clustrixmon::specification) : m_configuration(name, &clustrixmon::specification)
, m_cluster_monitor_interval(&m_configuration, &clustrixmon::cluster_monitor_interval) , m_cluster_monitor_interval(&m_configuration, &clustrixmon::cluster_monitor_interval)
, m_health_check_threshold(&m_configuration, &clustrixmon::health_check_threshold) , m_health_check_threshold(&m_configuration, &clustrixmon::health_check_threshold)
, m_dynamic_node_detection(&m_configuration, &clustrixmon::dynamic_node_detection) , m_dynamic_node_detection(&m_configuration, &clustrixmon::dynamic_node_detection)
@ -212,6 +212,7 @@ bool ClustrixMonitor::Config::configure(const MXS_CONFIG_PARAMETER& params)
ClustrixMonitor::ClustrixMonitor(const string& name, const string& module, sqlite3* pDb) ClustrixMonitor::ClustrixMonitor(const string& name, const string& module, sqlite3* pDb)
: MonitorWorker(name, module) : MonitorWorker(name, module)
, m_config(name)
, m_pDb(pDb) , m_pDb(pDb)
{ {
} }

View File

@ -31,7 +31,7 @@ public:
class Config class Config
{ {
public: public:
Config(); Config(const std::string& name);
static void populate(MXS_MODULE& module); static void populate(MXS_MODULE& module);

View File

@ -65,8 +65,8 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE()
return &info; return &info;
} }
SmartRouter::Config::Config() SmartRouter::Config::Config(const std::string& name)
: config::Configuration(&smartquery::specification) : config::Configuration(name, &smartquery::specification)
, m_master(this, &smartquery::master) , m_master(this, &smartquery::master)
{ {
} }
@ -100,10 +100,10 @@ bool SmartRouter::Config::post_configure(const MXS_CONFIG_PARAMETER& params)
{ {
if (strcmp(pServer->address, "127.0.0.1") == 0 || strcmp(pServer->address, "localhost")) if (strcmp(pServer->address, "127.0.0.1") == 0 || strcmp(pServer->address, "localhost"))
{ {
MXS_WARNING("The server %s, used by the smartrouter, is currently accessed " MXS_WARNING("The server %s, used by the smartrouter %s, is currently accessed "
"using a TCP/IP socket (%s:%d). For better performance, a Unix " "using a TCP/IP socket (%s:%d). For better performance, a Unix "
"domain socket should be used. See the 'socket' argument.", "domain socket should be used. See the 'socket' argument.",
pServer->name(), pServer->address, pServer->port); pServer->name(), name().c_str(), pServer->address, pServer->port);
} }
} }
} }
@ -124,8 +124,9 @@ bool SmartRouter::Config::post_configure(const MXS_CONFIG_PARAMETER& params)
s += server->name(); s += server->name();
} }
MXS_ERROR("The master server %s, is not one of the servers (%s) of the service.", MXS_ERROR("The master server %s of the smartrouter %s, is not one of the "
m_master.get()->name(), s.c_str()); "servers (%s) of the service.",
m_master.get()->name(), name().c_str(), s.c_str());
} }
return rv; return rv;
@ -149,6 +150,7 @@ SERVICE* SmartRouter::service() const
SmartRouter::SmartRouter(SERVICE* service) SmartRouter::SmartRouter(SERVICE* service)
: mxs::Router<SmartRouter, SmartRouterSession>(service) : mxs::Router<SmartRouter, SmartRouterSession>(service)
, m_config(service->name())
{ {
} }

View File

@ -32,7 +32,7 @@ public:
class Config : public config::Configuration class Config : public config::Configuration
{ {
public: public:
Config(); Config(const std::string& name);
Config(const Config&) = delete; Config(const Config&) = delete;
Config& operator=(const Config&) = delete; Config& operator=(const Config&) = delete;