diff --git a/examples/roundrobinrouter.cpp b/examples/roundrobinrouter.cpp index 1a4a911b1..5d17a7114 100644 --- a/examples/roundrobinrouter.cpp +++ b/examples/roundrobinrouter.cpp @@ -193,7 +193,7 @@ RRRouterSession* RRRouter::create_session(MXS_SESSION* session) SERVER_REF* sref; for (sref = m_service->dbref; sref != NULL; sref = sref->next) { - if (SERVER_REF_IS_ACTIVE(sref) && (backends.size() < m_max_backends)) + if (server_ref_is_active(sref) && (backends.size() < m_max_backends)) { /* Connect to server */ DCB* conn = dcb_connect(sref->server, session, sref->server->protocol().c_str()); diff --git a/include/maxscale/backend.hh b/include/maxscale/backend.hh index 91819cfc9..ec0f2c5b9 100644 --- a/include/maxscale/backend.hh +++ b/include/maxscale/backend.hh @@ -236,7 +236,7 @@ public: */ inline bool is_active() const { - return SERVER_REF_IS_ACTIVE(m_backend); + return server_ref_is_active(m_backend); } /** diff --git a/include/maxscale/server.hh b/include/maxscale/server.hh index 328ea4ece..2e9caf0ca 100644 --- a/include/maxscale/server.hh +++ b/include/maxscale/server.hh @@ -212,6 +212,16 @@ public: */ void update_extra_port(int new_port); + /** + * Is the server valid and active? TODO: Rename once "is_active" is moved to internal class. + * + * @return True, if server has not been removed from the runtime configuration. + */ + bool server_is_active() const + { + return is_active; + } + protected: SERVER() { @@ -241,17 +251,6 @@ private: // Bits providing general information #define SERVER_DISK_SPACE_EXHAUSTED (1 << 31) /**<< The disk space of the server is exhausted */ -/** - * Is the server valid and active? - * - * @param server The server - * @return True, if server has not been removed from the runtime configuration. - */ -inline bool server_is_active(const SERVER* server) -{ - return server->is_active; -} - inline bool status_is_usable(uint64_t status) { return (status & (SERVER_RUNNING | SERVER_MAINT)) == SERVER_RUNNING; diff --git a/include/maxscale/service.hh b/include/maxscale/service.hh index 04921d3c5..bbd43b970 100644 --- a/include/maxscale/service.hh +++ b/include/maxscale/service.hh @@ -59,8 +59,10 @@ typedef struct server_ref_t bool active; /**< Whether this reference is valid and in use*/ } SERVER_REF; -/** Macro to check whether a SERVER_REF is active */ -#define SERVER_REF_IS_ACTIVE(ref) (ref->active && server_is_active(ref->server)) +inline bool server_ref_is_active(const SERVER_REF* ref) +{ + return ref->active && ref->server->server_is_active(); +} #define SERVICE_MAX_RETRY_INTERVAL 3600 /*< The maximum interval between service start retries */ diff --git a/server/core/server.cc b/server/core/server.cc index ed49e15a2..89bcef451 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -499,7 +499,7 @@ void Server::dprintServer(DCB* dcb, const Server* srv) void Server::print_to_dcb(DCB* dcb) const { const Server* server = this; - if (!server_is_active(server)) + if (!server->server_is_active()) { return; } @@ -870,7 +870,7 @@ std::unique_ptr serverGetList() Guard guard(this_unit.all_servers_lock); for (Server* server : this_unit.all_servers) { - if (server_is_active(server)) + if (server->server_is_active()) { string stat = mxs::server_status(server); set->add_row({server->name(), server->address, std::to_string(server->port), @@ -1274,7 +1274,7 @@ json_t* server_list_to_json(const char* host) Guard guard(this_unit.all_servers_lock); for (Server* server : this_unit.all_servers) { - if (server_is_active(server)) + if (server->server_is_active()) { json_array_append_new(data, server_to_json_data(server, host)); } diff --git a/server/core/service.cc b/server/core/service.cc index 557fdc7fb..60f6b0290 100644 --- a/server/core/service.cc +++ b/server/core/service.cc @@ -913,7 +913,7 @@ void dprintService(DCB* dcb, SERVICE* svc) dcb_printf(dcb, "\tBackend databases:\n"); while (server) { - if (SERVER_REF_IS_ACTIVE(server)) + if (server_ref_is_active(server)) { dcb_printf(dcb, "\t\t[%s]:%d Protocol: %s Name: %s\n", @@ -974,7 +974,7 @@ void dListServices(DCB* dcb) bool first = true; while (server_ref) { - if (SERVER_REF_IS_ACTIVE(server_ref)) + if (server_ref_is_active(server_ref)) { if (first) { @@ -1479,7 +1479,7 @@ bool Service::dump_config(const char* filename) const for (SERVER_REF* db = dbref; db; db = db->next) { - if (SERVER_REF_IS_ACTIVE(db)) + if (server_ref_is_active(db)) { dprintf(file, "%s%s", sep, db->server->name()); sep = ","; @@ -1617,7 +1617,7 @@ static inline bool have_active_servers(const SERVICE* service) { for (SERVER_REF* ref = service->dbref; ref; ref = ref->next) { - if (SERVER_REF_IS_ACTIVE(ref)) + if (server_ref_is_active(ref)) { return true; } @@ -1707,7 +1707,7 @@ json_t* Service::json_relationships(const char* host) const for (SERVER_REF* ref = dbref; ref; ref = ref->next) { - if (SERVER_REF_IS_ACTIVE(ref)) + if (server_ref_is_active(ref)) { mxs_json_add_relation(servers, ref->server->name(), CN_SERVERS); } @@ -1813,7 +1813,7 @@ json_t* service_relations_to_server(const SERVER* server, const char* host) for (SERVER_REF* ref = service->dbref; ref; ref = ref->next) { - if (ref->server == server && SERVER_REF_IS_ACTIVE(ref)) + if (ref->server == server && server_ref_is_active(ref)) { names.push_back(service->name); } diff --git a/server/modules/authenticator/GSSAPI/GSSAPIAuth/gssapi_auth.cc b/server/modules/authenticator/GSSAPI/GSSAPIAuth/gssapi_auth.cc index 3b961da84..44476f328 100644 --- a/server/modules/authenticator/GSSAPI/GSSAPIAuth/gssapi_auth.cc +++ b/server/modules/authenticator/GSSAPI/GSSAPIAuth/gssapi_auth.cc @@ -636,7 +636,7 @@ int gssapi_auth_load_users(Listener* listener) for (SERVER_REF* servers = listener->service()->dbref; servers; servers = servers->next) { - if (!SERVER_REF_IS_ACTIVE(servers) || !server_is_active(servers->server)) + if (!server_ref_is_active(servers) || !servers->server->server_is_active()) { continue; } diff --git a/server/modules/authenticator/MySQLAuth/dbusers.cc b/server/modules/authenticator/MySQLAuth/dbusers.cc index 1d84efe38..a3e68f8f5 100644 --- a/server/modules/authenticator/MySQLAuth/dbusers.cc +++ b/server/modules/authenticator/MySQLAuth/dbusers.cc @@ -1220,7 +1220,7 @@ static int get_users(Listener* listener, bool skip_local) for (server = service->dbref; !maxscale_is_shutting_down() && server; server = server->next) { - if (!SERVER_REF_IS_ACTIVE(server) || !server_is_active(server->server) + if (!server_ref_is_active(server) || !server->server->server_is_active() || (skip_local && server_is_mxs_service(server->server)) || !server_is_running(server->server)) { diff --git a/server/modules/routing/hintrouter/hintrouter.cc b/server/modules/routing/hintrouter/hintrouter.cc index 9adbea3cf..722a2c9ea 100644 --- a/server/modules/routing/hintrouter/hintrouter.cc +++ b/server/modules/routing/hintrouter/hintrouter.cc @@ -85,7 +85,7 @@ HintRouterSession* HintRouter::newSession(MXS_SESSION* pSession) /* Go through the server references, find master and slaves */ for (SERVER_REF* pSref = pSession->service->dbref; pSref; pSref = pSref->next) { - if (SERVER_REF_IS_ACTIVE(pSref)) + if (server_ref_is_active(pSref)) { if (server_is_master(pSref->server)) { diff --git a/server/modules/routing/readconnroute/readconnroute.cc b/server/modules/routing/readconnroute/readconnroute.cc index d7d89f49a..5072bed96 100644 --- a/server/modules/routing/readconnroute/readconnroute.cc +++ b/server/modules/routing/readconnroute/readconnroute.cc @@ -315,7 +315,7 @@ static MXS_ROUTER_SESSION* newSession(MXS_ROUTER* instance, MXS_SESSION* session */ for (SERVER_REF* ref = inst->service->dbref; ref; ref = ref->next) { - if (!SERVER_REF_IS_ACTIVE(ref) || server_is_in_maint(ref->server)) + if (!server_ref_is_active(ref) || server_is_in_maint(ref->server)) { continue; }