Skip to content

Commit 012fe28

Browse files
authored
Merge pull request #5708 from sysown/issue-5686-galera-vars
feat: add Galera wsrep variables and MariaDB SET STATEMENT ... FOR support
2 parents 11eb213 + d0a1313 commit 012fe28

13 files changed

Lines changed: 279 additions & 16 deletions

include/proxysql_structs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ enum mysql_variable_name {
250250
SQL_UNIQUE_CHECKS,
251251
SQL_WSREP_OSU_METHOD,
252252
SQL_WSREP_SYNC_WAIT,
253+
SQL_WSREP_TRX_FRAGMENT_SIZE,
254+
SQL_WSREP_TRX_FRAGMENT_UNIT,
253255
SQL_NAME_LAST_HIGH_WM,
254256
};
255257

@@ -1854,6 +1856,8 @@ mysql_variable_st mysql_tracked_variables[] {
18541856
{ SQL_UNIQUE_CHECKS, SETTING_VARIABLE, true, false, false, true, (char *)"unique_checks", NULL, (char *)"" , false} ,
18551857
{ SQL_WSREP_OSU_METHOD, SETTING_VARIABLE, true, false, false, false, (char *)"wsrep_osu_method", NULL, (char *)"" , false} ,
18561858
{ SQL_WSREP_SYNC_WAIT, SETTING_VARIABLE, false, false, true, false, (char *)"wsrep_sync_wait", (char *)"wsrep_sync_wait", (char *)"0" , false} ,
1859+
{ SQL_WSREP_TRX_FRAGMENT_SIZE, SETTING_VARIABLE, false, false, true, false, (char *)"wsrep_trx_fragment_size", NULL, (char *)"0" , false} ,
1860+
{ SQL_WSREP_TRX_FRAGMENT_UNIT, SETTING_VARIABLE, true, false, false, false, (char *)"wsrep_trx_fragment_unit", NULL, (char *)"" , false} ,
18571861
/*
18581862
variables that will need input validation:
18591863
binlog_row_image

lib/MySQL_Session.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ static const std::set<std::string> mysql_variables_numeric = {
132132
"sql_select_limit",
133133
"timestamp",
134134
"tmp_table_size",
135-
"wsrep_sync_wait"
135+
"wsrep_sync_wait",
136+
"wsrep_trx_fragment_size"
136137
};
137138
static const std::set<std::string> mysql_variables_strings = {
138139
"default_storage_engine",
@@ -143,6 +144,7 @@ static const std::set<std::string> mysql_variables_strings = {
143144
"log_slow_filter",
144145
"optimizer_switch",
145146
"wsrep_osu_method",
147+
"wsrep_trx_fragment_unit",
146148
};
147149

148150
#include "proxysql_find_charset.h"
@@ -2686,6 +2688,10 @@ bool MySQL_Session::handler_again___status_SETTING_GENERIC_VARIABLE(int *_rc, co
26862688
||
26872689
(myerr == 1193) // variable is not found
26882690
||
2691+
(myerr == 1210) // Incorrect arguments to SET
2692+
||
2693+
(myerr == 1231) // Variable can't be set to the value
2694+
||
26892695
(myerr == 1651) // Query cache is disabled
26902696
||
26912697
(is_perm_track_err(myerr, var_name)) // Special permitted tracking errors (~= '1193')
@@ -6515,6 +6521,11 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
65156521
if (pos != nq.npos) {
65166522
nq.erase(pos + 1); // remove trailing spaces and semicolumns
65176523
}
6524+
// detect MariaDB SET STATEMENT ... FOR syntax
6525+
// pass through to backend without hostgroup locking
6526+
if (strncasecmp(nq.c_str(), (char *)"SET STATEMENT ", 14) == 0 && strcasestr(nq.c_str(), (char *)" FOR ")) {
6527+
return false;
6528+
}
65186529
if (
65196530
(
65206531
match_regexes && (match_regexes[1]->match(dig))

test/README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,24 @@ Common test groups (defined in `tap/groups/groups.json`):
5454

5555
## Prerequisites
5656

57-
1. Build the CI base image (one-time setup):
57+
1. Obtain the CI base image (one-time setup):
58+
59+
Pull from GHCR if available:
60+
```bash
61+
docker pull ghcr.io/sysown/proxysql-ci-base:latest
62+
docker tag ghcr.io/sysown/proxysql-ci-base:latest proxysql-ci-base:latest
63+
```
64+
65+
Or build locally:
5866
```bash
5967
cd test/infra/docker-base
6068
docker build --network host -t proxysql-ci-base:latest .
6169
cd ../../../
6270
```
6371

64-
2. Build ProxySQL and TAP tests:
72+
2. Build ProxySQL and TAP tests in debug mode:
6573
```bash
66-
make -j$(nproc) && make -j$(nproc) build_tap_test
74+
make debug -j$(nproc) && make -j$(nproc) build_tap_test_debug
6775
```
6876

6977
## Where logs actually live after a run

test/tap/groups/groups.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@
400400
"test_session_status_flags-t" : [ "legacy-g9","mysql-auto_increment_delay_multiplex=0-g4","mysql-multiplexing=false-g4","mysql-query_digests=0-g4","mysql-query_digests_keep_comment=1-g4","mysql84-g9","mysql90-g4","mysql95-g4" ],
401401
"test_set_character_results-t" : [ "legacy-g9","mysql-auto_increment_delay_multiplex=0-g4","mysql-multiplexing=false-g4","mysql-query_digests=0-g4","mysql-query_digests_keep_comment=1-g4","mysql84-g9","mysql90-g4","mysql95-g4","set_parser_algorithm_3-g1" ],
402402
"test_set_collation-t" : [ "legacy-g9","mysql-auto_increment_delay_multiplex=0-g4","mysql-multiplexing=false-g4","mysql-query_digests=0-g4","mysql-query_digests_keep_comment=1-g4","mysql84-g9","mysql90-g4","mysql95-g4","set_parser_algorithm_3-g1" ],
403+
"test_set_statement_for-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" ],
403404
"test_simple_embedded_HTTP_server-t" : [ "legacy-g9","mysql-auto_increment_delay_multiplex=0-g4","mysql-multiplexing=false-g4","mysql-query_digests=0-g4","mysql-query_digests_keep_comment=1-g4","mysql84-g9","mysql90-g4","mysql95-g4" ],
404405
"test_sqlite3_from_unixtime-t" : [ "legacy-g9","mysql-auto_increment_delay_multiplex=0-g4","mysql-multiplexing=false-g4","mysql-query_digests=0-g4","mysql-query_digests_keep_comment=1-g4","mysql84-g9","mysql90-g4","mysql95-g4" ],
405406
"test_sqlite3_pass_exts-t" : [ "legacy-g9","mysql-auto_increment_delay_multiplex=0-g4","mysql-multiplexing=false-g4","mysql-query_digests=0-g4","mysql-query_digests_keep_comment=1-g4","mysql84-g9","mysql90-g4","mysql95-g4" ],

test/tap/tests/generate_set_session_csv.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ int main() {
303303
vars["wsrep_osu_method"] = std::make_unique<variable>("wsrep_osu_method", true, false, false);
304304
add_values_and_quotes("wsrep_osu_method", {"TOI","RSU"});
305305

306+
vars["wsrep_trx_fragment_size"] = std::make_unique<variable>("wsrep_trx_fragment_size", false, true, false);
307+
vars["wsrep_trx_fragment_size"]->add(int_values_small, 100);
308+
vars["wsrep_trx_fragment_unit"] = std::make_unique<variable>("wsrep_trx_fragment_unit", false, false, false);
309+
add_values_and_quotes("wsrep_trx_fragment_unit", {"BYTES", "ROWS", "STATEMENTS"});
310+
306311
vars["sql_quote_show_create"] = std::make_unique<variable>("sql_quote_show_create", true, false, true);
307312
vars["sql_quote_show_create"]->add(bool_values);
308313

test/tap/tests/set_testing-240-t.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ int uniquequeries=0;
4949
int histograms=-1;
5050

5151
bool is_mariadb = false;
52+
bool is_cluster = false;
5253
unsigned int g_connect_OK=0;
5354
unsigned int g_connect_ERR=0;
5455
unsigned int g_select_OK=0;
@@ -256,6 +257,21 @@ void * my_conn_thread(void *arg) {
256257
vars[el.key()] = el.value();
257258
}
258259
}
260+
else if (el.key() == "wsrep_sync_wait") {
261+
if (is_cluster) {
262+
vars[el.key()] = el.value();
263+
}
264+
}
265+
else if (el.key() == "wsrep_trx_fragment_size") {
266+
if (is_cluster) {
267+
vars[el.key()] = el.value();
268+
}
269+
}
270+
else if (el.key() == "wsrep_trx_fragment_unit") {
271+
if (is_cluster) {
272+
vars[el.key()] = el.value();
273+
}
274+
}
259275
else {
260276
vars[el.key()] = el.value();
261277
}
@@ -558,7 +574,7 @@ int main(int argc, char *argv[]) {
558574
MYSQL_QUERY(proxysql_admin, update.c_str());
559575
MYSQL_QUERY(proxysql_admin, "LOAD MYSQL QUERY RULES TO RUNTIME");
560576

561-
if (detect_version(cl, is_mariadb) != 0) {
577+
if (detect_version(cl, is_mariadb, is_cluster) != 0) {
562578
diag("Cannot detect MySQL version");
563579
return exit_status();
564580
}

test/tap/tests/set_testing-240.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const std::vector<std::string> possible_unknown_variables = {
2121
"group_replication_consistency",
2222
"query_cache_type",
2323
"wsrep_osu_method",
24+
"wsrep_trx_fragment_size",
25+
"wsrep_trx_fragment_unit",
2426
"wsrep_sync_wait",
2527
"max_execution_time",
2628
"optimizer_use_condition_selectivity",
@@ -464,7 +466,7 @@ bool check_session_track_gtids(const std::string& expVal, const std::string& sVa
464466
return res;
465467
}
466468

467-
int detect_version(CommandLine& cl, bool& is_mariadb) {
469+
int detect_version(CommandLine& cl, bool& is_mariadb, bool& is_cluster) {
468470
MYSQL* mysql = mysql_init(NULL);
469471
if (!mysql)
470472
return 1;
@@ -487,6 +489,15 @@ int detect_version(CommandLine& cl, bool& is_mariadb) {
487489
}
488490
}
489491
mysql_free_result(result);
492+
MYSQL_QUERY(mysql, "SHOW VARIABLES LIKE 'wsrep_sync_wait'");
493+
result = mysql_store_result(mysql);
494+
unsigned long long nr = mysql_num_rows(result);
495+
if (nr == 0) {
496+
is_cluster = false;
497+
} else {
498+
is_cluster = true;
499+
}
500+
mysql_free_result(result);
490501
mysql_close(mysql);
491502
return 0;
492503
}

test/tap/tests/set_testing-multi-t.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ void * my_conn_thread(void *arg) {
165165
vars[el.key()] = el.value();
166166
}
167167
}
168+
else if (el.key() == "wsrep_trx_fragment_size") {
169+
if (is_cluster) {
170+
vars[el.key()] = el.value();
171+
}
172+
}
173+
else if (el.key() == "wsrep_trx_fragment_unit") {
174+
if (is_cluster) {
175+
vars[el.key()] = el.value();
176+
}
177+
}
168178
else if (el.key() == "transaction_read_only") {
169179
if (is_mariadb) {
170180
vars["tx_read_only"] = el.value();
@@ -287,13 +297,16 @@ void * my_conn_thread(void *arg) {
287297
(el.key() == "session_track_gtids" && !check_session_track_gtids(el.value(), s.value(), k.value()))
288298
))
289299
) {
290-
__sync_fetch_and_add(&g_failed, 1);
291-
testPassed = false;
292-
fprintf(stderr, "Test failed for this case %s->%s.\n\nmysql data %s\n\n proxysql data %s\n\n csv data %s\n\n\n",
300+
if (k != mysql_vars.end() && s != proxysql_vars.end() && s.value() == el.value() && k.value() == UNKNOWNVAR) {
301+
variables_tested++;
302+
} else {
303+
__sync_fetch_and_add(&g_failed, 1);
304+
testPassed = false;
305+
fprintf(stderr, "Test failed for this case %s->%s.\n\nmysql data %s\n\n proxysql data %s\n\n csv data %s\n\n\n",
293306
el.value().dump().c_str(), el.key().c_str(), mysql_vars.dump().c_str(), proxysql_vars.dump().c_str(), vars.dump().c_str());
294-
ok(testPassed, "mysql connection [%p], thread_id [%lu], command [%s]", mysql, mysql->thread_id, testCases[r2].command.c_str());
295-
// In case of failing test, exit completely.
296-
exit(EXIT_FAILURE);
307+
ok(testPassed, "mysql connection [%p], thread_id [%lu], command [%s]", mysql, mysql->thread_id, testCases[r2].command.c_str());
308+
exit(EXIT_FAILURE);
309+
}
297310
} else {
298311
variables_tested++;
299312
}

test/tap/tests/set_testing-t.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ void * my_conn_thread(void *arg) {
172172
vars[el.key()] = el.value();
173173
}
174174
}
175+
else if (el.key() == "wsrep_trx_fragment_size") {
176+
if (is_cluster) {
177+
vars[el.key()] = el.value();
178+
}
179+
}
180+
else if (el.key() == "wsrep_trx_fragment_unit") {
181+
if (is_cluster) {
182+
vars[el.key()] = el.value();
183+
}
184+
}
175185
else if (el.key() == "transaction_read_only") {
176186
if (is_mariadb) {
177187
vars["tx_read_only"] = el.value();
@@ -325,7 +335,9 @@ void * my_conn_thread(void *arg) {
325335
(el.key() == "session_track_gtids" && !check_session_track_gtids(el.value(), s.value(), k.value()))
326336
))
327337
) {
328-
if (el.key() == "wsrep_sync_wait" && k == mysql_vars.end() && (s.value() == el.value())) {
338+
if (k != mysql_vars.end() && s != proxysql_vars["conn"].end() && s.value() == el.value() && k.value() == UNKNOWNVAR) {
339+
variables_tested++;
340+
} else if (el.key() == "wsrep_sync_wait" && k == mysql_vars.end() && (s.value() == el.value())) {
329341
variables_tested++;
330342
} else {
331343
__sync_fetch_and_add(&g_failed, 1);
@@ -336,9 +348,6 @@ void * my_conn_thread(void *arg) {
336348
proxysql_vars["conn"].size(), proxysql_vars["conn"].dump(2).c_str(),
337349
vars.dump(2).c_str());
338350
diag("FAILED FOR: connections mysql[%p] proxysql[%s], thread_id [%lu], command [%s]", mysql, paddress.c_str(), mysql->thread_id, testCases[r2].command.c_str());
339-
//ok(testPassed, "connections mysql[%p] proxysql[%s], thread_id [%lu], command [%s]", mysql, paddress.c_str(), mysql->thread_id, testCases[r2].command.c_str());
340-
// In case of failing test, exit completely.
341-
//exit(EXIT_FAILURE);
342351
}
343352
} else {
344353
variables_tested++;

test/tap/tests/set_testing-t.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
"set max_join_size=18446744073709551615", "{'max_join_size':'18446744073709551615'}"
6969
"set wsrep_sync_wait=1", "{'wsrep_sync_wait':'1'}"
7070
"set wsrep_sync_wait=0", "{'wsrep_sync_wait':'0'}"
71+
"set wsrep_trx_fragment_size=1000", "{'wsrep_trx_fragment_size':'1000'}"
72+
"set wsrep_trx_fragment_size=0", "{'wsrep_trx_fragment_size':'0'}"
73+
"set wsrep_trx_fragment_unit='ROWS'", "{'wsrep_trx_fragment_unit':'ROWS'}"
74+
"set wsrep_trx_fragment_unit='BYTES'", "{'wsrep_trx_fragment_unit':'BYTES'}"
7175
"set group_concat_max_len=2048", "{'group_concat_max_len':'2048'}"
7276
"set group_concat_max_len=4096", "{'group_concat_max_len':'4096'}"
7377
"set tx_isolation='READ-COMMITTED', group_concat_max_len=4096", "{'transaction_isolation':'READ-COMMITTED', 'group_concat_max_len':'4096'}"

0 commit comments

Comments
 (0)