Skip to content

Commit b79ea9f

Browse files
committed
Add different compression choice
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags:
1 parent b354aae commit b79ea9f

File tree

7 files changed

+103
-0
lines changed

7 files changed

+103
-0
lines changed

include/mysql/components/services/clone_protocol_service.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ struct mysql_clone_ssl_context {
6161

6262
/** Enable network compression. */
6363
bool m_enable_compression;
64+
const char *m_compression_algorithm;
65+
uint m_compression_level;
6466
NET_SERVER *m_server_extn;
6567
};
6668

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
INSTALL PLUGIN clone SONAME 'CLONE_PLUGIN';
2+
SET GLOBAL clone_enable_compression = ON;
3+
SET GLOBAL clone_compression_algorithm = ZSTD;
4+
SET GLOBAL clone_zstd_compression_level = 8;
5+
SET GLOBAL clone_autotune_concurrency = OFF;
6+
SET GLOBAL clone_max_concurrency = 8;
7+
SET GLOBAL clone_valid_donor_list = 'HOST:PORT';
8+
CLONE INSTANCE FROM USER@HOST:PORT IDENTIFIED BY '' DATA DIRECTORY = 'CLONE_DATADIR';
9+
select ID, STATE, ERROR_NO from performance_schema.clone_status;
10+
ID STATE ERROR_NO
11+
1 Completed 0
12+
select ID, STAGE, STATE from performance_schema.clone_progress;
13+
ID STAGE STATE
14+
1 DROP DATA Completed
15+
1 FILE COPY Completed
16+
1 PAGE COPY Completed
17+
1 SST COPY Completed
18+
1 REDO COPY Completed
19+
1 FILE SYNC Completed
20+
1 RESTART Not Started
21+
1 RECOVERY Not Started
22+
# restart
23+
UNINSTALL PLUGIN clone;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--source include/have_rocksdb.inc
2+
3+
--let $HOST = 127.0.0.1
4+
--let $PORT =`select @@port`
5+
--let $USER = root
6+
--let remote_clone = 1
7+
8+
--source ../../clone/include/clone_connection_begin.inc
9+
--let $CLONE_DATADIR = $MYSQL_TMP_DIR/data_new
10+
11+
# Install Clone Plugin
12+
--replace_result $CLONE_PLUGIN CLONE_PLUGIN
13+
--eval INSTALL PLUGIN clone SONAME '$CLONE_PLUGIN'
14+
15+
--connection clone_conn_1
16+
SET GLOBAL clone_enable_compression = ON;
17+
SET GLOBAL clone_compression_algorithm = ZSTD;
18+
SET GLOBAL clone_zstd_compression_level = 8;
19+
--source ../../clone/include/clone_command.inc
20+
21+
--force-rmdir $CLONE_DATADIR
22+
23+
--let restart_parameters=
24+
--source include/restart_mysqld.inc
25+
26+
# Clean up
27+
UNINSTALL PLUGIN clone;
28+
--source ../../clone/include/clone_connection_end.inc

plugin/clone/include/clone.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ extern uint clone_max_io_bandwidth;
9090
/** Clone system variable: If network compression is enabled */
9191
extern bool clone_enable_compression;
9292

93+
extern ulong clone_compression_algorithm;
94+
95+
extern uint clone_zstd_compression_level;
96+
9397
/** Clone system variable: SSL private key */
9498
extern char *clone_client_ssl_private_key;
9599

plugin/clone/src/clone_client.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,13 @@ int Client::connect_remote(bool is_restart, bool use_aux) {
896896
mysql_clone_ssl_context ssl_context;
897897

898898
ssl_context.m_enable_compression = clone_enable_compression;
899+
900+
if (ssl_context.m_enable_compression) {
901+
ssl_context.m_compression_algorithm =
902+
mysql_compression_lib_names[clone_compression_algorithm];
903+
ssl_context.m_compression_level = clone_zstd_compression_level;
904+
}
905+
899906
ssl_context.m_server_extn =
900907
ssl_context.m_enable_compression ? &m_conn_server_extn : nullptr;
901908
ssl_context.m_ssl_mode = m_share->m_ssl_mode;

plugin/clone/src/clone_plugin.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ uint clone_max_io_bandwidth;
7070
/** Clone system variable: If network compression is enabled */
7171
bool clone_enable_compression;
7272

73+
ulong clone_compression_algorithm;
74+
75+
uint clone_zstd_compression_level;
76+
7377
/** Clone system variable: valid list of donor addresses. */
7478
static char *clone_valid_donor_list;
7579

@@ -636,6 +640,26 @@ static MYSQL_SYSVAR_BOOL(enable_compression, clone_enable_compression,
636640
"If compression is done at network", nullptr, nullptr,
637641
false); /* Disable compression by default */
638642

643+
enum enum_clone_compression_algorithm { ZLIB = 0, ZSTD };
644+
645+
static TYPELIB clone_compression_algorithms_typelib = {
646+
array_elements(mysql_compression_lib_names) - 1,
647+
"clone_compression_algorithms_typelib", mysql_compression_lib_names,
648+
nullptr};
649+
650+
static MYSQL_SYSVAR_ENUM(compression_algorithm, clone_compression_algorithm,
651+
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_MEMALLOC,
652+
"compression algorithm used in clone", nullptr,
653+
nullptr, enum_clone_compression_algorithm::ZSTD,
654+
&clone_compression_algorithms_typelib);
655+
656+
static MYSQL_SYSVAR_UINT(zstd_compression_level, clone_zstd_compression_level,
657+
PLUGIN_VAR_NOCMDARG, "zstd compression level", nullptr,
658+
nullptr, 3, /* Default */
659+
1, /* Minimum */
660+
10, /* Maximum */
661+
1);
662+
639663
/** List of valid donor addresses allowed to clone from. */
640664
static MYSQL_SYSVAR_STR(valid_donor_list, clone_valid_donor_list,
641665
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_MEMALLOC,
@@ -705,6 +729,8 @@ static SYS_VAR *clone_system_variables[] = {
705729
MYSQL_SYSVAR(ssl_cert),
706730
MYSQL_SYSVAR(ssl_ca),
707731
MYSQL_SYSVAR(donor_timeout_after_network_failure),
732+
MYSQL_SYSVAR(compression_algorithm),
733+
MYSQL_SYSVAR(zstd_compression_level),
708734
nullptr};
709735

710736
/** Declare clone plugin */

sql/server_component/clone_protocol_service.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,12 @@ DEFINE_METHOD(MYSQL *, mysql_clone_connect,
394394
/* Enable compression. */
395395
if (ssl_ctx->m_enable_compression) {
396396
mysql_options(mysql, MYSQL_OPT_COMPRESS, nullptr);
397+
if (ssl_ctx->m_compression_algorithm) {
398+
mysql_options(mysql, MYSQL_OPT_COMPRESSION_ALGORITHMS,
399+
ssl_ctx->m_compression_algorithm);
400+
mysql_options(mysql, MYSQL_OPT_ZSTD_COMPRESSION_LEVEL,
401+
&ssl_ctx->m_compression_level);
402+
}
397403
mysql_extension_set_server_extn(mysql, ssl_ctx->m_server_extn);
398404
}
399405

@@ -539,6 +545,13 @@ DEFINE_METHOD(int, mysql_clone_get_response,
539545
*net_length = 0;
540546
*length = my_net_read(net);
541547

548+
/* The ZSTD object has been updated to include the newly created decompressor
549+
context. Include the change in the net extension so that the resource can
550+
be released when de-init compress context. */
551+
if (net->compress) {
552+
static_cast<NET_SERVER *>(saved_extn)->compress_ctx =
553+
server_extn.compress_ctx;
554+
}
542555
net->extension = saved_extn;
543556
server_extn.compress_ctx.algorithm = MYSQL_UNCOMPRESSED;
544557

0 commit comments

Comments
 (0)