From d1b098d3b0a170b375d55f841188ec142b99c005 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Mon, 17 Dec 2018 18:31:06 +0200 Subject: [PATCH] MXS-2200 Store server version string and type in internal class --- include/maxscale/server.hh | 21 ++++++++++++++++++++ server/core/internal/server.hh | 32 +++++++++++++++++++----------- server/core/server.cc | 36 +++++++++++++++++++++++++++------- 3 files changed, 71 insertions(+), 18 deletions(-) diff --git a/include/maxscale/server.hh b/include/maxscale/server.hh index 5e12aba17..49f866944 100644 --- a/include/maxscale/server.hh +++ b/include/maxscale/server.hh @@ -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() { diff --git a/server/core/internal/server.hh b/server/core/internal/server.hh index 607b09dd9..fcab860cf 100644 --- a/server/core/internal/server.hh +++ b/server/core/internal/server.hh @@ -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 * diff --git a/server/core/server.cc b/server/core/server.cc index 29a810f74..339f40e33 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -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; }