mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
Compute binlog checksums (when enabled) already when writing events into the statement or transaction caches, where before it was done when the caches are copied to the real binlog file. This moves the checksum computation outside of holding LOCK_log, improving scalabitily. At stmt/trx cache write time, the final end_log_pos values are not known, so with this patch these will be set to 0. Events that are written directly to the binlog file (not through stmt/trx cache) keep the correct end_log_pos value. The GTID and COMMIT/XID events at the start and end of event groups are written directly, so the zero end_log_pos is only for events in the middle of event groups, which do not negatively affect replication. An option --binlog-legacy-event-pos, off by default, is provided to disable this behavior to provide backwards compatibility with any external applications that might rely on end_log_pos in events in the middle of event groups. Checksums cannot be pre-computed when binlog encryption is enabled, as encryption relies on correct end_log_pos to provide part of the nonce/IV. Checksum pre-computation is also disabled for WSREP/Galera, as it uses events differently in its write-sets and so on. Extending pre-computation of checksums to Galera where it makes sense could be added in a future patch. The current --binlog-checksum configuration is saved in binlog_cache_data at transaction start and used to pre-compute checksums in cache, if applicable. When the cache is later copied to the binlog, a check is made if the saved value still matches the configured global value; if so, the events are block-copied directly into the binlog file. If --binlog-checksum was changed during the transaction, events are re-written to the binlog file one-by-one and the checksums recomputed/discarded as appropriate. Reviewed-by: Monty <monty@mariadb.org> Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
335 lines
9.8 KiB
Plaintext
335 lines
9.8 KiB
Plaintext
################################################################################
|
|
# WL#4618 RBR: extended table metadata in the binary log
|
|
#
|
|
# Below metadata is logged into Table_map_log_event
|
|
# - signedness of numeric columns
|
|
# - charsets of character columns
|
|
# - column names
|
|
# - set/enum character sets and string values
|
|
# - primary key
|
|
#
|
|
# The first two are always logged. The others are controlled by system
|
|
# variable --binlog-row-metadata
|
|
#
|
|
# The test will verify if the metadata can be logged and printed by mysqlbinlog
|
|
# correctly.
|
|
# mysqlbinlog --print-table-metadata will print the extra metadata
|
|
################################################################################
|
|
--source include/have_debug.inc
|
|
--source include/have_binlog_format_row.inc
|
|
|
|
RESET MASTER;
|
|
SET GLOBAL binlog_row_metadata = MINIMAL;
|
|
|
|
--let $MYSQLD_DATADIR= `select @@datadir`
|
|
--let $binlog_file= $MYSQLD_DATADIR/master-bin.000001
|
|
|
|
--echo #
|
|
--echo # Temporal types can be printed correctly
|
|
--echo #
|
|
CREATE TABLE t1(c_year YEAR, c_date DATE, c_time TIME, c_time_f TIME(3),
|
|
c_datetime DATETIME, c_datetime_f DATETIME(3),
|
|
c_timestamp TIMESTAMP NOT NULL DEFAULT NOW(),
|
|
c_timestamp_f TIMESTAMP(3) DEFAULT "2017-1-1 10:10:10");
|
|
|
|
INSERT INTO t1(c_year) VALUES(2017);
|
|
--source include/print_optional_metadata.inc
|
|
|
|
DROP TABLE t1;
|
|
RESET MASTER;
|
|
|
|
--echo #
|
|
--echo # Geometry types can be printed correctly
|
|
--echo #
|
|
CREATE TABLE t1 (c_geo GEOMETRY, c_point POINT, c_linestring LINESTRING,
|
|
c_polygon POLYGON, c_multi_point MULTIPOINT,
|
|
c_multi_linestring MULTILINESTRING, c_multi_polygon MULTIPOLYGON,
|
|
c_geometrycollection GEOMETRYCOLLECTION, c_char CHAR(100));
|
|
|
|
INSERT INTO t1(c_point) VALUES(ST_PointFromText('POINT(10 10)'));
|
|
--source include/print_optional_metadata.inc
|
|
|
|
RESET MASTER;
|
|
SET GLOBAL binlog_row_metadata = FULL;
|
|
|
|
# geometry type is binlogged, the real geometry types are printed
|
|
INSERT INTO t1(c_point) VALUES(ST_PointFromText('POINT(10 10)'));
|
|
--source include/print_optional_metadata.inc
|
|
|
|
DROP TABLE t1;
|
|
RESET MASTER;
|
|
|
|
--echo #
|
|
--echo # Numeric types can be printed correctly
|
|
--echo #
|
|
CREATE TABLE t1(c_bit BIT(10), c_bool BOOL, c_smallint SMALLINT,
|
|
c_mediumint MEDIUMINT, c_int INT UNSIGNED, c_bigint BIGINT,
|
|
c_float FLOAT UNSIGNED, c_double DOUBLE, c_decimal DECIMAL(10, 2));
|
|
|
|
SET GLOBAL binlog_row_metadata = MINIMAL;
|
|
INSERT INTO t1(c_bool) VALUES(1);
|
|
|
|
--echo # UNSIGNED flag should be printed
|
|
--source include/print_optional_metadata.inc
|
|
|
|
RESET MASTER;
|
|
SET GLOBAL binlog_row_metadata = FULL;
|
|
INSERT INTO t1(c_bool) VALUES(1);
|
|
|
|
--source include/print_optional_metadata.inc
|
|
|
|
DROP TABLE t1;
|
|
RESET MASTER;
|
|
|
|
--echo #
|
|
--echo # Character types can be printed correctly
|
|
--echo #
|
|
CREATE TABLE t1(c_char CHAR(10), c_varchar VARCHAR(500),
|
|
c_tinytext TINYTEXT, c_text TEXT,
|
|
c_mediumtext MEDIUMTEXT, c_longtext LONGTEXT CHARSET utf8);
|
|
|
|
SET GLOBAL binlog_row_metadata = MINIMAL;
|
|
INSERT INTO t1(c_char) VALUES("1");
|
|
|
|
# Charset set is printed with default charset
|
|
--source include/print_optional_metadata.inc
|
|
|
|
RESET MASTER;
|
|
SET GLOBAL binlog_row_metadata = FULL;
|
|
INSERT INTO t1(c_char) VALUES("1");
|
|
|
|
--source include/print_optional_metadata.inc
|
|
|
|
DROP TABLE t1;
|
|
RESET MASTER;
|
|
|
|
--echo #
|
|
--echo # Column names with non-ascii characters and escape characters can be printed correctly
|
|
--echo #
|
|
set names utf8;
|
|
CREATE TABLE t1(`åäö表\a'``"` INT);
|
|
|
|
SHOW CREATE TABLE t1;
|
|
|
|
INSERT INTO t1 VALUES(1);
|
|
--source include/print_optional_metadata.inc
|
|
DROP TABLE t1;
|
|
RESET MASTER;
|
|
--echo #
|
|
--echo # Charsets can be printed correctly
|
|
--echo #
|
|
CREATE TABLE t1(c_char_utf8 CHAR(10) CHARSET utf8,
|
|
c_varchar_utf8 VARCHAR(10) CHARSET utf8,
|
|
c_text_utf8 TEXT CHARSET utf8);
|
|
|
|
INSERT INTO t1 VALUES("1", "2", "3");
|
|
|
|
# Charset set is printed with Default charset
|
|
--source include/print_optional_metadata.inc
|
|
|
|
DROP TABLE t1;
|
|
RESET MASTER;
|
|
|
|
# Test collation number less than 250 and collation number greater than 250
|
|
CREATE TABLE t1(c_utf8mb4_520 CHAR(10) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci,
|
|
c_utf8mb4_0900 VARCHAR(10) CHARSET utf8mb4 COLLATE utf8mb4_polish_ci,
|
|
c_utf8mb4_def TEXT CHARSET utf8mb4);
|
|
|
|
INSERT INTO t1 VALUES("1", "2", "3");
|
|
|
|
# Charset set is printed without default charset
|
|
--source include/print_optional_metadata.inc
|
|
|
|
DROP TABLE t1;
|
|
RESET MASTER;
|
|
|
|
--echo #
|
|
--echo # Blob and binary columns can be printed correctly
|
|
--echo #
|
|
CREATE TABLE t1(c_binary BINARY(10), c_varbinary VARBINARY(10),
|
|
c_tinyblob TINYBLOB, c_blob BLOB,
|
|
c_mediumblob MEDIUMBLOB, c_longblob LONGBLOB);
|
|
|
|
INSERT INTO t1 VALUES("1", "2", "3", "4", "5", "6");
|
|
--source include/print_optional_metadata.inc
|
|
|
|
DROP TABLE t1;
|
|
RESET MASTER;
|
|
|
|
--echo #
|
|
--echo # Verify that SET string values and character sets can be printed correctly
|
|
--echo #
|
|
|
|
set names utf8;
|
|
CREATE TABLE t1(
|
|
c_set_1 SET("set1_v1_å", "set1_v2_ä", "set1_v3_ö"),
|
|
c_set_2 SET("set2_v1_å", "set2_v2_ä", "set2_v3_ö") CHARACTER SET latin1,
|
|
c_set_4 SET("set3_v1_å", "set3_v2_ä", "set3_v3_ö") CHARACTER SET swe7 COLLATE swe7_bin);
|
|
|
|
SET GLOBAL binlog_row_metadata = MINIMAL;
|
|
INSERT INTO t1 VALUES("set1_v1_å", "set2_v3_ö", "set3_v1_å");
|
|
--source include/print_optional_metadata.inc
|
|
|
|
RESET MASTER;
|
|
SET GLOBAL binlog_row_metadata = FULL;
|
|
INSERT INTO t1 VALUES("set1_v1_å", "set2_v3_ö", "set3_v1_å");
|
|
--source include/print_optional_metadata.inc
|
|
|
|
DROP TABLE t1;
|
|
RESET MASTER;
|
|
|
|
--echo #
|
|
--echo # Verify that ENUM string values and character sets can be printed correctly
|
|
--echo #
|
|
|
|
CREATE TABLE t1(
|
|
c_enum_1 ENUM("enum1_v1_å", "enum1_v2_ä", "enum1_v3_ö"),
|
|
c_enum_3 ENUM("enum2_v1_å", "enum2_v2_ä", "enum2_v3_ö") CHARACTER SET latin1,
|
|
c_enum_4 ENUM("enum3_v1_å", "enum3_v2_ä", "enum3_v3_ö") CHARACTER SET swe7 COLLATE swe7_bin);
|
|
|
|
SET GLOBAL binlog_row_metadata = MINIMAL;
|
|
INSERT INTO t1 VALUES("enum1_v1_å", "enum2_v3_ö", "enum3_v1_å");
|
|
--source include/print_optional_metadata.inc
|
|
|
|
RESET MASTER;
|
|
SET GLOBAL binlog_row_metadata = FULL;
|
|
INSERT INTO t1 VALUES("enum1_v1_å", "enum2_v3_ö", "enum3_v1_å");
|
|
--source include/print_optional_metadata.inc
|
|
|
|
DROP TABLE t1;
|
|
RESET MASTER;
|
|
|
|
--echo #
|
|
--echo # Verify that explicit NOT NULL can be printed correctly
|
|
--echo #
|
|
CREATE TABLE t1(c_not_null1 INT NOT NULL, c_null1 INT, c_not_null2 INT NOT NULL,
|
|
c_null2 INT);
|
|
|
|
INSERT INTO t1 VALUES(1, 2, 3, 4);
|
|
--source include/print_optional_metadata.inc
|
|
|
|
DROP TABLE t1;
|
|
RESET MASTER;
|
|
|
|
--echo #
|
|
--echo # Verify that primary key can be printed correctly
|
|
--echo #
|
|
CREATE TABLE t1(c_key1 INT, c_key3 INT, c_not_key INT, c_key2 INT,
|
|
PRIMARY KEY(c_key1, c_key2, c_key3));
|
|
|
|
INSERT INTO t1 VALUES(1, 2, 3, 4);
|
|
--let $print_primary_key= 1
|
|
--source include/print_optional_metadata.inc
|
|
|
|
DROP TABLE t1;
|
|
RESET MASTER;
|
|
|
|
# Key has prefix
|
|
CREATE TABLE t1(c_key1 CHAR(100), c_key3 CHAR(100), c_not_key INT, c_key2 CHAR(10),
|
|
PRIMARY KEY(c_key1(5), c_key2, c_key3(10)));
|
|
|
|
INSERT INTO t1 VALUES("1", "2", 3, "4");
|
|
--source include/print_optional_metadata.inc
|
|
|
|
RESET MASTER;
|
|
# Primary key should not be printed
|
|
SET GLOBAL binlog_row_metadata = MINIMAL;
|
|
|
|
INSERT INTO t1 VALUES("2", "2", 3, "4");
|
|
--source include/print_optional_metadata.inc
|
|
|
|
RESET MASTER;
|
|
--echo #
|
|
--echo # Coverage test: Print column index instead of column name if column name
|
|
--echo # is not binlogged.
|
|
--echo #
|
|
SET GLOBAL binlog_row_metadata = FULL;
|
|
|
|
SET SESSION debug_dbug = 'd, dont_log_column_name';
|
|
INSERT INTO t1 VALUES("3", "2", 3, "4");
|
|
--source include/print_optional_metadata.inc
|
|
|
|
--let $print_primary_key=
|
|
DROP TABLE t1;
|
|
RESET MASTER;
|
|
|
|
--echo #
|
|
--echo # Coverage test: Inject an invalid column type
|
|
--echo #
|
|
CREATE TABLE t1(c1 int, c2 BLOB);
|
|
|
|
SET SESSION debug_dbug = 'd,inject_invalid_column_type';
|
|
INSERT INTO t1 VALUES(1, "a");
|
|
# It prints an error
|
|
--source include/print_optional_metadata.inc
|
|
|
|
RESET MASTER;
|
|
|
|
--echo #
|
|
--echo # Coverage test: Inject an invalid BLOB metadata
|
|
--echo #
|
|
--let $start_pos= query_get_value(SHOW MASTER STATUS, Position, 1)
|
|
|
|
SET SESSION debug_dbug = 'd,inject_invalid_blob_size';
|
|
INSERT INTO t1 VALUES(2, "b");
|
|
|
|
# The invalid metadata will case assertion failure on Write_rows_log_event
|
|
# So we need to stop mysqlbinlog before reading Write_rows_log_event.
|
|
--let $stop_position= query_get_value(SHOW BINLOG EVENTS FROM $start_pos LIMIT 4, Pos, 4)
|
|
--source include/print_optional_metadata.inc
|
|
|
|
--echo #
|
|
--echo # Coverage test: Inject an invalid Geometry type
|
|
--echo #
|
|
DROP TABLE t1;
|
|
CREATE TABLE t1(c_geometry GEOMETRY, c_point POINT, c_multilinestring MULTILINESTRING);
|
|
RESET MASTER;
|
|
--let $start_pos= query_get_value(SHOW MASTER STATUS, Position, 1)
|
|
|
|
SET SESSION debug_dbug = 'd,inject_invalid_geometry_type';
|
|
INSERT INTO t1(c_point) VALUES(ST_PointFromText('POINT(10 10)'));
|
|
|
|
# The invalid metadata will case assertion failure on Write_rows_log_event
|
|
# So we need to stop mysqlbinlog before reading Write_rows_log_event.
|
|
--let $stop_position= query_get_value(SHOW BINLOG EVENTS FROM $start_pos LIMIT 4, Pos, 4)
|
|
--source include/print_optional_metadata.inc
|
|
|
|
DROP TABLE t1;
|
|
RESET MASTER;
|
|
--echo #
|
|
--echo # Comptibility Test: Verify mysqlbinlog can print OLD table_map_log_event
|
|
--echo # without any optional metadata
|
|
--echo #
|
|
CREATE TABLE t1(c_int INT, c_tiny_int_unsigned TINYINT UNSIGNED,
|
|
c_binary BINARY(10), c_text TEXT, c_point POINT);
|
|
|
|
SET session debug_dbug='d,simulate_no_optional_metadata';
|
|
INSERT INTO t1(c_int) VALUES(1);
|
|
# TINYINT will be printed without UNSIGNED flag,
|
|
# CHAR will be printed as BINARY(10)
|
|
# POINT will be printed as GEOMETRY
|
|
--let $stop_position=
|
|
--source include/print_optional_metadata.inc
|
|
|
|
DROP TABLE t1;
|
|
RESET MASTER;
|
|
--echo #
|
|
--echo # Simulate error on initializing charset and primary key metadata
|
|
--echo #
|
|
CREATE TABLE t1(c1 char(10) PRIMARY KEY);
|
|
|
|
SET session debug_dbug='d,simulate_init_charset_field_error';
|
|
INSERT INTO t1 VALUES("a");
|
|
|
|
SET GLOBAL binlog_row_metadata = FULL;
|
|
SET session debug_dbug='d,simulate_init_primary_key_field_error';
|
|
INSERT INTO t1 VALUES("b");
|
|
|
|
--let $print_primary_key= 1
|
|
--source include/print_optional_metadata.inc
|
|
|
|
SET SESSION debug_dbug = '';
|
|
SET GLOBAL binlog_row_metadata = NO_LOG;
|
|
DROP TABLE t1;
|
|
RESET MASTER;
|