MXS-2313: Add server ranks

The servers now accept a rank parameter that tells which servers to
prioritize.
This commit is contained in:
Markus Mäkelä
2019-03-08 10:55:00 +02:00
parent 9e9cd0c596
commit 0693514047
5 changed files with 34 additions and 0 deletions

View File

@ -28,6 +28,7 @@ extern const char CN_MONITORUSER[];
extern const char CN_PERSISTMAXTIME[]; extern const char CN_PERSISTMAXTIME[];
extern const char CN_PERSISTPOOLMAX[]; extern const char CN_PERSISTPOOLMAX[];
extern const char CN_PROXY_PROTOCOL[]; extern const char CN_PROXY_PROTOCOL[];
extern const char CN_RANK[];
/** /**
* Status bits in the SERVER->status member, which describes the general state of a server. Although the * Status bits in the SERVER->status member, which describes the general state of a server. Although the
@ -276,6 +277,13 @@ public:
*/ */
virtual std::string protocol() const = 0; virtual std::string protocol() const = 0;
/**
* Get server rank
*
* @return The server rank
*/
virtual int rank() const = 0;
/* /*
* Update server address. TODO: Move this to internal class once blr is gone. * Update server address. TODO: Move this to internal class once blr is gone.
* *

View File

@ -425,6 +425,7 @@ const MXS_MODULE_PARAM config_server_params[] =
{CN_SSL_CERT_VERIFY_DEPTH, MXS_MODULE_PARAM_COUNT, "9"}, {CN_SSL_CERT_VERIFY_DEPTH, MXS_MODULE_PARAM_COUNT, "9"},
{CN_SSL_VERIFY_PEER_CERTIFICATE, MXS_MODULE_PARAM_BOOL, "true"}, {CN_SSL_VERIFY_PEER_CERTIFICATE, MXS_MODULE_PARAM_BOOL, "true"},
{CN_DISK_SPACE_THRESHOLD, MXS_MODULE_PARAM_STRING}, {CN_DISK_SPACE_THRESHOLD, MXS_MODULE_PARAM_STRING},
{CN_RANK, MXS_MODULE_PARAM_INT, "-1"},
{NULL} {NULL}
}; };

View File

@ -619,6 +619,13 @@ bool runtime_alter_server(Server* server, const char* key, const char* value)
server->set_persistmaxtime(atoi(value)); server->set_persistmaxtime(atoi(value));
} }
} }
if (strcmp(key, CN_RANK) == 0)
{
if (is_valid_integer(value))
{
server->set_rank(atoi(value));
}
}
else else
{ {
/** /**

View File

@ -62,6 +62,11 @@ public:
m_settings.persistmaxtime = persistmaxtime; m_settings.persistmaxtime = persistmaxtime;
} }
void set_rank(int rank)
{
m_settings.rank = rank;
}
bool have_disk_space_limits() const override bool have_disk_space_limits() const override
{ {
std::lock_guard<std::mutex> guard(m_settings.lock); std::lock_guard<std::mutex> guard(m_settings.lock);
@ -117,6 +122,11 @@ public:
return m_settings.authenticator; return m_settings.authenticator;
} }
int rank() const override
{
return m_settings.rank;
}
/** /**
* Get a DCB from the persistent connection pool, if possible * Get a DCB from the persistent connection pool, if possible
* *
@ -331,6 +341,8 @@ private:
long persistpoolmax = 0; /**< Maximum size of persistent connections pool */ long persistpoolmax = 0; /**< Maximum size of persistent connections pool */
long persistmaxtime = 0; /**< Maximum number of seconds connection can live */ long persistmaxtime = 0; /**< Maximum number of seconds connection can live */
int rank; /*< The ranking of this server, used to prioritize certain servers over others */
/** Disk space thresholds. Can be queried from modules at any time so access must be protected /** Disk space thresholds. Can be queried from modules at any time so access must be protected
* by mutex. */ * by mutex. */
DiskSpaceLimits disk_space_limits; DiskSpaceLimits disk_space_limits;

View File

@ -63,6 +63,7 @@ const char CN_MONITORUSER[] = "monitoruser";
const char CN_PERSISTMAXTIME[] = "persistmaxtime"; const char CN_PERSISTMAXTIME[] = "persistmaxtime";
const char CN_PERSISTPOOLMAX[] = "persistpoolmax"; const char CN_PERSISTPOOLMAX[] = "persistpoolmax";
const char CN_PROXY_PROTOCOL[] = "proxy_protocol"; const char CN_PROXY_PROTOCOL[] = "proxy_protocol";
const char CN_RANK[] = "rank";
namespace namespace
{ {
@ -252,6 +253,11 @@ Server* Server::server_alloc(const char* name, MXS_CONFIG_PARAMETER* params)
server->last_event = SERVER_UP_EVENT; server->last_event = SERVER_UP_EVENT;
server->status = SERVER_RUNNING; server->status = SERVER_RUNNING;
if ((server->m_settings.rank = params->get_integer(CN_RANK)) == -1)
{
server->m_settings.rank = std::numeric_limits<int>::max();
}
if (!monuser.empty()) if (!monuser.empty())
{ {
mxb_assert(!monpw.empty()); mxb_assert(!monpw.empty());