Skip to content

Commit f7048e9

Browse files
committed
Move common code to a separate function
1 parent 2864164 commit f7048e9

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

sql/table_cache.cc

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,31 @@ static void tc_remove_table(TABLE *table)
152152
}
153153

154154

155+
static void tc_remove_all_unused_tables(TDC_element *element,
156+
TABLE_list *purge_tables,
157+
bool mark_flushed)
158+
{
159+
TABLE *table;
160+
161+
element->wait_for_mdl_deadlock_detector();
162+
/*
163+
Mark share flushed in order to ensure that it gets
164+
automatically deleted once it is no longer referenced.
165+
166+
Note that code in TABLE_SHARE::wait_for_old_version() assumes that
167+
marking share flushed is followed by purge of unused table
168+
shares.
169+
*/
170+
if (mark_flushed)
171+
element->flushed= true;
172+
while ((table= element->free_tables.pop_front()))
173+
{
174+
tc_remove_table(table);
175+
purge_tables->push_front(table);
176+
}
177+
}
178+
179+
155180
/**
156181
Free all unused TABLE objects.
157182
@@ -176,17 +201,8 @@ struct tc_purge_arg
176201

177202
static my_bool tc_purge_callback(TDC_element *element, tc_purge_arg *arg)
178203
{
179-
TABLE *table;
180-
181204
mysql_mutex_lock(&element->LOCK_table_share);
182-
element->wait_for_mdl_deadlock_detector();
183-
if (arg->mark_flushed)
184-
element->flushed= true;
185-
while ((table= element->free_tables.pop_front()))
186-
{
187-
tc_remove_table(table);
188-
arg->purge_tables.push_front(table);
189-
}
205+
tc_remove_all_unused_tables(element, &arg->purge_tables, arg->mark_flushed);
190206
mysql_mutex_unlock(&element->LOCK_table_share);
191207
return FALSE;
192208
}
@@ -880,23 +896,9 @@ bool tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,
880896

881897
element->ref_count++;
882898

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

888-
Note that code in TABLE_SHARE::wait_for_old_version() assumes that
889-
marking share flushed is followed by purge of unused table
890-
shares.
891-
*/
892-
if (remove_type != TDC_RT_REMOVE_NOT_OWN_KEEP_SHARE)
893-
element->flushed= true;
894-
895-
while ((table= element->free_tables.pop_front()))
896-
{
897-
tc_remove_table(table);
898-
purge_tables.push_front(table);
899-
}
900902
if (kill_delayed_threads)
901903
kill_delayed_threads_for_table(element);
902904

0 commit comments

Comments
 (0)