Commit 1fa7e75f authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: TABLE_SHARE::lock_share() helper

also: renames, s/const/constexpr/ for consistency
parent d51c0518
......@@ -9838,12 +9838,10 @@ int TABLE::hlindex_open(uint nr)
DBUG_ASSERT(nr == s->keys);
if (!hlindex)
{
if (s->tmp_table == NO_TMP_TABLE)
mysql_mutex_lock(&s->LOCK_share);
s->lock_share();
if (!s->hlindex)
{
if (s->tmp_table == NO_TMP_TABLE)
mysql_mutex_unlock(&s->LOCK_share);
s->unlock_share();
TABLE_SHARE *share;
char *path= NULL;
size_t path_len= s->normalized_path.length + HLINDEX_BUF_LEN;
......@@ -9867,26 +9865,20 @@ int TABLE::hlindex_open(uint nr)
return 1;
}
if (s->tmp_table == NO_TMP_TABLE)
mysql_mutex_lock(&s->LOCK_share);
s->lock_share();
if (!s->hlindex)
{
s->hlindex= share;
if (s->tmp_table == NO_TMP_TABLE)
mysql_mutex_unlock(&s->LOCK_share);
s->unlock_share();
}
else
{
if (s->tmp_table == NO_TMP_TABLE)
mysql_mutex_unlock(&s->LOCK_share);
s->unlock_share();
free_table_share(share);
}
}
else
{
if (s->tmp_table == NO_TMP_TABLE)
mysql_mutex_unlock(&s->LOCK_share);
}
s->unlock_share();
TABLE *table= (TABLE*)alloc_root(&mem_root, sizeof(*table));
if (!table || open_table_from_share(in_use, s->hlindex, &empty_clex_str,
db_stat, EXTRA_RECORD, in_use->open_options, table, 0))
......
......@@ -2082,13 +2082,14 @@ bool log_drop_table(THD *thd, const LEX_CSTRING *db_name,
}
static int get_hlindex_keys(THD *thd, const LEX_CSTRING *db,
const LEX_CSTRING *table_name, const char *path,
uint *keys, uint *total_keys)
static int get_hlindex_keys_by_open(THD *thd, const LEX_CSTRING *db,
const LEX_CSTRING *table_name,
const char *path, uint *keys,
uint *total_keys)
{
TABLE_SHARE share;
int error;
DBUG_ENTER("get_hlindex_keys");
DBUG_ENTER("get_hlindex_keys_by_open");
init_tmp_table_share(thd, &share, db->str, 0, table_name->str, path, 1);
error= open_table_def(thd, &share, GTS_TABLE | GTS_USE_DISCOVERY);
......@@ -2145,8 +2146,8 @@ bool quick_rm_table(THD *thd, handlerton *base, const LEX_CSTRING *db,
if (flags & QRMT_HANDLER)
{
uint keys, total_keys;
int hlindex_error= get_hlindex_keys(thd, db, table_name, path, &keys,
&total_keys);
int hlindex_error= get_hlindex_keys_by_open(thd, db, table_name, path,
&keys, &total_keys);
error|= ha_delete_table(thd, base, path, db, table_name, 0) > 0;
if (!hlindex_error)
{
......@@ -5423,7 +5424,8 @@ mysql_rename_table(handlerton *base, const LEX_CSTRING *old_db,
char *idx_to_end= strmov(idx_to, to_base);
uint keys, total_keys;
if (!get_hlindex_keys(thd, new_db, new_name, to, &keys, &total_keys))
if (!get_hlindex_keys_by_open(thd, new_db, new_name, to, &keys,
&total_keys))
{
for (uint i= keys; i < total_keys; i++)
{
......
......@@ -63,9 +63,9 @@ enum enum_explain_filename_mode
#define WFRM_BACKUP_ORIGINAL 16
/* Flags for conversion functions. */
static const uint FN_FROM_IS_TMP= 1 << 0;
static const uint FN_TO_IS_TMP= 1 << 1;
static const uint FN_IS_TMP= FN_FROM_IS_TMP | FN_TO_IS_TMP;
static constexpr uint FN_FROM_IS_TMP= 1 << 0;
static constexpr uint FN_TO_IS_TMP= 1 << 1;
static constexpr uint FN_IS_TMP= FN_FROM_IS_TMP | FN_TO_IS_TMP;
/* Remove .frm table metadata. */
static constexpr uint QRMT_FRM= 1 << 2;
/* Remove .par partitioning metadata. */
......@@ -75,9 +75,9 @@ static constexpr uint QRMT_HANDLER= 1 << 4;
/* Default behaviour is to drop .FRM and handler, but not .par. */
static constexpr uint QRMT_DEFAULT= QRMT_FRM | QRMT_HANDLER;
/** Don't resolve MySQL's fake "foo.sym" symbolic directory names. */
static const uint SKIP_SYMDIR_ACCESS= 1 << 5;
static constexpr uint SKIP_SYMDIR_ACCESS= 1 << 5;
/** Don't check foreign key constraints while renaming table */
static const uint NO_FK_CHECKS= 1 << 6;
static constexpr uint NO_FK_CHECKS= 1 << 6;
uint filename_to_tablename(const char *from, char *to, size_t to_length,
bool stay_quiet = false);
......
......@@ -8284,8 +8284,7 @@ void TABLE::mark_columns_used_by_virtual_fields(void)
if (s->check_set_initialized)
return;
if (s->tmp_table == NO_TMP_TABLE)
mysql_mutex_lock(&s->LOCK_share);
s->lock_share();
if (s->check_set)
{
/* Mark fields used by check constraint */
......@@ -8325,8 +8324,7 @@ void TABLE::mark_columns_used_by_virtual_fields(void)
bitmap_clear_all(&tmp_set);
}
s->check_set_initialized= v_keys;
if (s->tmp_table == NO_TMP_TABLE)
mysql_mutex_unlock(&s->LOCK_share);
s->unlock_share();
}
/* Add fields used by CHECK CONSTRAINT to read map */
......
......@@ -728,6 +728,9 @@ struct TABLE_SHARE
mysql_mutex_t LOCK_share; /* To protect TABLE_SHARE */
mysql_mutex_t LOCK_statistics; /* To protect against concurrent load */
void lock_share() { if (!tmp_table) mysql_mutex_lock(&LOCK_share); }
void unlock_share() { if (!tmp_table) mysql_mutex_unlock(&LOCK_share); }
TDC_element *tdc;
LEX_CUSTRING tabledef_version;
......
......@@ -392,13 +392,13 @@ class MHNSW_Context : public Sql_alloc
virtual void reset(TABLE_SHARE *share)
{
mysql_mutex_lock(&share->LOCK_share);
share->lock_share();
if (static_cast<MHNSW_Context*>(share->hlindex->hlindex_data) == this)
{
share->hlindex->hlindex_data= nullptr;
--refcnt;
}
mysql_mutex_unlock(&share->LOCK_share);
share->unlock_share();
}
void release(TABLE *table)
......@@ -603,8 +603,7 @@ MHNSW_Trx *MHNSW_Trx::get_from_thd(TABLE *table, bool for_update)
MHNSW_Context *MHNSW_Context::get_from_share(TABLE_SHARE *share, TABLE *table)
{
if (share->tmp_table == NO_TMP_TABLE)
mysql_mutex_lock(&share->LOCK_share);
share->lock_share();
auto ctx= static_cast<MHNSW_Context*>(share->hlindex->hlindex_data);
if (!ctx && table)
{
......@@ -615,8 +614,7 @@ MHNSW_Context *MHNSW_Context::get_from_share(TABLE_SHARE *share, TABLE *table)
}
if (ctx)
ctx->refcnt++;
if (share->tmp_table == NO_TMP_TABLE)
mysql_mutex_unlock(&share->LOCK_share);
share->unlock_share();
return ctx;
}
......
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