diff --git a/server/modules/monitor/mariadbmon/cluster_manipulation.cc b/server/modules/monitor/mariadbmon/cluster_manipulation.cc index c74dab420..f7dd887f1 100644 --- a/server/modules/monitor/mariadbmon/cluster_manipulation.cc +++ b/server/modules/monitor/mariadbmon/cluster_manipulation.cc @@ -877,8 +877,7 @@ void MariaDBMonitor::wait_cluster_stabilization(ClusterOperation& op, const Serv { // IO error on slave MXS_WARNING("%s cannot start replication because of IO thread error: '%s'.", - slave_conn->to_short_string(slave->name()).c_str(), - slave_conn->last_error.c_str()); + slave_conn->to_short_string().c_str(), slave_conn->last_error.c_str()); repl_fails.push_back(*iter); iter = unconfirmed.erase(iter); } @@ -886,8 +885,7 @@ void MariaDBMonitor::wait_cluster_stabilization(ClusterOperation& op, const Serv { // SQL error on slave MXS_WARNING("%s cannot start replication because of SQL thread error: '%s'.", - slave_conn->to_short_string(slave->name()).c_str(), - slave_conn->last_error.c_str()); + slave_conn->to_short_string().c_str(), slave_conn->last_error.c_str()); repl_fails.push_back(*iter); iter = unconfirmed.erase(iter); } @@ -1394,7 +1392,7 @@ void MariaDBMonitor::check_cluster_operations_support() { supported = false; auto reason = string_printf("%s is not using gtid-replication.", - slave_conn.to_short_string(server->name()).c_str()); + slave_conn.to_short_string().c_str()); printer.cat(all_reasons, reason); } } diff --git a/server/modules/monitor/mariadbmon/mariadbserver.cc b/server/modules/monitor/mariadbmon/mariadbserver.cc index 66d4bea4d..7597b6a7e 100644 --- a/server/modules/monitor/mariadbmon/mariadbserver.cc +++ b/server/modules/monitor/mariadbmon/mariadbserver.cc @@ -291,6 +291,7 @@ bool MariaDBServer::do_show_slave_status(string* errmsg_out) while (result->next_row()) { SlaveStatus new_row; + new_row.owning_server = name(); new_row.master_host = result->get_string(i_master_host); new_row.master_port = result->get_uint(i_master_port); string last_io_error = result->get_string(i_last_io_error); @@ -1916,8 +1917,7 @@ bool MariaDBServer::merge_slave_conns(ClusterOperation& op, const SlaveStatusArr if (conn_can_be_merged(slave_conn, &ignore_reason)) { MXS_WARNING("%s was ignored when promoting %s because %s", - slave_conn.to_short_string(op.demotion_target->name()).c_str(), name(), - ignore_reason.c_str()); + slave_conn.to_short_string().c_str(), name(), ignore_reason.c_str()); } else { @@ -1968,9 +1968,7 @@ bool MariaDBServer::copy_slave_conns(ClusterOperation& op, const SlaveStatusArra else { MXS_WARNING("%s was not copied to %s because %s", - slave_conn.to_short_string(replacement->name()).c_str(), - name(), - reason_not_copied.c_str()); + slave_conn.to_short_string().c_str(), name(), reason_not_copied.c_str()); } } return !start_slave_error; @@ -1988,30 +1986,32 @@ bool MariaDBServer::create_start_slave(ClusterOperation& op, const SlaveStatus& StopWatch timer; string error_msg; bool success = false; - string change_master = generate_change_master_cmd(op, slave_conn); + SlaveStatus new_conn = slave_conn; + new_conn.owning_server = name(); + string change_master = generate_change_master_cmd(op, new_conn); bool conn_created = execute_cmd_time_limit(change_master, op.time_remaining, &error_msg); op.time_remaining -= timer.restart(); if (conn_created) { - string start_slave = string_printf("START SLAVE '%s';", slave_conn.name.c_str()); + string start_slave = string_printf("START SLAVE '%s';", new_conn.name.c_str()); bool slave_started = execute_cmd_time_limit(start_slave, op.time_remaining, &error_msg); op.time_remaining -= timer.restart(); if (slave_started) { success = true; - MXS_NOTICE("%s created and started.", slave_conn.to_short_string(name()).c_str()); + MXS_NOTICE("%s created and started.", new_conn.to_short_string().c_str()); } else { MXS_ERROR("%s could not be started: %s", - slave_conn.to_short_string(name()).c_str(), error_msg.c_str()); + new_conn.to_short_string().c_str(), error_msg.c_str()); } } else { // TODO: This may currently print out passwords. MXS_ERROR("%s could not be created: %s", - slave_conn.to_short_string(name()).c_str(), error_msg.c_str()); + new_conn.to_short_string().c_str(), error_msg.c_str()); } return success; } @@ -2076,8 +2076,7 @@ bool MariaDBServer::redirect_existing_slave_conn(ClusterOperation& op) { PRINT_MXS_JSON_ERROR(op.error_out, "%s could not be started: %s", - modified_conn.to_short_string(name()).c_str(), - error_msg.c_str()); + modified_conn.to_short_string().c_str(), error_msg.c_str()); } } else @@ -2085,7 +2084,7 @@ bool MariaDBServer::redirect_existing_slave_conn(ClusterOperation& op) // TODO: This may currently print out passwords. PRINT_MXS_JSON_ERROR(op.error_out, "%s could not be redirected to [%s]:%i: %s", - old_conn->to_short_string(name()).c_str(), + old_conn->to_short_string().c_str(), modified_conn.master_host.c_str(), modified_conn.master_port, error_msg.c_str()); } diff --git a/server/modules/monitor/mariadbmon/server_utils.cc b/server/modules/monitor/mariadbmon/server_utils.cc index 577829d55..d35381ce7 100644 --- a/server/modules/monitor/mariadbmon/server_utils.cc +++ b/server/modules/monitor/mariadbmon/server_utils.cc @@ -49,17 +49,17 @@ string SlaveStatus::to_string() const return rval; } -string SlaveStatus::to_short_string(const string& owner) const +string SlaveStatus::to_short_string() const { if (name.empty()) { return string_printf("Slave connection from %s to [%s]:%i", - owner.c_str(), master_host.c_str(), master_port); + owning_server.c_str(), master_host.c_str(), master_port); } else { return string_printf("Slave connection '%s' from %s to [%s]:%i", - name.c_str(), owner.c_str(), master_host.c_str(), master_port); + name.c_str(), owning_server.c_str(), master_host.c_str(), master_port); } } diff --git a/server/modules/monitor/mariadbmon/server_utils.hh b/server/modules/monitor/mariadbmon/server_utils.hh index c96f57e4f..f924296d5 100644 --- a/server/modules/monitor/mariadbmon/server_utils.hh +++ b/server/modules/monitor/mariadbmon/server_utils.hh @@ -170,9 +170,10 @@ public: SLAVE_IO_NO, }; - bool seen_connected = false; /* Has this slave connection been seen connected, - * meaning that the master server id is correct? - **/ + 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 @@ -193,9 +194,16 @@ public: maxbase::Clock::time_point last_data_time = maxbase::Clock::now(); - std::string to_string() const; - json_t* to_json() const; - std::string to_short_string(const std::string& owner) const; + std::string to_string() const; + json_t* to_json() const; + + /** + * Create a short description in the form of "Slave connection from to " + * + * @return Description + */ + std::string to_short_string() const; + static slave_io_running_t slave_io_from_string(const std::string& str); static std::string slave_io_to_string(slave_io_running_t slave_io); bool should_be_copied(std::string* ignore_reason_out) const;