1515 */
1616package com .github .shyiko .mysql .binlog .event ;
1717
18+ import java .util .HashMap ;
19+ import java .util .Map ;
20+
1821/**
1922 * @see <a href="https://dev.mysql.com/doc/internals/en/event-meanings.html">Event Meanings</a> for the original
2023 * documentation.
@@ -25,90 +28,94 @@ public enum EventType {
2528 /**
2629 * Events of this event type should never occur. Not written to a binary log.
2730 */
28- UNKNOWN ,
31+ UNKNOWN ( 0 ) ,
2932 /**
3033 * A descriptor event that is written to the beginning of the each binary log file. (In MySQL 4.0 and 4.1,
3134 * this event is written only to the first binary log file that the server creates after startup.) This event is
3235 * used in MySQL 3.23 through 4.1 and superseded in MySQL 5.0 by {@link #FORMAT_DESCRIPTION}.
3336 */
34- START_V3 ,
37+ START_V3 ( 1 ) ,
3538 /**
3639 * Written when an updating statement is done.
3740 */
38- QUERY ,
41+ QUERY ( 2 ) ,
3942 /**
4043 * Written when mysqld stops.
4144 */
42- STOP ,
45+ STOP ( 3 ) ,
4346 /**
4447 * Written when mysqld switches to a new binary log file. This occurs when someone issues a FLUSH LOGS statement or
4548 * the current binary log file becomes larger than max_binlog_size.
49+ *
50+ * See https://dev.mysql.com/doc/internals/en/rotate-event.html
4651 */
47- ROTATE ,
52+ ROTATE ( 4 ) ,
4853 /**
4954 * Written every time a statement uses an AUTO_INCREMENT column or the LAST_INSERT_ID() function; precedes other
5055 * events for the statement. This is written only before a {@link #QUERY} and is not used in case of RBR.
5156 */
52- INTVAR ,
57+ INTVAR ( 5 ) ,
5358 /**
5459 * Used for LOAD DATA INFILE statements in MySQL 3.23.
5560 */
56- LOAD ,
61+ LOAD ( 6 ) ,
5762 /**
5863 * Not used.
5964 */
60- SLAVE ,
65+ SLAVE ( 7 ) ,
6166 /**
6267 * Used for LOAD DATA INFILE statements in MySQL 4.0 and 4.1.
6368 */
64- CREATE_FILE ,
69+ CREATE_FILE ( 8 ) ,
6570 /**
6671 * Used for LOAD DATA INFILE statements as of MySQL 4.0.
6772 */
68- APPEND_BLOCK ,
73+ APPEND_BLOCK ( 9 ) ,
6974 /**
7075 * Used for LOAD DATA INFILE statements in 4.0 and 4.1.
7176 */
72- EXEC_LOAD ,
77+ EXEC_LOAD ( 10 ) ,
7378 /**
7479 * Used for LOAD DATA INFILE statements as of MySQL 4.0.
7580 */
76- DELETE_FILE ,
81+ DELETE_FILE ( 11 ) ,
7782 /**
7883 * Used for LOAD DATA INFILE statements in MySQL 4.0 and 4.1.
7984 */
80- NEW_LOAD ,
85+ NEW_LOAD ( 12 ) ,
8186 /**
8287 * Written every time a statement uses the RAND() function; precedes other events for the statement. Indicates the
8388 * seed values to use for generating a random number with RAND() in the next statement. This is written only
8489 * before a {@link #QUERY} and is not used in case of RBR.
8590 */
86- RAND ,
91+ RAND ( 13 ) ,
8792 /**
8893 * Written every time a statement uses a user variable; precedes other events for the statement. Indicates the
8994 * value to use for the user variable in the next statement. This is written only before a {@link #QUERY} and
9095 * is not used in case of RBR.
9196 */
92- USER_VAR ,
97+ USER_VAR ( 14 ) ,
9398 /**
9499 * A descriptor event that is written to the beginning of the each binary log file.
95100 * This event is used as of MySQL 5.0; it supersedes {@link #START_V3}.
101+ *
102+ * See: https://dev.mysql.com/doc/internals/en/format-description-event.html
96103 */
97- FORMAT_DESCRIPTION ,
104+ FORMAT_DESCRIPTION ( 15 ) ,
98105 /**
99106 * Generated for a commit of a transaction that modifies one or more tables of an XA-capable storage engine.
100107 * Normal transactions are implemented by sending a {@link #QUERY} containing a BEGIN statement and a {@link #QUERY}
101108 * containing a COMMIT statement (or a ROLLBACK statement if the transaction is rolled back).
102109 */
103- XID ,
110+ XID ( 16 ) ,
104111 /**
105112 * Used for LOAD DATA INFILE statements as of MySQL 5.0.
106113 */
107- BEGIN_LOAD_QUERY ,
114+ BEGIN_LOAD_QUERY ( 17 ) ,
108115 /**
109116 * Used for LOAD DATA INFILE statements as of MySQL 5.0.
110117 */
111- EXECUTE_LOAD_QUERY ,
118+ EXECUTE_LOAD_QUERY ( 18 ) ,
112119 /**
113120 * This event precedes each row operation event. It maps a table definition to a number, where the table definition
114121 * consists of database and table names and column definitions. The purpose of this event is to enable replication
@@ -117,82 +124,145 @@ public enum EventType {
117124 * of TABLE_MAP events: one per table used by events in the sequence.
118125 * Used in case of RBR.
119126 */
120- TABLE_MAP ,
127+ TABLE_MAP ( 19 ) ,
121128 /**
122129 * Describes inserted rows (within a single table).
123130 * Used in case of RBR (5.1.0 - 5.1.15).
124131 */
125- PRE_GA_WRITE_ROWS ,
132+ PRE_GA_WRITE_ROWS ( 20 ) ,
126133 /**
127134 * Describes updated rows (within a single table).
128135 * Used in case of RBR (5.1.0 - 5.1.15).
129136 */
130- PRE_GA_UPDATE_ROWS ,
137+ PRE_GA_UPDATE_ROWS ( 21 ) ,
131138 /**
132139 * Describes deleted rows (within a single table).
133140 * Used in case of RBR (5.1.0 - 5.1.15).
134141 */
135- PRE_GA_DELETE_ROWS ,
142+ PRE_GA_DELETE_ROWS ( 22 ) ,
136143 /**
137144 * Describes inserted rows (within a single table).
138145 * Used in case of RBR (5.1.16 - mysql-trunk).
139146 */
140- WRITE_ROWS ,
147+ WRITE_ROWS_V1 ( 23 ) ,
141148 /**
142149 * Describes updated rows (within a single table).
143150 * Used in case of RBR (5.1.16 - mysql-trunk).
144151 */
145- UPDATE_ROWS ,
152+ UPDATE_ROWS_V1 ( 24 ) ,
146153 /**
147154 * Describes deleted rows (within a single table).
148155 * Used in case of RBR (5.1.16 - mysql-trunk).
149156 */
150- DELETE_ROWS ,
157+ DELETE_ROWS_V1 ( 25 ) ,
151158 /**
152159 * Used to log an out of the ordinary event that occurred on the master. It notifies the slave that something
153160 * happened on the master that might cause data to be in an inconsistent state.
154161 */
155- INCIDENT ,
162+ INCIDENT ( 26 ) ,
156163 /**
157164 * Sent by a master to a slave to let the slave know that the master is still alive. Not written to a binary log.
158165 */
159- HEARTBEAT ,
166+ HEARTBEAT_LOG ( 27 ) ,
160167 /**
161168 * In some situations, it is necessary to send over ignorable data to the slave: data that a slave can handle in
162169 * case there is code for handling it, but which can be ignored if it is not recognized.
163170 */
164- IGNORABLE ,
171+ IGNORABLE_LOG ( 28 ) ,
165172 /**
166173 * Introduced to record the original query for rows events in RBR.
167174 */
168- ROWS_QUERY ,
175+ ROWS_QUERY_LOG ( 29 ) ,
169176 /**
170177 * Describes inserted rows (within a single table).
171178 * Used in case of RBR (5.1.18+).
172179 */
173- EXT_WRITE_ROWS ,
180+ WRITE_ROWS ( 30 ) ,
174181 /**
175182 * Describes updated rows (within a single table).
176183 * Used in case of RBR (5.1.18+).
177184 */
178- EXT_UPDATE_ROWS ,
185+ UPDATE_ROWS ( 31 ) ,
179186 /**
180187 * Describes deleted rows (within a single table).
181188 * Used in case of RBR (5.1.18+).
182189 */
183- EXT_DELETE_ROWS ,
190+ DELETE_ROWS (32 ),
191+
184192 /**
185193 * Global Transaction Identifier.
194+ *
195+ * MySQL 5.6 GTID events
196+ */
197+ GTID_LOG (33 ),
198+ ANONYMOUS_GTID_LOG (34 ),
199+ PREVIOUS_GTIDS_LOG (35 ),
200+
201+ /**
202+ * MySQL 5.7 Events
186203 */
187- GTID ,
188- ANONYMOUS_GTID ,
189- PREVIOUS_GTIDS ,
190- TRANSACTION_CONTEXT ,
191- VIEW_CHANGE ,
204+ TRANSACTION_CONTEXT (36 ),
205+ VIEW_CHANGE (37 ),
192206 /**
193207 * Prepared XA transaction terminal event similar to XID except that it is specific to XA transaction.
194208 */
195- XA_PREPARE ;
209+ XA_PREPARE_LOG (38 ),
210+
211+ /**
212+ * New Maria event numbers start from here
213+ */
214+ MARIA_ANNOTATE_ROWS (160 ),
215+ /**
216+ * Binlog checkpoint event. Used for XA crash recovery on the master, not used
217+ * in replication.
218+ * A binlog checkpoint event specifies a binlog file such that XA crash
219+ * recovery can start from that file - and it is guaranteed to find all XIDs
220+ * that are prepared in storage engines but not yet committed.
221+ */
222+ MARIA_BINLOG_CHECKPOINT (161 ),
223+ /**
224+ * Gtid event. For global transaction ID, used to start a new event group,
225+ * instead of the old BEGIN query event, and also to mark stand-alone
226+ * events.
227+ */
228+ MARIA_GTID (162 ),
229+ /**
230+ * Gtid list event. Logged at the start of every binlog, to record the
231+ * current replication state. This consists of the last GTID seen for
232+ * each replication domain.
233+ */
234+ MARIA_GTID_LIST (163 ),
235+
236+ MARIA_START_ENCRYPTION (164 ),
237+
238+ /**
239+ * Compressed binlog event.
240+
241+ * Note that the order between WRITE/UPDATE/DELETE events is significant;
242+ * this is so that we can convert from the compressed to the uncompressed
243+ * event type with (type-WRITE_ROWS_COMPRESSED_EVENT + WRITE_ROWS_EVENT)
244+ * and similar for _V1.
245+ */
246+ MARIA_QUERY_COMPRESSED (165 ),
247+ MARIA_WRITE_ROWS_COMPRESSED_V1 (166 ),
248+ MARIA_UPDATE_ROWS_COMPRESSED_V1 (167 ),
249+ MARIA_DELETE_ROWS_COMPRESSED_V1 (168 ),
250+ MARIA_WRITE_ROWS_COMPRESSED (169 ),
251+ MARIA_UPDATE_ROWS_COMPRESSED (170 ),
252+ MARIA_DELETE_ROWS_COMPRESSED (171 );
253+
254+ private int index ;
255+
256+ EventType (int index ) {
257+ this .index = index ;
258+ }
259+
260+ public static final Map <Integer , EventType > EVENT_TYPES = new HashMap <Integer , EventType >();
261+ static {
262+ for (EventType eventType : EventType .values ()) {
263+ EVENT_TYPES .put (eventType .index , eventType );
264+ }
265+ }
196266
197267 public static boolean isRowMutation (EventType eventType ) {
198268 return EventType .isWrite (eventType ) ||
@@ -202,20 +272,27 @@ public static boolean isRowMutation(EventType eventType) {
202272
203273 public static boolean isWrite (EventType eventType ) {
204274 return eventType == PRE_GA_WRITE_ROWS ||
275+ eventType == WRITE_ROWS_V1 ||
205276 eventType == WRITE_ROWS ||
206- eventType == EXT_WRITE_ROWS ;
277+ eventType == MARIA_WRITE_ROWS_COMPRESSED_V1 ||
278+ eventType == MARIA_WRITE_ROWS_COMPRESSED ;
279+
207280 }
208281
209282 public static boolean isUpdate (EventType eventType ) {
210283 return eventType == PRE_GA_UPDATE_ROWS ||
284+ eventType == UPDATE_ROWS_V1 ||
211285 eventType == UPDATE_ROWS ||
212- eventType == EXT_UPDATE_ROWS ;
286+ eventType == MARIA_UPDATE_ROWS_COMPRESSED_V1 ||
287+ eventType == MARIA_UPDATE_ROWS_COMPRESSED ;
213288 }
214289
215290 public static boolean isDelete (EventType eventType ) {
216291 return eventType == PRE_GA_DELETE_ROWS ||
292+ eventType == DELETE_ROWS_V1 ||
217293 eventType == DELETE_ROWS ||
218- eventType == EXT_DELETE_ROWS ;
294+ eventType == MARIA_DELETE_ROWS_COMPRESSED_V1 ||
295+ eventType == MARIA_DELETE_ROWS_COMPRESSED ;
219296 }
220297
221298}
0 commit comments