osheroff / mysql-binlog-connector-java

MySQL Binary Log connector
641 stars 161 forks source link

Avoid string formatting during gtid event data deserialization and st… #101

Closed janickr closed 1 year ago

janickr commented 1 year ago

…ring parsing when adding the gtid to a GtidSet

This is a PR for item 1) in https://github.com/osheroff/mysql-binlog-connector-java/issues/98

Afaik I did not break any interfaces, except I changed the protected gtid field in BinaryLogClient from String to Object

I didn't change the MariadbGtid handling until I know more about https://github.com/osheroff/mysql-binlog-connector-java/issues/100

osheroff commented 1 year ago

not quite quite right:

mysql> select @@server_uuid;
+--------------------------------------+
| @@server_uuid                        |
+--------------------------------------+
| dd2ea913-aa87-11ed-af75-0242ac110002 |
+--------------------------------------+
1 row in set (0.01 sec)

but with this change the uuid is being to-string'ed as ed1187aa-13a9-2edd-0200-11ac420275af.
so if we take that string and pass it back to mysql, boom.

osheroff commented 1 year ago

i presume it's a different view between mysql's uuid and java's uuid?

janickr commented 1 year ago

Thanks for catching this. It was not a different view between mysql and java, it was me constructing the UUID with the bytes in the wrong order.

I wrote an integration test for this, fixed the bug, and fixed my unit test.

MySql writes the bytes of the serverId to the stream most significant byte first (big endian). But I read the bytes with byteArrayInputStream.readLong(8) which assumes little endian.