1
0
mirror of https://github.com/MariaDB/server.git synced 2026-01-06 05:22:24 +03:00

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 <julius.goryavsky@mariadb.com>
This commit is contained in:
Hemant Dangi
2025-08-04 13:26:34 +05:30
committed by Julius Goryavsky
parent 858dc5bd5c
commit 88d43afd33
3 changed files with 91 additions and 0 deletions

View File

@@ -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;

View File

@@ -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

View File

@@ -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)
{