[MDEV-14760] Replication does not take into account SET STATEMENT Created: 2017-12-24 Updated: 2023-12-19 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | Replication |
| Affects Version/s: | 10.1, 10.2, 10.6 |
| Fix Version/s: | 10.4 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Elena Stepanova | Assignee: | Andrei Elkin |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | decide_logging_format | ||
| Issue Links: |
|
||||||||||||||||
| Description |
|
DDL statements sent to slave does not take into account the original environment where the query was executed.
|
| Comments |
| Comment by Sujatha Sivakumar (Inactive) [ 2019-03-12 ] | |||||||||||||||||||||||||||||||||||||||||||
|
IMHO the reported issue is not a bug, because of the following reasons. Reason 1:- https://dev.mysql.com/doc/refman/5.7/en/replication-features-variables.html I hope MariaDB also has the same behaviour. Reason 2:- The ported patch added a test named :rpl_set_statement.test This test has a scenario do demonstrate that following variables are never --echo 4) variables that are not replicated at all: Hence the documentation needs to be updated saying the above SET STATEMENTS will Please let me know your thoughts. | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Sujatha Sivakumar (Inactive) [ 2019-03-12 ] | |||||||||||||||||||||||||||||||||||||||||||
|
Hello Andrei, Please review the latest comments on the JIRA page and provide your thoughts. Thank you. | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Andrei Elkin [ 2019-05-29 ] | |||||||||||||||||||||||||||||||||||||||||||
|
sujatha.sivakumar, howdy. Thanks for briefing me with the feature's history, which really saved a little time
After the evaluation the chosen value is also present in Query-log-event (the evidence part is omitted though). And secondly the whole idea of the SET-STATEMENT I hope this makes it more clear. Cheers, | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Andrei Elkin [ 2019-05-29 ] | |||||||||||||||||||||||||||||||||||||||||||
|
It took time to arrive @ the question, Sujatha. | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Sujatha Sivakumar (Inactive) [ 2019-05-31 ] | |||||||||||||||||||||||||||||||||||||||||||
|
Hello Andrei, Good morning. Thank you for the review comments. The system variables which are set using "SET STATEMENT" are never replicated. But if we look at the 'rpl_set_statement.test' the second test case states that For example: In general 'auto_increment_increment' system variable is replicated. Please have
"SET STATEMENT" syntax is ignored on slave. The reason why the implementer chose Hence the original code looks like this.
The internal implementation of 'SET STATEMENT' looks like this
For example:
Binary log output:
Conclusion: Since "SET STATEMENT" also acts like above it should not replicate Please let me know your thoughts. | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Andrei Elkin [ 2019-07-01 ] | |||||||||||||||||||||||||||||||||||||||||||
|
sujatha.sivakumar, thanks for a thorough analysis and detailing! The matter finally settled in my mind. Like you say in The internal implementation it's fair to think of SET STATEMENT var1,var2,..., var_n FOR Query as a shortcut: save old values; set var:s; exec Query; restore var:s. Now we notice that among the var:s we have ones that are present in Query_log_event::"context" (replicated), and those that are not. Those that are currently not should not get into the context. Those that are in already don't need {{SET STATEMENT var1,var2,..., var_n }} preamble be replicated. I suggest we consider such cases are replication unsafe. Now the question is how to implement that technically, and also when/how urgently. | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Joffrey MICHAIE [ 2021-03-12 ] | |||||||||||||||||||||||||||||||||||||||||||
|
Hello, the same behavior is observed with old_alter_table: SET STATEMENT old_alter_table = 1 ALTER XXX While in show processlist on the replica, the SET STATEMENT is displayed in the command, under the hood the ALTER is being performed without setting the variable as requested (State: ALTERING TABLE) and taking much longer than planned. This can be confusing for the User/DBA. | 948403 | system user | | db_name | Slave_SQL | 329 | altering table | SET STATEMENT old_alter_table = 1 FOR alter table my_table add column_name smallint defaul | 0.000 | Maybe this should be documented more explicitly as not supported, and some downtime can be avoided. Cheers, | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Andrei Elkin [ 2021-03-12 ] | |||||||||||||||||||||||||||||||||||||||||||
|
sujatha.sivakumar: Could we try something like Annotate_log_event that is to embed the original SET-query into a new char[] Query_log_event::status_var::set_query. The variable would be replicated along with others see Query_log_event::write to replace Query_log_event::query on slave. | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Andrei Elkin [ 2021-03-12 ] | |||||||||||||||||||||||||||||||||||||||||||
|
joffrey92 Indeed! Thank you. We're still considering if/and how to fix. | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Widenius [ 2023-09-05 ] | |||||||||||||||||||||||||||||||||||||||||||
|
This is not only related to SET STATEMENT but with the whole environment on the master. set default_storage_engine=aria; A better way would be to send together with the query the whole environment that the query is using, like default storage engine, default character set etc. Another options is to send to the slave not the original query but the query one gets from 'show create table' as this includes all information needed. | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2023-09-05 ] | |||||||||||||||||||||||||||||||||||||||||||
Sure, but it has always been so, as a known legacy limitation that we only replicate a tiny part of the environment. | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Widenius [ 2023-10-23 ] | |||||||||||||||||||||||||||||||||||||||||||
|
Agree that the simple solution is to include the original SET STATEMENT into the binary log. |