Merge branch '2.2' into 2.2-mrm

This commit is contained in:
Johan Wikman
2017-10-02 15:49:08 +03:00
16 changed files with 220 additions and 195 deletions

View File

@ -161,7 +161,7 @@ typedef enum
/** /**
* The linked list of servers that are being monitored by the monitor module. * The linked list of servers that are being monitored by the monitor module.
*/ */
typedef struct monitor_servers typedef struct monitored_server
{ {
SERVER *server; /**< The server being monitored */ SERVER *server; /**< The server being monitored */
MYSQL *con; /**< The MySQL connection */ MYSQL *con; /**< The MySQL connection */
@ -170,8 +170,8 @@ typedef struct monitor_servers
unsigned int mon_prev_status; unsigned int mon_prev_status;
unsigned int pending_status; /**< Pending Status flag bitmap */ unsigned int pending_status; /**< Pending Status flag bitmap */
bool new_event; /**< Whether an action was taken on the last event */ bool new_event; /**< Whether an action was taken on the last event */
struct monitor_servers *next; /**< The next server in the list */ struct monitored_server *next; /**< The next server in the list */
} MXS_MONITOR_SERVERS; } MXS_MONITORED_SERVER;
/** /**
* Representation of the running monitor. * Representation of the running monitor.
@ -183,7 +183,7 @@ struct mxs_monitor
char password[MAX_MONITOR_PASSWORD_LEN]; /*< Monitor password */ char password[MAX_MONITOR_PASSWORD_LEN]; /*< Monitor password */
SPINLOCK lock; SPINLOCK lock;
MXS_CONFIG_PARAMETER* parameters; /*< configuration parameters */ MXS_CONFIG_PARAMETER* parameters; /*< configuration parameters */
MXS_MONITOR_SERVERS* databases; /*< List of databases the monitor monitors */ MXS_MONITORED_SERVER* monitored_servers; /*< List of servers the monitor monitors */
monitor_state_t state; /**< The state of the monitor */ monitor_state_t state; /**< The state of the monitor */
int connect_timeout; /**< Connect timeout in seconds for mysql_real_connect */ int connect_timeout; /**< Connect timeout in seconds for mysql_real_connect */
int connect_attempts; /**< How many times a connection is attempted */ int connect_attempts; /**< How many times a connection is attempted */
@ -258,16 +258,16 @@ extern const char CN_EVENTS[];
bool check_monitor_permissions(MXS_MONITOR* monitor, const char* query); bool check_monitor_permissions(MXS_MONITOR* monitor, const char* query);
void monitor_clear_pending_status(MXS_MONITOR_SERVERS *ptr, int bit); void monitor_clear_pending_status(MXS_MONITORED_SERVER *ptr, int bit);
void monitor_set_pending_status(MXS_MONITOR_SERVERS *ptr, int bit); void monitor_set_pending_status(MXS_MONITORED_SERVER *ptr, int bit);
void servers_status_pending_to_current(MXS_MONITOR *monitor); void servers_status_pending_to_current(MXS_MONITOR *monitor);
void servers_status_current_to_pending(MXS_MONITOR *monitor); void servers_status_current_to_pending(MXS_MONITOR *monitor);
bool mon_status_changed(MXS_MONITOR_SERVERS* mon_srv); bool mon_status_changed(MXS_MONITORED_SERVER* mon_srv);
bool mon_print_fail_status(MXS_MONITOR_SERVERS* mon_srv); bool mon_print_fail_status(MXS_MONITORED_SERVER* mon_srv);
mxs_connect_result_t mon_ping_or_connect_to_db(MXS_MONITOR* mon, MXS_MONITOR_SERVERS *database); mxs_connect_result_t mon_ping_or_connect_to_db(MXS_MONITOR* mon, MXS_MONITORED_SERVER *database);
void mon_log_connect_error(MXS_MONITOR_SERVERS* database, mxs_connect_result_t rval); void mon_log_connect_error(MXS_MONITORED_SERVER* database, mxs_connect_result_t rval);
const char* mon_get_event_name(mxs_monitor_event_t event); const char* mon_get_event_name(mxs_monitor_event_t event);
void lock_monitor_servers(MXS_MONITOR *monitor); void lock_monitor_servers(MXS_MONITOR *monitor);
@ -318,7 +318,7 @@ void mon_hangup_failed_servers(MXS_MONITOR *monitor);
* *
* @param db Database where the query failed * @param db Database where the query failed
*/ */
void mon_report_query_error(MXS_MONITOR_SERVERS* db); void mon_report_query_error(MXS_MONITORED_SERVER* db);
/** /**
* @brief Convert monitor to JSON * @brief Convert monitor to JSON
@ -355,7 +355,7 @@ json_t* monitor_relations_to_server(const SERVER* server, const char* host);
* @param monitor Monitor to journal * @param monitor Monitor to journal
* @param master The current master server or NULL if no master exists * @param master The current master server or NULL if no master exists
*/ */
void store_server_journal(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS *master); void store_server_journal(MXS_MONITOR *monitor, MXS_MONITORED_SERVER *master);
/** /**
* @brief Load a journal of server states * @brief Load a journal of server states
@ -363,6 +363,6 @@ void store_server_journal(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS *master);
* @param monitor Monitor where journal is loaded * @param monitor Monitor where journal is loaded
* @param master Set to point to the current master * @param master Set to point to the current master
*/ */
void load_server_journal(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS **master); void load_server_journal(MXS_MONITOR *monitor, MXS_MONITORED_SERVER **master);
MXS_END_DECLS MXS_END_DECLS

View File

@ -213,6 +213,20 @@ bool Connection::requestData(const std::string& table, const std::string& gtid)
m_error = "Failed to write request: "; m_error = "Failed to write request: ";
m_error += strerror_r(errno, err, sizeof (err)); m_error += strerror_r(errno, err, sizeof (err));
} }
else
{
// Read the first row to know if data request was successful
Row row = read();
if (row)
{
m_first_row = row;
}
else
{
rval = false;
}
}
return rval; return rval;
} }
@ -288,7 +302,11 @@ Row Connection::read()
Row rval; Row rval;
std::string row; std::string row;
if (readRow(row)) if (m_first_row)
{
rval.swap(m_first_row);
}
else if (readRow(row))
{ {
json_error_t err; json_error_t err;
json_t* js = json_loads(row.c_str(), JSON_ALLOW_NUL, &err); json_t* js = json_loads(row.c_str(), JSON_ALLOW_NUL, &err);

View File

@ -52,6 +52,7 @@ private:
std::string m_schema; std::string m_schema;
ValueList m_keys; ValueList m_keys;
ValueList m_types; ValueList m_types;
Row m_first_row;
bool doAuth(); bool doAuth();
bool doRegistration(); bool doRegistration();

View File

@ -985,9 +985,9 @@ bool runtime_destroy_monitor(MXS_MONITOR *monitor)
{ {
monitorStop(monitor); monitorStop(monitor);
while (monitor->databases) while (monitor->monitored_servers)
{ {
monitorRemoveServer(monitor, monitor->databases->server); monitorRemoveServer(monitor, monitor->monitored_servers->server);
} }
monitorDestroy(monitor); monitorDestroy(monitor);
MXS_NOTICE("Destroyed monitor '%s'", monitor->name); MXS_NOTICE("Destroyed monitor '%s'", monitor->name);

View File

@ -2082,6 +2082,9 @@ int main(int argc, char **argv)
/** Stop administrative interface */ /** Stop administrative interface */
mxs_admin_shutdown(); mxs_admin_shutdown();
/*< Stop all the monitors */
monitorStopAll();
/*< /*<
* Wait for the housekeeper to finish. * Wait for the housekeeper to finish.
*/ */
@ -2111,9 +2114,6 @@ int main(int argc, char **argv)
*/ */
thread_wait(log_flush_thr); thread_wait(log_flush_thr);
/*< Stop all the monitors */
monitorStopAll();
/*< Call finish on all modules. */ /*< Call finish on all modules. */
modules_process_finish(); modules_process_finish();

View File

@ -77,7 +77,7 @@ const char CN_EVENTS[] = "events";
static MXS_MONITOR *allMonitors = NULL; static MXS_MONITOR *allMonitors = NULL;
static SPINLOCK monLock = SPINLOCK_INIT; static SPINLOCK monLock = SPINLOCK_INIT;
static void monitor_server_free_all(MXS_MONITOR_SERVERS *servers); static void monitor_server_free_all(MXS_MONITORED_SERVER *servers);
static void remove_server_journal(MXS_MONITOR *monitor); static void remove_server_journal(MXS_MONITOR *monitor);
static bool journal_is_stale(MXS_MONITOR *monitor, time_t max_age); static bool journal_is_stale(MXS_MONITOR *monitor, time_t max_age);
@ -124,7 +124,7 @@ MXS_MONITOR* monitor_alloc(const char *name, const char *module)
mon->name = my_name; mon->name = my_name;
mon->module_name = my_module; mon->module_name = my_module;
mon->handle = NULL; mon->handle = NULL;
mon->databases = NULL; mon->monitored_servers = NULL;
*mon->password = '\0'; *mon->password = '\0';
*mon->user = '\0'; *mon->user = '\0';
mon->read_timeout = DEFAULT_READ_TIMEOUT; mon->read_timeout = DEFAULT_READ_TIMEOUT;
@ -177,7 +177,7 @@ monitor_free(MXS_MONITOR *mon)
} }
spinlock_release(&monLock); spinlock_release(&monLock);
config_parameter_free(mon->parameters); config_parameter_free(mon->parameters);
monitor_server_free_all(mon->databases); monitor_server_free_all(mon->monitored_servers);
MXS_FREE(mon->name); MXS_FREE(mon->name);
MXS_FREE(mon->module_name); MXS_FREE(mon->module_name);
MXS_FREE(mon); MXS_FREE(mon);
@ -254,7 +254,7 @@ monitorStop(MXS_MONITOR *monitor)
monitor->module->stopMonitor(monitor); monitor->module->stopMonitor(monitor);
monitor->state = MONITOR_STATE_STOPPED; monitor->state = MONITOR_STATE_STOPPED;
MXS_MONITOR_SERVERS* db = monitor->databases; MXS_MONITORED_SERVER* db = monitor->monitored_servers;
while (db) while (db)
{ {
// TODO: Create a generic entry point for this or move it inside stopMonitor // TODO: Create a generic entry point for this or move it inside stopMonitor
@ -314,7 +314,7 @@ bool monitorAddServer(MXS_MONITOR *mon, SERVER *server)
else else
{ {
rval = true; rval = true;
MXS_MONITOR_SERVERS *db = (MXS_MONITOR_SERVERS *)MXS_MALLOC(sizeof(MXS_MONITOR_SERVERS)); MXS_MONITORED_SERVER *db = (MXS_MONITORED_SERVER *)MXS_MALLOC(sizeof(MXS_MONITORED_SERVER));
MXS_ABORT_IF_NULL(db); MXS_ABORT_IF_NULL(db);
db->server = server; db->server = server;
@ -338,13 +338,13 @@ bool monitorAddServer(MXS_MONITOR *mon, SERVER *server)
spinlock_acquire(&mon->lock); spinlock_acquire(&mon->lock);
if (mon->databases == NULL) if (mon->monitored_servers == NULL)
{ {
mon->databases = db; mon->monitored_servers = db;
} }
else else
{ {
MXS_MONITOR_SERVERS *ptr = mon->databases; MXS_MONITORED_SERVER *ptr = mon->monitored_servers;
while (ptr->next != NULL) while (ptr->next != NULL)
{ {
ptr = ptr->next; ptr = ptr->next;
@ -362,7 +362,7 @@ bool monitorAddServer(MXS_MONITOR *mon, SERVER *server)
return rval; return rval;
} }
static void monitor_server_free(MXS_MONITOR_SERVERS *tofree) static void monitor_server_free(MXS_MONITORED_SERVER *tofree)
{ {
if (tofree) if (tofree)
{ {
@ -378,11 +378,11 @@ static void monitor_server_free(MXS_MONITOR_SERVERS *tofree)
* Free monitor server list * Free monitor server list
* @param servers Servers to free * @param servers Servers to free
*/ */
static void monitor_server_free_all(MXS_MONITOR_SERVERS *servers) static void monitor_server_free_all(MXS_MONITORED_SERVER *servers)
{ {
while (servers) while (servers)
{ {
MXS_MONITOR_SERVERS *tofree = servers; MXS_MONITORED_SERVER *tofree = servers;
servers = servers->next; servers = servers->next;
monitor_server_free(tofree); monitor_server_free(tofree);
} }
@ -405,15 +405,15 @@ void monitorRemoveServer(MXS_MONITOR *mon, SERVER *server)
spinlock_acquire(&mon->lock); spinlock_acquire(&mon->lock);
MXS_MONITOR_SERVERS *ptr = mon->databases; MXS_MONITORED_SERVER *ptr = mon->monitored_servers;
if (ptr && ptr->server == server) if (ptr && ptr->server == server)
{ {
mon->databases = mon->databases->next; mon->monitored_servers = mon->monitored_servers->next;
} }
else else
{ {
MXS_MONITOR_SERVERS *prev = ptr; MXS_MONITORED_SERVER *prev = ptr;
while (ptr) while (ptr)
{ {
@ -525,7 +525,7 @@ monitorShow(DCB *dcb, MXS_MONITOR *monitor)
const char *sep = ""; const char *sep = "";
for (MXS_MONITOR_SERVERS *db = monitor->databases; db; db = db->next) for (MXS_MONITORED_SERVER *db = monitor->monitored_servers; db; db = db->next)
{ {
dcb_printf(dcb, "%s[%s]:%d", sep, db->server->name, db->server->port); dcb_printf(dcb, "%s[%s]:%d", sep, db->server->name, db->server->port);
sep = ", "; sep = ", ";
@ -779,7 +779,7 @@ monitorGetList()
*/ */
bool check_monitor_permissions(MXS_MONITOR* monitor, const char* query) bool check_monitor_permissions(MXS_MONITOR* monitor, const char* query)
{ {
if (monitor->databases == NULL || // No servers to check if (monitor->monitored_servers == NULL || // No servers to check
config_get_global_options()->skip_permission_checks) config_get_global_options()->skip_permission_checks)
{ {
return true; return true;
@ -790,7 +790,7 @@ bool check_monitor_permissions(MXS_MONITOR* monitor, const char* query)
MXS_CONFIG* cnf = config_get_global_options(); MXS_CONFIG* cnf = config_get_global_options();
bool rval = false; bool rval = false;
for (MXS_MONITOR_SERVERS *mondb = monitor->databases; mondb; mondb = mondb->next) for (MXS_MONITORED_SERVER *mondb = monitor->monitored_servers; mondb; mondb = mondb->next)
{ {
if (mon_ping_or_connect_to_db(monitor, mondb) != MONITOR_CONN_OK) if (mon_ping_or_connect_to_db(monitor, mondb) != MONITOR_CONN_OK)
{ {
@ -909,7 +909,7 @@ bool monitorRemoveParameter(MXS_MONITOR *monitor, const char *key)
* @param bit The bit to clear for the server * @param bit The bit to clear for the server
*/ */
void void
monitor_set_pending_status(MXS_MONITOR_SERVERS *ptr, int bit) monitor_set_pending_status(MXS_MONITORED_SERVER *ptr, int bit)
{ {
ptr->pending_status |= bit; ptr->pending_status |= bit;
} }
@ -921,7 +921,7 @@ monitor_set_pending_status(MXS_MONITOR_SERVERS *ptr, int bit)
* @param bit The bit to clear for the server * @param bit The bit to clear for the server
*/ */
void void
monitor_clear_pending_status(MXS_MONITOR_SERVERS *ptr, int bit) monitor_clear_pending_status(MXS_MONITORED_SERVER *ptr, int bit)
{ {
ptr->pending_status &= ~bit; ptr->pending_status &= ~bit;
} }
@ -935,7 +935,7 @@ monitor_clear_pending_status(MXS_MONITOR_SERVERS *ptr, int bit)
* *
* @note This function must only be called from mon_process_state_changes * @note This function must only be called from mon_process_state_changes
*/ */
static mxs_monitor_event_t mon_get_event_type(MXS_MONITOR_SERVERS* node) static mxs_monitor_event_t mon_get_event_type(MXS_MONITORED_SERVER* node)
{ {
typedef enum typedef enum
{ {
@ -1065,7 +1065,7 @@ const char* mon_get_event_name(mxs_monitor_event_t event)
* @param node The monitor server data whose event is wanted * @param node The monitor server data whose event is wanted
* @result string The name of the monitor event for the server * @result string The name of the monitor event for the server
*/ */
static const char* mon_get_event_name(MXS_MONITOR_SERVERS* node) static const char* mon_get_event_name(MXS_MONITORED_SERVER* node)
{ {
return mon_get_event_name((mxs_monitor_event_t)node->server->last_event); return mon_get_event_name((mxs_monitor_event_t)node->server->last_event);
} }
@ -1090,7 +1090,7 @@ static void mon_append_node_names(MXS_MONITOR* mon,
int status, int status,
credentials_approach_t approach = CREDENTIALS_EXCLUDE) credentials_approach_t approach = CREDENTIALS_EXCLUDE)
{ {
MXS_MONITOR_SERVERS* servers = mon->databases; MXS_MONITORED_SERVER* servers = mon->monitored_servers;
const char *separator = ""; const char *separator = "";
char arr[MAX_SERVER_MONUSER_LEN + char arr[MAX_SERVER_MONUSER_LEN +
@ -1149,7 +1149,7 @@ static void mon_append_node_names(MXS_MONITOR* mon,
* @param mon_srv The monitored server * @param mon_srv The monitored server
* @return true if status has changed or false * @return true if status has changed or false
*/ */
bool mon_status_changed(MXS_MONITOR_SERVERS* mon_srv) bool mon_status_changed(MXS_MONITORED_SERVER* mon_srv)
{ {
bool rval = false; bool rval = false;
@ -1183,19 +1183,19 @@ bool mon_status_changed(MXS_MONITOR_SERVERS* mon_srv)
* @return true if failed status can be logged or false * @return true if failed status can be logged or false
*/ */
bool bool
mon_print_fail_status(MXS_MONITOR_SERVERS* mon_srv) mon_print_fail_status(MXS_MONITORED_SERVER* mon_srv)
{ {
return (SERVER_IS_DOWN(mon_srv->server) && mon_srv->mon_err_count == 0); return (SERVER_IS_DOWN(mon_srv->server) && mon_srv->mon_err_count == 0);
} }
static MXS_MONITOR_SERVERS* find_parent_node(MXS_MONITOR_SERVERS* servers, static MXS_MONITORED_SERVER* find_parent_node(MXS_MONITORED_SERVER* servers,
MXS_MONITOR_SERVERS* target) MXS_MONITORED_SERVER* target)
{ {
MXS_MONITOR_SERVERS* rval = NULL; MXS_MONITORED_SERVER* rval = NULL;
if (target->server->master_id > 0) if (target->server->master_id > 0)
{ {
for (MXS_MONITOR_SERVERS* node = servers; node; node = node->next) for (MXS_MONITORED_SERVER* node = servers; node; node = node->next)
{ {
if (node->server->node_id == target->server->master_id) if (node->server->node_id == target->server->master_id)
{ {
@ -1208,8 +1208,8 @@ static MXS_MONITOR_SERVERS* find_parent_node(MXS_MONITOR_SERVERS* servers,
return rval; return rval;
} }
static std::string child_nodes(MXS_MONITOR_SERVERS* servers, static std::string child_nodes(MXS_MONITORED_SERVER* servers,
MXS_MONITOR_SERVERS* parent) MXS_MONITORED_SERVER* parent)
{ {
std::stringstream ss; std::stringstream ss;
@ -1217,7 +1217,7 @@ static std::string child_nodes(MXS_MONITOR_SERVERS* servers,
{ {
bool have_content = false; bool have_content = false;
for (MXS_MONITOR_SERVERS* node = servers; node; node = node->next) for (MXS_MONITORED_SERVER* node = servers; node; node = node->next)
{ {
if (node->server->master_id == parent->server->node_id) if (node->server->master_id == parent->server->node_id)
{ {
@ -1245,7 +1245,7 @@ static std::string child_nodes(MXS_MONITOR_SERVERS* servers,
* *
* @return Return value of the executed script or -1 on error * @return Return value of the executed script or -1 on error
*/ */
int monitor_launch_script(MXS_MONITOR* mon, MXS_MONITOR_SERVERS* ptr, const char* script, uint32_t timeout) int monitor_launch_script(MXS_MONITOR* mon, MXS_MONITORED_SERVER* ptr, const char* script, uint32_t timeout)
{ {
char arg[strlen(script) + 1]; char arg[strlen(script) + 1];
strcpy(arg, script); strcpy(arg, script);
@ -1269,7 +1269,7 @@ int monitor_launch_script(MXS_MONITOR* mon, MXS_MONITOR_SERVERS* ptr, const char
if (externcmd_matches(cmd, "$PARENT")) if (externcmd_matches(cmd, "$PARENT"))
{ {
std::stringstream ss; std::stringstream ss;
MXS_MONITOR_SERVERS* parent = find_parent_node(mon->databases, ptr); MXS_MONITORED_SERVER* parent = find_parent_node(mon->monitored_servers, ptr);
if (parent) if (parent)
{ {
@ -1280,7 +1280,7 @@ int monitor_launch_script(MXS_MONITOR* mon, MXS_MONITOR_SERVERS* ptr, const char
if (externcmd_matches(cmd, "$CHILDREN")) if (externcmd_matches(cmd, "$CHILDREN"))
{ {
externcmd_substitute_arg(cmd, "[$]CHILDREN", child_nodes(mon->databases, ptr).c_str()); externcmd_substitute_arg(cmd, "[$]CHILDREN", child_nodes(mon->monitored_servers, ptr).c_str());
} }
if (externcmd_matches(cmd, "$EVENT")) if (externcmd_matches(cmd, "$EVENT"))
@ -1407,7 +1407,7 @@ int monitor_launch_script(MXS_MONITOR* mon, MXS_MONITOR_SERVERS* ptr, const char
* @return MONITOR_CONN_OK if the connection is OK, else the reason for the failure * @return MONITOR_CONN_OK if the connection is OK, else the reason for the failure
*/ */
mxs_connect_result_t mxs_connect_result_t
mon_ping_or_connect_to_db(MXS_MONITOR* mon, MXS_MONITOR_SERVERS *database) mon_ping_or_connect_to_db(MXS_MONITOR* mon, MXS_MONITORED_SERVER *database)
{ {
/** Return if the connection is OK */ /** Return if the connection is OK */
if (database->con && mysql_ping(database->con) == 0) if (database->con && mysql_ping(database->con) == 0)
@ -1472,7 +1472,7 @@ mon_ping_or_connect_to_db(MXS_MONITOR* mon, MXS_MONITOR_SERVERS *database)
* @param rval Return value of mon_connect_to_db * @param rval Return value of mon_connect_to_db
*/ */
void void
mon_log_connect_error(MXS_MONITOR_SERVERS* database, mxs_connect_result_t rval) mon_log_connect_error(MXS_MONITORED_SERVER* database, mxs_connect_result_t rval)
{ {
MXS_ERROR(rval == MONITOR_CONN_TIMEOUT ? MXS_ERROR(rval == MONITOR_CONN_TIMEOUT ?
"Monitor timed out when connecting to server [%s]:%d : \"%s\"" : "Monitor timed out when connecting to server [%s]:%d : \"%s\"" :
@ -1481,7 +1481,7 @@ mon_log_connect_error(MXS_MONITOR_SERVERS* database, mxs_connect_result_t rval)
mysql_error(database->con)); mysql_error(database->con));
} }
static void mon_log_state_change(MXS_MONITOR_SERVERS *ptr) static void mon_log_state_change(MXS_MONITORED_SERVER *ptr)
{ {
SERVER srv; SERVER srv;
srv.status = ptr->mon_prev_status; srv.status = ptr->mon_prev_status;
@ -1506,7 +1506,7 @@ MXS_MONITOR* monitor_server_in_use(const SERVER *server)
if (mon->active) if (mon->active)
{ {
for (MXS_MONITOR_SERVERS *db = mon->databases; db && !rval; db = db->next) for (MXS_MONITORED_SERVER *db = mon->monitored_servers; db && !rval; db = db->next)
{ {
if (db->server == server) if (db->server == server)
{ {
@ -1547,12 +1547,12 @@ static bool create_monitor_config(const MXS_MONITOR *monitor, const char *filena
dprintf(file, "%s=%ld\n", CN_JOURNAL_MAX_AGE, monitor->journal_max_age); dprintf(file, "%s=%ld\n", CN_JOURNAL_MAX_AGE, monitor->journal_max_age);
dprintf(file, "%s=%d\n", CN_SCRIPT_TIMEOUT, monitor->script_timeout); dprintf(file, "%s=%d\n", CN_SCRIPT_TIMEOUT, monitor->script_timeout);
if (monitor->databases) if (monitor->monitored_servers)
{ {
dprintf(file, "%s=", CN_SERVERS); dprintf(file, "%s=", CN_SERVERS);
for (MXS_MONITOR_SERVERS *db = monitor->databases; db; db = db->next) for (MXS_MONITORED_SERVER *db = monitor->monitored_servers; db; db = db->next)
{ {
if (db != monitor->databases) if (db != monitor->monitored_servers)
{ {
dprintf(file, ","); dprintf(file, ",");
} }
@ -1630,7 +1630,7 @@ bool monitor_serialize(const MXS_MONITOR *monitor)
void mon_hangup_failed_servers(MXS_MONITOR *monitor) void mon_hangup_failed_servers(MXS_MONITOR *monitor)
{ {
for (MXS_MONITOR_SERVERS *ptr = monitor->databases; ptr; ptr = ptr->next) for (MXS_MONITORED_SERVER *ptr = monitor->monitored_servers; ptr; ptr = ptr->next)
{ {
if (mon_status_changed(ptr) && if (mon_status_changed(ptr) &&
(!(SERVER_IS_RUNNING(ptr->server)) || (!(SERVER_IS_RUNNING(ptr->server)) ||
@ -1641,7 +1641,7 @@ void mon_hangup_failed_servers(MXS_MONITOR *monitor)
} }
} }
void mon_report_query_error(MXS_MONITOR_SERVERS* db) void mon_report_query_error(MXS_MONITORED_SERVER* db)
{ {
MXS_ERROR("Failed to execute query on server '%s' ([%s]:%d): %s", MXS_ERROR("Failed to execute query on server '%s' ([%s]:%d): %s",
db->server->unique_name, db->server->name, db->server->unique_name, db->server->name,
@ -1655,7 +1655,7 @@ void mon_report_query_error(MXS_MONITOR_SERVERS* db)
*/ */
void lock_monitor_servers(MXS_MONITOR *monitor) void lock_monitor_servers(MXS_MONITOR *monitor)
{ {
MXS_MONITOR_SERVERS *ptr = monitor->databases; MXS_MONITORED_SERVER *ptr = monitor->monitored_servers;
while (ptr) while (ptr)
{ {
spinlock_acquire(&ptr->server->lock); spinlock_acquire(&ptr->server->lock);
@ -1669,7 +1669,7 @@ void lock_monitor_servers(MXS_MONITOR *monitor)
*/ */
void release_monitor_servers(MXS_MONITOR *monitor) void release_monitor_servers(MXS_MONITOR *monitor)
{ {
MXS_MONITOR_SERVERS *ptr = monitor->databases; MXS_MONITORED_SERVER *ptr = monitor->monitored_servers;
while (ptr) while (ptr)
{ {
spinlock_release(&ptr->server->lock); spinlock_release(&ptr->server->lock);
@ -1684,7 +1684,7 @@ void release_monitor_servers(MXS_MONITOR *monitor)
*/ */
void servers_status_pending_to_current(MXS_MONITOR *monitor) void servers_status_pending_to_current(MXS_MONITOR *monitor)
{ {
MXS_MONITOR_SERVERS *ptr = monitor->databases; MXS_MONITORED_SERVER *ptr = monitor->monitored_servers;
while (ptr) while (ptr)
{ {
ptr->server->status = ptr->server->status_pending; ptr->server->status = ptr->server->status_pending;
@ -1700,7 +1700,7 @@ void servers_status_pending_to_current(MXS_MONITOR *monitor)
*/ */
void servers_status_current_to_pending(MXS_MONITOR *monitor) void servers_status_current_to_pending(MXS_MONITOR *monitor)
{ {
MXS_MONITOR_SERVERS *ptr = monitor->databases; MXS_MONITORED_SERVER *ptr = monitor->monitored_servers;
while (ptr) while (ptr)
{ {
ptr->server->status_pending = ptr->server->status; ptr->server->status_pending = ptr->server->status;
@ -1710,7 +1710,7 @@ void servers_status_current_to_pending(MXS_MONITOR *monitor)
void mon_process_state_changes(MXS_MONITOR *monitor, const char *script, uint64_t events) void mon_process_state_changes(MXS_MONITOR *monitor, const char *script, uint64_t events)
{ {
for (MXS_MONITOR_SERVERS *ptr = monitor->databases; ptr; ptr = ptr->next) for (MXS_MONITORED_SERVER *ptr = monitor->monitored_servers; ptr; ptr = ptr->next)
{ {
if (mon_status_changed(ptr)) if (mon_status_changed(ptr))
{ {
@ -1749,9 +1749,9 @@ bool mon_process_failover(MXS_MONITOR *monitor, uint32_t failover_timeout)
{ {
bool rval = true; bool rval = true;
MXS_CONFIG* cnf = config_get_global_options(); MXS_CONFIG* cnf = config_get_global_options();
MXS_MONITOR_SERVERS* failed_master = NULL; MXS_MONITORED_SERVER* failed_master = NULL;
for (MXS_MONITOR_SERVERS *ptr = monitor->databases; ptr; ptr = ptr->next) for (MXS_MONITORED_SERVER *ptr = monitor->monitored_servers; ptr; ptr = ptr->next)
{ {
if (mon_status_changed(ptr)) if (mon_status_changed(ptr))
{ {
@ -1905,11 +1905,11 @@ json_t* monitor_json_data(const MXS_MONITOR* monitor, const char* host)
json_t* rel = json_object(); json_t* rel = json_object();
if (monitor->databases) if (monitor->monitored_servers)
{ {
json_t* mon_rel = mxs_json_relationship(host, MXS_JSON_API_SERVERS); json_t* mon_rel = mxs_json_relationship(host, MXS_JSON_API_SERVERS);
for (MXS_MONITOR_SERVERS *db = monitor->databases; db; db = db->next) for (MXS_MONITORED_SERVER *db = monitor->monitored_servers; db; db = db->next)
{ {
mxs_json_add_relation(mon_rel, db->server->unique_name, CN_SERVERS); mxs_json_add_relation(mon_rel, db->server->unique_name, CN_SERVERS);
} }
@ -1969,7 +1969,7 @@ json_t* monitor_relations_to_server(const SERVER* server, const char* host)
if (mon->active) if (mon->active)
{ {
for (MXS_MONITOR_SERVERS* db = mon->databases; db; db = db->next) for (MXS_MONITORED_SERVER* db = mon->monitored_servers; db; db = db->next)
{ {
if (db->server == server) if (db->server == server)
{ {
@ -2057,7 +2057,7 @@ static FILE* open_tmp_file(MXS_MONITOR *monitor, char *path)
* PATH_MAX bytes long * PATH_MAX bytes long
* @param size Size of @c data * @param size Size of @c data
*/ */
static void store_data(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS *master, uint8_t *data, uint32_t size) static void store_data(MXS_MONITOR *monitor, MXS_MONITORED_SERVER *master, uint8_t *data, uint32_t size)
{ {
uint8_t* ptr = data; uint8_t* ptr = data;
@ -2069,7 +2069,7 @@ static void store_data(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS *master, uint8_
*ptr++ = MMB_SCHEMA_VERSION; *ptr++ = MMB_SCHEMA_VERSION;
/** Store the states of all servers */ /** Store the states of all servers */
for (MXS_MONITOR_SERVERS* db = monitor->databases; db; db = db->next) for (MXS_MONITORED_SERVER* db = monitor->monitored_servers; db; db = db->next)
{ {
*ptr++ = (char)SVT_SERVER; // Value type *ptr++ = (char)SVT_SERVER; // Value type
memcpy(ptr, db->server->unique_name, strlen(db->server->unique_name)); // Name of the server memcpy(ptr, db->server->unique_name, strlen(db->server->unique_name)); // Name of the server
@ -2155,7 +2155,7 @@ static bool has_null_terminator(const char *data, const char *end)
*/ */
static const char* process_server(MXS_MONITOR *monitor, const char *data, const char *end) static const char* process_server(MXS_MONITOR *monitor, const char *data, const char *end)
{ {
for (MXS_MONITOR_SERVERS* db = monitor->databases; db; db = db->next) for (MXS_MONITORED_SERVER* db = monitor->monitored_servers; db; db = db->next)
{ {
if (strcmp(db->server->unique_name, data) == 0) if (strcmp(db->server->unique_name, data) == 0)
{ {
@ -2180,12 +2180,12 @@ static const char* process_server(MXS_MONITOR *monitor, const char *data, const
/** /**
* Process a master * Process a master
*/ */
static const char* process_master(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS **master, const char *data, static const char* process_master(MXS_MONITOR *monitor, MXS_MONITORED_SERVER **master, const char *data,
const char *end) const char *end)
{ {
if (master) if (master)
{ {
for (MXS_MONITOR_SERVERS* db = monitor->databases; db; db = db->next) for (MXS_MONITORED_SERVER* db = monitor->monitored_servers; db; db = db->next)
{ {
if (strcmp(db->server->unique_name, data) == 0) if (strcmp(db->server->unique_name, data) == 0)
{ {
@ -2214,7 +2214,7 @@ static bool check_crc32(const uint8_t *data, uint32_t size, const uint8_t *crc_p
/** /**
* Process the stored journal data * Process the stored journal data
*/ */
static bool process_data_file(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS **master, const char *data, static bool process_data_file(MXS_MONITOR *monitor, MXS_MONITORED_SERVER **master, const char *data,
const char *crc_ptr) const char *crc_ptr)
{ {
const char *ptr = data; const char *ptr = data;
@ -2254,12 +2254,12 @@ static bool process_data_file(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS **master
return true; return true;
} }
void store_server_journal(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS *master) void store_server_journal(MXS_MONITOR *monitor, MXS_MONITORED_SERVER *master)
{ {
/** Calculate how much memory we need to allocate */ /** Calculate how much memory we need to allocate */
uint32_t size = MMB_LEN_SCHEMA_VERSION + MMB_LEN_CRC32; uint32_t size = MMB_LEN_SCHEMA_VERSION + MMB_LEN_CRC32;
for (MXS_MONITOR_SERVERS* db = monitor->databases; db; db = db->next) for (MXS_MONITORED_SERVER* db = monitor->monitored_servers; db; db = db->next)
{ {
/** Each server is stored as a type byte and a null-terminated string /** Each server is stored as a type byte and a null-terminated string
* followed by eight byte server status. */ * followed by eight byte server status. */
@ -2305,7 +2305,7 @@ void store_server_journal(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS *master)
MXS_FREE(data); MXS_FREE(data);
} }
void load_server_journal(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS **master) void load_server_journal(MXS_MONITOR *monitor, MXS_MONITORED_SERVER **master)
{ {
char path[PATH_MAX]; char path[PATH_MAX];
FILE *file = open_data_file(monitor, path); FILE *file = open_data_file(monitor, path);

View File

@ -43,7 +43,7 @@ typedef struct aurora_monitor
* @param monitor Monitor object * @param monitor Monitor object
* @param database Server whose status should be updated * @param database Server whose status should be updated
*/ */
void update_server_status(MXS_MONITOR *monitor, MXS_MONITOR_SERVERS *database) void update_server_status(MXS_MONITOR *monitor, MXS_MONITORED_SERVER *database)
{ {
if (!SERVER_IN_MAINT(database->server)) if (!SERVER_IN_MAINT(database->server))
{ {
@ -125,7 +125,7 @@ monitorMain(void *arg)
lock_monitor_servers(monitor); lock_monitor_servers(monitor);
servers_status_pending_to_current(monitor); servers_status_pending_to_current(monitor);
for (MXS_MONITOR_SERVERS *ptr = monitor->databases; ptr; ptr = ptr->next) for (MXS_MONITORED_SERVER *ptr = monitor->monitored_servers; ptr; ptr = ptr->next)
{ {
update_server_status(monitor, ptr); update_server_status(monitor, ptr);

View File

@ -34,8 +34,8 @@ static void *startMonitor(MXS_MONITOR *, const MXS_CONFIG_PARAMETER *params);
static void stopMonitor(MXS_MONITOR *); static void stopMonitor(MXS_MONITOR *);
static void diagnostics(DCB *, const MXS_MONITOR *); static void diagnostics(DCB *, const MXS_MONITOR *);
static json_t* diagnostics_json(const MXS_MONITOR *); static json_t* diagnostics_json(const MXS_MONITOR *);
static MXS_MONITOR_SERVERS *get_candidate_master(MXS_MONITOR*); static MXS_MONITORED_SERVER *get_candidate_master(MXS_MONITOR*);
static MXS_MONITOR_SERVERS *set_cluster_master(MXS_MONITOR_SERVERS *, MXS_MONITOR_SERVERS *, int); static MXS_MONITORED_SERVER *set_cluster_master(MXS_MONITORED_SERVER *, MXS_MONITORED_SERVER *, int);
static void disableMasterFailback(void *, int); static void disableMasterFailback(void *, int);
bool isGaleraEvent(mxs_monitor_event_t event); bool isGaleraEvent(mxs_monitor_event_t event);
static void update_sst_donor_nodes(MXS_MONITOR*, int); static void update_sst_donor_nodes(MXS_MONITOR*, int);
@ -269,7 +269,7 @@ static json_t* diagnostics_json(const MXS_MONITOR *mon)
* @param database The database to probe * @param database The database to probe
*/ */
static void static void
monitorDatabase(MXS_MONITOR *mon, MXS_MONITOR_SERVERS *database) monitorDatabase(MXS_MONITOR *mon, MXS_MONITORED_SERVER *database)
{ {
GALERA_MONITOR* handle = (GALERA_MONITOR*) mon->handle; GALERA_MONITOR* handle = (GALERA_MONITOR*) mon->handle;
MYSQL_ROW row; MYSQL_ROW row;
@ -483,9 +483,9 @@ monitorMain(void *arg)
{ {
GALERA_MONITOR *handle = (GALERA_MONITOR*)arg; GALERA_MONITOR *handle = (GALERA_MONITOR*)arg;
MXS_MONITOR* mon = handle->monitor; MXS_MONITOR* mon = handle->monitor;
MXS_MONITOR_SERVERS *ptr; MXS_MONITORED_SERVER *ptr;
size_t nrounds = 0; size_t nrounds = 0;
MXS_MONITOR_SERVERS *candidate_master = NULL; MXS_MONITORED_SERVER *candidate_master = NULL;
int master_stickiness; int master_stickiness;
int is_cluster = 0; int is_cluster = 0;
int log_no_members = 1; int log_no_members = 1;
@ -534,7 +534,7 @@ monitorMain(void *arg)
lock_monitor_servers(mon); lock_monitor_servers(mon);
servers_status_pending_to_current(mon); servers_status_pending_to_current(mon);
ptr = mon->databases; ptr = mon->monitored_servers;
while (ptr) while (ptr)
{ {
ptr->mon_prev_status = ptr->server->status; ptr->mon_prev_status = ptr->server->status;
@ -583,7 +583,7 @@ monitorMain(void *arg)
handle->master = set_cluster_master(handle->master, candidate_master, master_stickiness); handle->master = set_cluster_master(handle->master, candidate_master, master_stickiness);
ptr = mon->databases; ptr = mon->monitored_servers;
while (ptr) while (ptr)
{ {
@ -666,10 +666,10 @@ monitorMain(void *arg)
* @param servers The monitored servers list * @param servers The monitored servers list
* @return The candidate master on success, NULL on failure * @return The candidate master on success, NULL on failure
*/ */
static MXS_MONITOR_SERVERS *get_candidate_master(MXS_MONITOR* mon) static MXS_MONITORED_SERVER *get_candidate_master(MXS_MONITOR* mon)
{ {
MXS_MONITOR_SERVERS *moitor_servers = mon->databases; MXS_MONITORED_SERVER *moitor_servers = mon->monitored_servers;
MXS_MONITOR_SERVERS *candidate_master = NULL; MXS_MONITORED_SERVER *candidate_master = NULL;
GALERA_MONITOR* handle = mon->handle; GALERA_MONITOR* handle = mon->handle;
long min_id = -1; long min_id = -1;
int minval = INT_MAX; int minval = INT_MAX;
@ -741,8 +741,8 @@ static MXS_MONITOR_SERVERS *get_candidate_master(MXS_MONITOR* mon)
* @param candidate_master The candidate master server accordingly to the selection rule * @param candidate_master The candidate master server accordingly to the selection rule
* @return The master node pointer (could be NULL) * @return The master node pointer (could be NULL)
*/ */
static MXS_MONITOR_SERVERS *set_cluster_master(MXS_MONITOR_SERVERS *current_master, static MXS_MONITORED_SERVER *set_cluster_master(MXS_MONITORED_SERVER *current_master,
MXS_MONITOR_SERVERS *candidate_master, MXS_MONITORED_SERVER *candidate_master,
int master_stickiness) int master_stickiness)
{ {
/* /*
@ -791,7 +791,7 @@ static MXS_MONITOR_SERVERS *set_cluster_master(MXS_MONITOR_SERVERS *current_mast
*/ */
static void update_sst_donor_nodes(MXS_MONITOR *mon, int is_cluster) static void update_sst_donor_nodes(MXS_MONITOR *mon, int is_cluster)
{ {
MXS_MONITOR_SERVERS *ptr; MXS_MONITORED_SERVER *ptr;
MYSQL_ROW row; MYSQL_ROW row;
MYSQL_RES *result; MYSQL_RES *result;
GALERA_MONITOR *handle = mon->handle; GALERA_MONITOR *handle = mon->handle;
@ -804,7 +804,7 @@ static void update_sst_donor_nodes(MXS_MONITOR *mon, int is_cluster)
} }
unsigned int found_slaves = 0; unsigned int found_slaves = 0;
MXS_MONITOR_SERVERS *node_list[is_cluster - 1]; MXS_MONITORED_SERVER *node_list[is_cluster - 1];
/* Donor list size = DONOR_LIST_SET_VAR + n_hosts * max_host_len + n_hosts + 1 */ /* Donor list size = DONOR_LIST_SET_VAR + n_hosts * max_host_len + n_hosts + 1 */
char *donor_list = MXS_CALLOC(1, strlen(DONOR_LIST_SET_VAR) + char *donor_list = MXS_CALLOC(1, strlen(DONOR_LIST_SET_VAR) +
@ -819,14 +819,14 @@ static void update_sst_donor_nodes(MXS_MONITOR *mon, int is_cluster)
strcpy(donor_list, DONOR_LIST_SET_VAR); strcpy(donor_list, DONOR_LIST_SET_VAR);
ptr = mon->databases; ptr = mon->monitored_servers;
/* Create an array of slave nodes */ /* Create an array of slave nodes */
while (ptr) while (ptr)
{ {
if (SERVER_IS_JOINED(ptr->server) && SERVER_IS_SLAVE(ptr->server)) if (SERVER_IS_JOINED(ptr->server) && SERVER_IS_SLAVE(ptr->server))
{ {
node_list[found_slaves] = (MXS_MONITOR_SERVERS *)ptr; node_list[found_slaves] = (MXS_MONITORED_SERVER *)ptr;
found_slaves++; found_slaves++;
/* Check the server parameter "priority" /* Check the server parameter "priority"
@ -854,13 +854,13 @@ static void update_sst_donor_nodes(MXS_MONITOR *mon, int is_cluster)
/* Sort the array */ /* Sort the array */
qsort(node_list, qsort(node_list,
found_slaves, found_slaves,
sizeof(MXS_MONITOR_SERVERS *), sizeof(MXS_MONITORED_SERVER *),
sort_order ? compare_node_priority : compare_node_index); sort_order ? compare_node_priority : compare_node_index);
/* Select nodename from each server and append it to node_list */ /* Select nodename from each server and append it to node_list */
for (int k = 0; k < found_slaves; k++) for (int k = 0; k < found_slaves; k++)
{ {
MXS_MONITOR_SERVERS *ptr = node_list[k]; MXS_MONITORED_SERVER *ptr = node_list[k];
/* Get the Galera node name */ /* Get the Galera node name */
if (mysql_query(ptr->con, "SHOW VARIABLES LIKE 'wsrep_node_name'") == 0 if (mysql_query(ptr->con, "SHOW VARIABLES LIKE 'wsrep_node_name'") == 0
@ -906,7 +906,7 @@ static void update_sst_donor_nodes(MXS_MONITOR *mon, int is_cluster)
/* Set now rep_sst_donor in each slave node */ /* Set now rep_sst_donor in each slave node */
for (int k = 0; k < found_slaves; k++) for (int k = 0; k < found_slaves; k++)
{ {
MXS_MONITOR_SERVERS *ptr = node_list[k]; MXS_MONITORED_SERVER *ptr = node_list[k];
/* Set the Galera SST donor node list */ /* Set the Galera SST donor node list */
if (mysql_query(ptr->con, donor_list) == 0) if (mysql_query(ptr->con, donor_list) == 0)
{ {
@ -937,8 +937,8 @@ static void update_sst_donor_nodes(MXS_MONITOR *mon, int is_cluster)
static int compare_node_index (const void *a, const void *b) static int compare_node_index (const void *a, const void *b)
{ {
const MXS_MONITOR_SERVERS *s_a = *(MXS_MONITOR_SERVERS * const *)a; const MXS_MONITORED_SERVER *s_a = *(MXS_MONITORED_SERVER * const *)a;
const MXS_MONITOR_SERVERS *s_b = *(MXS_MONITOR_SERVERS * const *)b; const MXS_MONITORED_SERVER *s_b = *(MXS_MONITORED_SERVER * const *)b;
// Order is DESC: b - a // Order is DESC: b - a
return s_b->server->node_id - s_a->server->node_id; return s_b->server->node_id - s_a->server->node_id;
@ -965,8 +965,8 @@ static int compare_node_index (const void *a, const void *b)
static int compare_node_priority (const void *a, const void *b) static int compare_node_priority (const void *a, const void *b)
{ {
const MXS_MONITOR_SERVERS *s_a = *(MXS_MONITOR_SERVERS * const *)a; const MXS_MONITORED_SERVER *s_a = *(MXS_MONITORED_SERVER * const *)a;
const MXS_MONITOR_SERVERS *s_b = *(MXS_MONITOR_SERVERS * const *)b; const MXS_MONITORED_SERVER *s_b = *(MXS_MONITORED_SERVER * const *)b;
const char *pri_a = server_get_parameter(s_a->server, "priority"); const char *pri_a = server_get_parameter(s_a->server, "priority");
const char *pri_b = server_get_parameter(s_b->server, "priority"); const char *pri_b = server_get_parameter(s_b->server, "priority");
@ -1195,11 +1195,11 @@ static void set_cluster_members(MXS_MONITOR *mon)
{ {
GALERA_MONITOR *handle = mon->handle; GALERA_MONITOR *handle = mon->handle;
GALERA_NODE_INFO *value; GALERA_NODE_INFO *value;
MXS_MONITOR_SERVERS *ptr; MXS_MONITORED_SERVER *ptr;
char *c_uuid = handle->cluster_info.c_uuid; char *c_uuid = handle->cluster_info.c_uuid;
int c_size = handle->cluster_info.c_size; int c_size = handle->cluster_info.c_size;
ptr = mon->databases; ptr = mon->monitored_servers;
while (ptr) while (ptr)
{ {
/* Fetch cluster info for this server, if any */ /* Fetch cluster info for this server, if any */

View File

@ -85,7 +85,7 @@ typedef struct
int disableMasterFailback; /**< Monitor flag for Galera Cluster Master failback */ int disableMasterFailback; /**< Monitor flag for Galera Cluster Master failback */
int availableWhenDonor; /**< Monitor flag for Galera Cluster Donor availability */ int availableWhenDonor; /**< Monitor flag for Galera Cluster Donor availability */
bool disableMasterRoleSetting; /**< Monitor flag to disable setting master role */ bool disableMasterRoleSetting; /**< Monitor flag to disable setting master role */
MXS_MONITOR_SERVERS *master; /**< Master server for MySQL Master/Slave replication */ MXS_MONITORED_SERVER *master; /**< Master server for MySQL Master/Slave replication */
char* script; char* script;
bool root_node_as_master; /**< Whether we require that the Master should bool root_node_as_master; /**< Whether we require that the Master should
* have a wsrep_local_index of 0 */ * have a wsrep_local_index of 0 */

View File

@ -40,12 +40,12 @@ public:
~GRMon(); ~GRMon();
private: private:
THREAD m_thread; /**< Monitor thread */ THREAD m_thread; /**< Monitor thread */
int m_shutdown; /**< Flag to shutdown the monitor thread */ int m_shutdown; /**< Flag to shutdown the monitor thread */
MXS_MONITOR_SERVERS* m_master; /**< The master server */ MXS_MONITORED_SERVER* m_master; /**< The master server */
std::string m_script; std::string m_script;
uint64_t m_events; /**< Enabled events */ uint64_t m_events; /**< Enabled events */
MXS_MONITOR* m_monitor; MXS_MONITOR* m_monitor;
GRMon(MXS_MONITOR* monitor, const MXS_CONFIG_PARAMETER *params); GRMon(MXS_MONITOR* monitor, const MXS_CONFIG_PARAMETER *params);
@ -148,7 +148,7 @@ static inline bool is_false(const char* value)
strcasecmp(value, "false") == 0; strcasecmp(value, "false") == 0;
} }
static bool is_master(MXS_MONITOR_SERVERS* server) static bool is_master(MXS_MONITORED_SERVER* server)
{ {
bool rval = false; bool rval = false;
MYSQL_RES* result; MYSQL_RES* result;
@ -175,7 +175,7 @@ static bool is_master(MXS_MONITOR_SERVERS* server)
return rval; return rval;
} }
static bool is_slave(MXS_MONITOR_SERVERS* server) static bool is_slave(MXS_MONITORED_SERVER* server)
{ {
bool rval = false; bool rval = false;
MYSQL_RES* result; MYSQL_RES* result;
@ -202,7 +202,7 @@ static bool is_slave(MXS_MONITOR_SERVERS* server)
return rval; return rval;
} }
static void update_server_status(MXS_MONITOR* monitor, MXS_MONITOR_SERVERS* server) static void update_server_status(MXS_MONITOR* monitor, MXS_MONITORED_SERVER* server)
{ {
/* Don't even probe server flagged as in maintenance */ /* Don't even probe server flagged as in maintenance */
if (SERVER_IN_MAINT(server->server)) if (SERVER_IN_MAINT(server->server))
@ -273,7 +273,7 @@ void GRMon::main()
lock_monitor_servers(m_monitor); lock_monitor_servers(m_monitor);
servers_status_pending_to_current(m_monitor); servers_status_pending_to_current(m_monitor);
for (MXS_MONITOR_SERVERS *ptr = m_monitor->databases; ptr; ptr = ptr->next) for (MXS_MONITORED_SERVER *ptr = m_monitor->monitored_servers; ptr; ptr = ptr->next)
{ {
update_server_status(m_monitor, ptr); update_server_status(m_monitor, ptr);
} }

View File

@ -43,7 +43,7 @@ static void stopMonitor(MXS_MONITOR *);
static void diagnostics(DCB *, const MXS_MONITOR *); static void diagnostics(DCB *, const MXS_MONITOR *);
static json_t* diagnostics_json(const MXS_MONITOR *); static json_t* diagnostics_json(const MXS_MONITOR *);
static void detectStaleMaster(void *, int); static void detectStaleMaster(void *, int);
static MXS_MONITOR_SERVERS *get_current_master(MXS_MONITOR *); static MXS_MONITORED_SERVER *get_current_master(MXS_MONITOR *);
static bool isMySQLEvent(mxs_monitor_event_t event); static bool isMySQLEvent(mxs_monitor_event_t event);
/** /**
@ -203,7 +203,7 @@ static json_t* diagnostics_json(const MXS_MONITOR *mon)
* @param database The database to probe * @param database The database to probe
*/ */
static void static void
monitorDatabase(MXS_MONITOR* mon, MXS_MONITOR_SERVERS *database) monitorDatabase(MXS_MONITOR* mon, MXS_MONITORED_SERVER *database)
{ {
MYSQL_ROW row; MYSQL_ROW row;
MYSQL_RES *result; MYSQL_RES *result;
@ -500,9 +500,9 @@ monitorMain(void *arg)
{ {
MM_MONITOR *handle = (MM_MONITOR *)arg; MM_MONITOR *handle = (MM_MONITOR *)arg;
MXS_MONITOR* mon = handle->monitor; MXS_MONITOR* mon = handle->monitor;
MXS_MONITOR_SERVERS *ptr; MXS_MONITORED_SERVER *ptr;
int detect_stale_master = false; int detect_stale_master = false;
MXS_MONITOR_SERVERS *root_master = NULL; MXS_MONITORED_SERVER *root_master = NULL;
size_t nrounds = 0; size_t nrounds = 0;
detect_stale_master = handle->detectStaleMaster; detect_stale_master = handle->detectStaleMaster;
@ -547,7 +547,7 @@ monitorMain(void *arg)
servers_status_pending_to_current(mon); servers_status_pending_to_current(mon);
/* start from the first server in the list */ /* start from the first server in the list */
ptr = mon->databases; ptr = mon->monitored_servers;
while (ptr) while (ptr)
{ {
@ -584,7 +584,7 @@ monitorMain(void *arg)
/* Update server status from monitor pending status on that server*/ /* Update server status from monitor pending status on that server*/
ptr = mon->databases; ptr = mon->monitored_servers;
while (ptr) while (ptr)
{ {
if (!SERVER_IN_MAINT(ptr->server)) if (!SERVER_IN_MAINT(ptr->server))
@ -651,12 +651,12 @@ detectStaleMaster(void *arg, int enable)
* @return The server at root level with SERVER_MASTER bit * @return The server at root level with SERVER_MASTER bit
*/ */
static MXS_MONITOR_SERVERS *get_current_master(MXS_MONITOR *mon) static MXS_MONITORED_SERVER *get_current_master(MXS_MONITOR *mon)
{ {
MM_MONITOR* handle = mon->handle; MM_MONITOR* handle = mon->handle;
MXS_MONITOR_SERVERS *ptr; MXS_MONITORED_SERVER *ptr;
ptr = mon->databases; ptr = mon->monitored_servers;
while (ptr) while (ptr)
{ {

View File

@ -45,7 +45,7 @@ typedef struct
int status; /**< Monitor status */ int status; /**< Monitor status */
unsigned long id; /**< Monitor ID */ unsigned long id; /**< Monitor ID */
int detectStaleMaster; /**< Monitor flag for Stale Master detection */ int detectStaleMaster; /**< Monitor flag for Stale Master detection */
MXS_MONITOR_SERVERS *master; /**< Master server for Master/Slave replication */ MXS_MONITORED_SERVER *master; /**< Master server for Master/Slave replication */
char* script; /*< Script to call when state changes occur on servers */ char* script; /*< Script to call when state changes occur on servers */
uint64_t events; /*< enabled events */ uint64_t events; /*< enabled events */
MXS_MONITOR* monitor; MXS_MONITOR* monitor;

View File

@ -53,7 +53,7 @@ typedef struct
int availableWhenDonor; /**< Monitor flag for Galera Cluster Donor availability */ int availableWhenDonor; /**< Monitor flag for Galera Cluster Donor availability */
int disableMasterRoleSetting; /**< Monitor flag to disable setting master role */ int disableMasterRoleSetting; /**< Monitor flag to disable setting master role */
bool mysql51_replication; /**< Use MySQL 5.1 replication */ bool mysql51_replication; /**< Use MySQL 5.1 replication */
MXS_MONITOR_SERVERS *master; /**< Master server for MySQL Master/Slave replication */ MXS_MONITORED_SERVER *master; /**< Master server for MySQL Master/Slave replication */
char* script; /*< Script to call when state changes occur on servers */ char* script; /*< Script to call when state changes occur on servers */
uint64_t events; /*< enabled events */ uint64_t events; /*< enabled events */
HASHTABLE *server_info; /**< Contains server specific information */ HASHTABLE *server_info; /**< Contains server specific information */

View File

@ -55,11 +55,11 @@ static void stopMonitor(MXS_MONITOR *);
static bool stop_monitor(MXS_MONITOR *); static bool stop_monitor(MXS_MONITOR *);
static void diagnostics(DCB *, const MXS_MONITOR *); static void diagnostics(DCB *, const MXS_MONITOR *);
static json_t* diagnostics_json(const MXS_MONITOR *); static json_t* diagnostics_json(const MXS_MONITOR *);
static MXS_MONITOR_SERVERS *getServerByNodeId(MXS_MONITOR_SERVERS *, long); static MXS_MONITORED_SERVER *getServerByNodeId(MXS_MONITORED_SERVER *, long);
static MXS_MONITOR_SERVERS *getSlaveOfNodeId(MXS_MONITOR_SERVERS *, long); static MXS_MONITORED_SERVER *getSlaveOfNodeId(MXS_MONITORED_SERVER *, long);
static MXS_MONITOR_SERVERS *get_replication_tree(MXS_MONITOR *, int); static MXS_MONITORED_SERVER *get_replication_tree(MXS_MONITOR *, int);
static void set_master_heartbeat(MYSQL_MONITOR *, MXS_MONITOR_SERVERS *); static void set_master_heartbeat(MYSQL_MONITOR *, MXS_MONITORED_SERVER *);
static void set_slave_heartbeat(MXS_MONITOR *, MXS_MONITOR_SERVERS *); static void set_slave_heartbeat(MXS_MONITOR *, MXS_MONITORED_SERVER *);
static int add_slave_to_master(long *, int, long); static int add_slave_to_master(long *, int, long);
static bool isMySQLEvent(mxs_monitor_event_t event); static bool isMySQLEvent(mxs_monitor_event_t event);
void check_maxscale_schema_replication(MXS_MONITOR *monitor); void check_maxscale_schema_replication(MXS_MONITOR *monitor);
@ -192,14 +192,11 @@ bool mysql_switchover_check(MXS_MONITOR* mon, SERVER* new_master, SERVER* curren
{ {
bool rv = true; bool rv = true;
// TODO: Rename MXS_MONITOR_SERVERS to MXS_MONITORED_SERVER and
// TODO: mxs_monitor::databases to mxs_monitor::monitored_servers
bool current_master_found = false; bool current_master_found = false;
bool new_master_found = false; bool new_master_found = false;
// TODO: Is locking needed here? // TODO: Is locking needed here?
MXS_MONITOR_SERVERS* monitored_server = mon->databases; MXS_MONITORED_SERVER* monitored_server = mon->monitored_servers;
while (rv && !current_master_found && !new_master_found && monitored_server) while (rv && !current_master_found && !new_master_found && monitored_server)
{ {
@ -532,7 +529,7 @@ void info_free_func(void *val)
* @return True on success, false if initialization failed. At the moment * @return True on success, false if initialization failed. At the moment
* initialization can only fail if memory allocation fails. * initialization can only fail if memory allocation fails.
*/ */
bool init_server_info(MYSQL_MONITOR *handle, MXS_MONITOR_SERVERS *database) bool init_server_info(MYSQL_MONITOR *handle, MXS_MONITORED_SERVER *database)
{ {
bool rval = true; bool rval = true;
@ -625,7 +622,7 @@ startMonitor(MXS_MONITOR *monitor, const MXS_CONFIG_PARAMETER* params)
error = true; error = true;
} }
if (!init_server_info(handle, monitor->databases)) if (!init_server_info(handle, monitor->monitored_servers))
{ {
error = true; error = true;
} }
@ -713,7 +710,7 @@ static void diagnostics(DCB *dcb, const MXS_MONITOR *mon)
dcb_printf(dcb, "Detect Stale Master:\t%s\n", (handle->detectStaleMaster == 1) ? "enabled" : "disabled"); dcb_printf(dcb, "Detect Stale Master:\t%s\n", (handle->detectStaleMaster == 1) ? "enabled" : "disabled");
dcb_printf(dcb, "Server information\n\n"); dcb_printf(dcb, "Server information\n\n");
for (MXS_MONITOR_SERVERS *db = mon->databases; db; db = db->next) for (MXS_MONITORED_SERVER *db = mon->monitored_servers; db; db = db->next)
{ {
MYSQL_SERVER_INFO *serv_info = MYSQL_SERVER_INFO *serv_info =
static_cast<MYSQL_SERVER_INFO*>(hashtable_fetch(handle->server_info, db->server->unique_name)); static_cast<MYSQL_SERVER_INFO*>(hashtable_fetch(handle->server_info, db->server->unique_name));
@ -765,11 +762,11 @@ static json_t* diagnostics_json(const MXS_MONITOR *mon)
json_object_set_new(rval, "script", json_string(handle->script)); json_object_set_new(rval, "script", json_string(handle->script));
} }
if (mon->databases) if (mon->monitored_servers)
{ {
json_t* arr = json_array(); json_t* arr = json_array();
for (MXS_MONITOR_SERVERS *db = mon->databases; db; db = db->next) for (MXS_MONITORED_SERVER *db = mon->monitored_servers; db; db = db->next)
{ {
json_t* srv = json_object(); json_t* srv = json_object();
MYSQL_SERVER_INFO *serv_info = MYSQL_SERVER_INFO *serv_info =
@ -808,7 +805,7 @@ enum mysql_server_version
MYSQL_SERVER_VERSION_51 MYSQL_SERVER_VERSION_51
}; };
static inline void monitor_mysql_db(MXS_MONITOR_SERVERS* database, MYSQL_SERVER_INFO *serv_info, static inline void monitor_mysql_db(MXS_MONITORED_SERVER* database, MYSQL_SERVER_INFO *serv_info,
enum mysql_server_version server_version) enum mysql_server_version server_version)
{ {
unsigned int columns; unsigned int columns;
@ -943,10 +940,10 @@ static inline void monitor_mysql_db(MXS_MONITOR_SERVERS* database, MYSQL_SERVER_
* @param mon Monitor * @param mon Monitor
* @return Lowest server ID master in the monitor * @return Lowest server ID master in the monitor
*/ */
static MXS_MONITOR_SERVERS *build_mysql51_replication_tree(MXS_MONITOR *mon) static MXS_MONITORED_SERVER *build_mysql51_replication_tree(MXS_MONITOR *mon)
{ {
MXS_MONITOR_SERVERS* database = mon->databases; MXS_MONITORED_SERVER* database = mon->monitored_servers;
MXS_MONITOR_SERVERS *ptr, *rval = NULL; MXS_MONITORED_SERVER *ptr, *rval = NULL;
int i; int i;
MYSQL_MONITOR *handle = static_cast<MYSQL_MONITOR*>(mon->handle); MYSQL_MONITOR *handle = static_cast<MYSQL_MONITOR*>(mon->handle);
@ -1012,12 +1009,12 @@ static MXS_MONITOR_SERVERS *build_mysql51_replication_tree(MXS_MONITOR *mon)
database = database->next; database = database->next;
} }
database = mon->databases; database = mon->monitored_servers;
/** Set master server IDs */ /** Set master server IDs */
while (database) while (database)
{ {
ptr = mon->databases; ptr = mon->monitored_servers;
while (ptr) while (ptr)
{ {
@ -1058,7 +1055,7 @@ static MXS_MONITOR_SERVERS *build_mysql51_replication_tree(MXS_MONITOR *mon)
* @param database The database to probe * @param database The database to probe
*/ */
static void static void
monitorDatabase(MXS_MONITOR *mon, MXS_MONITOR_SERVERS *database) monitorDatabase(MXS_MONITOR *mon, MXS_MONITORED_SERVER *database)
{ {
MYSQL_MONITOR* handle = static_cast<MYSQL_MONITOR*>(mon->handle); MYSQL_MONITOR* handle = static_cast<MYSQL_MONITOR*>(mon->handle);
MYSQL_ROW row; MYSQL_ROW row;
@ -1219,7 +1216,7 @@ struct graph_node
bool active; bool active;
struct graph_node *parent; struct graph_node *parent;
MYSQL_SERVER_INFO *info; MYSQL_SERVER_INFO *info;
MXS_MONITOR_SERVERS *db; MXS_MONITORED_SERVER *db;
}; };
/** /**
@ -1332,13 +1329,13 @@ static void visit_node(struct graph_node *node, struct graph_node **stack,
* member. Nodes in a group get a positive group ID where the nodes not in a * member. Nodes in a group get a positive group ID where the nodes not in a
* group get a group ID of 0. * group get a group ID of 0.
*/ */
void find_graph_cycles(MYSQL_MONITOR *handle, MXS_MONITOR_SERVERS *database, int nservers) void find_graph_cycles(MYSQL_MONITOR *handle, MXS_MONITORED_SERVER *database, int nservers)
{ {
struct graph_node graph[nservers]; struct graph_node graph[nservers];
struct graph_node *stack[nservers]; struct graph_node *stack[nservers];
int nodes = 0; int nodes = 0;
for (MXS_MONITOR_SERVERS *db = database; db; db = db->next) for (MXS_MONITORED_SERVER *db = database; db; db = db->next)
{ {
graph[nodes].info = graph[nodes].info =
static_cast<MYSQL_SERVER_INFO*>(hashtable_fetch(handle->server_info, db->server->unique_name)); static_cast<MYSQL_SERVER_INFO*>(hashtable_fetch(handle->server_info, db->server->unique_name));
@ -1440,7 +1437,7 @@ void find_graph_cycles(MYSQL_MONITOR *handle, MXS_MONITOR_SERVERS *database, int
* *
* @return True if failover is required * @return True if failover is required
*/ */
bool failover_required(MYSQL_MONITOR *handle, MXS_MONITOR_SERVERS *db) bool failover_required(MYSQL_MONITOR *handle, MXS_MONITORED_SERVER *db)
{ {
int candidates = 0; int candidates = 0;
@ -1480,7 +1477,7 @@ bool failover_required(MYSQL_MONITOR *handle, MXS_MONITOR_SERVERS *db)
* @param handle Monitor instance * @param handle Monitor instance
* @param db Monitor servers * @param db Monitor servers
*/ */
void do_failover(MYSQL_MONITOR *handle, MXS_MONITOR_SERVERS *db) void do_failover(MYSQL_MONITOR *handle, MXS_MONITORED_SERVER *db)
{ {
while (db) while (db)
{ {
@ -1519,11 +1516,11 @@ monitorMain(void *arg)
{ {
MYSQL_MONITOR *handle = (MYSQL_MONITOR *) arg; MYSQL_MONITOR *handle = (MYSQL_MONITOR *) arg;
MXS_MONITOR* mon = handle->monitor; MXS_MONITOR* mon = handle->monitor;
MXS_MONITOR_SERVERS *ptr; MXS_MONITORED_SERVER *ptr;
int replication_heartbeat; int replication_heartbeat;
bool detect_stale_master; bool detect_stale_master;
int num_servers = 0; int num_servers = 0;
MXS_MONITOR_SERVERS *root_master = NULL; MXS_MONITORED_SERVER *root_master = NULL;
size_t nrounds = 0; size_t nrounds = 0;
int log_no_master = 1; int log_no_master = 1;
bool heartbeat_checked = false; bool heartbeat_checked = false;
@ -1579,7 +1576,7 @@ monitorMain(void *arg)
servers_status_pending_to_current(mon); servers_status_pending_to_current(mon);
/* start from the first server in the list */ /* start from the first server in the list */
ptr = mon->databases; ptr = mon->monitored_servers;
while (ptr) while (ptr)
{ {
@ -1636,7 +1633,7 @@ monitorMain(void *arg)
ptr = ptr->next; ptr = ptr->next;
} }
ptr = mon->databases; ptr = mon->monitored_servers;
/* if only one server is configured, that's is Master */ /* if only one server is configured, that's is Master */
if (num_servers == 1) if (num_servers == 1)
{ {
@ -1672,10 +1669,10 @@ monitorMain(void *arg)
/** Find all the master server cycles in the cluster graph. If /** Find all the master server cycles in the cluster graph. If
multiple masters are found, the servers with the read_only multiple masters are found, the servers with the read_only
variable set to ON will be assigned the slave status. */ variable set to ON will be assigned the slave status. */
find_graph_cycles(handle, mon->databases, num_servers); find_graph_cycles(handle, mon->monitored_servers, num_servers);
} }
ptr = mon->databases; ptr = mon->monitored_servers;
while (ptr) while (ptr)
{ {
MYSQL_SERVER_INFO *serv_info = MYSQL_SERVER_INFO *serv_info =
@ -1684,8 +1681,8 @@ monitorMain(void *arg)
ss_dassert(serv_info); ss_dassert(serv_info);
if (ptr->server->node_id > 0 && ptr->server->master_id > 0 && if (ptr->server->node_id > 0 && ptr->server->master_id > 0 &&
getSlaveOfNodeId(mon->databases, ptr->server->node_id) && getSlaveOfNodeId(mon->monitored_servers, ptr->server->node_id) &&
getServerByNodeId(mon->databases, ptr->server->master_id) && getServerByNodeId(mon->monitored_servers, ptr->server->master_id) &&
(!handle->multimaster || serv_info->group == 0)) (!handle->multimaster || serv_info->group == 0))
{ {
/** This server is both a slave and a master i.e. a relay master */ /** This server is both a slave and a master i.e. a relay master */
@ -1704,7 +1701,7 @@ monitorMain(void *arg)
/* Update server status from monitor pending status on that server*/ /* Update server status from monitor pending status on that server*/
ptr = mon->databases; ptr = mon->monitored_servers;
while (ptr) while (ptr)
{ {
if (!SERVER_IN_MAINT(ptr->server)) if (!SERVER_IN_MAINT(ptr->server))
@ -1790,10 +1787,10 @@ monitorMain(void *arg)
if we need to do a failover */ if we need to do a failover */
if (handle->detect_standalone_master) if (handle->detect_standalone_master)
{ {
if (failover_required(handle, mon->databases)) if (failover_required(handle, mon->monitored_servers))
{ {
/** Other servers have died, initiate a failover to the last remaining server */ /** Other servers have died, initiate a failover to the last remaining server */
do_failover(handle, mon->databases); do_failover(handle, mon->monitored_servers);
} }
else else
{ {
@ -1857,7 +1854,7 @@ monitorMain(void *arg)
SERVER_IS_RELAY_SERVER(root_master->server))) SERVER_IS_RELAY_SERVER(root_master->server)))
{ {
set_master_heartbeat(handle, root_master); set_master_heartbeat(handle, root_master);
ptr = mon->databases; ptr = mon->monitored_servers;
while (ptr) while (ptr)
{ {
@ -1894,8 +1891,8 @@ monitorMain(void *arg)
* @param node_id The MySQL server_id to fetch * @param node_id The MySQL server_id to fetch
* @return The server with the required server_id * @return The server with the required server_id
*/ */
static MXS_MONITOR_SERVERS * static MXS_MONITORED_SERVER *
getServerByNodeId(MXS_MONITOR_SERVERS *ptr, long node_id) getServerByNodeId(MXS_MONITORED_SERVER *ptr, long node_id)
{ {
SERVER *current; SERVER *current;
while (ptr) while (ptr)
@ -1917,8 +1914,8 @@ getServerByNodeId(MXS_MONITOR_SERVERS *ptr, long node_id)
* @param node_id The MySQL server_id to fetch * @param node_id The MySQL server_id to fetch
* @return The slave server of this node_id * @return The slave server of this node_id
*/ */
static MXS_MONITOR_SERVERS * static MXS_MONITORED_SERVER *
getSlaveOfNodeId(MXS_MONITOR_SERVERS *ptr, long node_id) getSlaveOfNodeId(MXS_MONITORED_SERVER *ptr, long node_id)
{ {
SERVER *current; SERVER *current;
while (ptr) while (ptr)
@ -1941,7 +1938,7 @@ getSlaveOfNodeId(MXS_MONITOR_SERVERS *ptr, long node_id)
* @param handle The monitor handle * @param handle The monitor handle
* @param database The number database server * @param database The number database server
*/ */
static void set_master_heartbeat(MYSQL_MONITOR *handle, MXS_MONITOR_SERVERS *database) static void set_master_heartbeat(MYSQL_MONITOR *handle, MXS_MONITORED_SERVER *database)
{ {
unsigned long id = handle->id; unsigned long id = handle->id;
time_t heartbeat; time_t heartbeat;
@ -2075,7 +2072,7 @@ static void set_master_heartbeat(MYSQL_MONITOR *handle, MXS_MONITOR_SERVERS *dat
* @param handle The monitor handle * @param handle The monitor handle
* @param database The number database server * @param database The number database server
*/ */
static void set_slave_heartbeat(MXS_MONITOR* mon, MXS_MONITOR_SERVERS *database) static void set_slave_heartbeat(MXS_MONITOR* mon, MXS_MONITORED_SERVER *database)
{ {
MYSQL_MONITOR *handle = (MYSQL_MONITOR*) mon->handle; MYSQL_MONITOR *handle = (MYSQL_MONITOR*) mon->handle;
unsigned long id = handle->id; unsigned long id = handle->id;
@ -2186,17 +2183,17 @@ static void set_slave_heartbeat(MXS_MONITOR* mon, MXS_MONITOR_SERVERS *database)
* @return The server at root level with SERVER_MASTER bit * @return The server at root level with SERVER_MASTER bit
*/ */
static MXS_MONITOR_SERVERS *get_replication_tree(MXS_MONITOR *mon, int num_servers) static MXS_MONITORED_SERVER *get_replication_tree(MXS_MONITOR *mon, int num_servers)
{ {
MYSQL_MONITOR* handle = (MYSQL_MONITOR*) mon->handle; MYSQL_MONITOR* handle = (MYSQL_MONITOR*) mon->handle;
MXS_MONITOR_SERVERS *ptr; MXS_MONITORED_SERVER *ptr;
MXS_MONITOR_SERVERS *backend; MXS_MONITORED_SERVER *backend;
SERVER *current; SERVER *current;
int depth = 0; int depth = 0;
long node_id; long node_id;
int root_level; int root_level;
ptr = mon->databases; ptr = mon->monitored_servers;
root_level = num_servers; root_level = num_servers;
while (ptr) while (ptr)
@ -2216,8 +2213,8 @@ static MXS_MONITOR_SERVERS *get_replication_tree(MXS_MONITOR *mon, int num_serve
node_id = current->master_id; node_id = current->master_id;
if (node_id < 1) if (node_id < 1)
{ {
MXS_MONITOR_SERVERS *find_slave; MXS_MONITORED_SERVER *find_slave;
find_slave = getSlaveOfNodeId(mon->databases, current->node_id); find_slave = getSlaveOfNodeId(mon->monitored_servers, current->node_id);
if (find_slave == NULL) if (find_slave == NULL)
{ {
@ -2244,7 +2241,7 @@ static MXS_MONITOR_SERVERS *get_replication_tree(MXS_MONITOR *mon, int num_serve
root_level = current->depth; root_level = current->depth;
handle->master = ptr; handle->master = ptr;
} }
backend = getServerByNodeId(mon->databases, node_id); backend = getServerByNodeId(mon->monitored_servers, node_id);
if (backend) if (backend)
{ {
@ -2263,10 +2260,10 @@ static MXS_MONITOR_SERVERS *get_replication_tree(MXS_MONITOR *mon, int num_serve
} }
else else
{ {
MXS_MONITOR_SERVERS *master; MXS_MONITORED_SERVER *master;
current->depth = depth; current->depth = depth;
master = getServerByNodeId(mon->databases, current->master_id); master = getServerByNodeId(mon->monitored_servers, current->master_id);
if (master && master->server && master->server->node_id > 0) if (master && master->server && master->server->node_id > 0)
{ {
add_slave_to_master(master->server->slaves, sizeof(master->server->slaves), add_slave_to_master(master->server->slaves, sizeof(master->server->slaves),
@ -2367,7 +2364,7 @@ static int add_slave_to_master(long *slaves_list, int list_size, long node_id)
* @return False if the table is not replicated or an error occurred when querying * @return False if the table is not replicated or an error occurred when querying
* the server * the server
*/ */
bool check_replicate_ignore_table(MXS_MONITOR_SERVERS* database) bool check_replicate_ignore_table(MXS_MONITORED_SERVER* database)
{ {
MYSQL_RES *result; MYSQL_RES *result;
bool rval = true; bool rval = true;
@ -2411,7 +2408,7 @@ bool check_replicate_ignore_table(MXS_MONITOR_SERVERS* database)
* @return False if the table is not replicated or an error occurred when querying * @return False if the table is not replicated or an error occurred when querying
* the server * the server
*/ */
bool check_replicate_do_table(MXS_MONITOR_SERVERS* database) bool check_replicate_do_table(MXS_MONITORED_SERVER* database)
{ {
MYSQL_RES *result; MYSQL_RES *result;
bool rval = true; bool rval = true;
@ -2454,7 +2451,7 @@ bool check_replicate_do_table(MXS_MONITOR_SERVERS* database)
* @return False if the table is not replicated or an error occurred when trying to * @return False if the table is not replicated or an error occurred when trying to
* query the server. * query the server.
*/ */
bool check_replicate_wild_do_table(MXS_MONITOR_SERVERS* database) bool check_replicate_wild_do_table(MXS_MONITORED_SERVER* database)
{ {
MYSQL_RES *result; MYSQL_RES *result;
bool rval = true; bool rval = true;
@ -2501,7 +2498,7 @@ bool check_replicate_wild_do_table(MXS_MONITOR_SERVERS* database)
* @return False if the table is not replicated or an error occurred when trying to * @return False if the table is not replicated or an error occurred when trying to
* query the server. * query the server.
*/ */
bool check_replicate_wild_ignore_table(MXS_MONITOR_SERVERS* database) bool check_replicate_wild_ignore_table(MXS_MONITORED_SERVER* database)
{ {
MYSQL_RES *result; MYSQL_RES *result;
bool rval = true; bool rval = true;
@ -2548,7 +2545,7 @@ bool check_replicate_wild_ignore_table(MXS_MONITOR_SERVERS* database)
*/ */
void check_maxscale_schema_replication(MXS_MONITOR *monitor) void check_maxscale_schema_replication(MXS_MONITOR *monitor)
{ {
MXS_MONITOR_SERVERS* database = monitor->databases; MXS_MONITORED_SERVER* database = monitor->monitored_servers;
bool err = false; bool err = false;
while (database) while (database)

View File

@ -188,7 +188,7 @@ static json_t* diagnostics_json(const MXS_MONITOR *mon)
* @param database The database to probe * @param database The database to probe
*/ */
static void static void
monitorDatabase(MXS_MONITOR_SERVERS *database, char *defaultUser, char *defaultPasswd, MXS_MONITOR *mon) monitorDatabase(MXS_MONITORED_SERVER *database, char *defaultUser, char *defaultPasswd, MXS_MONITOR *mon)
{ {
MYSQL_ROW row; MYSQL_ROW row;
MYSQL_RES *result; MYSQL_RES *result;
@ -308,7 +308,7 @@ monitorMain(void *arg)
{ {
MYSQL_MONITOR *handle = (MYSQL_MONITOR*)arg; MYSQL_MONITOR *handle = (MYSQL_MONITOR*)arg;
MXS_MONITOR* mon = handle->monitor; MXS_MONITOR* mon = handle->monitor;
MXS_MONITOR_SERVERS *ptr; MXS_MONITORED_SERVER *ptr;
size_t nrounds = 0; size_t nrounds = 0;
if (mysql_thread_init()) if (mysql_thread_init())
@ -350,7 +350,7 @@ monitorMain(void *arg)
lock_monitor_servers(mon); lock_monitor_servers(mon);
servers_status_pending_to_current(mon); servers_status_pending_to_current(mon);
ptr = mon->databases; ptr = mon->monitored_servers;
while (ptr) while (ptr)
{ {
ptr->mon_prev_status = ptr->server->status; ptr->mon_prev_status = ptr->server->status;

View File

@ -497,15 +497,18 @@ int gw_read_client_event(DCB* dcb)
*/ */
case MXS_AUTH_STATE_MESSAGE_READ: case MXS_AUTH_STATE_MESSAGE_READ:
/* After this call read_buffer will point to freed data */ /* After this call read_buffer will point to freed data */
dcb_readq_set(dcb, read_buffer);
if (nbytes_read < 3 || (0 == max_bytes && nbytes_read < if (nbytes_read < 3 || (0 == max_bytes && nbytes_read <
(int)(MYSQL_GET_PAYLOAD_LEN((uint8_t *) GWBUF_DATA(read_buffer)) + 4)) || (int)(MYSQL_GET_PAYLOAD_LEN((uint8_t *) GWBUF_DATA(read_buffer)) + 4)) ||
(0 != max_bytes && nbytes_read < max_bytes)) (0 != max_bytes && nbytes_read < max_bytes))
{ {
dcb_readq_set(dcb, read_buffer);
return 0; return 0;
} }
read_buffer = modutil_get_next_MySQL_packet(&dcb->readq);
ss_dassert(read_buffer);
nbytes_read = gwbuf_length(read_buffer);
return_code = gw_read_do_authentication(dcb, read_buffer, nbytes_read); return_code = gw_read_do_authentication(dcb, read_buffer, nbytes_read);
break; break;
@ -713,6 +716,12 @@ gw_read_do_authentication(DCB *dcb, GWBUF *read_buffer, int nbytes_read)
ss_debug(bool check = ) mxs_worker_register_session(session); ss_debug(bool check = ) mxs_worker_register_session(session);
ss_dassert(check); ss_dassert(check);
mxs_mysql_send_ok(dcb, next_sequence, 0, NULL); mxs_mysql_send_ok(dcb, next_sequence, 0, NULL);
if (dcb->readq)
{
// The user has already send more data, process it
poll_fake_read_event(dcb);
}
} }
else else
{ {