MXS-2220 Add server version and type information struct
The old fields are still used.
This commit is contained in:
@ -98,6 +98,13 @@ public:
|
||||
return m_settings.persistpoolmax > 0;
|
||||
}
|
||||
|
||||
void set_version(uint64_t version_num, const std::string& version_str) override;
|
||||
|
||||
Version get_version() const override
|
||||
{
|
||||
return info.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a DCB from the persistent connection pool, if possible
|
||||
*
|
||||
@ -230,8 +237,36 @@ private:
|
||||
long persistpoolmax = 0; /**< Maximum size of persistent connections pool */
|
||||
long persistmaxtime = 0; /**< Maximum number of seconds connection can live */
|
||||
};
|
||||
Settings m_settings; /**< Server settings */
|
||||
|
||||
/**
|
||||
* Stores server version info. Encodes/decodes to/from the version number received from the server.
|
||||
* Also stores the version string and parses information from it. */
|
||||
class VersionInfo
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Read in and decode a numeric version from the server. Deduce server type from 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;
|
||||
|
||||
private:
|
||||
mutable std::mutex m_lock; /**< Protects against concurrent writing */
|
||||
Version m_version;
|
||||
server_type_t m_type = SERVER_TYPE_MARIADB;
|
||||
};
|
||||
|
||||
Settings m_settings; /**< Server settings */
|
||||
VersionInfo info; /**< Server version and type information */
|
||||
maxbase::EMAverage m_response_time; /**< Response time calculations for this server */
|
||||
};
|
||||
|
||||
|
||||
@ -124,6 +124,35 @@ private:
|
||||
MXS_CONFIG_PARAMETER* m_params = nullptr;
|
||||
};
|
||||
|
||||
/**
|
||||
* Write to char array by first zeroing any extra space. This reduces effects of concurrent reading.
|
||||
*
|
||||
* @param dest Destination buffer. The buffer is assumed to contains at least \0 at the end.
|
||||
* @param dest_size Maximum size of destination buffer, including terminating \0.
|
||||
* @param source Source string. A maximum of @c dest_size - 1 characters are copied.
|
||||
*/
|
||||
void careful_strcpy(char* dest, size_t dest_size, const std::string& source)
|
||||
{
|
||||
// The string may be accessed while we are updating it.
|
||||
// Take some precautions to ensure that the string cannot be completely garbled at any point.
|
||||
// Strictly speaking, this is not fool-proof as writes may not appear in order to the reader.
|
||||
size_t old_len = strlen(dest);
|
||||
size_t new_len = source.length();
|
||||
if (new_len >= dest_size)
|
||||
{
|
||||
new_len = dest_size - 1; // Need space for the \0.
|
||||
}
|
||||
|
||||
if (new_len < old_len)
|
||||
{
|
||||
// If the new string is shorter, zero out the excess data.
|
||||
memset(dest + new_len, 0, old_len - new_len);
|
||||
}
|
||||
|
||||
// No null-byte needs to be set. The array starts out as all zeros and the above memset adds
|
||||
// the necessary null, should the new string be shorter than the old.
|
||||
strncpy(dest, source.c_str(), new_len);
|
||||
}
|
||||
}
|
||||
|
||||
Server* Server::server_alloc(const char* name, MXS_CONFIG_PARAMETER* params)
|
||||
@ -999,6 +1028,11 @@ void server_set_version_string(SERVER* server, const char* version_string)
|
||||
strncpy(server->version_string, version_string, new_len);
|
||||
}
|
||||
|
||||
void Server::set_version(uint64_t version_num, const std::string& version_str)
|
||||
{
|
||||
info.set(version_num, version_str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the version of the server.
|
||||
*
|
||||
@ -1454,3 +1488,26 @@ bool Server::is_custom_parameter(const string& name) const
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Server::VersionInfo::set(uint64_t version, const std::string& version_str)
|
||||
{
|
||||
/* This only protects against concurrent writing which could result in garbled values. Reads are not
|
||||
* synchronized. Since writing is rare, this is an unlikely issue. Readers should be prepared to
|
||||
* sometimes get inconsistent values. */
|
||||
Guard lock(m_lock);
|
||||
|
||||
uint32_t major, minor, patch;
|
||||
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;
|
||||
}
|
||||
|
||||
Server::Version Server::VersionInfo::get() const
|
||||
{
|
||||
return m_version;
|
||||
}
|
||||
|
||||
@ -912,11 +912,10 @@ void MariaDBServer::update_server_version()
|
||||
/* Not a binlog server, check version number and supported features. */
|
||||
m_srv_type = server_type::NORMAL;
|
||||
m_capabilities = Capabilities();
|
||||
SERVER_VERSION decoded = {0, 0, 0};
|
||||
server_decode_version(server_get_version(srv), &decoded);
|
||||
auto major = decoded.major;
|
||||
auto minor = decoded.minor;
|
||||
auto patch = decoded.patch;
|
||||
SERVER::Version info = srv->get_version();
|
||||
auto major = info.major;
|
||||
auto minor = info.minor;
|
||||
auto patch = info.patch;
|
||||
// MariaDB/MySQL 5.5 is the oldest supported version. MySQL 6 and later are treated as 5.5.
|
||||
if ((major == 5 && minor >= 5) || major > 5)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user