mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Code cleanups
- unused TABLE_SHARE::deleting and TABLE_LIST::deleting flags were removed - kill_delayed_threads_for_table() and intern_close_table() are now private methods of table cache - removed free_share flag of closefrm(): it was never used for temporary tables and was rarely useful for regular tables
This commit is contained in:
@ -4694,7 +4694,7 @@ int ha_create_table(THD *thd, const char *path,
|
||||
share.table_name.str, share.table_name.length);
|
||||
}
|
||||
|
||||
(void) closefrm(&table, 0);
|
||||
(void) closefrm(&table);
|
||||
|
||||
err:
|
||||
free_table_share(&share);
|
||||
|
@ -261,7 +261,10 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list,
|
||||
end:
|
||||
thd->locked_tables_list.unlink_all_closed_tables(thd, NULL, 0);
|
||||
if (table == &tmp_table)
|
||||
closefrm(table, 1); // Free allocated memory
|
||||
{
|
||||
closefrm(table);
|
||||
tdc_release_share(table->s);
|
||||
}
|
||||
/* In case of a temporary table there will be no metadata lock. */
|
||||
if (error && has_mdl_lock)
|
||||
thd->mdl_context.release_transactional_locks();
|
||||
|
@ -336,68 +336,6 @@ OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild)
|
||||
DBUG_RETURN(argument.open_list);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Functions to free open table cache
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
void intern_close_table(TABLE *table)
|
||||
{ // Free all structures
|
||||
DBUG_ENTER("intern_close_table");
|
||||
DBUG_PRINT("tcache", ("table: '%s'.'%s' 0x%lx",
|
||||
table->s ? table->s->db.str : "?",
|
||||
table->s ? table->s->table_name.str : "?",
|
||||
(long) table));
|
||||
|
||||
delete table->triggers;
|
||||
if (table->file) // Not true if placeholder
|
||||
(void) closefrm(table, 1); // close file
|
||||
table->alias.free();
|
||||
my_free(table);
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Auxiliary function which allows to kill delayed threads for
|
||||
particular table identified by its share.
|
||||
|
||||
@param share Table share.
|
||||
|
||||
@pre Caller should have TABLE_SHARE::tdc.LOCK_table_share mutex.
|
||||
*/
|
||||
|
||||
void kill_delayed_threads_for_table(TDC_element *element)
|
||||
{
|
||||
TDC_element::All_share_tables_list::Iterator it(element->all_tables);
|
||||
TABLE *tab;
|
||||
|
||||
mysql_mutex_assert_owner(&element->LOCK_table_share);
|
||||
|
||||
if (!delayed_insert_threads)
|
||||
return;
|
||||
|
||||
while ((tab= it++))
|
||||
{
|
||||
THD *in_use= tab->in_use;
|
||||
|
||||
DBUG_ASSERT(in_use && tab->s->tdc->flushed);
|
||||
if ((in_use->system_thread & SYSTEM_THREAD_DELAYED_INSERT) &&
|
||||
! in_use->killed)
|
||||
{
|
||||
in_use->killed= KILL_SYSTEM_THREAD;
|
||||
mysql_mutex_lock(&in_use->mysys_var->mutex);
|
||||
if (in_use->mysys_var->current_cond)
|
||||
{
|
||||
mysql_mutex_lock(in_use->mysys_var->current_mutex);
|
||||
mysql_cond_broadcast(in_use->mysys_var->current_cond);
|
||||
mysql_mutex_unlock(in_use->mysys_var->current_mutex);
|
||||
}
|
||||
mysql_mutex_unlock(&in_use->mysys_var->mutex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Close all tables which aren't in use by any thread
|
||||
@ -1779,7 +1717,7 @@ void close_temporary(TABLE *table, bool free_share, bool delete_table)
|
||||
DBUG_PRINT("tmptable", ("closing table: '%s'.'%s'",
|
||||
table->s->db.str, table->s->table_name.str));
|
||||
|
||||
closefrm(table, 0);
|
||||
closefrm(table);
|
||||
if (delete_table)
|
||||
rm_temporary_table(table_type, table->s->path.str);
|
||||
if (free_share)
|
||||
@ -2545,7 +2483,7 @@ retry_share:
|
||||
}
|
||||
if (open_table_entry_fini(thd, share, table))
|
||||
{
|
||||
closefrm(table, 0);
|
||||
closefrm(table);
|
||||
my_free(table);
|
||||
goto err_lock;
|
||||
}
|
||||
@ -3361,12 +3299,12 @@ static bool auto_repair_table(THD *thd, TABLE_LIST *table_list)
|
||||
sql_print_error("Couldn't repair table: %s.%s", share->db.str,
|
||||
share->table_name.str);
|
||||
if (entry->file)
|
||||
closefrm(entry, 0);
|
||||
closefrm(entry);
|
||||
}
|
||||
else
|
||||
{
|
||||
thd->clear_error(); // Clear error message
|
||||
closefrm(entry, 0);
|
||||
closefrm(entry);
|
||||
result= FALSE;
|
||||
}
|
||||
|
||||
|
@ -271,8 +271,6 @@ bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags,
|
||||
uint dt_phases);
|
||||
bool lock_tables(THD *thd, TABLE_LIST *tables, uint counter, uint flags);
|
||||
int decide_logging_format(THD *thd, TABLE_LIST *tables);
|
||||
void intern_close_table(TABLE *entry);
|
||||
void kill_delayed_threads_for_table(TDC_element *element);
|
||||
void close_thread_table(THD *thd, TABLE **table_ptr);
|
||||
bool close_temporary_tables(THD *thd);
|
||||
TABLE_LIST *unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
|
||||
|
@ -4889,7 +4889,7 @@ int create_table_impl(THD *thd,
|
||||
open_table_from_share(thd, &share, "", 0, (uint) READ_ALL,
|
||||
0, &table, true));
|
||||
if (!result)
|
||||
(void) closefrm(&table, 0);
|
||||
(void) closefrm(&table);
|
||||
|
||||
free_table_share(&share);
|
||||
|
||||
|
14
sql/table.cc
14
sql/table.cc
@ -3020,21 +3020,16 @@ partititon_err:
|
||||
SYNOPSIS
|
||||
closefrm()
|
||||
table TABLE object to free
|
||||
free_share Is 1 if we also want to free table_share
|
||||
*/
|
||||
|
||||
int closefrm(register TABLE *table, bool free_share)
|
||||
int closefrm(register TABLE *table)
|
||||
{
|
||||
int error=0;
|
||||
DBUG_ENTER("closefrm");
|
||||
DBUG_PRINT("enter", ("table: 0x%lx", (long) table));
|
||||
|
||||
if (table->db_stat)
|
||||
{
|
||||
if (table->s->deleting)
|
||||
table->file->extra(HA_EXTRA_PREPARE_FOR_DROP);
|
||||
error=table->file->ha_close();
|
||||
}
|
||||
table->alias.free();
|
||||
if (table->expr_arena)
|
||||
table->expr_arena->free_items();
|
||||
@ -3057,13 +3052,6 @@ int closefrm(register TABLE *table, bool free_share)
|
||||
table->part_info= 0;
|
||||
}
|
||||
#endif
|
||||
if (free_share)
|
||||
{
|
||||
if (table->s->tmp_table == NO_TMP_TABLE)
|
||||
tdc_release_share(table->s);
|
||||
else
|
||||
free_table_share(table->s);
|
||||
}
|
||||
free_root(&table->mem_root, MYF(0));
|
||||
DBUG_RETURN(error);
|
||||
}
|
||||
|
@ -673,7 +673,6 @@ struct TABLE_SHARE
|
||||
bool crypted; /* If .frm file is crypted */
|
||||
bool crashed;
|
||||
bool is_view;
|
||||
bool deleting; /* going to delete this table */
|
||||
bool can_cmp_whole_record;
|
||||
bool table_creation_was_logged;
|
||||
ulong table_map_id; /* for row-based replication */
|
||||
@ -2019,8 +2018,6 @@ struct TABLE_LIST
|
||||
*/
|
||||
bool is_fqtn;
|
||||
|
||||
bool deleting; /* going to delete this table */
|
||||
|
||||
/* TRUE <=> derived table should be filled right after optimization. */
|
||||
bool fill_me;
|
||||
/* TRUE <=> view/DT is merged. */
|
||||
@ -2621,7 +2618,7 @@ bool get_field(MEM_ROOT *mem, Field *field, class String *res);
|
||||
bool validate_comment_length(THD *thd, LEX_STRING *comment, size_t max_len,
|
||||
uint err_code, const char *name);
|
||||
|
||||
int closefrm(TABLE *table, bool free_share);
|
||||
int closefrm(TABLE *table);
|
||||
void free_blobs(TABLE *table);
|
||||
void free_field_buffers_larger_than(TABLE *table, uint32 size);
|
||||
ulong get_form_pos(File file, uchar *head, TYPELIB *save_names);
|
||||
|
@ -36,8 +36,6 @@
|
||||
- get number of TABLE objects in cache (tc_records())
|
||||
|
||||
Dependencies:
|
||||
- intern_close_table(): frees TABLE object
|
||||
- kill_delayed_threads_for_table()
|
||||
- close_cached_tables(): flush tables on shutdown
|
||||
- alloc_table_share()
|
||||
- free_table_share()
|
||||
@ -127,6 +125,25 @@ static int fix_thd_pins(THD *thd)
|
||||
part of table definition cache.
|
||||
*/
|
||||
|
||||
static void intern_close_table(TABLE *table)
|
||||
{
|
||||
DBUG_ENTER("intern_close_table");
|
||||
DBUG_PRINT("tcache", ("table: '%s'.'%s' 0x%lx",
|
||||
table->s ? table->s->db.str : "?",
|
||||
table->s ? table->s->table_name.str : "?",
|
||||
(long) table));
|
||||
|
||||
delete table->triggers;
|
||||
if (table->file) // Not true if placeholder
|
||||
{
|
||||
(void) closefrm(table);
|
||||
tdc_release_share(table->s);
|
||||
}
|
||||
table->alias.free();
|
||||
my_free(table);
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Get number of TABLE objects (used and unused) in table cache.
|
||||
@ -938,6 +955,47 @@ void tdc_release_share(TABLE_SHARE *share)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Auxiliary function which allows to kill delayed threads for
|
||||
particular table identified by its share.
|
||||
|
||||
@param share Table share.
|
||||
|
||||
@pre Caller should have TABLE_SHARE::tdc.LOCK_table_share mutex.
|
||||
*/
|
||||
|
||||
static void kill_delayed_threads_for_table(TDC_element *element)
|
||||
{
|
||||
TDC_element::All_share_tables_list::Iterator it(element->all_tables);
|
||||
TABLE *tab;
|
||||
|
||||
mysql_mutex_assert_owner(&element->LOCK_table_share);
|
||||
|
||||
if (!delayed_insert_threads)
|
||||
return;
|
||||
|
||||
while ((tab= it++))
|
||||
{
|
||||
THD *in_use= tab->in_use;
|
||||
|
||||
DBUG_ASSERT(in_use && tab->s->tdc->flushed);
|
||||
if ((in_use->system_thread & SYSTEM_THREAD_DELAYED_INSERT) &&
|
||||
! in_use->killed)
|
||||
{
|
||||
in_use->killed= KILL_SYSTEM_THREAD;
|
||||
mysql_mutex_lock(&in_use->mysys_var->mutex);
|
||||
if (in_use->mysys_var->current_cond)
|
||||
{
|
||||
mysql_mutex_lock(in_use->mysys_var->current_mutex);
|
||||
mysql_cond_broadcast(in_use->mysys_var->current_cond);
|
||||
mysql_mutex_unlock(in_use->mysys_var->current_mutex);
|
||||
}
|
||||
mysql_mutex_unlock(&in_use->mysys_var->mutex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Remove all or some (depending on parameter) instances of TABLE and
|
||||
TABLE_SHARE from the table definition cache.
|
||||
|
@ -663,7 +663,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
|
||||
{
|
||||
fprint_error("Column '%s.%s' (origid) is not a not-null integer type",
|
||||
options->table_name, options->origid);
|
||||
closefrm(edges, 0);
|
||||
closefrm(edges);
|
||||
free_table_share(share);
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
@ -673,7 +673,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
|
||||
|
||||
if (!origid) {
|
||||
fprint_error("Invalid OQGRAPH backing store ('%s.origid' attribute not set to a valid column of '%s')", p+1, options->table_name);
|
||||
closefrm(edges, 0);
|
||||
closefrm(edges);
|
||||
free_table_share(share);
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
@ -688,7 +688,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
|
||||
{
|
||||
fprint_error("Column '%s.%s' (destid) is not a not-null integer type or is a different type to origid attribute.",
|
||||
options->table_name, options->destid);
|
||||
closefrm(edges, 0);
|
||||
closefrm(edges);
|
||||
free_table_share(share);
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
@ -698,7 +698,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
|
||||
|
||||
if (!destid) {
|
||||
fprint_error("Invalid OQGRAPH backing store ('%s.destid' attribute not set to a valid column of '%s')", p+1, options->table_name);
|
||||
closefrm(edges, 0);
|
||||
closefrm(edges);
|
||||
free_table_share(share);
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
@ -706,7 +706,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
|
||||
// Make sure origid column != destid column
|
||||
if (strcmp( origid->field_name, destid->field_name)==0) {
|
||||
fprint_error("Invalid OQGRAPH backing store ('%s.destid' attribute set to same column as origid attribute)", p+1, options->table_name);
|
||||
closefrm(edges, 0);
|
||||
closefrm(edges);
|
||||
free_table_share(share);
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
@ -720,7 +720,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
|
||||
{
|
||||
fprint_error("Column '%s.%s' (weight) is not a not-null real type",
|
||||
options->table_name, options->weight);
|
||||
closefrm(edges, 0);
|
||||
closefrm(edges);
|
||||
free_table_share(share);
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
@ -730,7 +730,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
|
||||
|
||||
if (!weight && options->weight) {
|
||||
fprint_error("Invalid OQGRAPH backing store ('%s.weight' attribute not set to a valid column of '%s')", p+1, options->table_name);
|
||||
closefrm(edges, 0);
|
||||
closefrm(edges);
|
||||
free_table_share(share);
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
@ -738,7 +738,7 @@ int ha_oqgraph::open(const char *name, int mode, uint test_if_locked)
|
||||
if (!(graph_share = oqgraph::create(edges, origid, destid, weight)))
|
||||
{
|
||||
fprint_error("Unable to create graph instance.");
|
||||
closefrm(edges, 0);
|
||||
closefrm(edges);
|
||||
free_table_share(share);
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
@ -763,7 +763,7 @@ int ha_oqgraph::close(void)
|
||||
if (have_table_share)
|
||||
{
|
||||
if (edges->file)
|
||||
closefrm(edges, 0);
|
||||
closefrm(edges);
|
||||
free_table_share(share);
|
||||
have_table_share = false;
|
||||
}
|
||||
|
@ -227,7 +227,8 @@ void spider_close_sys_table(
|
||||
close_performance_schema_table(thd, open_tables_backup);
|
||||
} else {
|
||||
table->file->ha_reset();
|
||||
closefrm(table, TRUE);
|
||||
closefrm(table);
|
||||
tdc_release_share(table->s);
|
||||
spider_free(spider_current_trx, table, MYF(0));
|
||||
thd->restore_backup_open_tables_state(open_tables_backup);
|
||||
}
|
||||
|
Reference in New Issue
Block a user