forked from vozbu/libslave
-
Notifications
You must be signed in to change notification settings - Fork 1
/
slave_log_event.h
231 lines (154 loc) · 5.11 KB
/
slave_log_event.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/* Copyright 2011 ZAO "Begun".
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SLAVE_SLAVE_LOG_EVENT_H
#define __SLAVE_SLAVE_LOG_EVENT_H
#include "relayloginfo.h"
namespace slave {
/*
*
*/
enum Log_event_type
{
UNKNOWN_EVENT= 0,
START_EVENT_V3= 1,
QUERY_EVENT= 2,
STOP_EVENT= 3,
ROTATE_EVENT= 4,
INTVAR_EVENT= 5,
LOAD_EVENT= 6,
SLAVE_EVENT= 7,
CREATE_FILE_EVENT= 8,
APPEND_BLOCK_EVENT= 9,
EXEC_LOAD_EVENT= 10,
DELETE_FILE_EVENT= 11,
NEW_LOAD_EVENT= 12,
RAND_EVENT= 13,
USER_VAR_EVENT= 14,
FORMAT_DESCRIPTION_EVENT= 15,
XID_EVENT= 16,
BEGIN_LOAD_QUERY_EVENT= 17,
EXECUTE_LOAD_QUERY_EVENT= 18,
TABLE_MAP_EVENT = 19,
PRE_GA_WRITE_ROWS_EVENT = 20,
PRE_GA_UPDATE_ROWS_EVENT = 21,
PRE_GA_DELETE_ROWS_EVENT = 22,
WRITE_ROWS_EVENT_V1 = 23,
UPDATE_ROWS_EVENT_V1 = 24,
DELETE_ROWS_EVENT_V1 = 25,
INCIDENT_EVENT = 26,
HEARTBEAT_LOG_EVENT= 27,
// 5.6 new events
IGNORABLE_LOG_EVENT = 28,
ROWS_QUERY_LOG_EVENT = 29,
WRITE_ROWS_EVENT = 30,
UPDATE_ROWS_EVENT = 31,
DELETE_ROWS_EVENT = 32,
GTID_LOG_EVENT = 33,
ANONYMOUS_GTID_LOG_EVENT = 34,
PREVIOUS_GTIDS_LOG_EVENT = 35,
// 5.7 new events
TRANSACTION_CONTEXT_EVENT= 36,
VIEW_CHANGE_EVENT= 37,
XA_PREPARE_LOG_EVENT= 38,
ENUM_END_EVENT
};
enum Temporal_type
{
MYSQL_TYPE_TIMESTAMP = 7,
MYSQL_TYPE_TIME = 11,
MYSQL_TYPE_DATETIME = 12,
MYSQL_TYPE_TIMESTAMP2 = 17,
MYSQL_TYPE_DATETIME2 = 18,
MYSQL_TYPE_TIME2 = 19
};
#define LOG_EVENT_TYPES (ENUM_END_EVENT-1)
#define EVENT_TYPE_OFFSET 4
#define SERVER_ID_OFFSET 5
#define EVENT_LEN_OFFSET 9
#define LOG_POS_OFFSET 13
#define LOG_EVENT_HEADER_LEN 19
#define ROTATE_HEADER_LEN 8
#define R_POS_OFFSET 0
#define QUERY_HEADER_MINIMAL_LEN (4 + 4 + 1 + 2)
#define QUERY_HEADER_LEN (QUERY_HEADER_MINIMAL_LEN + 2)
#define Q_STATUS_VARS_LEN_OFFSET 11
#define Q_DB_LEN_OFFSET 8
#define TABLE_MAP_HEADER_LEN 8
#define TM_MAPID_OFFSET 0
#define ROWS_HEADER_LEN_V1 8
#define RW_MAPID_OFFSET 0
#define ROWS_HEADER_LEN 10
#define ENCODED_FLAG_LENGTH 1
#define ENCODED_SID_LENGTH 16
#define ENCODED_GNO_LENGTH 8
#define GTID_EVENT_LEN (ENCODED_FLAG_LENGTH + ENCODED_SID_LENGTH + ENCODED_GNO_LENGTH)
#define LOG_EVENT_MINIMAL_HEADER_LEN 19
#define ST_BINLOG_VER_LEN 2
#define ST_BINLOG_VER_OFFSET 0
#define ST_SERVER_VER_LEN 50
#define ST_SERVER_VER_OFFSET (ST_BINLOG_VER_OFFSET + 2)
#define ST_CREATED_OFFSET (ST_SERVER_VER_OFFSET + ST_SERVER_VER_LEN)
#define ST_COMMON_HEADER_LEN_OFFSET (ST_CREATED_OFFSET + 4)
#define START_V3_HEADER_LEN (2 + ST_SERVER_VER_LEN + 4)
#define BINLOG_CHECKSUM_LEN 4
#define BINLOG_CHECKSUM_ALG_DESC_LEN 1
//-----------------------------------------------------------------------------------------
struct Basic_event_info {
slave::Log_event_type type;
size_t log_pos;
time_t when;
unsigned int server_id;
const char* buf;
unsigned int event_len;
Basic_event_info(const char* _buf, unsigned int _event_len);
};
struct Rotate_event_info {
unsigned int ident_len;
std::string new_log_ident;
size_t pos;
Rotate_event_info(const char* buf, unsigned int event_len);
};
struct Query_event_info {
std::string db_name;
std::string query;
Query_event_info(const char* buf, unsigned int event_len);
};
struct Table_map_event_info {
unsigned long m_table_id;
std::string m_tblnam;
std::string m_dbnam;
std::vector<unsigned char> m_cols_types;
Table_map_event_info(const char* buf, unsigned int event_len);
};
struct Row_event_info {
unsigned long m_width;
unsigned long m_table_id;
std::vector<unsigned char> m_cols;
std::vector<unsigned char> m_cols_ai;
unsigned char* m_rows_buf;
unsigned char* m_rows_end;
bool has_after_image;
Row_event_info(const char* buf, unsigned int event_len, bool do_update, bool master_ge_56);
};
struct Gtid_event_info
{
std::string m_sid;
int64_t m_gno;
Gtid_event_info(const char* buf, unsigned int event_len);
};
bool check_log_event(const char* buf, unsigned int event_len, Basic_event_info& info, EventStatIface* event_stat, bool master_ge_56, MasterInfo& master_info);
void apply_row_event(slave::RelayLogInfo& rli, const Basic_event_info& bei, const Row_event_info& roi, ExtStateIface &ext_state, EventStatIface* event_stat);
//------------------------------------------------------------------------------------------
}; //namespace
#endif