MXS-2314 Populate services with servers

The services whose servers are defined using a monitor, will
now be populated from the monitor.

Note, no consideration has yet been given to runtime changes.
This commit is contained in:
Johan Wikman 2019-02-06 14:38:48 +02:00
parent f271c5cea1
commit b4eb87dfcc
6 changed files with 48 additions and 1 deletions

View File

@ -394,6 +394,11 @@ private:
*/
int launch_command(MXS_MONITORED_SERVER* ptr, EXTERNCMD* cmd);
/**
* Populate services with the servers of the monitor.
*/
virtual void populate_services();
bool journal_is_stale();
};

View File

@ -1692,7 +1692,11 @@ static bool process_config_context(CONFIG_CONTEXT* context)
}
}
if (error_count)
if (error_count == 0)
{
MonitorManager::populate_services();
}
else
{
MXS_ERROR("%d errors were encountered while processing the configuration "
"file '%s'.",

View File

@ -107,6 +107,11 @@ public:
static void destroy_all_monitors();
static void monitor_start(Monitor*, const MXS_CONFIG_PARAMETER*);
/**
* @brief Populate services with the servers of the monitors.
*/
static void populate_services();
};

View File

@ -48,6 +48,7 @@
#include "internal/monitor.hh"
#include "internal/modules.hh"
#include "internal/server.hh"
#include "internal/service.hh"
/** Schema version, journals must have a matching version */
#define MMB_SCHEMA_VERSION 2
@ -278,6 +279,14 @@ void MonitorManager::monitor_start(Monitor* monitor, const MXS_CONFIG_PARAMETER*
}
}
void MonitorManager::populate_services()
{
this_unit.foreach_monitor([](Monitor* pMonitor) -> bool {
pMonitor->populate_services();
return true;
});
}
/**
* Start all monitors
*/
@ -2364,8 +2373,16 @@ bool Monitor::clear_server_status(SERVER* srv, int bit, string* errmsg_out)
}
return written;
}
void Monitor::populate_services()
{
mxb_assert(m_state == MONITOR_STATE_STOPPED);
for (MXS_MONITORED_SERVER* pMs : m_servers)
{
service_add_server(this, pMs->server);
}
}
void monitor_debug_wait()

View File

@ -16,6 +16,7 @@
#include <set>
#include <maxscale/json_api.h>
#include "../../../core/internal/config_runtime.hh"
#include "../../../core/internal/service.hh"
namespace http = mxb::http;
using namespace std;
@ -65,6 +66,15 @@ bool ClustrixMonitor::configure(const MXS_CONFIG_PARAMETER* pParams)
return true;
}
void ClustrixMonitor::populate_services()
{
mxb_assert(Monitor::m_state == MONITOR_STATE_STOPPED);
// The servers that the Clustrix monitor has been configured with are
// only used for bootstrapping and services will not be populated
// with them.
}
bool ClustrixMonitor::softfail(SERVER* pServer, json_t** ppError)
{
bool rv = false;
@ -335,6 +345,10 @@ void ClustrixMonitor::refresh_nodes()
health_check_threshold, pServer);
m_nodes.insert(make_pair(id, node));
// New server, so it needs to be added to all services that
// use this monitor for defining its cluster of servers.
service_add_server(this, pServer);
}
else
{

View File

@ -64,6 +64,8 @@ public:
bool configure(const MXS_CONFIG_PARAMETER* pParams) override;
void populate_services() override;
bool softfail(SERVER* pServer, json_t** ppError);
bool unsoftfail(SERVER* pServer, json_t** ppError);