Skip to content

Commit

Permalink
Move common code to a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
svoj committed Jun 1, 2016
1 parent 2864164 commit f7048e9
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions sql/table_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,31 @@ static void tc_remove_table(TABLE *table)
}


static void tc_remove_all_unused_tables(TDC_element *element,
TABLE_list *purge_tables,
bool mark_flushed)
{
TABLE *table;

element->wait_for_mdl_deadlock_detector();
/*
Mark share flushed in order to ensure that it gets
automatically deleted once it is no longer referenced.
Note that code in TABLE_SHARE::wait_for_old_version() assumes that
marking share flushed is followed by purge of unused table
shares.
*/
if (mark_flushed)
element->flushed= true;
while ((table= element->free_tables.pop_front()))
{
tc_remove_table(table);
purge_tables->push_front(table);
}
}


/**
Free all unused TABLE objects.
Expand All @@ -176,17 +201,8 @@ struct tc_purge_arg

static my_bool tc_purge_callback(TDC_element *element, tc_purge_arg *arg)
{
TABLE *table;

mysql_mutex_lock(&element->LOCK_table_share);
element->wait_for_mdl_deadlock_detector();
if (arg->mark_flushed)
element->flushed= true;
while ((table= element->free_tables.pop_front()))
{
tc_remove_table(table);
arg->purge_tables.push_front(table);
}
tc_remove_all_unused_tables(element, &arg->purge_tables, arg->mark_flushed);
mysql_mutex_unlock(&element->LOCK_table_share);
return FALSE;
}
Expand Down Expand Up @@ -880,23 +896,9 @@ bool tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,

element->ref_count++;

element->wait_for_mdl_deadlock_detector();
/*
Mark share flushed in order to ensure that it gets
automatically deleted once it is no longer referenced.
tc_remove_all_unused_tables(element, &purge_tables,
remove_type != TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE);

Note that code in TABLE_SHARE::wait_for_old_version() assumes that
marking share flushed is followed by purge of unused table
shares.
*/
if (remove_type != TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE)
element->flushed= true;

while ((table= element->free_tables.pop_front()))
{
tc_remove_table(table);
purge_tables.push_front(table);
}
if (kill_delayed_threads)
kill_delayed_threads_for_table(element);

Expand Down

0 comments on commit f7048e9

Please sign in to comment.