5.10. How Servers Evaluate Replication RulesIf a master server does not write a statement to its binary log, the statement is not replicated. If the server does log the statement, the statement is sent to all slaves and each slave determines whether to execute it or ignore it. On the master side, decisions about which statements to log are based on the --binlog-dodb and --binlog-ignore-db options that control binary logging. For a description of the rules that servers use in evaluating these options, see Section 4.12.3, "The Binary Log." On the slave side, decisions about whether to execute or ignore statements received from the master are made according to the --replicate-* options that the slave was started with. (See Section 5.9, "Replication Startup Options.") The slave evaluates these options using the following procedure, which first checks the database-level options and then the table-level options. In the simplest case, when there are no --replicate-* options, the procedure yields the result that the slave executes all statements that it receives from the master. Otherwise, the result depends on the particular options given. In general, to make it easier to determine what effect an option set will have, it is recommended that you avoid mixing "do" and "ignore" options, or wildcard and non-wildcard options. Stage 1. Check the database options.At this stage, the slave checks whether there are any --replicate-do-db or --replicate-ignore-db options that specify database-specific conditions:
This stage can permit a statement for further option-checking, or cause it to be ignored. However, statements that are permitted at this stage are not actually executed yet. Instead, they pass to the following stage that checks the table options. Stage 2. Check the table options.First, as a preliminary condition, the slave checks whether statement-based replication is enabled. If so and the statement occurs within a stored function or (prior to MySQL 5.0.12) a stored procedure, execute the statement and exit. (Stored procedures are exempt from this test as of MySQL 5.0.12 because procedure logging occurs at the level of statements that are executed within the routine rather than at the CALL level. If row-based replication is enabled, the slave does not know whether a statement occurred within a stored function on the master, so this condition does not apply.) Next, the slave checks for table options and evaluates them. If the server reaches this point, it executes all statements if there are no table options. If there are "do" table options, the statement must match one of them if it is to be executed; otherwise, it is ignored. If there are any "ignore" options, all statements are executed except those that match any ignore option. The following steps describe how this evaluation occurs in more detail.
Examples:
Suppose that db1 is the default database and the slave receives this statement: INSERT INTO mytbl1 VALUES(1,2,3); The database is db1, which matches the --replicate-do-db option at the database-checking stage. The algorithm then proceeds to the table-checking stage. If there were no table options, the statement would be executed. However, because the options include a "do" table option, the statement must match if it is to be executed. The statement does not match, so it is ignored. (The same would happen for any table in db1.) |