Define inline functions for status variables

The functions are used in MariaDB Monitor.
This commit is contained in:
Esa Korhonen 2018-07-25 13:58:09 +03:00
parent 6c59da77fb
commit 18bfca0533
3 changed files with 76 additions and 42 deletions

View File

@ -195,52 +195,106 @@ enum
#define SERVER_DISK_SPACE_EXHAUSTED (1 << 31) /**<< The disk space of the server is exhausted */
/**
* Is the server valid and active
* 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_running(uint64_t status)
{
return (status & (SERVER_RUNNING | SERVER_MAINT)) == SERVER_RUNNING;
}
/**
* Is the server running - returns true if the server is marked as running.
* Is the server running?
*
* @param server The server
* @return True, if monitor can connect to server.
*/
inline bool server_is_running(const SERVER* server)
{
return ((server->status & (SERVER_RUNNING | SERVER_MAINT)) == SERVER_RUNNING);
return status_is_running(server->status);
}
inline bool status_is_down(uint64_t status)
{
return (status & SERVER_RUNNING) == 0;
}
/**
* Is the server marked as down - returns true if the server is believed
* to be inoperable.
* Is the server down?
*
* @param server The server
* @return True, if monitor cannot connect to the server.
*/
inline bool server_is_down(const SERVER* server)
{
return ((server->status & SERVER_RUNNING) == 0);
return status_is_down(server->status);
}
inline bool srv_master_status(uint64_t status)
inline bool status_is_in_maint(uint64_t status)
{
return ((status & (SERVER_RUNNING | SERVER_MASTER | SERVER_MAINT)) == (SERVER_RUNNING | SERVER_MASTER));
return status & SERVER_MAINT;
}
/**
* Is the server a master? Returns true if server is both running and marked as master.
* Is the server in maintenance mode?
*
* @param server The server
* @return True, if server is in maintenance.
*/
inline bool server_is_in_maint(const SERVER* server)
{
return status_is_in_maint(server->status);
}
inline bool status_is_master(uint64_t status)
{
return (status & (SERVER_RUNNING | SERVER_MASTER | SERVER_MAINT)) == (SERVER_RUNNING | SERVER_MASTER);
}
/**
* Is the server a master?
*
* @param server The server
* @return True, if server is running and marked as master.
*/
inline bool server_is_master(const SERVER* server)
{
return srv_master_status(server->status);
return status_is_master(server->status);
}
inline bool status_is_slave(uint64_t status)
{
return (status & (SERVER_RUNNING | SERVER_SLAVE | SERVER_MAINT)) ==
(SERVER_RUNNING | SERVER_SLAVE);
}
/**
* Is the server a slave? The server must be both running and marked as a slave
* in order for the macro to return true
* Is the server a slave.
*
* @param server The server
* @return True if server is running and marked as slave.
*/
inline bool server_is_slave(const SERVER* server)
{
return ((server->status & (SERVER_RUNNING | SERVER_SLAVE | SERVER_MAINT)) ==
(SERVER_RUNNING | SERVER_SLAVE));
return status_is_slave(server->status);
}
inline bool status_is_relay(uint64_t status)
{
return (status & (SERVER_RUNNING | SERVER_MASTER | SERVER_SLAVE | SERVER_MAINT)) == \
(SERVER_RUNNING | SERVER_MASTER | SERVER_SLAVE);
}
inline bool server_is_relay(const SERVER* server)
{
return status_is_relay(server->status);
}
/**
@ -260,25 +314,11 @@ inline bool server_is_ndb(const SERVER* server)
return ((server->status & (SERVER_RUNNING | SERVER_NDB | SERVER_MAINT)) == (SERVER_RUNNING | SERVER_NDB));
}
/**
* Is the server in maintenance mode.
*/
inline bool server_is_in_maint(const SERVER* server)
{
return (server->status & SERVER_MAINT);
}
inline bool server_is_in_cluster(const SERVER* server)
{
return ((server->status & (SERVER_MASTER | SERVER_SLAVE | SERVER_JOINED | SERVER_NDB)) != 0);
}
inline bool server_is_relay(const SERVER* server)
{
return ((server->status & (SERVER_RUNNING | SERVER_MASTER | SERVER_SLAVE | SERVER_MAINT)) == \
(SERVER_RUNNING | SERVER_MASTER | SERVER_SLAVE));
}
inline bool server_is_slave_of_ext_master(const SERVER* server)
{
return ((server->status & (SERVER_RUNNING | SERVER_SLAVE_OF_EXT_MASTER)) ==

View File

@ -1215,7 +1215,7 @@ bool MariaDBMonitor::switchover_check_current(const MXS_MONITORED_SERVER* sugges
mon_serv != NULL && extra_master == NULL;
mon_serv = mon_serv->next)
{
if (srv_master_status(mon_serv->pending_status))
if (status_is_master(mon_serv->pending_status))
{
if (mon_serv == suggested_curr_master)
{

View File

@ -435,38 +435,32 @@ bool MariaDBServer::wait_until_gtid(const GtidList& target, int timeout, json_t*
bool MariaDBServer::is_master() const
{
// Similar to macro SERVER_IS_MASTER
return srv_master_status(m_server_base->pending_status);
return status_is_master(m_server_base->pending_status);
}
bool MariaDBServer::is_slave() const
{
// Similar to macro SERVER_IS_SLAVE
return (m_server_base->pending_status & (SERVER_RUNNING | SERVER_SLAVE | SERVER_MAINT)) ==
(SERVER_RUNNING | SERVER_SLAVE);
return status_is_slave(m_server_base->pending_status);
}
bool MariaDBServer::is_running() const
{
// Similar to macro SERVER_IS_RUNNING
return (m_server_base->pending_status & (SERVER_RUNNING | SERVER_MAINT)) == SERVER_RUNNING;
return status_is_running(m_server_base->pending_status);
}
bool MariaDBServer::is_down() const
{
// Similar to macro SERVER_IS_DOWN
return (m_server_base->pending_status & SERVER_RUNNING) == 0;
return status_is_down(m_server_base->pending_status);
}
bool MariaDBServer::is_in_maintenance() const
{
return m_server_base->pending_status & SERVER_MAINT;
return status_is_in_maint(m_server_base->pending_status);
}
bool MariaDBServer::is_relay_master() const
{
return (m_server_base->pending_status & (SERVER_RUNNING | SERVER_RELAY_MASTER | SERVER_MAINT)) ==
(SERVER_RUNNING | SERVER_RELAY_MASTER);
return status_is_relay(m_server_base->pending_status);
}
bool MariaDBServer::has_status(uint64_t bits) const