Skip to content

Conversation

Samira-El
Copy link
Contributor

@Samira-El Samira-El commented Apr 14, 2023

Hi,

After upgrading our production databases from MariaDB 10.4 to 10.6.12, we started running into an issue which appears to be a bug in this Mariadb version, see the stacktrace:

Traceback (most recent call last):
  File "/projects/python-mysql-replication/examples/mariadb_gtid/read_event.py", line 80, in <module>
    for binlogevent in stream:
  File "/projects/python-mysql-replication/pymysqlreplication/binlogstream.py", line 490, in fetchone
    pkt = self._stream_connection._read_packet()
  File "/projects/python-mysql-replication/venv/lib/python3.8/site-packages/pymysql/connections.py", line 729, in _read_packet
    packet.raise_for_error()
  File "/projects/python-mysql-replication/venv/lib/python3.8/site-packages/pymysql/protocol.py", line 221, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "/projects/PycharmProjects/python-mysql-replication/venv/lib/python3.8/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1236, "Failed to replace GTID event with backwards-compatible event: corrupt event.; the first event 'mysql-bin-changelog.310754' at 18888372, the last event read from 'mysql-bin-changelog.310754' at 18888372, the last byte read from 'mysql-bin-changelog.310754' at 18888418.")

This error is coming from this function in Mariadb's source code.

The bug is triggered when using BinLogStreamReader with binlog coordinates (not GTID), the code doesn't specify the slave capability thus the condition mariadb_slave_capability < MARIA_SLAVE_CAPABILITY_GTID passes and Mariadb then tries to replace the GTID event with a dummy one but fails, we can mitigate this by setting mariadb_slave_capability=4 in the non-gtid path too (as it's done in the gtid one), it would not be an issue because the library has had support for MariaDB GTID events for sometime now.

This fix has been tested against the same production DB and it's working fine and we receive a MariaDBGtidEvent:

=== MariadbGtidEvent ===
Date: 2023-04-10T03:19:03
Log position: 18888418
Event size: 23
Read bytes: 13
Flags: 14
GTID: 0-201709275-3720522848

Running the query set @mariadb_slave_capability=4 against mysql doesn't do anything hence no need I reckon to run this in an if block which would require knowing the DB engine (mysql or mariadb), there is a flag is_mariadb but it's false and not required for the non-gtid path, using it would make this a breaking change for downstream users so I'm trying to avoid that, but needs be, I can make it dynamic to detect the DB engine type.

@Samira-El
Copy link
Contributor Author

Samira-El commented Apr 14, 2023

Hi @julien-duponchelle, can you please take a look at this?

@Samira-El
Copy link
Contributor Author

Hi @julien-duponchelle, do you reckon this has a chance of being merged?
Thanks

@julien-duponchelle
Copy link
Owner

Hi @Samira-El that sound correct.

Sorry I'm slow to reply :( I should be able to do a release at the end of next week.

@Samira-El
Copy link
Contributor Author

Thanks Julien!

@julien-duponchelle julien-duponchelle merged commit ef52618 into julien-duponchelle:main May 7, 2023
@julien-duponchelle
Copy link
Owner

And it's released !

@Samira-El
Copy link
Contributor Author

thank you 🥇 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants