Detect double monitoring of servers
Adding a server to multiple monitors is forbidden. This should be detected and reported to the end user. The information provided by the config_runtime system to the client isn't as detailed as it could be. Some sort of an error message stack should be added so that client facing interfaces could properly report the reason for the failure. Currently the only way to detect the reason of the failure is to parse the log files.
This commit is contained in:
parent
312cf69739
commit
cb218804ef
@ -206,7 +206,7 @@ struct monitor
|
||||
extern MONITOR *monitor_alloc(char *, char *);
|
||||
extern void monitor_free(MONITOR *);
|
||||
extern MONITOR *monitor_find(const char *);
|
||||
extern void monitorAddServer(MONITOR *mon, SERVER *server);
|
||||
extern bool monitorAddServer(MONITOR *mon, SERVER *server);
|
||||
extern void monitorRemoveServer(MONITOR *mon, SERVER *server);
|
||||
extern void monitorAddUser(MONITOR *, char *, char *);
|
||||
extern void monitorAddParameters(MONITOR *monitor, CONFIG_PARAMETER *params);
|
||||
|
@ -240,7 +240,7 @@ bool serviceStartListener(SERVICE *service, const char *name);
|
||||
SERVICE* service_find(const char *name);
|
||||
|
||||
// TODO: Change binlogrouter to use the functions in config_runtime.h
|
||||
void serviceAddBackend(SERVICE *service, SERVER *server);
|
||||
bool serviceAddBackend(SERVICE *service, SERVER *server);
|
||||
|
||||
/**
|
||||
* @brief Check if a service uses a server
|
||||
|
@ -29,23 +29,26 @@ bool runtime_link_server(SERVER *server, const char *target)
|
||||
SERVICE *service = service_find(target);
|
||||
MONITOR *monitor = service ? NULL : monitor_find(target);
|
||||
|
||||
if (service || monitor)
|
||||
if (service)
|
||||
{
|
||||
rval = true;
|
||||
|
||||
if (service)
|
||||
if (serviceAddBackend(service, server))
|
||||
{
|
||||
serviceAddBackend(service, server);
|
||||
service_serialize_servers(service);
|
||||
rval = true;
|
||||
}
|
||||
else if (monitor)
|
||||
}
|
||||
else if (monitor)
|
||||
{
|
||||
if (monitorAddServer(monitor, server))
|
||||
{
|
||||
monitorAddServer(monitor, server);
|
||||
monitor_serialize_servers(monitor);
|
||||
rval = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (rval)
|
||||
{
|
||||
const char *type = service ? "service" : "monitor";
|
||||
|
||||
MXS_NOTICE("Added server '%s' to %s '%s'", server->unique_name, type, target);
|
||||
}
|
||||
|
||||
|
@ -247,24 +247,17 @@ monitorStopAll()
|
||||
* @param mon The Monitor instance
|
||||
* @param server The Server to add to the monitoring
|
||||
*/
|
||||
void
|
||||
monitorAddServer(MONITOR *mon, SERVER *server)
|
||||
bool monitorAddServer(MONITOR *mon, SERVER *server)
|
||||
{
|
||||
bool new_server = true;
|
||||
spinlock_acquire(&mon->lock);
|
||||
bool rval = false;
|
||||
|
||||
for (MONITOR_SERVERS *db = mon->databases; db; db = db->next)
|
||||
if (monitor_server_in_use(server))
|
||||
{
|
||||
if (db->server == server)
|
||||
{
|
||||
new_server = false;
|
||||
}
|
||||
MXS_ERROR("Server '%s' is already monitored.", server->unique_name);
|
||||
}
|
||||
|
||||
spinlock_release(&mon->lock);
|
||||
|
||||
if (new_server)
|
||||
else
|
||||
{
|
||||
rval = true;
|
||||
MONITOR_SERVERS *db = (MONITOR_SERVERS *)MXS_MALLOC(sizeof(MONITOR_SERVERS));
|
||||
MXS_ABORT_IF_NULL(db);
|
||||
|
||||
@ -307,6 +300,8 @@ monitorAddServer(MONITOR *mon, SERVER *server)
|
||||
monitorStart(mon, mon->parameters);
|
||||
}
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
static void monitor_server_free(MONITOR_SERVERS *tofree)
|
||||
|
@ -768,15 +768,17 @@ static SERVER_REF* server_ref_create(SERVER *server)
|
||||
* @param service The service to add the server to
|
||||
* @param server The server to add
|
||||
*/
|
||||
void
|
||||
serviceAddBackend(SERVICE *service, SERVER *server)
|
||||
bool serviceAddBackend(SERVICE *service, SERVER *server)
|
||||
{
|
||||
bool rval = false;
|
||||
|
||||
if (!serviceHasBackend(service, server))
|
||||
{
|
||||
SERVER_REF *new_ref = server_ref_create(server);
|
||||
|
||||
if (new_ref)
|
||||
{
|
||||
rval = true;
|
||||
spinlock_acquire(&service->spin);
|
||||
|
||||
service->n_dbref++;
|
||||
@ -816,6 +818,8 @@ serviceAddBackend(SERVICE *service, SERVER *server)
|
||||
spinlock_release(&service->spin);
|
||||
}
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -852,7 +852,8 @@ static void cmd_AddServer(DCB *dcb, SERVER *server, char *v1, char *v2, char *v3
|
||||
}
|
||||
else
|
||||
{
|
||||
dcb_printf(dcb, "No service or monitor with the name '%s'\n", values[i]);
|
||||
dcb_printf(dcb, "Could not add server '%s' to object '%s'. See error log for more details.\n",
|
||||
server->unique_name, values[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user