390.1.2
by Monty Taylor
Fixed copyright headers in drizzled/ |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 Sun Microsystems
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
1
by brian
clean slate |
19 |
|
20 |
/**
|
|
21 |
@addtogroup Replication
|
|
22 |
@{
|
|
23 |
||
24 |
@file
|
|
25 |
|
|
26 |
@brief Binary log event definitions. This includes generic code
|
|
27 |
common to all types of log events, as well as specific code for each
|
|
28 |
type of log event.
|
|
29 |
*/
|
|
30 |
||
31 |
||
490
by Brian Aker
More effort around master.info (and relay.info) |
32 |
#ifndef DRIZZLED_LOG_EVENT_H
|
33 |
#define DRIZZLED_LOG_EVENT_H
|
|
1
by brian
clean slate |
34 |
|
35 |
||
575.4.6
by Monty Taylor
Removed my_getwd. |
36 |
#include <mysys/my_bitmap.h> |
37 |
#include <drizzled/replication/constants.h> |
|
38 |
#include <drizzled/replication/record.h> |
|
39 |
#include <drizzled/replication/reporting.h> |
|
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
40 |
#include <drizzled/session.h> |
490
by Brian Aker
More effort around master.info (and relay.info) |
41 |
#include <string> |
1
by brian
clean slate |
42 |
|
243.1.5
by Jay Pipes
* Pulled the remainder of the log and parse stuff out into |
43 |
#include <drizzled/sql_string.h> /* append_query_string() needs String declaration */ |
44 |
||
1
by brian
clean slate |
45 |
/**
|
46 |
Either assert or return an error.
|
|
47 |
||
48 |
In debug build, the condition will be checked, but in non-debug
|
|
49 |
builds, the error code given will be returned instead.
|
|
50 |
||
51 |
@param COND Condition to check
|
|
52 |
@param ERRNO Error number to return in non-debug builds
|
|
53 |
*/
|
|
51.1.31
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
54 |
#define ASSERT_OR_RETURN_ERROR(COND, ERRNO) \
|
55 |
assert(COND)
|
|
1
by brian
clean slate |
56 |
|
57 |
#define LOG_READ_EOF -1
|
|
58 |
#define LOG_READ_BOGUS -2
|
|
59 |
#define LOG_READ_IO -3
|
|
60 |
#define LOG_READ_MEM -5
|
|
61 |
#define LOG_READ_TRUNC -6
|
|
62 |
#define LOG_READ_TOO_LARGE -7
|
|
63 |
||
64 |
#define LOG_EVENT_OFFSET 4
|
|
65 |
||
66 |
/*
|
|
67 |
3 is MySQL 4.x; 4 is MySQL 5.0.0.
|
|
68 |
Compared to version 3, version 4 has:
|
|
69 |
- a different Start_log_event, which includes info about the binary log
|
|
70 |
(sizes of headers); this info is included for better compatibility if the
|
|
71 |
master's MySQL version is different from the slave's.
|
|
72 |
- all events have a unique ID (the triplet (server_id, timestamp at server
|
|
73 |
start, other) to be sure an event is not executed more than once in a
|
|
74 |
multimaster setup, example:
|
|
75 |
M1
|
|
76 |
/ \
|
|
77 |
v v
|
|
78 |
M2 M3
|
|
79 |
\ /
|
|
80 |
v v
|
|
81 |
S
|
|
82 |
if a query is run on M1, it will arrive twice on S, so we need that S
|
|
83 |
remembers the last unique ID it has processed, to compare and know if the
|
|
84 |
event should be skipped or not. Example of ID: we already have the server id
|
|
85 |
(4 bytes), plus:
|
|
86 |
timestamp_when_the_master_started (4 bytes), a counter (a sequence number
|
|
87 |
which increments every time we write an event to the binlog) (3 bytes).
|
|
88 |
Q: how do we handle when the counter is overflowed and restarts from 0 ?
|
|
89 |
||
90 |
- Query and Load (Create or Execute) events may have a more precise
|
|
91 |
timestamp (with microseconds), number of matched/affected/warnings rows
|
|
92 |
and fields of session variables: SQL_MODE,
|
|
93 |
FOREIGN_KEY_CHECKS, UNIQUE_CHECKS, SQL_AUTO_IS_NULL, the collations and
|
|
94 |
charsets, the PASSWORD() version (old/new/...).
|
|
95 |
*/
|
|
96 |
#define BINLOG_VERSION 4
|
|
97 |
||
98 |
/*
|
|
99 |
We could have used SERVER_VERSION_LENGTH, but this introduces an
|
|
100 |
obscure dependency - if somebody decided to change SERVER_VERSION_LENGTH
|
|
101 |
this would break the replication protocol
|
|
102 |
*/
|
|
103 |
#define ST_SERVER_VER_LEN 50
|
|
104 |
||
105 |
/*
|
|
106 |
These are flags and structs to handle all the LOAD DATA INFILE options (LINES
|
|
107 |
TERMINATED etc).
|
|
108 |
*/
|
|
109 |
||
110 |
/*
|
|
111 |
These are flags and structs to handle all the LOAD DATA INFILE options (LINES
|
|
112 |
TERMINATED etc).
|
|
113 |
DUMPFILE_FLAG is probably useless (DUMPFILE is a clause of SELECT, not of LOAD
|
|
114 |
DATA).
|
|
115 |
*/
|
|
116 |
#define DUMPFILE_FLAG 0x1
|
|
117 |
#define OPT_ENCLOSED_FLAG 0x2
|
|
118 |
#define REPLACE_FLAG 0x4
|
|
119 |
#define IGNORE_FLAG 0x8
|
|
120 |
||
121 |
#define FIELD_TERM_EMPTY 0x1
|
|
122 |
#define ENCLOSED_EMPTY 0x2
|
|
123 |
#define LINE_TERM_EMPTY 0x4
|
|
124 |
#define LINE_START_EMPTY 0x8
|
|
125 |
#define ESCAPED_EMPTY 0x10
|
|
126 |
||
127 |
#define NUM_LOAD_DELIM_STRS 5
|
|
128 |
||
129 |
/*****************************************************************************
|
|
130 |
||
131 |
sql_ex_info struct
|
|
132 |
||
133 |
****************************************************************************/
|
|
134 |
struct sql_ex_info |
|
135 |
{
|
|
136 |
sql_ex_info() {} /* Remove gcc warning */ |
|
137 |
const char* field_term; |
|
138 |
const char* enclosed; |
|
139 |
const char* line_term; |
|
140 |
const char* line_start; |
|
141 |
const char* escaped; |
|
142 |
int cached_new_format; |
|
206
by Brian Aker
Removed final uint dead types. |
143 |
uint8_t field_term_len,enclosed_len,line_term_len,line_start_len, escaped_len; |
1
by brian
clean slate |
144 |
char opt_flags; |
145 |
char empty_flags; |
|
146 |
||
496
by Brian Aker
Removed dead code around SHOW commands (I_S exist for collations/charsets) |
147 |
/* store in new format even if old is possible */
|
1
by brian
clean slate |
148 |
void force_new_format() { cached_new_format = 1;} |
149 |
int data_size() |
|
150 |
{
|
|
151 |
return (new_format() ? |
|
152 |
field_term_len + enclosed_len + line_term_len + |
|
153 |
line_start_len + escaped_len + 6 : 7); |
|
154 |
}
|
|
155 |
bool write_data(IO_CACHE* file); |
|
156 |
const char* init(const char* buf, const char* buf_end, bool use_new_format); |
|
157 |
bool new_format() |
|
158 |
{
|
|
159 |
return ((cached_new_format != -1) ? cached_new_format : |
|
160 |
(cached_new_format=(field_term_len > 1 || |
|
161 |
enclosed_len > 1 || |
|
162 |
line_term_len > 1 || line_start_len > 1 || |
|
163 |
escaped_len > 1))); |
|
164 |
}
|
|
165 |
};
|
|
166 |
||
167 |
/*****************************************************************************
|
|
168 |
||
169 |
MySQL Binary Log
|
|
170 |
||
171 |
This log consists of events. Each event has a fixed-length header,
|
|
172 |
possibly followed by a variable length data body.
|
|
173 |
||
174 |
The data body consists of an optional fixed length segment (post-header)
|
|
175 |
and an optional variable length segment.
|
|
176 |
||
177 |
See the #defines below for the format specifics.
|
|
178 |
||
179 |
The events which really update data are Query_log_event,
|
|
180 |
Execute_load_query_log_event and old Load_log_event and
|
|
181 |
Execute_load_log_event events (Execute_load_query is used together with
|
|
182 |
Begin_load_query and Append_block events to replicate LOAD DATA INFILE.
|
|
183 |
Create_file/Append_block/Execute_load (which includes Load_log_event)
|
|
184 |
were used to replicate LOAD DATA before the 5.0.3).
|
|
185 |
||
186 |
****************************************************************************/
|
|
187 |
||
188 |
#define LOG_EVENT_HEADER_LEN 19 /* the fixed header length */ |
|
189 |
#define OLD_HEADER_LEN 13 /* the fixed header length in 3.23 */ |
|
190 |
/*
|
|
191 |
Fixed header length, where 4.x and 5.0 agree. That is, 5.0 may have a longer
|
|
192 |
header (it will for sure when we have the unique event's ID), but at least
|
|
193 |
the first 19 bytes are the same in 4.x and 5.0. So when we have the unique
|
|
194 |
event's ID, LOG_EVENT_HEADER_LEN will be something like 26, but
|
|
195 |
LOG_EVENT_MINIMAL_HEADER_LEN will remain 19.
|
|
196 |
*/
|
|
287.3.8
by Monty Taylor
Oy. Replaced max and min macros with std::max and std::min so that we get |
197 |
#define LOG_EVENT_MINIMAL_HEADER_LEN (uint8_t)19
|
1
by brian
clean slate |
198 |
|
199 |
/* event-specific post-header sizes */
|
|
200 |
// where 3.23, 4.x and 5.0 agree
|
|
201 |
#define QUERY_HEADER_MINIMAL_LEN (4 + 4 + 1 + 2)
|
|
202 |
// where 5.0 differs: 2 for len of N-bytes vars.
|
|
203 |
#define QUERY_HEADER_LEN (QUERY_HEADER_MINIMAL_LEN + 2)
|
|
204 |
#define LOAD_HEADER_LEN (4 + 4 + 4 + 1 +1 + 4)
|
|
205 |
#define START_V3_HEADER_LEN (2 + ST_SERVER_VER_LEN + 4)
|
|
206 |
#define ROTATE_HEADER_LEN 8 // this is FROZEN (the Rotate post-header is frozen) |
|
207 |
#define CREATE_FILE_HEADER_LEN 4
|
|
208 |
#define APPEND_BLOCK_HEADER_LEN 4
|
|
209 |
#define EXEC_LOAD_HEADER_LEN 4
|
|
210 |
#define DELETE_FILE_HEADER_LEN 4
|
|
211 |
#define FORMAT_DESCRIPTION_HEADER_LEN (START_V3_HEADER_LEN+1+LOG_EVENT_TYPES)
|
|
212 |
#define ROWS_HEADER_LEN 8
|
|
213 |
#define TABLE_MAP_HEADER_LEN 8
|
|
214 |
#define EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN (4 + 4 + 4 + 1)
|
|
215 |
#define EXECUTE_LOAD_QUERY_HEADER_LEN (QUERY_HEADER_LEN + EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN)
|
|
216 |
#define INCIDENT_HEADER_LEN 2
|
|
217 |
#define HEARTBEAT_HEADER_LEN 0
|
|
218 |
/*
|
|
219 |
Max number of possible extra bytes in a replication event compared to a
|
|
220 |
packet (i.e. a query) sent from client to master;
|
|
221 |
First, an auxiliary log_event status vars estimation:
|
|
222 |
*/
|
|
223 |
#define MAX_SIZE_LOG_EVENT_STATUS (4 /* flags2 */ + \ |
|
224 |
8 /* sql mode */ + \ |
|
225 |
1 + 1 + 255 /* catalog */ + \ |
|
226 |
4 /* autoinc */ + \ |
|
227 |
6 /* charset */ + \ |
|
228 |
MAX_TIME_ZONE_NAME_LENGTH)
|
|
229 |
#define MAX_LOG_EVENT_HEADER ( /* in order of Query_log_event::write */ \ |
|
230 |
LOG_EVENT_HEADER_LEN + /* write_header */ \ |
|
231 |
QUERY_HEADER_LEN + /* write_data */ \ |
|
232 |
EXECUTE_LOAD_QUERY_EXTRA_HEADER_LEN + /*write_post_header_for_derived */ \ |
|
233 |
MAX_SIZE_LOG_EVENT_STATUS + /* status */ \ |
|
234 |
NAME_LEN + 1)
|
|
235 |
||
236 |
/*
|
|
237 |
Event header offsets;
|
|
238 |
these point to places inside the fixed header.
|
|
239 |
*/
|
|
240 |
||
241 |
#define EVENT_TYPE_OFFSET 4
|
|
242 |
#define SERVER_ID_OFFSET 5
|
|
243 |
#define EVENT_LEN_OFFSET 9
|
|
244 |
#define LOG_POS_OFFSET 13
|
|
245 |
#define FLAGS_OFFSET 17
|
|
246 |
||
247 |
/* start event post-header (for v3 and v4) */
|
|
248 |
||
249 |
#define ST_BINLOG_VER_OFFSET 0
|
|
250 |
#define ST_SERVER_VER_OFFSET 2
|
|
251 |
#define ST_CREATED_OFFSET (ST_SERVER_VER_OFFSET + ST_SERVER_VER_LEN)
|
|
252 |
#define ST_COMMON_HEADER_LEN_OFFSET (ST_CREATED_OFFSET + 4)
|
|
253 |
||
254 |
/* slave event post-header (this event is never written) */
|
|
255 |
||
256 |
#define SL_MASTER_PORT_OFFSET 8
|
|
257 |
#define SL_MASTER_POS_OFFSET 0
|
|
258 |
#define SL_MASTER_HOST_OFFSET 10
|
|
259 |
||
260 |
/* query event post-header */
|
|
261 |
||
262 |
#define Q_THREAD_ID_OFFSET 0
|
|
263 |
#define Q_EXEC_TIME_OFFSET 4
|
|
264 |
#define Q_DB_LEN_OFFSET 8
|
|
265 |
#define Q_ERR_CODE_OFFSET 9
|
|
266 |
#define Q_STATUS_VARS_LEN_OFFSET 11
|
|
267 |
#define Q_DATA_OFFSET QUERY_HEADER_LEN
|
|
268 |
/* these are codes, not offsets; not more than 256 values (1 byte). */
|
|
269 |
#define Q_FLAGS2_CODE 0
|
|
270 |
||
271 |
#define Q_LC_TIME_NAMES_CODE 7
|
|
272 |
||
273 |
#define Q_CHARSET_DATABASE_CODE 8
|
|
274 |
/* Intvar event post-header */
|
|
275 |
||
276 |
#define I_TYPE_OFFSET 0
|
|
277 |
#define I_VAL_OFFSET 1
|
|
278 |
||
279 |
/* Rand event post-header */
|
|
280 |
||
281 |
#define RAND_SEED1_OFFSET 0
|
|
282 |
#define RAND_SEED2_OFFSET 8
|
|
283 |
||
284 |
/* User_var event post-header */
|
|
285 |
||
286 |
#define UV_VAL_LEN_SIZE 4
|
|
287 |
#define UV_VAL_IS_NULL 1
|
|
288 |
#define UV_VAL_TYPE_SIZE 1
|
|
289 |
#define UV_NAME_LEN_SIZE 4
|
|
290 |
#define UV_CHARSET_NUMBER_SIZE 4
|
|
291 |
||
292 |
/* Load event post-header */
|
|
293 |
||
294 |
#define L_THREAD_ID_OFFSET 0
|
|
295 |
#define L_EXEC_TIME_OFFSET 4
|
|
296 |
#define L_SKIP_LINES_OFFSET 8
|
|
297 |
#define L_TBL_LEN_OFFSET 12
|
|
298 |
#define L_DB_LEN_OFFSET 13
|
|
299 |
#define L_NUM_FIELDS_OFFSET 14
|
|
300 |
#define L_SQL_EX_OFFSET 18
|
|
301 |
#define L_DATA_OFFSET LOAD_HEADER_LEN
|
|
302 |
||
303 |
/* Rotate event post-header */
|
|
304 |
||
305 |
#define R_POS_OFFSET 0
|
|
306 |
#define R_IDENT_OFFSET 8
|
|
307 |
||
308 |
/* CF to DF handle LOAD DATA INFILE */
|
|
309 |
||
310 |
/* CF = "Create File" */
|
|
311 |
#define CF_FILE_ID_OFFSET 0
|
|
312 |
#define CF_DATA_OFFSET CREATE_FILE_HEADER_LEN
|
|
313 |
||
314 |
/* AB = "Append Block" */
|
|
315 |
#define AB_FILE_ID_OFFSET 0
|
|
316 |
#define AB_DATA_OFFSET APPEND_BLOCK_HEADER_LEN
|
|
317 |
||
318 |
/* EL = "Execute Load" */
|
|
319 |
#define EL_FILE_ID_OFFSET 0
|
|
320 |
||
321 |
/* DF = "Delete File" */
|
|
322 |
#define DF_FILE_ID_OFFSET 0
|
|
323 |
||
324 |
/* TM = "Table Map" */
|
|
325 |
#define TM_MAPID_OFFSET 0
|
|
326 |
#define TM_FLAGS_OFFSET 6
|
|
327 |
||
328 |
/* RW = "RoWs" */
|
|
329 |
#define RW_MAPID_OFFSET 0
|
|
330 |
#define RW_FLAGS_OFFSET 6
|
|
331 |
||
332 |
/* ELQ = "Execute Load Query" */
|
|
333 |
#define ELQ_FILE_ID_OFFSET QUERY_HEADER_LEN
|
|
334 |
#define ELQ_FN_POS_START_OFFSET ELQ_FILE_ID_OFFSET + 4
|
|
335 |
#define ELQ_FN_POS_END_OFFSET ELQ_FILE_ID_OFFSET + 8
|
|
336 |
#define ELQ_DUP_HANDLING_OFFSET ELQ_FILE_ID_OFFSET + 12
|
|
337 |
||
338 |
/* 4 bytes which all binlogs should begin with */
|
|
339 |
#define BINLOG_MAGIC "\xfe\x62\x69\x6e"
|
|
340 |
||
341 |
/*
|
|
342 |
This flag only makes sense for Format_description_log_event. It is set
|
|
343 |
when the event is written, and *reset* when a binlog file is
|
|
344 |
closed (yes, it's the only case when MySQL modifies already written
|
|
345 |
part of binlog). Thus it is a reliable indicator that binlog was
|
|
346 |
closed correctly. (Stop_log_event is not enough, there's always a
|
|
347 |
small chance that mysqld crashes in the middle of insert and end of
|
|
348 |
the binlog would look like a Stop_log_event).
|
|
349 |
||
350 |
This flag is used to detect a restart after a crash, and to provide
|
|
351 |
"unbreakable" binlog. The problem is that on a crash storage engines
|
|
352 |
rollback automatically, while binlog does not. To solve this we use this
|
|
353 |
flag and automatically append ROLLBACK to every non-closed binlog (append
|
|
354 |
virtually, on reading, file itself is not changed). If this flag is found,
|
|
355 |
mysqlbinlog simply prints "ROLLBACK" Replication master does not abort on
|
|
356 |
binlog corruption, but takes it as EOF, and replication slave forces a
|
|
357 |
rollback in this case.
|
|
358 |
||
359 |
Note, that old binlogs does not have this flag set, so we get a
|
|
360 |
a backward-compatible behaviour.
|
|
361 |
*/
|
|
362 |
||
363 |
#define LOG_EVENT_BINLOG_IN_USE_F 0x1
|
|
364 |
||
365 |
/**
|
|
366 |
@def LOG_EVENT_THREAD_SPECIFIC_F
|
|
367 |
||
327.1.5
by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h |
368 |
If the query depends on the thread (for example: TEMPORARY Table).
|
1
by brian
clean slate |
369 |
Currently this is used by mysqlbinlog to know it must print
|
370 |
SET @@PSEUDO_THREAD_ID=xx; before the query (it would not hurt to print it
|
|
371 |
for every query but this would be slow).
|
|
372 |
*/
|
|
373 |
#define LOG_EVENT_THREAD_SPECIFIC_F 0x4
|
|
374 |
||
375 |
/**
|
|
376 |
@def LOG_EVENT_SUPPRESS_USE_F
|
|
377 |
||
378 |
Suppress the generation of 'USE' statements before the actual
|
|
379 |
statement. This flag should be set for any events that does not need
|
|
380 |
the current database set to function correctly. Most notable cases
|
|
381 |
are 'CREATE DATABASE' and 'DROP DATABASE'.
|
|
382 |
||
383 |
This flags should only be used in exceptional circumstances, since
|
|
384 |
it introduce a significant change in behaviour regarding the
|
|
385 |
replication logic together with the flags --binlog-do-db and
|
|
386 |
--replicated-do-db.
|
|
387 |
*/
|
|
388 |
#define LOG_EVENT_SUPPRESS_USE_F 0x8
|
|
389 |
||
390 |
/*
|
|
391 |
The table map version internal to the log should be increased after
|
|
392 |
the event has been written to the binary log.
|
|
393 |
*/
|
|
394 |
#define LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F 0x10
|
|
395 |
||
396 |
/**
|
|
397 |
@def OPTIONS_WRITTEN_TO_BIN_LOG
|
|
398 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
399 |
OPTIONS_WRITTEN_TO_BIN_LOG are the bits of session->options which must
|
1
by brian
clean slate |
400 |
be written to the binlog. OPTIONS_WRITTEN_TO_BIN_LOG could be
|
401 |
written into the Format_description_log_event, so that if later we
|
|
402 |
don't want to replicate a variable we did replicate, or the
|
|
403 |
contrary, it's doable. But it should not be too hard to decide once
|
|
404 |
for all of what we replicate and what we don't, among the fixed 32
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
405 |
bits of session->options.
|
1
by brian
clean slate |
406 |
|
407 |
I (Guilhem) have read through every option's usage, and it looks
|
|
408 |
like OPTION_AUTO_IS_NULL and OPTION_NO_FOREIGN_KEYS are the only
|
|
409 |
ones which alter how the query modifies the table. It's good to
|
|
410 |
replicate OPTION_RELAXED_UNIQUE_CHECKS too because otherwise, the
|
|
411 |
slave may insert data slower than the master, in InnoDB.
|
|
412 |
OPTION_BIG_SELECTS is not needed (the slave thread runs with
|
|
413 |
max_join_size=HA_POS_ERROR) and OPTION_BIG_TABLES is not needed
|
|
414 |
either, as the manual says (because a too big in-memory temp table
|
|
415 |
is automatically written to disk).
|
|
416 |
*/
|
|
417 |
#define OPTIONS_WRITTEN_TO_BIN_LOG \
|
|
418 |
(OPTION_AUTO_IS_NULL | OPTION_NO_FOREIGN_KEY_CHECKS | \
|
|
419 |
OPTION_RELAXED_UNIQUE_CHECKS | OPTION_NOT_AUTOCOMMIT)
|
|
420 |
||
421 |
/* Shouldn't be defined before */
|
|
422 |
#define EXPECTED_OPTIONS \
|
|
398.1.8
by Monty Taylor
Enabled -Wlong-long. |
423 |
((1U << 14) | (1U << 26) | (1U << 27) | (1U << 19))
|
1
by brian
clean slate |
424 |
|
425 |
#if OPTIONS_WRITTEN_TO_BIN_LOG != EXPECTED_OPTIONS
|
|
426 |
#error OPTIONS_WRITTEN_TO_BIN_LOG must NOT change their values!
|
|
427 |
#endif
|
|
428 |
#undef EXPECTED_OPTIONS /* You shouldn't use this one */ |
|
429 |
||
430 |
/**
|
|
431 |
@enum Log_event_type
|
|
432 |
||
433 |
Enumeration type for the different types of log events.
|
|
434 |
*/
|
|
435 |
enum Log_event_type |
|
436 |
{
|
|
437 |
/*
|
|
438 |
Every time you update this enum (when you add a type), you have to
|
|
439 |
fix Format_description_log_event::Format_description_log_event().
|
|
440 |
*/
|
|
441 |
UNKNOWN_EVENT= 0, |
|
442 |
START_EVENT_V3= 1, |
|
443 |
QUERY_EVENT= 2, |
|
444 |
STOP_EVENT= 3, |
|
445 |
ROTATE_EVENT= 4, |
|
446 |
INTVAR_EVENT= 5, |
|
447 |
LOAD_EVENT= 6, |
|
448 |
SLAVE_EVENT= 7, |
|
449 |
CREATE_FILE_EVENT= 8, |
|
450 |
APPEND_BLOCK_EVENT= 9, |
|
451 |
EXEC_LOAD_EVENT= 10, |
|
452 |
DELETE_FILE_EVENT= 11, |
|
453 |
/*
|
|
454 |
NEW_LOAD_EVENT is like LOAD_EVENT except that it has a longer
|
|
455 |
sql_ex, allowing multibyte TERMINATED BY etc; both types share the
|
|
456 |
same class (Load_log_event)
|
|
457 |
*/
|
|
458 |
NEW_LOAD_EVENT= 12, |
|
459 |
RAND_EVENT= 13, |
|
460 |
USER_VAR_EVENT= 14, |
|
461 |
FORMAT_DESCRIPTION_EVENT= 15, |
|
462 |
XID_EVENT= 16, |
|
463 |
BEGIN_LOAD_QUERY_EVENT= 17, |
|
464 |
EXECUTE_LOAD_QUERY_EVENT= 18, |
|
465 |
||
466 |
TABLE_MAP_EVENT = 19, |
|
467 |
||
468 |
/*
|
|
469 |
These event numbers are used from 5.1.16 and forward
|
|
470 |
*/
|
|
471 |
WRITE_ROWS_EVENT = 23, |
|
472 |
UPDATE_ROWS_EVENT = 24, |
|
473 |
DELETE_ROWS_EVENT = 25, |
|
474 |
||
475 |
/*
|
|
476 |
Something out of the ordinary happened on the master
|
|
477 |
*/
|
|
478 |
INCIDENT_EVENT= 26, |
|
479 |
||
480 |
/*
|
|
481 |
Heartbeat event to be send by master at its idle time
|
|
482 |
to ensure master's online status to slave
|
|
483 |
*/
|
|
484 |
HEARTBEAT_LOG_EVENT= 27, |
|
485 |
||
486 |
/*
|
|
487 |
Add new events here - right above this comment!
|
|
488 |
Existing events (except ENUM_END_EVENT) should never change their numbers
|
|
489 |
*/
|
|
490 |
||
491 |
ENUM_END_EVENT /* end marker */ |
|
492 |
};
|
|
493 |
||
494 |
/*
|
|
495 |
The number of types we handle in Format_description_log_event (UNKNOWN_EVENT
|
|
496 |
is not to be handled, it does not exist in binlogs, it does not have a
|
|
497 |
format).
|
|
498 |
*/
|
|
499 |
#define LOG_EVENT_TYPES (ENUM_END_EVENT-1)
|
|
500 |
||
501 |
enum Int_event_type |
|
502 |
{
|
|
503 |
INVALID_INT_EVENT = 0, LAST_INSERT_ID_EVENT = 1, INSERT_ID_EVENT = 2 |
|
504 |
};
|
|
505 |
||
506 |
||
507 |
class String; |
|
319.1.1
by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_ |
508 |
class DRIZZLE_BIN_LOG; |
520.1.21
by Brian Aker
THD -> Session rename |
509 |
class Session; |
1
by brian
clean slate |
510 |
|
511 |
class Format_description_log_event; |
|
512 |
class Relay_log_info; |
|
513 |
||
514 |
/**
|
|
515 |
the struct aggregates two paramenters that identify an event
|
|
516 |
uniquely in scope of communication of a particular master and slave couple.
|
|
517 |
I.e there can not be 2 events from the same staying connected master which
|
|
518 |
have the same coordinates.
|
|
519 |
@note
|
|
520 |
Such identifier is not yet unique generally as the event originating master
|
|
521 |
is resetable. Also the crashed master can be replaced with some other.
|
|
522 |
*/
|
|
523 |
struct event_coordinates |
|
524 |
{
|
|
525 |
char * file_name; // binlog file name (directories stripped) |
|
526 |
my_off_t pos; // event's position in the binlog file |
|
527 |
};
|
|
528 |
||
529 |
/**
|
|
530 |
@class Log_event
|
|
531 |
||
532 |
This is the abstract base class for binary log events.
|
|
533 |
|
|
534 |
@section Log_event_binary_format Binary Format
|
|
535 |
||
536 |
Any @c Log_event saved on disk consists of the following three
|
|
537 |
components.
|
|
538 |
||
539 |
- Common-Header
|
|
540 |
- Post-Header
|
|
541 |
- Body
|
|
542 |
||
543 |
The Common-Header, documented in the table @ref Table_common_header
|
|
544 |
"below", always has the same form and length within one version of
|
|
545 |
MySQL. Each event type specifies a format and length of the
|
|
546 |
Post-Header. The length of the Common-Header is the same for all
|
|
547 |
events of the same type. The Body may be of different format and
|
|
548 |
length even for different events of the same type. The binary
|
|
549 |
formats of Post-Header and Body are documented separately in each
|
|
550 |
subclass. The binary format of Common-Header is as follows.
|
|
551 |
||
552 |
<table>
|
|
553 |
<caption>Common-Header</caption>
|
|
554 |
||
555 |
<tr>
|
|
556 |
<th>Name</th>
|
|
557 |
<th>Format</th>
|
|
558 |
<th>Description</th>
|
|
559 |
</tr>
|
|
560 |
||
561 |
<tr>
|
|
562 |
<td>timestamp</td>
|
|
563 |
<td>4 byte unsigned integer</td>
|
|
564 |
<td>The time when the query started, in seconds since 1970.
|
|
565 |
</td>
|
|
566 |
</tr>
|
|
567 |
||
568 |
<tr>
|
|
569 |
<td>type</td>
|
|
570 |
<td>1 byte enumeration</td>
|
|
571 |
<td>See enum #Log_event_type.</td>
|
|
572 |
</tr>
|
|
573 |
||
574 |
<tr>
|
|
575 |
<td>server_id</td>
|
|
576 |
<td>4 byte unsigned integer</td>
|
|
577 |
<td>Server ID of the server that created the event.</td>
|
|
578 |
</tr>
|
|
579 |
||
580 |
<tr>
|
|
581 |
<td>total_size</td>
|
|
582 |
<td>4 byte unsigned integer</td>
|
|
583 |
<td>The total size of this event, in bytes. In other words, this
|
|
584 |
is the sum of the sizes of Common-Header, Post-Header, and Body.
|
|
585 |
</td>
|
|
586 |
</tr>
|
|
587 |
||
588 |
<tr>
|
|
589 |
<td>master_position</td>
|
|
590 |
<td>4 byte unsigned integer</td>
|
|
591 |
<td>The position of the next event in the master binary log, in
|
|
592 |
bytes from the beginning of the file. In a binlog that is not a
|
|
593 |
relay log, this is just the position of the next event, in bytes
|
|
594 |
from the beginning of the file. In a relay log, this is
|
|
595 |
the position of the next event in the master's binlog.
|
|
596 |
</td>
|
|
597 |
</tr>
|
|
598 |
||
599 |
<tr>
|
|
600 |
<td>flags</td>
|
|
601 |
<td>2 byte bitfield</td>
|
|
602 |
<td>See Log_event::flags.</td>
|
|
603 |
</tr>
|
|
604 |
</table>
|
|
605 |
||
606 |
Summing up the numbers above, we see that the total size of the
|
|
607 |
common header is 19 bytes.
|
|
608 |
||
609 |
@subsection Log_event_format_of_atomic_primitives Format of Atomic Primitives
|
|
610 |
||
611 |
- All numbers, whether they are 16-, 24-, 32-, or 64-bit numbers,
|
|
612 |
are stored in little endian, i.e., the least significant byte first,
|
|
613 |
unless otherwise specified.
|
|
614 |
||
615 |
@anchor packed_integer
|
|
616 |
- Some events use a special format for efficient representation of
|
|
617 |
unsigned integers, called Packed Integer. A Packed Integer has the
|
|
618 |
capacity of storing up to 8-byte integers, while small integers
|
|
619 |
still can use 1, 3, or 4 bytes. The value of the first byte
|
|
620 |
determines how to read the number, according to the following table:
|
|
621 |
||
622 |
<table>
|
|
623 |
<caption>Format of Packed Integer</caption>
|
|
624 |
||
625 |
<tr>
|
|
626 |
<th>First byte</th>
|
|
627 |
<th>Format</th>
|
|
628 |
</tr>
|
|
629 |
||
630 |
<tr>
|
|
631 |
<td>0-250</td>
|
|
632 |
<td>The first byte is the number (in the range 0-250), and no more
|
|
633 |
bytes are used.</td>
|
|
634 |
</tr>
|
|
635 |
||
636 |
<tr>
|
|
637 |
<td>252</td>
|
|
638 |
<td>Two more bytes are used. The number is in the range
|
|
639 |
251-0xffff.</td>
|
|
640 |
</tr>
|
|
641 |
||
642 |
<tr>
|
|
643 |
<td>253</td>
|
|
644 |
<td>Three more bytes are used. The number is in the range
|
|
645 |
0xffff-0xffffff.</td>
|
|
646 |
</tr>
|
|
647 |
||
648 |
<tr>
|
|
649 |
<td>254</td>
|
|
650 |
<td>Eight more bytes are used. The number is in the range
|
|
651 |
0xffffff-0xffffffffffffffff.</td>
|
|
652 |
</tr>
|
|
653 |
||
654 |
</table>
|
|
655 |
||
656 |
- Strings are stored in various formats. The format of each string
|
|
657 |
is documented separately.
|
|
658 |
*/
|
|
659 |
class Log_event |
|
660 |
{
|
|
661 |
public: |
|
662 |
/**
|
|
663 |
Enumeration of what kinds of skipping (and non-skipping) that can
|
|
664 |
occur when the slave executes an event.
|
|
665 |
||
666 |
@see shall_skip
|
|
667 |
@see do_shall_skip
|
|
668 |
*/
|
|
669 |
enum enum_skip_reason { |
|
670 |
/**
|
|
671 |
Don't skip event.
|
|
672 |
*/
|
|
673 |
EVENT_SKIP_NOT, |
|
674 |
||
675 |
/**
|
|
676 |
Skip event by ignoring it.
|
|
677 |
||
678 |
This means that the slave skip counter will not be changed.
|
|
679 |
*/
|
|
680 |
EVENT_SKIP_IGNORE, |
|
681 |
||
682 |
/**
|
|
683 |
Skip event and decrease skip counter.
|
|
684 |
*/
|
|
685 |
EVENT_SKIP_COUNT
|
|
686 |
};
|
|
687 |
||
688 |
||
689 |
/*
|
|
690 |
The following type definition is to be used whenever data is placed
|
|
691 |
and manipulated in a common buffer. Use this typedef for buffers
|
|
692 |
that contain data containing binary and character data.
|
|
693 |
*/
|
|
694 |
typedef unsigned char Byte; |
|
695 |
||
696 |
/*
|
|
697 |
The offset in the log where this event originally appeared (it is
|
|
698 |
preserved in relay logs, making SHOW SLAVE STATUS able to print
|
|
699 |
coordinates of the event in the master's binlog). Note: when a
|
|
700 |
transaction is written by the master to its binlog (wrapped in
|
|
701 |
BEGIN/COMMIT) the log_pos of all the queries it contains is the
|
|
702 |
one of the BEGIN (this way, when one does SHOW SLAVE STATUS it
|
|
703 |
sees the offset of the BEGIN, which is logical as rollback may
|
|
704 |
occur), except the COMMIT query which has its real offset.
|
|
705 |
*/
|
|
490
by Brian Aker
More effort around master.info (and relay.info) |
706 |
off_t log_pos; |
1
by brian
clean slate |
707 |
/*
|
708 |
A temp buffer for read_log_event; it is later analysed according to the
|
|
709 |
event's type, and its content is distributed in the event-specific fields.
|
|
710 |
*/
|
|
711 |
char *temp_buf; |
|
712 |
/*
|
|
713 |
Timestamp on the master(for debugging and replication of
|
|
714 |
NOW()/TIMESTAMP). It is important for queries and LOAD DATA
|
|
715 |
INFILE. This is set at the event's creation time, except for Query
|
|
716 |
and Load (et al.) events where this is set at the query's
|
|
717 |
execution time, which guarantees good replication (otherwise, we
|
|
718 |
could have a query and its event with different timestamps).
|
|
719 |
*/
|
|
720 |
time_t when; |
|
721 |
/* The number of seconds the query took to run on the master. */
|
|
722 |
ulong exec_time; |
|
723 |
/* Number of bytes written by write() function */
|
|
724 |
ulong data_written; |
|
725 |
||
726 |
/*
|
|
727 |
The master's server id (is preserved in the relay log; used to
|
|
728 |
prevent from infinite loops in circular replication).
|
|
729 |
*/
|
|
205
by Brian Aker
uint32 -> uin32_t |
730 |
uint32_t server_id; |
1
by brian
clean slate |
731 |
|
732 |
/**
|
|
733 |
Some 16 flags. See the definitions above for LOG_EVENT_TIME_F,
|
|
734 |
LOG_EVENT_FORCED_ROTATE_F, LOG_EVENT_THREAD_SPECIFIC_F, and
|
|
735 |
LOG_EVENT_SUPPRESS_USE_F for notes.
|
|
736 |
*/
|
|
206
by Brian Aker
Removed final uint dead types. |
737 |
uint16_t flags; |
1
by brian
clean slate |
738 |
|
739 |
bool cache_stmt; |
|
740 |
||
741 |
/**
|
|
742 |
A storage to cache the global system variable's value.
|
|
743 |
Handling of a separate event will be governed its member.
|
|
744 |
*/
|
|
745 |
ulong slave_exec_mode; |
|
746 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
747 |
Session* session; |
1
by brian
clean slate |
748 |
|
749 |
Log_event(); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
750 |
Log_event(Session* session_arg, uint16_t flags_arg, bool cache_stmt); |
1
by brian
clean slate |
751 |
/*
|
752 |
read_log_event() functions read an event from a binlog or relay
|
|
753 |
log; used by SHOW BINLOG EVENTS, the binlog_dump thread on the
|
|
754 |
master (reads master's binlog), the slave IO thread (reads the
|
|
755 |
event sent by binlog_dump), the slave SQL thread (reads the event
|
|
756 |
from the relay log). If mutex is 0, the read will proceed without
|
|
757 |
mutex. We need the description_event to be able to parse the
|
|
758 |
event (to know the post-header's size); in fact in read_log_event
|
|
759 |
we detect the event's type, then call the specific event's
|
|
760 |
constructor and pass description_event as an argument.
|
|
761 |
*/
|
|
762 |
static Log_event* read_log_event(IO_CACHE* file, |
|
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
763 |
pthread_mutex_t* log_lock, |
1
by brian
clean slate |
764 |
const Format_description_log_event |
765 |
*description_event); |
|
766 |
static int read_log_event(IO_CACHE* file, String* packet, |
|
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
767 |
pthread_mutex_t* log_lock); |
1
by brian
clean slate |
768 |
/*
|
769 |
init_show_field_list() prepares the column names and types for the
|
|
770 |
output of SHOW BINLOG EVENTS; it is used only by SHOW BINLOG
|
|
771 |
EVENTS.
|
|
772 |
*/
|
|
773 |
static void init_show_field_list(List<Item>* field_list); |
|
774 |
int net_send(Protocol *protocol, const char* log_name, my_off_t pos); |
|
775 |
||
776 |
/*
|
|
777 |
pack_info() is used by SHOW BINLOG EVENTS; as print() it prepares and sends
|
|
778 |
a string to display to the user, so it resembles print().
|
|
779 |
*/
|
|
780 |
||
781 |
virtual void pack_info(Protocol *protocol); |
|
782 |
||
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
783 |
virtual const char* get_db(); |
1
by brian
clean slate |
784 |
|
785 |
static void *operator new(size_t size) |
|
786 |
{
|
|
787 |
return (void*) my_malloc((uint)size, MYF(MY_WME|MY_FAE)); |
|
788 |
}
|
|
789 |
||
53.2.4
by Monty Taylor
Changes so that client/ builds cleanly with no warnings. |
790 |
static void operator delete(void *ptr, |
520.9.3
by mordred
zomg. Solaris actually builds all the way!!! |
791 |
size_t) |
1
by brian
clean slate |
792 |
{
|
481
by Brian Aker
Remove all of uchar. |
793 |
free((unsigned char*) ptr); |
1
by brian
clean slate |
794 |
}
|
795 |
||
796 |
/* Placement version of the above operators */
|
|
797 |
static void *operator new(size_t, void* ptr) { return ptr; } |
|
798 |
static void operator delete(void*, void*) { } |
|
799 |
||
800 |
bool write_header(IO_CACHE* file, ulong data_length); |
|
801 |
virtual bool write(IO_CACHE* file) |
|
802 |
{
|
|
803 |
return (write_header(file, get_data_size()) || |
|
804 |
write_data_header(file) || |
|
805 |
write_data_body(file)); |
|
806 |
}
|
|
520.9.3
by mordred
zomg. Solaris actually builds all the way!!! |
807 |
virtual bool write_data_header(IO_CACHE*) |
1
by brian
clean slate |
808 |
{ return 0; } |
520.9.3
by mordred
zomg. Solaris actually builds all the way!!! |
809 |
virtual bool write_data_body(IO_CACHE*) |
1
by brian
clean slate |
810 |
{ return 0; } |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
811 |
time_t get_time(); |
1
by brian
clean slate |
812 |
virtual Log_event_type get_type_code() = 0; |
813 |
virtual bool is_valid() const = 0; |
|
814 |
virtual bool is_artificial_event() { return 0; } |
|
815 |
inline bool get_cache_stmt() const { return cache_stmt; } |
|
816 |
Log_event(const char* buf, const Format_description_log_event |
|
817 |
*description_event); |
|
818 |
virtual ~Log_event() { free_temp_buf();} |
|
819 |
void register_temp_buf(char* buf) { temp_buf = buf; } |
|
820 |
void free_temp_buf() |
|
821 |
{
|
|
822 |
if (temp_buf) |
|
823 |
{
|
|
477
by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that. |
824 |
free(temp_buf); |
1
by brian
clean slate |
825 |
temp_buf = 0; |
826 |
}
|
|
827 |
}
|
|
828 |
/*
|
|
829 |
Get event length for simple events. For complicated events the length
|
|
830 |
is calculated during write()
|
|
831 |
*/
|
|
832 |
virtual int get_data_size() { return 0;} |
|
482
by Brian Aker
Remove uint. |
833 |
static Log_event* read_log_event(const char* buf, uint32_t event_len, |
1
by brian
clean slate |
834 |
const char **error, |
835 |
const Format_description_log_event |
|
836 |
*description_event); |
|
837 |
/**
|
|
838 |
Returns the human readable name of the given event type.
|
|
839 |
*/
|
|
840 |
static const char* get_type_str(Log_event_type type); |
|
841 |
/**
|
|
842 |
Returns the human readable name of this event's type.
|
|
843 |
*/
|
|
844 |
const char* get_type_str(); |
|
845 |
||
846 |
/* Return start of query time or current time */
|
|
847 |
||
848 |
public: |
|
849 |
||
850 |
/**
|
|
851 |
Apply the event to the database.
|
|
852 |
||
853 |
This function represents the public interface for applying an
|
|
854 |
event.
|
|
855 |
||
856 |
@see do_apply_event
|
|
857 |
*/
|
|
858 |
int apply_event(Relay_log_info const *rli) |
|
859 |
{
|
|
860 |
return do_apply_event(rli); |
|
861 |
}
|
|
862 |
||
863 |
||
864 |
/**
|
|
865 |
Update the relay log position.
|
|
866 |
||
867 |
This function represents the public interface for "stepping over"
|
|
868 |
the event and will update the relay log information.
|
|
869 |
||
870 |
@see do_update_pos
|
|
871 |
*/
|
|
872 |
int update_pos(Relay_log_info *rli) |
|
873 |
{
|
|
874 |
return do_update_pos(rli); |
|
875 |
}
|
|
876 |
||
877 |
/**
|
|
878 |
Decide if the event shall be skipped, and the reason for skipping
|
|
879 |
it.
|
|
880 |
||
881 |
@see do_shall_skip
|
|
882 |
*/
|
|
883 |
enum_skip_reason shall_skip(Relay_log_info *rli) |
|
884 |
{
|
|
885 |
return do_shall_skip(rli); |
|
886 |
}
|
|
887 |
||
888 |
protected: |
|
889 |
||
890 |
/**
|
|
891 |
Helper function to ignore an event w.r.t. the slave skip counter.
|
|
892 |
||
893 |
This function can be used inside do_shall_skip() for functions
|
|
894 |
that cannot end a group. If the slave skip counter is 1 when
|
|
895 |
seeing such an event, the event shall be ignored, the counter
|
|
896 |
left intact, and processing continue with the next event.
|
|
897 |
||
898 |
A typical usage is:
|
|
899 |
@code
|
|
900 |
enum_skip_reason do_shall_skip(Relay_log_info *rli) {
|
|
901 |
return continue_group(rli);
|
|
902 |
}
|
|
903 |
@endcode
|
|
904 |
||
905 |
@return Skip reason
|
|
906 |
*/
|
|
907 |
enum_skip_reason continue_group(Relay_log_info *rli); |
|
908 |
||
909 |
/**
|
|
910 |
Primitive to apply an event to the database.
|
|
911 |
||
912 |
This is where the change to the database is made.
|
|
913 |
||
914 |
@note The primitive is protected instead of private, since there
|
|
915 |
is a hierarchy of actions to be performed in some cases.
|
|
916 |
||
917 |
@see Format_description_log_event::do_apply_event()
|
|
918 |
||
919 |
@param rli Pointer to relay log info structure
|
|
920 |
||
921 |
@retval 0 Event applied successfully
|
|
922 |
@retval errno Error code if event application failed
|
|
923 |
*/
|
|
520.9.3
by mordred
zomg. Solaris actually builds all the way!!! |
924 |
virtual int do_apply_event(Relay_log_info const *) |
1
by brian
clean slate |
925 |
{
|
926 |
return 0; /* Default implementation does nothing */ |
|
927 |
}
|
|
928 |
||
929 |
||
930 |
/**
|
|
931 |
Advance relay log coordinates.
|
|
932 |
||
933 |
This function is called to advance the relay log coordinates to
|
|
934 |
just after the event. It is essential that both the relay log
|
|
935 |
coordinate and the group log position is updated correctly, since
|
|
936 |
this function is used also for skipping events.
|
|
937 |
||
938 |
Normally, each implementation of do_update_pos() shall:
|
|
939 |
||
940 |
- Update the event position to refer to the position just after
|
|
941 |
the event.
|
|
942 |
||
943 |
- Update the group log position to refer to the position just
|
|
944 |
after the event <em>if the event is last in a group</em>
|
|
945 |
||
946 |
@param rli Pointer to relay log info structure
|
|
947 |
||
948 |
@retval 0 Coordinates changed successfully
|
|
949 |
@retval errno Error code if advancing failed (usually just
|
|
950 |
1). Observe that handler errors are returned by the
|
|
951 |
do_apply_event() function, and not by this one.
|
|
952 |
*/
|
|
953 |
virtual int do_update_pos(Relay_log_info *rli); |
|
954 |
||
955 |
||
956 |
/**
|
|
957 |
Decide if this event shall be skipped or not and the reason for
|
|
958 |
skipping it.
|
|
959 |
||
960 |
The default implementation decide that the event shall be skipped
|
|
961 |
if either:
|
|
962 |
||
963 |
- the server id of the event is the same as the server id of the
|
|
964 |
server and <code>rli->replicate_same_server_id</code> is true,
|
|
965 |
or
|
|
966 |
||
967 |
- if <code>rli->slave_skip_counter</code> is greater than zero.
|
|
968 |
||
969 |
@see do_apply_event
|
|
970 |
@see do_update_pos
|
|
971 |
||
972 |
@retval Log_event::EVENT_SKIP_NOT
|
|
973 |
The event shall not be skipped and should be applied.
|
|
974 |
||
975 |
@retval Log_event::EVENT_SKIP_IGNORE
|
|
976 |
The event shall be skipped by just ignoring it, i.e., the slave
|
|
977 |
skip counter shall not be changed. This happends if, for example,
|
|
978 |
the originating server id of the event is the same as the server
|
|
979 |
id of the slave.
|
|
980 |
||
981 |
@retval Log_event::EVENT_SKIP_COUNT
|
|
982 |
The event shall be skipped because the slave skip counter was
|
|
983 |
non-zero. The caller shall decrease the counter by one.
|
|
984 |
*/
|
|
985 |
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli); |
|
986 |
};
|
|
987 |
||
988 |
||
989 |
/*
|
|
990 |
One class for each type of event.
|
|
991 |
Two constructors for each class:
|
|
992 |
- one to create the event for logging (when the server acts as a master),
|
|
993 |
called after an update to the database is done,
|
|
994 |
which accepts parameters like the query, the database, the options for LOAD
|
|
995 |
DATA INFILE...
|
|
996 |
- one to create the event from a packet (when the server acts as a slave),
|
|
997 |
called before reproducing the update, which accepts parameters (like a
|
|
998 |
buffer). Used to read from the master, from the relay log, and in
|
|
999 |
mysqlbinlog. This constructor must be format-tolerant.
|
|
1000 |
*/
|
|
1001 |
||
1002 |
/**
|
|
1003 |
@class Query_log_event
|
|
1004 |
|
|
1005 |
A @c Query_log_event is created for each query that modifies the
|
|
1006 |
database, unless the query is logged row-based.
|
|
1007 |
||
1008 |
@section Query_log_event_binary_format Binary format
|
|
1009 |
||
1010 |
See @ref Log_event_binary_format "Binary format for log events" for
|
|
1011 |
a general discussion and introduction to the binary format of binlog
|
|
1012 |
events.
|
|
1013 |
||
1014 |
The Post-Header has five components:
|
|
1015 |
||
1016 |
<table>
|
|
1017 |
<caption>Post-Header for Query_log_event</caption>
|
|
1018 |
||
1019 |
<tr>
|
|
1020 |
<th>Name</th>
|
|
1021 |
<th>Format</th>
|
|
1022 |
<th>Description</th>
|
|
1023 |
</tr>
|
|
1024 |
||
1025 |
<tr>
|
|
1026 |
<td>slave_proxy_id</td>
|
|
1027 |
<td>4 byte unsigned integer</td>
|
|
1028 |
<td>An integer identifying the client thread that issued the
|
|
1029 |
query. The id is unique per server. (Note, however, that two
|
|
1030 |
threads on different servers may have the same slave_proxy_id.)
|
|
1031 |
This is used when a client thread creates a temporary table local
|
|
1032 |
to the client. The slave_proxy_id is used to distinguish
|
|
1033 |
temporary tables that belong to different clients.
|
|
1034 |
</td>
|
|
1035 |
</tr>
|
|
1036 |
||
1037 |
<tr>
|
|
1038 |
<td>exec_time</td>
|
|
1039 |
<td>4 byte unsigned integer</td>
|
|
1040 |
<td>The time from when the query started to when it was logged in
|
|
1041 |
the binlog, in seconds.</td>
|
|
1042 |
</tr>
|
|
1043 |
||
1044 |
<tr>
|
|
1045 |
<td>db_len</td>
|
|
1046 |
<td>1 byte integer</td>
|
|
1047 |
<td>The length of the name of the currently selected database.</td>
|
|
1048 |
</tr>
|
|
1049 |
||
1050 |
<tr>
|
|
1051 |
<td>error_code</td>
|
|
1052 |
<td>2 byte unsigned integer</td>
|
|
1053 |
<td>Error code generated by the master. If the master fails, the
|
|
1054 |
slave will fail with the same error code, except for the error
|
|
1055 |
codes ER_DB_CREATE_EXISTS == 1007 and ER_DB_DROP_EXISTS == 1008.
|
|
1056 |
</td>
|
|
1057 |
</tr>
|
|
1058 |
||
1059 |
<tr>
|
|
1060 |
<td>status_vars_len</td>
|
|
1061 |
<td>2 byte unsigned integer</td>
|
|
1062 |
<td>The length of the status_vars block of the Body, in bytes. See
|
|
1063 |
@ref query_log_event_status_vars "below".
|
|
1064 |
</td>
|
|
1065 |
</tr>
|
|
1066 |
</table>
|
|
1067 |
||
1068 |
The Body has the following components:
|
|
1069 |
||
1070 |
<table>
|
|
1071 |
<caption>Body for Query_log_event</caption>
|
|
1072 |
||
1073 |
<tr>
|
|
1074 |
<th>Name</th>
|
|
1075 |
<th>Format</th>
|
|
1076 |
<th>Description</th>
|
|
1077 |
</tr>
|
|
1078 |
||
1079 |
<tr>
|
|
1080 |
<td>@anchor query_log_event_status_vars status_vars</td>
|
|
1081 |
<td>status_vars_len bytes</td>
|
|
1082 |
<td>Zero or more status variables. Each status variable consists
|
|
1083 |
of one byte identifying the variable stored, followed by the value
|
|
1084 |
of the variable. The possible variables are listed separately in
|
|
1085 |
the table @ref Table_query_log_event_status_vars "below". MySQL
|
|
1086 |
always writes events in the order defined below; however, it is
|
|
1087 |
capable of reading them in any order. </td>
|
|
1088 |
</tr>
|
|
1089 |
||
1090 |
<tr>
|
|
1091 |
<td>db</td>
|
|
1092 |
<td>db_len+1</td>
|
|
1093 |
<td>The currently selected database, as a null-terminated string.
|
|
1094 |
||
1095 |
(The trailing zero is redundant since the length is already known;
|
|
1096 |
it is db_len from Post-Header.)
|
|
1097 |
</td>
|
|
1098 |
</tr>
|
|
1099 |
||
1100 |
<tr>
|
|
1101 |
<td>query</td>
|
|
1102 |
<td>variable length string without trailing zero, extending to the
|
|
1103 |
end of the event (determined by the length field of the
|
|
1104 |
Common-Header)
|
|
1105 |
</td>
|
|
1106 |
<td>The SQL query.</td>
|
|
1107 |
</tr>
|
|
1108 |
</table>
|
|
1109 |
||
1110 |
The following table lists the status variables that may appear in
|
|
1111 |
the status_vars field.
|
|
1112 |
||
1113 |
@anchor Table_query_log_event_status_vars
|
|
1114 |
<table>
|
|
1115 |
<caption>Status variables for Query_log_event</caption>
|
|
1116 |
||
1117 |
<tr>
|
|
1118 |
<th>Status variable</th>
|
|
1119 |
<th>1 byte identifier</th>
|
|
1120 |
<th>Format</th>
|
|
1121 |
<th>Description</th>
|
|
1122 |
</tr>
|
|
1123 |
||
1124 |
<tr>
|
|
1125 |
<td>flags2</td>
|
|
1126 |
<td>Q_FLAGS2_CODE == 0</td>
|
|
1127 |
<td>4 byte bitfield</td>
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1128 |
<td>The flags in @c session->options, binary AND-ed with @c
|
1129 |
OPTIONS_WRITTEN_TO_BIN_LOG. The @c session->options bitfield contains
|
|
1
by brian
clean slate |
1130 |
options for "SELECT". @c OPTIONS_WRITTEN identifies those options
|
1131 |
that need to be written to the binlog (not all do). Specifically,
|
|
1132 |
@c OPTIONS_WRITTEN_TO_BIN_LOG equals (@c OPTION_AUTO_IS_NULL | @c
|
|
1133 |
OPTION_NO_FOREIGN_KEY_CHECKS | @c OPTION_RELAXED_UNIQUE_CHECKS |
|
|
1134 |
@c OPTION_NOT_AUTOCOMMIT), or 0x0c084000 in hex.
|
|
1135 |
||
1136 |
These flags correspond to the SQL variables SQL_AUTO_IS_NULL,
|
|
1137 |
FOREIGN_KEY_CHECKS, UNIQUE_CHECKS, and AUTOCOMMIT, documented in
|
|
1138 |
the "SET Syntax" section of the MySQL Manual.
|
|
1139 |
||
1140 |
This field is always written to the binlog in version >= 5.0, and
|
|
1141 |
never written in version < 5.0.
|
|
1142 |
</td>
|
|
1143 |
</tr>
|
|
1144 |
||
1145 |
<tr>
|
|
1146 |
<td>sql_mode</td>
|
|
1147 |
<td>Q_SQL_MODE_CODE == 1</td>
|
|
1148 |
<td>8 byte bitfield</td>
|
|
1149 |
<td>The @c sql_mode variable. See the section "SQL Modes" in the
|
|
1150 |
MySQL manual, and see mysql_priv.h for a list of the possible
|
|
1151 |
flags. Currently (2007-10-04), the following flags are available:
|
|
1152 |
<pre>
|
|
1153 |
MODE_REAL_AS_FLOAT==0x1
|
|
1154 |
MODE_PIPES_AS_CONCAT==0x2
|
|
1155 |
MODE_ANSI_QUOTES==0x4
|
|
1156 |
MODE_IGNORE_SPACE==0x8
|
|
1157 |
MODE_NOT_USED==0x10
|
|
1158 |
MODE_ONLY_FULL_GROUP_BY==0x20
|
|
1159 |
MODE_NO_UNSIGNED_SUBTRACTION==0x40
|
|
1160 |
MODE_NO_DIR_IN_CREATE==0x80
|
|
1161 |
MODE_POSTGRESQL==0x100
|
|
1162 |
MODE_ORACLE==0x200
|
|
1163 |
MODE_MSSQL==0x400
|
|
1164 |
MODE_DB2==0x800
|
|
1165 |
MODE_MAXDB==0x1000
|
|
1166 |
MODE_NO_KEY_OPTIONS==0x2000
|
|
1167 |
MODE_NO_TABLE_OPTIONS==0x4000
|
|
1168 |
MODE_NO_FIELD_OPTIONS==0x8000
|
|
1169 |
MODE_MYSQL323==0x10000
|
|
1170 |
MODE_MYSQL323==0x20000
|
|
1171 |
MODE_MYSQL40==0x40000
|
|
1172 |
MODE_ANSI==0x80000
|
|
1173 |
MODE_NO_AUTO_VALUE_ON_ZERO==0x100000
|
|
1174 |
MODE_NO_BACKSLASH_ESCAPES==0x200000
|
|
1175 |
MODE_STRICT_TRANS_TABLES==0x400000
|
|
1176 |
MODE_STRICT_ALL_TABLES==0x800000
|
|
1177 |
MODE_NO_ZERO_IN_DATE==0x1000000
|
|
1178 |
MODE_NO_ZERO_DATE==0x2000000
|
|
1179 |
MODE_INVALID_DATES==0x4000000
|
|
1180 |
MODE_ERROR_FOR_DIVISION_BY_ZERO==0x8000000
|
|
1181 |
MODE_TRADITIONAL==0x10000000
|
|
1182 |
MODE_NO_AUTO_CREATE_USER==0x20000000
|
|
1183 |
MODE_HIGH_NOT_PRECEDENCE==0x40000000
|
|
1184 |
MODE_PAD_CHAR_TO_FULL_LENGTH==0x80000000
|
|
1185 |
</pre>
|
|
1186 |
All these flags are replicated from the server. However, all
|
|
1187 |
flags except @c MODE_NO_DIR_IN_CREATE are honored by the slave;
|
|
1188 |
the slave always preserves its old value of @c
|
|
1189 |
MODE_NO_DIR_IN_CREATE. For a rationale, see comment in
|
|
1190 |
@c Query_log_event::do_apply_event in @c log_event.cc.
|
|
1191 |
||
1192 |
This field is always written to the binlog.
|
|
1193 |
</td>
|
|
1194 |
</tr>
|
|
1195 |
||
1196 |
<tr>
|
|
1197 |
<td>catalog</td>
|
|
1198 |
<td>Q_CATALOG_NZ_CODE == 6</td>
|
|
1199 |
<td>Variable-length string: the length in bytes (1 byte) followed
|
|
1200 |
by the characters (at most 255 bytes)
|
|
1201 |
</td>
|
|
1202 |
<td>Stores the client's current catalog. Every database belongs
|
|
1203 |
to a catalog, the same way that every table belongs to a
|
|
1204 |
database. Currently, there is only one catalog, "std".
|
|
1205 |
||
1206 |
This field is written if the length of the catalog is > 0;
|
|
1207 |
otherwise it is not written.
|
|
1208 |
</td>
|
|
1209 |
</tr>
|
|
1210 |
||
1211 |
<tr>
|
|
1212 |
<td>auto_increment</td>
|
|
1213 |
<td>Q_AUTO_INCREMENT == 3</td>
|
|
1214 |
<td>two 2 byte unsigned integers, totally 2+2=4 bytes</td>
|
|
1215 |
||
1216 |
<td>The two variables auto_increment_increment and
|
|
1217 |
auto_increment_offset, in that order. For more information, see
|
|
1218 |
"System variables" in the MySQL manual.
|
|
1219 |
||
1220 |
This field is written if auto_increment > 1. Otherwise, it is not
|
|
1221 |
written.
|
|
1222 |
</td>
|
|
1223 |
</tr>
|
|
1224 |
||
1225 |
<tr>
|
|
1226 |
<td>charset</td>
|
|
1227 |
<td>Q_CHARSET_CODE == 4</td>
|
|
1228 |
<td>three 2 byte unsigned integers, totally 2+2+2=6 bytes</td>
|
|
1229 |
<td>The three variables character_set_client,
|
|
1230 |
collation_connection, and collation_server, in that order.
|
|
1231 |
character_set_client is a code identifying the character set and
|
|
1232 |
collation used by the client to encode the query.
|
|
1233 |
collation_connection identifies the character set and collation
|
|
1234 |
that the master converts the query to when it receives it; this is
|
|
1235 |
useful when comparing literal strings. collation_server is the
|
|
1236 |
default character set and collation used when a new database is
|
|
1237 |
created.
|
|
1238 |
||
1239 |
See also "Connection Character Sets and Collations" in the MySQL
|
|
1240 |
5.1 manual.
|
|
1241 |
||
1242 |
All three variables are codes identifying a (character set,
|
|
1243 |
collation) pair. To see which codes map to which pairs, run the
|
|
1244 |
query "SELECT id, character_set_name, collation_name FROM
|
|
1245 |
COLLATIONS".
|
|
1246 |
||
1247 |
Cf. Q_CHARSET_DATABASE_CODE below.
|
|
1248 |
||
1249 |
This field is always written.
|
|
1250 |
</td>
|
|
1251 |
</tr>
|
|
1252 |
||
1253 |
<tr>
|
|
1254 |
<td>time_zone</td>
|
|
1255 |
<td>Q_TIME_ZONE_CODE == 5</td>
|
|
1256 |
<td>Variable-length string: the length in bytes (1 byte) followed
|
|
1257 |
by the characters (at most 255 bytes).
|
|
1258 |
<td>The time_zone of the master.
|
|
1259 |
||
1260 |
See also "System Variables" and "MySQL Server Time Zone Support"
|
|
1261 |
in the MySQL manual.
|
|
1262 |
||
1263 |
This field is written if the length of the time zone string is >
|
|
1264 |
0; otherwise, it is not written.
|
|
1265 |
</td>
|
|
1266 |
</tr>
|
|
1267 |
||
1268 |
<tr>
|
|
1269 |
<td>lc_time_names_number</td>
|
|
1270 |
<td>Q_LC_TIME_NAMES_CODE == 7</td>
|
|
1271 |
<td>2 byte integer</td>
|
|
1272 |
<td>A code identifying a table of month and day names. The
|
|
1273 |
mapping from codes to languages is defined in @c sql_locale.cc.
|
|
1274 |
||
1275 |
This field is written if it is not 0, i.e., if the locale is not
|
|
1276 |
en_US.
|
|
1277 |
</td>
|
|
1278 |
</tr>
|
|
1279 |
||
1280 |
<tr>
|
|
1281 |
<td>charset_database_number</td>
|
|
1282 |
<td>Q_CHARSET_DATABASE_CODE == 8</td>
|
|
1283 |
<td>2 byte integer</td>
|
|
1284 |
||
1285 |
<td>The value of the collation_database system variable (in the
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1286 |
source code stored in @c session->variables.collation_database), which
|
1
by brian
clean slate |
1287 |
holds the code for a (character set, collation) pair as described
|
1288 |
above (see Q_CHARSET_CODE).
|
|
1289 |
||
1290 |
collation_database was used in old versions (???WHEN). Its value
|
|
1291 |
was loaded when issuing a "use db" query and could be changed by
|
|
1292 |
issuing a "SET collation_database=xxx" query. It used to affect
|
|
1293 |
the "LOAD DATA INFILE" and "CREATE TABLE" commands.
|
|
1294 |
||
1295 |
In newer versions, "CREATE TABLE" has been changed to take the
|
|
1296 |
character set from the database of the created table, rather than
|
|
1297 |
the character set of the current database. This makes a
|
|
1298 |
difference when creating a table in another database than the
|
|
1299 |
current one. "LOAD DATA INFILE" has not yet changed to do this,
|
|
1300 |
but there are plans to eventually do it, and to make
|
|
1301 |
collation_database read-only.
|
|
1302 |
||
1303 |
This field is written if it is not 0.
|
|
1304 |
</td>
|
|
1305 |
</tr>
|
|
1306 |
</table>
|
|
1307 |
||
1308 |
@subsection Query_log_event_notes_on_previous_versions Notes on Previous Versions
|
|
1309 |
||
1310 |
* Status vars were introduced in version 5.0. To read earlier
|
|
1311 |
versions correctly, check the length of the Post-Header.
|
|
1312 |
||
1313 |
* The status variable Q_CATALOG_CODE == 2 existed in MySQL 5.0.x,
|
|
1314 |
where 0<=x<=3. It was identical to Q_CATALOG_CODE, except that the
|
|
1315 |
string had a trailing '\0'. The '\0' was removed in 5.0.4 since it
|
|
1316 |
was redundant (the string length is stored before the string). The
|
|
1317 |
Q_CATALOG_CODE will never be written by a new master, but can still
|
|
1318 |
be understood by a new slave.
|
|
1319 |
||
1320 |
* See Q_CHARSET_DATABASE_CODE in the table above.
|
|
1321 |
||
1322 |
*/
|
|
1323 |
class Query_log_event: public Log_event |
|
1324 |
{
|
|
1325 |
protected: |
|
1326 |
Log_event::Byte* data_buf; |
|
1327 |
public: |
|
1328 |
const char* query; |
|
1329 |
const char* catalog; |
|
1330 |
const char* db; |
|
1331 |
/*
|
|
1332 |
If we already know the length of the query string
|
|
1333 |
we pass it with q_len, so we would not have to call strlen()
|
|
1334 |
otherwise, set it to 0, in which case, we compute it with strlen()
|
|
1335 |
*/
|
|
205
by Brian Aker
uint32 -> uin32_t |
1336 |
uint32_t q_len; |
1337 |
uint32_t db_len; |
|
206
by Brian Aker
Removed final uint dead types. |
1338 |
uint16_t error_code; |
1
by brian
clean slate |
1339 |
ulong thread_id; |
1340 |
/*
|
|
1341 |
For events created by Query_log_event::do_apply_event (and
|
|
1342 |
Load_log_event::do_apply_event()) we need the *original* thread
|
|
1343 |
id, to be able to log the event with the original (=master's)
|
|
1344 |
thread id (fix for BUG#1686).
|
|
1345 |
*/
|
|
1346 |
ulong slave_proxy_id; |
|
1347 |
||
1348 |
/*
|
|
1349 |
Binlog format 3 and 4 start to differ (as far as class members are
|
|
1350 |
concerned) from here.
|
|
1351 |
*/
|
|
1352 |
||
482
by Brian Aker
Remove uint. |
1353 |
uint32_t catalog_len; // <= 255 char; 0 means uninited |
1
by brian
clean slate |
1354 |
|
1355 |
/*
|
|
1356 |
We want to be able to store a variable number of N-bit status vars:
|
|
1357 |
(generally N=32; but N=64 for SQL_MODE) a user may want to log the number
|
|
1358 |
of affected rows (for debugging) while another does not want to lose 4
|
|
1359 |
bytes in this.
|
|
1360 |
The storage on disk is the following:
|
|
1361 |
status_vars_len is part of the post-header,
|
|
1362 |
status_vars are in the variable-length part, after the post-header, before
|
|
1363 |
the db & query.
|
|
1364 |
status_vars on disk is a sequence of pairs (code, value) where 'code' means
|
|
1365 |
'sql_mode', 'affected' etc. Sometimes 'value' must be a short string, so
|
|
1366 |
its first byte is its length. For now the order of status vars is:
|
|
1367 |
flags2 - sql_mode - catalog - autoinc - charset
|
|
1368 |
We should add the same thing to Load_log_event, but in fact
|
|
1369 |
LOAD DATA INFILE is going to be logged with a new type of event (logging of
|
|
1370 |
the plain text query), so Load_log_event would be frozen, so no need. The
|
|
1371 |
new way of logging LOAD DATA INFILE would use a derived class of
|
|
1372 |
Query_log_event, so automatically benefit from the work already done for
|
|
1373 |
status variables in Query_log_event.
|
|
1374 |
*/
|
|
206
by Brian Aker
Removed final uint dead types. |
1375 |
uint16_t status_vars_len; |
1
by brian
clean slate |
1376 |
|
1377 |
/*
|
|
1378 |
'flags2' is a second set of flags (on top of those in Log_event), for
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1379 |
session variables. These are session->options which is & against a mask
|
1
by brian
clean slate |
1380 |
(OPTIONS_WRITTEN_TO_BIN_LOG).
|
1381 |
flags2_inited helps make a difference between flags2==0 (3.23 or 4.x
|
|
1382 |
master, we don't know flags2, so use the slave server's global options) and
|
|
1383 |
flags2==0 (5.0 master, we know this has a meaning of flags all down which
|
|
1384 |
must influence the query).
|
|
1385 |
*/
|
|
1386 |
bool flags2_inited; |
|
1387 |
bool sql_mode_inited; |
|
1388 |
bool charset_inited; |
|
1389 |
||
205
by Brian Aker
uint32 -> uin32_t |
1390 |
uint32_t flags2; |
1
by brian
clean slate |
1391 |
/* In connections sql_mode is 32 bits now but will be 64 bits soon */
|
1392 |
ulong sql_mode; |
|
1393 |
ulong auto_increment_increment, auto_increment_offset; |
|
1394 |
char charset[6]; |
|
482
by Brian Aker
Remove uint. |
1395 |
uint32_t time_zone_len; /* 0 means uninited */ |
1
by brian
clean slate |
1396 |
const char *time_zone_str; |
482
by Brian Aker
Remove uint. |
1397 |
uint32_t lc_time_names_number; /* 0 means en_US */ |
1398 |
uint32_t charset_database_number; |
|
1
by brian
clean slate |
1399 |
|
1400 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1401 |
Query_log_event(Session* session_arg, const char* query_arg, ulong query_length, |
1
by brian
clean slate |
1402 |
bool using_trans, bool suppress_use, |
520.1.21
by Brian Aker
THD -> Session rename |
1403 |
Session::killed_state killed_err_arg= Session::KILLED_NO_VALUE); |
1
by brian
clean slate |
1404 |
const char* get_db() { return db; } |
1405 |
void pack_info(Protocol* protocol); |
|
1406 |
||
1407 |
Query_log_event(); |
|
482
by Brian Aker
Remove uint. |
1408 |
Query_log_event(const char* buf, uint32_t event_len, |
1
by brian
clean slate |
1409 |
const Format_description_log_event *description_event, |
1410 |
Log_event_type event_type); |
|
1411 |
~Query_log_event() |
|
1412 |
{
|
|
1413 |
if (data_buf) |
|
481
by Brian Aker
Remove all of uchar. |
1414 |
free((unsigned char*) data_buf); |
1
by brian
clean slate |
1415 |
}
|
1416 |
Log_event_type get_type_code() { return QUERY_EVENT; } |
|
1417 |
bool write(IO_CACHE* file); |
|
520.9.3
by mordred
zomg. Solaris actually builds all the way!!! |
1418 |
virtual bool write_post_header_for_derived(IO_CACHE*) |
51.1.31
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1419 |
{ return false; } |
1
by brian
clean slate |
1420 |
bool is_valid() const { return query != 0; } |
1421 |
||
1422 |
/*
|
|
1423 |
Returns number of bytes additionaly written to post header by derived
|
|
1424 |
events (so far it is only Execute_load_query event).
|
|
1425 |
*/
|
|
1426 |
virtual ulong get_post_header_size_for_derived() { return 0; } |
|
1427 |
/* Writes derived event-specific part of post header. */
|
|
1428 |
||
1429 |
public: /* !!! Public in this patch to allow old usage */ |
|
1430 |
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli); |
|
1431 |
virtual int do_apply_event(Relay_log_info const *rli); |
|
1432 |
virtual int do_update_pos(Relay_log_info *rli); |
|
1433 |
||
1434 |
int do_apply_event(Relay_log_info const *rli, |
|
1435 |
const char *query_arg, |
|
205
by Brian Aker
uint32 -> uin32_t |
1436 |
uint32_t q_len_arg); |
1
by brian
clean slate |
1437 |
};
|
1438 |
||
1439 |
||
1440 |
/**
|
|
1441 |
@class Slave_log_event
|
|
1442 |
||
1443 |
Note that this class is currently not used at all; no code writes a
|
|
1444 |
@c Slave_log_event (though some code in @c repl_failsafe.cc reads @c
|
|
1445 |
Slave_log_event). So it's not a problem if this code is not
|
|
1446 |
maintained.
|
|
1447 |
||
1448 |
@section Slave_log_event_binary_format Binary Format
|
|
1449 |
||
1450 |
This event type has no Post-Header. The Body has the following
|
|
1451 |
four components.
|
|
1452 |
||
1453 |
<table>
|
|
1454 |
<caption>Body for Slave_log_event</caption>
|
|
1455 |
||
1456 |
<tr>
|
|
1457 |
<th>Name</th>
|
|
1458 |
<th>Format</th>
|
|
1459 |
<th>Description</th>
|
|
1460 |
</tr>
|
|
1461 |
||
1462 |
<tr>
|
|
1463 |
<td>master_pos</td>
|
|
1464 |
<td>8 byte integer</td>
|
|
1465 |
<td>???TODO
|
|
1466 |
</td>
|
|
1467 |
</tr>
|
|
1468 |
||
1469 |
<tr>
|
|
1470 |
<td>master_port</td>
|
|
1471 |
<td>2 byte integer</td>
|
|
1472 |
<td>???TODO</td>
|
|
1473 |
</tr>
|
|
1474 |
||
1475 |
<tr>
|
|
1476 |
<td>master_host</td>
|
|
1477 |
<td>null-terminated string</td>
|
|
1478 |
<td>???TODO</td>
|
|
1479 |
</tr>
|
|
1480 |
||
1481 |
<tr>
|
|
1482 |
<td>master_log</td>
|
|
1483 |
<td>null-terminated string</td>
|
|
1484 |
<td>???TODO</td>
|
|
1485 |
</tr>
|
|
1486 |
</table>
|
|
1487 |
*/
|
|
490
by Brian Aker
More effort around master.info (and relay.info) |
1488 |
|
1
by brian
clean slate |
1489 |
class Slave_log_event: public Log_event |
1490 |
{
|
|
1491 |
protected: |
|
1492 |
char* mem_pool; |
|
490
by Brian Aker
More effort around master.info (and relay.info) |
1493 |
void init_from_mem_pool(); |
1
by brian
clean slate |
1494 |
public: |
490
by Brian Aker
More effort around master.info (and relay.info) |
1495 |
off_t master_pos; |
1496 |
std::string master_host; |
|
1497 |
std::string master_log; |
|
206
by Brian Aker
Removed final uint dead types. |
1498 |
uint16_t master_port; |
1
by brian
clean slate |
1499 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1500 |
Slave_log_event(Session* session_arg, Relay_log_info* rli); |
1
by brian
clean slate |
1501 |
void pack_info(Protocol* protocol); |
1502 |
||
482
by Brian Aker
Remove uint. |
1503 |
Slave_log_event(const char* buf, uint32_t event_len); |
1
by brian
clean slate |
1504 |
~Slave_log_event(); |
1505 |
int get_data_size(); |
|
490
by Brian Aker
More effort around master.info (and relay.info) |
1506 |
bool is_valid() const { return master_host.length() != 0; } |
1
by brian
clean slate |
1507 |
Log_event_type get_type_code() { return SLAVE_EVENT; } |
1508 |
bool write(IO_CACHE* file); |
|
1509 |
||
1510 |
private: |
|
1511 |
virtual int do_apply_event(Relay_log_info const* rli); |
|
1512 |
};
|
|
1513 |
||
1514 |
||
1515 |
/**
|
|
1516 |
@class Load_log_event
|
|
1517 |
||
1518 |
This log event corresponds to a "LOAD DATA INFILE" SQL query on the
|
|
1519 |
following form:
|
|
1520 |
||
1521 |
@verbatim
|
|
1522 |
(1) USE db;
|
|
1523 |
(2) LOAD DATA [LOCAL] INFILE 'file_name'
|
|
1524 |
(3) [REPLACE | IGNORE]
|
|
327.1.5
by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h |
1525 |
(4) INTO Table 'table_name'
|
1
by brian
clean slate |
1526 |
(5) [FIELDS
|
1527 |
(6) [TERMINATED BY 'field_term']
|
|
1528 |
(7) [[OPTIONALLY] ENCLOSED BY 'enclosed']
|
|
1529 |
(8) [ESCAPED BY 'escaped']
|
|
1530 |
(9) ]
|
|
1531 |
(10) [LINES
|
|
1532 |
(11) [TERMINATED BY 'line_term']
|
|
1533 |
(12) [LINES STARTING BY 'line_start']
|
|
1534 |
(13) ]
|
|
1535 |
(14) [IGNORE skip_lines LINES]
|
|
1536 |
(15) (field_1, field_2, ..., field_n)@endverbatim
|
|
1537 |
||
1538 |
@section Load_log_event_binary_format Binary Format
|
|
1539 |
||
1540 |
The Post-Header consists of the following six components.
|
|
1541 |
||
1542 |
<table>
|
|
1543 |
<caption>Post-Header for Load_log_event</caption>
|
|
1544 |
||
1545 |
<tr>
|
|
1546 |
<th>Name</th>
|
|
1547 |
<th>Format</th>
|
|
1548 |
<th>Description</th>
|
|
1549 |
</tr>
|
|
1550 |
||
1551 |
<tr>
|
|
1552 |
<td>slave_proxy_id</td>
|
|
1553 |
<td>4 byte unsigned integer</td>
|
|
1554 |
<td>An integer identifying the client thread that issued the
|
|
1555 |
query. The id is unique per server. (Note, however, that two
|
|
1556 |
threads on different servers may have the same slave_proxy_id.)
|
|
1557 |
This is used when a client thread creates a temporary table local
|
|
1558 |
to the client. The slave_proxy_id is used to distinguish
|
|
1559 |
temporary tables that belong to different clients.
|
|
1560 |
</td>
|
|
1561 |
</tr>
|
|
1562 |
||
1563 |
<tr>
|
|
1564 |
<td>exec_time</td>
|
|
1565 |
<td>4 byte unsigned integer</td>
|
|
1566 |
<td>The time from when the query started to when it was logged in
|
|
1567 |
the binlog, in seconds.</td>
|
|
1568 |
</tr>
|
|
1569 |
||
1570 |
<tr>
|
|
1571 |
<td>skip_lines</td>
|
|
1572 |
<td>4 byte unsigned integer</td>
|
|
1573 |
<td>The number on line (14) above, if present, or 0 if line (14)
|
|
1574 |
is left out.
|
|
1575 |
</td>
|
|
1576 |
</tr>
|
|
1577 |
||
1578 |
<tr>
|
|
1579 |
<td>table_name_len</td>
|
|
1580 |
<td>1 byte unsigned integer</td>
|
|
1581 |
<td>The length of 'table_name' on line (4) above.</td>
|
|
1582 |
</tr>
|
|
1583 |
||
1584 |
<tr>
|
|
1585 |
<td>db_len</td>
|
|
1586 |
<td>1 byte unsigned integer</td>
|
|
1587 |
<td>The length of 'db' on line (1) above.</td>
|
|
1588 |
</tr>
|
|
1589 |
||
1590 |
<tr>
|
|
1591 |
<td>num_fields</td>
|
|
1592 |
<td>4 byte unsigned integer</td>
|
|
1593 |
<td>The number n of fields on line (15) above.</td>
|
|
1594 |
</tr>
|
|
1595 |
</table>
|
|
1596 |
||
1597 |
The Body contains the following components.
|
|
1598 |
||
1599 |
<table>
|
|
1600 |
<caption>Body of Load_log_event</caption>
|
|
1601 |
||
1602 |
<tr>
|
|
1603 |
<th>Name</th>
|
|
1604 |
<th>Format</th>
|
|
1605 |
<th>Description</th>
|
|
1606 |
</tr>
|
|
1607 |
||
1608 |
<tr>
|
|
1609 |
<td>sql_ex</td>
|
|
1610 |
<td>variable length</td>
|
|
1611 |
||
1612 |
<td>Describes the part of the query on lines (3) and
|
|
1613 |
(5)–(13) above. More precisely, it stores the five strings
|
|
1614 |
(on lines) field_term (6), enclosed (7), escaped (8), line_term
|
|
1615 |
(11), and line_start (12); as well as a bitfield indicating the
|
|
1616 |
presence of the keywords REPLACE (3), IGNORE (3), and OPTIONALLY
|
|
1617 |
(7).
|
|
1618 |
||
1619 |
The data is stored in one of two formats, called "old" and "new".
|
|
1620 |
The type field of Common-Header determines which of these two
|
|
1621 |
formats is used: type LOAD_EVENT means that the old format is
|
|
1622 |
used, and type NEW_LOAD_EVENT means that the new format is used.
|
|
1623 |
When MySQL writes a Load_log_event, it uses the new format if at
|
|
1624 |
least one of the five strings is two or more bytes long.
|
|
1625 |
Otherwise (i.e., if all strings are 0 or 1 bytes long), the old
|
|
1626 |
format is used.
|
|
1627 |
||
1628 |
The new and old format differ in the way the five strings are
|
|
1629 |
stored.
|
|
1630 |
||
1631 |
<ul>
|
|
1632 |
<li> In the new format, the strings are stored in the order
|
|
1633 |
field_term, enclosed, escaped, line_term, line_start. Each string
|
|
1634 |
consists of a length (1 byte), followed by a sequence of
|
|
1635 |
characters (0-255 bytes). Finally, a boolean combination of the
|
|
1636 |
following flags is stored in 1 byte: REPLACE_FLAG==0x4,
|
|
1637 |
IGNORE_FLAG==0x8, and OPT_ENCLOSED_FLAG==0x2. If a flag is set,
|
|
1638 |
it indicates the presence of the corresponding keyword in the SQL
|
|
1639 |
query.
|
|
1640 |
||
1641 |
<li> In the old format, we know that each string has length 0 or
|
|
1642 |
1. Therefore, only the first byte of each string is stored. The
|
|
1643 |
order of the strings is the same as in the new format. These five
|
|
1644 |
bytes are followed by the same 1 byte bitfield as in the new
|
|
1645 |
format. Finally, a 1 byte bitfield called empty_flags is stored.
|
|
1646 |
The low 5 bits of empty_flags indicate which of the five strings
|
|
1647 |
have length 0. For each of the following flags that is set, the
|
|
1648 |
corresponding string has length 0; for the flags that are not set,
|
|
1649 |
the string has length 1: FIELD_TERM_EMPTY==0x1,
|
|
1650 |
ENCLOSED_EMPTY==0x2, LINE_TERM_EMPTY==0x4, LINE_START_EMPTY==0x8,
|
|
1651 |
ESCAPED_EMPTY==0x10.
|
|
1652 |
</ul>
|
|
1653 |
||
1654 |
Thus, the size of the new format is 6 bytes + the sum of the sizes
|
|
1655 |
of the five strings. The size of the old format is always 7
|
|
1656 |
bytes.
|
|
1657 |
</td>
|
|
1658 |
</tr>
|
|
1659 |
||
1660 |
<tr>
|
|
1661 |
<td>field_lens</td>
|
|
1662 |
<td>num_fields 1 byte unsigned integers</td>
|
|
1663 |
<td>An array of num_fields integers representing the length of
|
|
1664 |
each field in the query. (num_fields is from the Post-Header).
|
|
1665 |
</td>
|
|
1666 |
</tr>
|
|
1667 |
||
1668 |
<tr>
|
|
1669 |
<td>fields</td>
|
|
1670 |
<td>num_fields null-terminated strings</td>
|
|
1671 |
<td>An array of num_fields null-terminated strings, each
|
|
1672 |
representing a field in the query. (The trailing zero is
|
|
1673 |
redundant, since the length are stored in the num_fields array.)
|
|
1674 |
The total length of all strings equals to the sum of all
|
|
1675 |
field_lens, plus num_fields bytes for all the trailing zeros.
|
|
1676 |
</td>
|
|
1677 |
</tr>
|
|
1678 |
||
1679 |
<tr>
|
|
1680 |
<td>table_name</td>
|
|
1681 |
<td>null-terminated string of length table_len+1 bytes</td>
|
|
1682 |
<td>The 'table_name' from the query, as a null-terminated string.
|
|
1683 |
(The trailing zero is actually redundant since the table_len is
|
|
1684 |
known from Post-Header.)
|
|
1685 |
</td>
|
|
1686 |
</tr>
|
|
1687 |
||
1688 |
<tr>
|
|
1689 |
<td>db</td>
|
|
1690 |
<td>null-terminated string of length db_len+1 bytes</td>
|
|
1691 |
<td>The 'db' from the query, as a null-terminated string.
|
|
1692 |
(The trailing zero is actually redundant since the db_len is known
|
|
1693 |
from Post-Header.)
|
|
1694 |
</td>
|
|
1695 |
</tr>
|
|
1696 |
||
1697 |
<tr>
|
|
1698 |
<td>file_name</td>
|
|
1699 |
<td>variable length string without trailing zero, extending to the
|
|
1700 |
end of the event (determined by the length field of the
|
|
1701 |
Common-Header)
|
|
1702 |
</td>
|
|
1703 |
<td>The 'file_name' from the query.
|
|
1704 |
</td>
|
|
1705 |
</tr>
|
|
1706 |
||
1707 |
</table>
|
|
1708 |
||
1709 |
@subsection Load_log_event_notes_on_previous_versions Notes on Previous Versions
|
|
1710 |
||
1711 |
This event type is understood by current versions, but only
|
|
1712 |
generated by MySQL 3.23 and earlier.
|
|
1713 |
*/
|
|
1714 |
class Load_log_event: public Log_event |
|
1715 |
{
|
|
1716 |
private: |
|
482
by Brian Aker
Remove uint. |
1717 |
uint32_t get_query_buffer_length(); |
1
by brian
clean slate |
1718 |
void print_query(bool need_db, char *buf, char **end, |
1719 |
char **fn_start, char **fn_end); |
|
1720 |
protected: |
|
1721 |
int copy_log_event(const char *buf, ulong event_len, |
|
1722 |
int body_offset, |
|
1723 |
const Format_description_log_event* description_event); |
|
1724 |
||
1725 |
public: |
|
1726 |
ulong thread_id; |
|
1727 |
ulong slave_proxy_id; |
|
205
by Brian Aker
uint32 -> uin32_t |
1728 |
uint32_t table_name_len; |
1
by brian
clean slate |
1729 |
/*
|
1730 |
No need to have a catalog, as these events can only come from 4.x.
|
|
1731 |
TODO: this may become false if Dmitri pushes his new LOAD DATA INFILE in
|
|
1732 |
5.0 only (not in 4.x).
|
|
1733 |
*/
|
|
205
by Brian Aker
uint32 -> uin32_t |
1734 |
uint32_t db_len; |
1735 |
uint32_t fname_len; |
|
1736 |
uint32_t num_fields; |
|
1
by brian
clean slate |
1737 |
const char* fields; |
481
by Brian Aker
Remove all of uchar. |
1738 |
const unsigned char* field_lens; |
205
by Brian Aker
uint32 -> uin32_t |
1739 |
uint32_t field_block_len; |
1
by brian
clean slate |
1740 |
|
1741 |
const char* table_name; |
|
1742 |
const char* db; |
|
1743 |
const char* fname; |
|
205
by Brian Aker
uint32 -> uin32_t |
1744 |
uint32_t skip_lines; |
1
by brian
clean slate |
1745 |
sql_ex_info sql_ex; |
1746 |
bool local_fname; |
|
1747 |
||
1748 |
/* fname doesn't point to memory inside Log_event::temp_buf */
|
|
482
by Brian Aker
Remove uint. |
1749 |
void set_fname_outside_temp_buf(const char *afname, uint32_t alen) |
1
by brian
clean slate |
1750 |
{
|
1751 |
fname= afname; |
|
1752 |
fname_len= alen; |
|
51.1.31
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
1753 |
local_fname= true; |
1
by brian
clean slate |
1754 |
}
|
1755 |
/* fname doesn't point to memory inside Log_event::temp_buf */
|
|
1756 |
int check_fname_outside_temp_buf() |
|
1757 |
{
|
|
1758 |
return local_fname; |
|
1759 |
}
|
|
1760 |
||
1761 |
String field_lens_buf; |
|
1762 |
String fields_buf; |
|
1763 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1764 |
Load_log_event(Session* session, sql_exchange* ex, const char* db_arg, |
1
by brian
clean slate |
1765 |
const char* table_name_arg, |
1766 |
List<Item>& fields_arg, enum enum_duplicates handle_dup, bool ignore, |
|
1767 |
bool using_trans); |
|
1768 |
void set_fields(const char* db, List<Item> &fields_arg, |
|
1769 |
Name_resolution_context *context); |
|
1770 |
const char* get_db() { return db; } |
|
1771 |
void pack_info(Protocol* protocol); |
|
1772 |
||
1773 |
/*
|
|
1774 |
Note that for all the events related to LOAD DATA (Load_log_event,
|
|
1775 |
Create_file/Append/Exec/Delete, we pass description_event; however as
|
|
1776 |
logging of LOAD DATA is going to be changed in 4.1 or 5.0, this is only used
|
|
1777 |
for the common_header_len (post_header_len will not be changed).
|
|
1778 |
*/
|
|
482
by Brian Aker
Remove uint. |
1779 |
Load_log_event(const char* buf, uint32_t event_len, |
1
by brian
clean slate |
1780 |
const Format_description_log_event* description_event); |
1781 |
~Load_log_event() |
|
1782 |
{}
|
|
1783 |
Log_event_type get_type_code() |
|
1784 |
{
|
|
1785 |
return sql_ex.new_format() ? NEW_LOAD_EVENT: LOAD_EVENT; |
|
1786 |
}
|
|
1787 |
bool write_data_header(IO_CACHE* file); |
|
1788 |
bool write_data_body(IO_CACHE* file); |
|
1789 |
bool is_valid() const { return table_name != 0; } |
|
1790 |
int get_data_size() |
|
1791 |
{
|
|
1792 |
return (table_name_len + db_len + 2 + fname_len |
|
1793 |
+ LOAD_HEADER_LEN |
|
1794 |
+ sql_ex.data_size() + field_block_len + num_fields); |
|
1795 |
}
|
|
1796 |
||
1797 |
public: /* !!! Public in this patch to allow old usage */ |
|
1798 |
virtual int do_apply_event(Relay_log_info const* rli) |
|
1799 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1800 |
return do_apply_event(session->slave_net,rli,0); |
1
by brian
clean slate |
1801 |
}
|
1802 |
||
1803 |
int do_apply_event(NET *net, Relay_log_info const *rli, |
|
1804 |
bool use_rli_only_for_errors); |
|
1805 |
};
|
|
1806 |
||
1807 |
extern char server_version[SERVER_VERSION_LENGTH]; |
|
1808 |
||
1809 |
/**
|
|
1810 |
@class Start_log_event_v3
|
|
1811 |
||
1812 |
Start_log_event_v3 is the Start_log_event of binlog format 3 (MySQL 3.23 and
|
|
1813 |
4.x).
|
|
1814 |
||
1815 |
Format_description_log_event derives from Start_log_event_v3; it is
|
|
1816 |
the Start_log_event of binlog format 4 (MySQL 5.0), that is, the
|
|
1817 |
event that describes the other events' Common-Header/Post-Header
|
|
1818 |
lengths. This event is sent by MySQL 5.0 whenever it starts sending
|
|
1819 |
a new binlog if the requested position is >4 (otherwise if ==4 the
|
|
1820 |
event will be sent naturally).
|
|
1821 |
||
1822 |
@section Start_log_event_v3_binary_format Binary Format
|
|
1823 |
*/
|
|
1824 |
class Start_log_event_v3: public Log_event |
|
1825 |
{
|
|
1826 |
public: |
|
1827 |
/*
|
|
1828 |
If this event is at the start of the first binary log since server
|
|
1829 |
startup 'created' should be the timestamp when the event (and the
|
|
1830 |
binary log) was created. In the other case (i.e. this event is at
|
|
1831 |
the start of a binary log created by FLUSH LOGS or automatic
|
|
1832 |
rotation), 'created' should be 0. This "trick" is used by MySQL
|
|
1833 |
>=4.0.14 slaves to know whether they must drop stale temporary
|
|
1834 |
tables and whether they should abort unfinished transaction.
|
|
1835 |
||
1836 |
Note that when 'created'!=0, it is always equal to the event's
|
|
1837 |
timestamp; indeed Start_log_event is written only in log.cc where
|
|
1838 |
the first constructor below is called, in which 'created' is set
|
|
1839 |
to 'when'. So in fact 'created' is a useless variable. When it is
|
|
1840 |
0 we can read the actual value from timestamp ('when') and when it
|
|
1841 |
is non-zero we can read the same value from timestamp
|
|
1842 |
('when'). Conclusion:
|
|
1843 |
- we use timestamp to print when the binlog was created.
|
|
1844 |
- we use 'created' only to know if this is a first binlog or not.
|
|
1845 |
In 3.23.57 we did not pay attention to this identity, so mysqlbinlog in
|
|
1846 |
3.23.57 does not print 'created the_date' if created was zero. This is now
|
|
1847 |
fixed.
|
|
1848 |
*/
|
|
1849 |
time_t created; |
|
206
by Brian Aker
Removed final uint dead types. |
1850 |
uint16_t binlog_version; |
1
by brian
clean slate |
1851 |
char server_version[ST_SERVER_VER_LEN]; |
1852 |
/*
|
|
1853 |
artifical_event is 1 in the case where this is a generated event that
|
|
1854 |
should not case any cleanup actions. We handle this in the log by
|
|
1855 |
setting log_event == 0 (for now).
|
|
1856 |
*/
|
|
1857 |
bool artificial_event; |
|
1858 |
/*
|
|
1859 |
We set this to 1 if we don't want to have the created time in the log,
|
|
1860 |
which is the case when we rollover to a new log.
|
|
1861 |
*/
|
|
1862 |
bool dont_set_created; |
|
1863 |
||
1864 |
Start_log_event_v3(); |
|
1865 |
void pack_info(Protocol* protocol); |
|
1866 |
||
1867 |
Start_log_event_v3(const char* buf, |
|
1868 |
const Format_description_log_event* description_event); |
|
1869 |
~Start_log_event_v3() {} |
|
1870 |
Log_event_type get_type_code() { return START_EVENT_V3;} |
|
1871 |
bool write(IO_CACHE* file); |
|
1872 |
bool is_valid() const { return 1; } |
|
1873 |
int get_data_size() |
|
1874 |
{
|
|
1875 |
return START_V3_HEADER_LEN; //no variable-sized part |
|
1876 |
}
|
|
1877 |
virtual bool is_artificial_event() { return artificial_event; } |
|
1878 |
||
1879 |
protected: |
|
1880 |
virtual int do_apply_event(Relay_log_info const *rli); |
|
1881 |
virtual enum_skip_reason do_shall_skip(Relay_log_info*) |
|
1882 |
{
|
|
1883 |
/*
|
|
1884 |
Events from ourself should be skipped, but they should not
|
|
1885 |
decrease the slave skip counter.
|
|
1886 |
*/
|
|
1887 |
if (this->server_id == ::server_id) |
|
1888 |
return Log_event::EVENT_SKIP_IGNORE; |
|
1889 |
else
|
|
1890 |
return Log_event::EVENT_SKIP_NOT; |
|
1891 |
}
|
|
1892 |
};
|
|
1893 |
||
1894 |
||
1895 |
/**
|
|
1896 |
@class Format_description_log_event
|
|
1897 |
||
1898 |
For binlog version 4.
|
|
1899 |
This event is saved by threads which read it, as they need it for future
|
|
1900 |
use (to decode the ordinary events).
|
|
1901 |
||
1902 |
@section Format_description_log_event_binary_format Binary Format
|
|
1903 |
*/
|
|
1904 |
||
1905 |
class Format_description_log_event: public Start_log_event_v3 |
|
1906 |
{
|
|
1907 |
public: |
|
1908 |
/*
|
|
1909 |
The size of the fixed header which _all_ events have
|
|
1910 |
(for binlogs written by this version, this is equal to
|
|
1911 |
LOG_EVENT_HEADER_LEN), except FORMAT_DESCRIPTION_EVENT and ROTATE_EVENT
|
|
1912 |
(those have a header of size LOG_EVENT_MINIMAL_HEADER_LEN).
|
|
1913 |
*/
|
|
206
by Brian Aker
Removed final uint dead types. |
1914 |
uint8_t common_header_len; |
1915 |
uint8_t number_of_event_types; |
|
1
by brian
clean slate |
1916 |
/* The list of post-headers' lengthes */
|
206
by Brian Aker
Removed final uint dead types. |
1917 |
uint8_t *post_header_len; |
481
by Brian Aker
Remove all of uchar. |
1918 |
unsigned char server_version_split[3]; |
206
by Brian Aker
Removed final uint dead types. |
1919 |
const uint8_t *event_type_permutation; |
1
by brian
clean slate |
1920 |
|
206
by Brian Aker
Removed final uint dead types. |
1921 |
Format_description_log_event(uint8_t binlog_ver, const char* server_ver=0); |
482
by Brian Aker
Remove uint. |
1922 |
Format_description_log_event(const char* buf, uint32_t event_len, |
1
by brian
clean slate |
1923 |
const Format_description_log_event |
1924 |
*description_event); |
|
1925 |
~Format_description_log_event() |
|
1926 |
{
|
|
481
by Brian Aker
Remove all of uchar. |
1927 |
free((unsigned char*)post_header_len); |
1
by brian
clean slate |
1928 |
}
|
1929 |
Log_event_type get_type_code() { return FORMAT_DESCRIPTION_EVENT;} |
|
1930 |
bool write(IO_CACHE* file); |
|
1931 |
bool is_valid() const |
|
1932 |
{
|
|
1933 |
return ((common_header_len >= ((binlog_version==1) ? OLD_HEADER_LEN : |
|
1934 |
LOG_EVENT_MINIMAL_HEADER_LEN)) && |
|
1935 |
(post_header_len != NULL)); |
|
1936 |
}
|
|
1937 |
int get_data_size() |
|
1938 |
{
|
|
1939 |
/*
|
|
1940 |
The vector of post-header lengths is considered as part of the
|
|
1941 |
post-header, because in a given version it never changes (contrary to the
|
|
1942 |
query in a Query_log_event).
|
|
1943 |
*/
|
|
1944 |
return FORMAT_DESCRIPTION_HEADER_LEN; |
|
1945 |
}
|
|
1946 |
||
1947 |
void calc_server_version_split(); |
|
1948 |
||
1949 |
protected: |
|
1950 |
virtual int do_apply_event(Relay_log_info const *rli); |
|
1951 |
virtual int do_update_pos(Relay_log_info *rli); |
|
1952 |
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli); |
|
1953 |
};
|
|
1954 |
||
1955 |
/**
|
|
1956 |
@class Xid_log_event
|
|
1957 |
||
1958 |
Logs xid of the transaction-to-be-committed in the 2pc protocol.
|
|
1959 |
Has no meaning in replication, slaves ignore it.
|
|
1960 |
||
1961 |
@section Xid_log_event_binary_format Binary Format
|
|
1962 |
*/
|
|
1963 |
class Xid_log_event: public Log_event |
|
1964 |
{
|
|
1965 |
public: |
|
1966 |
my_xid xid; |
|
1967 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1968 |
Xid_log_event(Session* session_arg, my_xid x): Log_event(session_arg,0,0), xid(x) {} |
1
by brian
clean slate |
1969 |
void pack_info(Protocol* protocol); |
1970 |
||
1971 |
Xid_log_event(const char* buf, |
|
1972 |
const Format_description_log_event *description_event); |
|
1973 |
~Xid_log_event() {} |
|
1974 |
Log_event_type get_type_code() { return XID_EVENT;} |
|
1975 |
int get_data_size() { return sizeof(xid); } |
|
1976 |
bool write(IO_CACHE* file); |
|
1977 |
bool is_valid() const { return 1; } |
|
1978 |
||
1979 |
private: |
|
1980 |
virtual int do_apply_event(Relay_log_info const *rli); |
|
1981 |
enum_skip_reason do_shall_skip(Relay_log_info *rli); |
|
1982 |
};
|
|
1983 |
||
1984 |
||
1985 |
/**
|
|
1986 |
@class Stop_log_event
|
|
1987 |
||
1988 |
@section Stop_log_event_binary_format Binary Format
|
|
1989 |
||
1990 |
The Post-Header and Body for this event type are empty; it only has
|
|
1991 |
the Common-Header.
|
|
1992 |
*/
|
|
1993 |
class Stop_log_event: public Log_event |
|
1994 |
{
|
|
1995 |
public: |
|
1996 |
Stop_log_event() :Log_event() |
|
1997 |
{}
|
|
1998 |
||
1999 |
Stop_log_event(const char* buf, |
|
2000 |
const Format_description_log_event *description_event): |
|
2001 |
Log_event(buf, description_event) |
|
2002 |
{}
|
|
2003 |
~Stop_log_event() {} |
|
2004 |
Log_event_type get_type_code() { return STOP_EVENT;} |
|
2005 |
bool is_valid() const { return 1; } |
|
2006 |
||
2007 |
private: |
|
2008 |
virtual int do_update_pos(Relay_log_info *rli); |
|
520.9.3
by mordred
zomg. Solaris actually builds all the way!!! |
2009 |
virtual enum_skip_reason do_shall_skip(Relay_log_info *) |
1
by brian
clean slate |
2010 |
{
|
2011 |
/*
|
|
2012 |
Events from ourself should be skipped, but they should not
|
|
2013 |
decrease the slave skip counter.
|
|
2014 |
*/
|
|
2015 |
if (this->server_id == ::server_id) |
|
2016 |
return Log_event::EVENT_SKIP_IGNORE; |
|
2017 |
else
|
|
2018 |
return Log_event::EVENT_SKIP_NOT; |
|
2019 |
}
|
|
2020 |
};
|
|
2021 |
||
2022 |
/**
|
|
2023 |
@class Rotate_log_event
|
|
2024 |
||
2025 |
This will be deprecated when we move to using sequence ids.
|
|
2026 |
||
2027 |
@section Rotate_log_event_binary_format Binary Format
|
|
2028 |
||
2029 |
The Post-Header has one component:
|
|
2030 |
||
2031 |
<table>
|
|
2032 |
<caption>Post-Header for Rotate_log_event</caption>
|
|
2033 |
||
2034 |
<tr>
|
|
2035 |
<th>Name</th>
|
|
2036 |
<th>Format</th>
|
|
2037 |
<th>Description</th>
|
|
2038 |
</tr>
|
|
2039 |
||
2040 |
<tr>
|
|
2041 |
<td>position</td>
|
|
2042 |
<td>8 byte integer</td>
|
|
2043 |
<td>The position within the binlog to rotate to.</td>
|
|
2044 |
</tr>
|
|
2045 |
||
2046 |
</table>
|
|
2047 |
||
2048 |
The Body has one component:
|
|
2049 |
||
2050 |
<table>
|
|
2051 |
<caption>Body for Rotate_log_event</caption>
|
|
2052 |
||
2053 |
<tr>
|
|
2054 |
<th>Name</th>
|
|
2055 |
<th>Format</th>
|
|
2056 |
<th>Description</th>
|
|
2057 |
</tr>
|
|
2058 |
||
2059 |
<tr>
|
|
2060 |
<td>new_log</td>
|
|
2061 |
<td>variable length string without trailing zero, extending to the
|
|
2062 |
end of the event (determined by the length field of the
|
|
2063 |
Common-Header)
|
|
2064 |
</td>
|
|
2065 |
<td>Name of the binlog to rotate to.</td>
|
|
2066 |
</tr>
|
|
2067 |
||
2068 |
</table>
|
|
2069 |
*/
|
|
2070 |
||
2071 |
class Rotate_log_event: public Log_event |
|
2072 |
{
|
|
2073 |
public: |
|
2074 |
enum { |
|
2075 |
DUP_NAME= 2 // if constructor should dup the string argument |
|
2076 |
};
|
|
2077 |
const char* new_log_ident; |
|
151
by Brian Aker
Ulonglong to uint64_t |
2078 |
uint64_t pos; |
482
by Brian Aker
Remove uint. |
2079 |
uint32_t ident_len; |
2080 |
uint32_t flags; |
|
1
by brian
clean slate |
2081 |
Rotate_log_event(const char* new_log_ident_arg, |
482
by Brian Aker
Remove uint. |
2082 |
uint32_t ident_len_arg, |
2083 |
uint64_t pos_arg, uint32_t flags); |
|
1
by brian
clean slate |
2084 |
void pack_info(Protocol* protocol); |
2085 |
||
482
by Brian Aker
Remove uint. |
2086 |
Rotate_log_event(const char* buf, uint32_t event_len, |
1
by brian
clean slate |
2087 |
const Format_description_log_event* description_event); |
2088 |
~Rotate_log_event() |
|
2089 |
{
|
|
2090 |
if (flags & DUP_NAME) |
|
481
by Brian Aker
Remove all of uchar. |
2091 |
free((unsigned char*) new_log_ident); |
1
by brian
clean slate |
2092 |
}
|
2093 |
Log_event_type get_type_code() { return ROTATE_EVENT;} |
|
2094 |
int get_data_size() { return ident_len + ROTATE_HEADER_LEN;} |
|
2095 |
bool is_valid() const { return new_log_ident != 0; } |
|
2096 |
bool write(IO_CACHE* file); |
|
2097 |
||
2098 |
private: |
|
2099 |
virtual int do_update_pos(Relay_log_info *rli); |
|
2100 |
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli); |
|
2101 |
};
|
|
2102 |
||
2103 |
||
2104 |
/* the classes below are for the new LOAD DATA INFILE logging */
|
|
2105 |
||
2106 |
/**
|
|
2107 |
@class Create_file_log_event
|
|
2108 |
||
2109 |
@section Create_file_log_event_binary_format Binary Format
|
|
2110 |
*/
|
|
2111 |
||
2112 |
class Create_file_log_event: public Load_log_event |
|
2113 |
{
|
|
2114 |
protected: |
|
2115 |
/*
|
|
2116 |
Pretend we are Load event, so we can write out just
|
|
2117 |
our Load part - used on the slave when writing event out to
|
|
2118 |
SQL_LOAD-*.info file
|
|
2119 |
*/
|
|
2120 |
bool fake_base; |
|
2121 |
public: |
|
481
by Brian Aker
Remove all of uchar. |
2122 |
unsigned char* block; |
1
by brian
clean slate |
2123 |
const char *event_buf; |
482
by Brian Aker
Remove uint. |
2124 |
uint32_t block_len; |
2125 |
uint32_t file_id; |
|
1
by brian
clean slate |
2126 |
bool inited_from_old; |
2127 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
2128 |
Create_file_log_event(Session* session, sql_exchange* ex, const char* db_arg, |
1
by brian
clean slate |
2129 |
const char* table_name_arg, |
2130 |
List<Item>& fields_arg, |
|
2131 |
enum enum_duplicates handle_dup, bool ignore, |
|
482
by Brian Aker
Remove uint. |
2132 |
unsigned char* block_arg, uint32_t block_len_arg, |
1
by brian
clean slate |
2133 |
bool using_trans); |
2134 |
void pack_info(Protocol* protocol); |
|
2135 |
||
482
by Brian Aker
Remove uint. |
2136 |
Create_file_log_event(const char* buf, uint32_t event_len, |
1
by brian
clean slate |
2137 |
const Format_description_log_event* description_event); |
2138 |
~Create_file_log_event() |
|
2139 |
{
|
|
477
by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that. |
2140 |
free((char*) event_buf); |
1
by brian
clean slate |
2141 |
}
|
2142 |
||
2143 |
Log_event_type get_type_code() |
|
2144 |
{
|
|
2145 |
return fake_base ? Load_log_event::get_type_code() : CREATE_FILE_EVENT; |
|
2146 |
}
|
|
2147 |
int get_data_size() |
|
2148 |
{
|
|
2149 |
return (fake_base ? Load_log_event::get_data_size() : |
|
2150 |
Load_log_event::get_data_size() + |
|
2151 |
4 + 1 + block_len); |
|
2152 |
}
|
|
2153 |
bool is_valid() const { return inited_from_old || block != 0; } |
|
2154 |
bool write_data_header(IO_CACHE* file); |
|
2155 |
bool write_data_body(IO_CACHE* file); |
|
2156 |
/*
|
|
2157 |
Cut out Create_file extentions and
|
|
2158 |
write it as Load event - used on the slave
|
|
2159 |
*/
|
|
2160 |
bool write_base(IO_CACHE* file); |
|
2161 |
||
2162 |
private: |
|
2163 |
virtual int do_apply_event(Relay_log_info const *rli); |
|
2164 |
};
|
|
2165 |
||
2166 |
||
2167 |
/**
|
|
2168 |
@class Append_block_log_event
|
|
2169 |
||
2170 |
@section Append_block_log_event_binary_format Binary Format
|
|
2171 |
*/
|
|
2172 |
||
2173 |
class Append_block_log_event: public Log_event |
|
2174 |
{
|
|
2175 |
public: |
|
481
by Brian Aker
Remove all of uchar. |
2176 |
unsigned char* block; |
482
by Brian Aker
Remove uint. |
2177 |
uint32_t block_len; |
2178 |
uint32_t file_id; |
|
1
by brian
clean slate |
2179 |
/*
|
2180 |
'db' is filled when the event is created in mysql_load() (the
|
|
2181 |
event needs to have a 'db' member to be well filtered by
|
|
2182 |
binlog-*-db rules). 'db' is not written to the binlog (it's not
|
|
2183 |
used by Append_block_log_event::write()), so it can't be read in
|
|
2184 |
the Append_block_log_event(const char* buf, int event_len)
|
|
2185 |
constructor. In other words, 'db' is used only for filtering by
|
|
2186 |
binlog-*-db rules. Create_file_log_event is different: it's 'db'
|
|
2187 |
(which is inherited from Load_log_event) is written to the binlog
|
|
2188 |
and can be re-read.
|
|
2189 |
*/
|
|
2190 |
const char* db; |
|
2191 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
2192 |
Append_block_log_event(Session* session, const char* db_arg, unsigned char* block_arg, |
482
by Brian Aker
Remove uint. |
2193 |
uint32_t block_len_arg, bool using_trans); |
1
by brian
clean slate |
2194 |
void pack_info(Protocol* protocol); |
2195 |
virtual int get_create_or_append() const; |
|
2196 |
||
482
by Brian Aker
Remove uint. |
2197 |
Append_block_log_event(const char* buf, uint32_t event_len, |
1
by brian
clean slate |
2198 |
const Format_description_log_event |
2199 |
*description_event); |
|
2200 |
~Append_block_log_event() {} |
|
2201 |
Log_event_type get_type_code() { return APPEND_BLOCK_EVENT;} |
|
2202 |
int get_data_size() { return block_len + APPEND_BLOCK_HEADER_LEN ;} |
|
2203 |
bool is_valid() const { return block != 0; } |
|
2204 |
bool write(IO_CACHE* file); |
|
2205 |
const char* get_db() { return db; } |
|
2206 |
||
2207 |
private: |
|
2208 |
virtual int do_apply_event(Relay_log_info const *rli); |
|
2209 |
};
|
|
2210 |
||
2211 |
||
2212 |
/**
|
|
2213 |
@class Delete_file_log_event
|
|
2214 |
||
2215 |
@section Delete_file_log_event_binary_format Binary Format
|
|
2216 |
*/
|
|
2217 |
||
2218 |
class Delete_file_log_event: public Log_event |
|
2219 |
{
|
|
2220 |
public: |
|
482
by Brian Aker
Remove uint. |
2221 |
uint32_t file_id; |
1
by brian
clean slate |
2222 |
const char* db; /* see comment in Append_block_log_event */ |
2223 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
2224 |
Delete_file_log_event(Session* session, const char* db_arg, bool using_trans); |
1
by brian
clean slate |
2225 |
void pack_info(Protocol* protocol); |
2226 |
||
482
by Brian Aker
Remove uint. |
2227 |
Delete_file_log_event(const char* buf, uint32_t event_len, |
1
by brian
clean slate |
2228 |
const Format_description_log_event* description_event); |
2229 |
~Delete_file_log_event() {} |
|
2230 |
Log_event_type get_type_code() { return DELETE_FILE_EVENT;} |
|
2231 |
int get_data_size() { return DELETE_FILE_HEADER_LEN ;} |
|
2232 |
bool is_valid() const { return file_id != 0; } |
|
2233 |
bool write(IO_CACHE* file); |
|
2234 |
const char* get_db() { return db; } |
|
2235 |
||
2236 |
private: |
|
2237 |
virtual int do_apply_event(Relay_log_info const *rli); |
|
2238 |
};
|
|
2239 |
||
2240 |
||
2241 |
/**
|
|
2242 |
@class Execute_load_log_event
|
|
2243 |
||
2244 |
@section Delete_file_log_event_binary_format Binary Format
|
|
2245 |
*/
|
|
2246 |
||
2247 |
class Execute_load_log_event: public Log_event |
|
2248 |
{
|
|
2249 |
public: |
|
482
by Brian Aker
Remove uint. |
2250 |
uint32_t file_id; |
1
by brian
clean slate |
2251 |
const char* db; /* see comment in Append_block_log_event */ |
2252 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
2253 |
Execute_load_log_event(Session* session, const char* db_arg, bool using_trans); |
1
by brian
clean slate |
2254 |
void pack_info(Protocol* protocol); |
2255 |
||
482
by Brian Aker
Remove uint. |
2256 |
Execute_load_log_event(const char* buf, uint32_t event_len, |
1
by brian
clean slate |
2257 |
const Format_description_log_event |
2258 |
*description_event); |
|
2259 |
~Execute_load_log_event() {} |
|
2260 |
Log_event_type get_type_code() { return EXEC_LOAD_EVENT;} |
|
2261 |
int get_data_size() { return EXEC_LOAD_HEADER_LEN ;} |
|
2262 |
bool is_valid() const { return file_id != 0; } |
|
2263 |
bool write(IO_CACHE* file); |
|
2264 |
const char* get_db() { return db; } |
|
2265 |
||
2266 |
private: |
|
2267 |
virtual int do_apply_event(Relay_log_info const *rli); |
|
2268 |
};
|
|
2269 |
||
2270 |
||
2271 |
/**
|
|
2272 |
@class Begin_load_query_log_event
|
|
2273 |
||
2274 |
Event for the first block of file to be loaded, its only difference from
|
|
2275 |
Append_block event is that this event creates or truncates existing file
|
|
2276 |
before writing data.
|
|
2277 |
||
2278 |
@section Begin_load_query_log_event_binary_format Binary Format
|
|
2279 |
*/
|
|
2280 |
class Begin_load_query_log_event: public Append_block_log_event |
|
2281 |
{
|
|
2282 |
public: |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
2283 |
Begin_load_query_log_event(Session* session_arg, const char *db_arg, |
482
by Brian Aker
Remove uint. |
2284 |
unsigned char* block_arg, uint32_t block_len_arg, |
1
by brian
clean slate |
2285 |
bool using_trans); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
2286 |
Begin_load_query_log_event(Session* session); |
1
by brian
clean slate |
2287 |
int get_create_or_append() const; |
482
by Brian Aker
Remove uint. |
2288 |
Begin_load_query_log_event(const char* buf, uint32_t event_len, |
1
by brian
clean slate |
2289 |
const Format_description_log_event |
2290 |
*description_event); |
|
2291 |
~Begin_load_query_log_event() {} |
|
2292 |
Log_event_type get_type_code() { return BEGIN_LOAD_QUERY_EVENT; } |
|
2293 |
private: |
|
2294 |
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli); |
|
2295 |
};
|
|
2296 |
||
2297 |
||
2298 |
/*
|
|
2299 |
Elements of this enum describe how LOAD DATA handles duplicates.
|
|
2300 |
*/
|
|
2301 |
enum enum_load_dup_handling { LOAD_DUP_ERROR= 0, LOAD_DUP_IGNORE, |
|
2302 |
LOAD_DUP_REPLACE }; |
|
2303 |
||
2304 |
/**
|
|
2305 |
@class Execute_load_query_log_event
|
|
2306 |
||
2307 |
Event responsible for LOAD DATA execution, it similar to Query_log_event
|
|
2308 |
but before executing the query it substitutes original filename in LOAD DATA
|
|
2309 |
query with name of temporary file.
|
|
2310 |
||
2311 |
@section Execute_load_query_log_event_binary_format Binary Format
|
|
2312 |
*/
|
|
2313 |
class Execute_load_query_log_event: public Query_log_event |
|
2314 |
{
|
|
2315 |
public: |
|
482
by Brian Aker
Remove uint. |
2316 |
uint32_t file_id; // file_id of temporary file |
2317 |
uint32_t fn_pos_start; // pointer to the part of the query that should |
|
1
by brian
clean slate |
2318 |
// be substituted
|
482
by Brian Aker
Remove uint. |
2319 |
uint32_t fn_pos_end; // pointer to the end of this part of query |
1
by brian
clean slate |
2320 |
/*
|
2321 |
We have to store type of duplicate handling explicitly, because
|
|
2322 |
for LOAD DATA it also depends on LOCAL option. And this part
|
|
2323 |
of query will be rewritten during replication so this information
|
|
2324 |
may be lost...
|
|
2325 |
*/
|
|
2326 |
enum_load_dup_handling dup_handling; |
|
2327 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
2328 |
Execute_load_query_log_event(Session* session, const char* query_arg, |
482
by Brian Aker
Remove uint. |
2329 |
ulong query_length, uint32_t fn_pos_start_arg, |
2330 |
uint32_t fn_pos_end_arg, |
|
1
by brian
clean slate |
2331 |
enum_load_dup_handling dup_handling_arg, |
2332 |
bool using_trans, bool suppress_use, |
|
520.1.21
by Brian Aker
THD -> Session rename |
2333 |
Session::killed_state |
2334 |
killed_err_arg= Session::KILLED_NO_VALUE); |
|
1
by brian
clean slate |
2335 |
void pack_info(Protocol* protocol); |
482
by Brian Aker
Remove uint. |
2336 |
Execute_load_query_log_event(const char* buf, uint32_t event_len, |
1
by brian
clean slate |
2337 |
const Format_description_log_event |
2338 |
*description_event); |
|
2339 |
~Execute_load_query_log_event() {} |
|
2340 |
||
2341 |
Log_event_type get_type_code() { return EXECUTE_LOAD_QUERY_EVENT; } |
|
2342 |
bool is_valid() const { return Query_log_event::is_valid() && file_id != 0; } |
|
2343 |
||
2344 |
ulong get_post_header_size_for_derived(); |
|
2345 |
bool write_post_header_for_derived(IO_CACHE* file); |
|
2346 |
||
2347 |
private: |
|
2348 |
virtual int do_apply_event(Relay_log_info const *rli); |
|
438.1.10
by Brian Aker
Removed binlog tool (we need to rewrite it) and removed all the hooks for |
2349 |
};
|
2350 |
||
2351 |
||
482
by Brian Aker
Remove uint. |
2352 |
char *str_to_hex(char *to, const char *from, uint32_t len); |
1
by brian
clean slate |
2353 |
|
2354 |
/**
|
|
2355 |
@class Table_map_log_event
|
|
2356 |
||
2357 |
In row-based mode, every row operation event is preceded by a
|
|
2358 |
Table_map_log_event which maps a table definition to a number. The
|
|
2359 |
table definition consists of database name, table name, and column
|
|
2360 |
definitions.
|
|
2361 |
||
2362 |
@section Table_map_log_event_binary_format Binary Format
|
|
2363 |
||
2364 |
The Post-Header has the following components:
|
|
2365 |
||
2366 |
<table>
|
|
2367 |
<caption>Post-Header for Table_map_log_event</caption>
|
|
2368 |
||
2369 |
<tr>
|
|
2370 |
<th>Name</th>
|
|
2371 |
<th>Format</th>
|
|
2372 |
<th>Description</th>
|
|
2373 |
</tr>
|
|
2374 |
||
2375 |
<tr>
|
|
2376 |
<td>table_id</td>
|
|
2377 |
<td>6 bytes unsigned integer</td>
|
|
2378 |
<td>The number that identifies the table.</td>
|
|
2379 |
</tr>
|
|
2380 |
||
2381 |
<tr>
|
|
2382 |
<td>flags</td>
|
|
2383 |
<td>2 byte bitfield</td>
|
|
2384 |
<td>Reserved for future use; currently always 0.</td>
|
|
2385 |
</tr>
|
|
2386 |
||
2387 |
</table>
|
|
2388 |
||
2389 |
The Body has the following components:
|
|
2390 |
||
2391 |
<table>
|
|
2392 |
<caption>Body for Table_map_log_event</caption>
|
|
2393 |
||
2394 |
<tr>
|
|
2395 |
<th>Name</th>
|
|
2396 |
<th>Format</th>
|
|
2397 |
<th>Description</th>
|
|
2398 |
</tr>
|
|
2399 |
||
2400 |
<tr>
|
|
2401 |
<td>database_name</td>
|
|
2402 |
<td>one byte string length, followed by null-terminated string</td>
|
|
2403 |
<td>The name of the database in which the table resides. The name
|
|
2404 |
is represented as a one byte unsigned integer representing the
|
|
2405 |
number of bytes in the name, followed by length bytes containing
|
|
2406 |
the database name, followed by a terminating 0 byte. (Note the
|
|
2407 |
redundancy in the representation of the length.) </td>
|
|
2408 |
</tr>
|
|
2409 |
||
2410 |
<tr>
|
|
2411 |
<td>table_name</td>
|
|
2412 |
<td>one byte string length, followed by null-terminated string</td>
|
|
2413 |
<td>The name of the table, encoded the same way as the database
|
|
2414 |
name above.</td>
|
|
2415 |
</tr>
|
|
2416 |
||
2417 |
<tr>
|
|
2418 |
<td>column_count</td>
|
|
2419 |
<td>@ref packed_integer "Packed Integer"</td>
|
|
2420 |
<td>The number of columns in the table, represented as a packed
|
|
2421 |
variable-length integer.</td>
|
|
2422 |
</tr>
|
|
2423 |
||
2424 |
<tr>
|
|
2425 |
<td>column_type</td>
|
|
2426 |
<td>List of column_count 1 byte enumeration values</td>
|
|
2427 |
<td>The type of each column in the table, listed from left to
|
|
2428 |
right. Each byte is mapped to a column type according to the
|
|
2429 |
enumeration type enum_field_types defined in mysql_com.h. The
|
|
2430 |
mapping of types to numbers is listed in the table @ref
|
|
2431 |
Table_table_map_log_event_column_types "below" (along with
|
|
2432 |
description of the associated metadata field). </td>
|
|
2433 |
</tr>
|
|
2434 |
||
2435 |
<tr>
|
|
2436 |
<td>metadata_length</td>
|
|
2437 |
<td>@ref packed_integer "Packed Integer"</td>
|
|
2438 |
<td>The length of the following metadata block</td>
|
|
2439 |
</tr>
|
|
2440 |
||
2441 |
<tr>
|
|
2442 |
<td>metadata</td>
|
|
2443 |
<td>list of metadata for each column</td>
|
|
2444 |
<td>For each column from left to right, a chunk of data who's
|
|
2445 |
length and semantics depends on the type of the column. The
|
|
2446 |
length and semantics for the metadata for each column are listed
|
|
2447 |
in the table @ref Table_table_map_log_event_column_types
|
|
2448 |
"below".</td>
|
|
2449 |
</tr>
|
|
2450 |
||
2451 |
<tr>
|
|
2452 |
<td>null_bits</td>
|
|
2453 |
<td>column_count bits, rounded up to nearest byte</td>
|
|
2454 |
<td>For each column, a bit indicating whether data in the column
|
|
2455 |
can be NULL or not. The number of bytes needed for this is
|
|
2456 |
int((column_count+7)/8). The flag for the first column from the
|
|
2457 |
left is in the least-significant bit of the first byte, the second
|
|
2458 |
is in the second least significant bit of the first byte, the
|
|
2459 |
ninth is in the least significant bit of the second byte, and so
|
|
2460 |
on. </td>
|
|
2461 |
</tr>
|
|
2462 |
||
2463 |
</table>
|
|
2464 |
||
2465 |
The table below lists all column types, along with the numerical
|
|
2466 |
identifier for it and the size and interpretation of meta-data used
|
|
2467 |
to describe the type.
|
|
2468 |
||
2469 |
@anchor Table_table_map_log_event_column_types
|
|
2470 |
<table>
|
|
2471 |
<caption>Table_map_log_event column types: numerical identifier and
|
|
2472 |
metadata</caption>
|
|
2473 |
<tr>
|
|
2474 |
<th>Name</th>
|
|
2475 |
<th>Identifier</th>
|
|
2476 |
<th>Size of metadata in bytes</th>
|
|
2477 |
<th>Description of metadata</th>
|
|
2478 |
</tr>
|
|
2479 |
||
2480 |
<tr>
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
2481 |
<td>DRIZZLE_TYPE_TINY</td><td>1</td>
|
2482 |
<td>0</td>
|
|
2483 |
<td>No column metadata.</td>
|
|
2484 |
</tr>
|
|
2485 |
||
2486 |
<tr>
|
|
2487 |
<td>DRIZZLE_TYPE_SHORT</td><td>2</td>
|
|
2488 |
<td>0</td>
|
|
2489 |
<td>No column metadata.</td>
|
|
2490 |
</tr>
|
|
2491 |
||
2492 |
<tr>
|
|
2493 |
<td>DRIZZLE_TYPE_LONG</td><td>3</td>
|
|
2494 |
<td>0</td>
|
|
2495 |
<td>No column metadata.</td>
|
|
2496 |
</tr>
|
|
2497 |
||
2498 |
<tr>
|
|
2499 |
<td>DRIZZLE_TYPE_DOUBLE</td><td>5</td>
|
|
1
by brian
clean slate |
2500 |
<td>1 byte</td>
|
2501 |
<td>1 byte unsigned integer, representing the "pack_length", which
|
|
2502 |
is equal to sizeof(double) on the server from which the event
|
|
2503 |
originates.</td>
|
|
2504 |
</tr>
|
|
2505 |
||
2506 |
<tr>
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
2507 |
<td>DRIZZLE_TYPE_NULL</td><td>6</td>
|
2508 |
<td>0</td>
|
|
2509 |
<td>No column metadata.</td>
|
|
2510 |
</tr>
|
|
2511 |
||
2512 |
<tr>
|
|
2513 |
<td>DRIZZLE_TYPE_TIMESTAMP</td><td>7</td>
|
|
2514 |
<td>0</td>
|
|
2515 |
<td>No column metadata.</td>
|
|
2516 |
</tr>
|
|
2517 |
||
2518 |
<tr>
|
|
2519 |
<td>DRIZZLE_TYPE_LONGLONG</td><td>8</td>
|
|
2520 |
<td>0</td>
|
|
2521 |
<td>No column metadata.</td>
|
|
2522 |
</tr>
|
|
2523 |
||
2524 |
<tr>
|
|
2525 |
<td>DRIZZLE_TYPE_DATE</td><td>10</td>
|
|
2526 |
<td>0</td>
|
|
2527 |
<td>No column metadata.</td>
|
|
2528 |
</tr>
|
|
2529 |
||
2530 |
<tr>
|
|
2531 |
<td>DRIZZLE_TYPE_TIME</td><td>11</td>
|
|
2532 |
<td>0</td>
|
|
2533 |
<td>No column metadata.</td>
|
|
2534 |
</tr>
|
|
2535 |
||
2536 |
<tr>
|
|
2537 |
<td>DRIZZLE_TYPE_DATETIME</td><td>12</td>
|
|
2538 |
<td>0</td>
|
|
2539 |
<td>No column metadata.</td>
|
|
2540 |
</tr>
|
|
2541 |
||
2542 |
<tr>
|
|
2543 |
<td>DRIZZLE_TYPE_YEAR</td><td>13</td>
|
|
2544 |
<td>0</td>
|
|
2545 |
<td>No column metadata.</td>
|
|
2546 |
</tr>
|
|
2547 |
||
2548 |
<tr>
|
|
575.5.1
by David Axmark
Changed NEWDATE to DATE. One failing test but I think its somewhere else in the code |
2549 |
<td><i>DRIZZLE_TYPE_DATE</i></td><td><i>14</i></td>
|
1
by brian
clean slate |
2550 |
<td>–</td>
|
2551 |
<td><i>This enumeration value is only used internally and cannot
|
|
2552 |
exist in a binlog.</i></td>
|
|
2553 |
</tr>
|
|
2554 |
||
2555 |
<tr>
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
2556 |
<td>DRIZZLE_TYPE_VARCHAR</td><td>15</td>
|
1
by brian
clean slate |
2557 |
<td>2 bytes</td>
|
2558 |
<td>2 byte unsigned integer representing the maximum length of
|
|
2559 |
the string.</td>
|
|
2560 |
</tr>
|
|
2561 |
||
2562 |
<tr>
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
2563 |
<td>DRIZZLE_TYPE_NEWDECIMAL</td><td>246</td>
|
1
by brian
clean slate |
2564 |
<td>2 bytes</td>
|
2565 |
<td>A 1 byte unsigned int representing the precision, followed
|
|
2566 |
by a 1 byte unsigned int representing the number of decimals.</td>
|
|
2567 |
</tr>
|
|
2568 |
||
2569 |
<tr>
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
2570 |
<td><i>DRIZZLE_TYPE_ENUM</i></td><td><i>247</i></td>
|
2571 |
<td>–</td>
|
|
2572 |
<td><i>This enumeration value is only used internally and cannot
|
|
2573 |
exist in a binlog.</i></td>
|
|
2574 |
</tr>
|
|
2575 |
||
2576 |
<tr>
|
|
2577 |
<td><i>DRIZZLE_TYPE_SET</i></td><td><i>248</i></td>
|
|
2578 |
<td>–</td>
|
|
2579 |
<td><i>This enumeration value is only used internally and cannot
|
|
2580 |
exist in a binlog.</i></td>
|
|
2581 |
</tr>
|
|
2582 |
||
2583 |
<tr>
|
|
2584 |
<td>DRIZZLE_TYPE_BLOB</td><td>252</td>
|
|
1
by brian
clean slate |
2585 |
<td>1 byte</td>
|
2586 |
<td>The pack length, i.e., the number of bytes needed to represent
|
|
2587 |
the length of the blob: 1, 2, 3, or 4.</td>
|
|
2588 |
</tr>
|
|
2589 |
||
2590 |
<tr>
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
2591 |
<td>DRIZZLE_TYPE_STRING</td><td>254</td>
|
1
by brian
clean slate |
2592 |
<td>2 bytes</td>
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
2593 |
<td>The first byte is always DRIZZLE_TYPE_VAR_STRING (i.e., 253).
|
1
by brian
clean slate |
2594 |
The second byte is the field size, i.e., the number of bytes in
|
2595 |
the representation of size of the string: 3 or 4.</td>
|
|
2596 |
</tr>
|
|
2597 |
||
2598 |
</table>
|
|
2599 |
*/
|
|
2600 |
class Table_map_log_event : public Log_event |
|
2601 |
{
|
|
2602 |
public: |
|
2603 |
/* Constants */
|
|
2604 |
enum
|
|
2605 |
{
|
|
2606 |
TYPE_CODE = TABLE_MAP_EVENT |
|
2607 |
};
|
|
2608 |
||
2609 |
/**
|
|
2610 |
Enumeration of the errors that can be returned.
|
|
2611 |
*/
|
|
2612 |
enum enum_error |
|
2613 |
{
|
|
2614 |
ERR_OPEN_FAILURE = -1, /**< Failure to open table */ |
|
2615 |
ERR_OK = 0, /**< No error */ |
|
2616 |
ERR_TABLE_LIMIT_EXCEEDED = 1, /**< No more room for tables */ |
|
2617 |
ERR_OUT_OF_MEM = 2, /**< Out of memory */ |
|
2618 |
ERR_BAD_TABLE_DEF = 3, /**< Table definition does not match */ |
|
2619 |
ERR_RBR_TO_SBR = 4 /**< daisy-chanining RBR to SBR not allowed */ |
|
2620 |
};
|
|
2621 |
||
2622 |
enum enum_flag |
|
2623 |
{
|
|
2624 |
/*
|
|
2625 |
Nothing here right now, but the flags support is there in
|
|
2626 |
preparation for changes that are coming. Need to add a
|
|
2627 |
constant to make it compile under HP-UX: aCC does not like
|
|
2628 |
empty enumerations.
|
|
2629 |
*/
|
|
2630 |
ENUM_FLAG_COUNT
|
|
2631 |
};
|
|
2632 |
||
206
by Brian Aker
Removed final uint dead types. |
2633 |
typedef uint16_t flag_set; |
1
by brian
clean slate |
2634 |
|
2635 |
/* Special constants representing sets of flags */
|
|
2636 |
enum
|
|
2637 |
{
|
|
2638 |
TM_NO_FLAGS = 0U |
|
2639 |
};
|
|
2640 |
||
2641 |
void set_flags(flag_set flag) { m_flags |= flag; } |
|
2642 |
void clear_flags(flag_set flag) { m_flags &= ~flag; } |
|
2643 |
flag_set get_flags(flag_set flag) const { return m_flags & flag; } |
|
2644 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
2645 |
Table_map_log_event(Session *session, Table *tbl, ulong tid, |
206
by Brian Aker
Removed final uint dead types. |
2646 |
bool is_transactional, uint16_t flags); |
482
by Brian Aker
Remove uint. |
2647 |
Table_map_log_event(const char *buf, uint32_t event_len, |
1
by brian
clean slate |
2648 |
const Format_description_log_event *description_event); |
2649 |
||
2650 |
~Table_map_log_event(); |
|
2651 |
||
2652 |
virtual Log_event_type get_type_code() { return TABLE_MAP_EVENT; } |
|
2653 |
virtual bool is_valid() const { return m_memory != NULL; /* we check malloc */ } |
|
2654 |
||
2655 |
virtual int get_data_size() { return m_data_size; } |
|
2656 |
virtual int save_field_metadata(); |
|
2657 |
virtual bool write_data_header(IO_CACHE *file); |
|
2658 |
virtual bool write_data_body(IO_CACHE *file); |
|
2659 |
virtual const char *get_db() { return m_dbnam; } |
|
2660 |
virtual void pack_info(Protocol *protocol); |
|
2661 |
||
2662 |
private: |
|
2663 |
virtual int do_apply_event(Relay_log_info const *rli); |
|
2664 |
virtual int do_update_pos(Relay_log_info *rli); |
|
2665 |
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli); |
|
2666 |
||
327.1.5
by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h |
2667 |
Table *m_table; |
1
by brian
clean slate |
2668 |
char const *m_dbnam; |
2669 |
size_t m_dblen; |
|
2670 |
char const *m_tblnam; |
|
2671 |
size_t m_tbllen; |
|
2672 |
ulong m_colcnt; |
|
481
by Brian Aker
Remove all of uchar. |
2673 |
unsigned char *m_coltype; |
1
by brian
clean slate |
2674 |
|
481
by Brian Aker
Remove all of uchar. |
2675 |
unsigned char *m_memory; |
1
by brian
clean slate |
2676 |
ulong m_table_id; |
2677 |
flag_set m_flags; |
|
2678 |
||
2679 |
size_t m_data_size; |
|
2680 |
||
481
by Brian Aker
Remove all of uchar. |
2681 |
unsigned char *m_field_metadata; // buffer for field metadata |
1
by brian
clean slate |
2682 |
/*
|
2683 |
The size of field metadata buffer set by calling save_field_metadata()
|
|
2684 |
*/
|
|
2685 |
ulong m_field_metadata_size; |
|
481
by Brian Aker
Remove all of uchar. |
2686 |
unsigned char *m_null_bits; |
2687 |
unsigned char *m_meta_memory; |
|
1
by brian
clean slate |
2688 |
};
|
2689 |
||
2690 |
||
2691 |
/**
|
|
2692 |
@class Rows_log_event
|
|
2693 |
||
2694 |
Common base class for all row-containing log events.
|
|
2695 |
||
2696 |
RESPONSIBILITIES
|
|
2697 |
||
2698 |
Encode the common parts of all events containing rows, which are:
|
|
2699 |
- Write data header and data body to an IO_CACHE.
|
|
2700 |
- Provide an interface for adding an individual row to the event.
|
|
2701 |
||
2702 |
@section Rows_log_event_binary_format Binary Format
|
|
2703 |
*/
|
|
2704 |
||
2705 |
||
2706 |
class Rows_log_event : public Log_event |
|
2707 |
{
|
|
2708 |
public: |
|
2709 |
/**
|
|
2710 |
Enumeration of the errors that can be returned.
|
|
2711 |
*/
|
|
2712 |
enum enum_error |
|
2713 |
{
|
|
2714 |
ERR_OPEN_FAILURE = -1, /**< Failure to open table */ |
|
2715 |
ERR_OK = 0, /**< No error */ |
|
2716 |
ERR_TABLE_LIMIT_EXCEEDED = 1, /**< No more room for tables */ |
|
2717 |
ERR_OUT_OF_MEM = 2, /**< Out of memory */ |
|
2718 |
ERR_BAD_TABLE_DEF = 3, /**< Table definition does not match */ |
|
2719 |
ERR_RBR_TO_SBR = 4 /**< daisy-chanining RBR to SBR not allowed */ |
|
2720 |
};
|
|
2721 |
||
2722 |
/*
|
|
2723 |
These definitions allow you to combine the flags into an
|
|
2724 |
appropriate flag set using the normal bitwise operators. The
|
|
2725 |
implicit conversion from an enum-constant to an integer is
|
|
2726 |
accepted by the compiler, which is then used to set the real set
|
|
2727 |
of flags.
|
|
2728 |
*/
|
|
2729 |
enum enum_flag |
|
2730 |
{
|
|
2731 |
/* Last event of a statement */
|
|
2732 |
STMT_END_F = (1U << 0), |
|
2733 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
2734 |
/* Value of the OPTION_NO_FOREIGN_KEY_CHECKS flag in session->options */
|
1
by brian
clean slate |
2735 |
NO_FOREIGN_KEY_CHECKS_F = (1U << 1), |
2736 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
2737 |
/* Value of the OPTION_RELAXED_UNIQUE_CHECKS flag in session->options */
|
1
by brian
clean slate |
2738 |
RELAXED_UNIQUE_CHECKS_F = (1U << 2), |
2739 |
||
2740 |
/**
|
|
2741 |
Indicates that rows in this event are complete, that is contain
|
|
2742 |
values for all columns of the table.
|
|
2743 |
*/
|
|
2744 |
COMPLETE_ROWS_F = (1U << 3) |
|
2745 |
};
|
|
2746 |
||
206
by Brian Aker
Removed final uint dead types. |
2747 |
typedef uint16_t flag_set; |
1
by brian
clean slate |
2748 |
|
2749 |
/* Special constants representing sets of flags */
|
|
2750 |
enum
|
|
2751 |
{
|
|
2752 |
RLE_NO_FLAGS = 0U |
|
2753 |
};
|
|
2754 |
||
2755 |
virtual ~Rows_log_event(); |
|
2756 |
||
2757 |
void set_flags(flag_set flags_arg) { m_flags |= flags_arg; } |
|
2758 |
void clear_flags(flag_set flags_arg) { m_flags &= ~flags_arg; } |
|
2759 |
flag_set get_flags(flag_set flags_arg) const { return m_flags & flags_arg; } |
|
2760 |
||
2761 |
virtual void pack_info(Protocol *protocol); |
|
438.1.10
by Brian Aker
Removed binlog tool (we need to rewrite it) and removed all the hooks for |
2762 |
|
481
by Brian Aker
Remove all of uchar. |
2763 |
int add_row_data(unsigned char *data, size_t length) |
1
by brian
clean slate |
2764 |
{
|
2765 |
return do_add_row_data(data,length); |
|
2766 |
}
|
|
2767 |
||
2768 |
/* Member functions to implement superclass interface */
|
|
2769 |
virtual int get_data_size(); |
|
2770 |
||
2771 |
MY_BITMAP const *get_cols() const { return &m_cols; } |
|
2772 |
size_t get_width() const { return m_width; } |
|
2773 |
ulong get_table_id() const { return m_table_id; } |
|
2774 |
||
2775 |
virtual bool write_data_header(IO_CACHE *file); |
|
2776 |
virtual bool write_data_body(IO_CACHE *file); |
|
2777 |
virtual const char *get_db() { return m_table->s->db.str; } |
|
2778 |
/*
|
|
2779 |
Check that malloc() succeeded in allocating memory for the rows
|
|
2780 |
buffer and the COLS vector. Checking that an Update_rows_log_event
|
|
2781 |
is valid is done in the Update_rows_log_event::is_valid()
|
|
2782 |
function.
|
|
2783 |
*/
|
|
2784 |
virtual bool is_valid() const |
|
2785 |
{
|
|
2786 |
return m_rows_buf && m_cols.bitmap; |
|
2787 |
}
|
|
2788 |
||
482
by Brian Aker
Remove uint. |
2789 |
uint32_t m_row_count; /* The number of rows added to the event */ |
1
by brian
clean slate |
2790 |
|
2791 |
protected: |
|
2792 |
/*
|
|
2793 |
The constructors are protected since you're supposed to inherit
|
|
2794 |
this class, not create instances of this class.
|
|
2795 |
*/
|
|
520.1.21
by Brian Aker
THD -> Session rename |
2796 |
Rows_log_event(Session*, Table*, ulong table_id, |
1
by brian
clean slate |
2797 |
MY_BITMAP const *cols, bool is_transactional); |
482
by Brian Aker
Remove uint. |
2798 |
Rows_log_event(const char *row_data, uint32_t event_len, |
1
by brian
clean slate |
2799 |
Log_event_type event_type, |
2800 |
const Format_description_log_event *description_event); |
|
2801 |
||
481
by Brian Aker
Remove all of uchar. |
2802 |
virtual int do_add_row_data(unsigned char *data, size_t length); |
1
by brian
clean slate |
2803 |
|
327.1.5
by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h |
2804 |
Table *m_table; /* The table the rows belong to */ |
1
by brian
clean slate |
2805 |
ulong m_table_id; /* Table ID */ |
2806 |
MY_BITMAP m_cols; /* Bitmap denoting columns available */ |
|
2807 |
ulong m_width; /* The width of the columns bitmap */ |
|
2808 |
/*
|
|
2809 |
Bitmap for columns available in the after image, if present. These
|
|
2810 |
fields are only available for Update_rows events. Observe that the
|
|
2811 |
width of both the before image COLS vector and the after image
|
|
2812 |
COLS vector is the same: the number of columns of the table on the
|
|
2813 |
master.
|
|
2814 |
*/
|
|
2815 |
MY_BITMAP m_cols_ai; |
|
2816 |
||
2817 |
ulong m_master_reclength; /* Length of record on master side */ |
|
2818 |
||
2819 |
/* Bit buffers in the same memory as the class */
|
|
205
by Brian Aker
uint32 -> uin32_t |
2820 |
uint32_t m_bitbuf[128/(sizeof(uint32_t)*8)]; |
2821 |
uint32_t m_bitbuf_ai[128/(sizeof(uint32_t)*8)]; |
|
1
by brian
clean slate |
2822 |
|
481
by Brian Aker
Remove all of uchar. |
2823 |
unsigned char *m_rows_buf; /* The rows in packed format */ |
2824 |
unsigned char *m_rows_cur; /* One-after the end of the data */ |
|
2825 |
unsigned char *m_rows_end; /* One-after the end of the allocated space */ |
|
1
by brian
clean slate |
2826 |
|
2827 |
flag_set m_flags; /* Flags for row-level events */ |
|
2828 |
||
2829 |
/* helper functions */
|
|
2830 |
||
481
by Brian Aker
Remove all of uchar. |
2831 |
const unsigned char *m_curr_row; /* Start of the row being processed */ |
2832 |
const unsigned char *m_curr_row_end; /* One-after the end of the current row */ |
|
2833 |
unsigned char *m_key; /* Buffer to keep key value during searches */ |
|
1
by brian
clean slate |
2834 |
|
2835 |
int find_row(const Relay_log_info *const); |
|
2836 |
int write_row(const Relay_log_info *const, const bool); |
|
2837 |
||
2838 |
// Unpack the current row into m_table->record[0]
|
|
2839 |
int unpack_current_row(const Relay_log_info *const rli, |
|
550
by Monty Taylor
Moved error.h into just the files that need it. |
2840 |
MY_BITMAP const *cols); |
1
by brian
clean slate |
2841 |
|
2842 |
private: |
|
2843 |
||
2844 |
virtual int do_apply_event(Relay_log_info const *rli); |
|
2845 |
virtual int do_update_pos(Relay_log_info *rli); |
|
2846 |
virtual enum_skip_reason do_shall_skip(Relay_log_info *rli); |
|
2847 |
||
2848 |
/*
|
|
2849 |
Primitive to prepare for a sequence of row executions.
|
|
2850 |
||
2851 |
DESCRIPTION
|
|
2852 |
||
2853 |
Before doing a sequence of do_prepare_row() and do_exec_row()
|
|
2854 |
calls, this member function should be called to prepare for the
|
|
2855 |
entire sequence. Typically, this member function will allocate
|
|
2856 |
space for any buffers that are needed for the two member
|
|
2857 |
functions mentioned above.
|
|
2858 |
||
2859 |
RETURN VALUE
|
|
2860 |
||
2861 |
The member function will return 0 if all went OK, or a non-zero
|
|
2862 |
error code otherwise.
|
|
2863 |
*/
|
|
2864 |
virtual
|
|
2865 |
int do_before_row_operations(const Slave_reporting_capability *const log) = 0; |
|
2866 |
||
2867 |
/*
|
|
2868 |
Primitive to clean up after a sequence of row executions.
|
|
2869 |
||
2870 |
DESCRIPTION
|
|
2871 |
|
|
2872 |
After doing a sequence of do_prepare_row() and do_exec_row(),
|
|
2873 |
this member function should be called to clean up and release
|
|
2874 |
any allocated buffers.
|
|
2875 |
|
|
2876 |
The error argument, if non-zero, indicates an error which happened during
|
|
2877 |
row processing before this function was called. In this case, even if
|
|
2878 |
function is successful, it should return the error code given in the argument.
|
|
2879 |
*/
|
|
2880 |
virtual
|
|
2881 |
int do_after_row_operations(const Slave_reporting_capability *const log, |
|
2882 |
int error) = 0; |
|
2883 |
||
2884 |
/*
|
|
2885 |
Primitive to do the actual execution necessary for a row.
|
|
2886 |
||
2887 |
DESCRIPTION
|
|
2888 |
The member function will do the actual execution needed to handle a row.
|
|
2889 |
The row is located at m_curr_row. When the function returns,
|
|
2890 |
m_curr_row_end should point at the next row (one byte after the end
|
|
2891 |
of the current row).
|
|
2892 |
||
2893 |
RETURN VALUE
|
|
2894 |
0 if execution succeeded, 1 if execution failed.
|
|
2895 |
|
|
2896 |
*/
|
|
2897 |
virtual int do_exec_row(const Relay_log_info *const rli) = 0; |
|
2898 |
||
2899 |
friend class Old_rows_log_event; |
|
2900 |
};
|
|
2901 |
||
2902 |
/**
|
|
2903 |
@class Write_rows_log_event
|
|
2904 |
||
2905 |
Log row insertions and updates. The event contain several
|
|
2906 |
insert/update rows for a table. Note that each event contains only
|
|
2907 |
rows for one table.
|
|
2908 |
||
2909 |
@section Write_rows_log_event_binary_format Binary Format
|
|
2910 |
*/
|
|
2911 |
class Write_rows_log_event : public Rows_log_event |
|
2912 |
{
|
|
2913 |
public: |
|
2914 |
enum
|
|
2915 |
{
|
|
520.1.21
by Brian Aker
THD -> Session rename |
2916 |
/* Support interface to Session::binlog_prepare_pending_rows_event */
|
1
by brian
clean slate |
2917 |
TYPE_CODE = WRITE_ROWS_EVENT |
2918 |
};
|
|
2919 |
||
520.1.21
by Brian Aker
THD -> Session rename |
2920 |
Write_rows_log_event(Session*, Table*, ulong table_id, |
1
by brian
clean slate |
2921 |
bool is_transactional); |
482
by Brian Aker
Remove uint. |
2922 |
Write_rows_log_event(const char *buf, uint32_t event_len, |
1
by brian
clean slate |
2923 |
const Format_description_log_event *description_event); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
2924 |
static bool binlog_row_logging_function(Session *session, Table *table, |
1
by brian
clean slate |
2925 |
bool is_transactional, |
520.9.3
by mordred
zomg. Solaris actually builds all the way!!! |
2926 |
const unsigned char *, |
481
by Brian Aker
Remove all of uchar. |
2927 |
const unsigned char *after_record) |
1
by brian
clean slate |
2928 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
2929 |
return session->binlog_write_row(table, is_transactional, after_record); |
1
by brian
clean slate |
2930 |
}
|
2931 |
||
2932 |
private: |
|
2933 |
virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; } |
|
2934 |
||
2935 |
virtual int do_before_row_operations(const Slave_reporting_capability *const); |
|
2936 |
virtual int do_after_row_operations(const Slave_reporting_capability *const,int); |
|
2937 |
virtual int do_exec_row(const Relay_log_info *const); |
|
2938 |
};
|
|
2939 |
||
2940 |
||
2941 |
/**
|
|
2942 |
@class Update_rows_log_event
|
|
2943 |
||
2944 |
Log row updates with a before image. The event contain several
|
|
2945 |
update rows for a table. Note that each event contains only rows for
|
|
2946 |
one table.
|
|
2947 |
||
2948 |
Also note that the row data consists of pairs of row data: one row
|
|
2949 |
for the old data and one row for the new data.
|
|
2950 |
||
2951 |
@section Update_rows_log_event_binary_format Binary Format
|
|
2952 |
*/
|
|
2953 |
class Update_rows_log_event : public Rows_log_event |
|
2954 |
{
|
|
2955 |
public: |
|
2956 |
enum
|
|
2957 |
{
|
|
520.1.21
by Brian Aker
THD -> Session rename |
2958 |
/* Support interface to Session::binlog_prepare_pending_rows_event */
|
1
by brian
clean slate |
2959 |
TYPE_CODE = UPDATE_ROWS_EVENT |
2960 |
};
|
|
2961 |
||
520.1.21
by Brian Aker
THD -> Session rename |
2962 |
Update_rows_log_event(Session*, Table*, ulong table_id, |
1
by brian
clean slate |
2963 |
bool is_transactional); |
2964 |
||
2965 |
void init(MY_BITMAP const *cols); |
|
2966 |
||
2967 |
virtual ~Update_rows_log_event(); |
|
2968 |
||
482
by Brian Aker
Remove uint. |
2969 |
Update_rows_log_event(const char *buf, uint32_t event_len, |
1
by brian
clean slate |
2970 |
const Format_description_log_event *description_event); |
2971 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
2972 |
static bool binlog_row_logging_function(Session *session, Table *table, |
1
by brian
clean slate |
2973 |
bool is_transactional, |
481
by Brian Aker
Remove all of uchar. |
2974 |
const unsigned char *before_record, |
2975 |
const unsigned char *after_record) |
|
1
by brian
clean slate |
2976 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
2977 |
return session->binlog_update_row(table, is_transactional, |
1
by brian
clean slate |
2978 |
before_record, after_record); |
2979 |
}
|
|
2980 |
||
2981 |
virtual bool is_valid() const |
|
2982 |
{
|
|
2983 |
return Rows_log_event::is_valid() && m_cols_ai.bitmap; |
|
2984 |
}
|
|
2985 |
||
2986 |
protected: |
|
2987 |
virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; } |
|
2988 |
||
2989 |
virtual int do_before_row_operations(const Slave_reporting_capability *const); |
|
2990 |
virtual int do_after_row_operations(const Slave_reporting_capability *const,int); |
|
2991 |
virtual int do_exec_row(const Relay_log_info *const); |
|
2992 |
};
|
|
2993 |
||
2994 |
/**
|
|
2995 |
@class Delete_rows_log_event
|
|
2996 |
||
2997 |
Log row deletions. The event contain several delete rows for a
|
|
2998 |
table. Note that each event contains only rows for one table.
|
|
2999 |
||
3000 |
RESPONSIBILITIES
|
|
3001 |
||
3002 |
- Act as a container for rows that has been deleted on the master
|
|
3003 |
and should be deleted on the slave.
|
|
3004 |
||
3005 |
COLLABORATION
|
|
3006 |
||
3007 |
Row_writer
|
|
3008 |
Create the event and add rows to the event.
|
|
3009 |
Row_reader
|
|
3010 |
Extract the rows from the event.
|
|
3011 |
||
3012 |
@section Delete_rows_log_event_binary_format Binary Format
|
|
3013 |
*/
|
|
3014 |
class Delete_rows_log_event : public Rows_log_event |
|
3015 |
{
|
|
3016 |
public: |
|
3017 |
enum
|
|
3018 |
{
|
|
520.1.21
by Brian Aker
THD -> Session rename |
3019 |
/* Support interface to Session::binlog_prepare_pending_rows_event */
|
1
by brian
clean slate |
3020 |
TYPE_CODE = DELETE_ROWS_EVENT |
3021 |
};
|
|
3022 |
||
520.1.21
by Brian Aker
THD -> Session rename |
3023 |
Delete_rows_log_event(Session*, Table*, ulong, |
1
by brian
clean slate |
3024 |
bool is_transactional); |
482
by Brian Aker
Remove uint. |
3025 |
Delete_rows_log_event(const char *buf, uint32_t event_len, |
1
by brian
clean slate |
3026 |
const Format_description_log_event *description_event); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
3027 |
static bool binlog_row_logging_function(Session *session, Table *table, |
1
by brian
clean slate |
3028 |
bool is_transactional, |
481
by Brian Aker
Remove all of uchar. |
3029 |
const unsigned char *before_record, |
520.9.3
by mordred
zomg. Solaris actually builds all the way!!! |
3030 |
const unsigned char *) |
1
by brian
clean slate |
3031 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
3032 |
return session->binlog_delete_row(table, is_transactional, before_record); |
1
by brian
clean slate |
3033 |
}
|
3034 |
||
3035 |
protected: |
|
3036 |
virtual Log_event_type get_type_code() { return (Log_event_type)TYPE_CODE; } |
|
3037 |
||
3038 |
virtual int do_before_row_operations(const Slave_reporting_capability *const); |
|
3039 |
virtual int do_after_row_operations(const Slave_reporting_capability *const,int); |
|
3040 |
virtual int do_exec_row(const Relay_log_info *const); |
|
3041 |
};
|
|
3042 |
||
3043 |
||
3044 |
/**
|
|
3045 |
@class Incident_log_event
|
|
3046 |
||
3047 |
Class representing an incident, an occurance out of the ordinary,
|
|
3048 |
that happened on the master.
|
|
3049 |
||
3050 |
The event is used to inform the slave that something out of the
|
|
3051 |
ordinary happened on the master that might cause the database to be
|
|
3052 |
in an inconsistent state.
|
|
3053 |
||
3054 |
<table id="IncidentFormat">
|
|
3055 |
<caption>Incident event format</caption>
|
|
3056 |
<tr>
|
|
3057 |
<th>Symbol</th>
|
|
3058 |
<th>Format</th>
|
|
3059 |
<th>Description</th>
|
|
3060 |
</tr>
|
|
3061 |
<tr>
|
|
3062 |
<td>INCIDENT</td>
|
|
3063 |
<td align="right">2</td>
|
|
3064 |
<td>Incident number as an unsigned integer</td>
|
|
3065 |
</tr>
|
|
3066 |
<tr>
|
|
3067 |
<td>MSGLEN</td>
|
|
3068 |
<td align="right">1</td>
|
|
3069 |
<td>Message length as an unsigned integer</td>
|
|
3070 |
</tr>
|
|
3071 |
<tr>
|
|
3072 |
<td>MESSAGE</td>
|
|
3073 |
<td align="right">MSGLEN</td>
|
|
3074 |
<td>The message, if present. Not null terminated.</td>
|
|
3075 |
</tr>
|
|
3076 |
</table>
|
|
3077 |
||
3078 |
@section Delete_rows_log_event_binary_format Binary Format
|
|
3079 |
*/
|
|
3080 |
class Incident_log_event : public Log_event { |
|
3081 |
public: |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
3082 |
Incident_log_event(Session *session_arg, Incident incident) |
3083 |
: Log_event(session_arg, 0, false), m_incident(incident) |
|
1
by brian
clean slate |
3084 |
{
|
3085 |
m_message.str= NULL; /* Just as a precaution */ |
|
3086 |
m_message.length= 0; |
|
51.1.31
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
3087 |
return; |
1
by brian
clean slate |
3088 |
}
|
3089 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
3090 |
Incident_log_event(Session *session_arg, Incident incident, LEX_STRING const msg) |
3091 |
: Log_event(session_arg, 0, false), m_incident(incident) |
|
1
by brian
clean slate |
3092 |
{
|
3093 |
m_message= msg; |
|
51.1.31
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
3094 |
return; |
1
by brian
clean slate |
3095 |
}
|
3096 |
||
3097 |
void pack_info(Protocol*); |
|
3098 |
||
482
by Brian Aker
Remove uint. |
3099 |
Incident_log_event(const char *buf, uint32_t event_len, |
1
by brian
clean slate |
3100 |
const Format_description_log_event *descr_event); |
3101 |
||
3102 |
virtual ~Incident_log_event(); |
|
3103 |
||
3104 |
virtual int do_apply_event(Relay_log_info const *rli); |
|
3105 |
||
3106 |
virtual bool write_data_header(IO_CACHE *file); |
|
3107 |
virtual bool write_data_body(IO_CACHE *file); |
|
3108 |
||
3109 |
virtual Log_event_type get_type_code() { return INCIDENT_EVENT; } |
|
3110 |
||
3111 |
virtual bool is_valid() const { return 1; } |
|
3112 |
virtual int get_data_size() { |
|
3113 |
return INCIDENT_HEADER_LEN + 1 + m_message.length; |
|
3114 |
}
|
|
3115 |
||
3116 |
private: |
|
3117 |
const char *description() const; |
|
3118 |
||
3119 |
Incident m_incident; |
|
3120 |
LEX_STRING m_message; |
|
3121 |
};
|
|
3122 |
||
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
3123 |
int append_query_string(const CHARSET_INFO * const csinfo, |
243.1.5
by Jay Pipes
* Pulled the remainder of the log and parse stuff out into |
3124 |
String const *from, String *to); |
3125 |
||
1
by brian
clean slate |
3126 |
static inline bool copy_event_cache_to_file_and_reinit(IO_CACHE *cache, |
3127 |
FILE *file) |
|
3128 |
{
|
|
3129 |
return
|
|
3130 |
my_b_copy_to_file(cache, file) || |
|
51.1.31
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE |
3131 |
reinit_io_cache(cache, WRITE_CACHE, 0, false, true); |
1
by brian
clean slate |
3132 |
}
|
3133 |
||
3134 |
/*****************************************************************************
|
|
3135 |
||
3136 |
Heartbeat Log Event class
|
|
3137 |
||
3138 |
Replication event to ensure to slave that master is alive.
|
|
3139 |
The event is originated by master's dump thread and sent straight to
|
|
3140 |
slave without being logged. Slave itself does not store it in relay log
|
|
3141 |
but rather uses a data for immediate checks and throws away the event.
|
|
3142 |
||
3143 |
Two members of the class log_ident and Log_event::log_pos comprise
|
|
3144 |
@see the event_coordinates instance. The coordinates that a heartbeat
|
|
3145 |
instance carries correspond to the last event master has sent from
|
|
3146 |
its binlog.
|
|
3147 |
||
3148 |
****************************************************************************/
|
|
3149 |
class Heartbeat_log_event: public Log_event |
|
3150 |
{
|
|
3151 |
public: |
|
482
by Brian Aker
Remove uint. |
3152 |
Heartbeat_log_event(const char* buf, uint32_t event_len, |
1
by brian
clean slate |
3153 |
const Format_description_log_event* description_event); |
3154 |
Log_event_type get_type_code() { return HEARTBEAT_LOG_EVENT; } |
|
3155 |
bool is_valid() const |
|
3156 |
{
|
|
3157 |
return (log_ident != NULL && |
|
3158 |
log_pos >= BIN_LOG_HEADER_SIZE); |
|
3159 |
}
|
|
3160 |
const char * get_log_ident() { return log_ident; } |
|
482
by Brian Aker
Remove uint. |
3161 |
uint32_t get_ident_len() { return ident_len; } |
1
by brian
clean slate |
3162 |
|
3163 |
private: |
|
3164 |
const char* log_ident; |
|
482
by Brian Aker
Remove uint. |
3165 |
uint32_t ident_len; |
1
by brian
clean slate |
3166 |
};
|
3167 |
||
3168 |
/**
|
|
3169 |
@} (end of group Replication)
|
|
3170 |
*/
|
|
3171 |
||
490
by Brian Aker
More effort around master.info (and relay.info) |
3172 |
#endif /* DRIZZLED_LOG_EVENT_H */ |