Skip to content

Commit 17a5419

Browse files
authored
Merge pull request #5637 from sysown/v3.0_new_zstd
feat: add mysql-zstd_compression_level variable
2 parents aecac96 + 174c5bd commit 17a5419

11 files changed

Lines changed: 476 additions & 13 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,9 @@ scripts/mcp/DiscoveryAgent/ClaudeCode_Headless/tmp/
211211
test/tap/tests/test_cluster_sync_config/test_cluster_sync_nomonitor/cluster_sync_node_stderr.txt
212212
test/tap/tests/test_cluster_sync_config/test_cluster_sync_withmonitor/cluster_sync_node_stderr.txt
213213

214+
# unit test binaries (built but not tracked)
215+
test/tap/tests/unit/*-t
216+
214217
# test-scripts runtime dependencies (created by run-tests-isolated.bash)
215218
test-scripts/deps/
219+
.worktrees/

CLAUDE.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,39 @@ The same codebase produces three product tiers via feature flags:
5555

5656
Tests use TAP (Test Anything Protocol) with Docker-based backend infrastructure.
5757

58+
### Running TAP tests — DO NOT manually set up Docker containers
59+
60+
**ALWAYS use `run-tests-isolated.bash`**. It handles infrastructure setup, ProxySQL start, test execution, and cleanup. Never manually create Docker networks, start containers, or run init scripts — the runner does all of that.
61+
5862
```bash
59-
# Build and run all TAP tests
60-
make build_tap_tests
61-
cd test/tap && make
63+
# Set up infrastructure (backends + ProxySQL container)
64+
WORKSPACE=$(pwd) INFRA_ID=dev-$USER TAP_GROUP=mysql84-g1 test/infra/control/ensure-infras.bash
6265

63-
# Run specific test groups
64-
cd test/tap/tests && make
65-
cd test/tap/tests_with_deps && make
66+
# Run all tests for a TAP group
67+
WORKSPACE=$(pwd) INFRA_ID=dev-$USER TAP_GROUP=mysql84-g1 test/infra/control/run-tests-isolated.bash
6668

67-
# Test infrastructure (Docker environments)
68-
# Located in test/infra/ with docker-compose configs for:
69-
# mysql57, mysql84, mariadb10, pgsql16, pgsql17, clickhouse23, etc.
69+
# Build test binaries first (requires proxysql binary)
70+
make build_tap_tests # release
71+
make build_tap_test_debug # debug
7072
```
7173

74+
Available TAP groups are defined in `test/tap/groups/groups.json`. Group names follow the pattern `<infra>-g<N>` (e.g., `mysql84-g1`, `legacy-g2`, `pgsql16-g1`).
75+
76+
### DO NOT
77+
78+
- **DO NOT** manually create Docker networks (`docker network create`)
79+
- **DO NOT** manually start containers (`docker start`, `docker run`)
80+
- **DO NOT** run `docker-compose-init.bash` directly — use `ensure-infras.bash`
81+
- **DO NOT** symlink build artifacts between worktrees — build in each worktree separately
82+
- **DO NOT** copy source files between worktrees or repos
83+
- **DO NOT** run `cd test/tap/tests && make` and expect tests to pass without infrastructure
84+
85+
### Test file conventions
86+
7287
Test files follow the naming pattern `test_*.cpp` or `*-t.cpp` in `test/tap/tests/`.
7388

89+
Test binaries are built via a pattern rule in `test/tap/tests/Makefile`: `make <testname>-t` compiles `<testname>-t.cpp` into `<testname>-t`. No special Makefile target is needed for new tests — just add the `.cpp` file and register it in `groups.json`.
90+
7491
## Architecture
7592

7693
### Build Pipeline

include/MySQL_Thread.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ class MySQL_Threads_Handler
488488
bool default_reconnect;
489489
bool have_compress;
490490
int protocol_compression_level;
491+
int zstd_compression_level;
491492
bool have_ssl;
492493
bool multiplexing;
493494
// bool stmt_multiplexing;

include/proxysql_structs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,7 @@ __thread int mysql_thread___poll_timeout_on_failure;
12961296
__thread bool mysql_thread___connection_warming;
12971297
__thread bool mysql_thread___have_compress;
12981298
__thread int mysql_thread___protocol_compression_level;
1299+
__thread int mysql_thread___zstd_compression_level;
12991300
__thread bool mysql_thread___have_ssl;
13001301
__thread bool mysql_thread___multiplexing;
13011302
__thread bool mysql_thread___log_unhealthy_connections;
@@ -1629,6 +1630,7 @@ extern __thread int mysql_thread___poll_timeout_on_failure;
16291630
extern __thread bool mysql_thread___connection_warming;
16301631
extern __thread bool mysql_thread___have_compress;
16311632
extern __thread int mysql_thread___protocol_compression_level;
1633+
extern __thread int mysql_thread___zstd_compression_level;
16321634
extern __thread bool mysql_thread___have_ssl;
16331635
extern __thread bool mysql_thread___multiplexing;
16341636
extern __thread bool mysql_thread___log_unhealthy_connections;

lib/MySQL_Protocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2300,7 +2300,7 @@ void MySQL_Protocol::PPHR_SetConnAttrs(MyProt_tmp_auth_vars& vars1, account_deta
23002300
const uint8_t zstd_compression_level =
23012301
(vars1.zstd_compression_level > 0 && vars1.zstd_compression_level <= ZSTD_maxCLevel())
23022302
? vars1.zstd_compression_level
2303-
: static_cast<uint8_t>(std::min<int>(ZSTD_maxCLevel(), std::max<int>(1, mysql_thread___protocol_compression_level)));
2303+
: static_cast<uint8_t>(mysql_thread___zstd_compression_level);
23042304

23052305
myconn->options.compression_zstd = false;
23062306
myconn->options.zstd_compression_level = 0;

lib/MySQL_Thread.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ using json = nlohmann::json;
3030
#include "MySQL_Resolution.h"
3131

3232
#include <fcntl.h>
33+
#include <zstd.h>
3334

3435
using std::vector;
3536
using std::function;
@@ -528,6 +529,7 @@ static char * mysql_thread_variables_names[]= {
528529
(char *)"evaluate_replication_lag_on_servers_load",
529530
(char *)"proxy_protocol_networks",
530531
(char *)"protocol_compression_level",
532+
(char *)"zstd_compression_level",
531533
(char *)"ignore_min_gtid_annotations",
532534
(char *)"fast_forward_grace_close_ms",
533535
#ifdef PROXYSQLFFTO
@@ -1453,6 +1455,7 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() {
14531455
variables.log_mysql_warnings_enabled=false;
14541456
variables.data_packets_history_size=0;
14551457
variables.protocol_compression_level=3;
1458+
variables.zstd_compression_level=3;
14561459
variables.ignore_min_gtid_annotations=false;
14571460
// status variables
14581461
status_variables.mirror_sessions_current=0;
@@ -2669,6 +2672,7 @@ char ** MySQL_Threads_Handler::get_variables_list() {
26692672
VariablesPointers_int["handle_warnings"] = make_tuple(&variables.handle_warnings, 0, 1, false);
26702673
VariablesPointers_int["evaluate_replication_lag_on_servers_load"] = make_tuple(&variables.evaluate_replication_lag_on_servers_load, 0, 1, false);
26712674
VariablesPointers_int["protocol_compression_level"] = make_tuple(&variables.protocol_compression_level, -1, 9, false);
2675+
VariablesPointers_int["zstd_compression_level"] = make_tuple(&variables.zstd_compression_level, 1, ZSTD_maxCLevel(), false);
26722676

26732677
// logs
26742678
VariablesPointers_int["auditlog_filesize"] = make_tuple(&variables.auditlog_filesize, 1024*1024, 1*1024*1024*1024, false);
@@ -4733,6 +4737,7 @@ void MySQL_Thread::refresh_variables() {
47334737
REFRESH_VARIABLE_INT(poll_timeout_on_failure);
47344738
REFRESH_VARIABLE_BOOL(have_compress);
47354739
REFRESH_VARIABLE_INT(protocol_compression_level);
4740+
REFRESH_VARIABLE_INT(zstd_compression_level);
47364741
REFRESH_VARIABLE_BOOL(have_ssl);
47374742
REFRESH_VARIABLE_BOOL(multiplexing);
47384743
REFRESH_VARIABLE_BOOL(log_unhealthy_connections);
@@ -4817,6 +4822,7 @@ MySQL_Thread::MySQL_Thread() {
48174822
mysql_thread___ssl_p2s_crlpath=NULL;
48184823

48194824
mysql_thread___protocol_compression_level=3;
4825+
mysql_thread___zstd_compression_level=3;
48204826

48214827
last_maintenance_time=0;
48224828
last_move_to_idle_thread_time=0;

lib/mysql_data_stream.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ static int get_zstd_compression_level(const MySQL_Connection* myconn) {
2929
if (zstd_level > 0 && zstd_level <= ZSTD_maxCLevel()) {
3030
return zstd_level;
3131
}
32-
if (mysql_thread___protocol_compression_level > 0 && mysql_thread___protocol_compression_level <= ZSTD_maxCLevel()) {
33-
return mysql_thread___protocol_compression_level;
32+
if (mysql_thread___zstd_compression_level > 0 && mysql_thread___zstd_compression_level <= ZSTD_maxCLevel()) {
33+
return mysql_thread___zstd_compression_level;
3434
}
3535
return ZSTD_CLEVEL_DEFAULT;
3636
}

test/tap/groups/groups.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@
9999
"mysql-test_malformed_packet-t" : [ "legacy-g1","mysql-auto_increment_delay_multiplex=0-g1","mysql-multiplexing=false-g1","mysql-query_digests=0-g1","mysql-query_digests_keep_comment=1-g1","mysql84-g1","mysql90-g1","mysql95-g1" ],
100100
"mysql-test_ssl_CA-t" : [ "legacy-g1","mysql-auto_increment_delay_multiplex=0-g1","mysql-multiplexing=false-g1","mysql-query_digests=0-g1","mysql-query_digests_keep_comment=1-g1","mysql84-g1","mysql90-g1","mysql95-g1" ],
101101
"mysql-watchdog_test-t" : [ "legacy-g4","mysql-auto_increment_delay_multiplex=0-g4","mysql-multiplexing=false-g4","mysql-query_digests=0-g4","mysql-query_digests_keep_comment=1-g4","mysql84-g4","mysql90-g4","mysql95-g4" ],
102+
"mysql-zstd_compression_level-t" : [ "legacy-g1","mysql-auto_increment_delay_multiplex=0-g1","mysql-multiplexing=false-g1","mysql-query_digests=0-g1","mysql-query_digests_keep_comment=1-g1","mysql84-g1","mysql90-g1","mysql95-g1" ],
103+
"mysql-zstd_compression_level_libmysql-t" : [ "mysql84-g1","mysql90-g1","mysql95-g1" ],
102104
"mysql_encode_unit-t" : [ "unit-tests-g1" ],
103105
"mysql_error_classifier_unit-t" : [ "unit-tests-g1" ],
104106
"mysql_hostgroup_attributes-servers_defaults-t" : [ "legacy-g1","mysql-auto_increment_delay_multiplex=0-g1","mysql-multiplexing=false-g1","mysql-query_digests=0-g1","mysql-query_digests_keep_comment=1-g1","mysql84-g1","mysql90-g1","mysql95-g1" ],

test/tap/tests/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ mysql_reconnect_libmariadb-t: mysql_reconnect.cpp $(TAP_LDIR)/libtap.so
263263
mysql_reconnect_libmysql-t: mysql_reconnect.cpp $(TAP_LDIR)/libtap_mysql8.a
264264
$(CXX) -DLIBMYSQL_HELPER8 -DDISABLE_WARNING_COUNT_LOGGING $< -I$(TEST_MYSQL8_IDIR) -I$(TEST_MYSQL8_EDIR) -L$(TEST_MYSQL8_LDIR) -lmysqlclient -ltap_mysql8 -lresolv $(CUSTOMARGS) -o $@
265265

266+
mysql-zstd_compression_level_libmysql-t: mysql-zstd_compression_level-t.cpp $(TAP_LDIR)/libtap_mysql8.a
267+
$(CXX) -DLIBMYSQL_HELPER8 -DDISABLE_WARNING_COUNT_LOGGING $< -I$(TEST_MYSQL8_IDIR) -I$(TEST_MYSQL8_EDIR) -L$(TEST_MYSQL8_LDIR) -lmysqlclient -ltap_mysql8 -lresolv $(CUSTOMARGS) -o $@
268+
266269
fast_forward_grace_close_libmysql-t: fast_forward_grace_close.cpp $(TAP_LDIR)/libtap_mysql8.a
267270
$(CXX) -DLIBMYSQL_HELPER8 -DDISABLE_WARNING_COUNT_LOGGING $< -I$(TEST_MYSQL8_IDIR) -I$(TEST_MYSQL8_EDIR) -L$(TEST_MYSQL8_LDIR) -lmysqlclient -ltap_mysql8 -lresolv $(CUSTOMARGS) -o $@
268271

0 commit comments

Comments
 (0)