From 88d43afd33ba35af02fdf64d27f591cfc55885b5 Mon Sep 17 00:00:00 2001 From: Hemant Dangi Date: Mon, 4 Aug 2025 13:26:34 +0530 Subject: [PATCH] MDEV-37366: Inconsistency detected - create sequence Issue: When applying 'SELECT NEXT VALUE..' on applier node with binlog_row_image=MINIMAL and log-binlog enabled, applier node fails with below error: Slave SQL: Could not execute Write_rows_v1 event on table monitor.seq_moni_num; Unknown error, Error_code: 1105; handler error No Error!; the event's master log FIRST, end_log_pos 0, Internal MariaDB error code: 1105 To reproduce run below command on the first/active node: > CREATE SEQUENCE `seq_test` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 0 cache 1000 nocycle ENGINE=InnoDB; > SELECT NEXT VALUE FOR seq_test; > SELECT NEXT VALUE FOR seq_test; The applier node will leave the cluster after executing the 'SELECT NEXT VALUE' with below error: ERROR] Slave SQL: Could not execute Write_rows_v1 event on table test.seq_test; Unknown error, Error_code: 1105; handler error No Error!; the event's master log FIRST, end_log_pos 0, Internal MariaDB error code: 1105 [Warning] WSREP: Event 3 Write_rows_v1 apply failed: 195, seqno 14511334511 Solution: When binary loggging is enabled and binlog_row_image is set to 'MINIMAL', then 'SELECT NEXT VALUE' fails to apply on applier node. It fails with error HA_ERR_SEQUENCE_INVALID_DATA 195 in sequence_definition::check_and_adjust() because sequence variables like min_value, max_value, start are 0. The marking of all columns in 'TABLE::mark_columns_per_binlog_row_image()' will prevent update/set column values for the sequence table. For the sequence table column bitmap sent from master is only used. Signed-off-by: Julius Goryavsky --- mysql-test/suite/galera/r/MDEV-37366.result | 27 +++++++++++ mysql-test/suite/galera/t/MDEV-37366.test | 51 +++++++++++++++++++++ sql/table.cc | 13 ++++++ 3 files changed, 91 insertions(+) create mode 100644 mysql-test/suite/galera/r/MDEV-37366.result create mode 100644 mysql-test/suite/galera/t/MDEV-37366.test diff --git a/mysql-test/suite/galera/r/MDEV-37366.result b/mysql-test/suite/galera/r/MDEV-37366.result new file mode 100644 index 00000000000..9fbd6be70f2 --- /dev/null +++ b/mysql-test/suite/galera/r/MDEV-37366.result @@ -0,0 +1,27 @@ +connection node_2; +connection node_1; +connection node_1; +connection node_2; +connection node_1; +SET SESSION binlog_row_image=minimal; +CREATE SEQUENCE `seq_test` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 0 cache 1000 nocycle ENGINE=InnoDB; +SHOW CREATE TABLE seq_test; +Table Create Table +seq_test CREATE TABLE `seq_test` ( + `next_not_cached_value` bigint(21) NOT NULL, + `minimum_value` bigint(21) NOT NULL, + `maximum_value` bigint(21) NOT NULL, + `start_value` bigint(21) NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used', + `increment` bigint(21) NOT NULL COMMENT 'increment value', + `cache_size` bigint(21) unsigned NOT NULL, + `cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed', + `cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done' +) ENGINE=InnoDB SEQUENCE=1 +SELECT NEXT VALUE FOR seq_test; +NEXT VALUE FOR seq_test +1 +SELECT NEXT VALUE FOR seq_test; +NEXT VALUE FOR seq_test +3 +connection node_2; +DROP SEQUENCE seq_test; diff --git a/mysql-test/suite/galera/t/MDEV-37366.test b/mysql-test/suite/galera/t/MDEV-37366.test new file mode 100644 index 00000000000..939f760308a --- /dev/null +++ b/mysql-test/suite/galera/t/MDEV-37366.test @@ -0,0 +1,51 @@ +# +# MDEV-37366: Inconsistency detected - create sequence +# Failed 'SELECT NEXT VALUE' on applier node. +# +--source include/galera_cluster.inc +--source include/have_innodb.inc +--source include/big_test.inc +--source include/have_log_bin.inc + +# +# Save original auto_increment_offset values. +# +--let $node_1=node_1 +--let $node_2=node_2 +--source ../galera/include/auto_increment_offset_save.inc + +# +# Verify there are two nodes in galera cluster. +# +--connection node_1 +--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc + +# +# Create a sequence table on node1. +# +SET SESSION binlog_row_image=minimal; +CREATE SEQUENCE `seq_test` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 0 cache 1000 nocycle ENGINE=InnoDB; +SHOW CREATE TABLE seq_test; + +# +# Execute 'SELECT NEXT VALUE' which should not fail on applier node. +# +SELECT NEXT VALUE FOR seq_test; +SELECT NEXT VALUE FOR seq_test; + +# +# Verify there are two nodes in galera cluster. +# +--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' +--source include/wait_condition.inc + +# +# Cleanup +# +--connection node_2 + +DROP SEQUENCE seq_test; + +# Restore original variable values. +--source ../galera/include/auto_increment_offset_restore.inc diff --git a/sql/table.cc b/sql/table.cc index 683da12f7d9..8cd9957b88c 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -7952,6 +7952,19 @@ void TABLE::mark_columns_per_binlog_row_image() if (file->row_logging && !ha_check_storage_engine_flag(s->db_type(), HTON_NO_BINLOG_ROW_OPT)) { +#ifdef WITH_WSREP + /** + The marking of all columns will prevent update/set column values for the + sequence table. For the sequence table column bitmap sent from master is + used. + */ + if (WSREP(thd) && wsrep_thd_is_applying(thd) && + s->sequence && s->primary_key >= MAX_KEY) + { + DBUG_VOID_RETURN; + } +#endif /* WITH_WSREP */ + /* if there is no PK, then mark all columns for the BI. */ if (s->primary_key >= MAX_KEY) {