Merge branch '2.3' into 2.4

This commit is contained in:
Markus Mäkelä
2020-02-24 14:10:19 +02:00
5 changed files with 112 additions and 27 deletions

View File

@ -7,6 +7,7 @@ if [ "$1" = "0" ] || [ "$1" = "remove" ]
then
if [ -f /etc/init.d/maxscale ]
then
/etc/init.d/maxscale stop
rm /etc/init.d/maxscale
fi

View File

@ -1022,6 +1022,9 @@ add_test_executable(mxs2621_lower_case_tables.cpp mxs2621_lower_case_tables mxs2
# MXS-2631: Duplicate system tables not ignored
add_test_executable(mxs2631_ignore_system_tables.cpp mxs2631_ignore_system_tables mxs2631_ignore_system_tables LABELS schemarouter BREAKS_REPL REPL_BACKEND)
# MXS-2878: Verify that TLS is required
add_test_executable(mxs2878_monitor_ssl.cpp mxs2878_monitor_ssl mxs2878_monitor_ssl LABELS REPL_BACKEND)
############################################
# END: Normal tests #
############################################

View File

@ -0,0 +1,47 @@
[maxscale]
threads=###threads###
[server1]
type=server
address=###node_server_IP_1###
port=###node_server_port_1###
protocol=MySQLBackend
ssl=true
[server2]
type=server
address=###node_server_IP_2###
port=###node_server_port_2###
protocol=MySQLBackend
ssl=true
[server3]
type=server
address=###node_server_IP_3###
port=###node_server_port_3###
protocol=MySQLBackend
ssl=true
[server4]
type=server
address=###node_server_IP_4###
port=###node_server_port_4###
protocol=MySQLBackend
ssl=true
[MySQL-Monitor]
type=monitor
module=mysqlmon
servers=server1,server2,server3,server4
user=maxskysql
password=skysql
[CLI]
type=service
router=cli
[CLI-Listener]
type=listener
service=CLI
protocol=maxscaled
socket=default

View File

@ -0,0 +1,35 @@
/**
* Covers the following bugs:
* MXS-2878: Monitor connections do not insist on SSL being used
* MXS-2896: Server wrongly in Running state after failure to connect
*/
#include "testconnections.h"
#include <sstream>
std::string join(StringSet st)
{
std::ostringstream ss;
for (const auto& a : st)
{
ss << a << " ";
}
return ss.str();
}
int main(int argc, char** argv)
{
TestConnections test(argc, argv);
for (auto srv : {"server1", "server2", "server3", "server4"})
{
StringSet expected = {"Down"};
auto status = test.maxscales->get_server_status(srv);
test.expect(status == expected,
"Expected '%s' but got '%s'", join(expected).c_str(), join(status).c_str());
}
return test.global_result;
}

View File

@ -1143,49 +1143,48 @@ Monitor::ping_or_connect_to_db(const MonitorServer::ConnectionSettings& sett, SE
}
/** Otherwise close the handle. */
mysql_close(pConn);
pConn = nullptr;
}
ConnectResult conn_result = ConnectResult::REFUSED;
if ((pConn = mysql_init(NULL)) != nullptr)
{
string uname = sett.username;
string passwd = sett.password;
const Server& srv = static_cast<const Server&>(server); // Clean this up later.
string server_specific_monuser = srv.monitor_user();
if (!server_specific_monuser.empty())
{
uname = server_specific_monuser;
passwd = srv.monitor_password();
}
char* dpwd = decrypt_password(passwd.c_str());
for (int i = 0; i < sett.connect_attempts; i++)
{
pConn = mysql_init(NULL);
mysql_optionsv(pConn, MYSQL_OPT_CONNECT_TIMEOUT, &sett.connect_timeout);
mysql_optionsv(pConn, MYSQL_OPT_READ_TIMEOUT, &sett.read_timeout);
mysql_optionsv(pConn, MYSQL_OPT_WRITE_TIMEOUT, &sett.write_timeout);
mysql_optionsv(pConn, MYSQL_PLUGIN_DIR, get_connector_plugindir());
time_t start = time(NULL);
time_t start = 0;
time_t end = 0;
for (int i = 0; i < sett.connect_attempts; i++)
{
start = time(NULL);
bool result = (mxs_mysql_real_connect(pConn, &server, uname.c_str(), dpwd) != NULL);
end = time(NULL);
if (result)
if (mxs_mysql_real_connect(pConn, &server, uname.c_str(), dpwd))
{
conn_result = ConnectResult::NEWCONN_OK;
break;
}
}
if (conn_result == ConnectResult::REFUSED && difftime(end, start) >= sett.connect_timeout)
else if (conn_result == ConnectResult::REFUSED
&& difftime(time(NULL), start) >= sett.connect_timeout)
{
conn_result = ConnectResult::TIMEOUT;
}
MXS_FREE(dpwd);
mysql_close(pConn);
pConn = nullptr;
}
MXS_FREE(dpwd);
*ppConn = pConn;
return conn_result;
}