[MDEV-5095] Executing triggers on slave in row-based replication Created: 2013-10-02 Updated: 2023-02-23 Resolved: 2014-04-10 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Fix Version/s: | 10.1.0 |
| Type: | Task | Priority: | Major |
| Reporter: | Rasmus Johansson (Inactive) | Assignee: | Oleksandr Byelkin |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | pf | ||
| Issue Links: |
|
||||||||||||||||||||||||
| Description |
|
Sometimes it is wanted that triggers are executed on slaves instead of masters. This is of course possible in statement-based replication but not in row-based replication. Some reasons for trigger execution on slave are:
Galera user don't have the option of using statement-based replication since galera always uses row-based replication. It becomes tricky to get triggers to execute on the slaves. New functionality is needed to enable triggers to execute on slaves in row-based replication. Please start this task by doing adding a design here in the task description. == General notes ==The idea of the feature is that
== Solution overview ==The server will get a new command-line option, tenative name When slave-run-triggers=yes, execution of row-based events by the slave SQL thread will cause triggers to be invoked. Triggers will be invoked for each row inserted, updated, or deleted. If a trigger fails with an error, replication will stop with an error. === Binary logging of trigger actions ===The slave might be writing its own binary log. Should trigger actions be
=== Triggers on a parallel slave ===Currently, parallel slave feature is under development for MariaDB. Parallel 1. "Domain ids" in GTID mode. If two master servers have different domain 2. Group-commit-based. The idea is that if certain transactions were commited ==== Parallel apply with conflicts in triggers ===If the slave is 1) logging triggers' actions to binlog and 2) uses parallel apply, Let's consider two transactions, T1 and T2, which didn't conflict on Let us also assume that slave has triggers for T1 and T2 which will conflict. The conclusion is:
The solution for this is: ignore this problem. We think, it is a very rare scenario where === Triggers and GTIDs ===Currently, there is work underway on MariaDB Global Transaction IDs (GTIDs). If actions made by slave's triggers are not written into the binary log, there If triggers' actions are written in the binary log, the following may happen:
This is okay, as long as DBAs take this into account, and do not do fail-over GTID replication has a "strict mode" which makes more checks and doesn't let one shoot himself in the foot. The suggestion is to disallow running with slave trigger actions being written to the binary log when in strict GTID mode. == Implementation ==
== "Triggers were executed" flag in the binlog ==Monty's suggestion: Introduce a flag into binary log that has meaning "triggers were executed for this change".
The slave will run triggers only when the triggers are present and the flag is not set for the event. If the slave has executed triggers, it will set the flag to true when writing its own binlog. serg suggestion: not to introduce a flag as it doesn't solve any of the anticipated replication issues, and use something much simpler for mysqlbinlog|mysql case. == Target version ==The intent is to push this into 10.0. |
| Comments |
| Comment by Oleksandr Byelkin [ 2013-11-25 ] |
|
Current implamentation include working RBR triggers: To switch it ON slave_run_triggers_for_rbr to YES (default is NO, and LOGGING is not working yet) on the slave SET GLOBAL slave_run_triggers_for_rbr=YES; the tree with more examples in mysql-test/t/rpl_row_trigger* is here lp:~maria-captains/maria/5.5-sanja- |
| Comment by Oleksandr Byelkin [ 2013-11-27 ] |
|
Protection against double run triggers added. If a table has any triggers on the master this will be writter in the TABLE MAP EVENT and triggers of this table will not be run on slave for RBR. |
| Comment by Oleksandr Byelkin [ 2013-12-08 ] |
|
the path ported to 10.0 tree |
| Comment by Oleksandr Byelkin [ 2013-12-19 ] |
|
The postreview changes are done and sent to review. |
| Comment by Elena Stepanova [ 2014-04-10 ] |
|
While the functionality was implemented in 10.0.10, it is not available, and apparently won't be till 10.1, so the fix version is misleading for end users. I'm changing it to 10.1. |
| Comment by Ian Gilfillan [ 2014-07-03 ] |
|
I don't see a variable slave_run_triggers (or slave_run_triggers_for_rbr) on my MariaDB 10.1 install - has this been implemented yet? |
| Comment by Sergei Petrunia [ 2014-07-04 ] |
|
It's wrapped inside #ifdef and therefore is not enabled by default. It should be enabled. I've created |