1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-07 00:04:31 +03:00

MDEV-32100 Online ALTER TABLE ends with 1032 under some isolation levels

1032 (Can't find record) could be emitted when ALTER TABLE is execued vs
concurrent DELETE/UPDATE/other DML that would require search on the online
ALTER's side.

Innodb's INPLACE, in comparison, creates a new trx_t and uses it in scope
of the alter table context.

ALTER TABLE class of statements (i.g. CREATE INDEX, OPTIMIZE, etc.) is
expected to be unaffected by the value of current session's transaction
isolation.

This patch save-and-restores thd->tx_isolation and sets in to
ISO_REPEATABLE_READ for almost a whole mysql_alter_table duration, to avoid
any possible side-effect of it. This should be primarily done before the
lock_tables call, to initialize the storage engine's local value correctly
during the store_lock() call.

sql_table.cc: set thd->tx_isolation to ISO_REPEATABLE_READ in
mysql_alter_table and then restore it to the original value in the end of
the call.
This commit is contained in:
Nikita Malyavin
2023-09-11 17:54:10 +04:00
parent 5c5123dfe0
commit 46ee272a10
3 changed files with 110 additions and 0 deletions

View File

@@ -65,6 +65,7 @@
#include "rpl_rli.h"
#include "log.h"
#include "sql_debug.h"
#include "scope.h"
#ifdef _WIN32
#include <io.h>
@@ -10236,6 +10237,12 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db,
table_list->lock_type= TL_READ;
}
enum_tx_isolation iso_level_initial= thd->tx_isolation;
SCOPE_EXIT([thd, iso_level_initial](){
thd->tx_isolation= iso_level_initial;
});
thd->tx_isolation= ISO_REPEATABLE_READ;
DEBUG_SYNC(thd, "alter_table_before_open_tables");
thd->open_options|= HA_OPEN_FOR_ALTER;