Clean up server status printing
Uses mostly the status functions for reading the flags. Strickly speaking this breaks the REST API since in some cases (status combinations) the printed string is different from what was printed before.
This commit is contained in:
parent
f7e3d4c2fb
commit
836db54800
@ -183,7 +183,7 @@ enum
|
||||
#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_RELAY (1 << 6) /**<< Server is a relay */
|
||||
#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
|
||||
@ -286,8 +286,7 @@ inline bool server_is_master(const SERVER* server)
|
||||
|
||||
inline bool status_is_slave(uint64_t status)
|
||||
{
|
||||
return ((status & (SERVER_RUNNING | SERVER_MAINT)) == SERVER_RUNNING) &&
|
||||
((status & SERVER_SLAVE) || (status & SERVER_WAS_SLAVE));
|
||||
return (status & (SERVER_RUNNING | SERVER_SLAVE | SERVER_MAINT)) == (SERVER_RUNNING | SERVER_SLAVE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -303,8 +302,8 @@ inline bool server_is_slave(const SERVER* server)
|
||||
|
||||
inline bool status_is_relay(uint64_t status)
|
||||
{
|
||||
return (status & (SERVER_RUNNING | SERVER_MASTER | SERVER_SLAVE | SERVER_MAINT)) == \
|
||||
(SERVER_RUNNING | SERVER_MASTER | SERVER_SLAVE);
|
||||
return (status & (SERVER_RUNNING | SERVER_RELAY | SERVER_MAINT)) == \
|
||||
(SERVER_RUNNING | SERVER_RELAY);
|
||||
}
|
||||
|
||||
inline bool server_is_relay(const SERVER* server)
|
||||
@ -312,13 +311,23 @@ inline bool server_is_relay(const SERVER* server)
|
||||
return status_is_relay(server->status);
|
||||
}
|
||||
|
||||
inline bool status_is_joined(uint64_t status)
|
||||
{
|
||||
return (status & (SERVER_RUNNING | SERVER_JOINED | SERVER_MAINT)) ==
|
||||
(SERVER_RUNNING | SERVER_JOINED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the server joined Galera node? The server must be running and joined.
|
||||
*/
|
||||
inline bool server_is_joined(const SERVER* server)
|
||||
{
|
||||
return ((server->status & (SERVER_RUNNING | SERVER_JOINED | SERVER_MAINT)) ==
|
||||
(SERVER_RUNNING | SERVER_JOINED));
|
||||
return status_is_joined(server->status);
|
||||
}
|
||||
|
||||
inline bool status_is_ndb(uint64_t status)
|
||||
{
|
||||
return (status & (SERVER_RUNNING | SERVER_NDB | SERVER_MAINT)) == (SERVER_RUNNING | SERVER_NDB);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -326,12 +335,13 @@ inline bool server_is_joined(const SERVER* server)
|
||||
*/
|
||||
inline bool server_is_ndb(const SERVER* server)
|
||||
{
|
||||
return ((server->status & (SERVER_RUNNING | SERVER_NDB | SERVER_MAINT)) == (SERVER_RUNNING | SERVER_NDB));
|
||||
return status_is_ndb(server->status);
|
||||
}
|
||||
|
||||
inline bool server_is_in_cluster(const SERVER* server)
|
||||
{
|
||||
return ((server->status & (SERVER_MASTER | SERVER_SLAVE | SERVER_JOINED | SERVER_NDB)) != 0);
|
||||
return ((server->status &
|
||||
(SERVER_MASTER | SERVER_SLAVE | SERVER_RELAY | SERVER_JOINED | SERVER_NDB)) != 0);
|
||||
}
|
||||
|
||||
inline bool server_is_slave_of_ext_master(const SERVER* server)
|
||||
|
@ -695,63 +695,67 @@ dListServers(DCB *dcb)
|
||||
* @param server The server to return the status of
|
||||
* @return A string representation of the status flags
|
||||
*/
|
||||
char *
|
||||
server_status(const SERVER *server)
|
||||
char* server_status(const SERVER *server)
|
||||
{
|
||||
char *status = NULL;
|
||||
|
||||
if (NULL == server || (status = (char *)MXS_MALLOC(512)) == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ss_dassert(server);
|
||||
uint64_t server_status = server->status;
|
||||
status[0] = 0;
|
||||
if (server_status & SERVER_MAINT)
|
||||
|
||||
string result;
|
||||
string separator;
|
||||
|
||||
// Helper function.
|
||||
auto concatenate_if = [&result, &separator](bool condition, const string& desc)
|
||||
{
|
||||
strcat(status, "Maintenance, ");
|
||||
}
|
||||
if (server_status & SERVER_MASTER)
|
||||
if (condition)
|
||||
{
|
||||
result += separator + desc;
|
||||
separator = ", ";
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: The following values should be revisited at some point, but since they are printed by
|
||||
// the REST API they should not be changed suddenly. Strictly speaking, even the combinations
|
||||
// should not change, but this is more dependant on the monitors and have already changed.
|
||||
const string maintenance = "Maintenance";
|
||||
const string master = "Master";
|
||||
const string relay = "Relay Master";
|
||||
const string slave = "Slave";
|
||||
const string synced = "Synced";
|
||||
const string ndb = "NDB";
|
||||
const string slave_ext = "Slave of External Server";
|
||||
const string sticky = "Master Stickiness";
|
||||
const string auth_err = "Auth Error";
|
||||
const string running = "Running";
|
||||
const string down = "Down";
|
||||
|
||||
// Maintenance is usually set by user so is printed first.
|
||||
concatenate_if(status_is_in_maint(server_status), maintenance);
|
||||
// Master cannot be a relay or a slave.
|
||||
if (status_is_master(server_status))
|
||||
{
|
||||
strcat(status, "Master, ");
|
||||
}
|
||||
if (server_status & SERVER_RELAY_MASTER)
|
||||
{
|
||||
strcat(status, "Relay Master, ");
|
||||
}
|
||||
if (server_status & SERVER_SLAVE)
|
||||
{
|
||||
strcat(status, "Slave, ");
|
||||
}
|
||||
if (server_status & SERVER_JOINED)
|
||||
{
|
||||
strcat(status, "Synced, ");
|
||||
}
|
||||
if (server_status & SERVER_NDB)
|
||||
{
|
||||
strcat(status, "NDB, ");
|
||||
}
|
||||
if (server_status & SERVER_SLAVE_OF_EXT_MASTER)
|
||||
{
|
||||
strcat(status, "Slave of External Server, ");
|
||||
}
|
||||
if (server_status & SERVER_MASTER_STICKINESS)
|
||||
{
|
||||
strcat(status, "Master Stickiness, ");
|
||||
}
|
||||
if (server_status & SERVER_AUTH_ERROR)
|
||||
{
|
||||
strcat(status, "Auth Error, ");
|
||||
}
|
||||
if (server_status & SERVER_RUNNING)
|
||||
{
|
||||
strcat(status, "Running");
|
||||
concatenate_if(true, master);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcat(status, "Down");
|
||||
// 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);
|
||||
}
|
||||
return status;
|
||||
|
||||
// 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);
|
||||
// May be combined with other MariaDB monitor flags.
|
||||
concatenate_if(server_status & 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(server_status & SERVER_AUTH_ERROR, auth_err);
|
||||
concatenate_if(status_is_running(server_status), running);
|
||||
concatenate_if(status_is_down(server_status), down);
|
||||
|
||||
return MXS_STRDUP(result.c_str());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -640,7 +640,7 @@ void MariaDBMonitor::assign_server_roles()
|
||||
// Remove any existing [Master], [Slave] etc flags from 'pending_status', they are still available in
|
||||
// 'mon_prev_status'.
|
||||
const uint64_t remove_bits = SERVER_MASTER | SERVER_WAS_MASTER | SERVER_SLAVE | SERVER_WAS_SLAVE |
|
||||
SERVER_RELAY_MASTER | SERVER_SLAVE_OF_EXT_MASTER;
|
||||
SERVER_RELAY | SERVER_SLAVE_OF_EXT_MASTER;
|
||||
for (auto server : m_servers)
|
||||
{
|
||||
server->clear_status(remove_bits);
|
||||
@ -657,7 +657,7 @@ void MariaDBMonitor::assign_server_roles()
|
||||
if (m_master->is_running())
|
||||
{
|
||||
// Master is running, assign bits for valid replication.
|
||||
m_master->clear_status(SLAVE_BITS | SERVER_RELAY_MASTER);
|
||||
m_master->clear_status(SLAVE_BITS | SERVER_RELAY);
|
||||
m_master->set_status(MASTER_BITS);
|
||||
// Run another graph search, this time assigning slaves.
|
||||
reset_node_index_info();
|
||||
@ -813,7 +813,7 @@ void MariaDBMonitor::assign_slave_and_relay_master(MariaDBServer* start_node)
|
||||
// Finally, if the node itself is a running slave and has slaves of its own, label it as relay.
|
||||
if (parent_has_live_link && parent->has_status(SERVER_SLAVE | SERVER_RUNNING) && has_slaves)
|
||||
{
|
||||
parent->set_status(SERVER_RELAY_MASTER);
|
||||
parent->set_status(SERVER_RELAY);
|
||||
}
|
||||
// If the node is a binlog relay, remove any slave bits that may have been set.
|
||||
// Relay master bit can stay.
|
||||
|
@ -809,7 +809,7 @@ void MariaDBServer::monitor_server()
|
||||
bool MariaDBServer::update_slave_status(string* errmsg_out)
|
||||
{
|
||||
/** Clear old states */
|
||||
clear_status(SERVER_SLAVE | SERVER_MASTER | SERVER_RELAY_MASTER | SERVER_SLAVE_OF_EXT_MASTER);
|
||||
clear_status(SERVER_SLAVE | SERVER_MASTER | SERVER_RELAY | SERVER_SLAVE_OF_EXT_MASTER);
|
||||
|
||||
bool rval = false;
|
||||
if (do_show_slave_status(errmsg_out))
|
||||
|
Loading…
x
Reference in New Issue
Block a user