MDL_lock encapsulation: MDL_lock::get_key()

Avoid accessing MDL_lock::key from outside of MDL_lock class directly,
use MDL_lock::get_key() instead.

This is part of broader cleanup, which aims to make large part of
MDL_lock members private. It is needed to simplify further work on
MDEV-19749 - MDL scalability regression after backup locks.
This commit is contained in:
Sergey Vojtovich 2025-05-04 01:59:52 +04:00
parent 36bec5697b
commit 02eb8f7246
5 changed files with 28 additions and 28 deletions

View File

@ -75,7 +75,7 @@ int i_s_metadata_lock_info_fill_row(
TABLE *table = param->table;
DBUG_ENTER("i_s_metadata_lock_info_fill_row");
MDL_context *mdl_ctx = mdl_ticket->get_ctx();
MDL_key *mdl_key = mdl_ticket->get_key();
const MDL_key *mdl_key = mdl_ticket->get_key();
MDL_key::enum_mdl_namespace mdl_namespace = mdl_key->mdl_namespace();
if (!granted)
DBUG_RETURN(0);

View File

@ -4165,7 +4165,7 @@ public:
const uchar *ull_get_key(const void *ptr, size_t *length, my_bool)
{
User_level_lock *ull = (User_level_lock*) ptr;
MDL_key *key = ull->lock->get_key();
const MDL_key *key = ull->lock->get_key();
*length= key->length();
return key->ptr();
}

View File

@ -257,7 +257,7 @@ private:
const char *dbug_print_mdl(MDL_ticket *mdl_ticket)
{
thread_local char buffer[256];
MDL_key *mdl_key= mdl_ticket->get_key();
const MDL_key *mdl_key= mdl_ticket->get_key();
my_snprintf(buffer, sizeof(buffer) - 1, "%.*s/%.*s (%s)",
(int) mdl_key->db_name_length(), mdl_key->db_name(),
(int) mdl_key->name_length(), mdl_key->name(),
@ -688,6 +688,14 @@ public:
lock->m_strategy= &m_object_lock_strategy;
}
static const uchar *mdl_locks_key(const void *record, size_t *length,
my_bool)
{
const MDL_lock *lock= static_cast<const MDL_lock *>(record);
*length= lock->key.length();
return lock->key.ptr();
}
/**
Return thread id of the thread to which the first ticket was
@ -884,6 +892,9 @@ end:
{ remove_ticket(pins, &MDL_lock::m_waiting, ticket); }
const MDL_key *get_key() const { return &key; }
const MDL_lock_strategy *m_strategy;
private:
static const MDL_backup_lock m_backup_lock_strategy;
@ -900,18 +911,6 @@ const MDL_lock::MDL_object_lock MDL_lock::m_object_lock_strategy;
static MDL_map mdl_locks;
extern "C"
{
static const uchar *mdl_locks_key(const void *record, size_t *length,
my_bool)
{
const MDL_lock *lock= static_cast<const MDL_lock *>(record);
*length= lock->key.length();
return lock->key.ptr();
}
} /* extern "C" */
/**
Initialize the metadata locking subsystem.
@ -1002,7 +1001,7 @@ void MDL_map::init()
m_backup_lock= new (std::nothrow) MDL_lock(&backup_lock_key);
lf_hash_init(&m_locks, sizeof(MDL_lock), LF_HASH_UNIQUE, 0, 0,
mdl_locks_key, &my_charset_bin);
MDL_lock::mdl_locks_key, &my_charset_bin);
m_locks.alloc.constructor= MDL_lock::lf_alloc_constructor;
m_locks.alloc.destructor= MDL_lock::lf_alloc_destructor;
m_locks.initializer= MDL_lock::lf_hash_initializer;
@ -1230,7 +1229,7 @@ MDL_ticket::~MDL_ticket()
uint MDL_ticket::get_deadlock_weight() const
{
if (m_lock->key.mdl_namespace() == MDL_key::BACKUP)
if (get_key()->mdl_namespace() == MDL_key::BACKUP)
{
if (m_type == MDL_BACKUP_FTWRL1)
return DEADLOCK_WEIGHT_FTWRL1;
@ -2106,7 +2105,7 @@ MDL_context::find_ticket(MDL_request *mdl_request,
while ((ticket= it++))
{
if (mdl_request->key.is_equal(&ticket->m_lock->key) &&
if (mdl_request->key.is_equal(ticket->get_key()) &&
ticket->has_stronger_or_equal_type(mdl_request->type))
{
DBUG_PRINT("info", ("Adding mdl lock %s to %s",
@ -2690,7 +2689,7 @@ MDL_context::upgrade_shared_lock(MDL_ticket *mdl_ticket,
mdl_ticket->get_key()->mdl_namespace() != MDL_key::BACKUP)
DBUG_RETURN(FALSE);
MDL_REQUEST_INIT_BY_KEY(&mdl_xlock_request, &mdl_ticket->m_lock->key,
MDL_REQUEST_INIT_BY_KEY(&mdl_xlock_request, mdl_ticket->get_key(),
new_type, MDL_TRANSACTION);
if (acquire_lock(&mdl_xlock_request, lock_wait_timeout))
@ -2966,7 +2965,8 @@ void MDL_context::release_lock(enum_mdl_duration duration, MDL_ticket *ticket)
MDL_lock *lock= ticket->m_lock;
DBUG_ENTER("MDL_context::release_lock");
DBUG_PRINT("enter", ("db: '%s' name: '%s'",
lock->key.db_name(), lock->key.name()));
ticket->get_key()->db_name(),
ticket->get_key()->name()));
DBUG_ASSERT(this == ticket->get_ctx());
DBUG_PRINT("mdl", ("Released: %s", dbug_print_mdl(ticket)));
@ -3156,9 +3156,9 @@ bool MDL_ticket::has_pending_conflicting_lock() const
}
/** Return a key identifying this lock. */
MDL_key *MDL_ticket::get_key() const
const MDL_key *MDL_ticket::get_key() const
{
return &m_lock->key;
return m_lock->get_key();
}
/**
@ -3389,12 +3389,12 @@ void MDL_ticket::wsrep_report(bool debug) const
{
if (!debug) return;
const PSI_stage_info *psi_stage= m_lock->key.get_wait_state_name();
const PSI_stage_info *psi_stage= get_key()->get_wait_state_name();
WSREP_DEBUG("MDL ticket: type: %s space: %s db: %s name: %s (%s)",
get_type_name()->str,
wsrep_get_mdl_namespace_name(m_lock->key.mdl_namespace()),
m_lock->key.db_name(),
m_lock->key.name(),
wsrep_get_mdl_namespace_name(get_key()->mdl_namespace()),
get_key()->db_name(),
get_key()->name(),
psi_stage->m_name);
}
#endif /* WITH_WSREP */

View File

@ -730,7 +730,7 @@ public:
const LEX_STRING *get_type_name() const;
const LEX_STRING *get_type_name(enum_mdl_type type) const;
MDL_lock *get_lock() const { return m_lock; }
MDL_key *get_key() const;
const MDL_key *get_key() const;
void downgrade_lock(enum_mdl_type type);
bool has_stronger_or_equal_type(enum_mdl_type type) const;

View File

@ -670,7 +670,7 @@ int MHNSW_Trx::do_commit(THD *thd, bool)
trx_next= trx->next;
if (trx->table_id)
{
MDL_key *key= trx->table_id->get_key();
const MDL_key *key= trx->table_id->get_key();
LEX_CSTRING db= {key->db_name(), key->db_name_length()},
tbl= {key->name(), key->name_length()};
TABLE_LIST tl;