
From system.membership we can find out what server exist in the cluster while system.nodeinfo contains information about those servers. If a node goes down, it will disappear from system.nodeinfo, but not from system.membership. Consequently, we must start from system.membership and then fetch more information from system.nodeinfo. Incidentally, a query like SELECT ms.nid, ni.iface_ip FROM system.membership AS ms LEFT JOIN system.nodeinfo AS ni ON ms.nid=ni.nodeid; should provide all information in one go, but it seems that such joins are not supported on the system tables.
89 lines
1.8 KiB
C++
89 lines
1.8 KiB
C++
/*
|
|
* Copyright (c) 2018 MariaDB Corporation Ab
|
|
*
|
|
* Use of this software is governed by the Business Source License included
|
|
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
|
*
|
|
* Change Date: 2022-01-01
|
|
*
|
|
* On the date above, in accordance with the Business Source License, use
|
|
* of this software will be governed by version 2 or later of the General
|
|
* Public License.
|
|
*/
|
|
|
|
#include "clustrix.hh"
|
|
#include <maxbase/assert.h>
|
|
|
|
namespace
|
|
{
|
|
|
|
const char CN_NORMAL[] = "normal";
|
|
const char CN_QUORUM[] = "quorum";
|
|
const char CN_STATIC[] = "static";
|
|
const char CN_UNKNOWN[] = "unknown";
|
|
|
|
}
|
|
|
|
std::string Clustrix::to_string(Clustrix::Status status)
|
|
{
|
|
switch (status)
|
|
{
|
|
case Status::QUORUM:
|
|
return CN_QUORUM;
|
|
|
|
case Status::STATIC:
|
|
return CN_STATIC;
|
|
|
|
case Status::UNKNOWN:
|
|
return CN_UNKNOWN;
|
|
}
|
|
|
|
mxb_assert(!true);
|
|
return CN_UNKNOWN;
|
|
}
|
|
|
|
Clustrix::Status Clustrix::status_from_string(const std::string& status)
|
|
{
|
|
if (status == CN_QUORUM)
|
|
{
|
|
return Status::QUORUM;
|
|
}
|
|
else if (status == CN_STATIC)
|
|
{
|
|
return Status::STATIC;
|
|
}
|
|
else
|
|
{
|
|
MXB_WARNING("'%s' is an unknown status for a Clustrix node.", status.c_str());
|
|
return Status::UNKNOWN;
|
|
}
|
|
}
|
|
|
|
std::string Clustrix::to_string(Clustrix::SubState substate)
|
|
{
|
|
switch (substate)
|
|
{
|
|
case SubState::NORMAL:
|
|
return CN_NORMAL;
|
|
|
|
case SubState::UNKNOWN:
|
|
return CN_UNKNOWN;
|
|
}
|
|
|
|
mxb_assert(!true);
|
|
return CN_UNKNOWN;
|
|
}
|
|
|
|
Clustrix::SubState Clustrix::substate_from_string(const std::string& substate)
|
|
{
|
|
if (substate == CN_NORMAL)
|
|
{
|
|
return SubState::NORMAL;
|
|
}
|
|
else
|
|
{
|
|
MXB_WARNING("'%s' is an unknown sub-state for a Clustrix node.", substate.c_str());
|
|
return SubState::UNKNOWN;
|
|
}
|
|
}
|