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