MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
show_slave_status.inc
1 # ==== Purpose ====
2 #
3 # Show selected columns of output from SHOW SLAVE STATUS.
4 #
5 # Note: test cases should never call SHOW SLAVE STATUS directly,
6 # because that outputs more information to the query log than what is
7 # needed for the property that is being tested. That would cause
8 # maintenance problems, because (1) it is hard for a human to
9 # understand what property is being tested; (2) the output of many of
10 # the fields is non-deterministic (e.g., Slave_IO_State) or changes
11 # frequently (e.g., binlog positions).
12 #
13 # Instead, what you want most of the time is to source one of the
14 # following scripts:
15 #
16 # include/check_slave_no_error.inc
17 # Assert that Slave_SQL_Errno = Slave_IO_Errno = 0.
18 #
19 # include/check_slave_is_running.inc
20 # Assert that Slave_IO_Running = Slave_SQL_Running = 'Yes'.
21 #
22 # include/wait_for_slave_sql_error.inc
23 # Wait for the SQL thread to get a given error (and assert that
24 # it has this error).
25 #
26 # include/wait_for_slave_io_error.inc
27 # Wait for the IO thread to get a given error (and assert that
28 # it has this error).
29 #
30 # include/wait_for_slave_sql_to_stop.inc
31 # include/wait_for_slave_io_to_stop.inc
32 # include/wait_for_slave_to_stop.inc
33 # Wait for the SQL thread, the IO thread, or both to stop (and
34 # assert they stop).
35 #
36 # When none of the above applies, you may use this script instead.
37 # However, take care so that the test never contains explicit binlog
38 # coordinates. Usually you can read the binlog coordinates into a
39 # variable and compare it to some other coordinates.
40 #
41 #
42 # ==== Usage ====
43 #
44 # --let $status_items= Column_Name[, Column_Name[, ...]]
45 # --source include/show_slave_status.inc
46 #
47 # Parameters:
48 # $status_items
49 # Set to the name of the column in the output of SHOW SLAVE STATUS
50 # that you want to display. Example:
51 #
52 # --let $status_items= Master_SSL_Allowed
53 #
54 # You can show multiple columns by setting $status_items to a
55 # comma-separated list. Example:
56 #
57 # --let $status_items= Master_Log_File, Relay_Master_Log_File
58 #
59 # $slave_field_result_replace
60 # If set, one or more regex patterns for replacing variable
61 # text in the error message. Syntax as --replace-regex
62 #
63 # $slave_sql_mode
64 # If set, change the slave sql mode during this macro, reverting
65 # to the previous on exit. Default sql_mode is NO_BACKSLASH_ESCAPES
66 # to allow replace '\' by '/' making paths OS independent. Example:
67 #
68 # --let $slave_sql_mode= NO_BACKSLASH_ESCAPES
69 #
70 
71 
72 --let $_show_slave_status_items= $status_items
73 if (!$status_items)
74 {
75  --die Bug in test case: The mysqltest variable $status_items is not set.
76 }
77 
78 
79 --let $_slave_sql_mode= NO_BACKSLASH_ESCAPES
80 if ($slave_sql_mode)
81 {
82  --let $_slave_sql_mode= $slave_sql_mode
83 }
84 --let $_previous_slave_sql_mode = `SELECT @@sql_mode`
85 --disable_query_log
86 eval SET sql_mode= '$_slave_sql_mode';
87 --enable_query_log
88 
89 
90 while ($_show_slave_status_items)
91 {
92  --let $_show_slave_status_name= `SELECT SUBSTRING_INDEX('$_show_slave_status_items', ',', 1)`
93  --let $_show_slave_status_items= `SELECT LTRIM(SUBSTRING('$_show_slave_status_items', LENGTH('$_show_slave_status_name') + 2))`
94 
95  --let $_show_slave_status_value= query_get_value(SHOW SLAVE STATUS, $_show_slave_status_name, 1)
96  --let $_slave_field_result_replace= /[\\]/\// $slave_field_result_replace
97  --replace_regex $_slave_field_result_replace
98  --let $_show_slave_status_value= `SELECT REPLACE("$_show_slave_status_value", '$MYSQL_TEST_DIR', 'MYSQL_TEST_DIR')`
99  --echo $_show_slave_status_name = '$_show_slave_status_value'
100 }
101 
102 
103 --disable_query_log
104 eval SET sql_mode= '$_previous_slave_sql_mode';
105 --enable_query_log