Move server_set_status and server_clear_status to monitor
The operation goes through monitor code so should be in the according file.
This commit is contained in:
@ -139,6 +139,26 @@ public:
|
||||
|
||||
static bool create_monitor_config(const mxs::Monitor* monitor, const char* filename);
|
||||
|
||||
/**
|
||||
* Set a status bit in the server. If the server is monitored, only some bits can be modified,
|
||||
* and the modification goes through the monitor.
|
||||
*
|
||||
* @param bit The bit to set for the server
|
||||
* @param errmsg_out Error output
|
||||
* @return True on success
|
||||
*/
|
||||
static bool set_server_status(SERVER* srv, int bit, std::string* errmsg_out = NULL);
|
||||
|
||||
/**
|
||||
* Clear a status bit in the server. If the server is monitored, only some bits can be modified,
|
||||
* and the modification goes through the monitor.
|
||||
*
|
||||
* @param bit The bit to clear for the server
|
||||
* @param errmsg_out Error output
|
||||
* @return True on success
|
||||
*/
|
||||
static bool clear_server_status(SERVER* srv, int bit, std::string* errmsg_out);
|
||||
|
||||
/**
|
||||
* Waits until all running monitors have advanced one tick.
|
||||
*/
|
||||
|
@ -474,3 +474,39 @@ json_t* MonitorManager::monitor_relations_to_server(const SERVER* server, const
|
||||
|
||||
return rel;
|
||||
}
|
||||
|
||||
bool MonitorManager::set_server_status(SERVER* srv, int bit, string* errmsg_out)
|
||||
{
|
||||
mxb_assert(Monitor::is_admin_thread());
|
||||
bool written = false;
|
||||
Monitor* mon = MonitorManager::server_is_monitored(srv);
|
||||
if (mon)
|
||||
{
|
||||
written = mon->set_server_status(srv, bit, errmsg_out);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the bit directly */
|
||||
srv->set_status(bit);
|
||||
written = true;
|
||||
}
|
||||
return written;
|
||||
}
|
||||
|
||||
bool MonitorManager::clear_server_status(SERVER* srv, int bit, string* errmsg_out)
|
||||
{
|
||||
mxb_assert(Monitor::is_admin_thread());
|
||||
bool written = false;
|
||||
Monitor* mon = MonitorManager::server_is_monitored(srv);
|
||||
if (mon)
|
||||
{
|
||||
written = mon->clear_server_status(srv, bit, errmsg_out);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Clear bit directly */
|
||||
srv->clear_status(bit);
|
||||
written = true;
|
||||
}
|
||||
return written;
|
||||
}
|
@ -794,7 +794,7 @@ HttpResponse cb_set_server(const HttpRequest& request)
|
||||
if (opt)
|
||||
{
|
||||
string errmsg;
|
||||
if (mxs::server_set_status(server, opt, &errmsg))
|
||||
if (MonitorManager::set_server_status(server, opt, &errmsg))
|
||||
{
|
||||
if (status_is_in_maint(opt) && request.get_option(CN_FORCE) == CN_YES)
|
||||
{
|
||||
@ -821,7 +821,7 @@ HttpResponse cb_clear_server(const HttpRequest& request)
|
||||
if (opt)
|
||||
{
|
||||
string errmsg;
|
||||
if (mxs::server_clear_status(server, opt, &errmsg))
|
||||
if (MonitorManager::clear_server_status(server, opt, &errmsg))
|
||||
{
|
||||
return HttpResponse(MHD_HTTP_NO_CONTENT);
|
||||
}
|
||||
|
@ -922,46 +922,6 @@ bool Server::serialize() const
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool mxs::server_set_status(SERVER* srv, int bit, string* errmsg_out)
|
||||
{
|
||||
bool written = false;
|
||||
/* First check if the server is monitored. This isn't done under a lock
|
||||
* but the race condition cannot cause significant harm. Monitors are never
|
||||
* freed so the pointer stays valid. */
|
||||
Monitor* mon = MonitorManager::server_is_monitored(srv);
|
||||
if (mon)
|
||||
{
|
||||
written = mon->set_server_status(srv, bit, errmsg_out);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Set the bit directly */
|
||||
srv->set_status(bit);
|
||||
written = true;
|
||||
}
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
bool mxs::server_clear_status(SERVER* srv, int bit, string* errmsg_out)
|
||||
{
|
||||
// See server_set_status().
|
||||
bool written = false;
|
||||
Monitor* mon = MonitorManager::server_is_monitored(srv);
|
||||
if (mon)
|
||||
{
|
||||
written = mon->clear_server_status(srv, bit, errmsg_out);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Clear bit directly */
|
||||
srv->clear_status(bit);
|
||||
written = true;
|
||||
}
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
bool SERVER::is_mxs_service()
|
||||
{
|
||||
bool rval = false;
|
||||
|
Reference in New Issue
Block a user