| 1 |
## Create connection to clone instance optionally restarting instance with |
| 2 |
## monitoring process. |
| 3 |
|
| 4 |
# These variables can to be set before sourcing this file. Currently we used |
| 5 |
# to test both with and without monitoring process. |
| 6 |
# |
| 7 |
# 1. Need to restart mysqld with monitoring process |
| 8 |
# --let inst_monitor = 1 |
| 9 |
# |
| 10 |
# 2. Mysqld server instance number for clone |
| 11 |
# --let clone_inst_number = <instance number> 1/2/3 ... |
| 12 |
# - Instances must be configured in .cnf |
| 13 |
# - SERVER_PORT_[n] ENV must be set to server PORT in .cnf |
| 14 |
# |
| 15 |
# 3. Mysqld user name for connecting to the instance. |
| 16 |
# --let clone_user = <user_name> |
| 17 |
# |
| 18 |
# 4. Number of connections to be created to the instance |
| 19 |
# --let clone_connections = <number of connections> 1/2/3 ... |
| 20 |
# Connections have the name as clone_conn_<number> |
| 21 |
# e.g. clone_conn_1, clone_conn_2, clone_conn_3 etc. |
| 22 |
# |
| 23 |
# This script should be used in pair with clone_connection_end.inc |
| 24 |
# --source clone_connection_begin.inc |
| 25 |
# ... |
| 26 |
# --source clone_connection_end.inc |
| 27 |
|
| 28 |
if (!$clone_user) { |
| 29 |
--let $clone_user = 'root' |
| 30 |
} |
| 31 |
|
| 32 |
if (!$clone_connections) { |
| 33 |
--let $clone_connections = 1 |
| 34 |
} |
| 35 |
|
| 36 |
if ($clone_inst_number) { |
| 37 |
--let $clone_port= \$SERVER_PORT_$clone_inst_number |
| 38 |
--connect (clone_conn_1, 127.0.0.1, $clone_user,,test,$clone_port) |
| 39 |
} |
| 40 |
|
| 41 |
if (!$clone_inst_number) { |
| 42 |
--connection default |
| 43 |
} |
| 44 |
|
| 45 |
# Get Server ID |
| 46 |
--let $SERVER_ID= `SELECT @@server_id` |
| 47 |
|
| 48 |
if ($clone_inst_number) { |
| 49 |
if ($SERVER_ID == 1) { |
| 50 |
--disconnect clone_conn_1 |
| 51 |
--connection default |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
if ($SERVER_ID != 1) { |
| 56 |
--echo Install clone plugin on recipient server |
| 57 |
--replace_result $CLONE_PLUGIN CLONE_PLUGIN |
| 58 |
--eval INSTALL PLUGIN clone SONAME '$CLONE_PLUGIN' |
| 59 |
} |
| 60 |
|
| 61 |
# A. Check if we need monitoring process. Taken from mysqld_safe.test |
| 62 |
if ($inst_monitor) { |
| 63 |
|
| 64 |
# 1. Set variables to be used in parameters of mysqld_safe. |
| 65 |
--let $SERVER_ID= `SELECT @@server_id` |
| 66 |
--let $MYSQLD_DATADIR= `SELECT @@datadir` |
| 67 |
--let $MYSQL_BASEDIR= `SELECT @@basedir` |
| 68 |
--let $MYSQL_MESSAGESDIR= `SELECT @@lc_messages_dir` |
| 69 |
|
| 70 |
--let $MYSQL_PIDFILE= `SELECT @@pid_file` |
| 71 |
--let $MYSQL_SOCKET= `SELECT @@socket` |
| 72 |
--let $MYSQLX_SOCKET= `SELECT @@mysqlx_socket` |
| 73 |
--let $MYSQL_PORT= `SELECT @@port` |
| 74 |
--let $MYSQLX_PORT= `SELECT @@mysqlx_port` |
| 75 |
--let $MYSQL_PLUGIN_DIR = `SELECT @@plugin_dir` |
| 76 |
|
| 77 |
--let $page_size= `select @@innodb_page_size` |
| 78 |
--let $error_verbosity = `select @@log_error_verbosity` |
| 79 |
|
| 80 |
# mysqld_path to be passed to --ledir |
| 81 |
perl; |
| 82 |
my $dir = $ENV{'MYSQLTEST_VARDIR'}; |
| 83 |
open ( OUTPUT, ">$dir/tmp/mysqld_path_file.inc") ; |
| 84 |
my $path = $ENV{MYSQLD}; |
| 85 |
$path =~ /^(.*)\/([^\/]*)$/; |
| 86 |
print OUTPUT "let \$mysqld_path = $1;\n"; |
| 87 |
print OUTPUT "let \$mysqld_bin = $2;\n"; |
| 88 |
close (OUTPUT); |
| 89 |
EOF |
| 90 |
|
| 91 |
# Get the value of the variable to MTR, from perl |
| 92 |
--source $MYSQLTEST_VARDIR/tmp/mysqld_path_file.inc |
| 93 |
|
| 94 |
# Remove the temp file |
| 95 |
--remove_file $MYSQLTEST_VARDIR/tmp/mysqld_path_file.inc |
| 96 |
|
| 97 |
# 2. Shutdown mysqld instance which is started by mtr. |
| 98 |
--let $_expect_file_name= $MYSQLTEST_VARDIR/tmp/mysqld.$SERVER_ID.expect |
| 99 |
--exec echo "wait" > $_expect_file_name |
| 100 |
--shutdown_server |
| 101 |
--source include/wait_until_disconnected.inc |
| 102 |
|
| 103 |
# 3. Run mysqld_safe script |
| 104 |
--exec sh $MYSQLD_SAFE --defaults-file=$MYSQLTEST_VARDIR/my.cnf --server-id=$SERVER_ID --log-error=$MYSQLTEST_VARDIR/log/mysqld.$SERVER_ID.err --log-error-verbosity=$error_verbosity --basedir=$MYSQL_BASEDIR --ledir=$mysqld_path --mysqld=$mysqld_bin --datadir=$MYSQLD_DATADIR --socket=$MYSQL_SOCKET --mysqlx_socket=$MYSQLX_SOCKET --pid-file=$MYSQL_PIDFILE --port=$MYSQL_PORT --mysqlx_port=$MYSQLX_PORT --plugin_dir=$MYSQL_PLUGIN_DIR --timezone=SYSTEM --log-output=file --secure-file-priv="" --core-file --lc-messages-dir=$MYSQL_MESSAGESDIR --innodb-page-size=$page_size < /dev/null > /dev/null 2>&1 & |
| 105 |
--enable_reconnect |
| 106 |
--source include/wait_until_connected_again.inc |
| 107 |
--disable_reconnect |
| 108 |
} |
| 109 |
|
| 110 |
# B. Create the connections |
| 111 |
--let $conn_nummber = 1 |
| 112 |
|
| 113 |
# For non default server, we have already created the first connection |
| 114 |
if ($SERVER_ID != 1) { |
| 115 |
--let $conn_nummber = 2 |
| 116 |
|
| 117 |
# Create some local table and tablespace in recipient |
| 118 |
CREATE TABLE t_recipient(col1 INT PRIMARY KEY, col2 int); |
| 119 |
INSERT INTO t_recipient VALUES(1, 10); |
| 120 |
CREATE UNDO TABLESPACE undo_005 ADD DATAFILE 'undo_005.ibu'; |
| 121 |
CREATE TABLESPACE tbs1_recipient ADD DATAFILE 'tbs1_data1.ibd'; |
| 122 |
} |
| 123 |
|
| 124 |
while ($conn_nummber <= $clone_connections) |
| 125 |
{ |
| 126 |
--let $conn_name = clone_conn_$conn_nummber |
| 127 |
|
| 128 |
if ($clone_inst_number) { |
| 129 |
--let $clone_port= \$SERVER_PORT_$clone_inst_number |
| 130 |
--connect ($conn_name, 127.0.0.1, $clone_user,,test,$clone_port) |
| 131 |
} |
| 132 |
|
| 133 |
# Connect to the default instance if instance number is not provided. |
| 134 |
if (!$clone_inst_number) { |
| 135 |
--connect ($conn_name, localhost, $clone_user,,test) |
| 136 |
} |
| 137 |
--inc $conn_nummber |
| 138 |
} |
| 139 |
--connection default |