From 9394cc89143e4fce3126a96ac1c8a91a66d71dea Mon Sep 17 00:00:00 2001 From: Daniele Sciascia Date: Sat, 21 Mar 2020 08:17:28 +0100 Subject: MDEV-21675: Data inconsistency after multirow insert rollback (#1474) * Remove dead code * MDEV-21675 Data inconsistency after multirow insert rollback This patch fixes data inconsistencies that happen after rollback of multirow inserts, with binlog disabled. For example, statements such as `INSERT INTO t1 VALUES (1,'a'),(1,'b')` that fail with duplicate key error. In such cases the whole statement is rolled back. However, with wsrep_emulate_binlog in effect, the IO_CACHE would not be truncated, and the pending rows events would be replicated to the rest of the cluster. In the above example, it would result in row (1,'a') being replicated, whereas locally the statement is rolled back entirely. Making the cluster inconsistent. The patch changes the code so that prior to statement rollback, pending rows event are removed and the stmt cache reset. That patch also introduces MTR tests that excercise multirow insert statements for regular, and streaming replication. --- sql/log.cc | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'sql/log.cc') diff --git a/sql/log.cc b/sql/log.cc index ffeb3661783..1da73ab25df 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -10702,7 +10702,6 @@ maria_declare_plugin(binlog) maria_declare_plugin_end; #ifdef WITH_WSREP -#include "wsrep_trans_observer.h" #include "wsrep_mysqld.h" IO_CACHE *wsrep_get_trans_cache(THD * thd) @@ -10725,33 +10724,33 @@ void wsrep_thd_binlog_trx_reset(THD * thd) /* todo: fix autocommit select to not call the caller */ - if (thd_get_ha_data(thd, binlog_hton) != NULL) + binlog_cache_mngr *const cache_mngr= + (binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton); + if (cache_mngr) { - binlog_cache_mngr *const cache_mngr= - (binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton); - if (cache_mngr) + cache_mngr->reset(false, true); + if (!cache_mngr->stmt_cache.empty()) { - cache_mngr->reset(false, true); - if (!cache_mngr->stmt_cache.empty()) - { - WSREP_DEBUG("pending events in stmt cache, sql: %s", thd->query()); - cache_mngr->stmt_cache.reset(); - } + WSREP_DEBUG("pending events in stmt cache, sql: %s", thd->query()); + cache_mngr->stmt_cache.reset(); } } thd->clear_binlog_table_maps(); DBUG_VOID_RETURN; } - -void thd_binlog_rollback_stmt(THD * thd) +void wsrep_thd_binlog_stmt_rollback(THD * thd) { - WSREP_DEBUG("thd_binlog_rollback_stmt connection: %llu", - thd->thread_id); + DBUG_ENTER("wsrep_thd_binlog_stmt_rollback"); + WSREP_DEBUG("wsrep_thd_binlog_stmt_rollback"); binlog_cache_mngr *const cache_mngr= (binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton); if (cache_mngr) - cache_mngr->trx_cache.set_prev_position(MY_OFF_T_UNDEF); + { + thd->binlog_remove_pending_rows_event(TRUE, TRUE); + cache_mngr->stmt_cache.reset(); + } + DBUG_VOID_RETURN; } bool wsrep_stmt_rollback_is_safe(THD* thd) -- cgit v1.2.1