1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-07 02:42:49 +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

@@ -241,7 +241,98 @@ static int test_conc467(MYSQL *my __attribute__((unused)))
return rc;
}
static int test_conc592(MYSQL *my __attribute__((unused)))
{
MARIADB_RPL *rpl;
MYSQL *mysql= mysql_init(NULL);
MYSQL *mysql_check= mysql_init(NULL);
const char *host= "myhost";
MYSQL_RES *result;
MYSQL_ROW row;
int rc;
int found= 0;
mysql_optionsv(mysql, MARIADB_OPT_RPL_REGISTER_REPLICA, host, 123);
SKIP_SKYSQL;
SKIP_MAXSCALE;
if (!is_mariadb)
return SKIP;
if (!my_test_connect(mysql, hostname, username,
password, schema, port, socketname, 0))
{
diag("Error: %s", mysql_error(mysql));
mysql_close(mysql);
return FAIL;
}
if (!my_test_connect(mysql_check, hostname, username,
password, schema, port, socketname, 0))
{
diag("Error: %s", mysql_error(mysql));
mysql_close(mysql);
return FAIL;
}
rc= mysql_query(mysql, "SELECT @@log_bin");
check_mysql_rc(rc, mysql);
result= mysql_store_result(mysql);
row= mysql_fetch_row(result);
if (!atoi(row[0]))
rc= SKIP;
mysql_free_result(result);
if (rc == SKIP)
{
diag("binary log disabled -> skip");
mysql_close(mysql);
return SKIP;
}
rpl = mariadb_rpl_init(mysql);
mysql_query(mysql, "SET @mariadb_slave_capability=4");
mysql_query(mysql, "SET NAMES latin1");
mysql_query(mysql, "SET @slave_gtid_strict_mode=1");
mysql_query(mysql, "SET @slave_gtid_ignore_duplicates=1");
mysql_query(mysql, "SET NAMES utf8");
mysql_query(mysql, "SET @master_binlog_checksum= @@global.binlog_checksum");
mysql_query(mysql, "SET @rpl_semi_sync_slave=1");
rpl->server_id= 12;
rpl->start_position= 4;
rpl->flags= MARIADB_RPL_BINLOG_SEND_ANNOTATE_ROWS;
if (mariadb_rpl_open(rpl))
return FAIL;
rc= mysql_query(mysql_check, "SHOW SLAVE HOSTS");
check_mysql_rc(rc, mysql_check);
result= mysql_store_result(mysql_check);
while ((row= mysql_fetch_row(result)))
if (!strcmp(row[1], host))
found= 1;
mysql_free_result(result);
mysql_close(mysql);
mysql_close(mysql_check);
if (!found)
{
diag("Host '%s' not found in replica list", host);
return FAIL;
}
return OK;
}
struct my_tests_st my_tests[] = {
{"test_conc592", test_conc592, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"test_rpl_async", test_rpl_async, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"test_rpl_semisync", test_rpl_semisync, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"test_conc467", test_conc467, TEST_CONNECTION_NEW, 0, NULL, NULL},