mirror of
https://github.com/MariaDB/server.git
synced 2025-04-28 06:45:23 +03:00
New Feature: ============ Extend mariadb-binlog command-line tool to allow for filtering events using GTID domain and server ids. The functionality mimics that of a replica server’s DO_DOMAIN_IDS, IGNORE_DOMAIN_IDS, and IGNORE_SERVER_IDS from CHANGE MASTER TO. For completeness, this patch additionally adds the option --do-server-ids as an alias for --server-id, which now accepts a list of server ids instead of a single one. Example usage: mariadb-binlog --do-domain-ids=2,3,4 --do-server-ids=1,3 master-bin.000001 Functional Notes: 1. --do-domain-ids cannot be combined with --ignore-domain-ids 2. --do-server-ids cannot be combined with --ignore-server-ids 3. A domain id filter can be combined with a server id filter 4. When any new filter options are combined with the --gtid-strict-mode option, events from excluded domains/servers are not validated. 5. Domain/server id filters can be combined with GTID ranges (i.e. specifications of --start-position and --stop-position). However, because the --stop-position option implicitly undertakes filtering to only output events within its range of domains, when combined with --do-domain-ids or --ignore-domain-ids, output will consist of the intersection between the filters. Specifically, with --do-domain-ids and --stop-position, only events with domain ids present in both argument lists will be output. Conversely, with --ignore-domain-ids and --stop-position, only events with domain ids present in the --stop-position and absent from the --ignore-domain-ids options will be output. Reviewed By ============ Andrei Elkin <andrei.elkin@mariadb.com>
162 lines
5.2 KiB
Plaintext
162 lines
5.2 KiB
Plaintext
###############################
|
|
# Test Setup
|
|
###############################
|
|
set @a=UNIX_TIMESTAMP("1970-01-21 15:32:22");
|
|
SET timestamp=@a;
|
|
RESET MASTER;
|
|
SET @@session.gtid_domain_id= 0;
|
|
SET @@session.server_id= 1;
|
|
CREATE TABLE t1 (a int);
|
|
SET @@session.server_id= 2;
|
|
CREATE TABLE t2 (a int);
|
|
INSERT INTO t2 values (3);
|
|
SET @@session.gtid_domain_id= 1;
|
|
SET @@session.server_id= 1;
|
|
CREATE TABLE t3 (a int);
|
|
INSERT INTO t3 values (4);
|
|
SET @@session.server_id= 3;
|
|
SET timestamp=@a+1;
|
|
CREATE TABLE t4 (a int);
|
|
SET timestamp=@a+2;
|
|
INSERT INTO t4 values (5);
|
|
SET @@session.gtid_domain_id= 0;
|
|
SET @@session.server_id= 1;
|
|
INSERT INTO t1 values (1);
|
|
SET @@session.gtid_domain_id= 2;
|
|
SET @@session.server_id= 1;
|
|
CREATE TABLE t5 (a int);
|
|
INSERT INTO t5 values (6);
|
|
SET @@session.gtid_domain_id= 0;
|
|
SET @@session.server_id= 1;
|
|
INSERT INTO t1 values (2);
|
|
FLUSH LOGS;
|
|
SET @@session.gtid_domain_id= 0;
|
|
SET @@session.server_id= 2;
|
|
CREATE TABLE t6 (a int);
|
|
INSERT INTO t6 values (1);
|
|
FLUSH LOGS;
|
|
DROP TABLE t1;
|
|
DROP TABLE t2;
|
|
DROP TABLE t3;
|
|
DROP TABLE t4;
|
|
DROP TABLE t5;
|
|
DROP TABLE t6;
|
|
RESET MASTER;
|
|
###############################
|
|
# Test Cases
|
|
###############################
|
|
#
|
|
# Test Case 1) --do-server-ids with a single server id limits output
|
|
# to that single server
|
|
# MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=2 | MYSQL
|
|
DROP TABLE t2;
|
|
#
|
|
# Test Case 2) --do-server-ids with multiple server ids limits output
|
|
# to the provided servers
|
|
# MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=2,3 | MYSQL
|
|
DROP TABLE t2;
|
|
DROP TABLE t4;
|
|
#
|
|
# Test Case 3) --do-server-ids when combined with --do-domain-ids should
|
|
# intersect the results
|
|
# MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=1 --do-domain-ids=0 | MYSQL
|
|
DROP TABLE t1;
|
|
#
|
|
# Test Case 4) --do-server-ids when combined with --ignore-domain-ids should
|
|
# intersect the results
|
|
# MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=1 --ignore-domain-ids=0 | MYSQL
|
|
DROP TABLE t3;
|
|
DROP TABLE t5;
|
|
#
|
|
# Test Case 5) --do-server-ids when combined with a GTID range should
|
|
# intersect the results
|
|
# MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=1 --stop-position=0-1-4 | MYSQL
|
|
DROP TABLE t1;
|
|
#
|
|
# Test Case 6) --do-server-ids when combined with both --ignore-domain-ids
|
|
# and a GTID range should intersect all results
|
|
# MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=1 --ignore-domain-ids=0 --start-position=1-1-0 | MYSQL
|
|
DROP TABLE t3;
|
|
DROP TABLE t5;
|
|
#
|
|
# Test Case 7) --do-server-ids when combined with both --do-domain-ids and
|
|
# a GTID range should intersect all results
|
|
# MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=2 --do-domain-ids=0 --start-position=0-1-0 | MYSQL
|
|
DROP TABLE t2;
|
|
#
|
|
# Test Case 8) --do-server-ids and --offset=<n> skips n events after the
|
|
# first GTID is found
|
|
CREATE TABLE t4 (a int);
|
|
# MYSQL_BINLOG BINLOG_FILE_PARAM --offset=5 --do-server-ids=3 --do-domain-ids=1 | MYSQL
|
|
DROP TABLE t4;
|
|
#
|
|
# Test Case 9) --do-server-ids with --start-datetime=<T> where T occurs
|
|
# after the first GTID is found results in no events before T
|
|
CREATE TABLE t4 (a int);
|
|
# MYSQL_BINLOG BINLOG_FILE_PARAM --start-datetime="1970-01-21 15:32:24" --do-server-ids=3 --do-domain-ids=1 | MYSQL
|
|
DROP TABLE t4;
|
|
#
|
|
# Test Case 10) --do-server-ids works with --read-from-remote-server
|
|
# Setup test specific data
|
|
RESET MASTER;
|
|
SET @@session.gtid_domain_id= 0;
|
|
SET @@session.server_id= 1;
|
|
CREATE TABLE t1 (a int);
|
|
INSERT INTO t1 VALUES (1);
|
|
SET @@session.server_id= 2;
|
|
CREATE TABLE t2 (a int);
|
|
INSERT INTO t2 VALUES (1);
|
|
SET @@session.server_id= 1;
|
|
DROP TABLE t1;
|
|
DROP TABLE t2;
|
|
# MYSQL_BINLOG BINLOG_FILENAME --read-from-remote-server --do-server-ids=2 | MYSQL
|
|
DROP TABLE t2;
|
|
#
|
|
# Test Case 11) --do-server-ids works over multiple binary log input
|
|
# files
|
|
# MYSQL_BINLOG BINLOG_FILE_PARAM BINLOG_FILE_PARAM2 --do-server-ids=2 | MYSQL
|
|
DROP TABLE t2;
|
|
DROP TABLE t6;
|
|
#
|
|
# Test Case 12) --do-server-ids re-specifications should override
|
|
# previous ones
|
|
# MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=1 --do-server-ids=2 | MYSQL
|
|
DROP TABLE t2;
|
|
#
|
|
# Test Case 13) --do-server-ids and --server-id should be aliases and
|
|
# a re-specification of one should override the former
|
|
# MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=1 --server-id=2 | MYSQL
|
|
DROP TABLE t2;
|
|
#
|
|
# Test Case 14) --ignore-server-ids re-specifications should override
|
|
# previous ones
|
|
# MYSQL_BINLOG BINLOG_FILE_PARAM --ignore-server-ids=2 --ignore-server-ids=1,3 | MYSQL
|
|
DROP TABLE t2;
|
|
#
|
|
# Test Case 15) --do-domain-ids re-specifications should override
|
|
# previous ones
|
|
# MYSQL_BINLOG BINLOG_FILE_PARAM --do-domain-ids=1 --do-domain-ids=0 | MYSQL
|
|
DROP TABLE t1,t2;
|
|
#
|
|
# Test Case 16) --ignore-domain-ids re-specifications should override
|
|
# previous ones
|
|
# MYSQL_BINLOG BINLOG_FILE_PARAM --ignore-domain-ids=0 --ignore-domain-ids=1,2 | MYSQL
|
|
DROP TABLE t1,t2;
|
|
##############################
|
|
# Error Cases
|
|
##############################
|
|
#
|
|
# Error Case 1:
|
|
# --ignore-server-ids and --do-server-ids both specified
|
|
# MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=1 --ignore-server-ids=2
|
|
#
|
|
# Error Case 2:
|
|
# Invalid server ID number provided
|
|
# MYSQL_BINLOG BINLOG_FILE_PARAM --do-server-ids=-1
|
|
##############################
|
|
# Cleanup
|
|
##############################
|
|
SET @@global.gtid_domain_id= 0;
|
|
SET @@global.server_id= 1;
|
|
# End of tests
|