MXS-2200 Store server version string and type in internal class
This commit is contained in:
parent
54ae7119cf
commit
d1b098d3b0
@ -73,6 +73,13 @@ public:
|
||||
static const int MAX_VERSION_LEN = 256;
|
||||
static const int RLAG_UNDEFINED = -1; // Default replication lag value
|
||||
|
||||
enum class Type
|
||||
{
|
||||
MARIADB,
|
||||
MYSQL,
|
||||
CLUSTRIX
|
||||
};
|
||||
|
||||
struct Version
|
||||
{
|
||||
uint32_t major = 0;
|
||||
@ -179,6 +186,20 @@ public:
|
||||
*/
|
||||
virtual Version get_version() const = 0;
|
||||
|
||||
/**
|
||||
* Get the type of the server.
|
||||
*
|
||||
* @return Server type
|
||||
*/
|
||||
virtual Type get_type() const = 0;
|
||||
|
||||
/**
|
||||
* Get version string.
|
||||
*
|
||||
* @return Version string
|
||||
*/
|
||||
virtual std::string get_version_string() const = 0;
|
||||
|
||||
protected:
|
||||
SERVER()
|
||||
{
|
||||
|
@ -102,7 +102,17 @@ public:
|
||||
|
||||
Version get_version() const override
|
||||
{
|
||||
return info.get();
|
||||
return info.version_num();
|
||||
}
|
||||
|
||||
Type get_type() const override
|
||||
{
|
||||
return info.type();
|
||||
}
|
||||
|
||||
std::string get_version_string() const override
|
||||
{
|
||||
return info.version_string();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -244,25 +254,24 @@ private:
|
||||
class VersionInfo
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Read in and decode a numeric version from the server. Deduce server type from string.
|
||||
* Reads in version data. Deduces server type from version string.
|
||||
*
|
||||
* @param version_num Version number from server
|
||||
* @param version_string Version string from server
|
||||
*/
|
||||
void set(uint64_t version_num, const std::string& version_string);
|
||||
|
||||
/**
|
||||
* Get version and type info.
|
||||
*
|
||||
* @return Version information
|
||||
*/
|
||||
Version get() const;
|
||||
Version version_num() const;
|
||||
Type type() const;
|
||||
std::string version_string() const;
|
||||
|
||||
private:
|
||||
mutable std::mutex m_lock; /**< Protects against concurrent writing */
|
||||
Version m_version;
|
||||
server_type_t m_type = SERVER_TYPE_MARIADB;
|
||||
mutable std::mutex m_lock; /**< Protects against concurrent writing */
|
||||
Version m_version_num; /**< Numeric version */
|
||||
Type m_type = Type::MARIADB; /**< Server type */
|
||||
char m_version_str[MAX_VERSION_LEN] = {'\0'}; /**< Server version string */
|
||||
};
|
||||
|
||||
Settings m_settings; /**< Server settings */
|
||||
@ -271,6 +280,7 @@ private:
|
||||
};
|
||||
|
||||
void server_free(Server* server);
|
||||
|
||||
/**
|
||||
* @brief Convert a server to JSON format
|
||||
*
|
||||
|
@ -1502,14 +1502,36 @@ void Server::VersionInfo::set(uint64_t version, const std::string& version_str)
|
||||
major = version / 10000;
|
||||
minor = (version - major * 10000) / 100;
|
||||
patch = version - major * 10000 - minor * 100;
|
||||
m_version.major = major;
|
||||
m_version.minor = minor;
|
||||
m_version.patch = patch;
|
||||
bool is_mariadb = (strcasestr(version_str.c_str(), "mariadb") != NULL);
|
||||
m_type = is_mariadb ? SERVER_TYPE_MARIADB : SERVER_TYPE_MYSQL;
|
||||
m_version_num.major = major;
|
||||
m_version_num.minor = minor;
|
||||
m_version_num.patch = patch;
|
||||
|
||||
careful_strcpy(m_version_str, MAX_VERSION_LEN, version_str);
|
||||
if (strcasestr(version_str.c_str(), "clustrix") != NULL)
|
||||
{
|
||||
m_type = Type::CLUSTRIX;
|
||||
}
|
||||
else if (strcasestr(version_str.c_str(), "mariadb") != NULL)
|
||||
{
|
||||
m_type = Type::MARIADB;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_type = Type::MYSQL;
|
||||
}
|
||||
}
|
||||
|
||||
Server::Version Server::VersionInfo::get() const
|
||||
Server::Version Server::VersionInfo::version_num() const
|
||||
{
|
||||
return m_version;
|
||||
return m_version_num;
|
||||
}
|
||||
|
||||
Server::Type Server::VersionInfo::type() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
std::string Server::VersionInfo::version_string() const
|
||||
{
|
||||
return m_version_str;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user