MXS-2556 Add master configuration handling to SmartRouter

This commit is contained in:
Johan Wikman 2019-06-10 19:07:12 +03:00
parent 68af4cb62e
commit acdc3b2396
3 changed files with 110 additions and 2 deletions

View File

@ -16,6 +16,23 @@
#include <maxscale/modutil.hh>
namespace
{
namespace smartquery
{
config::Specification specification(MXS_MODULE_NAME, config::Specification::ROUTER);
config::ParamServer
master(&specification,
"master",
"The server/cluster to be treated as master, that is, the one where updates are sent.");
}
}
/**
* The module entry point.
*
@ -43,13 +60,68 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE()
}
};
SmartRouter::Config::populate(info);
return &info;
}
SmartRouter::Config::Config()
: config::Configuration(&smartquery::specification)
, m_master(this, &smartquery::master)
{
}
void SmartRouter::Config::populate(MXS_MODULE& module)
{
smartquery::specification.populate(module);
}
bool SmartRouter::Config::configure(const MXS_CONFIG_PARAMETER& params)
{
return smartquery::specification.configure(*this, params);
}
bool SmartRouter::Config::post_configure(const MXS_CONFIG_PARAMETER& params)
{
bool rv = true;
auto servers = params.get_server_list(CN_SERVERS);
// TODO: Check that the servers are local ones.
auto it = std::find(servers.begin(), servers.end(), m_master.get());
if (it == servers.end())
{
rv = false;
std::string s;
for (auto server : servers)
{
if (!s.empty())
{
s+= ", ";
}
s += server->name();
}
MXS_ERROR("The master server %s, is not one of the servers (%s) of the service.",
m_master.get()->name(), s.c_str());
}
return rv;
}
bool SmartRouter::configure(MXS_CONFIG_PARAMETER* pParams)
{
// TODO ensure Servers are internal ones. Later TODO call routers directly.
return true;
if (!smartquery::specification.validate(*pParams))
{
return false;
}
// Since post_configure() has been overriden, this may fail.
return m_config.configure(*pParams);
}
SERVICE* SmartRouter::service() const

View File

@ -19,6 +19,7 @@
*/
#include <maxscale/ccdefs.hh>
#include <maxscale/config2.hh>
#include <maxscale/router.hh>
class SmartRouterSession;
@ -28,6 +29,30 @@ class SmartRouterSession;
class SmartRouter : public mxs::Router<SmartRouter, SmartRouterSession>
{
public:
class Config : public config::Configuration
{
public:
Config();
Config(const Config&) = delete;
Config& operator=(const Config&) = delete;
static void populate(MXS_MODULE& module);
bool configure(const MXS_CONFIG_PARAMETER& params);
SERVER* master() const
{
return m_master.get();
}
private:
bool post_configure(const MXS_CONFIG_PARAMETER& params) override;
private:
config::Server m_master;
};
static SmartRouter* create(SERVICE* pService, MXS_CONFIG_PARAMETER* pParams);
SmartRouterSession* newSession(MXS_SESSION* pSession);
@ -38,6 +63,14 @@ public:
bool configure(MXS_CONFIG_PARAMETER* pParams);
SERVICE* service() const;
const Config& config() const
{
return m_config;
}
private:
SmartRouter(SERVICE* service);
Config m_config;
};

View File

@ -121,6 +121,9 @@ SmartRouterSession* SmartRouterSession::create(SmartRouter* pRouter, MXS_SESSION
{
Clusters clusters;
SERVER* pMaster = pRouter->config().master();
// TODO: Use pMaster below.
bool is_master = true; // TODO this will be read from config
int master_pos = 0; // and this will be initialized to the position of the master