From f859b82fde1f3169ce775540e065d47db81c5d54 Mon Sep 17 00:00:00 2001 From: Nikita Malyavin Date: Tue, 7 Nov 2023 19:05:17 +0100 Subject: [PATCH] MCOL-5603 Online alter can break data consistency Propagate the TL lock to TL_READ_NO_INSERT, blocking any concurrent writes until the end of a copy stage. After that, this lock will be unlocked, allowing a window to write into a table before MDL is upgraded to exclusive (see online_alter_read_from_binlog call and the "alter_table_online_before_lock" debug syncpoint). This window will be covered by the second replication iteration after the lock upgrade --- dbcon/mysql/ha_mcs.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dbcon/mysql/ha_mcs.cpp b/dbcon/mysql/ha_mcs.cpp index c735dbc454..ecf99f9834 100644 --- a/dbcon/mysql/ha_mcs.cpp +++ b/dbcon/mysql/ha_mcs.cpp @@ -922,6 +922,10 @@ THR_LOCK_DATA** ha_mcs::store_lock(THD* thd, THR_LOCK_DATA** to, enum thr_lock_t #ifdef INFINIDB_DEBUG puts("store_lock"); #endif + if (thd_sql_command(thd) == SQLCOM_ALTER_TABLE + && thd_tx_isolation(thd) == ISO_REPEATABLE_READ + && lock_type == TL_READ) + table->reginfo.lock_type= TL_READ_NO_INSERT; return to; }