Replication Errors in GTID-Based ReplicationIn this blog, I’m going to discuss how to easily skip the replication errors in GTID (Global Transaction Identifier)-based replication.

In the MySQL world, if replication is broken we all use the famous SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; to skip the replication error. It always works if it’s a traditional binlogs events-based replication and is helpful to quickly resume the replication. But does this same method work for GTID-based replication? Let’s see.

In GTID-based replication, skipping a replication error in a broken replica is not as simple as binlogs-based replication. We have one old blog postRepair MySQL 5.6 GTID replication by injecting empty transactions —where one of our colleagues showed us one way to skip and fix the replication.

Let’s get into action and see another way of skipping an errored transaction in GTID replication.

Let’s try skipping the error with SQL_SLAVE_SKIP_COUNTER:

As you can see we are unable to skip the error and we got an error message while skipping with SQL_SLAVE_SKIP_COUNTER. As per the error message, it was unable to skip as this replica is running with GTID_MODE = ON.

Let’s test the trick and skip this error:

Here we have stopped the replication and changed the GTID_MODE from ON to ON_PERMISSIVE (New transactions are GTID transactions. Replicated transactions can be either anonymous or GTID transactions) and skipped it using SQL_SLAVE_SKIP_COUNTER = 1 and started the replication.

Once replication is caught up, we need to set the  GTID_MODE back to ON.

The SQL SQL_SLAVE_SKIP_COUNTER must be defined as 0 in order for MySQL to permit changing the GTID_MODE from ON_PERMISSIVE to ON.

According to the MySQL documentation, there are four different GTID modes available as noted below

  • OFF: Both new and replicated transactions must be anonymous.
  • OFF_PERMISSIVE: New transactions are anonymous. Replicated transactions can be either anonymous or GTID transactions.
  • ON_PERMISSIVE: New transactions are GTID transactions. Replicated transactions can be either anonymous or GTID transactions.
  • ON: Both new and replicated transactions must be GTID transactions.

Conclusion: Changing the GTID_MODE online is available since MySQL 5.7.6, and hope this method helps in quickly skipping the errors. Please be aware that you are making data inconsistent between the primary and replica by skipping a transaction, so we might have to fix the data inconsistency. pt-table-checksum and pt-table-sync can help you with fixing data inconsistency. 

Looking for database support your team can count on?

Get Started with Percona Support Today!

Subscribe
Notify of
guest

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Francisco Miguel Biete Banon

I’m not sure what to think about this post.
That’s not the recommended method – The documentation has a very clear example of how to skip transactions when GTID is enabled, without messing around with the modes globally (notice how that “old” method has been moved down in the procedure list).

https://dev.mysql.com/doc/refman/8.0/en/replication-administration-skip.html

Omar Hugo Gomez

Hey Francisco, you’re barely right, therefore, would you mind specifying exactly where are the right steps for the specific issue?
You pointed out almost everything. Please be more specific, if you don’t mind, otherwise I’ll mess around everything anyway.

Francisco Miguel Biete Banon

Read the referenced Oracle MySQL page, you have the procedure step by step in that page.
The method described in this post is, per Oracle documentation, to be used when GTID is not enabled… not when GTIDs are enabled. For GTID enabled servers the procedure is 17.1.7.3.1.

17.1.7.3.1 Skipping Transactions With GTIDs17.1.7.3.2 Skipping Transactions Without GTIDs17.1.7.3.2.1 Skipping Transactions With SET GLOBAL sql_slave_skip_counter
17.1.7.3.2.2 Skipping Transactions With CHANGE MASTER TO