MXS-2220 Read server version using public methods
Version related fields have been removed from the public class.
This commit is contained in:
@ -118,9 +118,9 @@ mxs_mysql_name_kind_t mxs_mysql_name_to_pcre(char* pcre,
|
|||||||
* Get server information from connector, store it to server object. This does not query
|
* Get server information from connector, store it to server object. This does not query
|
||||||
* the server as the data has been read while connecting.
|
* the server as the data has been read while connecting.
|
||||||
*
|
*
|
||||||
* @param mysql MySQL handle from which information is read.
|
* @param dest Server object to write
|
||||||
* @param server Server object to write.
|
* @param source MySQL handle from which information is read
|
||||||
*/
|
*/
|
||||||
void mxs_mysql_update_server_version(MYSQL* mysql, SERVER* server);
|
void mxs_mysql_update_server_version(SERVER* dest, MYSQL* source);
|
||||||
|
|
||||||
MXS_END_DECLS
|
MXS_END_DECLS
|
||||||
|
@ -51,13 +51,6 @@ struct SERVER_STATS
|
|||||||
uint64_t packets = 0; /**< Number of packets routed to this server */
|
uint64_t packets = 0; /**< Number of packets routed to this server */
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Add clustrix etc types
|
|
||||||
enum server_type_t
|
|
||||||
{
|
|
||||||
SERVER_TYPE_MARIADB,
|
|
||||||
SERVER_TYPE_MYSQL
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SERVER structure defines a backend server. Each server has a name
|
* The SERVER structure defines a backend server. Each server has a name
|
||||||
* or IP address for the server, a port that the server listens on and
|
* or IP address for the server, a port that the server listens on and
|
||||||
@ -82,9 +75,10 @@ public:
|
|||||||
|
|
||||||
struct Version
|
struct Version
|
||||||
{
|
{
|
||||||
uint32_t major = 0;
|
uint64_t total = 0; /**< The version number received from server */
|
||||||
uint32_t minor = 0;
|
uint32_t major = 0; /**< Major version */
|
||||||
uint32_t patch = 0;
|
uint32_t minor = 0; /**< Minor version */
|
||||||
|
uint32_t patch = 0; /**< Patch version */
|
||||||
};
|
};
|
||||||
|
|
||||||
// Base settings
|
// Base settings
|
||||||
@ -118,10 +112,6 @@ public:
|
|||||||
uint64_t status = 0; /**< Current status flag bitmap */
|
uint64_t status = 0; /**< Current status flag bitmap */
|
||||||
int maint_request = MAINTENANCE_NO_CHANGE; /**< Is admin requesting Maintenance=ON/OFF on the
|
int maint_request = MAINTENANCE_NO_CHANGE; /**< Is admin requesting Maintenance=ON/OFF on the
|
||||||
* server? */
|
* server? */
|
||||||
char version_string[MAX_VERSION_LEN] = {'\0'}; /**< Server version string as given by backend */
|
|
||||||
uint64_t version = 0; /**< Server version numeric representation */
|
|
||||||
server_type_t server_type = SERVER_TYPE_MARIADB; /**< Server type (MariaDB or MySQL), deduced from
|
|
||||||
* version string */
|
|
||||||
|
|
||||||
long node_id = -1; /**< Node id, server_id for M/S or local_index for Galera */
|
long node_id = -1; /**< Node id, server_id for M/S or local_index for Galera */
|
||||||
long master_id = -1; /**< Master server id of this node */
|
long master_id = -1; /**< Master server id of this node */
|
||||||
@ -180,25 +170,25 @@ public:
|
|||||||
virtual void set_version(uint64_t version_num, const std::string& version_str) = 0;
|
virtual void set_version(uint64_t version_num, const std::string& version_str) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get numeric version information. TODO: Rename to "version" once cleanup is done.
|
* Get numeric version information.
|
||||||
*
|
*
|
||||||
* @return Major, minor and patch numbers
|
* @return Major, minor and patch numbers
|
||||||
*/
|
*/
|
||||||
virtual Version get_version() const = 0;
|
virtual Version version() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the type of the server.
|
* Get the type of the server.
|
||||||
*
|
*
|
||||||
* @return Server type
|
* @return Server type
|
||||||
*/
|
*/
|
||||||
virtual Type get_type() const = 0;
|
virtual Type type() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get version string.
|
* Get version string.
|
||||||
*
|
*
|
||||||
* @return Version string
|
* @return Version string
|
||||||
*/
|
*/
|
||||||
virtual std::string get_version_string() const = 0;
|
virtual std::string version_string() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SERVER()
|
SERVER()
|
||||||
@ -461,9 +451,6 @@ extern void server_update_address(SERVER* server, const char* address);
|
|||||||
extern void server_update_port(SERVER* server, unsigned short port);
|
extern void server_update_port(SERVER* server, unsigned short port);
|
||||||
extern void server_update_extra_port(SERVER* server, unsigned short port);
|
extern void server_update_extra_port(SERVER* server, unsigned short port);
|
||||||
extern uint64_t server_map_status(const char* str);
|
extern uint64_t server_map_status(const char* str);
|
||||||
extern void server_set_version_string(SERVER* server, const char* version_string);
|
|
||||||
extern void server_set_version(SERVER* server, const char* version_string, uint64_t version);
|
|
||||||
extern uint64_t server_get_version(const SERVER* server);
|
|
||||||
|
|
||||||
extern void printServer(const SERVER*);
|
extern void printServer(const SERVER*);
|
||||||
extern void printAllServers();
|
extern void printAllServers();
|
||||||
|
@ -100,17 +100,17 @@ public:
|
|||||||
|
|
||||||
void set_version(uint64_t version_num, const std::string& version_str) override;
|
void set_version(uint64_t version_num, const std::string& version_str) override;
|
||||||
|
|
||||||
Version get_version() const override
|
Version version() const override
|
||||||
{
|
{
|
||||||
return info.version_num();
|
return info.version_num();
|
||||||
}
|
}
|
||||||
|
|
||||||
Type get_type() const override
|
Type type() const override
|
||||||
{
|
{
|
||||||
return info.type();
|
return info.type();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_version_string() const override
|
std::string version_string() const override
|
||||||
{
|
{
|
||||||
return info.version_string();
|
return info.version_string();
|
||||||
}
|
}
|
||||||
|
@ -2750,11 +2750,11 @@ void MonitorInstance::update_disk_space_status(MXS_MONITORED_SERVER* pMs)
|
|||||||
pMs->disk_space_checked = -1;
|
pMs->disk_space_checked = -1;
|
||||||
|
|
||||||
MXS_ERROR("Disk space cannot be checked for %s at %s, because either the "
|
MXS_ERROR("Disk space cannot be checked for %s at %s, because either the "
|
||||||
"version %s is too old, or the DISKS information schema plugin "
|
"version (%s) is too old, or the DISKS information schema plugin "
|
||||||
"has not been installed. Disk space checking has been disabled.",
|
"has not been installed. Disk space checking has been disabled.",
|
||||||
pServer->name,
|
pServer->name,
|
||||||
pServer->address,
|
pServer->address,
|
||||||
pServer->version_string);
|
pServer->version_string().c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -350,11 +350,11 @@ mxs_mysql_name_kind_t mxs_mysql_name_to_pcre(char* pcre,
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mxs_mysql_update_server_version(MYSQL* mysql, SERVER* server)
|
void mxs_mysql_update_server_version(SERVER* dest, MYSQL* source)
|
||||||
{
|
{
|
||||||
// This function should only be called for a live connection.
|
// This function should only be called for a live connection.
|
||||||
const char* version_string = mysql_get_server_info(mysql);
|
const char* version_string = mysql_get_server_info(source);
|
||||||
unsigned long version_num = mysql_get_server_version(mysql);
|
unsigned long version_num = mysql_get_server_version(source);
|
||||||
mxb_assert(version_string != NULL && version_num != 0);
|
mxb_assert(version_string != NULL && version_num != 0);
|
||||||
server_set_version(server, version_string, version_num);
|
dest->set_version(version_num, version_string);
|
||||||
}
|
}
|
||||||
|
@ -534,7 +534,7 @@ void Server::print_to_dcb(DCB* dcb) const
|
|||||||
dcb_printf(dcb, "\tStatus: %s\n", stat.c_str());
|
dcb_printf(dcb, "\tStatus: %s\n", stat.c_str());
|
||||||
dcb_printf(dcb, "\tProtocol: %s\n", server->protocol);
|
dcb_printf(dcb, "\tProtocol: %s\n", server->protocol);
|
||||||
dcb_printf(dcb, "\tPort: %d\n", server->port);
|
dcb_printf(dcb, "\tPort: %d\n", server->port);
|
||||||
dcb_printf(dcb, "\tServer Version: %s\n", server->version_string);
|
dcb_printf(dcb, "\tServer Version: %s\n", server->version_string().c_str());
|
||||||
dcb_printf(dcb, "\tNode Id: %ld\n", server->node_id);
|
dcb_printf(dcb, "\tNode Id: %ld\n", server->node_id);
|
||||||
dcb_printf(dcb, "\tMaster Id: %ld\n", server->master_id);
|
dcb_printf(dcb, "\tMaster Id: %ld\n", server->master_id);
|
||||||
dcb_printf(dcb,
|
dcb_printf(dcb,
|
||||||
@ -998,64 +998,11 @@ uint64_t server_map_status(const char* str)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the version string of the server.
|
|
||||||
*
|
|
||||||
* @param server Server to update
|
|
||||||
* @param version_string Version string
|
|
||||||
*/
|
|
||||||
void server_set_version_string(SERVER* server, const char* version_string)
|
|
||||||
{
|
|
||||||
// Possible data race. 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(server->version_string);
|
|
||||||
size_t new_len = strlen(version_string);
|
|
||||||
if (new_len >= SERVER::MAX_VERSION_LEN)
|
|
||||||
{
|
|
||||||
new_len = SERVER::MAX_VERSION_LEN - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (new_len < old_len)
|
|
||||||
{
|
|
||||||
// If the new string is shorter, we start by nulling out the
|
|
||||||
// excess data.
|
|
||||||
memset(server->version_string + 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(server->version_string, version_string, new_len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Server::set_version(uint64_t version_num, const std::string& version_str)
|
void Server::set_version(uint64_t version_num, const std::string& version_str)
|
||||||
{
|
{
|
||||||
info.set(version_num, version_str);
|
info.set(version_num, version_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the version of the server.
|
|
||||||
*
|
|
||||||
* @param server Server to update
|
|
||||||
* @param version_string Human readable version string.
|
|
||||||
* @param version Version encoded as MariaDB encodes the version, i.e.:
|
|
||||||
* version = major * 10000 + minor * 100 + patch
|
|
||||||
*/
|
|
||||||
void server_set_version(SERVER* srv, const char* version_string, uint64_t version)
|
|
||||||
{
|
|
||||||
Server* server = static_cast<Server*>(srv);
|
|
||||||
server_set_version_string(server, version_string);
|
|
||||||
atomic_store_uint64(&server->version, version);
|
|
||||||
bool is_mariadb = (strcasestr(version_string, "mariadb") != NULL);
|
|
||||||
server->server_type = is_mariadb ? SERVER_TYPE_MARIADB : SERVER_TYPE_MYSQL;
|
|
||||||
server->set_version(version, version_string);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t server_get_version(const SERVER* server)
|
|
||||||
{
|
|
||||||
return atomic_load_uint64(&server->version);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a server configuration at the location pointed by @c filename
|
* Creates a server configuration at the location pointed by @c filename
|
||||||
* TODO: Move to member
|
* TODO: Move to member
|
||||||
@ -1292,7 +1239,7 @@ json_t* Server::server_json_attributes(const Server* server)
|
|||||||
string stat = mxs::server_status(server);
|
string stat = mxs::server_status(server);
|
||||||
json_object_set_new(attr, CN_STATE, json_string(stat.c_str()));
|
json_object_set_new(attr, CN_STATE, json_string(stat.c_str()));
|
||||||
|
|
||||||
json_object_set_new(attr, CN_VERSION_STRING, json_string(server->version_string));
|
json_object_set_new(attr, CN_VERSION_STRING, json_string(server->version_string().c_str()));
|
||||||
|
|
||||||
json_object_set_new(attr, "node_id", json_integer(server->node_id));
|
json_object_set_new(attr, "node_id", json_integer(server->node_id));
|
||||||
json_object_set_new(attr, "master_id", json_integer(server->master_id));
|
json_object_set_new(attr, "master_id", json_integer(server->master_id));
|
||||||
@ -1498,10 +1445,10 @@ void Server::VersionInfo::set(uint64_t version, const std::string& version_str)
|
|||||||
* sometimes get inconsistent values. */
|
* sometimes get inconsistent values. */
|
||||||
Guard lock(m_lock);
|
Guard lock(m_lock);
|
||||||
|
|
||||||
uint32_t major, minor, patch;
|
mxb::atomic::store(&m_version_num.total, version, mxb::atomic::RELAXED);
|
||||||
major = version / 10000;
|
uint32_t major = version / 10000;
|
||||||
minor = (version - major * 10000) / 100;
|
uint32_t minor = (version - major * 10000) / 100;
|
||||||
patch = version - major * 10000 - minor * 100;
|
uint32_t patch = version - major * 10000 - minor * 100;
|
||||||
m_version_num.major = major;
|
m_version_num.major = major;
|
||||||
m_version_num.minor = minor;
|
m_version_num.minor = minor;
|
||||||
m_version_num.patch = patch;
|
m_version_num.patch = patch;
|
||||||
|
@ -1852,7 +1852,7 @@ uint64_t service_get_version(const SERVICE* svc, service_version_which_t which)
|
|||||||
|
|
||||||
if (sref)
|
if (sref)
|
||||||
{
|
{
|
||||||
version = server_get_version(sref->server);
|
version = sref->server->version().total;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1881,7 +1881,7 @@ uint64_t service_get_version(const SERVICE* svc, service_version_which_t which)
|
|||||||
++n;
|
++n;
|
||||||
|
|
||||||
SERVER* s = sref->server;
|
SERVER* s = sref->server;
|
||||||
uint64_t server_version = server_get_version(s);
|
uint64_t server_version = s->version().total;
|
||||||
|
|
||||||
if (which == SERVICE_VERSION_MIN)
|
if (which == SERVICE_VERSION_MIN)
|
||||||
{
|
{
|
||||||
|
@ -37,12 +37,6 @@
|
|||||||
/** Don't include the root user */
|
/** Don't include the root user */
|
||||||
#define USERS_QUERY_NO_ROOT " AND user.user NOT IN ('root')"
|
#define USERS_QUERY_NO_ROOT " AND user.user NOT IN ('root')"
|
||||||
|
|
||||||
/** Normal password column name */
|
|
||||||
#define MYSQL_PASSWORD "password"
|
|
||||||
|
|
||||||
/** MySQL 5.7 password column name */
|
|
||||||
#define MYSQL57_PASSWORD "authentication_string"
|
|
||||||
|
|
||||||
// Query used with 10.0 or older
|
// Query used with 10.0 or older
|
||||||
const char* mariadb_users_query_format =
|
const char* mariadb_users_query_format =
|
||||||
"SELECT u.user, u.host, d.db, u.select_priv, u.%s "
|
"SELECT u.user, u.host, d.db, u.select_priv, u.%s "
|
||||||
@ -170,10 +164,27 @@ static char* get_mariadb_101_users_query(bool include_root)
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* get_mariadb_users_query(bool include_root, const char* server_version)
|
/**
|
||||||
|
* Return the column name of the password hash in the mysql.user table.
|
||||||
|
*
|
||||||
|
* @param version Server version
|
||||||
|
* @return Column name
|
||||||
|
*/
|
||||||
|
static const char* get_password_column_name(const SERVER::Version& version)
|
||||||
{
|
{
|
||||||
const char* password = strstr(server_version, "5.7.") || strstr(server_version, "8.0.") ?
|
const char* rval = "password"; // Usual result, used in MariaDB.
|
||||||
MYSQL57_PASSWORD : MYSQL_PASSWORD;
|
auto major = version.major;
|
||||||
|
auto minor = version.minor;
|
||||||
|
if ((major == 5 && minor == 7) || (major == 8 && minor == 0))
|
||||||
|
{
|
||||||
|
rval = "authentication_string";
|
||||||
|
}
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char* get_mariadb_users_query(bool include_root, const SERVER::Version& version)
|
||||||
|
{
|
||||||
|
const char* password = get_password_column_name(version);
|
||||||
const char* with_root = include_root ? "" : " AND u.user NOT IN ('root')";
|
const char* with_root = include_root ? "" : " AND u.user NOT IN ('root')";
|
||||||
|
|
||||||
size_t n_bytes = snprintf(NULL, 0, mariadb_users_query_format, password, with_root, password, with_root);
|
size_t n_bytes = snprintf(NULL, 0, mariadb_users_query_format, password, with_root, password, with_root);
|
||||||
@ -196,16 +207,14 @@ static char* get_clustrix_users_query(bool include_root)
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char* get_users_query(const char* server_version, int version, bool include_root, server_category_t category)
|
static char* get_users_query(const SERVER::Version& version, bool include_root, server_category_t category)
|
||||||
{
|
{
|
||||||
char* rval = nullptr;
|
char* rval = nullptr;
|
||||||
|
|
||||||
switch (category)
|
switch (category)
|
||||||
{
|
{
|
||||||
case SERVER_ROLES:
|
case SERVER_ROLES:
|
||||||
rval =
|
rval = version.total >= 100202 ? get_mariadb_102_users_query(include_root) :
|
||||||
version >= 100202 ?
|
|
||||||
get_mariadb_102_users_query(include_root) :
|
|
||||||
get_mariadb_101_users_query(include_root);
|
get_mariadb_101_users_query(include_root);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -215,7 +224,7 @@ static char* get_users_query(const char* server_version, int version, bool inclu
|
|||||||
|
|
||||||
case SERVER_NO_ROLES:
|
case SERVER_NO_ROLES:
|
||||||
// Either an older MariaDB version or a MySQL variant, use the legacy query
|
// Either an older MariaDB version or a MySQL variant, use the legacy query
|
||||||
rval = get_mariadb_users_query(include_root, server_version);
|
rval = get_mariadb_users_query(include_root, version);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -764,8 +773,8 @@ static bool check_default_table_permissions(MYSQL* mysql,
|
|||||||
bool rval = true;
|
bool rval = true;
|
||||||
|
|
||||||
const char* format = "SELECT user, host, %s, Select_priv FROM mysql.user limit 1";
|
const char* format = "SELECT user, host, %s, Select_priv FROM mysql.user limit 1";
|
||||||
const char* query_pw = strstr(server->version_string, "5.7.") ?
|
const char* query_pw = get_password_column_name(server->version());
|
||||||
MYSQL57_PASSWORD : MYSQL_PASSWORD;
|
|
||||||
char query[strlen(format) + strlen(query_pw) + 1];
|
char query[strlen(format) + strlen(query_pw) + 1];
|
||||||
sprintf(query, format, query_pw);
|
sprintf(query, format, query_pw);
|
||||||
|
|
||||||
@ -890,15 +899,13 @@ static bool check_server_permissions(SERVICE* service,
|
|||||||
mysql_get_character_set_info(mysql, &cs_info);
|
mysql_get_character_set_info(mysql, &cs_info);
|
||||||
server->charset = cs_info.number;
|
server->charset = cs_info.number;
|
||||||
|
|
||||||
if (server->version_string[0] == 0)
|
if (server->version().total == 0)
|
||||||
{
|
{
|
||||||
mxs_mysql_update_server_version(mysql, server);
|
mxs_mysql_update_server_version(server, mysql);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_clustrix = (strcasestr(server->version_string, "clustrix") != nullptr);
|
|
||||||
|
|
||||||
bool rval = true;
|
bool rval = true;
|
||||||
if (is_clustrix)
|
if (server->type() == SERVER::Type::CLUSTRIX)
|
||||||
{
|
{
|
||||||
rval = check_clustrix_table_permissions(mysql, service, server, user);
|
rval = check_clustrix_table_permissions(mysql, service, server, user);
|
||||||
}
|
}
|
||||||
@ -992,8 +999,7 @@ static bool get_hostname(DCB* dcb, char* client_hostname, size_t size)
|
|||||||
static bool roles_are_available(MYSQL* conn, SERVICE* service, SERVER* server)
|
static bool roles_are_available(MYSQL* conn, SERVICE* service, SERVER* server)
|
||||||
{
|
{
|
||||||
bool rval = false;
|
bool rval = false;
|
||||||
|
if (server->version().total >= 100101)
|
||||||
if (server->version >= 100101)
|
|
||||||
{
|
{
|
||||||
static bool log_missing_privs = true;
|
static bool log_missing_privs = true;
|
||||||
|
|
||||||
@ -1097,18 +1103,20 @@ bool query_and_process_users(const char* query,
|
|||||||
|
|
||||||
int get_users_from_server(MYSQL* con, SERVER_REF* server_ref, SERVICE* service, Listener* listener)
|
int get_users_from_server(MYSQL* con, SERVER_REF* server_ref, SERVICE* service, Listener* listener)
|
||||||
{
|
{
|
||||||
if (server_ref->server->version_string[0] == 0)
|
SERVER* server = server_ref->server;
|
||||||
|
auto server_version = server->version();
|
||||||
|
if (server_version.total == 0) // No monitor or the monitor hasn't ran yet.
|
||||||
{
|
{
|
||||||
mxs_mysql_update_server_version(con, server_ref->server);
|
mxs_mysql_update_server_version(server, con);
|
||||||
|
server_version = server->version();
|
||||||
}
|
}
|
||||||
|
|
||||||
server_category_t category;
|
server_category_t category;
|
||||||
|
if (server->type() == SERVER::Type::CLUSTRIX)
|
||||||
if (strstr(server_ref->server->version_string, "clustrix") != nullptr)
|
|
||||||
{
|
{
|
||||||
category = SERVER_CLUSTRIX;
|
category = SERVER_CLUSTRIX;
|
||||||
}
|
}
|
||||||
else if (roles_are_available(con, service, server_ref->server))
|
else if (roles_are_available(con, service, server))
|
||||||
{
|
{
|
||||||
category = SERVER_ROLES;
|
category = SERVER_ROLES;
|
||||||
}
|
}
|
||||||
@ -1117,10 +1125,7 @@ int get_users_from_server(MYSQL* con, SERVER_REF* server_ref, SERVICE* service,
|
|||||||
category = SERVER_NO_ROLES;
|
category = SERVER_NO_ROLES;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* query = get_users_query(server_ref->server->version_string,
|
char* query = get_users_query(server_version, service->enable_root, category);
|
||||||
server_ref->server->version,
|
|
||||||
service->enable_root,
|
|
||||||
category);
|
|
||||||
|
|
||||||
MYSQL_AUTH* instance = (MYSQL_AUTH*)listener->auth_instance();
|
MYSQL_AUTH* instance = (MYSQL_AUTH*)listener->auth_instance();
|
||||||
sqlite3* handle = get_handle(instance);
|
sqlite3* handle = get_handle(instance);
|
||||||
@ -1128,20 +1133,20 @@ int get_users_from_server(MYSQL* con, SERVER_REF* server_ref, SERVICE* service,
|
|||||||
|
|
||||||
bool rv = query_and_process_users(query, con, handle, service, &users, category);
|
bool rv = query_and_process_users(query, con, handle, service, &users, category);
|
||||||
|
|
||||||
if (!rv && have_mdev13453_problem(con, server_ref->server))
|
if (!rv && have_mdev13453_problem(con, server))
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Try to work around MDEV-13453 by using a query without CTEs. Masquerading as
|
* Try to work around MDEV-13453 by using a query without CTEs. Masquerading as
|
||||||
* a 10.1.10 server makes sure CTEs aren't used.
|
* a 10.1.10 server makes sure CTEs aren't used.
|
||||||
*/
|
*/
|
||||||
MXS_FREE(query);
|
MXS_FREE(query);
|
||||||
query = get_users_query(server_ref->server->version_string, 100110, service->enable_root, SERVER_ROLES);
|
query = get_users_query(server_version, service->enable_root, SERVER_ROLES);
|
||||||
rv = query_and_process_users(query, con, handle, service, &users, SERVER_ROLES);
|
rv = query_and_process_users(query, con, handle, service, &users, SERVER_ROLES);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rv)
|
if (!rv)
|
||||||
{
|
{
|
||||||
MXS_ERROR("Failed to load users from server '%s': %s", server_ref->server->name, mysql_error(con));
|
MXS_ERROR("Failed to load users from server '%s': %s", server->name, mysql_error(con));
|
||||||
}
|
}
|
||||||
|
|
||||||
MXS_FREE(query);
|
MXS_FREE(query);
|
||||||
|
@ -127,11 +127,10 @@ void GaleraMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
{
|
{
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
MYSQL_RES* result;
|
MYSQL_RES* result;
|
||||||
char* server_string;
|
|
||||||
|
|
||||||
/* get server version string */
|
/* get server version string */
|
||||||
mxs_mysql_update_server_version(monitored_server->con, monitored_server->server);
|
mxs_mysql_update_server_version(monitored_server->server, monitored_server->con);
|
||||||
server_string = monitored_server->server->version_string;
|
auto server_string = monitored_server->server->version_string();
|
||||||
|
|
||||||
/* Check if the the Galera FSM shows this node is joined to the cluster */
|
/* Check if the the Galera FSM shows this node is joined to the cluster */
|
||||||
const char* cluster_member =
|
const char* cluster_member =
|
||||||
@ -150,7 +149,7 @@ void GaleraMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
MXS_ERROR("Unexpected result for \"%s\". "
|
MXS_ERROR("Unexpected result for \"%s\". "
|
||||||
"Expected 2 columns. MySQL Version: %s",
|
"Expected 2 columns. MySQL Version: %s",
|
||||||
cluster_member,
|
cluster_member,
|
||||||
server_string);
|
server_string.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GaleraNode info = {};
|
GaleraNode info = {};
|
||||||
@ -193,7 +192,7 @@ void GaleraMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
}
|
}
|
||||||
/* Check if the node is a donor and is using xtrabackup, in this case it can stay alive */
|
/* Check if the node is a donor and is using xtrabackup, in this case it can stay alive */
|
||||||
else if (strcmp(row[1], "2") == 0 && m_availableWhenDonor == 1
|
else if (strcmp(row[1], "2") == 0 && m_availableWhenDonor == 1
|
||||||
&& using_xtrabackup(monitored_server, server_string))
|
&& using_xtrabackup(monitored_server, server_string.c_str()))
|
||||||
{
|
{
|
||||||
info.joined = 1;
|
info.joined = 1;
|
||||||
}
|
}
|
||||||
|
@ -1494,7 +1494,8 @@ void MariaDBMonitor::check_cluster_operations_support()
|
|||||||
supported = false;
|
supported = false;
|
||||||
auto reason = string_printf("The version of '%s' (%s) is not supported. Failover/switchover "
|
auto reason = string_printf("The version of '%s' (%s) is not supported. Failover/switchover "
|
||||||
"requires MariaDB 10.0.2 or later.",
|
"requires MariaDB 10.0.2 or later.",
|
||||||
server->name(), server->m_server_base->server->version_string);
|
server->name(),
|
||||||
|
server->m_server_base->server->version_string().c_str());
|
||||||
printer.cat(all_reasons, reason);
|
printer.cat(all_reasons, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -887,20 +887,18 @@ bool MariaDBServer::update_slave_status(string* errmsg_out)
|
|||||||
|
|
||||||
void MariaDBServer::update_server_version()
|
void MariaDBServer::update_server_version()
|
||||||
{
|
{
|
||||||
m_srv_type = server_type::UNKNOWN;
|
|
||||||
auto conn = m_server_base->con;
|
auto conn = m_server_base->con;
|
||||||
auto srv = m_server_base->server;
|
auto srv = m_server_base->server;
|
||||||
|
mxs_mysql_update_server_version(srv, conn);
|
||||||
|
|
||||||
/* Get server version string, also get/set numeric representation. This function does not query the
|
m_srv_type = server_type::UNKNOWN; // TODO: Use type information in SERVER directly
|
||||||
* server, since the data was obtained when connecting. */
|
auto server_type = srv->type();
|
||||||
mxs_mysql_update_server_version(conn, srv);
|
|
||||||
|
|
||||||
// Check whether this server is a MaxScale Binlog Server.
|
|
||||||
MYSQL_RES* result;
|
MYSQL_RES* result;
|
||||||
if (strcasestr(srv->version_string, "clustrix") != nullptr)
|
if (server_type == SERVER::Type::CLUSTRIX)
|
||||||
{
|
{
|
||||||
m_srv_type = server_type::CLUSTRIX;
|
m_srv_type = server_type::CLUSTRIX;
|
||||||
}
|
}
|
||||||
|
// Check whether this server is a MaxScale Binlog Server.
|
||||||
else if (mxs_mysql_query(conn, "SELECT @@maxscale_version") == 0
|
else if (mxs_mysql_query(conn, "SELECT @@maxscale_version") == 0
|
||||||
&& (result = mysql_store_result(conn)) != NULL)
|
&& (result = mysql_store_result(conn)) != NULL)
|
||||||
{
|
{
|
||||||
@ -912,7 +910,7 @@ void MariaDBServer::update_server_version()
|
|||||||
/* Not a binlog server, check version number and supported features. */
|
/* Not a binlog server, check version number and supported features. */
|
||||||
m_srv_type = server_type::NORMAL;
|
m_srv_type = server_type::NORMAL;
|
||||||
m_capabilities = Capabilities();
|
m_capabilities = Capabilities();
|
||||||
SERVER::Version info = srv->get_version();
|
SERVER::Version info = srv->version();
|
||||||
auto major = info.major;
|
auto major = info.major;
|
||||||
auto minor = info.minor;
|
auto minor = info.minor;
|
||||||
auto patch = info.patch;
|
auto patch = info.patch;
|
||||||
@ -921,7 +919,7 @@ void MariaDBServer::update_server_version()
|
|||||||
{
|
{
|
||||||
m_capabilities.basic_support = true;
|
m_capabilities.basic_support = true;
|
||||||
// For more specific features, at least MariaDB 10.X is needed.
|
// For more specific features, at least MariaDB 10.X is needed.
|
||||||
if (srv->server_type == SERVER_TYPE_MARIADB && major >= 10)
|
if (server_type == SERVER::Type::MARIADB && major >= 10)
|
||||||
{
|
{
|
||||||
// 10.0.2 or 10.1.X or greater than 10
|
// 10.0.2 or 10.1.X or greater than 10
|
||||||
if (((minor == 0 && patch >= 2) || minor >= 1) || major > 10)
|
if (((minor == 0 && patch >= 2) || minor >= 1) || major > 10)
|
||||||
@ -938,7 +936,7 @@ void MariaDBServer::update_server_version()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
MXS_ERROR("MariaDB/MySQL version of '%s' (%s) is less than 5.5, which is not supported. "
|
MXS_ERROR("MariaDB/MySQL version of '%s' (%s) is less than 5.5, which is not supported. "
|
||||||
"The server is ignored by the monitor.", name(), srv->version_string);
|
"The server is ignored by the monitor.", name(), srv->version_string().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,15 +81,13 @@ void MMMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
int isslave = 0;
|
int isslave = 0;
|
||||||
int ismaster = 0;
|
int ismaster = 0;
|
||||||
unsigned long int server_version = 0;
|
unsigned long int server_version = 0;
|
||||||
char* server_string;
|
|
||||||
|
|
||||||
|
|
||||||
/* get server version from current server */
|
/* get server version from current server */
|
||||||
server_version = mysql_get_server_version(monitored_server->con);
|
server_version = mysql_get_server_version(monitored_server->con);
|
||||||
|
|
||||||
/* get server version string */
|
/* get server version string */
|
||||||
mxs_mysql_update_server_version(monitored_server->con, monitored_server->server);
|
mxs_mysql_update_server_version(monitored_server->server, monitored_server->con);
|
||||||
server_string = monitored_server->server->version_string;
|
auto server_string = monitored_server->server->version_string();
|
||||||
|
|
||||||
/* get server_id form current node */
|
/* get server_id form current node */
|
||||||
if (mxs_mysql_query(monitored_server->con, "SELECT @@server_id") == 0
|
if (mxs_mysql_query(monitored_server->con, "SELECT @@server_id") == 0
|
||||||
@ -102,7 +100,7 @@ void MMMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
mysql_free_result(result);
|
mysql_free_result(result);
|
||||||
MXS_ERROR("Unexpected result for 'SELECT @@server_id'. Expected 1 column."
|
MXS_ERROR("Unexpected result for 'SELECT @@server_id'. Expected 1 column."
|
||||||
" MySQL Version: %s",
|
" MySQL Version: %s",
|
||||||
server_string);
|
server_string.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +139,7 @@ void MMMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
mysql_free_result(result);
|
mysql_free_result(result);
|
||||||
MXS_ERROR("\"SHOW ALL SLAVES STATUS\" returned less than the expected"
|
MXS_ERROR("\"SHOW ALL SLAVES STATUS\" returned less than the expected"
|
||||||
" amount of columns. Expected 42 columns MySQL Version: %s",
|
" amount of columns. Expected 42 columns MySQL Version: %s",
|
||||||
server_string);
|
server_string.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,7 +209,7 @@ void MMMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
"replication tree cannot be resolved for server %s."
|
"replication tree cannot be resolved for server %s."
|
||||||
" MySQL Version: %s",
|
" MySQL Version: %s",
|
||||||
monitored_server->server->name,
|
monitored_server->server->name,
|
||||||
server_string);
|
server_string.c_str());
|
||||||
monitored_server->log_version_err = false;
|
monitored_server->log_version_err = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -220,7 +218,7 @@ void MMMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
MXS_ERROR("\"SHOW SLAVE STATUS\" "
|
MXS_ERROR("\"SHOW SLAVE STATUS\" "
|
||||||
"returned less than the expected amount of columns. "
|
"returned less than the expected amount of columns. "
|
||||||
"Expected 40 columns. MySQL Version: %s",
|
"Expected 40 columns. MySQL Version: %s",
|
||||||
server_string);
|
server_string.c_str());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -269,7 +267,7 @@ void MMMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
mysql_free_result(result);
|
mysql_free_result(result);
|
||||||
MXS_ERROR("Unexpected result for \"SHOW GLOBAL VARIABLES LIKE 'read_only'\". "
|
MXS_ERROR("Unexpected result for \"SHOW GLOBAL VARIABLES LIKE 'read_only'\". "
|
||||||
"Expected 2 columns. MySQL Version: %s",
|
"Expected 2 columns. MySQL Version: %s",
|
||||||
server_string);
|
server_string.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,11 +47,9 @@ void NDBCMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
MYSQL_RES* result;
|
MYSQL_RES* result;
|
||||||
int isjoined = 0;
|
int isjoined = 0;
|
||||||
char* server_string;
|
|
||||||
|
|
||||||
/* get server version string */
|
/* get server version string */
|
||||||
mxs_mysql_update_server_version(monitored_server->con, monitored_server->server);
|
mxs_mysql_update_server_version(monitored_server->server, monitored_server->con);
|
||||||
server_string = monitored_server->server->version_string;
|
|
||||||
|
|
||||||
/* Check if the the SQL node is able to contact one or more data nodes */
|
/* Check if the the SQL node is able to contact one or more data nodes */
|
||||||
if (mxs_mysql_query(monitored_server->con, "SHOW STATUS LIKE 'Ndb_number_of_ready_data_nodes'") == 0
|
if (mxs_mysql_query(monitored_server->con, "SHOW STATUS LIKE 'Ndb_number_of_ready_data_nodes'") == 0
|
||||||
@ -63,7 +61,7 @@ void NDBCMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
MXS_ERROR("Unexpected result for \"SHOW STATUS LIKE "
|
MXS_ERROR("Unexpected result for \"SHOW STATUS LIKE "
|
||||||
"'Ndb_number_of_ready_data_nodes'\". Expected 2 columns."
|
"'Ndb_number_of_ready_data_nodes'\". Expected 2 columns."
|
||||||
" MySQL Version: %s",
|
" MySQL Version: %s",
|
||||||
server_string);
|
monitored_server->server->version_string().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +89,7 @@ void NDBCMonitor::update_server_status(MXS_MONITORED_SERVER* monitored_server)
|
|||||||
MXS_ERROR("Unexpected result for \"SHOW STATUS LIKE 'Ndb_cluster_node_id'\". "
|
MXS_ERROR("Unexpected result for \"SHOW STATUS LIKE 'Ndb_cluster_node_id'\". "
|
||||||
"Expected 2 columns."
|
"Expected 2 columns."
|
||||||
" MySQL Version: %s",
|
" MySQL Version: %s",
|
||||||
server_string);
|
monitored_server->server->version_string().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,14 +209,14 @@ std::string get_version_string(SERVICE* service)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint64_t intver = UINT64_MAX;
|
uint64_t smallest_found = UINT64_MAX;
|
||||||
|
|
||||||
for (SERVER_REF* ref = service->dbref; ref; ref = ref->next)
|
for (SERVER_REF* ref = service->dbref; ref; ref = ref->next)
|
||||||
{
|
{
|
||||||
if (ref->server->version && ref->server->version < intver)
|
auto version = ref->server->version();
|
||||||
|
if (version.total > 0 && version.total < smallest_found)
|
||||||
{
|
{
|
||||||
rval = ref->server->version_string;
|
rval = ref->server->version_string();
|
||||||
intver = ref->server->version;
|
smallest_found = version.total;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,7 +265,7 @@ int MySQLSendHandshake(DCB* dcb)
|
|||||||
{
|
{
|
||||||
mysql_server_language = dcb->service->dbref->server->charset;
|
mysql_server_language = dcb->service->dbref->server->charset;
|
||||||
|
|
||||||
if (dcb->service->dbref->server->version >= 100200)
|
if (dcb->service->dbref->server->version().total >= 100200)
|
||||||
{
|
{
|
||||||
/** The backend servers support the extended capabilities */
|
/** The backend servers support the extended capabilities */
|
||||||
is_maria = true;
|
is_maria = true;
|
||||||
|
@ -1044,8 +1044,8 @@ GWBUF* RWSplitSession::add_prefix_wait_gtid(SERVER* server, GWBUF* origin)
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
GWBUF* rval = origin;
|
GWBUF* rval = origin;
|
||||||
const char* wait_func = (server->server_type == SERVER_TYPE_MARIADB) ?
|
const char* wait_func = (server->type() == SERVER::Type::MARIADB) ? MARIADB_WAIT_GTID_FUNC :
|
||||||
MARIADB_WAIT_GTID_FUNC : MYSQL_WAIT_GTID_FUNC;
|
MYSQL_WAIT_GTID_FUNC;
|
||||||
const char* gtid_wait_timeout = m_config.causal_reads_timeout.c_str();
|
const char* gtid_wait_timeout = m_config.causal_reads_timeout.c_str();
|
||||||
const char* gtid_position = m_gtid_pos.c_str();
|
const char* gtid_position = m_gtid_pos.c_str();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user