Skip to content

Commit 39a44a2

Browse files
committed
MDEV-34902: debian-start erroneously reports issues
Remove the complexity of check_for_crashed_tables by using mariadb-check directly. This can auto-repair. We use --fast to limit to Aria and MyISAM tables per the CHECK TABLES FAST option. Added a check_for_crashed_system_tables on the system tables before an upgrade to ensure they are ready to be upgraded. Removed the mail part of checking tables. With this removed there is no need for a mailx package recommendation. Adjusted the bash scripts to use arrays for correct command execution. Corrected message for insecure passwords to refer to the mysql.global_privs table.
1 parent b81aef5 commit 39a44a2

File tree

3 files changed

+22
-59
lines changed

3 files changed

+22
-59
lines changed

debian/additions/debian-start

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,24 @@ then
2222
. /etc/default/mariadb
2323
fi
2424

25-
MARIADB="/usr/bin/mariadb --defaults-extra-file=/etc/mysql/debian.cnf"
26-
MYADMIN="/usr/bin/mariadb-admin --defaults-extra-file=/etc/mysql/debian.cnf"
25+
MARIADB=(/usr/bin/mariadb --defaults-extra-file=/etc/mysql/debian.cnf)
2726
# Don't run full mariadb-upgrade on every server restart, use --version-check to do it only once
28-
MYUPGRADE="/usr/bin/mariadb-upgrade --defaults-extra-file=/etc/mysql/debian.cnf --version-check --silent"
29-
MYCHECK_SUBJECT="WARNING: mariadb-check has found corrupt tables"
30-
MYCHECK_RCPT="${MYCHECK_RCPT:-root}"
27+
MYUPGRADE=(/usr/bin/mariadb-upgrade --defaults-extra-file=/etc/mysql/debian.cnf --version-check --silent)
28+
MARIADBCHECK=(/usr/bin/mariadb-check --defaults-extra-file=/etc/mysql/debian.cnf --fast --auto-repair --silent)
29+
MARIADBCHECK_ALL=( "${MARIADBCHECK}" --all-databases)
3130

3231
## Checking for corrupt, not cleanly closed (only for MyISAM and Aria engines) and upgrade needing tables.
3332

3433
# The following commands should be run when the server is up but in background
3534
# where they do not block the server start and in one shell instance so that
3635
# they run sequentially. They are supposed not to echo anything to stdout.
37-
# If you want to disable the check for crashed tables comment
38-
# "check_for_crashed_tables" out.
3936
# (There may be no output to stdout inside the background process!)
4037

4138
# Need to ignore SIGHUP, as otherwise a SIGHUP can sometimes abort the upgrade
4239
# process in the middle.
4340
trap "" SIGHUP
4441
(
42+
check_for_crashed_system_tables;
4543
upgrade_system_tables_if_necessary;
4644
check_root_accounts;
4745
check_for_crashed_tables;

debian/additions/debian-start.inc.sh

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,26 @@
33
# This file is included by /etc/mysql/debian-start
44
#
55

6+
## Is there MyISAM or Aria system tables needing fixing
7+
# We want to recover these quickly before an upgrade.
8+
function check_for_crashed_system_tables()
9+
{
10+
set -e
11+
set -u
12+
13+
logger -p daemon.info -i -t"$0" "Triggering fast check and recovery for system tables"
14+
"${MARIADBCHECK[@]}" mysql
15+
}
16+
617
## Is there MyISAM or Aria unclosed tables.
718
# - Requires the server to be up.
819
# - Is supposed to run silently in background.
920
function check_for_crashed_tables() {
1021
set -e
1122
set -u
1223

13-
# But do it in the background to not stall the boot process.
14-
logger -p daemon.info -i -t"$0" "Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables"
15-
16-
# Checking for $? is unreliable so the size of the output is checked.
17-
# Some table handlers like HEAP do not support CHECK TABLE.
18-
tempfile=$(mktemp)
19-
20-
# We have to use xargs in this case, because a for loop barfs on the
21-
# spaces in the thing to be looped over.
22-
23-
# If a crashed table is encountered, the "mariadb" command will return with a status different from 0
24-
#
25-
# The first query will generate lines like.
26-
# select count(*) into @discard from 'mysql'.'db'
27-
# The second line will load all tables without printing any actual results,
28-
# but may show warnings and definitely is expected to have some error and
29-
# exit code if crashed tables are encountered.
30-
#
31-
# Note that inside single quotes must be quoted with '\'' (to be outside of single quotes).
32-
set +e
33-
# The $MARIADB is intentionally used to expand into a command and arguments
34-
# shellcheck disable=SC2086
35-
echo '
36-
SELECT CONCAT("select count(*) into @discard from '\''", TABLE_SCHEMA, "'\''.'\''", TABLE_NAME, "'\''")
37-
FROM information_schema.TABLES WHERE TABLE_SCHEMA<>"INFORMATION_SCHEMA" AND TABLE_SCHEMA<>"PERFORMANCE_SCHEMA"
38-
AND (ENGINE="MyISAM" OR ENGINE="Aria")
39-
' | \
40-
LC_ALL=C $MARIADB --skip-column-names --batch | \
41-
xargs --no-run-if-empty -i $MARIADB --skip-column-names --silent --batch --force -e "{}" &> "${tempfile}"
42-
set -e
43-
44-
if [ -s "$tempfile" ]
45-
then
46-
(
47-
/bin/echo -e "\n" \
48-
"Improperly closed tables are also reported if clients are accessing\n" \
49-
"the tables *now*. A list of current connections is below.\n";
50-
$MYADMIN processlist status
51-
) >> "${tempfile}"
52-
# Check for presence as a dependency on mailx would require an MTA.
53-
if [ -x /usr/bin/mailx ]
54-
then
55-
mailx -e -s"$MYCHECK_SUBJECT" "$MYCHECK_RCPT" < "$tempfile"
56-
fi
57-
(echo "$MYCHECK_SUBJECT"; cat "${tempfile}") | logger -p daemon.warn -i -t"$0"
58-
fi
59-
rm "${tempfile}"
24+
logger -p daemon.info -i -t"$0" "Triggering fast check and recovery for all tables"
25+
"${MARIADBCHECK_ALL[@]}"
6026
}
6127

6228
## Check for tables needing an upgrade.
@@ -70,7 +36,7 @@ function upgrade_system_tables_if_necessary() {
7036

7137
# Filter all "duplicate column", "duplicate key" and "unknown column"
7238
# errors as the script is designed to be idempotent.
73-
LC_ALL=C $MYUPGRADE \
39+
LC_ALL=C "${MYUPGRADE[@]}" \
7440
2>&1 \
7541
| grep -E -v '^(1|@had|ERROR (1051|1054|1060|1061|1146|1347|1348))' \
7642
| logger -p daemon.warn -i -t"$0"
@@ -90,9 +56,9 @@ function check_root_accounts() {
9056
JSON_VALUE(priv, '$.plugin') in ('mysql_native_password', 'mysql_old_password', 'parsec') AND
9157
JSON_VALUE(priv, '$.authentication_string') = '' AND
9258
JSON_VALUE(priv, '$.password_last_changed') != 0
93-
" | $MARIADB --skip-column-names)
59+
" | "${MARIADB[@]}" --skip-column-names)
9460
if [ "$ret" -ne "0" ]
9561
then
96-
logger -p daemon.warn -i -t"$0" "WARNING: mysql.user contains $ret root accounts without password!"
62+
logger -p daemon.warn -i -t"$0" "WARNING: mysql.global_priv contains $ret root accounts without password!"
9763
fi
9864
}

debian/control

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,7 @@ Description: MariaDB database core server files
674674

675675
Package: mariadb-server
676676
Architecture: any
677-
Suggests: mailx,
678-
mariadb-test,
677+
Suggests: mariadb-test,
679678
netcat-openbsd
680679
Recommends: libhtml-template-perl,
681680
pv

0 commit comments

Comments
 (0)