Skip to content

Commit 8ca4e32

Browse files
authored
Merge pull request #5978 from sysown/agent/issue-5977-uds-compression
Fix compressed fast-forward connections over Unix sockets
2 parents 4486d37 + 789052f commit 8ca4e32

6 files changed

Lines changed: 117 additions & 2 deletions

File tree

lib/mysql_connection.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,10 @@ void MySQL_Connection::connect_start() {
10151015
char* host_ip = connect_start_DNS_lookup();
10161016
async_exit_status=mysql_real_connect_start(&ret_mysql, mysql, host_ip, userinfo->username, auth_password, userinfo->schemaname, parent->port, NULL, client_flags);
10171017
} else {
1018-
client_flags &= ~(CLIENT_COMPRESS | CLIENT_ZSTD_COMPRESSION_ALGORITHM); // disabling compression for connections made via Unix socket
1018+
const bool fast_forward = myds && myds->sess && myds->sess->session_fast_forward;
1019+
if (!fast_forward) {
1020+
client_flags &= ~(CLIENT_COMPRESS | CLIENT_ZSTD_COMPRESSION_ALGORITHM); // disabling compression for regular connections made via Unix socket
1021+
}
10191022
async_exit_status=mysql_real_connect_start(&ret_mysql, mysql, "localhost", userinfo->username, auth_password, userinfo->schemaname, parent->port, parent->address, client_flags);
10201023
}
10211024
fd=mysql_get_socket(mysql);

test/infra/control/proxysql-ci.cnf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ pgsql_variables=
2020

2121
sqliteserver_variables=
2222
{
23-
mysql_ifaces="0.0.0.0:6030"
23+
mysql_ifaces="0.0.0.0:6030;/tmp/proxysql_sqlite.sock"
2424
}

test/tap/groups/groups.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@
278278
"reg_test_5639_stmt_execute_max_allowed_packet-t" : [ "mysql84-g6","mysql95-g1" ],
279279
"reg_test_5766_libconfig_escape_passthrough-t" : [ "mysql95-g4" ],
280280
"reg_test_5790-mariadb_collation_255-t" : [ "mariadb10-galera-g1" ],
281+
"reg_test_5977_fast_forward_unix_socket_compression-t" : [ "legacy-g9" ],
281282
"reg_test__ssl_client_busy_wait-t" : [ "legacy-g2","mysql-auto_increment_delay_multiplex=0-g2","mysql-multiplexing=false-g2","mysql-query_digests=0-g2","mysql-query_digests_keep_comment=1-g2","mysql84-g2","mysql90-g2","mysql95-g2" ],
282283
"reg_test_com_change_user_malformed_packet-t" : [ "mysql84-g6","mysql95-g1" ],
283284
"reg_test_compression_split_packets-t" : [ "legacy-g2","mysql-auto_increment_delay_multiplex=0-g2","mysql-multiplexing=false-g2","mysql-query_digests=0-g2","mysql-query_digests_keep_comment=1-g2","mysql84-g2","mysql90-g2","mysql95-g2" ],

test/tap/tap/utils.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,6 +1650,13 @@ int extract_sqlite3_host_port(MYSQL* admin, std::pair<std::string, int>& host_po
16501650
return EXIT_FAILURE;
16511651
}
16521652

1653+
// The SQLite3 server may expose multiple listeners. Existing tests using
1654+
// this helper connect to the first TCP listener.
1655+
const std::string::size_type first_iface_end = sqlite3_ifaces.find(";");
1656+
if (first_iface_end != std::string::npos) {
1657+
sqlite3_ifaces.erase(first_iface_end);
1658+
}
1659+
16531660
// Extract the correct port to connect to SQLite server
16541661
std::string::size_type colon_pos = sqlite3_ifaces.find(":");
16551662
if (colon_pos == std::string::npos) {

test/tap/tests/modules_server_test.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ int extract_module_host_port(MYSQL* proxysql_admin, const std::string varname, s
7979
return res;
8080
}
8181

82+
// Module interfaces may contain multiple listeners. Existing tests using
83+
// this helper connect to the first TCP listener.
84+
const std::string::size_type first_iface_end = module_ifaces.find(";");
85+
if (first_iface_end != std::string::npos) {
86+
module_ifaces.erase(first_iface_end);
87+
}
88+
8289
// Extract the correct port to connect to MODULE server
8390
std::string::size_type colon_pos = module_ifaces.find(":");
8491
if (colon_pos == std::string::npos) {
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* @file reg_test_5977_fast_forward_unix_socket_compression-t.cpp
3+
* @brief Regression test for compressed fast-forward sessions using a Unix socket backend.
4+
*/
5+
6+
#include <string>
7+
8+
#include "mysql.h"
9+
10+
#include "tap.h"
11+
#include "command_line.h"
12+
13+
namespace {
14+
15+
constexpr const char* TEST_USER = "issue5977";
16+
constexpr const char* TEST_PASSWORD = "issue5977";
17+
18+
bool query(MYSQL* mysql, const std::string& sql) {
19+
return mysql_query(mysql, sql.c_str()) == 0;
20+
}
21+
22+
bool configure(MYSQL* admin) {
23+
return
24+
query(admin, "DELETE FROM mysql_servers WHERE hostgroup_id=5977") &&
25+
query(admin,
26+
"INSERT INTO mysql_servers "
27+
"(hostgroup_id,hostname,port,status,compression,max_connections,comment) VALUES "
28+
"(5977,'/tmp/proxysql_sqlite.sock',0,'ONLINE',0,10,'reg_test_5977')") &&
29+
query(admin, "DELETE FROM mysql_users WHERE username='issue5977'") &&
30+
query(admin,
31+
"INSERT INTO mysql_users "
32+
"(username,password,active,default_hostgroup,fast_forward,backend,frontend,comment) VALUES "
33+
"('issue5977','issue5977',1,5977,1,1,1,'reg_test_5977')") &&
34+
query(admin, "LOAD MYSQL SERVERS TO RUNTIME") &&
35+
query(admin, "LOAD MYSQL USERS TO RUNTIME");
36+
}
37+
38+
void cleanup(MYSQL* admin) {
39+
query(admin, "DELETE FROM mysql_servers WHERE hostgroup_id=5977");
40+
query(admin, "DELETE FROM mysql_users WHERE username='issue5977'");
41+
query(admin, "LOAD MYSQL SERVERS TO RUNTIME");
42+
query(admin, "LOAD MYSQL USERS TO RUNTIME");
43+
}
44+
45+
} // namespace
46+
47+
int main(int argc, char** argv) {
48+
CommandLine cl;
49+
50+
if (cl.getEnv()) {
51+
diag("Failed to get the required environmental variables.");
52+
return EXIT_FAILURE;
53+
}
54+
55+
plan(3);
56+
57+
MYSQL* admin = mysql_init(nullptr);
58+
const bool admin_connected = admin && mysql_real_connect(
59+
admin, cl.host, cl.admin_username, cl.admin_password, nullptr, cl.admin_port, nullptr, 0
60+
);
61+
ok(admin_connected, "ProxySQL Admin connection succeeds");
62+
63+
bool configured = false;
64+
if (admin_connected) {
65+
configured = configure(admin);
66+
}
67+
ok(configured, "SQLite3 Unix-socket backend and fast-forward user are configured");
68+
69+
MYSQL* proxy = mysql_init(nullptr);
70+
const bool compression_enabled = proxy && mysql_options(proxy, MYSQL_OPT_COMPRESS, nullptr) == 0;
71+
MYSQL* connected = (configured && compression_enabled)
72+
? mysql_real_connect(proxy, cl.host, TEST_USER, TEST_PASSWORD, nullptr, cl.port, nullptr, CLIENT_COMPRESS)
73+
: nullptr;
74+
75+
bool query_ok = false;
76+
if (connected && mysql_query(proxy, "SELECT 'fast-forward-unix-socket-compression'") == 0) {
77+
MYSQL_RES* result = mysql_store_result(proxy);
78+
MYSQL_ROW row = result ? mysql_fetch_row(result) : nullptr;
79+
query_ok = row && row[0] && std::string(row[0]) == "fast-forward-unix-socket-compression";
80+
if (result) {
81+
mysql_free_result(result);
82+
}
83+
}
84+
ok(query_ok, "compressed fast-forward query returns the SQLite3 backend result");
85+
86+
if (proxy) {
87+
mysql_close(proxy);
88+
}
89+
if (admin_connected) {
90+
cleanup(admin);
91+
}
92+
if (admin) {
93+
mysql_close(admin);
94+
}
95+
96+
return exit_status();
97+
}

0 commit comments

Comments
 (0)