Commit 781ad971 authored by Sergei Golubchik's avatar Sergei Golubchik Committed by Nikita Malyavin

separate online_alter_cache_data from binlog_cache_data

parent 9298c2f3
...@@ -7233,39 +7233,6 @@ bool handler::check_table_binlog_row_based_internal() ...@@ -7233,39 +7233,6 @@ bool handler::check_table_binlog_row_based_internal()
mysql_bin_log.is_open())); mysql_bin_log.is_open()));
} }
#ifdef HAVE_REPLICATION
static int binlog_log_row_online_alter(TABLE* table,
const uchar *before_record,
const uchar *after_record,
Log_func *log_func)
{
THD *thd= table->in_use;
if (!table->online_alter_cache)
{
table->online_alter_cache= online_alter_binlog_get_cache_data(thd, table);
trans_register_ha(thd, false, binlog_hton, 0);
if (thd->in_multi_stmt_transaction_mode())
trans_register_ha(thd, true, binlog_hton, 0);
}
// We need to log all columns for the case if alter table changes primary key
DBUG_ASSERT(!before_record || bitmap_is_set_all(table->read_set));
MY_BITMAP *old_rpl_write_set= table->rpl_write_set;
table->rpl_write_set= &table->s->all_set;
int error= (*log_func)(thd, table, table->s->online_alter_binlog,
table->online_alter_cache, true,
before_record, after_record);
table->rpl_write_set= old_rpl_write_set;
return unlikely(error) ? HA_ERR_RBR_LOGGING_FAILED : 0;
}
#endif // HAVE_REPLICATION
static int binlog_log_row_to_binlog(TABLE* table, static int binlog_log_row_to_binlog(TABLE* table,
const uchar *before_record, const uchar *before_record,
const uchar *after_record, const uchar *after_record,
......
...@@ -655,6 +655,7 @@ typedef ulonglong alter_table_operations; ...@@ -655,6 +655,7 @@ typedef ulonglong alter_table_operations;
class Event_log; class Event_log;
class Cache_flip_event_log; class Cache_flip_event_log;
class binlog_cache_data; class binlog_cache_data;
class online_alter_cache_data;
typedef bool Log_func(THD*, TABLE*, Event_log *, binlog_cache_data *, bool, typedef bool Log_func(THD*, TABLE*, Event_log *, binlog_cache_data *, bool,
const uchar*, const uchar*); const uchar*, const uchar*);
......
...@@ -275,13 +275,11 @@ void make_default_log_name(char **out, const char* log_ext, bool once) ...@@ -275,13 +275,11 @@ void make_default_log_name(char **out, const char* log_ext, bool once)
Helper classes to store non-transactional and transactional data Helper classes to store non-transactional and transactional data
before copying it to the binary log. before copying it to the binary log.
*/ */
class binlog_cache_data: public Sql_alloc, public ilist_node<> class binlog_cache_data
{ {
public: public:
binlog_cache_data(): share(0), sv_list(0), m_pending(0), status(0), binlog_cache_data(): before_stmt_pos(MY_OFF_T_UNDEF), m_pending(0), status(0),
before_stmt_pos(MY_OFF_T_UNDEF), incident(FALSE), saved_max_binlog_cache_size(0), ptr_binlog_cache_use(0),
incident(FALSE),
saved_max_binlog_cache_size(0), ptr_binlog_cache_use(0),
ptr_binlog_cache_disk_use(0) ptr_binlog_cache_disk_use(0)
{ } { }
...@@ -361,11 +359,6 @@ class binlog_cache_data: public Sql_alloc, public ilist_node<> ...@@ -361,11 +359,6 @@ class binlog_cache_data: public Sql_alloc, public ilist_node<>
before_stmt_pos= pos; before_stmt_pos= pos;
} }
void store_prev_position()
{
before_stmt_pos= my_b_write_tell(&cache_log);
}
void restore_prev_position() void restore_prev_position()
{ {
truncate(before_stmt_pos); truncate(before_stmt_pos);
...@@ -418,8 +411,12 @@ class binlog_cache_data: public Sql_alloc, public ilist_node<> ...@@ -418,8 +411,12 @@ class binlog_cache_data: public Sql_alloc, public ilist_node<>
*/ */
IO_CACHE cache_log; IO_CACHE cache_log;
TABLE_SHARE *share; // for online alter table protected:
SAVEPOINT *sv_list; /*
Binlog position before the start of the current statement.
*/
my_off_t before_stmt_pos;
private: private:
/* /*
Pending binrows event. This event is the event where the rows are currently Pending binrows event. This event is the event where the rows are currently
...@@ -434,11 +431,6 @@ class binlog_cache_data: public Sql_alloc, public ilist_node<> ...@@ -434,11 +431,6 @@ class binlog_cache_data: public Sql_alloc, public ilist_node<>
*/ */
uint32 status; uint32 status;
/*
Binlog position before the start of the current statement.
*/
my_off_t before_stmt_pos;
/* /*
This indicates that some events did not get into the cache and most likely This indicates that some events did not get into the cache and most likely
it is corrupted. it is corrupted.
...@@ -506,6 +498,19 @@ class binlog_cache_data: public Sql_alloc, public ilist_node<> ...@@ -506,6 +498,19 @@ class binlog_cache_data: public Sql_alloc, public ilist_node<>
}; };
class online_alter_cache_data: public Sql_alloc, public ilist_node<>,
public binlog_cache_data
{
public:
void store_prev_position()
{
before_stmt_pos= my_b_write_tell(&cache_log);
}
TABLE_SHARE *share;
SAVEPOINT *sv_list;
};
void Log_event_writer::add_status(enum_logged_status status) void Log_event_writer::add_status(enum_logged_status status)
{ {
if (likely(cache_data)) if (likely(cache_data))
...@@ -2261,8 +2266,35 @@ static int binlog_commit_flush_xa_prepare(THD *thd, bool all, ...@@ -2261,8 +2266,35 @@ static int binlog_commit_flush_xa_prepare(THD *thd, bool all,
} }
#ifdef HAVE_REPLICATION #ifdef HAVE_REPLICATION
int binlog_log_row_online_alter(TABLE* table, const uchar *before_record,
const uchar *after_record, Log_func *log_func)
{
THD *thd= table->in_use;
if (!table->online_alter_cache)
{
table->online_alter_cache= online_alter_binlog_get_cache_data(thd, table);
trans_register_ha(thd, false, binlog_hton, 0);
if (thd->in_multi_stmt_transaction_mode())
trans_register_ha(thd, true, binlog_hton, 0);
}
// We need to log all columns for the case if alter table changes primary key
DBUG_ASSERT(!before_record || bitmap_is_set_all(table->read_set));
MY_BITMAP *old_rpl_write_set= table->rpl_write_set;
table->rpl_write_set= &table->s->all_set;
int error= (*log_func)(thd, table, table->s->online_alter_binlog,
table->online_alter_cache, true,
before_record, after_record);
table->rpl_write_set= old_rpl_write_set;
return unlikely(error) ? HA_ERR_RBR_LOGGING_FAILED : 0;
}
static void static void
binlog_online_alter_cleanup(ilist<binlog_cache_data> &list, bool ending_trans) binlog_online_alter_cleanup(ilist<online_alter_cache_data> &list, bool ending_trans)
{ {
if (ending_trans) if (ending_trans)
{ {
...@@ -6355,9 +6387,9 @@ bool MYSQL_BIN_LOG::write_table_map(THD *thd, TABLE *table, bool with_annotate) ...@@ -6355,9 +6387,9 @@ bool MYSQL_BIN_LOG::write_table_map(THD *thd, TABLE *table, bool with_annotate)
#ifdef HAVE_REPLICATION #ifdef HAVE_REPLICATION
static binlog_cache_data *binlog_setup_cache_data(MEM_ROOT *root, TABLE_SHARE *share) static online_alter_cache_data *binlog_setup_cache_data(MEM_ROOT *root, TABLE_SHARE *share)
{ {
auto cache= new (root) binlog_cache_data(); auto cache= new (root) online_alter_cache_data();
if (!cache || open_cached_file(&cache->cache_log, mysql_tmpdir, if (!cache || open_cached_file(&cache->cache_log, mysql_tmpdir,
LOG_PREFIX, (size_t)binlog_cache_size, MYF(MY_WME))) LOG_PREFIX, (size_t)binlog_cache_size, MYF(MY_WME)))
{ {
...@@ -6372,9 +6404,9 @@ static binlog_cache_data *binlog_setup_cache_data(MEM_ROOT *root, TABLE_SHARE *s ...@@ -6372,9 +6404,9 @@ static binlog_cache_data *binlog_setup_cache_data(MEM_ROOT *root, TABLE_SHARE *s
return cache; return cache;
} }
binlog_cache_data *online_alter_binlog_get_cache_data(THD *thd, TABLE *table) online_alter_cache_data *online_alter_binlog_get_cache_data(THD *thd, TABLE *table)
{ {
ilist<binlog_cache_data> &list= thd->online_alter_cache_list; ilist<online_alter_cache_data> &list= thd->online_alter_cache_list;
/* we assume it's very rare to have more than one online ALTER running */ /* we assume it's very rare to have more than one online ALTER running */
for (auto &cache: list) for (auto &cache: list)
......
...@@ -1320,7 +1320,9 @@ int binlog_flush_pending_rows_event(THD *thd, bool stmt_end, ...@@ -1320,7 +1320,9 @@ int binlog_flush_pending_rows_event(THD *thd, bool stmt_end,
binlog_cache_data *cache_data); binlog_cache_data *cache_data);
Rows_log_event* binlog_get_pending_rows_event(binlog_cache_mngr *cache_mngr, Rows_log_event* binlog_get_pending_rows_event(binlog_cache_mngr *cache_mngr,
bool use_trans_cache); bool use_trans_cache);
binlog_cache_data *online_alter_binlog_get_cache_data(THD *thd, TABLE *table); int binlog_log_row_online_alter(TABLE* table, const uchar *before_record,
const uchar *after_record, Log_func *log_func);
online_alter_cache_data *online_alter_binlog_get_cache_data(THD *thd, TABLE *table);
binlog_cache_data* binlog_get_cache_data(binlog_cache_mngr *cache_mngr, binlog_cache_data* binlog_get_cache_data(binlog_cache_mngr *cache_mngr,
bool use_trans_cache); bool use_trans_cache);
......
...@@ -5547,7 +5547,7 @@ class THD: public THD_count, /* this must be first */ ...@@ -5547,7 +5547,7 @@ class THD: public THD_count, /* this must be first */
Item *sp_prepare_func_item(Item **it_addr, uint cols); Item *sp_prepare_func_item(Item **it_addr, uint cols);
bool sp_eval_expr(Field *result_field, Item **expr_item_ptr); bool sp_eval_expr(Field *result_field, Item **expr_item_ptr);
ilist<binlog_cache_data> online_alter_cache_list; ilist<online_alter_cache_data> online_alter_cache_list;
bool sql_parser(LEX *old_lex, LEX *lex, bool sql_parser(LEX *old_lex, LEX *lex,
char *str, uint str_len, bool stmt_prepare_mode); char *str, uint str_len, bool stmt_prepare_mode);
......
...@@ -1617,7 +1617,7 @@ struct TABLE ...@@ -1617,7 +1617,7 @@ struct TABLE
*/ */
Item *notnull_cond; Item *notnull_cond;
binlog_cache_data *online_alter_cache; online_alter_cache_data *online_alter_cache;
inline void reset() { bzero((void*)this, sizeof(*this)); } inline void reset() { bzero((void*)this, sizeof(*this)); }
void init(THD *thd, TABLE_LIST *tl); void init(THD *thd, TABLE_LIST *tl);
......
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