1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-08 14:02:17 +03:00

CONC-592: Register replica with host and port

Added new option MARIADB_OPT_RPL_REGISTER_REPLICA which expects
two parameters, host and port. When this option was set, rpl_open
will send a COM_REGISTER_SLAVE command with server_id, host and
port to the connected server. This information can be retrieved
by "SHOW SLAVE STATUS" command.

Example:

rc= mysql_optionsv(mysql, MARIADB_OPT_RPL_REGISTER_REPLICA,
                   "myhost", 123);
This commit is contained in:
Georg Richter
2022-05-23 14:05:06 +02:00
parent 5e94e7c27f
commit fcce4a8c76
5 changed files with 152 additions and 4 deletions

View File

@@ -38,6 +38,7 @@
#include <signal.h>
#include <time.h>
#include <mariadb_dyncol.h>
#include <mariadb_rpl.h>
#ifndef __has_feature
# define __has_feature(x) 0
@@ -704,7 +705,7 @@ struct st_default_options mariadb_defaults[] =
(OPTS)->extension= (struct st_mysql_options_extension *) \
calloc(1, sizeof(struct st_mysql_options_extension));
#define OPT_SET_EXTENDED_VALUE_BIN(OPTS, KEY, KEY_LEN, VAL, LEN) \
#define OPT_SET_EXTENDED_VALUE_BIN(OPTS, KEY, KEY_LEN, VAL, LEN)\
CHECK_OPT_EXTENSION_SET(OPTS) \
free((gptr)(OPTS)->extension->KEY); \
if((VAL) && (LEN)) { \
@@ -719,7 +720,7 @@ struct st_default_options mariadb_defaults[] =
#define OPT_SET_EXTENDED_VALUE_STR(OPTS, KEY, VAL) \
CHECK_OPT_EXTENSION_SET(OPTS) \
free((gptr)(OPTS)->extension->KEY); \
if((VAL)) \
if((VAL)) \
(OPTS)->extension->KEY= strdup((char *)(VAL)); \
else \
(OPTS)->extension->KEY= NULL
@@ -2280,6 +2281,7 @@ static void mysql_close_options(MYSQL *mysql)
if (ma_hashtbl_inited(&mysql->options.extension->userdata))
ma_hashtbl_free(&mysql->options.extension->userdata);
free(mysql->options.extension->restricted_auth);
free(mysql->options.extension->rpl_host);
}
free(mysql->options.extension);
@@ -3654,6 +3656,13 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...)
case MARIADB_OPT_RESTRICTED_AUTH:
OPT_SET_EXTENDED_VALUE_STR(&mysql->options, restricted_auth, (char *)arg1);
break;
case MARIADB_OPT_RPL_REGISTER_REPLICA:
{
unsigned int arg2 = va_arg(ap, unsigned int);
OPT_SET_EXTENDED_VALUE_STR(&mysql->options, rpl_host,(char *)arg1);
OPT_SET_EXTENDED_VALUE(&mysql->options, rpl_port, (ushort)arg2);
}
break;
default:
va_end(ap);
SET_CLIENT_ERROR(mysql, CR_NOT_IMPLEMENTED, SQLSTATE_UNKNOWN, 0);