Skip to content

Commit 3b1cbdd

Browse files
author
Venkatesh Prasad Venugopal
committed
PS-6002: CREATE/ALTER EVENT STATE TO KEEP ENABLED ON REPLICAS
https://jira.percona.com/browse/PS-6002 This feature introduces a global config variable --replica-enable-event that accepts the regex patterns of the events in format "db_pattern.event_pattern" for those events that need to be re-enabld after the creation or modification of event on replica server, unlike the current behavior where the replicated events are by default set to the state SLAVESIDE_DISABLED. The below shall be the behavior when a replicated event matches the pattern specified in the `--replica-enable-event`. 1. When an event is created as ENABLED on source, it shall remain ENABLED on replica as well. 2. When an event is created as DISABLED it shall remain DISABLED on replica as well. 3. If an event in ENABLED state is altered as DISABLED on source, then it shall become DISABLED on replica as well. 4. If an event in ENABLED state is altered and if it remains ENABLED on source, then it shall remain ENABLED on replica as well. 5. If an event in DISABLED state is altered and if it remains DISABLED on source then, shall remain DISABLED on replica as well. 6. If an event in DISABLED state is altered to ENABLED state on the source server, then it shall become ENABLED on replica as well.
1 parent c59f87d commit 3b1cbdd

23 files changed

+1723
-12
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Start the server with the provided value for --replica-enable-event.
2+
# This may result with startup abort, or proper startup with no errors.
3+
# Validate the expected log accordingly.
4+
#
5+
# Usage:
6+
#
7+
# --let $wild_pattern = db%.%event%
8+
# --let $expect_abort = no <-- We expect that server shall start properly
9+
# --let $reason <-- Message to be searched in the error log for validation
10+
# --source rpl_enable_event_cmd_line_validation.inc
11+
#
12+
# === References ===
13+
#
14+
# PS-6002: Create/alter event state to keep enabled on replicas
15+
16+
--echo
17+
--echo Starting the replica server with --replica-enable-event='$wild_pattern'
18+
19+
--let $error_log= $MYSQL_TMP_DIR/test_error_log.err
20+
--let $start_params = --replica-enable-event=$wild_pattern
21+
22+
if ($expect_abort == 'yes')
23+
{
24+
--let $rpl_server_parameters= --log-error=$error_log $start_params
25+
--let $mysqld= $MYSQLD --defaults-file=$MYSQLTEST_VARDIR/my.cnf --defaults-group-suffix=.2
26+
27+
# Server abort is expected
28+
--error 1
29+
--exec $mysqld $rpl_server_parameters
30+
--echo Server Startup aborted as expected.
31+
}
32+
33+
if ($expect_abort != 'yes')
34+
{
35+
--let $rpl_server_number = 2
36+
--let $rpl_omit_print_server_parameters= 1
37+
--let $rpl_server_parameters= --log-error=$error_log $start_params
38+
--source include/rpl_start_server.inc
39+
}
40+
41+
# Validation
42+
if ($expect_abort == 'yes')
43+
{
44+
# Restart the server with defaut options for validation
45+
--let $rpl_server_number = 2
46+
--let $rpl_omit_print_server_parameters= 1
47+
--let $rpl_server_parameters=
48+
--source include/rpl_start_server.inc
49+
50+
# Assert that the server logs the message "Could not add event rule .* to --replica-enable-event"
51+
--let $assert_file= $error_log
52+
--let $assert_text= Found the message: Could not add event rule '$wild_pattern' to --replica-enable-event
53+
--let $assert_select= \[ERROR\] .* Could not add event rule '$wild_pattern' to --replica-enable-event
54+
--let $assert_count= 1
55+
--source include/assert_grep.inc
56+
57+
# Additional validation for the exact reason for the server abort.
58+
--let $assert_file= $error_log
59+
--let $assert_text= Found the reason: $reason
60+
--let $assert_select= $reason
61+
--let $assert_count= 1
62+
--source include/assert_grep.inc
63+
}
64+
65+
--echo # Stop the server
66+
--source include/rpl_stop_server.inc
67+
--remove_file $error_log

mysql-test/r/mysqld--help-notwin.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,17 @@ The following options may be given as the first argument:
12371237
maximum number of milliseconds between updates.
12381238
--replica-compressed-protocol
12391239
Use compression in the source/replica protocol.
1240+
--replica-enable-event=name
1241+
Tells the replication applier thread to enable the events
1242+
that match the specified wildcard pattern without setting
1243+
it as SLAVESIDE_DISABLED. To specify more than one event,
1244+
use the directive multiple times, once for each event.
1245+
This will work for cross-database events. Example:
1246+
replica-enable-event=foo%.bar% will enable the events in
1247+
all databases on replica server that start with 'foo' and
1248+
whose event names start with 'bar'. It is recommended to
1249+
use this feature only for read-only events to avoid data
1250+
inconsistency.
12401251
--replica-exec-mode=name
12411252
Modes for how replication events should be executed.
12421253
Legal values are STRICT (default) and IDEMPOTENT. In

mysql-test/suite/binlog_nogtid/r/binlog_persist_only_variables.result

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ INSERT INTO non_persisted VALUES
3030
('log_bin_basename'), ('log_bin_index'), ('relay_log'), ('relay_log_basename'),
3131
('relay_log_index'), ('relay_log_info_file'), ('replica_load_tmpdir'),
3232
('slave_load_tmpdir'), ('log_bin_use_v1_row_events'),
33-
('have_backup_safe_binlog_info');
33+
('have_backup_safe_binlog_info'), ('replica_enable_event');
3434
CREATE TABLE aliases (
3535
name VARCHAR(100) PRIMARY KEY
3636
);
@@ -47,7 +47,7 @@ INSERT INTO aliases(name) VALUES
4747
('slave_parallel_workers'), ('slave_pending_jobs_size_max'),
4848
('pseudo_slave_mode'), ('skip_slave_start');
4949

50-
include/assert.inc [Expect 118 variables in the table.]
50+
include/assert.inc [Expect 119 variables in the table.]
5151

5252
# Test SET PERSIST_ONLY
5353
SET PERSIST_ONLY binlog_cache_size = @@GLOBAL.binlog_cache_size;
@@ -148,6 +148,8 @@ SET PERSIST_ONLY replica_allow_batching = @@GLOBAL.replica_allow_batching;
148148
SET PERSIST_ONLY replica_checkpoint_group = @@GLOBAL.replica_checkpoint_group;
149149
SET PERSIST_ONLY replica_checkpoint_period = @@GLOBAL.replica_checkpoint_period;
150150
SET PERSIST_ONLY replica_compressed_protocol = @@GLOBAL.replica_compressed_protocol;
151+
SET PERSIST_ONLY replica_enable_event = @@GLOBAL.replica_enable_event;
152+
ERROR HY000: Variable 'replica_enable_event' is a non persistent read only variable
151153
SET PERSIST_ONLY replica_exec_mode = @@GLOBAL.replica_exec_mode;
152154
SET PERSIST_ONLY replica_load_tmpdir = @@GLOBAL.replica_load_tmpdir;
153155
ERROR HY000: Variable 'replica_load_tmpdir' is a non persistent read only variable
@@ -354,6 +356,8 @@ RESET PERSIST replica_allow_batching;
354356
RESET PERSIST replica_checkpoint_group;
355357
RESET PERSIST replica_checkpoint_period;
356358
RESET PERSIST replica_compressed_protocol;
359+
RESET PERSIST replica_enable_event;
360+
ERROR HY000: Variable replica_enable_event does not exist in persisted config file
357361
RESET PERSIST replica_exec_mode;
358362
RESET PERSIST replica_load_tmpdir;
359363
ERROR HY000: Variable replica_load_tmpdir does not exist in persisted config file

mysql-test/suite/binlog_nogtid/r/binlog_persist_variables.result

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ VARIABLE_NAME LIKE '%source%') AND
2525
(VARIABLE_NAME NOT LIKE 'innodb%')
2626
ORDER BY VARIABLE_NAME;
2727

28-
include/assert.inc [Expect 118 variables in the table.]
28+
include/assert.inc [Expect 119 variables in the table.]
2929

3030
# Test SET PERSIST
3131
SET PERSIST binlog_cache_size = @@GLOBAL.binlog_cache_size;
@@ -131,6 +131,8 @@ SET PERSIST replica_allow_batching = @@GLOBAL.replica_allow_batching;
131131
SET PERSIST replica_checkpoint_group = @@GLOBAL.replica_checkpoint_group;
132132
SET PERSIST replica_checkpoint_period = @@GLOBAL.replica_checkpoint_period;
133133
SET PERSIST replica_compressed_protocol = @@GLOBAL.replica_compressed_protocol;
134+
SET PERSIST replica_enable_event = @@GLOBAL.replica_enable_event;
135+
ERROR HY000: Variable 'replica_enable_event' is a read only variable
134136
SET PERSIST replica_exec_mode = @@GLOBAL.replica_exec_mode;
135137
SET PERSIST replica_load_tmpdir = @@GLOBAL.replica_load_tmpdir;
136138
ERROR HY000: Variable 'replica_load_tmpdir' is a read only variable
@@ -371,6 +373,9 @@ RESET PERSIST IF EXISTS replica_allow_batching;
371373
RESET PERSIST IF EXISTS replica_checkpoint_group;
372374
RESET PERSIST IF EXISTS replica_checkpoint_period;
373375
RESET PERSIST IF EXISTS replica_compressed_protocol;
376+
RESET PERSIST IF EXISTS replica_enable_event;
377+
Warnings:
378+
Warning 3615 Variable replica_enable_event does not exist in persisted config file
374379
RESET PERSIST IF EXISTS replica_exec_mode;
375380
RESET PERSIST IF EXISTS replica_load_tmpdir;
376381
Warnings:

mysql-test/suite/binlog_nogtid/t/binlog_persist_only_variables.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ INSERT INTO non_persisted VALUES
6363
('log_bin_basename'), ('log_bin_index'), ('relay_log'), ('relay_log_basename'),
6464
('relay_log_index'), ('relay_log_info_file'), ('replica_load_tmpdir'),
6565
('slave_load_tmpdir'), ('log_bin_use_v1_row_events'),
66-
('have_backup_safe_binlog_info');
66+
('have_backup_safe_binlog_info'), ('replica_enable_event');
6767

6868
CREATE TABLE aliases (
6969
name VARCHAR(100) PRIMARY KEY
@@ -84,7 +84,7 @@ INSERT INTO aliases(name) VALUES
8484
# If this count differs, it means a variable has been added or removed.
8585
# In that case, this testcase needs to be updated accordingly.
8686
--echo
87-
--let $expected = 118
87+
--let $expected = 119
8888
--let $assert_text = Expect $expected variables in the table.
8989
--let $assert_cond = [SELECT COUNT(*) as count FROM rplvars, count, 1] = $expected
9090
--source include/assert.inc

mysql-test/suite/binlog_nogtid/t/binlog_persist_variables.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ INSERT INTO rplvars (varname, varvalue)
6161
# If this count differs, it means a variable has been added or removed.
6262
# In that case, this testcase needs to be updated accordingly.
6363
--echo
64-
--let $expected = 118
64+
--let $expected = 119
6565
--let $assert_text = Expect $expected variables in the table.
6666
--let $assert_cond = [SELECT COUNT(*) as count FROM rplvars, count, 1] = $expected
6767
--source include/assert.inc
@@ -74,7 +74,7 @@ while ( $varid <= $countvars )
7474
--let $varnames = `SELECT varname FROM rplvars WHERE id=$varid;`
7575

7676
# The following variables are either non persistent or read only variables.
77-
if (`SELECT '$varnames' IN ('binlog_row_event_max_size', 'binlog_gtid_simple_recovery', 'binlog_space_limit', 'gtid_executed', 'gtid_next', 'gtid_owned', 'gtid_purged', 'have_backup_safe_binlog_info', 'log_bin', 'log_bin_basename', 'log_bin_index', 'log_replica_updates', 'log_slave_updates', 'relay_log', 'relay_log_basename', 'relay_log_index', 'relay_log_index', 'relay_log_info_file', 'relay_log_recovery', 'relay_log_space_limit', 'replica_load_tmpdir', 'slave_load_tmpdir', 'replica_skip_errors', 'slave_skip_errors', 'log_bin_use_v1_row_events', 'binlog_rotate_encryption_master_key_at_startup', 'skip_replica_start', 'skip_slave_start')`)
77+
if (`SELECT '$varnames' IN ('binlog_row_event_max_size', 'binlog_gtid_simple_recovery', 'binlog_space_limit', 'gtid_executed', 'gtid_next', 'gtid_owned', 'gtid_purged', 'have_backup_safe_binlog_info', 'log_bin', 'log_bin_basename', 'log_bin_index', 'log_replica_updates', 'log_slave_updates', 'relay_log', 'relay_log_basename', 'relay_log_index', 'relay_log_index', 'relay_log_info_file', 'relay_log_recovery', 'relay_log_space_limit', 'replica_load_tmpdir', 'slave_load_tmpdir', 'replica_skip_errors', 'slave_skip_errors', 'log_bin_use_v1_row_events', 'binlog_rotate_encryption_master_key_at_startup', 'skip_replica_start', 'skip_slave_start', 'replica_enable_event')`)
7878
{
7979
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
8080
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
include/master-slave.inc
2+
Warnings:
3+
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
4+
Note #### Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
5+
[connection master]
6+
[connection slave]
7+
include/rpl_stop_server.inc [server_number=2]
8+
9+
Starting the replica server with --replica-enable-event=''
10+
Server Startup aborted as expected.
11+
include/rpl_start_server.inc [server_number=2]
12+
include/assert_grep.inc [Found the message: Could not add event rule '' to --replica-enable-event]
13+
include/assert_grep.inc [Found the reason: Cannot process empty pattern]
14+
# Stop the server
15+
include/rpl_stop_server.inc [server_number=2]
16+
17+
Starting the replica server with --replica-enable-event='.event%'
18+
Server Startup aborted as expected.
19+
include/rpl_start_server.inc [server_number=2]
20+
include/assert_grep.inc [Found the message: Could not add event rule '.event%' to --replica-enable-event]
21+
include/assert_grep.inc [Found the reason: The pattern doesn't follow the format <db_pattern>.<event_pattern>]
22+
# Stop the server
23+
include/rpl_stop_server.inc [server_number=2]
24+
25+
Starting the replica server with --replica-enable-event='db%.'
26+
Server Startup aborted as expected.
27+
include/rpl_start_server.inc [server_number=2]
28+
include/assert_grep.inc [Found the message: Could not add event rule 'db%.' to --replica-enable-event]
29+
include/assert_grep.inc [Found the reason: The pattern doesn't follow the format <db_pattern>.<event_pattern>]
30+
# Stop the server
31+
include/rpl_stop_server.inc [server_number=2]
32+
33+
Starting the replica server with --replica-enable-event='event'
34+
Server Startup aborted as expected.
35+
include/rpl_start_server.inc [server_number=2]
36+
include/assert_grep.inc [Found the message: Could not add event rule 'event' to --replica-enable-event]
37+
include/assert_grep.inc [Found the reason: The pattern doesn't follow the format <db_pattern>.<event_pattern>]
38+
# Stop the server
39+
include/rpl_stop_server.inc [server_number=2]
40+
41+
Starting the replica server with --replica-enable-event='db%.event%.random'
42+
Server Startup aborted as expected.
43+
include/rpl_start_server.inc [server_number=2]
44+
include/assert_grep.inc [Found the message: Could not add event rule 'db%.event%.random' to --replica-enable-event]
45+
include/assert_grep.inc [Found the reason: The pattern has multiple dot characters. Please restart with format <db_pattern>.<event_pattern>]
46+
# Stop the server
47+
include/rpl_stop_server.inc [server_number=2]
48+
49+
Starting the replica server with --replica-enable-event='channel:db%.event%'
50+
Server Startup aborted as expected.
51+
include/rpl_start_server.inc [server_number=2]
52+
include/assert_grep.inc [Found the message: Could not add event rule 'channel:db%.event%' to --replica-enable-event]
53+
include/assert_grep.inc [Found the reason: This server doesn't support per-channel --replica-enable-event feature]
54+
# Stop the server
55+
include/rpl_stop_server.inc [server_number=2]
56+
57+
Starting the replica server with --replica-enable-event='db%.event1%'
58+
include/rpl_start_server.inc [server_number=2]
59+
# Stop the server
60+
include/rpl_stop_server.inc [server_number=2]
61+
62+
Starting the replica server with --replica-enable-event='d%b%.%event%'
63+
include/rpl_start_server.inc [server_number=2]
64+
# Stop the server
65+
include/rpl_stop_server.inc [server_number=2]
66+
include/rpl_start_server.inc [server_number=2]
67+
include/start_slave.inc
68+
SHOW GLOBAL VARIABLES LIKE '%replica_enable_event%';
69+
Variable_name Value
70+
replica_enable_event db%.event1%,d%b%.%event%
71+
SELECT VARIABLE_VALUE FROM performance_schema.global_variables WHERE VARIABLE_NAME LIKE 'replica_enable_event%';
72+
VARIABLE_VALUE
73+
db%.event1%,d%b%.%event%
74+
SET @hex_expected= HEX("db%.event1%,d%b%.%event%");
75+
SELECT HEX(VARIABLE_VALUE) FROM performance_schema.global_variables WHERE VARIABLE_NAME LIKE 'replica_enable_event%' INTO @hex_value;
76+
include/assert.inc [Assert that perfschema query reports the list contents in the CSV format.]
77+
include/rpl_end.inc

0 commit comments

Comments
 (0)