1# ==== Purpose ====
2#
3# Setup replication from an existing relay log in the current
4# connection.
5#
6# ==== Usage ====
7#
8# Make sure the slave is not running and issue:
9#
10#   let $fake_relay_log= /path/to/fake-relay-log-file.000001
11#   source include/setup_fake_relay_log.inc;
12#   START SLAVE SQL_THREAD; # setup_fake_relay_log doesn't start slave
13#   ...
14#   source include/cleanup_fake_relay_log.inc
15#
16# You must run the server with --relay-log=FILE. You probably want to
17# run with --replicate-same-server-id too.
18#
19# ==== Implementation ====
20#
21# First makes a sanity check, ensuring that the slave threads are not
22# running.  Then copies the $fake_relay_log to RELAY_BIN-fake.000001,
23# where RELAY_BIN is the basename of the relay log, and updates
24# RELAY_BIN.index. Finally issues CHANGE MASTER so that it uses the
25# given files.
26#
27# ==== Side effects ====
28#
29# Creates a binlog file and a binlog index file, and sets
30# @@global.relay_log_purge=1. All this is restored when you call
31# cleanup_fake_relay_log.inc.
32
33
34--let $include_filename= setup_fake_relay_log.inc
35--source include/begin_include_file.inc
36
37if (!$rpl_debug)
38{
39  --disable_query_log
40}
41
42# Print message.
43let $_fake_relay_log_printable= `SELECT REPLACE('$fake_relay_log', '$MYSQL_TEST_DIR', 'MYSQL_TEST_DIR')`;
44--echo Setting up fake replication from $_fake_relay_log_printable
45
46# Sanity check.
47let $running= 0;
48let $_sql_running= query_get_value(SHOW SLAVE STATUS, Slave_SQL_Running, 1);
49let $_io_running= query_get_value(SHOW SLAVE STATUS, Slave_IO_Running, 1);
50if ($_sql_running == Yes) {
51  let $running= 1;
52}
53if ($_io_running == Yes) {
54  let $running= 1;
55}
56if ($running) {
57  --echo Error: Slave was running when test case sourced
58  --echo include/setup_fake_replication.inc
59  --echo Slave_IO_Running = $_io_running; Slave_SQL_Running = $_sql_running
60  --source include/show_rpl_debug_info.inc
61  --die
62}
63
64# Read server variables.
65let $_fake_datadir= `SELECT @@datadir`;
66let $_fake_filename= query_get_value(SHOW VARIABLES LIKE 'relay_log', Value, 1);
67if (!$_fake_filename) {
68  --die ERROR IN TEST: relay_log variable is empty. Please use the server option --relay-log=FILE.
69}
70let $_fake_relay_log= $_fake_datadir/$_fake_filename-fake.000001;
71let $_fake_relay_index= $_fake_datadir/$_fake_filename.index;
72# Need to restore relay_log_purge in cleanup_fake_relay_log.inc, since
73# CHANGE MASTER modifies it (see the manual for CHANGE MASTER).
74let $_fake_relay_log_purge= `SELECT @@global.relay_log_purge`;
75
76RESET SLAVE;
77
78# Create relay log file.
79--copy_file $fake_relay_log $_fake_relay_log
80
81# Create relay log index.
82
83# After patch for BUG#12190, the filename used in CHANGE MASTER
84# RELAY_LOG_FILE will be automatically added the directory of the
85# relay log before comparison, thus we need to added the directory
86# part (./ on unix .\ on windows) when faking the relay-log-bin.index.
87
88# mysqltest currently parses backslash escapes wrong, so any sequence
89# of N backslashes is collapsed to just one backslash. So we use the
90# SQL function CHAR() to generate a backslash character instead. Since
91# the string is interpreted in SQL context, we to escape it, so we use
92# two backslashes.
93
94--let $_fake_dir= `select IF(convert(@@version_compile_os using latin1) IN ("Win32","Win64","Windows"), CONCAT('.', CHAR(92), CHAR(92)), './')`
95--let $write_var= $_fake_dir$_fake_filename-fake.000001\n
96--let $write_to_file= $_fake_relay_index
97--source include/write_var_to_file.inc
98
99# Remember old settings.
100--let $_fake_old_master_host= query_get_value(SHOW SLAVE STATUS, Master_Host, 1)
101
102# Setup replication from existing relay log.
103eval CHANGE MASTER TO MASTER_HOST='dummy.localdomain', RELAY_LOG_FILE='$_fake_filename-fake.000001', RELAY_LOG_POS=4;
104
105--let $include_filename= setup_fake_relay_log.inc
106--source include/end_include_file.inc
107