From 0693514047f106639f4ec98d7a415adbf57d4045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 8 Mar 2019 10:55:00 +0200 Subject: [PATCH] MXS-2313: Add server ranks The servers now accept a rank parameter that tells which servers to prioritize. --- include/maxscale/server.hh | 8 ++++++++ server/core/config.cc | 1 + server/core/config_runtime.cc | 7 +++++++ server/core/internal/server.hh | 12 ++++++++++++ server/core/server.cc | 6 ++++++ 5 files changed, 34 insertions(+) diff --git a/include/maxscale/server.hh b/include/maxscale/server.hh index 1e35a7577..15216cc1c 100644 --- a/include/maxscale/server.hh +++ b/include/maxscale/server.hh @@ -28,6 +28,7 @@ extern const char CN_MONITORUSER[]; extern const char CN_PERSISTMAXTIME[]; extern const char CN_PERSISTPOOLMAX[]; 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 @@ -276,6 +277,13 @@ public: */ 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. * diff --git a/server/core/config.cc b/server/core/config.cc index c5c7f38d6..044710578 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -425,6 +425,7 @@ const MXS_MODULE_PARAM config_server_params[] = {CN_SSL_CERT_VERIFY_DEPTH, MXS_MODULE_PARAM_COUNT, "9"}, {CN_SSL_VERIFY_PEER_CERTIFICATE, MXS_MODULE_PARAM_BOOL, "true"}, {CN_DISK_SPACE_THRESHOLD, MXS_MODULE_PARAM_STRING}, + {CN_RANK, MXS_MODULE_PARAM_INT, "-1"}, {NULL} }; diff --git a/server/core/config_runtime.cc b/server/core/config_runtime.cc index 34e62ca28..8a0977014 100644 --- a/server/core/config_runtime.cc +++ b/server/core/config_runtime.cc @@ -619,6 +619,13 @@ bool runtime_alter_server(Server* server, const char* key, const char* value) server->set_persistmaxtime(atoi(value)); } } + if (strcmp(key, CN_RANK) == 0) + { + if (is_valid_integer(value)) + { + server->set_rank(atoi(value)); + } + } else { /** diff --git a/server/core/internal/server.hh b/server/core/internal/server.hh index 4a648fb09..205b72c39 100644 --- a/server/core/internal/server.hh +++ b/server/core/internal/server.hh @@ -62,6 +62,11 @@ public: m_settings.persistmaxtime = persistmaxtime; } + void set_rank(int rank) + { + m_settings.rank = rank; + } + bool have_disk_space_limits() const override { std::lock_guard guard(m_settings.lock); @@ -117,6 +122,11 @@ public: return m_settings.authenticator; } + int rank() const override + { + return m_settings.rank; + } + /** * 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 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 * by mutex. */ DiskSpaceLimits disk_space_limits; diff --git a/server/core/server.cc b/server/core/server.cc index 32ee88129..a2e6804e9 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -63,6 +63,7 @@ const char CN_MONITORUSER[] = "monitoruser"; const char CN_PERSISTMAXTIME[] = "persistmaxtime"; const char CN_PERSISTPOOLMAX[] = "persistpoolmax"; const char CN_PROXY_PROTOCOL[] = "proxy_protocol"; +const char CN_RANK[] = "rank"; namespace { @@ -252,6 +253,11 @@ Server* Server::server_alloc(const char* name, MXS_CONFIG_PARAMETER* params) server->last_event = SERVER_UP_EVENT; server->status = SERVER_RUNNING; + if ((server->m_settings.rank = params->get_integer(CN_RANK)) == -1) + { + server->m_settings.rank = std::numeric_limits::max(); + } + if (!monuser.empty()) { mxb_assert(!monpw.empty());