Skip to content

Commit 91a2192

Browse files
committed
Merge 10.5 into 10.6
2 parents d337700 + f5373db commit 91a2192

36 files changed

+1666
-108
lines changed

debian/rules

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ endif
9292
-DCOMPILATION_COMMENT="mariadb.org binary distribution" \
9393
-DMYSQL_SERVER_SUFFIX="-$(DEB_VERSION_REVISION)" \
9494
-DSYSTEM_TYPE="debian-$(DEB_HOST_GNU_SYSTEM)" \
95-
-DCMAKE_SYSTEM_PROCESSOR=$(DEB_HOST_ARCH) \
9695
-DBUILD_CONFIG=mysql_release \
9796
-DCONC_DEFAULT_CHARSET=utf8mb4 \
9897
-DPLUGIN_AWS_KEY_MANAGEMENT=NO \

extra/mariabackup/backup_mysql.cc

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ Street, Fifth Floor, Boston, MA 02110-1335 USA
4747
#include <stdlib.h>
4848
#include <string.h>
4949
#include <limits>
50+
#ifdef HAVE_PWD_H
51+
#ifdef HAVE_SYS_TYPES_H
52+
#include <sys/types.h>
53+
#endif
54+
#include <pwd.h>
55+
#endif
5056
#include "common.h"
5157
#include "xtrabackup.h"
5258
#include "srv0srv.h"
@@ -95,11 +101,54 @@ MYSQL *mysql_connection;
95101

96102
extern my_bool opt_ssl_verify_server_cert, opt_use_ssl;
97103

104+
105+
/*
106+
get_os_user()
107+
Ressemles read_user_name() from libmariadb/libmariadb/mariadb_lib.c.
108+
*/
109+
110+
#if !defined(_WIN32)
111+
112+
#if defined(HAVE_GETPWUID) && defined(NO_GETPWUID_DECL)
113+
struct passwd *getpwuid(uid_t);
114+
char* getlogin(void);
115+
#endif
116+
117+
static const char *get_os_user() // Posix
118+
{
119+
if (!geteuid())
120+
return "root";
121+
#ifdef HAVE_GETPWUID
122+
struct passwd *pw;
123+
const char *str;
124+
if ((pw= getpwuid(geteuid())) != NULL)
125+
return pw->pw_name;
126+
if ((str= getlogin()) != NULL)
127+
return str;
128+
#endif
129+
if ((str= getenv("USER")) ||
130+
(str= getenv("LOGNAME")) ||
131+
(str= getenv("LOGIN")))
132+
return str;
133+
return NULL;
134+
}
135+
136+
#else
137+
138+
static const char *get_os_user() // Windows
139+
{
140+
return getenv("USERNAME");
141+
}
142+
143+
#endif // _WIN32
144+
145+
98146
MYSQL *
99147
xb_mysql_connect()
100148
{
101149
MYSQL *connection = mysql_init(NULL);
102150
char mysql_port_str[std::numeric_limits<int>::digits10 + 3];
151+
const char *user= opt_user ? opt_user : get_os_user();
103152

104153
sprintf(mysql_port_str, "%d", opt_port);
105154

@@ -129,7 +178,7 @@ xb_mysql_connect()
129178

130179
msg("Connecting to MariaDB server host: %s, user: %s, password: %s, "
131180
"port: %s, socket: %s", opt_host ? opt_host : "localhost",
132-
opt_user ? opt_user : "not set",
181+
user ? user : "not set",
133182
opt_password ? "set" : "not set",
134183
opt_port != 0 ? mysql_port_str : "not set",
135184
opt_socket ? opt_socket : "not set");
@@ -150,7 +199,7 @@ xb_mysql_connect()
150199

151200
if (!mysql_real_connect(connection,
152201
opt_host ? opt_host : "localhost",
153-
opt_user,
202+
user,
154203
opt_password,
155204
"" /*database*/, opt_port,
156205
opt_socket, 0)) {
Lines changed: 297 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,297 @@
1+
if ($cnf == "galera2_to_mariadb")
2+
{
3+
--let MASTER_MYPORT= $NODE_MYPORT_1
4+
--connect master, 127.0.0.1, root, , test, $NODE_MYPORT_1
5+
--connect slave, 127.0.0.1, root, , test, $NODE_MYPORT_3
6+
--disable_query_log
7+
--replace_result $MASTER_MYPORT ###
8+
--eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_USER='root', MASTER_PORT=$MASTER_MYPORT;
9+
--enable_query_log
10+
START SLAVE;
11+
--source include/wait_for_slave_to_start.inc
12+
13+
--let XTRABACKUP_BACKUP_OPTIONS=--no-defaults --user=root --host='127.0.0.1' --port=$NODE_MYPORT_3
14+
--let XTRABACKUP_COPY_BACK_OPTIONS= --no-defaults
15+
}
16+
17+
if ($cnf == "mariadb_to_mariadb")
18+
{
19+
--let XTRABACKUP_BACKUP_OPTIONS=--defaults-file=$MYSQLTEST_VARDIR/my.cnf --defaults-group-suffix=.2
20+
--let XTRABACKUP_COPY_BACK_OPTIONS=--defaults-file=$MYSQLTEST_VARDIR/my.cnf --defaults-group-suffix=.2
21+
}
22+
23+
--connection master
24+
--let $MYSQLD_DATADIR_MASTER= `select @@datadir`
25+
--connection slave
26+
--let $MYSQLD_DATADIR_SLAVE= `select @@datadir`
27+
28+
# This test covers the filename:pos based synchronization
29+
# between the master and the slave.
30+
# If we ever need to test a GTID based synchronization,
31+
# it should be done in a separate test.
32+
33+
34+
--echo ##############################################################
35+
--echo ### Initial block with some transactions
36+
37+
--echo ### Slave: Make sure replication is not using GTID
38+
--connection slave
39+
--let $value= query_get_value(SHOW SLAVE STATUS, "Using_Gtid", 1)
40+
--echo # Using_Gtid=$value
41+
42+
--echo ### Master: Create and populate t1
43+
--connection master
44+
CREATE TABLE t1(a TEXT) ENGINE=InnoDB;
45+
START TRANSACTION;
46+
INSERT INTO t1 VALUES ('tr#00:stmt#00 - slave run#0, before backup');
47+
INSERT INTO t1 VALUES ('tr#00:stmt#01 - slave run#0, before backup');
48+
INSERT INTO t1 VALUES ('tr#00:stmt#02 - slave run#0, before backup');
49+
COMMIT;
50+
--sync_slave_with_master
51+
52+
53+
54+
--echo ##############################################################
55+
--echo ### Run the last transaction before mariadb-backup --backup
56+
--echo ### Remember SHOW MASTER STATUS and @@gtid_binlog_pos
57+
--echo ### before and after the transaction.
58+
59+
--echo ### Master: Rember MASTER STATUS and @@gtid_binlog_pos before tr#01
60+
--connection master
61+
--let $master_before_tr01_show_master_status_file=query_get_value(SHOW MASTER STATUS, File, 1)
62+
--let $master_before_tr01_show_master_status_position=query_get_value(SHOW MASTER STATUS, Position, 1)
63+
--let $master_before_tr01_gtid_binlog_pos=`SELECT @@global.gtid_binlog_pos`
64+
65+
--echo ### Slave: Remember MASTER STATUS and @@gtid_binlog_pos before tr#01
66+
--connection slave
67+
--let $slave_before_tr01_show_master_status_file=query_get_value(SHOW MASTER STATUS, File, 1)
68+
--let $slave_before_tr01_show_master_status_position=query_get_value(SHOW MASTER STATUS, Position, 1)
69+
--let $slave_before_tr01_gtid_binlog_pos=`SELECT @@global.gtid_binlog_pos`
70+
71+
--echo ### Master: Run the actual last transaction before the backup
72+
--connection master
73+
START TRANSACTION;
74+
INSERT INTO t1 VALUES ('tr#01:stmt#00 - slave run#0, before backup');
75+
INSERT INTO t1 VALUES ('tr#01:stmt#01 - slave run#0, before backup');
76+
INSERT INTO t1 VALUES ('tr#01:stmt#02 - slave run#0, before backup');
77+
COMMIT;
78+
--sync_slave_with_master
79+
80+
--echo ### Master: Remember MASTER STATUS and @@gtid_binlog_pos after tr#01
81+
--connection master
82+
--let $master_after_tr01_show_master_status_file=query_get_value(SHOW MASTER STATUS, File, 1)
83+
--let $master_after_tr01_show_master_status_position=query_get_value(SHOW MASTER STATUS, Position, 1)
84+
--let $master_after_tr01_gtid_binlog_pos=`SELECT @@global.gtid_binlog_pos`
85+
86+
--echo ### Slave: Remember MASTER STATUS and @@gtid_binlog_pos after tr#01
87+
--connection slave
88+
--let $slave_after_tr01_show_master_status_file=query_get_value(SHOW MASTER STATUS, File, 1)
89+
--let $slave_after_tr01_show_master_status_position=query_get_value(SHOW MASTER STATUS, Position, 1)
90+
--let $slave_after_tr01_gtid_binlog_pos=`SELECT @@global.gtid_binlog_pos`
91+
92+
93+
--echo ##############################################################
94+
--echo ### Running `mariadb-backup --backup,--prepare` and checking
95+
--echo ### that xtrabackup_slave_info and xtrabackup_binlog_info are OK
96+
97+
--echo ### Slave: Create a backup
98+
--let $backup_slave=$MYSQLTEST_VARDIR/tmp/backup-slave
99+
--disable_result_log
100+
--exec $XTRABACKUP $XTRABACKUP_BACKUP_OPTIONS --slave-info --backup --target-dir=$backup_slave
101+
--enable_result_log
102+
103+
--echo ### Slave: Prepare the backup
104+
--exec $XTRABACKUP --prepare --target-dir=$backup_slave
105+
106+
--echo ### Slave: xtrabackup files:
107+
--echo ############################ xtrabackup_slave_info
108+
--replace_result $master_after_tr01_show_master_status_file master_after_tr01_show_master_status_file $master_after_tr01_show_master_status_position master_after_tr01_show_master_status_position
109+
--cat_file $backup_slave/xtrabackup_slave_info
110+
--echo ############################ xtrabackup_binlog_info
111+
--replace_result $slave_after_tr01_show_master_status_file slave_after_tr01_show_master_status_file $slave_after_tr01_show_master_status_position slave_after_tr01_show_master_status_position $slave_after_tr01_gtid_binlog_pos slave_after_tr01_gtid_binlog_pos
112+
--cat_file $backup_slave/xtrabackup_binlog_info
113+
--echo ############################
114+
115+
116+
--echo ##############################################################
117+
--echo ### Run more transactions after the backup:
118+
--echo ### - while the slave is still running, then
119+
--echo ### - while the slave is shut down
120+
121+
--echo ### Master: Run another transaction while the slave is still running
122+
--connection master
123+
START TRANSACTION;
124+
INSERT INTO t1 VALUES ('tr#02:stmt#00 - slave run#0, after backup');
125+
INSERT INTO t1 VALUES ('tr#02:stmt#01 - slave run#0, after backup');
126+
INSERT INTO t1 VALUES ('tr#02:stmt@02 - slave run#0, after backup');
127+
COMMIT;
128+
--sync_slave_with_master
129+
130+
--echo ### Master: Remember MASTER STATUS and @@gtid_binlog_pos after tr#02
131+
--connection master
132+
--let $master_after_tr02_show_master_status_file=query_get_value(SHOW MASTER STATUS, File, 1)
133+
--let $master_after_tr02_show_master_status_position=query_get_value(SHOW MASTER STATUS, Position, 1)
134+
--let $master_after_tr02_gtid_binlog_pos=`SELECT @@global.gtid_binlog_pos`
135+
136+
--echo ### Slave: Remember MASTER STATUS and @@gtid_binlog_pos after tr#02
137+
--connection slave
138+
--let $slave_after_tr02_show_master_status_file=query_get_value(SHOW MASTER STATUS, File, 1)
139+
--let $slave_after_tr02_show_master_status_position=query_get_value(SHOW MASTER STATUS, Position, 1)
140+
--let $slave_after_tr02_gtid_binlog_pos=`SELECT @@global.gtid_binlog_pos`
141+
142+
143+
--echo ### Master: Checking SHOW BINLOG EVENTS
144+
145+
--connection master
146+
--vertical_results
147+
### The BEGIN event
148+
--replace_column 4 # 5 #
149+
--replace_result $master_after_tr01_show_master_status_file master_after_tr01_show_master_status_file $master_after_tr01_show_master_status_position master_after_tr01_show_master_status_position $master_after_tr02_gtid_binlog_pos master_after_tr02_gtid_binlog_pos
150+
--eval SHOW BINLOG EVENTS IN '$master_after_tr01_show_master_status_file' FROM $master_after_tr01_show_master_status_position LIMIT 0,1
151+
### The INSERT event
152+
--replace_column 2 # 4 # 5 #
153+
--replace_result $master_after_tr01_show_master_status_file master_after_tr01_show_master_status_file $master_after_tr01_show_master_status_position master_after_tr01_show_master_status_position
154+
# Hide the difference between row and stmt binary logging
155+
--replace_regex /use `test`; // /(Query|Annotate_rows)/Query_or_Annotate_rows/
156+
--eval SHOW BINLOG EVENTS IN '$master_after_tr01_show_master_status_file' FROM $master_after_tr01_show_master_status_position LIMIT 1,1
157+
--horizontal_results
158+
159+
--echo ### Slave: Checking SHOW BINLOG EVENTS
160+
--connection slave
161+
--vertical_results
162+
### The BEGIN event
163+
--replace_column 2 # 5 #
164+
--replace_result $slave_after_tr01_show_master_status_file slave_after_tr01_show_master_status_file $slave_after_tr01_show_master_status_position slave_after_tr01_show_master_status_position $slave_after_tr02_gtid_binlog_pos slave_after_tr02_gtid_binlog_pos
165+
--eval SHOW BINLOG EVENTS IN '$slave_after_tr01_show_master_status_file' FROM $slave_after_tr01_show_master_status_position LIMIT 0,1
166+
### The INSERT event
167+
--replace_column 2 # 4 # 5 #
168+
--replace_result $slave_after_tr01_show_master_status_file slave_after_tr01_show_master_status_file $slave_after_tr01_show_master_status_position slave_after_tr01_show_master_status_position $slave_after_tr02_gtid_binlog_pos slave_after_tr02_gtid_binlog_pos
169+
# Hide the difference between row and stmt binary logging
170+
--replace_regex /use `test`; // /(Query|Annotate_rows)/Query_or_Annotate_rows/
171+
--eval SHOW BINLOG EVENTS IN '$slave_after_tr01_show_master_status_file' FROM $slave_after_tr01_show_master_status_position LIMIT 1,1
172+
--horizontal_results
173+
174+
--echo ### Slave: Stop replication
175+
--connection slave
176+
STOP SLAVE;
177+
--source include/wait_for_slave_to_stop.inc
178+
RESET SLAVE;
179+
180+
--echo ### Slave: Shutdown the server
181+
182+
if ($cnf == "mariadb_to_mariadb")
183+
{
184+
--let $rpl_server_number= 2
185+
--source include/rpl_stop_server.inc
186+
}
187+
188+
if ($cnf == "galera2_to_mariadb")
189+
{
190+
--connection slave
191+
--source $MYSQL_TEST_DIR/include/shutdown_mysqld.inc
192+
}
193+
194+
--echo ### Master: Run a transaction while the slave is shut down
195+
--connection master
196+
START TRANSACTION;
197+
INSERT INTO t1 VALUES ('tr#03:stmt#00 - after slave run#0, slave is shut down, after backup');
198+
INSERT INTO t1 VALUES ('tr#03:stmt#01 - after slave run#0, slave is shut down, after backup');
199+
INSERT INTO t1 VALUES ('tr#03:stmt#02 - after slave run#0, slave is shut down, after backup');
200+
COMMIT;
201+
202+
203+
--echo ##############################################################
204+
--echo ### Emulate starting a new virgin slave
205+
206+
--echo ### Slave: Remove the data directory
207+
--rmdir $MYSQLD_DATADIR_SLAVE
208+
209+
--echo ### Slave: Copy back the backup
210+
--exec $XTRABACKUP $XTRABACKUP_COPY_BACK_OPTIONS --copy-back --datadir=$MYSQLD_DATADIR_SLAVE --target-dir=$backup_slave
211+
212+
--echo ### Slave: Restart the server
213+
if ($cnf == "mariadb_to_mariadb")
214+
{
215+
--let $rpl_server_number= 2
216+
--source include/rpl_start_server.inc
217+
--source include/wait_until_connected_again.inc
218+
}
219+
220+
if ($cnf == "galera2_to_mariadb")
221+
{
222+
--connection slave
223+
--source $MYSQL_TEST_DIR/include/start_mysqld.inc
224+
}
225+
226+
--echo ### Slave: Display the restored data before START SLAVE
227+
--connection slave
228+
SELECT * FROM t1 ORDER BY a;
229+
230+
--echo ### Slave: Execute the CHANGE MASTER statement to set up the host and port
231+
--replace_result $MASTER_MYPORT ###
232+
--eval CHANGE MASTER '' TO MASTER_USER='root', MASTER_HOST='127.0.0.1', MASTER_PORT=$MASTER_MYPORT, MASTER_CONNECT_RETRY=1
233+
234+
--echo ### Slave: Execute the CHANGE MASTER statement from xtrabackup_slave_info
235+
--replace_result $master_after_tr01_show_master_status_file master_after_tr01_show_master_status_file $master_after_tr01_show_master_status_position master_after_tr01_show_master_status_position
236+
--source $backup_slave/xtrabackup_slave_info
237+
238+
--echo ### Slave: Execute START SLAVE
239+
--source include/start_slave.inc
240+
241+
--echo ### Master: Wait for the slave to apply all master events
242+
--connection master
243+
--sync_slave_with_master slave
244+
245+
--echo ### Slave: Make sure replication is not using GTID after the slave restart
246+
--connection slave
247+
--let $value= query_get_value(SHOW SLAVE STATUS, "Using_Gtid", 1)
248+
--echo # Using_Gtid=$value
249+
250+
--echo ### Slave: Display the restored data after START SLAVE
251+
--connection slave
252+
SELECT * FROM t1 ORDER BY a;
253+
254+
255+
--echo ##############################################################
256+
--echo ### Continue master transactions, check the new slave replicates well.
257+
258+
--echo ### Master: Run a transaction after restarting replication
259+
--connection master
260+
START TRANSACTION;
261+
INSERT INTO t1 VALUES ('tr#04:stmt#00 - slave run#1');
262+
INSERT INTO t1 VALUES ('tr#04:stmt#01 - slave run#1');
263+
INSERT INTO t1 VALUES ('tr#04:stmt#02 - slave run#1');
264+
COMMIT;
265+
--sync_slave_with_master
266+
267+
--echo ### Slave: Display the restored data + new transactions
268+
--connection slave
269+
SELECT * FROM t1 ORDER BY a;
270+
271+
272+
--echo ##############################################################
273+
--echo ### Cleanup
274+
275+
--echo ### Removing the backup directory
276+
--rmdir $backup_slave
277+
278+
--connection master
279+
DROP TABLE t1;
280+
--sync_slave_with_master
281+
282+
if ($cnf == "mariadb_to_mariadb")
283+
{
284+
--source include/rpl_end.inc
285+
}
286+
287+
if ($cnf == "galera2_to_mariadb")
288+
{
289+
STOP SLAVE;
290+
--source include/wait_for_slave_to_stop.inc
291+
RESET SLAVE ALL;
292+
293+
--connection master
294+
set global wsrep_on=OFF;
295+
RESET MASTER;
296+
set global wsrep_on=ON;
297+
}

0 commit comments

Comments
 (0)