Skip to content

Commit 13690e4

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

File tree

7 files changed

+108
-0
lines changed

7 files changed

+108
-0
lines changed

include/mysql/components/services/clone_protocol_service.h

+2
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

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;
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

+7
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

@@ -111,6 +115,9 @@ const uint CLONE_MIN_BLOCK = 1024 * 1024;
111115
/** Minimum network packet. Safe margin for meta information */
112116
const uint CLONE_MIN_NET_BLOCK = 2 * CLONE_MIN_BLOCK;
113117

118+
/** Clone compression algorithms to use */
119+
extern const char *clone_compression_algorithms[3];
120+
114121
/* Namespace for all clone data types */
115122
namespace myclone {
116123

plugin/clone/src/clone_client.cc

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Clone Plugin: Client implementation
2727
*/
2828
#include <inttypes.h>
2929

30+
#include "plugin/clone/include/clone.h"
3031
#include "plugin/clone/include/clone_client.h"
3132
#include "plugin/clone/include/clone_os.h"
3233

@@ -896,6 +897,13 @@ int Client::connect_remote(bool is_restart, bool use_aux) {
896897
mysql_clone_ssl_context ssl_context;
897898

898899
ssl_context.m_enable_compression = clone_enable_compression;
900+
901+
if (ssl_context.m_enable_compression) {
902+
ssl_context.m_compression_algorithm =
903+
clone_compression_algorithms[clone_compression_algorithm];
904+
ssl_context.m_compression_level = clone_zstd_compression_level;
905+
}
906+
899907
ssl_context.m_server_extn =
900908
ssl_context.m_enable_compression ? &m_conn_server_extn : nullptr;
901909
ssl_context.m_ssl_mode = m_share->m_ssl_mode;

plugin/clone/src/clone_plugin.cc

+27
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,27 @@ 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+
const char *clone_compression_algorithms[] = {"ZLIB", "ZSTD", NullS};
645+
646+
static TYPELIB clone_compression_algorithms_typelib = {
647+
array_elements(clone_compression_algorithms) - 1,
648+
"clone_compression_algorithms_typelib",
649+
clone_compression_algorithms, nullptr};
650+
651+
static MYSQL_SYSVAR_ENUM(compression_algorithm, clone_compression_algorithm,
652+
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_MEMALLOC,
653+
"compression algorithm used in clone", nullptr,
654+
nullptr, enum_clone_compression_algorithm::ZSTD,
655+
&clone_compression_algorithms_typelib);
656+
657+
static MYSQL_SYSVAR_UINT(zstd_compression_level, clone_zstd_compression_level,
658+
PLUGIN_VAR_NOCMDARG, "zstd compression level", nullptr,
659+
nullptr, 3, /* Default */
660+
1, /* Minimum */
661+
10, /* Maximum */
662+
1);
663+
639664
/** List of valid donor addresses allowed to clone from. */
640665
static MYSQL_SYSVAR_STR(valid_donor_list, clone_valid_donor_list,
641666
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_MEMALLOC,
@@ -705,6 +730,8 @@ static SYS_VAR *clone_system_variables[] = {
705730
MYSQL_SYSVAR(ssl_cert),
706731
MYSQL_SYSVAR(ssl_ca),
707732
MYSQL_SYSVAR(donor_timeout_after_network_failure),
733+
MYSQL_SYSVAR(compression_algorithm),
734+
MYSQL_SYSVAR(zstd_compression_level),
708735
nullptr};
709736

710737
/** Declare clone plugin */

sql/server_component/clone_protocol_service.cc

+13
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 && server_extn.compress_ctx.algorithm == MYSQL_ZSTD) {
552+
static_cast<NET_SERVER *>(saved_extn)->compress_ctx.u.zstd_ctx =
553+
static_cast<NET_SERVER *>(net->extension)->compress_ctx.u.zstd_ctx;
554+
}
542555
net->extension = saved_extn;
543556
server_extn.compress_ctx.algorithm = MYSQL_UNCOMPRESSED;
544557

0 commit comments

Comments
 (0)