Skip to content

Commit 9cdb3d2

Browse files
committed
Modified the bug fix for MDEV-36554 by replacing the general
mechanishm for disabling assertions in InnoDB code with solution specific to this rollback issue. The appliers sets a flag in the applier thread for the duration of the local rollback. This is used in InnoDB code to detect a local rollback.
1 parent 7694880 commit 9cdb3d2

File tree

8 files changed

+37
-35
lines changed

8 files changed

+37
-35
lines changed

include/mysql/service_wsrep.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ extern struct wsrep_service_st {
6969
bool (*wsrep_thd_ignore_table_func)(MYSQL_THD thd);
7070
long long (*wsrep_thd_trx_seqno_func)(const MYSQL_THD thd);
7171
my_bool (*wsrep_thd_is_aborting_func)(const MYSQL_THD thd);
72+
my_bool (*wsrep_thd_in_rollback_func)(const THD *thd);
7273
void (*wsrep_set_data_home_dir_func)(const char *data_dir);
7374
my_bool (*wsrep_thd_is_BF_func)(const MYSQL_THD thd, my_bool sync);
7475
my_bool (*wsrep_thd_is_local_func)(const MYSQL_THD thd);
@@ -128,6 +129,7 @@ extern struct wsrep_service_st {
128129
#define wsrep_set_data_home_dir(A) wsrep_service->wsrep_set_data_home_dir_func(A)
129130
#define wsrep_thd_is_BF(T,S) wsrep_service->wsrep_thd_is_BF_func(T,S)
130131
#define wsrep_thd_is_aborting(T) wsrep_service->wsrep_thd_is_aborting_func(T)
132+
#define wsrep_thd_in_rollback_func(T) wsrep_service->wsrep_thd_in_rollback_func(T)
131133
#define wsrep_thd_is_local(T) wsrep_service->wsrep_thd_is_local_func(T)
132134
#define wsrep_thd_self_abort(T) wsrep_service->wsrep_thd_self_abort_func(T)
133135
#define wsrep_thd_append_key(T,W,N,K) wsrep_service->wsrep_thd_append_key_func(T,W,N,K)
@@ -230,6 +232,8 @@ extern "C" my_bool wsrep_thd_order_before(const MYSQL_THD left, const MYSQL_THD
230232
extern "C" my_bool wsrep_thd_skip_locking(const MYSQL_THD thd);
231233
/* Return true if thd is aborting */
232234
extern "C" my_bool wsrep_thd_is_aborting(const MYSQL_THD thd);
235+
/* Return true if thd is a WSREP applier rolling back a transaction locally */
236+
extern "C" my_bool wsrep_thd_in_rollback(const MYSQL_THD thd);
233237

234238
struct wsrep_key;
235239
struct wsrep_key_array;

sql/service_wsrep.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,22 @@ extern "C" my_bool wsrep_thd_is_aborting(const MYSQL_THD thd)
295295
return false;
296296
}
297297

298+
/** Check if a wsrep applier is rolling back a transaction locally.
299+
300+
This function is used for notifying InnoDB routines that this thread
301+
is rolling back a wsrep transaction locally.
302+
303+
@param thd thread handle
304+
305+
@return true if wsrep applier is rolling back a transaction locally
306+
@return false otherwise
307+
308+
*/
309+
extern "C" my_bool wsrep_thd_in_rollback(const THD *thd)
310+
{
311+
return thd->wsrep_applier_is_in_rollback();
312+
}
313+
298314
static inline enum wsrep::key::type
299315
map_key_type(enum Wsrep_service_key_type type)
300316
{

sql/sql_class.cc

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
742742
,
743743
wsrep_applier(is_wsrep_applier),
744744
wsrep_applier_closing(false),
745+
wsrep_applier_in_rollback(false),
745746
wsrep_client_thread(false),
746747
wsrep_retry_counter(0),
747748
wsrep_PA_safe(true),
@@ -762,7 +763,6 @@ THD::THD(my_thread_id id, bool is_wsrep_applier)
762763
wsrep_affected_rows(0),
763764
wsrep_has_ignored_error(false),
764765
wsrep_was_on(false),
765-
wsrep_assert_bitmask(0),
766766
wsrep_ignore_table(false),
767767
wsrep_aborter(0),
768768
wsrep_delayed_BF_abort(false),
@@ -8660,20 +8660,3 @@ LEX_CSTRING make_string(THD *thd, const char *start_ptr,
86608660
size_t length= end_ptr - start_ptr;
86618661
return {strmake_root(thd->mem_root, start_ptr, length), length};
86628662
}
8663-
8664-
8665-
#ifdef WITH_WSREP
8666-
void wsrep_set_assert(THD *thd, uint64 assert, bool is_disabled)
8667-
{
8668-
if (is_disabled) {
8669-
thd->wsrep_assert_bitmask |= assert;
8670-
} else {
8671-
thd->wsrep_assert_bitmask &= ~assert;
8672-
}
8673-
}
8674-
8675-
bool wsrep_get_assert(THD *thd, uint64 assert)
8676-
{
8677-
return (thd->wsrep_assert_bitmask & assert ? true: false);
8678-
}
8679-
#endif /* WITH_WSREP */

sql/sql_class.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5641,6 +5641,8 @@ class THD: public THD_count, /* this must be first */
56415641
#ifdef WITH_WSREP
56425642
bool wsrep_applier; /* dedicated slave applier thread */
56435643
bool wsrep_applier_closing; /* applier marked to close */
5644+
bool wsrep_applier_in_rollback; /* applier is rolling
5645+
back a transaction */
56445646
bool wsrep_client_thread; /* to identify client threads*/
56455647
query_id_t wsrep_last_query_id;
56465648
XID wsrep_xid;
@@ -5682,7 +5684,6 @@ class THD: public THD_count, /* this must be first */
56825684
bool wsrep_has_ignored_error;
56835685
/* true if wsrep_on was ON in last wsrep_on_update */
56845686
bool wsrep_was_on;
5685-
uint64 wsrep_assert_bitmask;
56865687

56875688
/*
56885689
When enabled, do not replicate/binlog updates from the current table that's
@@ -5760,6 +5761,8 @@ class THD: public THD_count, /* this must be first */
57605761
Wsrep_applier_service* wsrep_applier_service;
57615762
/* wait_for_commit struct for binlog group commit */
57625763
wait_for_commit wsrep_wfc;
5764+
bool wsrep_applier_is_in_rollback() const
5765+
{ return wsrep_applier_in_rollback; }
57635766
#endif /* WITH_WSREP */
57645767

57655768
/* Handling of timeouts for commands */
@@ -8522,11 +8525,5 @@ LEX_CSTRING make_string(THD *thd, const char *start_ptr,
85228525

85238526
#include "deprecation.h"
85248527

8525-
8526-
#ifdef WITH_WSREP
8527-
extern void wsrep_set_assert(THD* thd, uint64 assert, bool is_disabled);
8528-
extern bool wsrep_get_assert(THD* thd, uint64 assert);
8529-
#endif
8530-
85318528
#endif /* MYSQL_SERVER */
85328529
#endif /* SQL_CLASS_INCLUDED */

sql/sql_plugin_services.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ static struct wsrep_service_st wsrep_handler = {
159159
wsrep_thd_ignore_table,
160160
wsrep_thd_trx_seqno,
161161
wsrep_thd_is_aborting,
162+
wsrep_thd_in_rollback,
162163
wsrep_set_data_home_dir,
163164
wsrep_thd_is_BF,
164165
wsrep_thd_is_local,

sql/wsrep_applier.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,14 @@ int wsrep_apply_events(THD* thd,
292292

293293
/* rollback to savepoint without telling Wsrep-lib */
294294
thd->variables.wsrep_on = false;
295-
wsrep_set_assert(thd, true, WSREP_ASSERT_INNODB_TRX);
295+
thd->wsrep_applier_in_rollback= true;
296296
if (FALSE != trans_rollback_to_savepoint(thd, savepoint)) {
297297
thd->variables.wsrep_on = true;
298-
wsrep_set_assert(thd, false, WSREP_ASSERT_INNODB_TRX);
298+
thd->wsrep_applier_in_rollback= false;
299299
break;
300300
}
301301
thd->variables.wsrep_on = true;
302-
wsrep_set_assert(thd, false, WSREP_ASSERT_INNODB_TRX);
302+
thd->wsrep_applier_in_rollback= false;
303303

304304
/* reset THD object for retry */
305305
thd->clear_error();

sql/wsrep_dummy.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ long long wsrep_thd_trx_seqno(const THD *)
9494
my_bool wsrep_thd_is_aborting(const THD *)
9595
{ return 0; }
9696

97+
my_bool wsrep_thd_in_rollback(const THD *)
98+
{ return 0; }
99+
97100
void wsrep_set_data_home_dir(const char *)
98101
{ }
99102

storage/innobase/trx/trx0trx.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,10 +1382,6 @@ ATTRIBUTE_NOINLINE static void trx_commit_cleanup(trx_undo_t *&undo)
13821382
undo= nullptr;
13831383
}
13841384

1385-
1386-
extern bool wsrep_get_assert(THD *thd, uint64 assert);
1387-
1388-
13891385
TRANSACTIONAL_INLINE inline void trx_t::commit_in_memory(const mtr_t *mtr)
13901386
{
13911387
/* We already detached from rseg in write_serialisation_history() */
@@ -1505,9 +1501,11 @@ TRANSACTIONAL_INLINE inline void trx_t::commit_in_memory(const mtr_t *mtr)
15051501
trx_finalize_for_fts(this, undo_no != 0);
15061502

15071503
#ifdef WITH_WSREP
1508-
if (!mysql_thd || !wsrep_get_assert(mysql_thd, WSREP_ASSERT_INNODB_TRX)) {
1509-
ut_ad(is_wsrep() == wsrep_on(mysql_thd));
1510-
}
1504+
/* Assert that any transaction which is started as a wsrep
1505+
transaction, also commits or rolls back as a wsrep
1506+
transaction. Wsrep applier may turn wsrep off temporarily for
1507+
rollback when the applying of wsrep transactions is retried. */
1508+
ut_ad(is_wsrep() == wsrep_on(mysql_thd) || wsrep_thd_in_rollback(mysql_thd));
15111509

15121510
/* Serialization history has been written and the transaction is
15131511
committed in memory, which makes this commit ordered. Release commit

0 commit comments

Comments
 (0)