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:
@ -528,26 +528,3 @@ private:
|
|||||||
maxbase::EMAverage m_response_time; /**< Response time calculations for this server */
|
maxbase::EMAverage m_response_time; /**< Response time calculations for this server */
|
||||||
std::mutex m_average_write_mutex; /**< Protects response time from concurrent writing */
|
std::mutex m_average_write_mutex; /**< Protects response time from concurrent writing */
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace maxscale
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set a status bit in the server. This should not be called from within a monitor. If the server is
|
|
||||||
* monitored, only set the pending bit.
|
|
||||||
*
|
|
||||||
* @param bit The bit to set for the server
|
|
||||||
* @param errmsg_out Error output
|
|
||||||
*/
|
|
||||||
bool server_set_status(SERVER* server, int bit, std::string* errmsg_out = NULL);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear a status bit in the server under a lock. This ensures synchronization
|
|
||||||
* with the server monitor thread. Calling this inside the monitor will likely
|
|
||||||
* cause a deadlock. If the server is monitored, only clear the pending bit.
|
|
||||||
*
|
|
||||||
* @param bit The bit to clear for the server
|
|
||||||
* @param errmsg_out Error output
|
|
||||||
*/
|
|
||||||
bool server_clear_status(SERVER* server, int bit, std::string* errmsg_out = NULL);
|
|
||||||
}
|
|
||||||
|
@ -139,6 +139,26 @@ public:
|
|||||||
|
|
||||||
static bool create_monitor_config(const mxs::Monitor* monitor, const char* filename);
|
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.
|
* 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;
|
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)
|
if (opt)
|
||||||
{
|
{
|
||||||
string errmsg;
|
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)
|
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)
|
if (opt)
|
||||||
{
|
{
|
||||||
string errmsg;
|
string errmsg;
|
||||||
if (mxs::server_clear_status(server, opt, &errmsg))
|
if (MonitorManager::clear_server_status(server, opt, &errmsg))
|
||||||
{
|
{
|
||||||
return HttpResponse(MHD_HTTP_NO_CONTENT);
|
return HttpResponse(MHD_HTTP_NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
@ -922,46 +922,6 @@ bool Server::serialize() const
|
|||||||
return rval;
|
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 SERVER::is_mxs_service()
|
||||||
{
|
{
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
#include <maxscale/router.hh>
|
#include <maxscale/router.hh>
|
||||||
#include <maxscale/server.hh>
|
#include <maxscale/server.hh>
|
||||||
#include <maxscale/utils.h>
|
#include <maxscale/utils.h>
|
||||||
|
// For setting server status through monitor
|
||||||
|
#include "../../../../core/internal/monitormanager.hh"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* MySQL Protocol module for handling the protocol between the gateway
|
* MySQL Protocol module for handling the protocol between the gateway
|
||||||
@ -340,10 +342,16 @@ static void handle_error_response(DCB* dcb, GWBUF* buffer)
|
|||||||
errcode,
|
errcode,
|
||||||
bufstr);
|
bufstr);
|
||||||
|
|
||||||
/** If the error is ER_HOST_IS_BLOCKED put the server into maintenace mode.
|
/** If the error is ER_HOST_IS_BLOCKED put the server into maintenance mode.
|
||||||
* This will prevent repeated authentication failures. */
|
* This will prevent repeated authentication failures. */
|
||||||
if (errcode == ER_HOST_IS_BLOCKED)
|
if (errcode == ER_HOST_IS_BLOCKED)
|
||||||
{
|
{
|
||||||
|
auto main_worker = mxs::RoutingWorker::get(mxs::RoutingWorker::MAIN);
|
||||||
|
auto target_server = dcb->server;
|
||||||
|
main_worker->execute([target_server]() {
|
||||||
|
MonitorManager::set_server_status(target_server, SERVER_MAINT);
|
||||||
|
}, mxb::Worker::EXECUTE_AUTO);
|
||||||
|
|
||||||
MXS_ERROR("Server %s has been put into maintenance mode due to the server blocking connections "
|
MXS_ERROR("Server %s has been put into maintenance mode due to the server blocking connections "
|
||||||
"from MaxScale. Run 'mysqladmin -h %s -P %d flush-hosts' on this server before taking "
|
"from MaxScale. Run 'mysqladmin -h %s -P %d flush-hosts' on this server before taking "
|
||||||
"this server out of maintenance mode. To avoid this problem in the future, set "
|
"this server out of maintenance mode. To avoid this problem in the future, set "
|
||||||
@ -351,8 +359,6 @@ static void handle_error_response(DCB* dcb, GWBUF* buffer)
|
|||||||
dcb->server->name(),
|
dcb->server->name(),
|
||||||
dcb->server->address,
|
dcb->server->address,
|
||||||
dcb->server->port);
|
dcb->server->port);
|
||||||
|
|
||||||
mxs::server_set_status(dcb->server, SERVER_MAINT);
|
|
||||||
}
|
}
|
||||||
else if (errcode == ER_ACCESS_DENIED_ERROR
|
else if (errcode == ER_ACCESS_DENIED_ERROR
|
||||||
|| errcode == ER_DBACCESS_DENIED_ERROR
|
|| errcode == ER_DBACCESS_DENIED_ERROR
|
||||||
|
@ -2525,7 +2525,7 @@ static void set_server(DCB* dcb, Server* server, char* bit)
|
|||||||
if ((bitvalue = SERVER::status_from_string(bit)) != 0)
|
if ((bitvalue = SERVER::status_from_string(bit)) != 0)
|
||||||
{
|
{
|
||||||
std::string errmsg;
|
std::string errmsg;
|
||||||
if (!mxs::server_set_status(server, bitvalue, &errmsg))
|
if (!MonitorManager::set_server_status(server, bitvalue, &errmsg))
|
||||||
{
|
{
|
||||||
dcb_printf(dcb, "%s\n", errmsg.c_str());
|
dcb_printf(dcb, "%s\n", errmsg.c_str());
|
||||||
}
|
}
|
||||||
@ -2551,7 +2551,7 @@ static void clear_server(DCB* dcb, Server* server, char* bit)
|
|||||||
if ((bitvalue = SERVER::status_from_string(bit)) != 0)
|
if ((bitvalue = SERVER::status_from_string(bit)) != 0)
|
||||||
{
|
{
|
||||||
std::string errmsg;
|
std::string errmsg;
|
||||||
if (!mxs::server_clear_status(server, bitvalue, &errmsg))
|
if (!MonitorManager::clear_server_status(server, bitvalue, &errmsg))
|
||||||
{
|
{
|
||||||
dcb_printf(dcb, "%s", errmsg.c_str());
|
dcb_printf(dcb, "%s", errmsg.c_str());
|
||||||
}
|
}
|
||||||
|
@ -325,7 +325,7 @@ void exec_set_server(DCB* dcb, MAXINFO_TREE* tree)
|
|||||||
if (status != 0)
|
if (status != 0)
|
||||||
{
|
{
|
||||||
std::string errmsgs;
|
std::string errmsgs;
|
||||||
if (mxs::server_set_status(server, status, &errmsgs))
|
if (MonitorManager::set_server_status(server, status, &errmsgs))
|
||||||
{
|
{
|
||||||
maxinfo_send_ok(dcb);
|
maxinfo_send_ok(dcb);
|
||||||
}
|
}
|
||||||
@ -412,7 +412,7 @@ void exec_clear_server(DCB* dcb, MAXINFO_TREE* tree)
|
|||||||
if (status != 0)
|
if (status != 0)
|
||||||
{
|
{
|
||||||
std::string errmsgs;
|
std::string errmsgs;
|
||||||
if (mxs::server_clear_status(server, status, &errmsgs))
|
if (MonitorManager::clear_server_status(server, status, &errmsgs))
|
||||||
{
|
{
|
||||||
maxinfo_send_ok(dcb);
|
maxinfo_send_ok(dcb);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user