Thursday 26 March 2015

Error while grant execution can break replication in mysql 5.6

This looks like a bug in MySQL 5.6 : user  with GRANT privileges can  cause all replicas to break,  if the grant executed errors.

How?

 Let me explain . Lets assume iam trying to issue a grant replication client privilege to an user as seen below:

mysql> grant replication client on mine.*  to user@'10.29.1%';
ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES

 The above grant failed coz the global privilege was supposed to be granted on *.*.
 Hence I re-execute by making corrections :

mysql> grant replication client on *.* to user@'10.29.1%';
Query OK, 0 rows affected (0.10 sec)
mysql> flush privileges;

All i did was corrected a grant statement. However this broke the replication of mysql database.
and Its a bug as per mysql : 68892.
 
Explaination:
 
Due to this replication bug, any GRANT command that errors out will break the mysql replication.
Then hence  skip the offending event on ALL replicas (or inject an empty transaction if GTID in use). The reason  is that MySQL 5.6 writes the following in the binlog when your grant fails:
#120009 01:02:10 server id 1 end_log_pos 422 CRC32 0x4d815dbc
# Incident: LOST_EVENTS
RELOAD DATABASE; # Shall generate syntax error
# at 422

This is intended to avoid any grant that fails on the master due to insufficient privileges, to succeed on the replicas instead (due to the fact that replication thread runs with SUPER privileges). To avoid that, replication is stopped with an error.
Concluding that any user on 5.6 which has GRANT privileges can break the replication if while executing any GRANT it error.


Cheers.

No comments:

Post a Comment