Commit 4c628c04 authored by Konstantin Osipov's avatar Konstantin Osipov

Backport of:

------------------------------------------------------------
revno: 2630.4.24
committer: Dmitry Lenev <dlenev@mysql.com>
branch nick: mysql-6.0-3726-w2
timestamp: Fri 2008-06-06 14:28:58 +0400
message:
  WL#3726 "DDL locking for all metadata objects".

  After review fixes in progress.

  Get rid of upgradability and priority attributes of
  metadata lock requests by replacing them with two
  new types of lock requests MDL_SHARED_UPGRADABLE and
  MDL_SHARED_HIGH_PRIO correspondingly.
parent 8227a34e
This diff is collapsed.
...@@ -26,24 +26,25 @@ struct MDL_LOCK_DATA; ...@@ -26,24 +26,25 @@ struct MDL_LOCK_DATA;
struct MDL_LOCK; struct MDL_LOCK;
struct MDL_CONTEXT; struct MDL_CONTEXT;
/** Type of metadata lock request. */ /**
Type of metadata lock request.
enum enum_mdl_type {MDL_SHARED=0, MDL_EXCLUSIVE};
- High-priority shared locks differ from ordinary shared locks by
that they ignore pending requests for exclusive locks.
- Upgradable shared locks can be later upgraded to exclusive
(because of that their acquisition involves implicit
acquisition of global intention-exclusive lock).
/** States which metadata lock request can have. */ @see Comments for can_grant_lock() and can_grant_global_lock() for details.
*/
enum enum_mdl_state {MDL_PENDING=0, MDL_ACQUIRED, MDL_PENDING_UPGRADE}; enum enum_mdl_type {MDL_SHARED=0, MDL_SHARED_HIGH_PRIO,
MDL_SHARED_UPGRADABLE, MDL_EXCLUSIVE};
/** /** States which metadata lock request can have. */
Priority of metadata lock requests. High priority attribute is
applicable only to requests for shared locks and indicates that
such request should ignore pending requests for exclusive locks
and for upgrading of shared locks to exclusive.
*/
enum enum_mdl_prio {MDL_NORMAL_PRIO=0, MDL_HIGH_PRIO}; enum enum_mdl_state {MDL_PENDING=0, MDL_ACQUIRED, MDL_PENDING_UPGRADE};
/** /**
...@@ -60,13 +61,6 @@ struct MDL_LOCK_DATA ...@@ -60,13 +61,6 @@ struct MDL_LOCK_DATA
uint key_length; uint key_length;
enum enum_mdl_type type; enum enum_mdl_type type;
enum enum_mdl_state state; enum enum_mdl_state state;
enum enum_mdl_prio prio;
/**
TRUE -- if shared lock corresponding to this lock request at some
point might be upgraded to an exclusive lock and therefore conflicts
with global shared lock, FALSE -- otherwise.
*/
bool is_upgradable;
private: private:
/** /**
...@@ -170,28 +164,6 @@ inline void mdl_set_lock_type(MDL_LOCK_DATA *lock_data, enum_mdl_type lock_type) ...@@ -170,28 +164,6 @@ inline void mdl_set_lock_type(MDL_LOCK_DATA *lock_data, enum_mdl_type lock_type)
lock_data->type= lock_type; lock_data->type= lock_type;
} }
/**
Set priority for lock request. High priority can be only set
for shared locks.
*/
inline void mdl_set_lock_priority(MDL_LOCK_DATA *lock_data, enum_mdl_prio prio)
{
DBUG_ASSERT(lock_data->type == MDL_SHARED && lock_data->state == MDL_PENDING);
lock_data->prio= prio;
}
/**
Mark request for shared lock as upgradable. Can be only applied
to pending locks.
*/
inline void mdl_set_upgradable(MDL_LOCK_DATA *lock_data)
{
DBUG_ASSERT(lock_data->type == MDL_SHARED && lock_data->state == MDL_PENDING);
lock_data->is_upgradable= TRUE;
}
bool mdl_acquire_shared_lock(MDL_LOCK_DATA *lock_data, bool *retry); bool mdl_acquire_shared_lock(MDL_LOCK_DATA *lock_data, bool *retry);
bool mdl_acquire_exclusive_locks(MDL_CONTEXT *context); bool mdl_acquire_exclusive_locks(MDL_CONTEXT *context);
bool mdl_upgrade_shared_lock_to_exclusive(MDL_CONTEXT *context, bool mdl_upgrade_shared_lock_to_exclusive(MDL_CONTEXT *context,
......
...@@ -2822,11 +2822,19 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, ...@@ -2822,11 +2822,19 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
{ {
bool retry; bool retry;
/*
There is no MDL_SHARED_UPGRADABLE_HIGH_PRIO type of metadata lock so we
want to be sure that caller doesn't pass us both flags simultaneously.
*/
DBUG_ASSERT(!(flags & MYSQL_OPEN_TAKE_UPGRADABLE_MDL) ||
!(flags & MYSQL_LOCK_IGNORE_FLUSH));
if (flags & MYSQL_OPEN_TAKE_UPGRADABLE_MDL && if (flags & MYSQL_OPEN_TAKE_UPGRADABLE_MDL &&
table_list->lock_type >= TL_WRITE_ALLOW_WRITE) table_list->lock_type >= TL_WRITE_ALLOW_WRITE)
mdl_set_upgradable(mdl_lock_data); mdl_set_lock_type(mdl_lock_data, MDL_SHARED_UPGRADABLE);
mdl_set_lock_priority(mdl_lock_data, (flags & MYSQL_LOCK_IGNORE_FLUSH) ? if (flags & MYSQL_LOCK_IGNORE_FLUSH)
MDL_HIGH_PRIO : MDL_NORMAL_PRIO); mdl_set_lock_type(mdl_lock_data, MDL_SHARED_HIGH_PRIO);
if (mdl_acquire_shared_lock(mdl_lock_data, &retry)) if (mdl_acquire_shared_lock(mdl_lock_data, &retry))
{ {
if (retry) if (retry)
......
...@@ -3136,7 +3136,7 @@ static int fill_schema_table_from_frm(THD *thd,TABLE *table, ...@@ -3136,7 +3136,7 @@ static int fill_schema_table_from_frm(THD *thd,TABLE *table,
mdl_init_lock(&mdl_lock_data, mdlkey, 0, db_name->str, table_name->str); mdl_init_lock(&mdl_lock_data, mdlkey, 0, db_name->str, table_name->str);
table_list.mdl_lock_data= &mdl_lock_data; table_list.mdl_lock_data= &mdl_lock_data;
mdl_add_lock(&thd->mdl_context, &mdl_lock_data); mdl_add_lock(&thd->mdl_context, &mdl_lock_data);
mdl_set_lock_priority(&mdl_lock_data, MDL_HIGH_PRIO); mdl_set_lock_type(&mdl_lock_data, MDL_SHARED_HIGH_PRIO);
/* /*
TODO: investigate if in this particular situation we can get by TODO: investigate if in this particular situation we can get by
......
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