shyiko / mysql-binlog-connector-java

MySQL Binary Log connector
2.22k stars 817 forks source link

Make `EventType` extensible or injectable #177

Open adsr opened 7 years ago

adsr commented 7 years ago

Hello. I maintain a fork of this library (and Debezium[0]) primarily to support a custom binlog event[1] from Twitter's fork of mysql. In order to support different flavors of mysql and custom binlog events, I propose moving away from a strict enum and using a more extensible data structure for EventType, or somehow allowing library users to inject their own enum.

[0] https://github.com/debezium/debezium

[1] https://github.com/twitter/mysql/blob/865aae5f23e2091e1316ca0e6c6651d57f786c76/sql/log_event.h#L605

shyiko commented 7 years ago

Hi Adam.

It's (definitely) on the roadmap for 1.0.0. The plan is to convert EventType into a class akin to Netty's AbstractConstant.

(before 1.0.0 is out) As an alternative to maintaining a fork:

This is obviously just a workaround. A proper solution is coming in 1.0.0.

adsr commented 7 years ago

Great. Thank you @shyiko

bluebike commented 6 years ago

In my opinion this whole EvenType could be handled other way. EventDataDeserializers would registered by event number (0-255) and EventType could just optional way to have EventConstants.

So EventDeserializer.java map of <EventType, EventDataDeserializer> could changed to Array of EventDataDeserializers[256].

private final Map<EventType, EventDataDeserializer> eventDataDeserializers => private EventDataDeserializer eventDataDeserializers[256] and all registering is actually done by event number and in case of EventType, type event_number (is ordinal()) is just used as index to that table.

Actually EventType should contain event_number as constant (not as enum ordinal). This is important especially if MariaDB event numbers (160+ something are added) That can be easily patched.