Skip to content

Commit

Permalink
MDEV-32050: Allow table to be guarded by an MDL of another thread
Browse files Browse the repository at this point in the history
Add a debug-only field MDL_context::lock_warrant. This field can be set
to the MDL context different from the one the current execution is done in.

The lock warrantor has to hold an MDL for at least a duration of a table
lifetime.

This is needed in the subsequent commit so that the shared MDL acquired by
the InnoDB purge_coordinator_task can be shared by purge_worker_task
that access index records that include virtual columns.

Reviewed by: Vladislav Vaintroub
  • Loading branch information
FooBarrior authored and dr-m committed Oct 25, 2023
1 parent d70a98a commit 39bb5eb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
20 changes: 20 additions & 0 deletions sql/mdl.h
Expand Up @@ -1100,6 +1100,26 @@ class MDL_context

/* metadata_lock_info plugin */
friend int i_s_metadata_lock_info_fill_row(MDL_ticket*, void*);
#ifndef DBUG_OFF
public:
/**
This is for the case when the thread opening the table does not acquire
the lock itself, but utilizes a lock guarantee from another MDL context.
For example, in InnoDB, MDL is acquired by the purge_coordinator_task,
but the table may be opened and used in a purge_worker_task.
The coordinator thread holds the lock for the duration of worker's purge
job, or longer, possibly reusing shared MDL for different workers and jobs.
*/
MDL_context *lock_warrant= NULL;

inline bool is_lock_warrantee(MDL_key::enum_mdl_namespace ns,
const char *db, const char *name,
enum_mdl_type mdl_type) const
{
return lock_warrant && lock_warrant->is_lock_owner(ns, db, name, mdl_type);
}
#endif
};


Expand Down
6 changes: 5 additions & 1 deletion sql/sql_base.cc
Expand Up @@ -978,7 +978,11 @@ void close_thread_table(THD *thd, TABLE **table_ptr)
DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE,
table->s->db.str,
table->s->table_name.str,
MDL_SHARED));
MDL_SHARED) ||
thd->mdl_context.is_lock_warrantee(MDL_key::TABLE,
table->s->db.str,
table->s->table_name.str,
MDL_SHARED));
table->vcol_cleanup_expr(thd);
table->mdl_ticket= NULL;

Expand Down

0 comments on commit 39bb5eb

Please sign in to comment.