osheroff / mysql-binlog-connector-java

MySQL Binary Log connector
680 stars 167 forks source link

Issue with byte array and binlog compression (Debezium) #118

Open rolevinks opened 1 year ago

rolevinks commented 1 year ago

Hi,

I'm not sure if this is the correct place to ask this question, but may be somebody here can help me.

In our system, we're trying to use the Debezium MySql connector, with the binlog compression on on the database. Our entities have a UUID as id, these are stored as binary(16) in the database. However, when the binlog is read and decompressed, the byte array representing the UUID is 32 bytes long, and converting this back to a UUID results in a different UUID than the actual id of the entity.

For example, when an entity with UUID 299fc7af-ff34-4a30-9a28-8e7b0b0cd116 is saved, the event in the TransactionPayloadEventDataDeserializer contains byte array [41, 0, -3, -1, -3, -1, -3, -1, -3, -1, 52, 0, 74, 0, 48, 0, -3, -1, 40, 0, -3, -1, 123, 0, 11, 0, 12, 0, -3, -1, 22, 0] for this id.

Without the binlog compression everything works as expected.

Does anybody know what is happening here?

So, I figured out what the problem is; byte arrays are read as a string, in AbstractRowsEventDataDeserializer.deserializeString, because the deserializeCharAndBinaryAsByteArray is set to false. The CompatibilityMode.CHAR_AND_BINARY_AS_BYTE_ARRAY is not set. According tot the JavaDoc, this will be enabled by default with version 1.0.0

 /**
 * Return CHAR/VARCHAR/BINARY/VARBINARY values as byte[]|s (instead of String|s).
 *
 * <p>This option is going to be enabled by default starting from mysql-binlog-connector-java@1.0.0.
 */
 CHAR_AND_BINARY_AS_BYTE_ARRAY,

So, two questions:

  1. When will version 1.0.0 come out?
  2. Why does this mode cover these four types? In the situation I described above, ideally I would want my binary(16) values to be read as byte arrays and varchar variables as strings, there is no reason to read the latter as byte arrays. This would mean there would be two compatibilitymodes, CompatibilityMode.BINARY_AND_VARBINARY_AS_BYTE_ARRAY and CompatibilityMode.CHAR_AND_VARCHAR_AS_BYTE_ARRAY