MXS-2220 server_alloc returns internal type

Also adds default initializers to SERVER fields.
This commit is contained in:
Esa Korhonen
2018-12-11 15:27:52 +02:00
parent 3f81a37e70
commit 6209d737e9
16 changed files with 135 additions and 154 deletions

View File

@ -484,7 +484,7 @@ void MariaDBMonitor::assign_server_roles()
for (auto server : m_servers)
{
server->clear_status(remove_bits);
server->m_replication_lag = MXS_RLAG_UNDEFINED;
server->m_replication_lag = SERVER::RLAG_UNDEFINED;
}
// Check the the master node, label it as the [Master] if
@ -636,8 +636,8 @@ void MariaDBMonitor::assign_slave_and_relay_master(MariaDBServer* start_node)
// leading to the master or a relay.
int curr_rlag = slave->m_replication_lag;
int new_rlag = sstatus->seconds_behind_master;
if (new_rlag != MXS_RLAG_UNDEFINED
&& (curr_rlag == MXS_RLAG_UNDEFINED || new_rlag < curr_rlag))
if (new_rlag != SERVER::RLAG_UNDEFINED
&& (curr_rlag == SERVER::RLAG_UNDEFINED || new_rlag < curr_rlag))
{
slave->m_replication_lag = new_rlag;
}

View File

@ -330,7 +330,7 @@ bool MariaDBServer::do_show_slave_status(string* errmsg_out)
auto rlag = result->get_uint(i_seconds_behind_master);
// If slave connection is stopped, the value given by the backend is null -> -1.
new_row.seconds_behind_master = (rlag < 0) ? MXS_RLAG_UNDEFINED :
new_row.seconds_behind_master = (rlag < 0) ? SERVER::RLAG_UNDEFINED :
(rlag > INT_MAX) ? INT_MAX : rlag;
if (all_slaves_status)

View File

@ -126,7 +126,7 @@ public:
/* Replication lag of the server. Used during calculation so that the actual SERVER struct is
* only written to once. */
int m_replication_lag = MXS_RLAG_UNDEFINED;
int m_replication_lag = SERVER::RLAG_UNDEFINED;
/* Copy of same field in monitor object. TODO: pass in struct when adding concurrent updating. */
bool m_assume_unique_hostnames = true;
/* Has anything that could affect replication topology changed this iteration?

View File

@ -74,9 +74,8 @@ json_t* SlaveStatus::to_json() const
"slave_io_running",
json_string(slave_io_to_string(slave_io_running).c_str()));
json_object_set_new(result, "slave_sql_running", json_string(slave_sql_running ? "Yes" : "No"));
json_object_set_new(result,
"seconds_behing_master",
seconds_behind_master == MXS_RLAG_UNDEFINED ? json_null() :
json_object_set_new(result, "seconds_behing_master",
seconds_behind_master == SERVER::RLAG_UNDEFINED ? json_null() :
json_integer(seconds_behind_master));
json_object_set_new(result, "master_server_id", json_integer(master_server_id));
json_object_set_new(result, "last_io_or_sql_error", json_string(last_error.c_str()));

View File

@ -170,30 +170,28 @@ public:
SLAVE_IO_NO,
};
std::string owning_server; /* Server name of the owner */
bool seen_connected = false; /* Has this slave connection been seen connected,
* meaning that the master server id
* is correct? */
std::string name; /* Slave connection name. Must be unique for
* the server.*/
int64_t master_server_id = SERVER_ID_UNKNOWN; /* The master's server_id value. Valid ids are
* 32bit unsigned. -1 is unread/error. */
std::string master_host; /* Master server host name. */
int master_port = PORT_UNKNOWN; /* Master server port. */
slave_io_running_t slave_io_running = SLAVE_IO_NO; /* Slave I/O thread running state: * "Yes",
* "Connecting" or "No" */
bool slave_sql_running = false; /* Slave SQL thread running state, true if "Yes"
* */
GtidList gtid_io_pos; /* Gtid I/O position of the slave thread. */
std::string last_error; /* Last IO or SQL error encountered. */
int seconds_behind_master = MXS_RLAG_UNDEFINED; /* How much behind the slave is. */
int64_t received_heartbeats = 0; /* How many heartbeats the connection has received
* */
std::string owning_server; /* Server name of the owner */
bool seen_connected = false; /* Has this slave connection been seen connected,
* meaning that the master server id is correct? */
std::string name; /* Slave connection name. Must be unique for
* the server.*/
int64_t master_server_id = SERVER_ID_UNKNOWN; /* The master's server_id value. Valid ids are
* 32bit unsigned. -1 is unread/error. */
std::string master_host; /* Master server host name. */
int master_port = PORT_UNKNOWN; /* Master server port. */
slave_io_running_t slave_io_running = SLAVE_IO_NO; /* Slave I/O thread running state: * "Yes",
* "Connecting" or "No" */
bool slave_sql_running = false; /* Slave SQL thread running state, true if "Yes" */
GtidList gtid_io_pos; /* Gtid I/O position of the slave thread. */
std::string last_error; /* Last IO or SQL error encountered. */
int64_t received_heartbeats = 0; /* How many heartbeats the connection has
* received */
int seconds_behind_master = SERVER::RLAG_UNDEFINED; /* How much behind the slave is. */
/* Time of the latest gtid event or heartbeat the slave connection has received, timed by the monitor. */
maxbase::Clock::time_point last_data_time = maxbase::Clock::now();
std::string to_string() const;
json_t* to_json() const;

View File

@ -50,6 +50,7 @@
#include <maxscale/utils.h>
#include <maxscale/utils.hh>
#include <maxscale/paths.h>
#include "../../../core/internal/server.hh"
/* The router entry points */
static MXS_ROUTER* createInstance(SERVICE* service, MXS_CONFIG_PARAMETER* params);
@ -810,7 +811,7 @@ static MXS_ROUTER* createInstance(SERVICE* service, MXS_CONFIG_PARAMETER* params
{"authenticator", "MySQLBackendAuth"}
}, config_server_params);
SERVER* server = server_alloc("binlog_router_master_host", p.params());
Server* server = Server::server_alloc("binlog_router_master_host", p.params());
if (server == NULL)
{

View File

@ -40,6 +40,7 @@
#include <maxscale/utils.hh>
#include "../../../../core/internal/modules.hh"
#include "../../../../core/internal/config.hh"
#include "../../../../core/internal/server.hh"
#include <maxscale/protocol/mysql.hh>
#include <ini.h>
@ -142,7 +143,7 @@ int main(int argc, char** argv)
{"authenticator", "MySQLBackendAuth"}
}, config_server_params);
SERVER* server = server_alloc("binlog_router_master_host", p.params());
Server* server = Server::server_alloc("binlog_router_master_host", p.params());
if (server == NULL)
{
printf("Failed to allocate 'server' object\n");

View File

@ -481,7 +481,7 @@ static void closeSession(MXS_ROUTER* instance, MXS_ROUTER_SESSION* router_sessio
/** Log routing failure due to closed session */
static void log_closed_session(mxs_mysql_cmd_t mysql_command, SERVER_REF* ref)
{
char msg[MAX_SERVER_ADDRESS_LEN + 200] = ""; // Extra space for message
char msg[SERVER::MAX_ADDRESS_LEN + 200] = ""; // Extra space for message
if (server_is_down(ref->server))
{

View File

@ -551,7 +551,7 @@ bool RWSplitSession::route_session_write(GWBUF* querybuf, uint8_t command, uint3
*/
static inline bool rpl_lag_is_ok(RWBackend* backend, int max_rlag)
{
return max_rlag == MXS_RLAG_UNDEFINED || backend->server()->rlag <= max_rlag;
return max_rlag == SERVER::RLAG_UNDEFINED || backend->server()->rlag <= max_rlag;
}
RWBackend* RWSplitSession::get_hinted_backend(char* name)
@ -724,7 +724,7 @@ int RWSplitSession::get_max_replication_lag()
RWBackend* RWSplitSession::handle_hinted_target(GWBUF* querybuf, route_target_t route_target)
{
char* named_server = NULL;
int rlag_max = MXS_RLAG_UNDEFINED;
int rlag_max = SERVER::RLAG_UNDEFINED;
HINT* hint = querybuf->hint;
@ -756,7 +756,7 @@ RWBackend* RWSplitSession::handle_hinted_target(GWBUF* querybuf, route_target_t
hint = hint->next;
} /*< while */
if (rlag_max == MXS_RLAG_UNDEFINED) /*< no rlag max hint, use config */
if (rlag_max == SERVER::RLAG_UNDEFINED) /*< no rlag max hint, use config */
{
rlag_max = get_max_replication_lag();
}
@ -861,7 +861,7 @@ void RWSplitSession::log_master_routing_failure(bool found,
|| old_master->dcb()->role == DCB::Role::BACKEND);
mxb_assert(!curr_master || !curr_master->in_use()
|| curr_master->dcb()->role == DCB::Role::BACKEND);
char errmsg[MAX_SERVER_ADDRESS_LEN * 2 + 100]; // Extra space for error message
char errmsg[SERVER::MAX_ADDRESS_LEN * 2 + 100]; // Extra space for error message
if (m_config.delayed_retry && m_retry_duration >= m_config.delayed_retry_timeout)
{
@ -959,7 +959,7 @@ bool RWSplitSession::should_migrate_trx(RWBackend* target)
*/
bool RWSplitSession::handle_master_is_target(RWBackend** dest)
{
RWBackend* target = get_target_backend(BE_MASTER, NULL, MXS_RLAG_UNDEFINED);
RWBackend* target = get_target_backend(BE_MASTER, NULL, SERVER::RLAG_UNDEFINED);
bool succp = true;
if (should_replace_master(target))