Skip to content

Commit

Permalink
Simplify rgi->get_table_data call
Browse files Browse the repository at this point in the history
  • Loading branch information
FooBarrior authored and vuvova committed Aug 15, 2023
1 parent b8c5f94 commit bdbd357
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
17 changes: 8 additions & 9 deletions sql/rpl_record.cc
Expand Up @@ -223,12 +223,10 @@ int unpack_row(rpl_group_info *rgi, TABLE *table, uint const colcnt,
// The "current" null bits
unsigned int null_bits= *null_ptr++;
uint i= 0;
table_def *tabledef= NULL;
TABLE *conv_table= NULL;
const Copy_field *copy_fields;
const Copy_field *copy_fields_end;
bool table_found= rgi && rgi->get_table_data(table, &tabledef, &conv_table,
&copy_fields, &copy_fields_end);
Rpl_table_data rpl_data{};
bool table_found= rgi && rgi->get_table_data(table, &rpl_data);
const table_def *tabledef= rpl_data.tabledef;
const TABLE *conv_table= rpl_data.conv_table;
DBUG_PRINT("debug", ("Table data: table_found: %d, tabldef: %p, conv_table: %p",
table_found, tabledef, conv_table));
DBUG_ASSERT(table_found);
Expand Down Expand Up @@ -350,7 +348,7 @@ int unpack_row(rpl_group_info *rgi, TABLE *table, uint const colcnt,
If copy_fields is set, it means we are doing an online alter table,
and will use copy_fields set up in copy_data_between_tables
*/
if (conv_field && !copy_fields)
if (conv_field && !rpl_data.is_online_alter())
{
Copy_field copy;
#ifndef DBUG_OFF
Expand Down Expand Up @@ -382,9 +380,10 @@ int unpack_row(rpl_group_info *rgi, TABLE *table, uint const colcnt,
i++;
}

if (copy_fields)
if (rpl_data.is_online_alter())
{
for (const auto *copy=copy_fields; copy != copy_fields_end; copy++)
for (const auto *copy=rpl_data.copy_fields;
copy != rpl_data.copy_fields_end; copy++)
{
copy->do_copy(copy);
}
Expand Down
31 changes: 22 additions & 9 deletions sql/rpl_rli.h
Expand Up @@ -669,6 +669,23 @@ struct start_alter_info
mysql_cond_t start_alter_cond;
};

struct Rpl_table_data
{
const table_def *tabledef;
TABLE *conv_table;
const Copy_field *copy_fields;
const Copy_field *copy_fields_end;
Rpl_table_data& operator =(const RPL_TABLE_LIST &rpl_table_list)
{
tabledef= &rpl_table_list.m_tabledef;
conv_table= rpl_table_list.m_conv_table;
copy_fields= rpl_table_list.m_online_alter_copy_fields;
copy_fields_end= rpl_table_list.m_online_alter_copy_fields_end;
return *this;
}
bool is_online_alter() const { return copy_fields != NULL; }
};

/*
This is data for various state needed to be kept for the processing of
one event group (transaction) during replication.
Expand Down Expand Up @@ -941,24 +958,20 @@ struct rpl_group_info
}
}

bool get_table_data(TABLE *table_arg, table_def **tabledef_var,
TABLE **conv_table_var,
const Copy_field *copy[], const Copy_field **copy_end) const
bool get_table_data(const TABLE *table_arg, Rpl_table_data *table_data) const
{
DBUG_ASSERT(tabledef_var && conv_table_var);
DBUG_ASSERT(table_data);
for (TABLE_LIST *ptr= tables_to_lock ; ptr != NULL ; ptr= ptr->next_global)
if (ptr->table == table_arg)
{
auto *rpl_table_list= static_cast<RPL_TABLE_LIST*>(ptr);
DBUG_ASSERT(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;
*table_data= *rpl_table_list;

DBUG_PRINT("debug", ("Fetching table data for table %s.%s:"
" tabledef: %p, conv_table: %p",
table_arg->s->db.str, table_arg->s->table_name.str,
*tabledef_var, *conv_table_var));
table_data->tabledef, table_data->conv_table));
return true;
}
return false;
Expand Down

0 comments on commit bdbd357

Please sign in to comment.