Simplify initialization of replication
The users are now created on both the slaves as well as the master. This allows static binlog coordinates to be used on the slaves and the replication initialization boils down to a set of SQL queries.
This commit is contained in:
@ -30,4 +30,5 @@ DROP USER 'maxskysql'@'localhost';
|
|||||||
CREATE USER 'maxskysql'@'localhost' IDENTIFIED BY 'skysql';
|
CREATE USER 'maxskysql'@'localhost' IDENTIFIED BY 'skysql';
|
||||||
GRANT ALL ON *.* TO 'maxskysql'@'localhost' WITH GRANT OPTION;
|
GRANT ALL ON *.* TO 'maxskysql'@'localhost' WITH GRANT OPTION;
|
||||||
|
|
||||||
|
RESET MASTER;
|
||||||
EOF
|
EOF
|
||||||
|
@ -17,6 +17,16 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
static bool require_gtid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mariadb_nodes::require_gtid(bool value)
|
||||||
|
{
|
||||||
|
::require_gtid = value;
|
||||||
|
}
|
||||||
|
|
||||||
Mariadb_nodes::Mariadb_nodes(const char *pref, const char *test_cwd, bool verbose):
|
Mariadb_nodes::Mariadb_nodes(const char *pref, const char *test_cwd, bool verbose):
|
||||||
v51(false)
|
v51(false)
|
||||||
{
|
{
|
||||||
@ -350,7 +360,7 @@ int Mariadb_nodes::start_replication()
|
|||||||
char dtr[1024];
|
char dtr[1024];
|
||||||
int local_result = 0;
|
int local_result = 0;
|
||||||
|
|
||||||
// Start all nodes
|
// Start all nodes
|
||||||
for (int i = 0; i < N; i++)
|
for (int i = 0; i < N; i++)
|
||||||
{
|
{
|
||||||
if (start_node(i, (char *) ""))
|
if (start_node(i, (char *) ""))
|
||||||
@ -361,71 +371,30 @@ int Mariadb_nodes::start_replication()
|
|||||||
local_result += start_node(i, (char *) "");
|
local_result += start_node(i, (char *) "");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("trying to get version\n");
|
|
||||||
if (connect(i))
|
|
||||||
{
|
|
||||||
printf("Connect attempt to node %d failed\n", i);
|
|
||||||
}
|
|
||||||
get_version(i);
|
|
||||||
close_connections();
|
|
||||||
printf("Node %d: Version is %s\n", i, version_major[i]);
|
|
||||||
if (strcmp(version_major[i], "5.5") == 0)
|
|
||||||
{
|
|
||||||
ssh_node_f(i, true,
|
|
||||||
"mysql --force -u root %s -e \"STOP SLAVE; RESET SLAVE; RESET MASTER; SET GLOBAL read_only=OFF;\"",
|
|
||||||
socket_cmd[i]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ssh_node_f(i, true,
|
|
||||||
"mysql --force -u root %s -e \"STOP SLAVE; STOP ALL SLAVES; RESET SLAVE; RESET SLAVE ALL; RESET MASTER; SET GLOBAL read_only=OFF;\"",
|
|
||||||
socket_cmd[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
ssh_node_f(i, true, "sudo rm -f /etc/my.cnf.d/kerb.cnf");
|
ssh_node_f(i, true, "sudo rm -f /etc/my.cnf.d/kerb.cnf");
|
||||||
ssh_node_f(i, true,
|
|
||||||
"for i in `mysql -ss --force -u root %s -e \"SHOW DATABASES\"|grep -iv 'mysql\\|information_schema\\|performance_schema'`; "
|
// Create users for replication as well as the users that are used by the tests
|
||||||
"do mysql --force -u root %s -e \"DROP DATABASE $i\";"
|
sprintf(str, "%s/create_user.sh", test_dir);
|
||||||
"done", socket_cmd[i], socket_cmd[i]);
|
sprintf(dtr, "%s", access_homedir[i]);
|
||||||
|
copy_to_node(i, str, dtr);
|
||||||
|
ssh_node_f(i, false, "export node_user=\"%s\"; export node_password=\"%s\"; %s/create_user.sh %s",
|
||||||
|
user_name, password, access_homedir[0], socket_cmd[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(str, "%s/create_user.sh", test_dir);
|
connect();
|
||||||
sprintf(dtr, "%s", access_homedir[0]);
|
|
||||||
copy_to_node(0, str, dtr);
|
|
||||||
ssh_node_f(0, false, "export node_user=\"%s\"; export node_password=\"%s\"; %s/create_user.sh %s",
|
|
||||||
user_name, password, access_homedir[0], socket_cmd[0]);
|
|
||||||
|
|
||||||
// Create a database dump from the master and distribute it to the slaves
|
|
||||||
if (version_major[0][0] == '5')
|
|
||||||
{
|
|
||||||
printf("Version 5 on master detected, do not use --gtid flag for mysqldump\n");
|
|
||||||
ssh_node_f(0, true, "mysql --force -u root %s -e \"CREATE DATABASE test\"; "
|
|
||||||
"mysqldump --all-databases --add-drop-database --flush-privileges --master-data=1 %s > /tmp/master_backup.sql",
|
|
||||||
socket_cmd[0], socket_cmd[0]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ssh_node_f(0, true, "mysql --force -u root %s -e \"CREATE DATABASE test\"; "
|
|
||||||
"mysqldump --all-databases --add-drop-database --flush-privileges --master-data=1 --gtid %s > /tmp/master_backup.sql",
|
|
||||||
socket_cmd[0], socket_cmd[0]);
|
|
||||||
}
|
|
||||||
sprintf(str, "%s/master_backup.sql", test_dir);
|
|
||||||
copy_from_node(0, "/tmp/master_backup.sql", str);
|
|
||||||
|
|
||||||
for (int i = 1; i < N; i++)
|
for (int i = 1; i < N; i++)
|
||||||
{
|
{
|
||||||
// Reset all nodes by first loading the dump and then starting the replication
|
// TODO: Reuse the code in sync_slaves() to get the actual file name and position
|
||||||
printf("Setting node %d\n", i);
|
execute_query(nodes[i], "STOP SLAVE;"
|
||||||
fflush(stdout);
|
"CHANGE MASTER TO "
|
||||||
copy_to_node(i, str, "/tmp/master_backup.sql");
|
"MASTER_HOST='%s', MASTER_PORT=%d, "
|
||||||
ssh_node_f(i, true, "mysql --force -u root %s -e \"STOP SLAVE;\"",
|
"MASTER_USER='repl', MASTER_PASSWORD='repl', "
|
||||||
socket_cmd[i]);
|
"%s;"
|
||||||
ssh_node_f(i, true, "mysql --force -u root %s < /tmp/master_backup.sql",
|
"START SLAVE;",
|
||||||
socket_cmd[i]);
|
IP_private[0], port[0], require_gtid ?
|
||||||
printf("change master to...\n");
|
"MASTER_USE_GTID=slave_pos" :
|
||||||
ssh_node_f(i, true, "mysql --force -u root %s -e \"CHANGE MASTER TO MASTER_HOST=\\\"%s\\\", MASTER_PORT=%d, "
|
"MASTER_LOG_FILE='mar-bin.000001', MASTER_LOG_POS=4");
|
||||||
"MASTER_USER=\\\"repl\\\", MASTER_PASSWORD=\\\"repl\\\";"
|
|
||||||
"START SLAVE;\"", socket_cmd[i], IP_private[0], port[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return local_result;
|
return local_result;
|
||||||
|
@ -411,6 +411,12 @@ public:
|
|||||||
virtual int prepare_server(int i);
|
virtual int prepare_server(int i);
|
||||||
int prepare_servers();
|
int prepare_servers();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Whether to require GTID based replication, defaults to false */
|
||||||
|
static void require_gtid(bool value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user