Commit c1d1c598 authored by Sergey Vojtovich's avatar Sergey Vojtovich

MDEV-9488 - Table cache cleanups

Remove tdc_acquire_share() helpers: they don't actually make things simpler.
parent d3af8942
...@@ -5047,7 +5047,9 @@ bool ha_table_exists(THD *thd, const char *db, const char *table_name, ...@@ -5047,7 +5047,9 @@ bool ha_table_exists(THD *thd, const char *db, const char *table_name,
Table_exists_error_handler no_such_table_handler; Table_exists_error_handler no_such_table_handler;
thd->push_internal_handler(&no_such_table_handler); thd->push_internal_handler(&no_such_table_handler);
TABLE_SHARE *share= tdc_acquire_share(thd, db, table_name, flags); table.init_one_table(db, strlen(db), table_name, strlen(table_name),
table_name, TL_READ);
TABLE_SHARE *share= tdc_acquire_share(thd, &table, flags);
thd->pop_internal_handler(); thd->pop_internal_handler();
if (hton && share) if (hton && share)
......
...@@ -131,7 +131,7 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list, ...@@ -131,7 +131,7 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list,
DBUG_RETURN(0); DBUG_RETURN(0);
has_mdl_lock= TRUE; has_mdl_lock= TRUE;
share= tdc_acquire_share_shortlived(thd, table_list, GTS_TABLE); share= tdc_acquire_share(thd, table_list, GTS_TABLE);
if (share == NULL) if (share == NULL)
DBUG_RETURN(0); // Can't open frm file DBUG_RETURN(0); // Can't open frm file
......
...@@ -2419,10 +2419,7 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx) ...@@ -2419,10 +2419,7 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
retry_share: retry_share:
share= tdc_acquire_share(thd, table_list->db, table_list->table_name, share= tdc_acquire_share(thd, table_list, gts_flags, &table);
key, key_length,
table_list->mdl_request.key.tc_hash_value(),
gts_flags, &table);
if (!share) if (!share)
{ {
...@@ -3291,8 +3288,7 @@ bool tdc_open_view(THD *thd, TABLE_LIST *table_list, const char *alias, ...@@ -3291,8 +3288,7 @@ bool tdc_open_view(THD *thd, TABLE_LIST *table_list, const char *alias,
TABLE_SHARE *share; TABLE_SHARE *share;
bool err= TRUE; bool err= TRUE;
if (!(share= tdc_acquire_share(thd, table_list->db, table_list->table_name, if (!(share= tdc_acquire_share(thd, table_list, GTS_VIEW)))
cache_key, cache_key_length, GTS_VIEW)))
return TRUE; return TRUE;
DBUG_ASSERT(share->is_view); DBUG_ASSERT(share->is_view);
...@@ -3379,7 +3375,7 @@ static bool auto_repair_table(THD *thd, TABLE_LIST *table_list) ...@@ -3379,7 +3375,7 @@ static bool auto_repair_table(THD *thd, TABLE_LIST *table_list)
if (!(entry= (TABLE*)my_malloc(sizeof(TABLE), MYF(MY_WME)))) if (!(entry= (TABLE*)my_malloc(sizeof(TABLE), MYF(MY_WME))))
return result; return result;
if (!(share= tdc_acquire_share_shortlived(thd, table_list, GTS_TABLE))) if (!(share= tdc_acquire_share(thd, table_list, GTS_TABLE)))
goto end_free; goto end_free;
DBUG_ASSERT(! share->is_view); DBUG_ASSERT(! share->is_view);
...@@ -3598,8 +3594,7 @@ Open_table_context::recover_from_failed_open() ...@@ -3598,8 +3594,7 @@ Open_table_context::recover_from_failed_open()
if (open_if_exists) if (open_if_exists)
m_thd->push_internal_handler(&no_such_table_handler); m_thd->push_internal_handler(&no_such_table_handler);
result= !tdc_acquire_share(m_thd, m_failed_table->db, result= !tdc_acquire_share(m_thd, m_failed_table,
m_failed_table->table_name,
GTS_TABLE | GTS_FORCE_DISCOVERY | GTS_NOLOCK); GTS_TABLE | GTS_FORCE_DISCOVERY | GTS_NOLOCK);
if (open_if_exists) if (open_if_exists)
{ {
......
...@@ -4489,7 +4489,7 @@ static int fill_schema_table_from_frm(THD *thd, TABLE_LIST *tables, ...@@ -4489,7 +4489,7 @@ static int fill_schema_table_from_frm(THD *thd, TABLE_LIST *tables,
goto end; goto end;
} }
share= tdc_acquire_share_shortlived(thd, &table_list, GTS_TABLE | GTS_VIEW); share= tdc_acquire_share(thd, &table_list, GTS_TABLE | GTS_VIEW);
if (!share) if (!share)
{ {
res= 0; res= 0;
......
...@@ -598,13 +598,14 @@ void tdc_unlock_share(TDC_element *element) ...@@ -598,13 +598,14 @@ void tdc_unlock_share(TDC_element *element)
# Share for table # Share for table
*/ */
TABLE_SHARE *tdc_acquire_share(THD *thd, const char *db, const char *table_name, TABLE_SHARE *tdc_acquire_share(THD *thd, TABLE_LIST *tl, uint flags,
const char *key, uint key_length,
my_hash_value_type hash_value, uint flags,
TABLE **out_table) TABLE **out_table)
{ {
TABLE_SHARE *share; TABLE_SHARE *share;
TDC_element *element; TDC_element *element;
const char *key;
uint key_length= get_table_def_key(tl, &key);
my_hash_value_type hash_value= tl->mdl_request.key.tc_hash_value();
bool was_unused; bool was_unused;
DBUG_ENTER("tdc_acquire_share"); DBUG_ENTER("tdc_acquire_share");
...@@ -628,7 +629,7 @@ TABLE_SHARE *tdc_acquire_share(THD *thd, const char *db, const char *table_name, ...@@ -628,7 +629,7 @@ TABLE_SHARE *tdc_acquire_share(THD *thd, const char *db, const char *table_name,
lf_hash_search_unpin(thd->tdc_hash_pins); lf_hash_search_unpin(thd->tdc_hash_pins);
DBUG_ASSERT(element); DBUG_ASSERT(element);
if (!(share= alloc_table_share(db, table_name, key, key_length))) if (!(share= alloc_table_share(tl->db, tl->table_name, key, key_length)))
{ {
lf_hash_delete(&tdc_hash, thd->tdc_hash_pins, key, key_length); lf_hash_delete(&tdc_hash, thd->tdc_hash_pins, key, key_length);
DBUG_RETURN(0); DBUG_RETURN(0);
......
...@@ -205,11 +205,8 @@ extern void tdc_purge(bool all); ...@@ -205,11 +205,8 @@ extern void tdc_purge(bool all);
extern TDC_element *tdc_lock_share(THD *thd, const char *db, extern TDC_element *tdc_lock_share(THD *thd, const char *db,
const char *table_name); const char *table_name);
extern void tdc_unlock_share(TDC_element *element); extern void tdc_unlock_share(TDC_element *element);
extern TABLE_SHARE *tdc_acquire_share(THD *thd, const char *db, extern TABLE_SHARE *tdc_acquire_share(THD *thd, TABLE_LIST *tl, uint flags,
const char *table_name, TABLE **out_table= 0);
const char *key, uint key_length,
my_hash_value_type hash_value,
uint flags, TABLE **out_table);
extern void tdc_release_share(TABLE_SHARE *share); extern void tdc_release_share(TABLE_SHARE *share);
extern bool tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type, extern bool tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,
const char *db, const char *table_name, const char *db, const char *table_name,
...@@ -248,50 +245,3 @@ inline uint tdc_create_key(char *key, const char *db, const char *table_name) ...@@ -248,50 +245,3 @@ inline uint tdc_create_key(char *key, const char *db, const char *table_name)
return (uint) (strmake(strmake(key, db, NAME_LEN) + 1, table_name, return (uint) (strmake(strmake(key, db, NAME_LEN) + 1, table_name,
NAME_LEN) - key + 1); NAME_LEN) - key + 1);
} }
/**
Convenience helper: call tdc_acquire_share() without out_table.
*/
static inline TABLE_SHARE *tdc_acquire_share(THD *thd, const char *db,
const char *table_name,
const char *key,
uint key_length, uint flags)
{
return tdc_acquire_share(thd, db, table_name, key, key_length,
my_hash_sort(&my_charset_bin, (uchar*) key,
key_length), flags, 0);
}
/**
Convenience helper: call tdc_acquire_share() without precomputed cache key.
*/
static inline TABLE_SHARE *tdc_acquire_share(THD *thd, const char *db,
const char *table_name, uint flags)
{
char key[MAX_DBKEY_LENGTH];
uint key_length;
key_length= tdc_create_key(key, db, table_name);
return tdc_acquire_share(thd, db, table_name, key, key_length, flags);
}
/**
Convenience helper: call tdc_acquire_share() reusing the MDL cache key.
@note lifetime of the returned TABLE_SHARE is limited by the
lifetime of the TABLE_LIST object!!!
*/
uint get_table_def_key(const TABLE_LIST *table_list, const char **key);
static inline TABLE_SHARE *tdc_acquire_share_shortlived(THD *thd, TABLE_LIST *tl,
uint flags)
{
const char *key;
uint key_length= get_table_def_key(tl, &key);
return tdc_acquire_share(thd, tl->db, tl->table_name, key, key_length,
tl->mdl_request.key.tc_hash_value(), flags, 0);
}
...@@ -1015,10 +1015,7 @@ TABLE_SHARE *mrn_get_table_share(TABLE_LIST *table_list, int *error) ...@@ -1015,10 +1015,7 @@ TABLE_SHARE *mrn_get_table_share(TABLE_LIST *table_list, int *error)
share = get_table_share(thd, table_list, key, key_length, 0, error, share = get_table_share(thd, table_list, key, key_length, 0, error,
hash_value); hash_value);
#elif defined(MRN_HAVE_TDC_ACQUIRE_SHARE) #elif defined(MRN_HAVE_TDC_ACQUIRE_SHARE)
share = tdc_acquire_share(thd, table_list->db, table_list->table_name, key, share = tdc_acquire_share(thd, table_list, GTS_TABLE);
key_length,
table_list->mdl_request.key.tc_hash_value(),
GTS_TABLE, NULL);
#else #else
share = get_table_share(thd, table_list, key, key_length, 0, error); share = get_table_share(thd, table_list, key, key_length, 0, error);
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment