MDEV-34891 : SST failure occurs when gtid_strict_mode is enabled

Problem was that initial GTID was set on wsrep_before_prepare
out-of-order. In practice GTID was set to same as previous
executed transaction GTID. In recovery valid GTID was found
from prepared transaction and this transaction is committed
leading to fact that same GTID was executed twice.

This is fixed by setting invalid GTID at wsrep_before_prepare
and later in wsrep_before_commit actual correct GTID is set
and this setting is done while we are in commit monitor i.e.
assigment is done in order of replication.

In recovery if prepared transaction is found we check its
GTID, if it is invalid transaction will be rolled back
and if it is valid it will be committed.

Initialize gtid seqno from recovered seqno when
bootstrapping a new cluster.

Added two test cases for both mariabackup and rsync SST methods
to show that GTIDs remain consistent on cluster and that
all expected rows are in the table.

Added tests for wsrep GTID recovery with binlog on and off.

Signed-off-by: Julius Goryavsky <julius.goryavsky@mariadb.com>
This commit is contained in:
Jan Lindström 2025-01-02 11:13:32 +02:00 committed by Julius Goryavsky
commit b167730499
23 changed files with 1853 additions and 26 deletions

View file

@ -1,4 +1,4 @@
/* Copyright 2016-2023 Codership Oy <http://www.codership.com>
/* Copyright 2016-2025 Codership Oy <http://www.codership.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -265,12 +265,17 @@ static inline int wsrep_before_prepare(THD* thd, bool all)
{
DBUG_RETURN(ret);
}
if ((ret= thd->wsrep_cs().before_prepare()) == 0)
{
DBUG_ASSERT(!thd->wsrep_trx().ws_meta().gtid().is_undefined());
/* Here we init xid with UUID and wsrep seqno. GTID is
set to undefined because commit order is decided later
in wsrep_before_commit(). wsrep_before_prepare() is
executed out of order. */
wsrep_xid_init(&thd->wsrep_xid,
thd->wsrep_trx().ws_meta().gtid(),
wsrep_gtid_server.gtid());
wsrep_gtid_server.undefined());
}
mysql_mutex_lock(&thd->LOCK_thd_kill);
@ -470,12 +475,6 @@ static inline
int wsrep_after_statement(THD* thd)
{
DBUG_ENTER("wsrep_after_statement");
WSREP_DEBUG("wsrep_after_statement for %lu client_state %s "
" client_mode %s trans_state %s",
thd_get_thread_id(thd),
wsrep::to_c_string(thd->wsrep_cs().state()),
wsrep::to_c_string(thd->wsrep_cs().mode()),
wsrep::to_c_string(thd->wsrep_cs().transaction().state()));
int ret= ((thd->wsrep_cs().state() != wsrep::client_state::s_none &&
thd->wsrep_cs().mode() == Wsrep_client_state::m_local) &&
!thd->internal_transaction() ?