diff options
Diffstat (limited to 'sql/log_event.cc')
-rw-r--r-- | sql/log_event.cc | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/sql/log_event.cc b/sql/log_event.cc index 68d4c69f398..4c82d686d5a 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -382,7 +382,7 @@ static void cleanup_load_tmpdir() uint i; char fname[FN_REFLEN], prefbuf[31], *p; - if (!(dirp=my_dir(slave_load_tmpdir,MYF(MY_WME)))) + if (!(dirp=my_dir(slave_load_tmpdir,MYF(0)))) return; /* @@ -1279,7 +1279,7 @@ void Log_event::print_header(IO_CACHE* file, char emit_buf[256]; // Enough for storing one line my_b_printf(file, "# Position Timestamp Type Master ID " "Size Master Pos Flags \n"); - int const bytes_written= + size_t const bytes_written= my_snprintf(emit_buf, sizeof(emit_buf), "# %8.8lx %02x %02x %02x %02x %02x " "%02x %02x %02x %02x %02x %02x %02x %02x " @@ -1288,7 +1288,6 @@ void Log_event::print_header(IO_CACHE* file, ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7], ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13], ptr[14], ptr[15], ptr[16], ptr[17], ptr[18]); - DBUG_ASSERT(bytes_written >= 0); DBUG_ASSERT(static_cast<size_t>(bytes_written) < sizeof(emit_buf)); my_b_write(file, (uchar*) emit_buf, bytes_written); ptr += LOG_EVENT_MINIMAL_HEADER_LEN; @@ -1314,12 +1313,11 @@ void Log_event::print_header(IO_CACHE* file, TODO: Rewrite my_b_printf() to support full printf() syntax. */ char emit_buf[256]; - int const bytes_written= + size_t const bytes_written= my_snprintf(emit_buf, sizeof(emit_buf), "# %8.8lx %-48.48s |%16s|\n", (unsigned long) (hexdump_from + (i & 0xfffffff0)), hex_string, char_string); - DBUG_ASSERT(bytes_written >= 0); DBUG_ASSERT(static_cast<size_t>(bytes_written) < sizeof(emit_buf)); my_b_write(file, (uchar*) emit_buf, bytes_written); hex_string[0]= 0; @@ -1334,12 +1332,11 @@ void Log_event::print_header(IO_CACHE* file, if (hex_string[0]) { char emit_buf[256]; - int const bytes_written= + size_t const bytes_written= my_snprintf(emit_buf, sizeof(emit_buf), "# %8.8lx %-48.48s |%s|\n", (unsigned long) (hexdump_from + (i & 0xfffffff0)), hex_string, char_string); - DBUG_ASSERT(bytes_written >= 0); DBUG_ASSERT(static_cast<size_t>(bytes_written) < sizeof(emit_buf)); my_b_write(file, (uchar*) emit_buf, bytes_written); } @@ -1627,7 +1624,7 @@ beg: case MYSQL_TYPE_DATETIME: { - uint d, t; + size_t d, t; uint64 i64= uint8korr(ptr); /* YYYYMMDDhhmmss */ d= i64 / 1000000; t= i64 % 1000000; @@ -4197,7 +4194,7 @@ int Load_log_event::copy_log_event(const char *buf, ulong event_len, table_name = fields + field_block_len; db = table_name + table_name_len + 1; fname = db + db_len + 1; - fname_len = strlen(fname); + fname_len = (uint) strlen(fname); // null termination is accomplished by the caller doing buf[event_len]=0 DBUG_RETURN(0); @@ -5699,7 +5696,7 @@ void Slave_log_event::init_from_mem_pool(int data_size) master_pos = uint8korr(mem_pool + SL_MASTER_POS_OFFSET); master_port = uint2korr(mem_pool + SL_MASTER_PORT_OFFSET); master_host = mem_pool + SL_MASTER_HOST_OFFSET; - master_host_len = strlen(master_host); + master_host_len = (uint) strlen(master_host); // safety master_log = master_host + master_host_len + 1; if (master_log > mem_pool + data_size) @@ -5707,7 +5704,7 @@ void Slave_log_event::init_from_mem_pool(int data_size) master_host = 0; return; } - master_log_len = strlen(master_log); + master_log_len = (uint) strlen(master_log); } @@ -6180,6 +6177,12 @@ int Append_block_log_event::do_apply_event(Relay_log_info const *rli) thd_proc_info(thd, proc_info); if (get_create_or_append()) { + /* + Usually lex_start() is called by mysql_parse(), but we need it here + as the present method does not call mysql_parse(). + */ + lex_start(thd); + mysql_reset_thd_for_next_command(thd); my_delete(fname, MYF(0)); // old copy may exist already if ((fd= my_create(fname, CREATE_MODE, O_WRONLY | O_BINARY | O_EXCL | O_NOFOLLOW, @@ -6199,6 +6202,10 @@ int Append_block_log_event::do_apply_event(Relay_log_info const *rli) get_type_str(), fname); goto err; } + + DBUG_EXECUTE_IF("remove_slave_load_file_before_write", + my_close(fd,MYF(0)); fd= -1; my_delete(fname, MYF(0));); + if (my_write(fd, (uchar*) block, block_len, MYF(MY_WME+MY_NABP))) { rli->report(ERROR_LEVEL, my_errno, @@ -6620,7 +6627,7 @@ void Execute_load_query_log_event::print(FILE* file, my_b_printf(&cache, "\'"); if (dup_handling == LOAD_DUP_REPLACE) my_b_printf(&cache, " REPLACE"); - my_b_printf(&cache, " INTO"); + my_b_printf(&cache, " INTO "); my_b_write(&cache, (uchar*) query + fn_pos_end, q_len-fn_pos_end); my_b_printf(&cache, "\n%s\n", print_event_info->delimiter); } @@ -6701,7 +6708,7 @@ Execute_load_query_log_event::do_apply_event(Relay_log_info const *rli) /* Ordinary load data */ break; } - p= strmake(p, STRING_WITH_LEN(" INTO")); + p= strmake(p, STRING_WITH_LEN(" INTO ")); p= strmake(p, query+fn_pos_end, q_len-fn_pos_end); error= Query_log_event::do_apply_event(rli, buf, p-buf); @@ -6988,8 +6995,8 @@ int Rows_log_event::get_data_size() { int const type_code= get_type_code(); - uchar buf[sizeof(m_width)+1]; - uchar *end= net_store_length(buf, (m_width + 7) / 8); + uchar buf[sizeof(m_width) + 1]; + uchar *end= net_store_length(buf, m_width); DBUG_EXECUTE_IF("old_row_based_repl_4_byte_map_id_master", return 6 + no_bytes_in_map(&m_cols) + (end - buf) + @@ -6997,12 +7004,12 @@ int Rows_log_event::get_data_size() (m_rows_cur - m_rows_buf);); int data_size= ROWS_HEADER_LEN; data_size+= no_bytes_in_map(&m_cols); - data_size+= end - buf; + data_size+= (uint) (end - buf); if (type_code == UPDATE_ROWS_EVENT) data_size+= no_bytes_in_map(&m_cols_ai); - data_size+= (m_rows_cur - m_rows_buf); + data_size+= (uint) (m_rows_cur - m_rows_buf); return data_size; } @@ -7578,7 +7585,7 @@ bool Rows_log_event::write_data_body(IO_CACHE*file) Note that this should be the number of *bits*, not the number of bytes. */ - uchar sbuf[sizeof(m_width)]; + uchar sbuf[sizeof(m_width) + 1]; my_ptrdiff_t const data_size= m_rows_cur - m_rows_buf; bool res= false; uchar *const sbuf_end= net_store_length(sbuf, (size_t) m_width); @@ -7740,6 +7747,8 @@ Table_map_log_event::Table_map_log_event(THD *thd, TABLE *tbl, ulong tid, m_null_bits(0), m_meta_memory(NULL) { + uchar cbuf[sizeof(m_colcnt) + 1]; + uchar *cbuf_end; DBUG_ASSERT(m_table_id != ~0UL); /* In TABLE_SHARE, "db" and "table_name" are 0-terminated (see this comment in @@ -7756,7 +7765,9 @@ Table_map_log_event::Table_map_log_event(THD *thd, TABLE *tbl, ulong tid, DBUG_EXECUTE_IF("old_row_based_repl_4_byte_map_id_master", m_data_size= 6;); m_data_size+= m_dblen + 2; // Include length and terminating \0 m_data_size+= m_tbllen + 2; // Include length and terminating \0 - m_data_size+= 1 + m_colcnt; // COLCNT and column types + cbuf_end= net_store_length(cbuf, (size_t) m_colcnt); + DBUG_ASSERT(static_cast<size_t>(cbuf_end - cbuf) <= sizeof(cbuf)); + m_data_size+= (cbuf_end - cbuf) + m_colcnt; // COLCNT and column types /* If malloc fails, caught in is_valid() */ if ((m_memory= (uchar*) my_malloc(m_colcnt, MYF(MY_WME)))) @@ -7895,7 +7906,7 @@ Table_map_log_event::Table_map_log_event(const char *buf, uint event_len, memcpy(m_coltype, ptr_after_colcnt, m_colcnt); ptr_after_colcnt= ptr_after_colcnt + m_colcnt; - bytes_read= ptr_after_colcnt - (uchar *)buf; + bytes_read= (uint) (ptr_after_colcnt - (uchar *)buf); DBUG_PRINT("info", ("Bytes read: %d.\n", bytes_read)); if (bytes_read < event_len) { @@ -8048,7 +8059,7 @@ bool Table_map_log_event::write_data_body(IO_CACHE *file) uchar const dbuf[]= { (uchar) m_dblen }; uchar const tbuf[]= { (uchar) m_tbllen }; - uchar cbuf[sizeof(m_colcnt)]; + uchar cbuf[sizeof(m_colcnt) + 1]; uchar *const cbuf_end= net_store_length(cbuf, (size_t) m_colcnt); DBUG_ASSERT(static_cast<size_t>(cbuf_end - cbuf) <= sizeof(cbuf)); @@ -9269,7 +9280,7 @@ bool Incident_log_event::write_data_body(IO_CACHE *file) { DBUG_ENTER("Incident_log_event::write_data_body"); - DBUG_RETURN(write_str(file, m_message.str, m_message.length)); + DBUG_RETURN(write_str(file, m_message.str, (uint) m_message.length)); } |