summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Malyavin <nikitamalyavin@gmail.com>2020-03-26 01:04:49 +1000
committerNikita Malyavin <nikitamalyavin@gmail.com>2020-09-30 22:32:35 +1000
commit86d9fcce37258511336f40dcd72d5ac1d3c675e9 (patch)
treef2f6cc13e80a8fa7f707ee501853a1a32b028ae4
parente41eaba5c2f10577c88194ce3e554e3cb1991883 (diff)
downloadmariadb-git-86d9fcce37258511336f40dcd72d5ac1d3c675e9.tar.gz
it works!
-rw-r--r--sql/log.cc12
-rw-r--r--sql/log_event.h3
-rw-r--r--sql/log_event_server.cc11
-rw-r--r--sql/rpl_record.cc4
-rw-r--r--sql/rpl_rli.h3
-rw-r--r--sql/rpl_utility.h4
-rw-r--r--sql/sql_table.cc17
7 files changed, 40 insertions, 14 deletions
diff --git a/sql/log.cc b/sql/log.cc
index 3971787b5f8..21b5a2de1d6 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -2160,7 +2160,13 @@ static int binlog_commit(handlerton *hton, THD *thd, bool all)
auto *binlog= table->s->online_ater_binlog;
DBUG_ASSERT(binlog);
- error= binlog_flush_pending_rows_event(thd, true, true,
+ error= binlog_flush_pending_rows_event(thd,
+ /*
+ do not set STMT_END for last event
+ to leave table open in altering thd
+ */
+ false,
+ true,
binlog,
table->online_alter_cache);
if (unlikely(error))
@@ -2168,6 +2174,8 @@ static int binlog_commit(handlerton *hton, THD *thd, bool all)
mysql_mutex_lock(binlog->get_log_lock());
error= binlog->write_cache(thd, &table->online_alter_cache->cache_log);
+ if (!error)
+ error= binlog->flush_and_sync(NULL);
mysql_mutex_unlock(binlog->get_log_lock());
if (error)
@@ -2176,7 +2184,7 @@ static int binlog_commit(handlerton *hton, THD *thd, bool all)
DBUG_RETURN(error);
}
}
-
+
binlog_cache_mngr *const cache_mngr= thd->binlog_get_cache_mngr();
if (!cache_mngr)
diff --git a/sql/log_event.h b/sql/log_event.h
index 036bb9de43e..fdf6b20d097 100644
--- a/sql/log_event.h
+++ b/sql/log_event.h
@@ -4164,6 +4164,8 @@ private:
bool m_used_query_txt;
};
+class table_def;
+
/**
@class Table_map_log_event
@@ -4815,6 +4817,7 @@ public:
virtual bool print(FILE *file, PRINT_EVENT_INFO *print_event_info);
#endif
+ table_def get_table_def();
private:
#if defined(MYSQL_SERVER) && defined(HAVE_REPLICATION)
diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc
index e339315870b..8a99dd392ed 100644
--- a/sql/log_event_server.cc
+++ b/sql/log_event_server.cc
@@ -6359,6 +6359,13 @@ check_table_map(rpl_group_info *rgi, RPL_TABLE_LIST *table_list)
DBUG_RETURN(res);
}
+table_def Table_map_log_event::get_table_def()
+{
+ return table_def(m_coltype, m_colcnt,
+ m_field_metadata, m_field_metadata_size,
+ m_null_bits, m_flags);
+}
+
int Table_map_log_event::do_apply_event(rpl_group_info *rgi)
{
RPL_TABLE_LIST *table_list;
@@ -6404,9 +6411,7 @@ int Table_map_log_event::do_apply_event(rpl_group_info *rgi)
table_def destructor explicitly.
*/
new(table_list) RPL_TABLE_LIST(&tmp_db_name, &tmp_tbl_name, TL_WRITE,
- table_def(m_coltype, m_colcnt,
- m_field_metadata, m_field_metadata_size,
- m_null_bits, m_flags),
+ get_table_def(),
m_flags & TM_BIT_HAS_TRIGGERS_F);
table_list->table_id= DBUG_EVALUATE_IF("inject_tblmap_same_id_maps_diff_table",
diff --git a/sql/rpl_record.cc b/sql/rpl_record.cc
index 0e11961afed..29de111ac14 100644
--- a/sql/rpl_record.cc
+++ b/sql/rpl_record.cc
@@ -245,7 +245,9 @@ unpack_row(rpl_group_info *rgi,
if (rgi && !table_found)
DBUG_RETURN(HA_ERR_GENERIC);
- for (field_ptr= begin_ptr ; field_ptr < end_ptr && *field_ptr ; ++field_ptr)
+ for (field_ptr= begin_ptr;
+ tabledef && field_ptr < end_ptr && *field_ptr;
+ ++field_ptr)
{
/*
If there is a conversion table, we pick up the field pointer to
diff --git a/sql/rpl_rli.h b/sql/rpl_rli.h
index 123b38e2c5b..25013ed2148 100644
--- a/sql/rpl_rli.h
+++ b/sql/rpl_rli.h
@@ -907,7 +907,8 @@ struct rpl_group_info
if (ptr->table == table_arg)
{
auto *rpl_table_list= static_cast<RPL_TABLE_LIST*>(ptr);
- *tabledef_var= &rpl_table_list->m_tabledef;
+ if (rpl_table_list->m_tabledef_valid)
+ *tabledef_var= &rpl_table_list->m_tabledef;
*conv_table_var= rpl_table_list->m_conv_table;
*copy= rpl_table_list->m_online_alter_copy_fields;
*copy_end= rpl_table_list->m_online_alter_copy_fields_end;
diff --git a/sql/rpl_utility.h b/sql/rpl_utility.h
index 453089294ae..39f7eb659e6 100644
--- a/sql/rpl_utility.h
+++ b/sql/rpl_utility.h
@@ -257,10 +257,12 @@ struct RPL_TABLE_LIST
{}
RPL_TABLE_LIST(TABLE *table, thr_lock_type lock_type, TABLE *conv_table,
+ table_def tabledef,
const Copy_field online_alter_copy_fields[],
const Copy_field *online_alter_copy_fields_end)
: TABLE_LIST(table, lock_type),
- m_tabledef_valid(false), m_tabledef(NULL, 0, NULL, 0, NULL, 0),
+ m_tabledef_valid(true),
+ m_tabledef(tabledef),
m_conv_table(conv_table), master_had_triggers(false),
m_online_alter_copy_fields(online_alter_copy_fields),
m_online_alter_copy_fields_end(online_alter_copy_fields_end)
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 2aa913cb9aa..bd6be6f21ba 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -11663,9 +11663,13 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
if (online && error < 0)
{
+ Table_map_log_event table_event(thd, from, from->s->table_map_id,
+ from->file->has_transactions());
Relay_log_info rli(false);
rpl_group_info rgi(&rli);
- RPL_TABLE_LIST rpl_table(to, TL_WRITE, from, copy, copy_end);
+ RPL_TABLE_LIST rpl_table(to, TL_WRITE, from, table_event.get_table_def(),
+ copy, copy_end);
+ rgi.thd= thd;
rgi.tables_to_lock= &rpl_table;
rgi.m_table_map.set_table(from->s->table_map_id, to);
@@ -11685,17 +11689,18 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
rli.relay_log.description_event_for_exec=
new Format_description_log_event(4);
+ MEM_ROOT event_mem_root;
+ Query_arena backup_arena;
+ Query_arena event_arena(&event_mem_root, Query_arena::STMT_INITIALIZED);
+ init_sql_alloc(&event_mem_root, "event_memroot",
+ MEM_ROOT_BLOCK_SIZE, 0, MYF(0));
+
mysql_mutex_lock(binlog->get_log_lock()); // TODO decrease window
while (auto *ev= Log_event::read_log_event(&log,
rli.relay_log.description_event_for_exec, false))
{
ev->thd= thd;
- MEM_ROOT event_mem_root;
- Query_arena backup_arena;
- Query_arena event_arena(&event_mem_root, Query_arena::STMT_INITIALIZED);
- init_sql_alloc(&event_mem_root, "event_memroot",
- MEM_ROOT_BLOCK_SIZE, 0, MYF(0));
thd->set_n_backup_active_arena(&event_arena, &backup_arena);
ev->apply_event(&rgi);
thd->restore_active_arena(&event_arena, &backup_arena);