Commit 5d37cac7 authored by Nikita Malyavin's avatar Nikita Malyavin

MDEV-33348 ALTER TABLE lock waiting stages are indistinguishable

Several points of synchronization during ALTER TABLE COPY looked identical
in the progress report query. Besides, if its the late lock upgrade stage,
the data would be:
STAGE   0
MAX_STAGE       0
PROGRESS        0.000

which looks irrelevant.

This patch moves thd_progress_deinit call after the last lock upgrade.

Also, for online alter, if there is nothing to replicate, the
progress and max_progress values would be 0, which discard the result data
on the side of sql_show, see processlist_callback in sql_show.cc.
So now the minimal max_progress will be 1. To avoid 0% progress in the
report, minimax progress value is also set to 1, so we will see 100% if
there's nothing to replicate.
parent ba6f9943
......@@ -238,3 +238,33 @@ ERROR 0A000: LOCK=NONE is not supported. Reason: Function or expression 'NEXTVAL
drop table t2;
drop table t1;
drop sequence s;
#
# MDEV-33348 ALTER TABLE lock waiting stages are indistinguishable
#
connect con2, localhost, root,,;
create or replace table t1 (a int);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
insert t1 values (5);
connection con2;
begin;
select * from t1;
a
5
connection default;
alter table t1 add b int NULL, algorithm= copy, lock= none;
connection con2;
select stage, state, info from information_schema.processlist where id = @con;
stage 4
state Waiting for table metadata lock
info alter table t1 add b int NULL, algorithm= copy, lock= none
rollback;
connection default;
drop table t1;
disconnect con2;
#
# End of 11.2 tests
#
......@@ -246,3 +246,45 @@ alter table t2 modify b int not null default (nextval(s)), lock=none;
drop table t2;
drop table t1;
drop sequence s;
--echo #
--echo # MDEV-33348 ALTER TABLE lock waiting stages are indistinguishable
--echo #
--connect (con2, localhost, root,,)
create or replace table t1 (a int);
show create table t1;
insert t1 values (5);
--connection con2
begin;
select * from t1;
--connection default
--let $con= `select connection_id()`
send alter table t1 add b int NULL, algorithm= copy, lock= none;
--connection con2
disable_query_log;
eval set @con= $con;
enable_query_log;
let $wait_condition= select stage = 4 and progress = 100
and state= "Waiting for table metadata lock"
from information_schema.processlist where id = @con;
--source include/wait_condition.inc
query_vertical select stage, state, info from information_schema.processlist where id = @con;
rollback;
--connection default
reap;
drop table t1;
--disconnect con2
--echo #
--echo # End of 11.2 tests
--echo #
......@@ -11364,6 +11364,15 @@ do_continue:;
new_table->mark_columns_needed_for_insert();
mysql_bin_log.write_table_map(thd, new_table, 1);
}
/*
if ORDER BY: sorting
always: copying, building indexes.
if online: reading up the binlog (second binlog is being written)
reading up the second binlog under exclusive lock
*/
thd_progress_init(thd, MY_TEST(order) + 2 + 2 * MY_TEST(online));
if (copy_data_between_tables(thd, table, new_table,
ignore,
order_num, order, &copied, &deleted,
......@@ -11532,6 +11541,8 @@ do_continue:;
NULL);
table_list->table= table= NULL; /* Safety */
thd_progress_end(thd);
DBUG_PRINT("info", ("is_table_renamed: %d engine_changed: %d",
alter_ctx.is_table_renamed(), engine_changed));
......@@ -11761,6 +11772,8 @@ do_continue:;
DBUG_PRINT("error", ("err_new_table_cleanup"));
thd->variables.option_bits&= ~OPTION_BIN_COMMIT_OFF;
thd_progress_end(thd);
/*
No default value was provided for a DATE/DATETIME field, the
current sql_mode doesn't allow the '0000-00-00' value and
......@@ -11890,7 +11903,7 @@ static int online_alter_read_from_binlog(THD *thd, rpl_group_info *rgi,
IO_CACHE *log_file= log->flip();
thd_progress_report(thd, 0, my_b_write_tell(log_file));
thd_progress_report(thd, 1, MY_MAX(1, my_b_write_tell(log_file)));
Has_default_error_handler hdeh;
thd->push_internal_handler(&hdeh);
......@@ -11957,14 +11970,6 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
MYSQL_TIME query_start;
DBUG_ENTER("copy_data_between_tables");
/*
if ORDER BY: sorting
always: copying, building indexes.
if online: reading up the binlog (second binlog is being written)
reading up the second binlog under exclusive lock
*/
thd_progress_init(thd, MY_TEST(order) + 2 + 2 * MY_TEST(online));
if (!(copy= new (thd->mem_root) Copy_field[to->s->fields]))
DBUG_RETURN(-1);
......@@ -12431,7 +12436,6 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
if (error < 0 && !from->s->tmp_table &&
to->file->extra(HA_EXTRA_PREPARE_FOR_RENAME))
error= 1;
thd_progress_end(thd);
DBUG_RETURN(error > 0 ? -1 : 0);
}
......
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