Commit 6dab094f authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-20257 Server crashes in Grant_table_base::init_read_record upon crash-upgrade

when opening the `user` table separately, reset `thd->open_tables`
for the duration of open, otherwise auto-repair fallback-and-retry
will close *all* tables (but reopen only `user`)
parent a58b2b3b
call mtr.add_suppression("/mysql/user");
# switching from mysql.global_priv to mysql.user
flush tables;
flush privileges;
Warnings:
Error 145 Table './mysql/user' is marked as crashed and should be repaired
Warning 1034 12544 clients are using or haven't closed the table properly
Note 1034 Table is fixed
# switching back from mysql.user to mysql.global_priv
#
# MDEV-20257 Server crashes in Grant_table_base::init_read_record upon crash-upgrade
#
call mtr.add_suppression("/mysql/user");
source include/switch_to_mysql_user.inc;
let mysql_datadir=`select @@datadir`;
flush tables;
perl;
$f=$ENV{mysql_datadir} . '/mysql/user.MAI';
sysopen F, $f, 2 or die "sysopen $f: $!";
# set the open_count to 1, "table was not closed properly"
sysseek F, 24, O_RDWR or die "sysseek: $!";
syswrite F, 1, 1 or die "syswrite: $!";
EOF
flush privileges;
source include/switch_to_mysql_global_priv.inc;
......@@ -1847,10 +1847,13 @@ class Grant_tables
int res= really_open(thd, first, &counter);
/* if User_table_json wasn't found, let's try User_table_tabular */
if (!res && (which_tables & Table_user) && !(tables[USER_TABLE].table))
if (!res && (which_tables & Table_user) && !tables[USER_TABLE].table)
{
uint unused;
TABLE_LIST *tl= tables + USER_TABLE;
TABLE *backup_open_tables= thd->open_tables;
thd->set_open_tables(NULL);
tl->init_one_table(&MYSQL_SCHEMA_NAME, &MYSQL_TABLE_NAME_USER,
NULL, lock_type);
tl->open_type= OT_BASE_ONLY;
......@@ -1859,6 +1862,12 @@ class Grant_tables
p_user_table= &m_user_table_tabular;
counter++;
res= really_open(thd, tl, &unused);
thd->set_open_tables(backup_open_tables);
if (tables[USER_TABLE].table)
{
tables[USER_TABLE].table->next= backup_open_tables;
thd->set_open_tables(tables[USER_TABLE].table);
}
}
if (res)
DBUG_RETURN(res);
......
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