From 1e33ab69f2ae7ee4ef661ac13bb164804fcba633 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Fri, 27 Jul 2018 13:20:47 +0300 Subject: [PATCH] Rename server_is_running() to server_is_usable() The previous name was misleading. The new server_is_running() only checks for the running bit so that a server is always either running or down. --- include/maxscale/backend.hh | 2 +- include/maxscale/debug.h | 4 ++-- include/maxscale/server.h | 20 +++++++++++++++++-- server/core/monitor.cc | 2 +- .../monitor/mariadbmon/cluster_discovery.cc | 6 +++--- .../mariadbmon/cluster_manipulation.cc | 4 ++-- .../monitor/mariadbmon/mariadbserver.cc | 5 +++++ .../monitor/mariadbmon/mariadbserver.hh | 17 +++++++++++----- .../routing/readconnroute/readconnroute.cc | 4 ++-- .../schemarouter/schemarouterinstance.cc | 2 +- .../schemarouter/schemaroutersession.cc | 8 ++++---- 11 files changed, 51 insertions(+), 23 deletions(-) diff --git a/include/maxscale/backend.hh b/include/maxscale/backend.hh index 754a8c7df..bf1585ccc 100644 --- a/include/maxscale/backend.hh +++ b/include/maxscale/backend.hh @@ -147,7 +147,7 @@ public: */ inline bool can_connect() const { - return !has_failed() && server_is_running(m_backend->server); + return !has_failed() && server_is_usable(m_backend->server); } /** diff --git a/include/maxscale/debug.h b/include/maxscale/debug.h index 91c8b43e3..771ca913c 100644 --- a/include/maxscale/debug.h +++ b/include/maxscale/debug.h @@ -202,9 +202,9 @@ typedef enum skygw_chk_t (server_is_slave(s) ? "RUNNING SLAVE" : \ (server_is_joined(s) ? "RUNNING JOINED" : \ (server_is_ndb(s) ? "RUNNING NDB" : \ - ((!server_is_down(s) && server_is_in_maint(s)) ? "RUNNING MAINTENANCE" : \ + ((server_is_running(s) && server_is_in_maint(s)) ? "RUNNING MAINTENANCE" : \ (server_is_relay(s) ? "RUNNING RELAY" : \ - (server_is_running(s) ? "RUNNING (only)" : \ + (server_is_usable(s) ? "RUNNING (only)" : \ (server_is_down(s) ? "DOWN" : "UNKNOWN STATUS")))))))) #define STRTARGET(t) (t == TARGET_ALL ? "TARGET_ALL" : \ diff --git a/include/maxscale/server.h b/include/maxscale/server.h index e60ed7b2a..5f4393894 100644 --- a/include/maxscale/server.h +++ b/include/maxscale/server.h @@ -205,16 +205,32 @@ inline bool server_is_active(const SERVER* server) return server->is_active; } -inline bool status_is_running(uint64_t status) +inline bool status_is_usable(uint64_t status) { return (status & (SERVER_RUNNING | SERVER_MAINT)) == SERVER_RUNNING; } +/** + * Is the server running and not in maintenance? + * + * @param server The server + * @return True, if server can be used. + */ +inline bool server_is_usable(const SERVER* server) +{ + return status_is_usable(server->status); +} + +inline bool status_is_running(uint64_t status) +{ + return (status & SERVER_RUNNING); +} + /** * Is the server running? * * @param server The server - * @return True, if monitor can connect to server. + * @return True, if monitor can connect to the server. */ inline bool server_is_running(const SERVER* server) { diff --git a/server/core/monitor.cc b/server/core/monitor.cc index 27ee3ec7d..e426dc8f6 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -1715,7 +1715,7 @@ void mon_hangup_failed_servers(MXS_MONITOR *monitor) for (MXS_MONITORED_SERVER *ptr = monitor->monitored_servers; ptr; ptr = ptr->next) { if (mon_status_changed(ptr) && - (!(server_is_running(ptr->server)) || + (!(server_is_usable(ptr->server)) || !(server_is_in_cluster(ptr->server)))) { dcb_hangup_foreach(ptr->server); diff --git a/server/modules/monitor/mariadbmon/cluster_discovery.cc b/server/modules/monitor/mariadbmon/cluster_discovery.cc index 8ac5afbdb..d8e6fd344 100644 --- a/server/modules/monitor/mariadbmon/cluster_discovery.cc +++ b/server/modules/monitor/mariadbmon/cluster_discovery.cc @@ -539,7 +539,7 @@ MariaDBServer* MariaDBMonitor::find_topology_master_server(string* msg_out) MariaDBServer* server = *iter; if (server->m_node.parents.empty()) { - if (server->is_running() && !server->is_read_only()) + if (server->is_usable() && !server->is_read_only()) { master_candidates.push_back(server); } @@ -624,7 +624,7 @@ MariaDBServer* MariaDBMonitor::find_master_inside_cycle(ServerArray& cycle_membe { MariaDBServer* server = *iter; ss_dassert(server->m_node.cycle != NodeData::CYCLE_NONE); - if (server->is_running() && !server->is_read_only()) + if (server->is_usable() && !server->is_read_only()) { return server; } @@ -798,7 +798,7 @@ void MariaDBMonitor::assign_slave_and_relay_master(MariaDBServer* start_node) // The slave only gets the slave flags if it's running. // TODO: If slaves with broken links should be given different flags, add that here. slave->clear_status(MASTER_BITS); - if (slave->has_status(SERVER_RUNNING)) + if (slave->is_running()) { slave->set_status(SLAVE_BITS); } diff --git a/server/modules/monitor/mariadbmon/cluster_manipulation.cc b/server/modules/monitor/mariadbmon/cluster_manipulation.cc index 8c914c9c7..2876e0f01 100644 --- a/server/modules/monitor/mariadbmon/cluster_manipulation.cc +++ b/server/modules/monitor/mariadbmon/cluster_manipulation.cc @@ -392,7 +392,7 @@ bool MariaDBMonitor::get_joinable_servers(ServerArray* output) bool MariaDBMonitor::server_is_rejoin_suspect(MariaDBServer* rejoin_cand, json_t** output) { bool is_suspect = false; - if (rejoin_cand->is_running() && !rejoin_cand->is_master()) + if (rejoin_cand->is_usable() && !rejoin_cand->is_master()) { // Has no slave connection, yet is not a master. if (rejoin_cand->m_slave_status.empty()) @@ -1673,7 +1673,7 @@ void MariaDBMonitor::set_low_disk_slaves_maintenance() // Only set pure slave and standalone servers to maintenance. for (MariaDBServer* server : m_servers) { - if (server->has_status(SERVER_DISK_SPACE_EXHAUSTED) && server->is_running() && + if (server->has_status(SERVER_DISK_SPACE_EXHAUSTED) && server->is_usable() && !server->is_master() && !server->is_relay_master()) { server->set_status(SERVER_MAINT); diff --git a/server/modules/monitor/mariadbmon/mariadbserver.cc b/server/modules/monitor/mariadbmon/mariadbserver.cc index 5f9db20f0..936431477 100644 --- a/server/modules/monitor/mariadbmon/mariadbserver.cc +++ b/server/modules/monitor/mariadbmon/mariadbserver.cc @@ -443,6 +443,11 @@ bool MariaDBServer::is_slave() const return status_is_slave(m_server_base->pending_status); } +bool MariaDBServer::is_usable() const +{ + return status_is_usable(m_server_base->pending_status); +} + bool MariaDBServer::is_running() const { return status_is_running(m_server_base->pending_status); diff --git a/server/modules/monitor/mariadbmon/mariadbserver.hh b/server/modules/monitor/mariadbmon/mariadbserver.hh index 65735fa75..54fbae524 100644 --- a/server/modules/monitor/mariadbmon/mariadbserver.hh +++ b/server/modules/monitor/mariadbmon/mariadbserver.hh @@ -229,35 +229,42 @@ public: bool wait_until_gtid(const GtidList& target, int timeout, json_t** err_out); /** - * Convenience method for SERVER_IS_MASTER + * Check if server is a running master. * * @return True if server is a master */ bool is_master() const; /** - * Convenience method for SERVER_IS_SLAVE + * Check if server is a running slave. * * @return True if server is a slave */ bool is_slave() const; /** - * Convenience method for SERVER_IS_RUNNING + * Check if server is running and not in maintenance. + * + * @return True if server is usable + */ + bool is_usable() const; + + /** + * Check if server is running. * * @return True if server is running */ bool is_running() const; /** - * Convenience method for SERVER_IS_DOWN + * Check if server is down. * * @return True if server is down */ bool is_down() const; /** - * Convenience method for SERVER_IN_MAINT + * Check if server is in maintenance. */ bool is_in_maintenance() const; diff --git a/server/modules/routing/readconnroute/readconnroute.cc b/server/modules/routing/readconnroute/readconnroute.cc index edc6e3bfe..83fc03680 100644 --- a/server/modules/routing/readconnroute/readconnroute.cc +++ b/server/modules/routing/readconnroute/readconnroute.cc @@ -320,7 +320,7 @@ newSession(MXS_ROUTER *instance, MXS_SESSION *session) } /* Check server status bits against bitvalue from router_options */ - if (ref && server_is_running(ref->server) && + if (ref && server_is_usable(ref->server) && (ref->server->status & client_rses->bitmask & client_rses->bitvalue)) { if (master_host) @@ -545,7 +545,7 @@ static inline bool connection_is_valid(ROUTER_INSTANCE* inst, ROUTER_CLIENT_SES* // 'router_options=slave' in the configuration file and there was only // the sole master available at session creation time. - if (server_is_running(router_cli_ses->backend->server) && + if (server_is_usable(router_cli_ses->backend->server) && (router_cli_ses->backend->server->status & router_cli_ses->bitmask & router_cli_ses->bitvalue)) { // Note the use of '==' and not '|'. We must use the former to exclude a diff --git a/server/modules/routing/schemarouter/schemarouterinstance.cc b/server/modules/routing/schemarouter/schemarouterinstance.cc index 69cdaf8a5..819fa0f2f 100644 --- a/server/modules/routing/schemarouter/schemarouterinstance.cc +++ b/server/modules/routing/schemarouter/schemarouterinstance.cc @@ -130,7 +130,7 @@ bool connect_backend_servers(SSRBackendList& backends, MXS_SESSION* session) { SERVER_REF* b = (*it)->backend(); - if (server_is_running(b->server)) + if (server_is_usable(b->server)) { servers_found += 1; diff --git a/server/modules/routing/schemarouter/schemaroutersession.cc b/server/modules/routing/schemarouter/schemaroutersession.cc index 60812852b..d8064d397 100644 --- a/server/modules/routing/schemarouter/schemaroutersession.cc +++ b/server/modules/routing/schemarouter/schemaroutersession.cc @@ -209,7 +209,7 @@ SERVER* SchemaRouterSession::resolve_query_target(GWBUF* pPacket, /** We either don't know or don't care where this query should go */ target = get_shard_target(pPacket, type); - if (target && server_is_running(target)) + if (target && server_is_usable(target)) { route_target = TARGET_NAMED_SERVER; } @@ -236,7 +236,7 @@ SERVER* SchemaRouterSession::resolve_query_target(GWBUF* pPacket, for (SSRBackendList::iterator it = m_backends.begin(); it != m_backends.end(); it++) { SERVER *server = (*it)->backend()->server; - if (server_is_running(server)) + if (server_is_usable(server)) { route_target = TARGET_NAMED_SERVER; target = server; @@ -1405,7 +1405,7 @@ void SchemaRouterSession::query_databases() for (SSRBackendList::iterator it = m_backends.begin(); it != m_backends.end(); it++) { if ((*it)->in_use() && !(*it)->is_closed() & - server_is_running((*it)->backend()->server)) + server_is_usable((*it)->backend()->server)) { GWBUF* clone = gwbuf_clone(buffer); MXS_ABORT_IF_NULL(clone); @@ -1629,7 +1629,7 @@ bool SchemaRouterSession::get_shard_dcb(DCB** p_dcb, char* name) */ if ((*it)->in_use() && (strncasecmp(name, b->server->name, PATH_MAX) == 0) && - server_is_running(b->server)) + server_is_usable(b->server)) { *p_dcb = (*it)->dcb(); succp = true;