diff --git a/include/maxscale/server.h b/include/maxscale/server.h index bea68b8dc..5ae3d5fa9 100644 --- a/include/maxscale/server.h +++ b/include/maxscale/server.h @@ -173,23 +173,25 @@ enum }; /** - * Status bits in the server->status member. - * - * These are a bitmap of attributes that may be applied to a server + * Status bits in the SERVER->status member, which describes the general state of a server. Although the + * individual bits are independent, not all combinations make sense or are used. The bitfield is 64bits wide. */ -#define SERVER_RUNNING 0x0001 /**<< The server is up and running */ -#define SERVER_MASTER 0x0002 /**<< The server is a master, i.e. can handle writes */ -#define SERVER_SLAVE 0x0004 /**<< The server is a slave, i.e. can handle reads */ -#define SERVER_JOINED 0x0008 /**<< The server is joined in a Galera cluster */ -#define SERVER_NDB 0x0010 /**<< The server is part of a MySQL cluster setup */ -#define SERVER_MAINT 0x0020 /**<< Server is in maintenance mode */ -#define SERVER_SLAVE_OF_EXTERNAL_MASTER 0x0040 /**<< Server is slave of a Master outside - the provided replication topology */ -#define SERVER_STALE_STATUS 0x0080 /**<< Server stale status, monitor didn't update it */ -#define SERVER_MASTER_STICKINESS 0x0100 /**<< Server Master stickiness */ -#define SERVER_AUTH_ERROR 0x1000 /**<< Authentication error from monitor */ -#define SERVER_STALE_SLAVE 0x2000 /**<< Slave status is possible even without a master */ -#define SERVER_RELAY_MASTER 0x4000 /**<< Server is a relay master */ +// Bits used by most monitors +#define SERVER_RUNNING (1 << 0) /**<< The server is up and running */ +#define SERVER_MAINT (1 << 1) /**<< Server is in maintenance mode */ +#define SERVER_AUTH_ERROR (1 << 2) /**<< Authentication error from monitor */ +#define SERVER_MASTER (1 << 3) /**<< The server is a master, i.e. can handle writes */ +#define SERVER_SLAVE (1 << 4) /**<< The server is a slave, i.e. can handle reads */ +// Bits used by MariaDB Monitor (mostly) +#define SERVER_SLAVE_OF_EXT_MASTER (1 << 5) /**<< Server is slave of a non-monitored master */ +#define SERVER_RELAY_MASTER (1 << 6) /**<< Server is a relay master */ +#define SERVER_WAS_MASTER (1 << 7) /**<< Server was a master but lost all slaves. */ +#define SERVER_WAS_SLAVE (1 << 8) /**<< Server was a slave but lost its master. */ +// Bits used by other monitors +#define SERVER_JOINED (1 << 9) /**<< The server is joined in a Galera cluster */ +#define SERVER_NDB (1 << 10) /**<< The server is part of a MySQL cluster setup */ +#define SERVER_MASTER_STICKINESS (1 << 11) /**<< Server Master stickiness */ + /** * Is the server valid and active @@ -216,13 +218,6 @@ enum (SERVER_RUNNING|SERVER_MASTER|SERVER_MAINT)) == \ (SERVER_RUNNING|SERVER_MASTER)) -/** - * Is the server valid candidate for root master. The server must be running, - * marked as master and not have maintenance bit set. - */ -#define SERVER_IS_ROOT_MASTER(server) \ - (((server)->status & (SERVER_RUNNING|SERVER_MASTER|SERVER_MAINT)) == (SERVER_RUNNING|SERVER_MASTER)) - /** * Is the server a slave? The server must be both running and marked as a slave * in order for the macro to return true @@ -248,18 +243,15 @@ enum */ #define SERVER_IN_MAINT(server) ((server)->status & SERVER_MAINT) -/** server is not master, slave or joined */ -#define SERVER_NOT_IN_CLUSTER(s) (((s)->status & (SERVER_MASTER|SERVER_SLAVE|SERVER_JOINED|SERVER_NDB)) == 0) - #define SERVER_IS_IN_CLUSTER(s) (((s)->status & (SERVER_MASTER|SERVER_SLAVE|SERVER_JOINED|SERVER_NDB)) != 0) #define SERVER_IS_RELAY_SERVER(server) \ (((server)->status & (SERVER_RUNNING|SERVER_MASTER|SERVER_SLAVE|SERVER_MAINT)) == \ (SERVER_RUNNING|SERVER_MASTER|SERVER_SLAVE)) -#define SERVER_IS_SLAVE_OF_EXTERNAL_MASTER(s) (((s)->status & \ - (SERVER_RUNNING|SERVER_SLAVE_OF_EXTERNAL_MASTER)) == \ - (SERVER_RUNNING|SERVER_SLAVE_OF_EXTERNAL_MASTER)) +#define SERVER_IS_SLAVE_OF_EXT_MASTER(s) (((s)->status & \ + (SERVER_RUNNING|SERVER_SLAVE_OF_EXT_MASTER)) == \ + (SERVER_RUNNING|SERVER_SLAVE_OF_EXT_MASTER)) /** * @brief Allocate a new server diff --git a/server/core/server.cc b/server/core/server.cc index 275b7cf61..96124f3a2 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -688,7 +688,7 @@ server_status(const SERVER *server) { strcat(status, "NDB, "); } - if (server_status & SERVER_SLAVE_OF_EXTERNAL_MASTER) + if (server_status & SERVER_SLAVE_OF_EXT_MASTER) { strcat(status, "Slave of External Server, "); } @@ -1103,7 +1103,7 @@ static struct { "ndb", SERVER_NDB }, { "maintenance", SERVER_MAINT }, { "maint", SERVER_MAINT }, - { "stale", SERVER_STALE_STATUS }, + { "stale", SERVER_WAS_MASTER }, { NULL, 0 } }; diff --git a/server/modules/monitor/mariadbmon/cluster_discovery.cc b/server/modules/monitor/mariadbmon/cluster_discovery.cc index da040683a..992e61a3b 100644 --- a/server/modules/monitor/mariadbmon/cluster_discovery.cc +++ b/server/modules/monitor/mariadbmon/cluster_discovery.cc @@ -139,7 +139,7 @@ MXS_MONITORED_SERVER* MariaDBMonitor::get_replication_tree() if (current->master_id > 0) { monitor_set_pending_status(ptr, SERVER_SLAVE); - monitor_set_pending_status(ptr, SERVER_SLAVE_OF_EXTERNAL_MASTER); + monitor_set_pending_status(ptr, SERVER_SLAVE_OF_EXT_MASTER); } } break; @@ -397,13 +397,13 @@ void MariaDBMonitor::assign_cycle_roles(int cycle) /** We have at least one cycle in the graph */ if (server.m_read_only) { - monitor_set_pending_status(mon_srv, SERVER_SLAVE | SERVER_STALE_SLAVE); + monitor_set_pending_status(mon_srv, SERVER_SLAVE | SERVER_WAS_SLAVE); monitor_clear_pending_status(mon_srv, SERVER_MASTER); } else { monitor_set_pending_status(mon_srv, SERVER_MASTER); - monitor_clear_pending_status(mon_srv, SERVER_SLAVE | SERVER_STALE_SLAVE); + monitor_clear_pending_status(mon_srv, SERVER_SLAVE | SERVER_WAS_SLAVE); } } else if (m_detect_stale_master && cycle == 1 && mon_srv->mon_prev_status & SERVER_MASTER && @@ -422,13 +422,13 @@ void MariaDBMonitor::assign_cycle_roles(int cycle) if (server.m_read_only) { /** The master is in read-only mode, set it into Slave state */ - monitor_set_pending_status(mon_srv, SERVER_SLAVE | SERVER_STALE_SLAVE); - monitor_clear_pending_status(mon_srv, SERVER_MASTER | SERVER_STALE_STATUS); + monitor_set_pending_status(mon_srv, SERVER_SLAVE | SERVER_WAS_SLAVE); + monitor_clear_pending_status(mon_srv, SERVER_MASTER | SERVER_WAS_MASTER); } else { - monitor_set_pending_status(mon_srv, SERVER_MASTER | SERVER_STALE_STATUS); - monitor_clear_pending_status(mon_srv, SERVER_SLAVE | SERVER_STALE_SLAVE); + monitor_set_pending_status(mon_srv, SERVER_MASTER | SERVER_WAS_MASTER); + monitor_clear_pending_status(mon_srv, SERVER_SLAVE | SERVER_WAS_SLAVE); } } } @@ -711,7 +711,7 @@ bool MariaDBMonitor::set_standalone_master() m_warn_set_standalone_master = false; } - monitor_set_pending_status(mon_server, SERVER_MASTER | SERVER_STALE_STATUS); + monitor_set_pending_status(mon_server, SERVER_MASTER | SERVER_WAS_MASTER); monitor_clear_pending_status(mon_server, SERVER_SLAVE); m_master = server; rval = true; @@ -815,11 +815,11 @@ void MariaDBMonitor::update_server_states(MariaDBServer& db_server, MariaDBServe (ptr->mon_prev_status & SERVER_MASTER) && !(ptr->pending_status & SERVER_MASTER) && !db_server.m_read_only) { - db_server.set_status(SERVER_STALE_STATUS | SERVER_MASTER); + db_server.set_status(SERVER_WAS_MASTER | SERVER_MASTER); /** Log the message only if the master server didn't have * the stale master bit set */ - if ((ptr->mon_prev_status & SERVER_STALE_STATUS) == 0) + if ((ptr->mon_prev_status & SERVER_WAS_MASTER) == 0) { MXS_WARNING("All slave servers under the current master server have been lost. " "Assigning Stale Master status to the old master server '%s' (%s:%i).", @@ -838,18 +838,18 @@ void MariaDBMonitor::update_server_states(MariaDBServer& db_server, MariaDBServe /** Slave with a running master, assign stale slave candidacy */ if ((ptr->pending_status & bits) == bits) { - monitor_set_pending_status(ptr, SERVER_STALE_SLAVE); + monitor_set_pending_status(ptr, SERVER_WAS_SLAVE); } /** Server lost slave when a master is available, remove * stale slave candidacy */ else if ((ptr->pending_status & bits) == SERVER_RUNNING) { - monitor_clear_pending_status(ptr, SERVER_STALE_SLAVE); + monitor_clear_pending_status(ptr, SERVER_WAS_SLAVE); } } /** If this server was a stale slave candidate, assign * slave status to it */ - else if (ptr->mon_prev_status & SERVER_STALE_SLAVE && + else if (ptr->mon_prev_status & SERVER_WAS_SLAVE && ptr->pending_status & SERVER_RUNNING && // Master is down (!root_master || !SRV_MASTER_STATUS(root_master->pending_status) || diff --git a/server/modules/monitor/mariadbmon/cluster_manipulation.cc b/server/modules/monitor/mariadbmon/cluster_manipulation.cc index 6168979c5..c1204df3f 100644 --- a/server/modules/monitor/mariadbmon/cluster_manipulation.cc +++ b/server/modules/monitor/mariadbmon/cluster_manipulation.cc @@ -752,7 +752,7 @@ bool MariaDBMonitor::switchover_demote_master(MariaDBServer* current_master, jso MYSQL* conn = current_master->m_server_base->con; const char* query = ""; // The next query to execute. Used also for error printing. // The presence of an external master changes several things. - const bool external_master = SERVER_IS_SLAVE_OF_EXTERNAL_MASTER(current_master->m_server_base->server); + const bool external_master = SERVER_IS_SLAVE_OF_EXT_MASTER(current_master->m_server_base->server); if (external_master) { diff --git a/server/modules/monitor/mariadbmon/mariadbmon.cc b/server/modules/monitor/mariadbmon/mariadbmon.cc index dfac2e733..454ca5b58 100644 --- a/server/modules/monitor/mariadbmon/mariadbmon.cc +++ b/server/modules/monitor/mariadbmon/mariadbmon.cc @@ -390,7 +390,7 @@ void MariaDBMonitor::main() if (root_master && root_master->is_master()) { // Clear slave and stale slave status bits from current master - root_master->clear_status(SERVER_SLAVE | SERVER_STALE_SLAVE); + root_master->clear_status(SERVER_SLAVE | SERVER_WAS_SLAVE); /** * Clear external slave status from master if configured to do so. @@ -399,7 +399,7 @@ void MariaDBMonitor::main() */ if (m_ignore_external_masters) { - root_master->clear_status(SERVER_SLAVE_OF_EXTERNAL_MASTER); + root_master->clear_status(SERVER_SLAVE_OF_EXT_MASTER); } } @@ -509,7 +509,7 @@ void MariaDBMonitor::update_gtid_domain() void MariaDBMonitor::update_external_master() { - if (SERVER_IS_SLAVE_OF_EXTERNAL_MASTER(m_master->m_server_base->server)) + if (SERVER_IS_SLAVE_OF_EXT_MASTER(m_master->m_server_base->server)) { ss_dassert(!m_master->m_slave_status.empty()); if (m_master->m_slave_status[0].master_host != m_external_master_host || @@ -569,11 +569,11 @@ void MariaDBMonitor::log_master_changes(MariaDBServer* root_master_server, int* { MXS_MONITORED_SERVER* root_master = root_master_server ? root_master_server->m_server_base : NULL; if (root_master && mon_status_changed(root_master) && - !(root_master->pending_status & SERVER_STALE_STATUS)) + !(root_master->pending_status & SERVER_WAS_MASTER)) { if ((root_master->pending_status & SERVER_MASTER) && root_master_server->is_running()) { - if (!(root_master->mon_prev_status & SERVER_STALE_STATUS) && + if (!(root_master->mon_prev_status & SERVER_WAS_MASTER) && !(root_master->pending_status & SERVER_MAINT)) { MXS_NOTICE("A Master Server is now available: %s:%i", diff --git a/server/modules/monitor/mariadbmon/mariadbserver.cc b/server/modules/monitor/mariadbmon/mariadbserver.cc index 816120d10..4255e7780 100644 --- a/server/modules/monitor/mariadbmon/mariadbserver.cc +++ b/server/modules/monitor/mariadbmon/mariadbserver.cc @@ -735,7 +735,7 @@ void MariaDBServer::monitor_server(MXS_MONITOR* base_monitor) { /* The current server is not running. Clear all but the stale master bit as it is used to detect * masters that went down but came up. */ - clear_status(~SERVER_STALE_STATUS); + clear_status(~SERVER_WAS_MASTER); auto conn_errno = mysql_errno(conn); if (conn_errno == ER_ACCESS_DENIED_ERROR || conn_errno == ER_ACCESS_DENIED_NO_PASSWORD_ERROR) { @@ -797,7 +797,7 @@ void MariaDBServer::monitor_server(MXS_MONITOR* base_monitor) bool MariaDBServer::update_slave_status(string* errmsg_out) { /** Clear old states */ - clear_status(SERVER_SLAVE | SERVER_MASTER | SERVER_RELAY_MASTER | SERVER_SLAVE_OF_EXTERNAL_MASTER); + clear_status(SERVER_SLAVE | SERVER_MASTER | SERVER_RELAY_MASTER | SERVER_SLAVE_OF_EXT_MASTER); bool rval = false; if (do_show_slave_status(errmsg_out)) diff --git a/server/modules/monitor/mmmon/mmmon.cc b/server/modules/monitor/mmmon/mmmon.cc index 8b454b58e..f902fba15 100644 --- a/server/modules/monitor/mmmon/mmmon.cc +++ b/server/modules/monitor/mmmon/mmmon.cc @@ -289,7 +289,7 @@ void MMMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server) } /* Remove addition info */ - monitor_clear_pending_status(monitored_server, SERVER_STALE_STATUS); + monitor_clear_pending_status(monitored_server, SERVER_WAS_MASTER); /* Set the Slave Role */ /* Set the Master role */ @@ -349,7 +349,7 @@ void MMMonitor::tick() monitor_set_pending_status(ptr, SERVER_RUNNING); /* Set the STALE bit for this server in server struct */ - monitor_set_pending_status(ptr, SERVER_STALE_STATUS); + monitor_set_pending_status(ptr, SERVER_WAS_MASTER); } } }