MXS-2342 Run MariaDBMonitor diagnostics concurrent with the monitor loop
This fixes some situations where MaxAdmin/MaxCtrl would block and wait until a monitor operation or tick is complete. This also fixes a deadlock caused by calling monitor diagnostics inside a monitor script. Concurrency is enabled by adding one mutex per server object to protect array-like fields from concurrent reading/writing.
This commit is contained in:
@ -25,6 +25,7 @@ using std::string;
|
||||
using maxscale::string_printf;
|
||||
using maxbase::Duration;
|
||||
using maxbase::StopWatch;
|
||||
using Guard = std::lock_guard<std::mutex>;
|
||||
|
||||
MariaDBServer::MariaDBServer(MXS_MONITORED_SERVER* monitored_server, int config_index,
|
||||
bool assume_unique_hostnames, bool query_events)
|
||||
@ -386,6 +387,7 @@ bool MariaDBServer::do_show_slave_status(string* errmsg_out)
|
||||
|
||||
// Always write to m_slave_status. Even if the new status is equal by topology,
|
||||
// gtid:s etc may have changed.
|
||||
Guard guard(m_arraylock);
|
||||
m_slave_status = std::move(slave_status_new);
|
||||
return true;
|
||||
}
|
||||
@ -400,6 +402,8 @@ bool MariaDBServer::update_gtids(string* errmsg_out)
|
||||
auto result = execute_query(query, errmsg_out);
|
||||
if (result.get() != NULL)
|
||||
{
|
||||
Guard guard(m_arraylock);
|
||||
|
||||
rval = true;
|
||||
if (result->next_row())
|
||||
{
|
||||
@ -655,9 +659,12 @@ string MariaDBServer::diagnostics() const
|
||||
const char fmt_int64[] = "%-23s %" PRIi64 "\n";
|
||||
|
||||
string rval;
|
||||
rval.reserve(300); // Enough for most common ouput.
|
||||
|
||||
rval += string_printf(fmt_string, "Server:", name());
|
||||
rval += string_printf(fmt_int64, "Server ID:", m_server_id);
|
||||
rval += string_printf(fmt_string, "Read only:", (m_read_only ? "Yes" : "No"));
|
||||
Guard guard(m_arraylock);
|
||||
if (!m_gtid_current_pos.empty())
|
||||
{
|
||||
rval += string_printf(fmt_string, "Gtid current position:", m_gtid_current_pos.to_string().c_str());
|
||||
@ -686,6 +693,7 @@ json_t* MariaDBServer::to_json() const
|
||||
json_object_set_new(result, "server_id", json_integer(m_server_id));
|
||||
json_object_set_new(result, "read_only", json_boolean(m_read_only));
|
||||
|
||||
Guard guard(m_arraylock);
|
||||
json_object_set_new(result,
|
||||
"gtid_current_pos",
|
||||
m_gtid_current_pos.empty() ? json_null() :
|
||||
|
||||
Reference in New Issue
Block a user