summaryrefslogtreecommitdiff
path: root/sql/log_event.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/log_event.cc')
-rw-r--r--sql/log_event.cc140
1 files changed, 64 insertions, 76 deletions
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 84757a0a1f2..f64f740da30 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000-2003 MySQL AB
+/* Copyright (C) 2000-2004 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -290,6 +290,8 @@ Log_event::Log_event(const char* buf, bool old_format)
int Log_event::exec_event(struct st_relay_log_info* rli)
{
+ DBUG_ENTER("Log_event::exec_event");
+
/*
rli is null when (as far as I (Guilhem) know)
the caller is
@@ -342,7 +344,7 @@ int Log_event::exec_event(struct st_relay_log_info* rli)
rli->last_master_timestamp= when;
}
}
- return 0;
+ DBUG_RETURN(0);
}
@@ -592,11 +594,13 @@ Error in Log_event::read_log_event(): '%s', data_len: %d, event_type: %d",
Log_event* Log_event::read_log_event(const char* buf, int event_len,
const char **error, bool old_format)
{
+ DBUG_ENTER("Log_event::read_log_event");
+
if (event_len < EVENT_LEN_OFFSET ||
(uint) event_len != uint4korr(buf+EVENT_LEN_OFFSET))
{
*error="Sanity check failed"; // Needed to free buffer
- return NULL; // general sanity check - will fail on a partial read
+ DBUG_RETURN(NULL); // general sanity check - will fail on a partial read
}
Log_event* ev = NULL;
@@ -658,16 +662,16 @@ Log_event* Log_event::read_log_event(const char* buf, int event_len,
if (!force_opt)
{
*error= "Found invalid event in binary log";
- return 0;
+ DBUG_RETURN(0);
}
ev= new Unknown_log_event(buf, old_format);
#else
*error= "Found invalid event in binary log";
- return 0;
+ DBUG_RETURN(0);
#endif
}
ev->cached_event_len = event_len;
- return ev;
+ DBUG_RETURN(ev);
}
#ifdef MYSQL_CLIENT
@@ -1249,38 +1253,21 @@ void Load_log_event::pack_info(Protocol *protocol)
memcpy(pos, table_name, table_name_len);
pos+= table_name_len;
- if (sql_ex.field_term_len)
- {
- pos= strmov(pos, " FIELDS TERMINATED BY ");
- pos= pretty_print_str(pos, sql_ex.field_term, sql_ex.field_term_len);
- }
-
- if (sql_ex.enclosed_len)
- {
- if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
- pos= strmov(pos, " OPTIONALLY ");
- pos= strmov(pos, " ENCLOSED BY ");
- pos= pretty_print_str(pos, sql_ex.enclosed, sql_ex.enclosed_len);
- }
+ /* We have to create all optinal fields as the default is not empty */
+ pos= strmov(pos, " FIELDS TERMINATED BY ");
+ pos= pretty_print_str(pos, sql_ex.field_term, sql_ex.field_term_len);
+ if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
+ pos= strmov(pos, " OPTIONALLY ");
+ pos= strmov(pos, " ENCLOSED BY ");
+ pos= pretty_print_str(pos, sql_ex.enclosed, sql_ex.enclosed_len);
- if (sql_ex.escaped_len)
- {
- pos= strmov(pos, " ESCAPED BY ");
- pos= pretty_print_str(pos, sql_ex.escaped, sql_ex.escaped_len);
- }
-
- bool line_lexem_added= false;
- if (sql_ex.line_term_len)
- {
- pos= strmov(pos, " LINES TERMINATED BY ");
- pos= pretty_print_str(pos, sql_ex.line_term, sql_ex.line_term_len);
- line_lexem_added= true;
- }
+ pos= strmov(pos, " ESCAPED BY ");
+ pos= pretty_print_str(pos, sql_ex.escaped, sql_ex.escaped_len);
+ pos= strmov(pos, " LINES TERMINATED BY ");
+ pos= pretty_print_str(pos, sql_ex.line_term, sql_ex.line_term_len);
if (sql_ex.line_start_len)
{
- if (!line_lexem_added)
- pos= strmov(pos," LINES");
pos= strmov(pos, " STARTING BY ");
pos= pretty_print_str(pos, sql_ex.line_start, sql_ex.line_start_len);
}
@@ -1455,9 +1442,10 @@ Load_log_event::Load_log_event(const char *buf, int event_len,
field_lens(0), field_block_len(0),
table_name(0), db(0), fname(0), local_fname(FALSE)
{
- if (!event_len) // derived class, will call copy_log_event() itself
- return;
- copy_log_event(buf, event_len, old_format);
+ DBUG_ENTER("Load_log_event");
+ if (event_len) // derived class, will call copy_log_event() itself
+ copy_log_event(buf, event_len, old_format);
+ DBUG_VOID_RETURN;
}
@@ -1472,6 +1460,8 @@ int Load_log_event::copy_log_event(const char *buf, ulong event_len,
char* buf_end = (char*)buf + event_len;
uint header_len= old_format ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN;
const char* data_head = buf + header_len;
+ DBUG_ENTER("Load_log_event::copy_log_event");
+
slave_proxy_id= thread_id= uint4korr(data_head + L_THREAD_ID_OFFSET);
exec_time = uint4korr(data_head + L_EXEC_TIME_OFFSET);
skip_lines = uint4korr(data_head + L_SKIP_LINES_OFFSET);
@@ -1484,19 +1474,19 @@ int Load_log_event::copy_log_event(const char *buf, ulong event_len,
get_data_body_offset());
if ((int) event_len < body_offset)
- return 1;
+ DBUG_RETURN(1);
/*
Sql_ex.init() on success returns the pointer to the first byte after
the sql_ex structure, which is the start of field lengths array.
*/
if (!(field_lens=(uchar*)sql_ex.init((char*)buf + body_offset,
- buf_end,
- buf[EVENT_TYPE_OFFSET] != LOAD_EVENT)))
- return 1;
-
+ buf_end,
+ buf[EVENT_TYPE_OFFSET] != LOAD_EVENT)))
+ DBUG_RETURN(1);
+
data_len = event_len - body_offset;
if (num_fields > data_len) // simple sanity check against corruption
- return 1;
+ DBUG_RETURN(1);
for (uint i = 0; i < num_fields; i++)
field_block_len += (uint)field_lens[i] + 1;
@@ -1506,7 +1496,7 @@ int Load_log_event::copy_log_event(const char *buf, ulong event_len,
fname = db + db_len + 1;
fname_len = strlen(fname);
// null termination is accomplished by the caller doing buf[event_len]=0
- return 0;
+ DBUG_RETURN(0);
}
@@ -1524,6 +1514,7 @@ void Load_log_event::print(FILE* file, bool short_form, char* last_db)
void Load_log_event::print(FILE* file, bool short_form, char* last_db,
bool commented)
{
+ DBUG_ENTER("Load_log_event::print");
if (!short_form)
{
print_header(file);
@@ -1555,42 +1546,26 @@ void Load_log_event::print(FILE* file, bool short_form, char* last_db,
fprintf(file," IGNORE ");
fprintf(file, "INTO TABLE %s ", table_name);
- if (sql_ex.field_term)
- {
- fprintf(file, " FIELDS TERMINATED BY ");
- pretty_print_str(file, sql_ex.field_term, sql_ex.field_term_len);
- }
+ fprintf(file, " FIELDS TERMINATED BY ");
+ pretty_print_str(file, sql_ex.field_term, sql_ex.field_term_len);
- if (sql_ex.enclosed)
- {
- if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
- fprintf(file," OPTIONALLY ");
- fprintf(file, " ENCLOSED BY ");
- pretty_print_str(file, sql_ex.enclosed, sql_ex.enclosed_len);
- }
+ if (sql_ex.opt_flags & OPT_ENCLOSED_FLAG)
+ fprintf(file," OPTIONALLY ");
+ fprintf(file, " ENCLOSED BY ");
+ pretty_print_str(file, sql_ex.enclosed, sql_ex.enclosed_len);
- if (sql_ex.escaped)
- {
- fprintf(file, " ESCAPED BY ");
- pretty_print_str(file, sql_ex.escaped, sql_ex.escaped_len);
- }
+ fprintf(file, " ESCAPED BY ");
+ pretty_print_str(file, sql_ex.escaped, sql_ex.escaped_len);
- bool line_lexem_added= false;
- if (sql_ex.line_term)
- {
- fprintf(file," LINES TERMINATED BY ");
- pretty_print_str(file, sql_ex.line_term, sql_ex.line_term_len);
- line_lexem_added= true;
- }
+ fprintf(file," LINES TERMINATED BY ");
+ pretty_print_str(file, sql_ex.line_term, sql_ex.line_term_len);
+
if (sql_ex.line_start)
{
- if (!line_lexem_added)
- fprintf(file," LINES");
fprintf(file," STARTING BY ");
pretty_print_str(file, sql_ex.line_start, sql_ex.line_start_len);
}
-
if ((long) skip_lines > 0)
fprintf(file, " IGNORE %ld LINES", (long) skip_lines);
@@ -1611,6 +1586,7 @@ void Load_log_event::print(FILE* file, bool short_form, char* last_db,
}
fprintf(file, ";\n");
+ DBUG_VOID_RETURN;
}
#endif /* MYSQL_CLIENT */
@@ -1877,8 +1853,11 @@ Rotate_log_event::Rotate_log_event(const char* buf, int event_len,
// The caller will ensure that event_len is what we have at EVENT_LEN_OFFSET
int header_size = (old_format) ? OLD_HEADER_LEN : LOG_EVENT_HEADER_LEN;
uint ident_offset;
+ DBUG_ENTER("Rotate_log_event");
+
if (event_len < header_size)
- return;
+ DBUG_VOID_RETURN;
+
buf += header_size;
if (old_format)
{
@@ -1897,8 +1876,9 @@ Rotate_log_event::Rotate_log_event(const char* buf, int event_len,
ident_offset,
(uint) ident_len,
MYF(MY_WME))))
- return;
+ DBUG_VOID_RETURN;
alloced = 1;
+ DBUG_VOID_RETURN;
}
@@ -2593,7 +2573,9 @@ Create_file_log_event(THD* thd_arg, sql_exchange* ex,
fake_base(0),block(block_arg),block_len(block_len_arg),
file_id(thd_arg->file_id = mysql_bin_log.next_file_id())
{
+ DBUG_ENTER("Create_file_log_event");
sql_ex.force_new_format();
+ DBUG_VOID_RETURN;
}
#endif /* !MYSQL_CLIENT */
@@ -2650,8 +2632,10 @@ Create_file_log_event::Create_file_log_event(const char* buf, int len,
:Load_log_event(buf,0,old_format),fake_base(0),block(0),inited_from_old(0)
{
int block_offset;
+ DBUG_ENTER("Create_file_log_event");
+
if (copy_log_event(buf,len,old_format))
- return;
+ DBUG_VOID_RETURN;
if (!old_format)
{
file_id = uint4korr(buf + LOG_EVENT_HEADER_LEN +
@@ -2669,6 +2653,7 @@ Create_file_log_event::Create_file_log_event(const char* buf, int len,
sql_ex.force_new_format();
inited_from_old = 1;
}
+ DBUG_VOID_RETURN;
}
@@ -2821,11 +2806,13 @@ Append_block_log_event::Append_block_log_event(THD* thd_arg, const char* db_arg,
Append_block_log_event::Append_block_log_event(const char* buf, int len)
:Log_event(buf, 0),block(0)
{
+ DBUG_ENTER("Append_block_log_event");
if ((uint)len < APPEND_BLOCK_EVENT_OVERHEAD)
- return;
+ DBUG_VOID_RETURN;
file_id = uint4korr(buf + LOG_EVENT_HEADER_LEN + AB_FILE_ID_OFFSET);
block = (char*)buf + APPEND_BLOCK_EVENT_OVERHEAD;
block_len = len - APPEND_BLOCK_EVENT_OVERHEAD;
+ DBUG_VOID_RETURN;
}
@@ -2888,6 +2875,7 @@ int Append_block_log_event::exec_event(struct st_relay_log_info* rli)
char *p= slave_load_file_stem(fname, file_id, server_id);
int fd;
int error = 1;
+ DBUG_ENTER("Append_block_log_event::exec_event");
memcpy(p, ".data", 6);
if ((fd = my_open(fname, O_WRONLY|O_APPEND|O_BINARY, MYF(MY_WME))) < 0)
@@ -2905,7 +2893,7 @@ int Append_block_log_event::exec_event(struct st_relay_log_info* rli)
err:
if (fd >= 0)
my_close(fd, MYF(0));
- return error ? error : Log_event::exec_event(rli);
+ DBUG_RETURN(error ? error : Log_event::exec_event(rli));
}
#endif