diff --git a/include/maxscale/server.hh b/include/maxscale/server.hh index 3f20304ff..44ca296f0 100644 --- a/include/maxscale/server.hh +++ b/include/maxscale/server.hh @@ -482,6 +482,7 @@ double server_response_time_average(const SERVER* server); namespace maxscale { +std::string server_status(uint64_t flags); std::string server_status(const SERVER*); bool server_set_status(SERVER* server, int bit, std::string* errmsg_out = NULL); bool server_clear_status(SERVER* server, int bit, std::string* errmsg_out = NULL); diff --git a/server/core/monitor.cc b/server/core/monitor.cc index efbe9860f..07396af5c 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -1542,17 +1542,12 @@ void mon_log_connect_error(MXS_MONITORED_SERVER* database, mxs_connect_result_t static void mon_log_state_change(MXS_MONITORED_SERVER* ptr) { - SERVER srv; - srv.status = ptr->mon_prev_status; - string prev = mxs::server_status(&srv); + string prev = mxs::server_status(ptr->mon_prev_status); string next = mxs::server_status(ptr->server); MXS_NOTICE("Server changed state: %s[%s:%u]: %s. [%s] -> [%s]", - ptr->server->name, - ptr->server->address, - ptr->server->port, + ptr->server->name, ptr->server->address, ptr->server->port, mon_get_event_name(ptr), - prev.c_str(), - next.c_str()); + prev.c_str(), next.c_str()); } MXS_MONITOR* monitor_server_in_use(const SERVER* server) @@ -2858,12 +2853,9 @@ void MonitorInstanceSimple::tick() if (mon_status_changed(pMs) || mon_print_fail_status(pMs)) { // The current status is still in pMs->pending_status. - SERVER server = {}; - server.status = pMs->pending_status; MXS_DEBUG("Backend server [%s]:%d state : %s", - pMs->server->address, - pMs->server->port, - mxs::server_status(&server).c_str()); + pMs->server->address, pMs->server->port, + mxs::server_status(pMs->pending_status).c_str()); } #endif diff --git a/server/core/server.cc b/server/core/server.cc index f331ba5a7..f9084bfc7 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -654,16 +654,13 @@ void dListServers(DCB* dcb) } /** - * Convert a set of server status flags to a string. + * Convert a set of server status flags to a string. * - * @param server The server to return the status of + * @param flags Status flags * @return A string representation of the status flags */ -string mxs::server_status(const SERVER* server) +string mxs::server_status(uint64_t flags) { - mxb_assert(server); - uint64_t server_status = server->status; - string result; string separator; @@ -693,35 +690,46 @@ string mxs::server_status(const SERVER* server) const string down = "Down"; // Maintenance is usually set by user so is printed first. - concatenate_if(status_is_in_maint(server_status), maintenance); + concatenate_if(status_is_in_maint(flags), maintenance); // Master cannot be a relay or a slave. - if (status_is_master(server_status)) + if (status_is_master(flags)) { concatenate_if(true, master); } else { // Relays are typically slaves as well. The binlog server may be an exception. - concatenate_if(status_is_relay(server_status), relay); - concatenate_if(status_is_slave(server_status), slave); + concatenate_if(status_is_relay(flags), relay); + concatenate_if(status_is_slave(flags), slave); } // The following Galera and Cluster bits may be combined with master/slave. - concatenate_if(status_is_joined(server_status), synced); - concatenate_if(status_is_ndb(server_status), ndb); + concatenate_if(status_is_joined(flags), synced); + concatenate_if(status_is_ndb(flags), ndb); // May be combined with other MariaDB monitor flags. - concatenate_if(server_status & SERVER_SLAVE_OF_EXT_MASTER, slave_ext); + concatenate_if(flags & SERVER_SLAVE_OF_EXT_MASTER, slave_ext); // Should this be printed only if server is master? - concatenate_if(server_status & SERVER_MASTER_STICKINESS, sticky); + concatenate_if(flags & SERVER_MASTER_STICKINESS, sticky); - concatenate_if(server_status & SERVER_AUTH_ERROR, auth_err); - concatenate_if(status_is_running(server_status), running); - concatenate_if(status_is_down(server_status), down); + concatenate_if(flags & SERVER_AUTH_ERROR, auth_err); + concatenate_if(status_is_running(flags), running); + concatenate_if(status_is_down(flags), down); return result; } +/** + * Convert the current server status flags to a string. + * + * @param server The server to return the status for + * @return A string representation of the status + */ +string mxs::server_status(const SERVER* server) +{ + mxb_assert(server); + return mxs::server_status(server->status); +} /** * Set a status bit in the server without locking *