Commit 0fd4d6d3 authored by Monty's avatar Monty

MDEV-27068 running mariadb-upgrade in parallel make it hangs forever

MDEV-27107 prevent two mariadb-upgrade running in parallel
MDEV-27279 mariadb_upgrade add --check-if-upgrade-is-needed /
           restrict tests to major version

Code is based of pull request from Daniel Black, but with a several
extensions.

- mysql_upgrade now locks the mysql_upgrade file with my_lock()
  (Advisory record locking). This ensures that two mysql_upgrades
   cannot be run in parallel.
- Added --check-if-upgrade-is-needed to mysql_upgrade. This will return
  0 if one has to run mysql_upgrade.

Other changes:
- mysql_upgrade will now immediately exit if the major version and minor
  version  (two first numbers in the version string) is same as last run.
  Before this change mysql_upgrade was run if the version string was different
  from last run.
- Better messages when there is no need to run mysql_upgrade.
- mysql_upgrade --verbose now prints out a lot more information about
  the version checking.
- mysql_upgrade --debug now uses default debug arguments if there is no
  option to --debug
- "MySQL" is renamed to MariaDB in the messages
- mysql_upgrade version increased to 2.0

Notes
Verifying "prevent two mariadb-upgrade running in parallel" was
done in a debugger as it would be a bit complex to do that in mtr.

Reviewer: Danial Black <daniel@mariadb.org>
parent d28d3aee
...@@ -99,6 +99,7 @@ enum options_client ...@@ -99,6 +99,7 @@ enum options_client
OPT_SKIP_ANNOTATE_ROWS_EVENTS, OPT_SKIP_ANNOTATE_ROWS_EVENTS,
OPT_SSL_CRL, OPT_SSL_CRLPATH, OPT_SSL_CRL, OPT_SSL_CRLPATH,
OPT_IGNORE_DATA, OPT_IGNORE_DATA,
OPT_CHECK_IF_UPGRADE_NEEDED,
OPT_MAX_CLIENT_OPTION /* should be always the last */ OPT_MAX_CLIENT_OPTION /* should be always the last */
}; };
......
This diff is collapsed.
...@@ -239,6 +239,21 @@ Old option accepted for backward compatibility but ignored\&. ...@@ -239,6 +239,21 @@ Old option accepted for backward compatibility but ignored\&.
.sp -1 .sp -1
.IP \(bu 2.3 .IP \(bu 2.3
.\} .\}
.\" mysql_upgrade: check-if-upgrade-is-needed option
.\" check-if-upgrade-is-needed option: mysql_upgrade
\fB\-\-check\-if\-upgrade\-is\-needed\fR
.sp
Exit with a status code indicating if an upgrade is needed\&. Returns 0 if upgrade needed or current version couldn't be determined, 1 when no action required\&.
.RE
.sp
.RS 4
.ie n \{\
\h'-04'\(bu\h'+03'\c
.\}
.el \{\
.sp -1
.IP \(bu 2.3
.\}
.\" mysql_upgrade: datadir option .\" mysql_upgrade: datadir option
.\" datadir option: mysql_upgrade .\" datadir option: mysql_upgrade
\fB\-\-datadir=\fR\fB\fIpath\fR\fR \fB\-\-datadir=\fR\fB\fIpath\fR\fR
......
...@@ -46,7 +46,9 @@ test ...@@ -46,7 +46,9 @@ test
Phase 7/7: Running 'FLUSH PRIVILEGES' Phase 7/7: Running 'FLUSH PRIVILEGES'
OK OK
Run it again - should say already completed Run it again - should say already completed
This installation of MySQL is already upgraded to VERSION, use --force if you still need to run mysql_upgrade This installation of MariaDB is already upgraded to VERSION.
There is no need to run mysql_upgrade again for VERSION.
You can use --force if you still want to run mysql_upgrade
Force should run it regardless of whether it has been run before Force should run it regardless of whether it has been run before
Phase 1/7: Checking and upgrading mysql database Phase 1/7: Checking and upgrading mysql database
Processing databases Processing databases
...@@ -142,11 +144,12 @@ test ...@@ -142,11 +144,12 @@ test
Phase 7/7: Running 'FLUSH PRIVILEGES' Phase 7/7: Running 'FLUSH PRIVILEGES'
OK OK
DROP USER mysqltest1@'%'; DROP USER mysqltest1@'%';
Version check failed. Got the following error when calling the 'mysql' command line client Reading datadir from the MariaDB server failed. Got the following error when executing the 'mysql' command line client
ERROR 1045 (28000): Access denied for user 'mysqltest1'@'localhost' (using password: YES) ERROR 1045 (28000): Access denied for user 'mysqltest1'@'localhost' (using password: YES)
FATAL ERROR: Upgrade failed FATAL ERROR: Upgrade failed
Run mysql_upgrade with a non existing server socket Run mysql_upgrade with a non existing server socket
mysqlcheck: Got error: 2005: Unknown MySQL server host 'not_existing_host' (errno) when trying to connect Reading datadir from the MariaDB server failed. Got the following error when executing the 'mysql' command line client
ERROR 2005 (HY000): Unknown MySQL server host 'not_existing_host' (errno)
FATAL ERROR: Upgrade failed FATAL ERROR: Upgrade failed
set GLOBAL sql_mode='STRICT_ALL_TABLES,ANSI_QUOTES,NO_ZERO_DATE'; set GLOBAL sql_mode='STRICT_ALL_TABLES,ANSI_QUOTES,NO_ZERO_DATE';
Phase 1/7: Checking and upgrading mysql database Phase 1/7: Checking and upgrading mysql database
...@@ -405,9 +408,12 @@ OK ...@@ -405,9 +408,12 @@ OK
# Bug #21489398: MYSQL_UPGRADE: FATAL ERROR: UPGRADE FAILED - IMPROVE ERROR # Bug #21489398: MYSQL_UPGRADE: FATAL ERROR: UPGRADE FAILED - IMPROVE ERROR
# #
Run mysql_upgrade with unauthorized access Run mysql_upgrade with unauthorized access
Version check failed. Got the following error when calling the 'mysql' command line client Reading datadir from the MariaDB server failed. Got the following error when executing the 'mysql' command line client
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
FATAL ERROR: Upgrade failed FATAL ERROR: Upgrade failed
Reading datadir from the MariaDB server failed. Got the following error when executing the 'mysql' command line client
ERROR 1045 (errno): Access denied for user 'root'@'localhost' (using password: YES)
FATAL ERROR: Upgrade failed
# #
# MDEV-4332 Increase username length from 16 characters # MDEV-4332 Increase username length from 16 characters
# MDEV-6068, MDEV-6178 mysql_upgrade breaks databases with long user names # MDEV-6068, MDEV-6178 mysql_upgrade breaks databases with long user names
...@@ -854,4 +860,32 @@ GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION ...@@ -854,4 +860,32 @@ GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION
GRANT USAGE ON *.* TO 'aRole' GRANT USAGE ON *.* TO 'aRole'
DROP ROLE `aRole`; DROP ROLE `aRole`;
FLUSH PRIVILEGES; FLUSH PRIVILEGES;
#
# MDEV-27279: mariadb_upgrade add --check-if-upgrade-is-needed
#
This installation of MariaDB is already upgraded to MariaDB .
There is no need to run mysql_upgrade again for MariaDB .
Looking for 'mysql' as: mysql
This installation of MariaDB is already upgraded to MariaDB .
There is no need to run mysql_upgrade again for MariaDB .
#
# MDEV-27279: mariadb_upgrade check-if-upgrade absence is do it
#
Looking for 'mysql' as: mysql
Empty or non existent ...mysql_upgrade_info. Assuming mysql_upgrade has to be run!
#
# MDEV-27279: mariadb_upgrade check-if-upgrade with minor version change
#
Looking for 'mysql' as: mysql
This installation of MariaDB is already upgraded to MariaDB .
There is no need to run mysql_upgrade again for MariaDB .
This installation of MariaDB is already upgraded to MariaDB .
There is no need to run mysql_upgrade again for MariaDB .
You can use --force if you still want to run mysql_upgrade
#
# MDEV-27279: mariadb_upgrade check-if-upgrade with major version change
#
Major version upgrade detected from MariaDB to MariaDB . Check required!
Looking for 'mysql' as: mysql
Major version upgrade detected from MariaDB to MariaDB . Check required!
End of 10.2 tests End of 10.2 tests
...@@ -50,6 +50,7 @@ Message Unknown storage engine 'BLACKHOLE' ...@@ -50,6 +50,7 @@ Message Unknown storage engine 'BLACKHOLE'
Level Warning Level Warning
Code 1286 Code 1286
Message Unknown storage engine 'ARCHIVE' Message Unknown storage engine 'ARCHIVE'
# upgrade from 10.1 - engines aren't enabled
Phase 1/7: Checking and upgrading mysql database Phase 1/7: Checking and upgrading mysql database
Processing databases Processing databases
mysql mysql
...@@ -136,6 +137,8 @@ Level Warning ...@@ -136,6 +137,8 @@ Level Warning
Code 1286 Code 1286
Message Unknown storage engine 'ARCHIVE' Message Unknown storage engine 'ARCHIVE'
alter table mysql.user drop column default_role, drop column max_statement_time; alter table mysql.user drop column default_role, drop column max_statement_time;
# still upgrade from 10.1
Major version upgrade detected from MariaDB to MariaDB . Check required!
Phase 1/7: Checking and upgrading mysql database Phase 1/7: Checking and upgrading mysql database
Processing databases Processing databases
mysql mysql
...@@ -222,6 +225,7 @@ Level Warning ...@@ -222,6 +225,7 @@ Level Warning
Code 1286 Code 1286
Message Unknown storage engine 'ARCHIVE' Message Unknown storage engine 'ARCHIVE'
alter table mysql.user drop column default_role, drop column max_statement_time; alter table mysql.user drop column default_role, drop column max_statement_time;
# upgrade from 10.0 - engines are enabled
Phase 1/7: Checking and upgrading mysql database Phase 1/7: Checking and upgrading mysql database
Processing databases Processing databases
mysql mysql
......
...@@ -205,7 +205,7 @@ v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VI ...@@ -205,7 +205,7 @@ v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VI
show create view v4; show create view v4;
View Create View character_set_client collation_connection View Create View character_set_client collation_connection
v4 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS select `t1`.`a` AS `a` from `t1` latin1 latin1_swedish_ci v4 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS select `t1`.`a` AS `a` from `t1` latin1 latin1_swedish_ci
MySQL upgrade detected MariaDB upgrade detected
Phase 1/7: Checking and upgrading mysql database Phase 1/7: Checking and upgrading mysql database
Processing databases Processing databases
mysql mysql
...@@ -324,7 +324,7 @@ drop view v1,v2,v3,v4; ...@@ -324,7 +324,7 @@ drop view v1,v2,v3,v4;
rename table mysql.event to mysql.ev_bk; rename table mysql.event to mysql.ev_bk;
flush tables; flush tables;
The --upgrade-system-tables option was used, user tables won't be touched. The --upgrade-system-tables option was used, user tables won't be touched.
MySQL upgrade detected MariaDB upgrade detected
Phase 1/7: Checking and upgrading mysql database Phase 1/7: Checking and upgrading mysql database
Processing databases Processing databases
mysql mysql
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
update mysql.user set password=password("foo") where user='root'; update mysql.user set password=password("foo") where user='root';
--replace_regex /[^ ]*mysql_upgrade_info/...mysql_upgrade_info/
--exec $MYSQL_UPGRADE --exec $MYSQL_UPGRADE
connect(con1,localhost,root,foo,,,); connect(con1,localhost,root,foo,,,);
...@@ -21,3 +22,6 @@ update mysql.user set password='' where user='root'; ...@@ -21,3 +22,6 @@ update mysql.user set password='' where user='root';
flush privileges; flush privileges;
# Load event table # Load event table
set global event_scheduler=OFF; set global event_scheduler=OFF;
let MYSQLD_DATADIR= `select @@datadir`;
--remove_file $MYSQLD_DATADIR/mysql_upgrade_info
...@@ -17,7 +17,7 @@ let $MYSQLD_DATADIR= `select @@datadir`; ...@@ -17,7 +17,7 @@ let $MYSQLD_DATADIR= `select @@datadir`;
file_exists $MYSQLD_DATADIR/mysql_upgrade_info; file_exists $MYSQLD_DATADIR/mysql_upgrade_info;
--echo Run it again - should say already completed --echo Run it again - should say already completed
--replace_result $MYSQL_SERVER_VERSION VERSION --replace_regex /upgraded to [^\n]*/upgraded to VERSION./ /again for [^\n]*/again for VERSION./
--exec $MYSQL_UPGRADE 2>&1 --exec $MYSQL_UPGRADE 2>&1
# It should have created a file in the MySQL Servers datadir # It should have created a file in the MySQL Servers datadir
...@@ -126,7 +126,7 @@ let $MYSQLD_DATADIR= `select @@datadir`; ...@@ -126,7 +126,7 @@ let $MYSQLD_DATADIR= `select @@datadir`;
--remove_file $MYSQLD_DATADIR/mysql_upgrade_info --remove_file $MYSQLD_DATADIR/mysql_upgrade_info
--echo # Running mysql_upgrade with --skip-write-binlog.. --echo # Running mysql_upgrade with --skip-write-binlog..
--replace_result $MYSQLTEST_VARDIR var --replace_regex /[^ ]*mysql_upgrade_info/...mysql_upgrade_info/
--exec $MYSQL_UPGRADE --skip-write-binlog --exec $MYSQL_UPGRADE --skip-write-binlog
# mysql_upgrade must have created mysql_upgrade_info file, # mysql_upgrade must have created mysql_upgrade_info file,
...@@ -140,6 +140,9 @@ let $MYSQLD_DATADIR= `select @@datadir`; ...@@ -140,6 +140,9 @@ let $MYSQLD_DATADIR= `select @@datadir`;
--echo Run mysql_upgrade with unauthorized access --echo Run mysql_upgrade with unauthorized access
--error 1 --error 1
--exec $MYSQL_UPGRADE --skip-verbose --user=root --password=wrong_password 2>&1 --exec $MYSQL_UPGRADE --skip-verbose --user=root --password=wrong_password 2>&1
--replace_regex /.*mysqlcheck.*: Got/mysqlcheck: Got/ /\([0-9|-]*\)/(errno)/
--error 1
--exec $MYSQL_UPGRADE --skip-verbose --skip-version-check --user=root --password=wrong_password 2>&1
--echo # --echo #
--echo # MDEV-4332 Increase username length from 16 characters --echo # MDEV-4332 Increase username length from 16 characters
...@@ -235,6 +238,7 @@ FLUSH TABLES mysql.user; ...@@ -235,6 +238,7 @@ FLUSH TABLES mysql.user;
FLUSH PRIVILEGES; FLUSH PRIVILEGES;
SHOW CREATE TABLE mysql.user; SHOW CREATE TABLE mysql.user;
--replace_result $MYSQLTEST_VARDIR var
--exec $MYSQL_UPGRADE --force 2>&1 --exec $MYSQL_UPGRADE --force 2>&1
SHOW CREATE TABLE mysql.user; SHOW CREATE TABLE mysql.user;
...@@ -279,6 +283,79 @@ SHOW GRANTS; ...@@ -279,6 +283,79 @@ SHOW GRANTS;
DROP ROLE `aRole`; DROP ROLE `aRole`;
--exec $MYSQL mysql < $MYSQLTEST_VARDIR/tmp/user.sql --exec $MYSQL mysql < $MYSQLTEST_VARDIR/tmp/user.sql
FLUSH PRIVILEGES; FLUSH PRIVILEGES;
--echo #
--echo # MDEV-27279: mariadb_upgrade add --check-if-upgrade-is-needed
--echo #
--error 1
--exec $MYSQL_UPGRADE --check-if-upgrade-is-needed --silent
--replace_regex /\d\d\.\d*\.\d*[^ .\n]*/MariaDB /
--error 1
--exec $MYSQL_UPGRADE --check-if-upgrade-is-needed
--replace_regex /\d\d\.\d*\.\d*[^ .\n]*/MariaDB / /'mysql.* as:[^\n]*/'mysql' as: mysql/
--error 1
--exec $MYSQL_UPGRADE --check-if-upgrade-is-needed --verbose
--echo #
--echo # MDEV-27279: mariadb_upgrade check-if-upgrade absence is do it
--echo #
--remove_file $MYSQLD_DATADIR/mysql_upgrade_info
--replace_regex /[^ ]*mysql_upgrade_info/...mysql_upgrade_info/
--exec $MYSQL_UPGRADE --check-if-upgrade-is-needed
--replace_regex /'mysql.* as:[^\n]*/'mysql' as: mysql/ /open .* Assuming/open XXX. Assuming/ /[^ ]*mysql_upgrade_info/...mysql_upgrade_info/
--exec $MYSQL_UPGRADE --check-if-upgrade-is-needed --verbose
--echo #
--echo # MDEV-27279: mariadb_upgrade check-if-upgrade with minor version change
--echo #
# take 3rd number of version and change to 0
let DATADIR= $MYSQLD_DATADIR;
perl;
my $ver= $ENV{'MYSQL_SERVER_VERSION'} or die "MYSQL_SERVER_VERSION not set";
my $file= $ENV{'DATADIR'} or die "MYSQLD_DATADIR not set";
$ver =~ s/^(\d*)\.(\d*).(\d*)(.*)/$1.$2.0$4/;
open(FILE, ">$file/mysql_upgrade_info") or die "Failed to open $file";
print FILE "$ver\n";
close(FILE);
EOF
--error 1
--exec $MYSQL_UPGRADE --check-if-upgrade-is-needed --silent
--replace_regex /\d\d\.\d*\.\d*[^ .\n]*/MariaDB / /'mysql.* as:[^\n]*/'mysql' as: mysql/
--error 1
--exec $MYSQL_UPGRADE --check-if-upgrade-is-needed --verbose
--replace_regex /\d\d\.\d*\.\d*[^ .\n]*/MariaDB /
--exec $MYSQL_UPGRADE
--remove_file $MYSQLD_DATADIR/mysql_upgrade_info
--echo #
--echo # MDEV-27279: mariadb_upgrade check-if-upgrade with major version change
--echo #
# take 2rd number of version and change to 0
let DATADIR= $MYSQLD_DATADIR;
perl;
my $ver= $ENV{'MYSQL_SERVER_VERSION'} or die "MYSQL_SERVER_VERSION not set";
my $file= $ENV{'DATADIR'} or die "MYSQLD_DATADIR not set";
$ver =~ s/^(\d*)\.(\d*).(\d*)(.*)/$1.0.$3$4/;
open(FILE, ">$file/mysql_upgrade_info") or die "Failed to open $file";
print FILE "$ver\n";
close(FILE);
EOF
--exec $MYSQL_UPGRADE --check-if-upgrade-is-needed --silent
--replace_regex /\d\d\.\d*\.\d*[^ .\n]*/MariaDB /
--exec $MYSQL_UPGRADE --check-if-upgrade-is-needed
--replace_regex /\d\d\.\d*\.\d*[^ .\n]*/MariaDB / /'mysql.* as:[^\n]*/'mysql' as: mysql/
--exec $MYSQL_UPGRADE --check-if-upgrade-is-needed --verbose
--remove_file $MYSQLD_DATADIR/mysql_upgrade_info --remove_file $MYSQLD_DATADIR/mysql_upgrade_info
--echo End of 10.2 tests --echo End of 10.2 tests
...@@ -26,7 +26,8 @@ uninstall plugin blackhole; ...@@ -26,7 +26,8 @@ uninstall plugin blackhole;
uninstall plugin archive; uninstall plugin archive;
select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test'; select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test';
# upgrade from 10.1 - engines aren't enabled --echo # upgrade from 10.1 - engines aren't enabled
--replace_regex /\d\d\.\d*\.\d*[^ .\n]*/MariaDB /
exec $MYSQL_UPGRADE 2>&1; exec $MYSQL_UPGRADE 2>&1;
select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test'; select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test';
...@@ -39,14 +40,16 @@ write_file $datadir/mysql_upgrade_info; ...@@ -39,14 +40,16 @@ write_file $datadir/mysql_upgrade_info;
10.1.10-MariaDB 10.1.10-MariaDB
EOF EOF
# still upgrade from 10.1 --echo # still upgrade from 10.1
--replace_regex /\d\d\.\d*\.\d*[^ .\n]*/MariaDB /
exec $MYSQL_UPGRADE 2>&1; exec $MYSQL_UPGRADE 2>&1;
select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test'; select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test';
alter table mysql.user drop column default_role, drop column max_statement_time; alter table mysql.user drop column default_role, drop column max_statement_time;
remove_file $datadir/mysql_upgrade_info; remove_file $datadir/mysql_upgrade_info;
# upgrade from 10.0 - engines are enabled --echo # upgrade from 10.0 - engines are enabled
--replace_regex /\d\d\.\d*\.\d*[^ .\n]*/MariaDB /
exec $MYSQL_UPGRADE 2>&1; exec $MYSQL_UPGRADE 2>&1;
select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test'; select table_catalog, table_schema, table_name, table_type, engine, row_format, table_rows, data_length, table_comment from information_schema.tables where table_schema='test';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment