1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-30388 : Assertion `!wsrep_has_changes(thd) || (thd->lex->sql_command == SQLCOM_CREATE_TABLE && !thd->is_current_stmt_binlog_format_row()) || thd->wsrep_cs().transaction().state() == wsrep::transaction::s_aborted' failed

Problem for Galera is the fact that sequences are not really
transactional. Sequence operation is committed immediately
in sql_sequence.cd and later Galera could find out that
we have changes but actual statement is not there anymore.

Therefore, we must make some restrictions what kind
of sequences Galera can support.

(1) Galera cluster supports only sequences implemented
by InnoDB storage engine. This is because Galera replication
supports currently only InnoDB.

(2) We do not allow LOCK TABLE on sequence object and
we do not allow sequence creation under LOCK TABLE, instead
lock is released and we issue warning.

(3) We allow sequences with NOCACHE definition or with
INCREMEMENT BY 0 CACHE=n definition. This makes sure that
sequence values are unique accross Galera cluster.

Signed-off-by: Julius Goryavsky <julius.goryavsky@mariadb.com>
This commit is contained in:
Jan Lindström
2023-05-10 08:42:37 +03:00
committed by Julius Goryavsky
parent de703a2b21
commit 28eaf66e18
13 changed files with 516 additions and 74 deletions

View File

@ -5301,6 +5301,51 @@ int mysql_create_table_no_lock(THD *thd, const LEX_CSTRING *db,
return res;
}
#ifdef WITH_WSREP
/** Additional sequence checks for Galera cluster.
@param thd thread handle
@param seq sequence definition
@retval 0 failure
@retval 1 success
*/
bool wsrep_check_sequence(THD* thd, const sequence_definition *seq)
{
enum legacy_db_type db_type;
if (thd->lex->create_info.used_fields & HA_CREATE_USED_ENGINE)
{
db_type= thd->lex->create_info.db_type->db_type;
}
else
{
const handlerton *hton= ha_default_handlerton(thd);
db_type= hton->db_type;
}
// In Galera cluster we support only InnoDB sequences
if (db_type != DB_TYPE_INNODB)
{
my_error(ER_NOT_SUPPORTED_YET, MYF(0),
"Galera cluster does support only InnoDB sequences");
return(true);
}
// In Galera cluster it is best to use INCREMENT BY 0 with CACHE
// or NOCACHE
if (seq &&
seq->increment &&
seq->cache)
{
my_error(ER_NOT_SUPPORTED_YET, MYF(0),
"In Galera if you use CACHE you should set INCREMENT BY 0"
" to behave correctly in a cluster");
return(true);
}
return (false);
}
#endif /* WITH_WSREP */
/**
Implementation of SQLCOM_CREATE_TABLE.
@ -5356,6 +5401,15 @@ bool mysql_create_table(THD *thd, TABLE_LIST *create_table,
if (!opt_explicit_defaults_for_timestamp)
promote_first_timestamp_column(&alter_info->create_list);
#ifdef WITH_WSREP
if (thd->lex->sql_command == SQLCOM_CREATE_SEQUENCE &&
WSREP(thd) && wsrep_thd_is_local_toi(thd))
{
if (wsrep_check_sequence(thd, create_info->seq_create_info))
DBUG_RETURN(true);
}
#endif /* WITH_WSREP */
/* We can abort create table for any table type */
thd->abort_on_warning= thd->is_strict_mode();
@ -10143,6 +10197,15 @@ do_continue:;
}
#endif
#ifdef WITH_WSREP
if (table->s->sequence && WSREP(thd) &&
wsrep_thd_is_local_toi(thd))
{
if (wsrep_check_sequence(thd, create_info->seq_create_info))
DBUG_RETURN(TRUE);
}
#endif /* WITH_WSREP */
/*
Use copy algorithm if:
- old_alter_table system variable is set without in-place requested using