1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-28487: sequences not respect value of binlog_row_image with select nextval(seq_gen)

Problem:
========
When using sequences, the function
sequence_definition::write(TABLE *table, bool all_fields)
is used to save DML/DDL updates to sequence tables (e.g. nextval,
setval, and alter). Prior to this patch, the value all_fields was
always false when invoked via nextval and setval, which forced the
bitmap to only include changed columns.

Solution:
========
Change all_fields when invoked via nextval and setval to be reliant
on binlog_row_image, such that it is false when binlog_row_image is
MINIMAL, and true otherwise.

Reviewed By:
===========
Andrei Elkin <andrei.elkin@mariadb.com>
This commit is contained in:
Brandon Nesterenko
2022-07-05 07:12:49 -06:00
parent 96be3fe841
commit 02e85aeafd
6 changed files with 2546 additions and 2 deletions

View File

@@ -0,0 +1,90 @@
#
# This include file validates that sequence events are properly binlogged
# and replicated.
#
# Parameters:
# expected_columns (list<uint>, in) : A list of positive integers which
# correspond to the column numbers that should be output in a binary
# log's write_rows event
#
--echo # Create sequences with specific engines per server
--connection server_1
--eval SET STATEMENT sql_log_bin=0 FOR create sequence s1 cache=0 engine=$server_1_engine
--source include/save_master_gtid.inc
--connection server_2
--eval SET STATEMENT sql_log_bin=0 FOR create sequence s1 cache=0 engine=$server_2_engine
--source include/sync_with_master_gtid.inc
--connection server_3
--eval SET STATEMENT sql_log_bin=0 FOR create sequence s1 cache=0 engine=$server_3_engine
--source include/sync_with_master_gtid.inc
--echo # Pt.1 Ensure SETVAL replicates and binlogs correctly
--connection server_1
SELECT SETVAL(s1, 10);
--source include/save_master_gtid.inc
--echo # Validate SETVAL replicated correctly to other servers
--connection server_3
--source include/sync_with_master_gtid.inc
--let $diff_tables= server_1:test.s1,server_2:test.s1,server_3:test.s1
--source include/diff_tables.inc
--echo # Validate server_1 binlogged SETVAL with the correct columns
--connection server_1
--let binlog_filenamE= query_get_value(SHOW MASTER STATUS, File, 1)
FLUSH LOGS;
--source include/ensure_binlog_row_event_columns.inc
--echo # Validate server_2 binlogged SETVAL with the correct columns
--connection server_2
--let binlog_filename= query_get_value(SHOW MASTER STATUS, File, 1)
FLUSH LOGS;
--source include/ensure_binlog_row_event_columns.inc
--echo # Validate server_3 binlogged SETVAL with the correct columns
--connection server_3
--let binlog_filename= query_get_value(SHOW MASTER STATUS, File, 1)
FLUSH LOGS;
--source include/ensure_binlog_row_event_columns.inc
--echo # Pt.2 Ensure NEXTVAL replicates and binlogs correctly
--connection server_1
SELECT NEXTVAL(s1);
--source include/save_master_gtid.inc
--echo # Validate NEXTVAL replicated correctly to other servers
--connection server_3
--source include/sync_with_master_gtid.inc
--let $diff_tables= server_1:test.s1,server_2:test.s1,server_3:test.s1
--source include/diff_tables.inc
--echo # Validate server_1 binlogged NEXTVAL with the correct columns
--connection server_1
--let binlog_filename= query_get_value(SHOW MASTER STATUS, File, 1)
FLUSH LOGS;
--source include/ensure_binlog_row_event_columns.inc
--echo # Validate server_2 binlogged NEXTVAL with the correct columns
--connection server_2
--let binlog_filename= query_get_value(SHOW MASTER STATUS, File, 1)
FLUSH LOGS;
--source include/ensure_binlog_row_event_columns.inc
--echo # Validate server_3 binlogged NEXTVAL with the correct columns
--connection server_3
--let binlog_filename= query_get_value(SHOW MASTER STATUS, File, 1)
FLUSH LOGS;
--source include/ensure_binlog_row_event_columns.inc
--echo # Cleanup
--connection server_1
DROP TABLE s1;
--source include/save_master_gtid.inc
--connection server_3
--source include/sync_with_master_gtid.inc

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,21 @@
!include include/default_mysqld.cnf
[mysqld.1]
log-slave-updates
innodb
gtid_domain_id=0
[mysqld.2]
log-slave-updates
innodb
gtid_domain_id=1
[mysqld.3]
log-slave-updates
innodb
gtid_domain_id=2
[ENV]
SERVER_MYPORT_1= @mysqld.1.port
SERVER_MYPORT_2= @mysqld.2.port
SERVER_MYPORT_3= @mysqld.3.port

View File

@@ -0,0 +1,65 @@
#
# Purpose:
# This test verifies that sequence DML updates, i.e. NEXTVAL and SETVAL,
# respect the binlog_row_image variable value when written into the binary log.
# In particular, it ensures that only changed columns are written with MINIMAL
# image mode, and all columns are written otherwise.
#
# Methodology
# After issuing a sequence update, ensure that both 1) it was replicated
# correctly, and 2) it was binlogged respective to the binlog_row_image value.
# The sequence table does not use caching to ensure each update is immediately
# binlogged. Each command is binlogged into its own unique log file, and the
# entirety of the file is analyzed for correctness of its sequence event.
# Specifically, mysqlbinlog is used in verbose mode so it outputs the columns
# which belong to the event, and the columns are analyzed to ensure the correct
# ones were logged. rpl_row_img_general_loop.inc is used to test with multiple
# chained replicas, varying engines between InnoDB and MyISAM.
#
# References:
# MDEV-28487: sequences not respect value of binlog_row_image with select
# nextval(seq_gen)
#
--let $rpl_topology= 1->2->3
--source include/rpl_init.inc
--source include/have_binlog_format_row.inc
--connection server_1
--source include/have_innodb.inc
--connection server_2
--source include/have_innodb.inc
--connection server_3
--source include/have_innodb.inc
--connection server_1
--echo #
--echo # Test Case 1) binlog_row_image=MINIMAL should write only columns
--echo # 1 and 8 to the binary log
--echo #
--let $row_img_set=server_1:MINIMAL:N,server_2:MINIMAL:Y,server_3:MINIMAL:Y
--source include/rpl_row_img_set.inc
--let $expected_columns=(1,8)
--let row_img_test_script= include/rpl_row_img_sequence.inc
--source include/rpl_row_img_general_loop.inc
--echo #
--echo # Test Case 2) binlog_row_image=NOBLOB should write all columns to the
--echo # binary log
--echo #
--let $row_img_set=server_1:NOBLOB:N,server_2:NOBLOB:Y,server_3:NOBLOB:Y
--source include/rpl_row_img_set.inc
--let $expected_columns=(1,2,3,4,5,6,7,8)
--source include/rpl_row_img_general_loop.inc
--echo #
--echo # Test Case 3) binlog_row_image=NOBLOB should write all columns to the
--echo # binary log
--echo #
--let $row_img_set=server_1:FULL:N,server_2:FULL:Y,server_3:FULL:Y
--source include/rpl_row_img_set.inc
--let $expected_columns=(1,2,3,4,5,6,7,8)
--source include/rpl_row_img_general_loop.inc
--source include/rpl_end.inc
--echo # End of tests