From ebbd5ef6e2902a51a46e47dbb8a8667593cb25e7 Mon Sep 17 00:00:00 2001 From: mkaruza Date: Tue, 10 May 2022 11:15:32 +0200 Subject: MDEV-27862 Galera should replicate nextval()-related changes in sequences with INCREMENT <> 0, at least NOCACHE ones with engine=InnoDB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sequence storage engine is not transactionl so cache will be written in stmt_cache that is not replicated in cluster. To fix this replicate what is available in both trans_cache and stmt_cache. Sequences will only work when NOCACHE keyword is used when sequnce is created. If WSREP is enabled and we don't have this keyword report error indicting that sequence will not work correctly in cluster. When binlog is enabled statement cache will be cleared in transaction before COMMIT so cache generated from sequence will not be replicated. We need to keep cache until replication. Tests are re-recorded because of replication changes that were introducted with this PR. Reviewed-by: Jan Lindström --- sql/sql_sequence.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'sql/sql_sequence.cc') diff --git a/sql/sql_sequence.cc b/sql/sql_sequence.cc index 367fbad144c..8488fa67ecb 100644 --- a/sql/sql_sequence.cc +++ b/sql/sql_sequence.cc @@ -308,6 +308,11 @@ bool sequence_insert(THD *thd, LEX *lex, TABLE_LIST *org_table_list) DBUG_RETURN(TRUE); } +#ifdef WITH_WSREP + if (WSREP_ON && seq->cache != 0) + WSREP_WARN("CREATE SEQUENCES declared without `NOCACHE` will not behave correctly in galera cluster."); +#endif + /* If not temporary table */ if (!temporary_table) { @@ -904,12 +909,18 @@ bool Sql_cmd_alter_sequence::execute(THD *thd) No_such_table_error_handler no_such_table_handler; DBUG_ENTER("Sql_cmd_alter_sequence::execute"); + if (check_access(thd, ALTER_ACL, first_table->db.str, &first_table->grant.privilege, &first_table->grant.m_internal, 0, 0)) DBUG_RETURN(TRUE); /* purecov: inspected */ +#ifdef WITH_WSREP + if (WSREP_ON && new_seq->cache != 0) + WSREP_WARN("ALTER SEQUENCES declared without `NOCACHE` will not behave correctly in galera cluster."); +#endif + if (check_grant(thd, ALTER_ACL, first_table, FALSE, 1, FALSE)) DBUG_RETURN(TRUE); /* purecov: inspected */ -- cgit v1.2.1