Skip to content

Commit fbd4c0a

Browse files
author
Bharathy Satish
committed
WL#12475: Protocol Changes to specify compression configuration for connections
WL12475 provides a framework to configure compression algorithm and compression level to be used with mysql protocol. Different compression algorithms supported for mysql protocol compression are zlib and zstd. MYSQL_OPT_COMPRESSION_ALGORITHMS option can be used to configure compression algorithm from a client application. MYSQL_OPT_ZSTD_COMPRESSION_LEVEL option can be used to specify compression level for zstd compression algorithm. This WL also introduces a new server variable "protocol-compression-algorithms" which can be used to configure servers compression algorithms. Based on how this variable is configured mysql protocol compression algorithm is negotiated between client and server accordingly. This WL also extends CHANGE MASTER TO statement to allow users to configure compression algorithm/level on slave replication channels. To view what compression algorithm and compression level are configured on a connection user can query status variables like compression_algorithm and compression_level. Reviewed-by: Georgi Kodinov <georgi.kodinov@oracle.com> Gleb Shchepa <gleb.shchepa@oracle.com> Sven Sandberg <sven.sandberg@oracle.com> Nuno Carvalho <nuno.carvalho@oracle.com> RB: 21705
1 parent 8904f89 commit fbd4c0a

File tree

107 files changed

+4922
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+4922
-133
lines changed

client/base/mysql_connection_options.cc

+20
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "caching_sha2_passwordopt-vars.h"
3333
#include "client/base/abstract_options_provider.h"
3434
#include "client/base/abstract_program.h"
35+
#include "compression.h"
3536
#include "m_ctype.h"
3637
#include "mysys_err.h"
3738
#include "typelib.h"
@@ -67,6 +68,18 @@ void Mysql_connection_options::create_options() {
6768
this->create_new_option(&this->m_compress, "compress",
6869
"Use compression in server/client protocol.")
6970
->set_short_character('C');
71+
this->create_new_option(
72+
&this->m_compress_algorithm, "compression-algorithms",
73+
"Use compression algorithm in server/client protocol. Valid values "
74+
"are any combination of 'zstd','zlib','uncompressed'");
75+
this->create_new_option(
76+
&this->m_zstd_compress_level, "zstd-compression-level",
77+
"Use this compression level in the client/server protocol, in case "
78+
"--compression-algorithms=zstd. Valid range is between 1 and 22, "
79+
"inclusive. Default is 3.")
80+
->set_minimum_value(1)
81+
->set_maximum_value(22)
82+
->set_value(default_zstd_compression_level);
7083
this->create_new_option(&this->m_default_charset, "default-character-set",
7184
"Set the default character set.")
7285
->set_value("UTF8MB4");
@@ -131,6 +144,13 @@ MYSQL *Mysql_connection_options::create_connection() {
131144
MYSQL *connection = mysql_init(NULL);
132145
if (this->m_compress) mysql_options(connection, MYSQL_OPT_COMPRESS, NullS);
133146

147+
if (this->m_compress_algorithm.has_value())
148+
mysql_options(connection, MYSQL_OPT_COMPRESSION_ALGORITHMS,
149+
this->m_compress_algorithm.value().c_str());
150+
151+
mysql_options(connection, MYSQL_OPT_ZSTD_COMPRESSION_LEVEL,
152+
&this->m_zstd_compress_level);
153+
134154
if (this->m_ssl_options_provider.apply_for_connection(connection))
135155
return NULL;
136156

client/base/mysql_connection_options.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -143,6 +143,8 @@ class Mysql_connection_options : public Composite_options_provider,
143143
Nullable<std::string> m_default_charset;
144144
Nullable<std::string> m_server_public_key;
145145
bool m_get_server_public_key;
146+
uint m_zstd_compress_level;
147+
Nullable<std::string> m_compress_algorithm;
146148
};
147149

148150
} // namespace Options

client/check/mysqlcheck.cc

+21
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "caching_sha2_passwordopt-vars.h"
3232
#include "client/client_priv.h"
33+
#include "compression.h"
3334
#include "m_ctype.h"
3435
#include "my_alloc.h"
3536
#include "my_dbug.h"
@@ -69,6 +70,8 @@ static const char *default_charset = nullptr;
6970
static char *opt_plugin_dir = 0, *opt_default_auth = 0;
7071
static int first_error = 0;
7172
static const char *opt_skip_database = "";
73+
static uint opt_zstd_compress_level = default_zstd_compression_level;
74+
static char *opt_compress_algorithm = nullptr;
7275
#if defined(_WIN32)
7376
static char *shared_memory_base_name = 0;
7477
#endif
@@ -226,6 +229,17 @@ static struct my_option my_long_options[] = {
226229
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
227230
{"version", 'V', "Output version information and exit.", 0, 0, 0,
228231
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
232+
{"compression-algorithms", 0,
233+
"Use compression algorithm in server/client protocol. Valid values "
234+
"are any combination of 'zstd','zlib','uncompressed'.",
235+
&opt_compress_algorithm, &opt_compress_algorithm, 0, GET_STR, REQUIRED_ARG,
236+
0, 0, 0, 0, 0, 0},
237+
{"zstd-compression-level", 0,
238+
"Use this compression level in the client/server protocol, in case "
239+
"--compression-algorithms=zstd. Valid range is between 1 and 22, "
240+
"inclusive. Default is 3.",
241+
&opt_zstd_compress_level, &opt_zstd_compress_level, 0, GET_UINT,
242+
REQUIRED_ARG, 3, 1, 22, 0, 0, 0},
229243
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}};
230244

231245
static const char *load_default_groups[] = {"mysqlcheck", "client", 0};
@@ -431,6 +445,13 @@ static int dbConnect(char *host, char *user, char *passwd) {
431445
}
432446
mysql_init(&mysql_connection);
433447
if (opt_compress) mysql_options(&mysql_connection, MYSQL_OPT_COMPRESS, NullS);
448+
if (opt_compress_algorithm)
449+
mysql_options(&mysql_connection, MYSQL_OPT_COMPRESSION_ALGORITHMS,
450+
opt_compress_algorithm);
451+
452+
mysql_options(&mysql_connection, MYSQL_OPT_ZSTD_COMPRESSION_LEVEL,
453+
&opt_zstd_compress_level);
454+
434455
if (SSL_SET_OPTIONS(&mysql_connection)) {
435456
fprintf(stderr, "%s", SSL_SET_OPTIONS_ERROR);
436457
return 1;

client/mysql.cc

+21
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "client/client_priv.h"
4141
#include "client/my_readline.h"
4242
#include "client/pattern_matcher.h"
43+
#include "compression.h"
4344
#include "lex_string.h"
4445
#include "m_ctype.h"
4546
#include "my_compiler.h"
@@ -212,6 +213,8 @@ static uint prompt_counter;
212213
static char delimiter[16] = DEFAULT_DELIMITER;
213214
static size_t delimiter_length = 1;
214215
unsigned short terminal_width = 80;
216+
static uint opt_zstd_compress_level = default_zstd_compression_level;
217+
static char *opt_compress_algorithm = nullptr;
215218

216219
#if defined(_WIN32)
217220
static char *shared_memory_base_name = 0;
@@ -1857,6 +1860,18 @@ static struct my_option my_long_options[] = {
18571860
&opt_network_namespace, &opt_network_namespace, 0, GET_STR, REQUIRED_ARG,
18581861
0, 0, 0, 0, 0, 0},
18591862
#endif
1863+
{"compression-algorithms", 0,
1864+
"Use compression algorithm in server/client protocol. Valid values "
1865+
"are any combination of 'zstd','zlib','uncompressed'.",
1866+
&opt_compress_algorithm, &opt_compress_algorithm, 0, GET_STR, REQUIRED_ARG,
1867+
0, 0, 0, 0, 0, 0},
1868+
{"zstd-compression-level", 0,
1869+
"Use this compression level in the client/server protocol, in case "
1870+
"--compression-algorithms=zstd. Valid range is between 1 and 22, "
1871+
"inclusive. Default is 3.",
1872+
&opt_zstd_compress_level, &opt_zstd_compress_level, 0, GET_UINT,
1873+
REQUIRED_ARG, 3, 1, 22, 0, 0, 0},
1874+
18601875
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}};
18611876

18621877
static void usage(int version) {
@@ -4533,6 +4548,12 @@ static bool init_connection_options(MYSQL *mysql) {
45334548
if (opt_bind_addr) mysql_options(mysql, MYSQL_OPT_BIND, opt_bind_addr);
45344549

45354550
if (opt_compress) mysql_options(mysql, MYSQL_OPT_COMPRESS, NullS);
4551+
if (opt_compress_algorithm)
4552+
mysql_options(mysql, MYSQL_OPT_COMPRESSION_ALGORITHMS,
4553+
opt_compress_algorithm);
4554+
4555+
mysql_options(mysql, MYSQL_OPT_ZSTD_COMPRESSION_LEVEL,
4556+
&opt_zstd_compress_level);
45364557

45374558
if (using_opt_local_infile)
45384559
mysql_options(mysql, MYSQL_OPT_LOCAL_INFILE, (char *)&opt_local_infile);

client/mysqladmin.cc

+22-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <string>
3636

3737
#include "client/client_priv.h"
38+
#include "compression.h"
3839
#include "m_ctype.h"
3940
#include "my_alloc.h"
4041
#include "my_compiler.h"
@@ -74,7 +75,8 @@ static char *opt_plugin_dir = 0, *opt_default_auth = 0;
7475
static uint opt_enable_cleartext_plugin = 0;
7576
static bool using_opt_enable_cleartext_plugin = 0;
7677
static bool opt_show_warnings = 0;
77-
78+
static uint opt_zstd_compress_level = default_zstd_compression_level;
79+
static char *opt_compress_algorithm = nullptr;
7880
#if defined(_WIN32)
7981
static char *shared_memory_base_name = 0;
8082
#endif
@@ -287,6 +289,18 @@ static struct my_option my_long_options[] = {
287289
{"show_warnings", OPT_SHOW_WARNINGS, "Show warnings after execution",
288290
&opt_show_warnings, &opt_show_warnings, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
289291
0},
292+
{"compression-algorithms", 0,
293+
"Use compression algorithm in server/client protocol. Valid values "
294+
"are any combination of 'zstd','zlib','uncompressed'.",
295+
&opt_compress_algorithm, &opt_compress_algorithm, 0, GET_STR, REQUIRED_ARG,
296+
0, 0, 0, 0, 0, 0},
297+
{"zstd-compression-level", 0,
298+
"Use this compression level in the client/server protocol, in case "
299+
"--compression-algorithms=zstd. Valid range is between 1 and 22, "
300+
"inclusive. Default is 3.",
301+
&opt_zstd_compress_level, &opt_zstd_compress_level, 0, GET_UINT,
302+
REQUIRED_ARG, 3, 1, 22, 0, 0, 0},
303+
290304
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}};
291305

292306
static const char *load_default_groups[] = {"mysqladmin", "client", 0};
@@ -422,6 +436,13 @@ int main(int argc, char *argv[]) {
422436
mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset);
423437
error_flags = (myf)(opt_nobeep ? 0 : ME_BELL);
424438

439+
if (opt_compress_algorithm)
440+
mysql_options(&mysql, MYSQL_OPT_COMPRESSION_ALGORITHMS,
441+
opt_compress_algorithm);
442+
443+
mysql_options(&mysql, MYSQL_OPT_ZSTD_COMPRESSION_LEVEL,
444+
&opt_zstd_compress_level);
445+
425446
if (opt_plugin_dir && *opt_plugin_dir)
426447
mysql_options(&mysql, MYSQL_PLUGIN_DIR, opt_plugin_dir);
427448

client/mysqlbinlog.cc

+21
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
#include "caching_sha2_passwordopt-vars.h"
4848
#include "client/client_priv.h"
49+
#include "compression.h"
4950
#include "my_byteorder.h"
5051
#include "my_dbug.h"
5152
#include "my_default.h"
@@ -344,6 +345,8 @@ Sid_map *global_sid_map = nullptr;
344345
Checkable_rwlock *global_sid_lock = nullptr;
345346
Gtid_set *gtid_set_included = nullptr;
346347
Gtid_set *gtid_set_excluded = nullptr;
348+
static uint opt_zstd_compress_level = default_zstd_compression_level;
349+
static char *opt_compress_algorithm = nullptr;
347350

348351
static bool opt_print_table_metadata;
349352

@@ -1585,6 +1588,17 @@ static struct my_option my_long_options[] = {
15851588
&opt_print_table_metadata, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
15861589
{"compress", 'C', "Use compression in server/client protocol.",
15871590
&opt_compress, &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
1591+
{"compression-algorithms", 0,
1592+
"Use compression algorithm in server/client protocol. Valid values "
1593+
"are any combination of 'zstd','zlib','uncompressed'.",
1594+
&opt_compress_algorithm, &opt_compress_algorithm, 0, GET_STR, REQUIRED_ARG,
1595+
0, 0, 0, 0, 0, 0},
1596+
{"zstd-compression-level", 0,
1597+
"Use this compression level in the client/server protocol, in case "
1598+
"--compression-algorithms=zstd. Valid range is between 1 and 22, "
1599+
"inclusive. Default is 3.",
1600+
&opt_zstd_compress_level, &opt_zstd_compress_level, 0, GET_UINT,
1601+
REQUIRED_ARG, 3, 1, 22, 0, 0, 0},
15881602
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}};
15891603

15901604
/**
@@ -1844,6 +1858,13 @@ static Exit_status safe_connect() {
18441858
if (opt_plugin_dir && *opt_plugin_dir)
18451859
mysql_options(mysql, MYSQL_PLUGIN_DIR, opt_plugin_dir);
18461860

1861+
if (opt_compress_algorithm)
1862+
mysql_options(mysql, MYSQL_OPT_COMPRESSION_ALGORITHMS,
1863+
opt_compress_algorithm);
1864+
1865+
mysql_options(mysql, MYSQL_OPT_ZSTD_COMPRESSION_LEVEL,
1866+
&opt_zstd_compress_level);
1867+
18471868
if (opt_default_auth && *opt_default_auth)
18481869
mysql_options(mysql, MYSQL_DEFAULT_AUTH, opt_default_auth);
18491870

client/mysqldump.cc

+23
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <string>
3838

3939
#include "client/client_priv.h"
40+
#include "compression.h"
4041
#include "m_ctype.h"
4142
#include "m_string.h"
4243
#include "map_helpers.h"
@@ -135,6 +136,10 @@ static bool server_supports_switching_charsets = true;
135136
otherwise backticks (``, non-standard MySQL feature).
136137
*/
137138
static bool ansi_quotes_mode = false;
139+
140+
static uint opt_zstd_compress_level = default_zstd_compression_level;
141+
static char *opt_compress_algorithm = nullptr;
142+
138143
#define MYSQL_OPT_MASTER_DATA_EFFECTIVE_SQL 1
139144
#define MYSQL_OPT_MASTER_DATA_COMMENTED_SQL 2
140145
#define MYSQL_OPT_SLAVE_DATA_EFFECTIVE_SQL 1
@@ -562,6 +567,17 @@ static struct my_option my_long_options[] = {
562567
&opt_show_create_table_skip_secondary_engine,
563568
&opt_show_create_table_skip_secondary_engine, 0, GET_BOOL, NO_ARG, 0, 0, 0,
564569
0, 0, 0},
570+
{"compression-algorithms", 0,
571+
"Use compression algorithm in server/client protocol. Valid values "
572+
"are any combination of 'zstd','zlib','uncompressed'.",
573+
&opt_compress_algorithm, &opt_compress_algorithm, 0, GET_STR, REQUIRED_ARG,
574+
0, 0, 0, 0, 0, 0},
575+
{"zstd-compression-level", 0,
576+
"Use this compression level in the client/server protocol, in case "
577+
"--compression-algorithms=zstd. Valid range is between 1 and 22, "
578+
"inclusive. Default is 3.",
579+
&opt_zstd_compress_level, &opt_zstd_compress_level, 0, GET_UINT,
580+
REQUIRED_ARG, 3, 1, 22, 0, 0, 0},
565581
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}};
566582

567583
static const char *load_default_groups[] = {"mysqldump", "client", 0};
@@ -1491,6 +1507,13 @@ static int connect_to_db(char *host, char *user, char *passwd) {
14911507
set_server_public_key(&mysql_connection);
14921508
set_get_server_public_key_option(&mysql_connection);
14931509

1510+
if (opt_compress_algorithm)
1511+
mysql_options(&mysql_connection, MYSQL_OPT_COMPRESSION_ALGORITHMS,
1512+
opt_compress_algorithm);
1513+
1514+
mysql_options(&mysql_connection, MYSQL_OPT_ZSTD_COMPRESSION_LEVEL,
1515+
&opt_zstd_compress_level);
1516+
14941517
if (opt_network_timeout) {
14951518
uint timeout = 700;
14961519
ulong max_packet_allowed = 1024L * 1024L * 1024L;

client/mysqlimport.cc

+23
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <time.h>
3434

3535
#include "client/client_priv.h"
36+
#include "compression.h"
3637
#include "my_alloc.h"
3738
#include "my_dbug.h"
3839
#include "my_default.h"
@@ -76,6 +77,9 @@ static char *opt_bind_addr = NULL;
7677
static char *opt_mysql_unix_port = 0;
7778
static char *opt_plugin_dir = 0, *opt_default_auth = 0;
7879
static longlong opt_ignore_lines = -1;
80+
static uint opt_zstd_compress_level = default_zstd_compression_level;
81+
static char *opt_compress_algorithm = nullptr;
82+
7983
#include "caching_sha2_passwordopt-vars.h"
8084
#include "sslopt-vars.h"
8185

@@ -211,6 +215,17 @@ static struct my_option my_long_options[] = {
211215
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
212216
{"version", 'V', "Output version information and exit.", 0, 0, 0,
213217
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
218+
{"compression-algorithms", 0,
219+
"Use compression algorithm in server/client protocol. Valid values "
220+
"are any combination of 'zstd','zlib','uncompressed'.",
221+
&opt_compress_algorithm, &opt_compress_algorithm, 0, GET_STR, REQUIRED_ARG,
222+
0, 0, 0, 0, 0, 0},
223+
{"zstd-compression-level", 0,
224+
"Use this compression level in the client/server protocol, in case "
225+
"--compression-algorithms=zstd. Valid range is between 1 and 22, "
226+
"inclusive. Default is 3.",
227+
&opt_zstd_compress_level, &opt_zstd_compress_level, 0, GET_UINT,
228+
REQUIRED_ARG, 3, 1, 22, 0, 0, 0},
214229
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}};
215230

216231
static const char *load_default_groups[] = {"mysqlimport", "client", 0};
@@ -419,6 +434,14 @@ static MYSQL *db_connect(char *host, char *database, char *user, char *passwd) {
419434
} else if (!(mysql = mysql_init(NULL)))
420435
return 0;
421436
if (opt_compress) mysql_options(mysql, MYSQL_OPT_COMPRESS, NullS);
437+
438+
if (opt_compress_algorithm)
439+
mysql_options(mysql, MYSQL_OPT_COMPRESSION_ALGORITHMS,
440+
opt_compress_algorithm);
441+
442+
mysql_options(mysql, MYSQL_OPT_ZSTD_COMPRESSION_LEVEL,
443+
&opt_zstd_compress_level);
444+
422445
if (opt_local_file)
423446
mysql_options(mysql, MYSQL_OPT_LOCAL_INFILE, (char *)&opt_local_file);
424447
if (SSL_SET_OPTIONS(mysql)) {

0 commit comments

Comments
 (0)