List:Commits« Previous MessageNext Message »
From:Dmitry Lenev Date:June 10 2008 2:02pm
Subject:bzr commit into mysql-6.0 branch (dlenev:2666) WL#3726
View as plain text  
#At file:///home/dlenev/src/bzr/mysql-6.0-3726-w3/

 2666 Dmitry Lenev	2008-06-10
      WL#3726 "DDL locking for all metadata objects".
      
      After review fixes in progress.
modified:
  sql/mdl.cc
  sql/mdl.h
  sql/sql_base.cc
  sql/sql_show.cc

per-file comments:
  sql/mdl.cc
    Changed mdl_acquire_shared_lock() signature to accept MDL_CONTEXT
    as one of arguments as described in specification.
  sql/mdl.h
    Changed mdl_acquire_shared_lock() signature to accept MDL_CONTEXT
    as one of arguments as described in specification.
  sql/sql_base.cc
    Changed mdl_acquire_shared_lock() signature to accept MDL_CONTEXT
    as one of arguments as described in specification.
    Renamed handle_failed_open_table_attempt() to
    recover_from_failed_open_table_attempt() as suggested by review.
    Added comment clarifying why we need to check TABLE::db_stat
    while looking at TABLE instances open by other threads.
  sql/sql_show.cc
    Changed mdl_acquire_shared_lock() signature to accept MDL_CONTEXT
    as one of arguments as described in specification.
=== modified file 'sql/mdl.cc'
--- a/sql/mdl.cc	2008-06-06 10:28:58 +0000
+++ b/sql/mdl.cc	2008-06-10 14:01:56 +0000
@@ -611,6 +611,7 @@ static bool can_grant_lock(MDL_LOCK *loc
 
    This function must be called after the lock is added to a context.
 
+   @param context    [in]  Context containing request for lock
    @param lock_data  [in]  Lock request object for lock to be acquired
    @param retry      [out] Indicates that conflicting lock exists and another
                            attempt should be made after releasing all current
@@ -622,16 +623,19 @@ static bool can_grant_lock(MDL_LOCK *loc
                     In the latter case "retry" parameter is set to TRUE.
 */
 
-bool mdl_acquire_shared_lock(MDL_LOCK_DATA *lock_data, bool *retry)
+bool mdl_acquire_shared_lock(MDL_CONTEXT *context, MDL_LOCK_DATA *lock_data,
+                             bool *retry)
 {
   MDL_LOCK *lock;
   *retry= FALSE;
 
   DBUG_ASSERT(is_shared(lock_data) && lock_data->state == MDL_PENDING);
 
+  DBUG_ASSERT(lock_data->ctx == context);
+
   safe_mutex_assert_not_owner(&LOCK_open);
 
-  if (lock_data->ctx->has_global_shared_lock &&
+  if (context->has_global_shared_lock &&
       lock_data->type == MDL_SHARED_UPGRADABLE)
   {
     my_error(ER_CANT_UPDATE_WITH_READLOCK, MYF(0));

=== modified file 'sql/mdl.h'
--- a/sql/mdl.h	2008-06-06 10:28:58 +0000
+++ b/sql/mdl.h	2008-06-10 14:01:56 +0000
@@ -164,7 +164,8 @@ inline void mdl_set_lock_type(MDL_LOCK_D
   lock_data->type= lock_type;
 }
 
-bool mdl_acquire_shared_lock(MDL_LOCK_DATA *lock_data, bool *retry);
+bool mdl_acquire_shared_lock(MDL_CONTEXT *context, MDL_LOCK_DATA *lock_data,
+                             bool *retry);
 bool mdl_acquire_exclusive_locks(MDL_CONTEXT *context);
 bool mdl_upgrade_shared_lock_to_exclusive(MDL_CONTEXT *context,
                                           MDL_LOCK_DATA *lock_data);

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2008-06-08 18:13:58 +0000
+++ b/sql/sql_base.cc	2008-06-10 14:01:56 +0000
@@ -2792,7 +2792,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *
     if (flags & MYSQL_LOCK_IGNORE_FLUSH)
       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(&thd->mdl_context, mdl_lock_data, &retry))
     {
       if (retry)
         *action= OT_BACK_OFF_AND_RETRY;
@@ -3990,18 +3990,21 @@ end_with_lock_open:
 
 
 /**
-   Handle failed attempt ot open table by performing requested action.
+   Recover from failed attempt ot open table by performing requested action.
 
    @param  thd     Thread context
    @param  table   Table list element for table that caused problem
    @param  action  Type of action requested by failed open_table() call
 
+   @pre This function should be called only with "action" != OT_NO_ACTION.
+
    @retval FALSE - Success. One should try to open tables once again.
    @retval TRUE  - Error
 */
 
-static bool handle_failed_open_table_attempt(THD *thd, TABLE_LIST *table,
-                                             enum_open_table_action action)
+static bool
+recover_from_failed_open_table_attempt(THD *thd, TABLE_LIST *table,
+                                       enum_open_table_action action)
 {
   bool result= FALSE;
 
@@ -4635,7 +4638,7 @@ int open_tables(THD *thd, TABLE_LIST **s
           TABLE_LIST element. Altough currently this assumption is valid
           it may change in future.
         */
-        if (handle_failed_open_table_attempt(thd, tables, action))
+        if (recover_from_failed_open_table_attempt(thd, tables, action))
         {
           result= -1;
           goto err;
@@ -4910,7 +4913,7 @@ retry:
       might have been acquired successfully.
     */
     close_thread_tables(thd, (action == OT_BACK_OFF_AND_RETRY));
-    if (handle_failed_open_table_attempt(thd, table_list, action))
+    if (recover_from_failed_open_table_attempt(thd, table_list, action))
       break;
   }
 
@@ -8328,7 +8331,13 @@ bool notify_thread_having_shared_lock(TH
        thd_table ;
        thd_table= thd_table->next)
   {
-    /* TODO With new MDL check for db_stat is probably a legacy */
+    /*
+      Check for TABLE::db_stat is needed since in some places we call
+      handler::close() for table instance (and set TABLE::db_stat to 0)
+      and do not remove such instances from the THD::open_tables
+      for some time, during which other thread can see those instances
+      (e.g. see partitioning code).
+    */
     if (thd_table->db_stat)
       signalled|= mysql_lock_abort_for_thread(thd, thd_table);
   }

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2008-06-06 10:28:58 +0000
+++ b/sql/sql_show.cc	2008-06-10 14:01:56 +0000
@@ -3121,7 +3121,7 @@ static int fill_schema_table_from_frm(TH
   */
   while (1)
   {
-    if (mdl_acquire_shared_lock(&mdl_lock_data, &retry))
+    if (mdl_acquire_shared_lock(&thd->mdl_context, &mdl_lock_data, &retry))
     {
       if (!retry || mdl_wait_for_locks(&thd->mdl_context))
       {

Thread
bzr commit into mysql-6.0 branch (dlenev:2666) WL#3726Dmitry Lenev10 Jun