Commit 41d68cab authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: Log_event::write() and MYSQL_BIN_LOG::write_cache()

Introduce Log_event_writer() that encapsulates
writing data to an IO_CACHE with automatic checksum calculation.

Now all events properly checksum themselves as needed.

Use Log_event_writer in MYSQL_BIN_LOG::write_cache() instead
of copy-pasting its logic all over.

Later Log_event_writer will also do encryption.
parent 704ba5c5
This diff is collapsed.
......@@ -737,6 +737,9 @@ public:
void stop_union_events(THD *thd);
bool is_query_in_union(THD *thd, query_id_t query_id_param);
bool write_event(Log_event *ev, IO_CACHE *file);
bool write_event(Log_event *ev) { return write_event(ev, &log_file); }
/*
v stands for vector
invoked as appendv(buf1,len1,buf2,len2,...,bufn,lenn,0)
......
This diff is collapsed.
This diff is collapsed.
......@@ -1753,7 +1753,7 @@ Old_rows_log_event::do_update_pos(rpl_group_info *rgi)
#ifndef MYSQL_CLIENT
bool Old_rows_log_event::write_data_header(IO_CACHE *file)
bool Old_rows_log_event::write_data_header()
{
uchar buf[ROWS_HEADER_LEN]; // No need to init the buffer
......@@ -1765,15 +1765,15 @@ bool Old_rows_log_event::write_data_header(IO_CACHE *file)
{
int4store(buf + 0, m_table_id);
int2store(buf + 4, m_flags);
return (my_b_safe_write(file, buf, 6));
return write_data(buf, 6);
});
int6store(buf + RW_MAPID_OFFSET, (ulonglong)m_table_id);
int2store(buf + RW_FLAGS_OFFSET, m_flags);
return (my_b_safe_write(file, buf, ROWS_HEADER_LEN));
return write_data(buf, ROWS_HEADER_LEN);
}
bool Old_rows_log_event::write_data_body(IO_CACHE*file)
bool Old_rows_log_event::write_data_body()
{
/*
Note that this should be the number of *bits*, not the number of
......@@ -1790,13 +1790,12 @@ bool Old_rows_log_event::write_data_body(IO_CACHE*file)
DBUG_ASSERT(static_cast<size_t>(sbuf_end - sbuf) <= sizeof(sbuf));
DBUG_DUMP("m_width", sbuf, (size_t) (sbuf_end - sbuf));
res= res || my_b_safe_write(file, sbuf, (size_t) (sbuf_end - sbuf));
res= res || write_data(sbuf, (size_t) (sbuf_end - sbuf));
DBUG_DUMP("m_cols", (uchar*) m_cols.bitmap, no_bytes_in_map(&m_cols));
res= res || my_b_safe_write(file, (uchar*) m_cols.bitmap,
no_bytes_in_map(&m_cols));
res= res || write_data((uchar*)m_cols.bitmap, no_bytes_in_map(&m_cols));
DBUG_DUMP("rows", m_rows_buf, data_size);
res= res || my_b_safe_write(file, m_rows_buf, (size_t) data_size);
res= res || write_data(m_rows_buf, (size_t) data_size);
return res;
......
......@@ -134,8 +134,8 @@ public:
ulong get_table_id() const { return m_table_id; }
#ifndef MYSQL_CLIENT
virtual bool write_data_header(IO_CACHE *file);
virtual bool write_data_body(IO_CACHE *file);
virtual bool write_data_header();
virtual bool write_data_body();
virtual const char *get_db() { return m_table->s->db.str; }
#endif
/*
......
......@@ -5501,7 +5501,7 @@ static int queue_event(Master_info* mi,const char* buf, ulong event_len)
mi->master_log_name, rev.new_log_ident);
mysql_mutex_lock(log_lock);
if (likely(!fdle.write(rli->relay_log.get_log_file()) &&
if (likely(!rli->relay_log.write_event(&fdle) &&
!rli->relay_log.flush_and_sync(NULL)))
{
rli->relay_log.harvest_bytes_written(&rli->log_space_total);
......
......@@ -445,6 +445,7 @@ void wsrep_dump_rbr_buf_with_header(THD *thd, const void *rbr_buf,
char filename[PATH_MAX]= {0};
File file;
IO_CACHE cache;
Log_event_writer writer(&cache);
Format_description_log_event *ev= wsrep_get_apply_format(thd);
int len= my_snprintf(filename, PATH_MAX, "%s/GRA_%ld_%lld_v2.log",
......@@ -476,7 +477,7 @@ void wsrep_dump_rbr_buf_with_header(THD *thd, const void *rbr_buf,
goto cleanup2;
}
if (ev->write(&cache) || my_b_write(&cache, (uchar*)rbr_buf, buf_len) ||
if (writer.write(ev) || my_b_write(&cache, (uchar*)rbr_buf, buf_len) ||
flush_io_cache(&cache))
{
WSREP_ERROR("Failed to write to '%s'.", filename);
......
......@@ -1215,6 +1215,7 @@ int wsrep_to_buf_helper(
THD* thd, const char *query, uint query_len, uchar** buf, size_t* buf_len)
{
IO_CACHE tmp_io_cache;
Log_event_writer writer(&tmp_io_cache);
if (open_cached_file(&tmp_io_cache, mysql_tmpdir, TEMP_PREFIX,
65536, MYF(MY_WME)))
return 1;
......@@ -1222,7 +1223,7 @@ int wsrep_to_buf_helper(
Format_description_log_event *tmp_fd= new Format_description_log_event(4);
tmp_fd->checksum_alg= (enum_binlog_checksum_alg)binlog_checksum_options;
tmp_fd->write(&tmp_io_cache);
writer.write(tmp_fd);
delete tmp_fd;
#ifdef GTID_SUPPORT
......@@ -1230,7 +1231,7 @@ int wsrep_to_buf_helper(
{
Gtid_log_event gtid_ev(thd, FALSE, &thd->variables.gtid_next);
if (!gtid_ev.is_valid()) ret= 0;
if (!ret && gtid_ev.write(&tmp_io_cache)) ret= 1;
if (!ret && writer.write(&gtid_ev)) ret= 1;
}
#endif /* GTID_SUPPORT */
......@@ -1240,12 +1241,12 @@ int wsrep_to_buf_helper(
Query_log_event ev(thd, thd->wsrep_TOI_pre_query,
thd->wsrep_TOI_pre_query_len,
FALSE, FALSE, FALSE, 0);
if (ev.write(&tmp_io_cache)) ret= 1;
if (writer.write(&ev)) ret= 1;
}
/* continue to append the actual query */
Query_log_event ev(thd, query, query_len, FALSE, FALSE, FALSE, 0);
if (!ret && ev.write(&tmp_io_cache)) ret= 1;
if (!ret && writer.write(&ev)) ret= 1;
if (!ret && wsrep_write_cache_buf(&tmp_io_cache, buf, buf_len)) ret= 1;
close_cached_file(&tmp_io_cache);
return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment