Skip to content

Commit 5a6de6f

Browse files
author
Jan Lindström
committed
MDEV-18848 : Galera: 10.4 node crashed with Assertion client_state.transaction().active() after altering SEQUENCE table's engine to myisam and back to innodb
We need to start Galera transaction for select NEXT VALUE FOR sequence if it is not yet started. Note that ALTER is handled as TOI and transaction is already started.
1 parent c6a890a commit 5a6de6f

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

mysql-test/suite/galera/r/galera_sequences.result

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,25 @@ ERROR 42S02: Table 'test.seq' doesn't exist
2525
connection node_2;
2626
SHOW CREATE SEQUENCE seq;
2727
ERROR 42S02: Table 'test.seq' doesn't exist
28+
connection node_1;
29+
CREATE SEQUENCE Seq1_1 START WITH 1 INCREMENT BY 1;
30+
select NEXT VALUE FOR Seq1_1;
31+
NEXT VALUE FOR Seq1_1
32+
1
33+
alter table Seq1_1 engine=myisam;
34+
select NEXT VALUE FOR Seq1_1;
35+
NEXT VALUE FOR Seq1_1
36+
1001
37+
alter table Seq1_1 engine=innodb;
38+
select NEXT VALUE FOR Seq1_1;
39+
NEXT VALUE FOR Seq1_1
40+
2001
41+
connection node_2;
42+
SHOW CREATE SEQUENCE Seq1_1;
43+
Table Create Table
44+
Seq1_1 CREATE SEQUENCE `Seq1_1` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB
45+
select NEXT VALUE FOR Seq1_1;
46+
NEXT VALUE FOR Seq1_1
47+
1
48+
connection node_1;
49+
DROP SEQUENCE Seq1_1;

mysql-test/suite/galera/t/galera_sequences.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
--source include/galera_cluster.inc
22

3+
#
4+
# MDEV-19353 : Alter Sequence do not replicate to another nodes with in Galera Cluster
5+
#
6+
37
--connection node_1
48
CREATE SEQUENCE `seq` start with 1 minvalue 1 maxvalue 1000000 increment by 0 cache 1000 nocycle ENGINE=InnoDB;
59
SHOW CREATE SEQUENCE seq;
@@ -22,3 +26,21 @@ SHOW CREATE SEQUENCE seq;
2226
--connection node_2
2327
--error ER_NO_SUCH_TABLE
2428
SHOW CREATE SEQUENCE seq;
29+
30+
#
31+
# MDEV-18848 : Galera: 10.4 node crashed with Assertion `client_state.transaction().active()` after altering SEQUENCE table's engine to myisam and back to innodb
32+
#
33+
--connection node_1
34+
CREATE SEQUENCE Seq1_1 START WITH 1 INCREMENT BY 1;
35+
select NEXT VALUE FOR Seq1_1;
36+
alter table Seq1_1 engine=myisam;
37+
select NEXT VALUE FOR Seq1_1;
38+
alter table Seq1_1 engine=innodb;
39+
select NEXT VALUE FOR Seq1_1;
40+
41+
--connection node_2
42+
SHOW CREATE SEQUENCE Seq1_1;
43+
select NEXT VALUE FOR Seq1_1;
44+
45+
--connection node_1
46+
DROP SEQUENCE Seq1_1;

sql/ha_sequence.cc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
#include "sql_base.h"
3131
#include "log_event.h"
3232

33+
#ifdef WITH_WSREP
34+
#include "wsrep_trans_observer.h" /* wsrep_start_transaction() */
35+
#endif
36+
3337
/*
3438
Table flags we should inherit and disable from the original engine.
3539
We add HA_STATS_RECORDS_IS_EXACT as ha_sequence::info() will ensure
@@ -199,6 +203,7 @@ int ha_sequence::write_row(const uchar *buf)
199203
int error;
200204
sequence_definition tmp_seq;
201205
bool sequence_locked;
206+
THD *thd= table->in_use;
202207
DBUG_ENTER("ha_sequence::write_row");
203208
DBUG_ASSERT(table->record[0] == buf);
204209

@@ -235,8 +240,6 @@ int ha_sequence::write_row(const uchar *buf)
235240
on master and slaves
236241
- Check that the new row is an accurate SEQUENCE object
237242
*/
238-
239-
THD *thd= table->in_use;
240243
if (table->s->tmp_table == NO_TMP_TABLE &&
241244
thd->mdl_context.upgrade_shared_lock(table->mdl_ticket,
242245
MDL_EXCLUSIVE,
@@ -255,6 +258,16 @@ int ha_sequence::write_row(const uchar *buf)
255258
sequence->write_lock(table);
256259
}
257260

261+
#ifdef WITH_WSREP
262+
/* We need to start Galera transaction for select NEXT VALUE FOR
263+
sequence if it is not yet started. Note that ALTER is handled
264+
as TOI. */
265+
if (WSREP_ON && WSREP(thd) &&
266+
!thd->wsrep_trx().active() &&
267+
wsrep_thd_is_local(thd))
268+
wsrep_start_transaction(thd, thd->wsrep_next_trx_id());
269+
#endif
270+
258271
if (likely(!(error= file->update_first_row(buf))))
259272
{
260273
Log_func *log_func= Write_rows_log_event::binlog_row_logging_function;

0 commit comments

Comments
 (0)