-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathslave_log_event.h
186 lines (118 loc) · 4.01 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
/* 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 = 23,
UPDATE_ROWS_EVENT = 24,
DELETE_ROWS_EVENT = 25,
INCIDENT_EVENT = 26,
ENUM_END_EVENT
};
#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 8
#define RW_MAPID_OFFSET 0
#define ROWS_HEADER_LEN 8
#define LOG_EVENT_MINIMAL_HEADER_LEN 19
#define ST_SERVER_VER_LEN 50
#define ST_SERVER_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 FORMAT_DESCRIPTION_HEADER_LEN (START_V3_HEADER_LEN + 1 + LOG_EVENT_TYPES)
//-----------------------------------------------------------------------------------------
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() : type(UNKNOWN_EVENT), log_pos(0), when(0), server_id(0), buf(NULL), event_len(0)
{}
void parse(const char* b, unsigned int el);
};
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 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;
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 read_log_event(const char* buf, unsigned int event_len, Basic_event_info& info);
void apply_row_event(slave::RelayLogInfo& rli, const Basic_event_info& bei, const Row_event_info& roi, ExtStateIface &ext_state);
//------------------------------------------------------------------------------------------
}; //namespace
#endif