Commit 39bb5ebb authored by Nikita Malyavin's avatar Nikita Malyavin Committed by Marko Mäkelä

MDEV-32050: Allow table to be guarded by an MDL of another thread

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
parent d70a98ae
......@@ -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
};
......
......@@ -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;
......
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