MySQL 8.0.39
Source Code Documentation
clone_protocol_service.cc File Reference

Typedefs

template<typename T >
using DD_Objs = std::vector< const T * >
 
using Releaser = dd::cache::Dictionary_client::Auto_releaser
 
typedef std::array< std::string, CLONE_PARSE_ARRAY_SIZEParseArray
 Parsed version strings array type. More...
 

Functions

static void set_read_timeout (NET *net, uint32_t timeout)
 Set Network read timeout. More...
 
static void set_write_timeout (NET *net, uint32_t timeout)
 Set Network write timeout. More...
 
static void set_idle_timeout (NET *net, uint32_t timeout)
 Set Network idle timeout. More...
 
void mysql_clone_start_statement (THD *&thd, PSI_thread_key thread_key, PSI_statement_key statement_key) noexcept
 Start and set session and statement key form current thread. More...
 
void mysql_clone_finish_statement (THD *thd) noexcept
 Finish statement and session. More...
 
int mysql_clone_get_charsets (THD *thd, Mysql_Clone_Values &char_sets) noexcept
 Get all character set and collations. More...
 
int mysql_clone_validate_charsets (THD *thd, Mysql_Clone_Values &char_sets) noexcept
 Check if all characters sets are supported by server. More...
 
static int get_utf8_config (THD *thd, std::string config_name, String &utf8_val)
 Get configuration parameter value in utf8. More...
 
int mysql_clone_get_configs (THD *thd, Mysql_Clone_Key_Values &configs) noexcept
 Get system configuration parameter values. More...
 
static ParseArray parse_version_string (std::string version)
 Parse a version string into an array of strings corresponding to the MAJOR, MINOR, PATCH and BUILD versions. More...
 
static void test_configure_versions (std::string &config_val, std::string &donor_val)
 Test specific function to configure the version strings of the donor and recipient to cover various scenarios where clone is allowed or not. More...
 
bool compare_server_version (std::string ver1, std::string ver2)
 Compares versions and determine if clone is allowed. More...
 
int mysql_clone_validate_configs (THD *thd, Mysql_Clone_Key_Values &configs) noexcept
 Check if configuration parameter values match. More...
 
MYSQLmysql_clone_connect (THD *thd, const char *host, uint32_t port, const char *user, const char *passwd, mysql_clone_ssl_context *ssl_ctx, MYSQL_SOCKET *socket) noexcept
 Connect to a remote server and switch to clone protocol. More...
 
int mysql_clone_send_command (THD *thd, MYSQL *connection, bool set_active, uchar command, uchar *com_buffer, size_t buffer_length) noexcept
 Execute clone command on remote server. More...
 
int mysql_clone_get_response (THD *thd, MYSQL *connection, bool set_active, uint32_t timeout, uchar **packet, size_t *length, size_t *net_length) noexcept
 Get response from remote server. More...
 
int mysql_clone_kill (MYSQL *connection, MYSQL *kill_connection) noexcept
 Kill a remote connection. More...
 
void mysql_clone_disconnect (THD *thd, MYSQL *mysql, bool is_fatal, bool clear_error) noexcept
 Disconnect from a remote server. More...
 
void mysql_clone_get_error (THD *thd, uint32_t *err_num, const char **err_mesg) noexcept
 Get error number and message. More...
 
int mysql_clone_get_command (THD *thd, uchar *command, uchar **com_buffer, size_t *buffer_length) noexcept
 Get command from client. More...
 
int mysql_clone_send_response (THD *thd, bool secure, uchar *packet, size_t length) noexcept
 Send response to client. More...
 
int mysql_clone_send_error (THD *thd, uchar err_cmd, bool is_fatal) noexcept
 Send error to client. More...
 

Variables

static const uint32_t MIN_IDLE_TIME_OUT_SEC = 8 * 60 * 60
 The minimum idle timeout in seconds. More...
 
static const uint32_t MIN_READ_TIME_OUT_SEC = 30
 Minimum read timeout in seconds. More...
 
static const uint32_t MIN_WRITE_TIME_OUT_SEC = 60
 Minimum write timeout in seconds. More...
 
constexpr unsigned int CLONE_PARSE_ARRAY_SIZE = 4
 Size of the parsed version strings array. More...
 
constexpr unsigned int MAJOR = 0
 Index of the array correpsonding to parts of version. More...
 
constexpr unsigned int MINOR = 1
 
constexpr unsigned int PATCH = 2
 
constexpr unsigned int BUILD = 3
 
constexpr unsigned long CLONE_BACKPORT_VERSION = 37
 

Typedef Documentation

◆ DD_Objs

template<typename T >
using DD_Objs = std::vector<const T *>

◆ ParseArray

typedef std::array<std::string, CLONE_PARSE_ARRAY_SIZE> ParseArray

Parsed version strings array type.

◆ Releaser

Function Documentation

◆ compare_server_version()

bool compare_server_version ( std::string  ver1,
std::string  ver2 
)
inline

Compares versions and determine if clone is allowed.

Clone is allowed if both the donor and recipient have exactly same version string. In version series 8.1 and above, cloning is allowed if Major and Minor versions match. In 8.0 series, clone is allowed if patch version is above clone backport version. In this comparison, suffixes are ignored: i.e. 8.0.25 should be the same as 8.0.25-debug, but 8.0.25 isn't the same as 8.0.251

Parameters
ver1version1 string
ver2version2 string
Returns
true if cloning is allowed between ver1 and ver2, false otherwise

◆ get_utf8_config()

static int get_utf8_config ( THD thd,
std::string  config_name,
String utf8_val 
)
static

Get configuration parameter value in utf8.

Parameters
[in]thdserver session THD
[in]config_nameparameter name
[out]utf8_valparameter value in utf8 string
Returns
error code.

◆ mysql_clone_connect()

MYSQL * mysql_clone_connect ( THD thd,
const char *  host,
uint32_t  port,
const char *  user,
const char *  passwd,
mysql_clone_ssl_context ssl_ctx,
MYSQL_SOCKET socket 
)
noexcept

Connect to a remote server and switch to clone protocol.

Parameters
[in,out]thdserver session THD
[in]hosthost name to connect to
[in]portport number to connect to
[in]useruser name on remote host
[in]passwdpassword for the user
[in]ssl_ctxclient ssl context
[out]socketNetwork socket for the connection
Returns
Connection object if successful.

◆ mysql_clone_disconnect()

void mysql_clone_disconnect ( THD thd,
MYSQL mysql,
bool  is_fatal,
bool  clear_error 
)
noexcept

Disconnect from a remote server.

Parameters
[in,out]thdlocal session THD
[in,out]mysqlconnection object
[in]is_fatalif closing after fatal error
[in]clear_errorclear any earlier error in session

◆ mysql_clone_finish_statement()

void mysql_clone_finish_statement ( THD thd)
noexcept

Finish statement and session.

Parameters
[in,out]thdserver session THD

◆ mysql_clone_get_charsets()

int mysql_clone_get_charsets ( THD thd,
Mysql_Clone_Values char_sets 
)
noexcept

Get all character set and collations.

Parameters
[in,out]thdserver session THD
[out]char_setsall character set collations
Returns
error code.

◆ mysql_clone_get_command()

int mysql_clone_get_command ( THD thd,
uchar command,
uchar **  com_buffer,
size_t *  buffer_length 
)
noexcept

Get command from client.

Parameters
[in,out]thdserver session THD
[out]commandremote command
[out]com_bufferdata following command
[out]buffer_lengthdata length
Returns
error code.

◆ mysql_clone_get_configs()

int mysql_clone_get_configs ( THD thd,
Mysql_Clone_Key_Values configs 
)
noexcept

Get system configuration parameter values.

Parameters
[in,out]thdserver session THD
[in,out]configsa list of configuration key value pair keys are input and values are output
Returns
error code.

◆ mysql_clone_get_error()

void mysql_clone_get_error ( THD thd,
uint32_t *  err_num,
const char **  err_mesg 
)
noexcept

Get error number and message.

Parameters
[in,out]thdlocal session THD
[out]err_numerror number
[out]err_mesgerror message text

◆ mysql_clone_get_response()

int mysql_clone_get_response ( THD thd,
MYSQL connection,
bool  set_active,
uint32_t  timeout,
uchar **  packet,
size_t *  length,
size_t *  net_length 
)
noexcept

Get response from remote server.

Parameters
[in,out]thdlocal session THD
[in,out]connectionconnection object
[in]set_activeset socket active for current THD
[in]timeouttimeout in seconds
[out]packetresponse packet
[out]lengthpacket length
[out]net_lengthnetwork data length for compressed data
Returns
error code.

◆ mysql_clone_kill()

int mysql_clone_kill ( MYSQL connection,
MYSQL kill_connection 
)
noexcept

Kill a remote connection.

Parameters
[in,out]connectionconnection object
[in]kill_connectionconnection to kill
Returns
error code.

◆ mysql_clone_send_command()

int mysql_clone_send_command ( THD thd,
MYSQL connection,
bool  set_active,
uchar  command,
uchar com_buffer,
size_t  buffer_length 
)
noexcept

Execute clone command on remote server.

Parameters
[in,out]thdlocal session THD
[in,out]connectionconnection object
[in]set_activeset socket active for current THD
[in]commandremote command
[in]com_bufferdata following command
[in]buffer_lengthdata length
Returns
error code.

◆ mysql_clone_send_error()

int mysql_clone_send_error ( THD thd,
uchar  err_cmd,
bool  is_fatal 
)
noexcept

Send error to client.

Parameters
[in,out]thdserver session THD
[in]err_cmderror response command
[in]is_fatalif fatal error
Returns
error code.

◆ mysql_clone_send_response()

int mysql_clone_send_response ( THD thd,
bool  secure,
uchar packet,
size_t  length 
)
noexcept

Send response to client.

Parameters
[in,out]thdserver session THD
[in]secureneeds to be sent over secure connection
[in]packetresponse packet
[in]lengthpacket length
Returns
error code.

◆ mysql_clone_start_statement()

void mysql_clone_start_statement ( THD *&  thd,
PSI_thread_key  thread_key,
PSI_statement_key  statement_key 
)
noexcept

Start and set session and statement key form current thread.

Parameters
[in,out]thdserver session THD
[in]thread_keyPSI key for thread
[in]statement_keyPSI Key for statement

◆ mysql_clone_validate_charsets()

int mysql_clone_validate_charsets ( THD thd,
Mysql_Clone_Values char_sets 
)
noexcept

Check if all characters sets are supported by server.

Parameters
[in,out]thdserver session THD
[in]char_setsall character set collations to validate
Returns
error code.

◆ mysql_clone_validate_configs()

int mysql_clone_validate_configs ( THD thd,
Mysql_Clone_Key_Values configs 
)
noexcept

Check if configuration parameter values match.

Parameters
[in,out]thdserver session THD
[in]configsa list of configuration key value pair
Returns
error code.

◆ parse_version_string()

static ParseArray parse_version_string ( std::string  version)
static

Parse a version string into an array of strings corresponding to the MAJOR, MINOR, PATCH and BUILD versions.

A string of length 0 is filled in case a particular version string could not be parsed. For example, "Major.Minor.Patch-Build" yields ["Major", "Minor", "Patch", "Build"], "8.0.23-SR1" yields ["8", "0", "23", "SR1"], "8.0.-u5" yields ["8", "0", "", "u5"]

Note
: This function allocates the array, populates it and returns the array
Parameters
versioninput version string

◆ set_idle_timeout()

static void set_idle_timeout ( NET net,
uint32_t  timeout 
)
static

Set Network idle timeout.

Parameters
[in,out]netnetwork object
[in]timeouttime out in seconds

◆ set_read_timeout()

static void set_read_timeout ( NET net,
uint32_t  timeout 
)
static

Set Network read timeout.

Parameters
[in,out]netnetwork object
[in]timeouttime out in seconds

◆ set_write_timeout()

static void set_write_timeout ( NET net,
uint32_t  timeout 
)
static

Set Network write timeout.

Parameters
[in,out]netnetwork object
[in]timeouttime out in seconds

◆ test_configure_versions()

static void test_configure_versions ( std::string &  config_val,
std::string &  donor_val 
)
static

Test specific function to configure the version strings of the donor and recipient to cover various scenarios where clone is allowed or not.

This function will modify the input to ensure correct error message is printed.

Parameters
config_valrecipient server's version string
donor_valdonor server's version string

Variable Documentation

◆ BUILD

constexpr unsigned int BUILD = 3
constexpr

◆ CLONE_BACKPORT_VERSION

constexpr unsigned long CLONE_BACKPORT_VERSION = 37
constexpr

◆ CLONE_PARSE_ARRAY_SIZE

constexpr unsigned int CLONE_PARSE_ARRAY_SIZE = 4
constexpr

Size of the parsed version strings array.

◆ MAJOR

constexpr unsigned int MAJOR = 0
constexpr

Index of the array correpsonding to parts of version.

◆ MIN_IDLE_TIME_OUT_SEC

const uint32_t MIN_IDLE_TIME_OUT_SEC = 8 * 60 * 60
static

The minimum idle timeout in seconds.

It is kept at 8 hours which is also the Server default. Currently recipient sends ACK during state transition. In future we could have better time controlled ACK.

◆ MIN_READ_TIME_OUT_SEC

const uint32_t MIN_READ_TIME_OUT_SEC = 30
static

Minimum read timeout in seconds.

Maintain above the donor ACK frequency.

◆ MIN_WRITE_TIME_OUT_SEC

const uint32_t MIN_WRITE_TIME_OUT_SEC = 60
static

Minimum write timeout in seconds.

Disallow configuring it to too low. We might need a separate clone configuration in future or retry on failure.

◆ MINOR

constexpr unsigned int MINOR = 1
constexpr

◆ PATCH

constexpr unsigned int PATCH = 2
constexpr