15
15
*/
16
16
package com .github .shyiko .mysql .binlog .event ;
17
17
18
+ import java .util .HashMap ;
19
+ import java .util .Map ;
20
+
18
21
/**
19
22
* @see <a href="https://dev.mysql.com/doc/internals/en/event-meanings.html">Event Meanings</a> for the original
20
23
* documentation.
@@ -25,90 +28,94 @@ public enum EventType {
25
28
/**
26
29
* Events of this event type should never occur. Not written to a binary log.
27
30
*/
28
- UNKNOWN ,
31
+ UNKNOWN ( 0 ) ,
29
32
/**
30
33
* A descriptor event that is written to the beginning of the each binary log file. (In MySQL 4.0 and 4.1,
31
34
* this event is written only to the first binary log file that the server creates after startup.) This event is
32
35
* used in MySQL 3.23 through 4.1 and superseded in MySQL 5.0 by {@link #FORMAT_DESCRIPTION}.
33
36
*/
34
- START_V3 ,
37
+ START_V3 ( 1 ) ,
35
38
/**
36
39
* Written when an updating statement is done.
37
40
*/
38
- QUERY ,
41
+ QUERY ( 2 ) ,
39
42
/**
40
43
* Written when mysqld stops.
41
44
*/
42
- STOP ,
45
+ STOP ( 3 ) ,
43
46
/**
44
47
* Written when mysqld switches to a new binary log file. This occurs when someone issues a FLUSH LOGS statement or
45
48
* the current binary log file becomes larger than max_binlog_size.
49
+ *
50
+ * See https://dev.mysql.com/doc/internals/en/rotate-event.html
46
51
*/
47
- ROTATE ,
52
+ ROTATE ( 4 ) ,
48
53
/**
49
54
* Written every time a statement uses an AUTO_INCREMENT column or the LAST_INSERT_ID() function; precedes other
50
55
* events for the statement. This is written only before a {@link #QUERY} and is not used in case of RBR.
51
56
*/
52
- INTVAR ,
57
+ INTVAR ( 5 ) ,
53
58
/**
54
59
* Used for LOAD DATA INFILE statements in MySQL 3.23.
55
60
*/
56
- LOAD ,
61
+ LOAD ( 6 ) ,
57
62
/**
58
63
* Not used.
59
64
*/
60
- SLAVE ,
65
+ SLAVE ( 7 ) ,
61
66
/**
62
67
* Used for LOAD DATA INFILE statements in MySQL 4.0 and 4.1.
63
68
*/
64
- CREATE_FILE ,
69
+ CREATE_FILE ( 8 ) ,
65
70
/**
66
71
* Used for LOAD DATA INFILE statements as of MySQL 4.0.
67
72
*/
68
- APPEND_BLOCK ,
73
+ APPEND_BLOCK ( 9 ) ,
69
74
/**
70
75
* Used for LOAD DATA INFILE statements in 4.0 and 4.1.
71
76
*/
72
- EXEC_LOAD ,
77
+ EXEC_LOAD ( 10 ) ,
73
78
/**
74
79
* Used for LOAD DATA INFILE statements as of MySQL 4.0.
75
80
*/
76
- DELETE_FILE ,
81
+ DELETE_FILE ( 11 ) ,
77
82
/**
78
83
* Used for LOAD DATA INFILE statements in MySQL 4.0 and 4.1.
79
84
*/
80
- NEW_LOAD ,
85
+ NEW_LOAD ( 12 ) ,
81
86
/**
82
87
* Written every time a statement uses the RAND() function; precedes other events for the statement. Indicates the
83
88
* seed values to use for generating a random number with RAND() in the next statement. This is written only
84
89
* before a {@link #QUERY} and is not used in case of RBR.
85
90
*/
86
- RAND ,
91
+ RAND ( 13 ) ,
87
92
/**
88
93
* Written every time a statement uses a user variable; precedes other events for the statement. Indicates the
89
94
* value to use for the user variable in the next statement. This is written only before a {@link #QUERY} and
90
95
* is not used in case of RBR.
91
96
*/
92
- USER_VAR ,
97
+ USER_VAR ( 14 ) ,
93
98
/**
94
99
* A descriptor event that is written to the beginning of the each binary log file.
95
100
* 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
96
103
*/
97
- FORMAT_DESCRIPTION ,
104
+ FORMAT_DESCRIPTION ( 15 ) ,
98
105
/**
99
106
* Generated for a commit of a transaction that modifies one or more tables of an XA-capable storage engine.
100
107
* Normal transactions are implemented by sending a {@link #QUERY} containing a BEGIN statement and a {@link #QUERY}
101
108
* containing a COMMIT statement (or a ROLLBACK statement if the transaction is rolled back).
102
109
*/
103
- XID ,
110
+ XID ( 16 ) ,
104
111
/**
105
112
* Used for LOAD DATA INFILE statements as of MySQL 5.0.
106
113
*/
107
- BEGIN_LOAD_QUERY ,
114
+ BEGIN_LOAD_QUERY ( 17 ) ,
108
115
/**
109
116
* Used for LOAD DATA INFILE statements as of MySQL 5.0.
110
117
*/
111
- EXECUTE_LOAD_QUERY ,
118
+ EXECUTE_LOAD_QUERY ( 18 ) ,
112
119
/**
113
120
* This event precedes each row operation event. It maps a table definition to a number, where the table definition
114
121
* 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 {
117
124
* of TABLE_MAP events: one per table used by events in the sequence.
118
125
* Used in case of RBR.
119
126
*/
120
- TABLE_MAP ,
127
+ TABLE_MAP ( 19 ) ,
121
128
/**
122
129
* Describes inserted rows (within a single table).
123
130
* Used in case of RBR (5.1.0 - 5.1.15).
124
131
*/
125
- PRE_GA_WRITE_ROWS ,
132
+ PRE_GA_WRITE_ROWS ( 20 ) ,
126
133
/**
127
134
* Describes updated rows (within a single table).
128
135
* Used in case of RBR (5.1.0 - 5.1.15).
129
136
*/
130
- PRE_GA_UPDATE_ROWS ,
137
+ PRE_GA_UPDATE_ROWS ( 21 ) ,
131
138
/**
132
139
* Describes deleted rows (within a single table).
133
140
* Used in case of RBR (5.1.0 - 5.1.15).
134
141
*/
135
- PRE_GA_DELETE_ROWS ,
142
+ PRE_GA_DELETE_ROWS ( 22 ) ,
136
143
/**
137
144
* Describes inserted rows (within a single table).
138
145
* Used in case of RBR (5.1.16 - mysql-trunk).
139
146
*/
140
- WRITE_ROWS ,
147
+ WRITE_ROWS_V1 ( 23 ) ,
141
148
/**
142
149
* Describes updated rows (within a single table).
143
150
* Used in case of RBR (5.1.16 - mysql-trunk).
144
151
*/
145
- UPDATE_ROWS ,
152
+ UPDATE_ROWS_V1 ( 24 ) ,
146
153
/**
147
154
* Describes deleted rows (within a single table).
148
155
* Used in case of RBR (5.1.16 - mysql-trunk).
149
156
*/
150
- DELETE_ROWS ,
157
+ DELETE_ROWS_V1 ( 25 ) ,
151
158
/**
152
159
* Used to log an out of the ordinary event that occurred on the master. It notifies the slave that something
153
160
* happened on the master that might cause data to be in an inconsistent state.
154
161
*/
155
- INCIDENT ,
162
+ INCIDENT ( 26 ) ,
156
163
/**
157
164
* Sent by a master to a slave to let the slave know that the master is still alive. Not written to a binary log.
158
165
*/
159
- HEARTBEAT ,
166
+ HEARTBEAT_LOG ( 27 ) ,
160
167
/**
161
168
* In some situations, it is necessary to send over ignorable data to the slave: data that a slave can handle in
162
169
* case there is code for handling it, but which can be ignored if it is not recognized.
163
170
*/
164
- IGNORABLE ,
171
+ IGNORABLE_LOG ( 28 ) ,
165
172
/**
166
173
* Introduced to record the original query for rows events in RBR.
167
174
*/
168
- ROWS_QUERY ,
175
+ ROWS_QUERY_LOG ( 29 ) ,
169
176
/**
170
177
* Describes inserted rows (within a single table).
171
178
* Used in case of RBR (5.1.18+).
172
179
*/
173
- EXT_WRITE_ROWS ,
180
+ WRITE_ROWS ( 30 ) ,
174
181
/**
175
182
* Describes updated rows (within a single table).
176
183
* Used in case of RBR (5.1.18+).
177
184
*/
178
- EXT_UPDATE_ROWS ,
185
+ UPDATE_ROWS ( 31 ) ,
179
186
/**
180
187
* Describes deleted rows (within a single table).
181
188
* Used in case of RBR (5.1.18+).
182
189
*/
183
- EXT_DELETE_ROWS ,
190
+ DELETE_ROWS (32 ),
191
+
184
192
/**
185
193
* 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
186
203
*/
187
- GTID ,
188
- ANONYMOUS_GTID ,
189
- PREVIOUS_GTIDS ,
190
- TRANSACTION_CONTEXT ,
191
- VIEW_CHANGE ,
204
+ TRANSACTION_CONTEXT (36 ),
205
+ VIEW_CHANGE (37 ),
192
206
/**
193
207
* Prepared XA transaction terminal event similar to XID except that it is specific to XA transaction.
194
208
*/
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
+ }
196
266
197
267
public static boolean isRowMutation (EventType eventType ) {
198
268
return EventType .isWrite (eventType ) ||
@@ -202,20 +272,27 @@ public static boolean isRowMutation(EventType eventType) {
202
272
203
273
public static boolean isWrite (EventType eventType ) {
204
274
return eventType == PRE_GA_WRITE_ROWS ||
275
+ eventType == WRITE_ROWS_V1 ||
205
276
eventType == WRITE_ROWS ||
206
- eventType == EXT_WRITE_ROWS ;
277
+ eventType == MARIA_WRITE_ROWS_COMPRESSED_V1 ||
278
+ eventType == MARIA_WRITE_ROWS_COMPRESSED ;
279
+
207
280
}
208
281
209
282
public static boolean isUpdate (EventType eventType ) {
210
283
return eventType == PRE_GA_UPDATE_ROWS ||
284
+ eventType == UPDATE_ROWS_V1 ||
211
285
eventType == UPDATE_ROWS ||
212
- eventType == EXT_UPDATE_ROWS ;
286
+ eventType == MARIA_UPDATE_ROWS_COMPRESSED_V1 ||
287
+ eventType == MARIA_UPDATE_ROWS_COMPRESSED ;
213
288
}
214
289
215
290
public static boolean isDelete (EventType eventType ) {
216
291
return eventType == PRE_GA_DELETE_ROWS ||
292
+ eventType == DELETE_ROWS_V1 ||
217
293
eventType == DELETE_ROWS ||
218
- eventType == EXT_DELETE_ROWS ;
294
+ eventType == MARIA_DELETE_ROWS_COMPRESSED_V1 ||
295
+ eventType == MARIA_DELETE_ROWS_COMPRESSED ;
219
296
}
220
297
221
298
}
0 commit comments