Skip to content

Commit bc94ade

Browse files
committed
WL#13510 COMPRESSION PROTOCOL FOR ASYNC CLIENT
Description ----------- This worklog adds support of compression protocol for asynchronous clients. it does not change the wire format used in compressing packets for the usual clients. User need to set the compression algorithm name and if supported compression level in the asynchronous client to able the packets compression. For instance : ------------- if (mysql_options(mysql_local, MYSQL_OPT_COMPRESSION_ALGORITHMS, "zstd")) exit(1); if (mysql_options(mysql_local, MYSQL_OPT_ZSTD_COMPRESSION_LEVEL, 4)) exit(1); if(mysql_real_connect(mysql_local, opt_host, opt_user, opt_password, current_db, opt_port, opt_unix_socket, client_flag)) exit(1); stmt_text = "SELECT col2 FROM test_table"; /* run query in asynchronous way */ status = mysql_real_query_nonblocking(mysql_local, stmt_text, (ulong)strlen(stmt_text)); /* do some other task */ perform_arithmatic(); while (status == NET_ASYNC_NOT_READY) { status = mysql_real_query_nonblocking(mysql_local, stmt_text, (ulong)strlen(stmt_text)); } Testing ------- - Added following two tests in the testclients/mysql_client_test.cc. 1. test_wl13510() 2. test_wl13510_multi_statements() Above two tests are verified through main.mysql_client_test file. - Added MTR test file main.async_compress_client.test - Improved the existing big packet tests and added scenarios for testing with Nonblocking as well as Nonblocking compress clients. Worklog PB2 page - mysql-trunk-wl13510 Review ------ RB#23665
1 parent 7f9e429 commit bc94ade

29 files changed

+1703
-340
lines changed

client/mysqltest.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6452,10 +6452,6 @@ static void do_connect(struct st_command *command) {
64526452
opt_protocol = MYSQL_PROTOCOL_PIPE;
64536453
}
64546454

6455-
if (opt_compress || con_compress) {
6456-
enable_async_client = false;
6457-
}
6458-
64596455
if (opt_protocol) {
64606456
mysql_options(&con_slot->mysql, MYSQL_OPT_PROTOCOL, (char *)&opt_protocol);
64616457
/*
@@ -9173,9 +9169,6 @@ int main(int argc, char **argv) {
91739169
opt_ssl_mode = SSL_MODE_VERIFY_CA;
91749170
}
91759171

9176-
if (opt_compress) {
9177-
enable_async_client = false;
9178-
}
91799172
if (SSL_SET_OPTIONS(&con->mysql)) die("%s", SSL_SET_OPTIONS_ERROR);
91809173
#if defined(_WIN32)
91819174
if (shared_memory_base_name)

include/errmsg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ extern const char *client_errors[]; /* Error messages */
123123
#define CR_INSECURE_API_ERR 2062
124124
#define CR_FILE_NAME_TOO_LONG 2063
125125
#define CR_SSL_FIPS_MODE_ERR 2064
126-
#define CR_COMPRESSION_NOT_SUPPORTED 2065
126+
#define CR_DEPRECATED_COMPRESSION_NOT_SUPPORTED 2065
127127
#define CR_COMPRESSION_WRONGLY_CONFIGURED 2066
128128
#define CR_KERBEROS_USER_NOT_FOUND 2067
129129
#define CR_LOAD_DATA_LOCAL_INFILE_REJECTED 2068

include/mysql_async.h

Lines changed: 99 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -23,54 +23,55 @@
2323
#ifndef MYSQL_ASYNC_INCLUDED
2424
#define MYSQL_ASYNC_INCLUDED
2525

26-
#define MYSQL_ASYNC_INCLUDED
27-
2826
#include <mysql.h>
2927

30-
/*
31-
NOTE:this file should not be included as part of packaging.
28+
/**
29+
@file mysql_async.h
30+
31+
Declarations for asynchronous client communication.
32+
33+
@note this file should not be included as part of packaging.
3234
*/
33-
/* Async MySQL extension fields here. */
3435

35-
/*
36+
/**
3637
This enum is to represent different asynchronous operations like reading the
3738
network, writing to network, idle state, or complete state.
3839
*/
3940
enum net_async_operation {
40-
NET_ASYNC_OP_IDLE = 0, /* default state */
41-
NET_ASYNC_OP_READING, /* used by my_net_read calls */
42-
NET_ASYNC_OP_WRITING, /* used by my_net_write calls */
43-
NET_ASYNC_OP_COMPLETE /* network read or write is complete */
41+
NET_ASYNC_OP_IDLE = 0, /**< default state */
42+
NET_ASYNC_OP_READING, /**< used by my_net_read calls */
43+
NET_ASYNC_OP_WRITING, /**< used by my_net_write calls */
44+
NET_ASYNC_OP_COMPLETE /**< network read or write is complete */
4445
};
4546

46-
/* Reading a packet is a multi-step process, so we have a state machine. */
47+
/** Reading a packet is a multi-step process, so we have a state machine. */
4748
enum net_async_read_packet_state {
48-
NET_ASYNC_PACKET_READ_IDLE = 0, /* default packet read state */
49-
NET_ASYNC_PACKET_READ_HEADER, /* read packet header */
50-
NET_ASYNC_PACKET_READ_BODY, /* read packet contents */
51-
NET_ASYNC_PACKET_READ_COMPLETE /* state to define if packet is
52-
completely read */
49+
NET_ASYNC_PACKET_READ_IDLE = 0, /**< default packet read state */
50+
NET_ASYNC_PACKET_READ_HEADER, /**< read packet header */
51+
NET_ASYNC_PACKET_READ_BODY, /**< read packet contents */
52+
NET_ASYNC_PACKET_READ_COMPLETE /**< state to define if packet is
53+
completely read */
5354
};
5455

55-
/* Different states when reading a query result. */
56+
/** Different states when reading a query result. */
5657
enum net_read_query_result_status {
57-
NET_ASYNC_READ_QUERY_RESULT_IDLE = 0, /* default state */
58-
NET_ASYNC_READ_QUERY_RESULT_FIELD_COUNT, /* read Ok or read field
59-
count sent as part of
60-
COM_QUERY */
61-
NET_ASYNC_READ_QUERY_RESULT_FIELD_INFO /* read result of above
62-
COM_* command */
58+
NET_ASYNC_READ_QUERY_RESULT_IDLE = 0, /**< default state */
59+
NET_ASYNC_READ_QUERY_RESULT_FIELD_COUNT, /**< read Ok or read field
60+
count sent as part of
61+
COM_QUERY */
62+
NET_ASYNC_READ_QUERY_RESULT_FIELD_INFO /**< read result of above
63+
COM_* command */
6364
};
6465

65-
/* Sending a command involves the write as well as reading the status. */
66+
/** Sending a command involves the write as well as reading the status. */
6667
enum net_send_command_status {
67-
NET_ASYNC_SEND_COMMAND_IDLE = 0, /* default send command state */
68-
NET_ASYNC_SEND_COMMAND_WRITE_COMMAND, /* send COM_* command */
69-
NET_ASYNC_SEND_COMMAND_READ_STATUS /* read result of above COM_*
70-
command */
68+
NET_ASYNC_SEND_COMMAND_IDLE = 0, /**< default send command state */
69+
NET_ASYNC_SEND_COMMAND_WRITE_COMMAND, /**< send COM_* command */
70+
NET_ASYNC_SEND_COMMAND_READ_STATUS /**< read result of above COM_*
71+
command */
7172
};
7273

73-
/*
74+
/**
7475
Async operations are broadly classified into 3 phases:
7576
Connection phase, phase of sending data to server (which is writing phase)
7677
and reading data from server (which is reading phase). Below enum describes
@@ -82,49 +83,93 @@ enum net_async_block_state {
8283
NET_NONBLOCKING_WRITE
8384
};
8485

86+
/**
87+
Represents the packet to be sent on wire asynchronously.
88+
*/
8589
struct io_vec {
86-
void *iov_base; /* Starting address */
87-
size_t iov_len; /* Number of bytes to transfer */
90+
void *iov_base; /**< Starting address */
91+
size_t iov_len; /**< Number of bytes to transfer */
8892
};
8993

9094
typedef struct NET_ASYNC {
91-
/* The position in buff we continue reads from when data is next available */
95+
/**
96+
The position in buff we continue reads from when data is next
97+
available
98+
*/
9299
unsigned char *cur_pos;
93100
/** Blocking state */
94101
enum net_async_block_state async_blocking_state;
95102
/** Our current operation */
96103
enum net_async_operation async_operation;
97104
/** How many bytes we want to read */
98105
size_t async_bytes_wanted;
99-
/*
106+
/**
100107
Simple state to know if we're reading the first row, and
101108
command/query statuses.
102109
*/
103110
bool read_rows_is_first_read;
104111
enum net_send_command_status async_send_command_status;
105112
enum net_read_query_result_status async_read_query_result_status;
106113

107-
/* State when waiting on an async read */
114+
/** State when waiting on an async read */
108115
enum net_async_read_packet_state async_packet_read_state;
109-
/* Size of the packet we're currently reading */
116+
/** Size of the packet we're currently reading */
110117
size_t async_packet_length;
111118

112-
/*
119+
/**
113120
Headers and vector for our async writes; see net_serv.c for
114121
detailed description.
115122
*/
116123
unsigned char *async_write_headers;
117124
struct io_vec *async_write_vector;
118125
size_t async_write_vector_size;
119126
size_t async_write_vector_current;
120-
unsigned char
121-
inline_async_write_header[NET_HEADER_SIZE + COMP_HEADER_SIZE + 1 + 1];
127+
128+
/**
129+
If the packet length is less than MAX_PACKET_LENGTH then use a static array
130+
to hold the meta packet header. The array either holds the usual packet
131+
header or a compressed meta packet header as following. The compressed
132+
meta packet header is followwed by usual compresses packet heder that is
133+
7 bytes in length.
134+
135+
136+
Packet
137+
138+
Header
139+
~~~~~~~~~~~~~~~~~~~
140+
B1 B2 B3 : Packet length
141+
B4 : Packet number
142+
~~~~~~~~~~~~~~~~~~~
143+
144+
Payload
145+
~~~~~~~~~~~~~~~~~~~
146+
B5 : COM_COMMAND
147+
~~~~~~~~~~~~~~~~~~~
148+
149+
Compressed Packet
150+
151+
Header
152+
~~~~~~~~~~~~~~~~~~~
153+
B1 B2 B3 : Compress packet length
154+
B4 : Compress Packet Nunmber
155+
00 00 00 : Indicates following payload is uncompressed
156+
~~~~~~~~~~~~~~~~~~~
157+
158+
Payload
159+
~~~~~~~~~~~~~~~~~~~
160+
B8 B9 B10 : Packet size
161+
B11 : Packet number
162+
B12 : COM_COMMAND
163+
~~~~~~~~~~~~~~~~~~~
164+
*/
165+
unsigned char inline_async_write_header[NET_HEADER_SIZE + COMP_HEADER_SIZE +
166+
NET_HEADER_SIZE + 1];
122167
struct io_vec inline_async_write_vector[3];
123168

124-
/* State for reading responses that are larger than MAX_PACKET_LENGTH */
125-
unsigned long async_multipacket_read_saved_whereb;
126-
unsigned long async_multipacket_read_total_len;
127-
bool async_multipacket_read_started;
169+
/** Keep track of compressed buffers */
170+
unsigned char **compressed_write_buffers;
171+
/** Size of the compressed buffer */
172+
size_t compressed_buffers_size;
128173
} NET_ASYNC;
129174

130175
struct NET_EXTENSION {
@@ -141,7 +186,7 @@ void net_extension_free(NET *);
141186
#define NET_ASYNC_DATA(M) \
142187
((NET_EXTENSION_PTR(M)) ? (NET_EXTENSION_PTR(M)->net_async_context) : NULL)
143188

144-
/*
189+
/**
145190
Asynchronous operations are broadly classified into 2 categories.
146191
1. Connection
147192
2. Query execution
@@ -153,7 +198,7 @@ enum mysql_async_operation_status {
153198
ASYNC_OP_QUERY
154199
};
155200

156-
/*
201+
/**
157202
Query execution in an asynchronous fashion is broadly divided into 3 states
158203
which is described in below enum
159204
*/
@@ -164,24 +209,24 @@ enum mysql_async_query_state_enum {
164209
};
165210

166211
typedef struct MYSQL_ASYNC {
167-
/* Buffer storing the rows result for cli_read_rows_nonblocking */
212+
/** Buffer storing the rows result for cli_read_rows_nonblocking */
168213
MYSQL_DATA *rows_result_buffer;
169-
/* a pointer to keep track of the previous row of the current result row */
214+
/** a pointer to keep track of the previous row of the current result row */
170215
MYSQL_ROWS **prev_row_ptr;
171-
/* Context needed to track the state of a connection being established */
216+
/** Context needed to track the state of a connection being established */
172217
struct mysql_async_connect *connect_context;
173-
/* Status of the current async op */
218+
/** Status of the current async op */
174219
enum mysql_async_operation_status async_op_status;
175-
/* Size of the current running async query */
220+
/** Size of the current running async query */
176221
size_t async_query_length;
177-
/* If a query is running, this is its state */
222+
/** If a query is running, this is its state */
178223
enum mysql_async_query_state_enum async_query_state;
179-
/* context needed to support metadata read operation */
224+
/** context needed to support metadata read operation */
180225
unsigned long *async_read_metadata_field_len;
181226
MYSQL_FIELD *async_read_metadata_fields;
182227
MYSQL_ROWS async_read_metadata_data;
183228
unsigned int async_read_metadata_cur_field;
184-
/* a pointer to keep track of the result sets */
229+
/** a pointer to keep track of the result sets */
185230
struct MYSQL_RES *async_store_result_result;
186231
} MYSQL_ASYNC;
187232

@@ -192,8 +237,7 @@ enum net_async_status net_write_command_nonblocking(
192237
NET *net, unsigned char command, const unsigned char *prefix,
193238
size_t prefix_len, const unsigned char *packet, size_t packet_len,
194239
bool *res);
195-
enum net_async_status my_net_read_nonblocking(NET *net, unsigned long *len_ptr,
196-
unsigned long *complen_ptr);
240+
enum net_async_status my_net_read_nonblocking(NET *net, unsigned long *len_ptr);
197241

198242
int mysql_get_socket_descriptor(MYSQL *mysql);
199243

mysql-test/r/async_client.result

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ CREATE TABLE t1(i INT, j VARCHAR(2048));
1414
INSERT INTO t1 VALUES(1,repeat('a',1000)),(2,repeat('def',600));
1515
SELECT * FROM t1;
1616
i j
17-
1 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
18-
2 defdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdef
17+
count big_value
18+
count big_value
1919
# case2: request a large packet
2020
SET GLOBAL max_allowed_packet=4*1024;
2121
Warnings:
2222
Warning 1708 The value of 'max_allowed_packet' should be no less than the value of 'net_buffer_length'
2323
SELECT SPACE(@@global.max_allowed_packet);
2424
SPACE(@@global.max_allowed_packet)
25-
25+
lot_of_spaces
2626
SET GLOBAL max_allowed_packet=default;
2727
# connect with wrong password
2828
connect(localhost,caching_sha2,caching1,wl11381,MASTER_PORT,MASTER_SOCKET);
@@ -64,7 +64,7 @@ caching_sha2@localhost
6464
# case3: authenticate user with sha256_password
6565
CREATE USER sha256@localhost IDENTIFIED WITH 'sha256_password' BY 'auth_string';
6666
# restart: --default-authentication-plugin=sha256_password
67-
# connect as sha256
67+
# connect as sha256
6868
SELECT USER();
6969
USER()
7070
sha256@localhost

0 commit comments

Comments
 (0)