← Back to team overview

maria-developers team mailing list archive

Rev 2791: Preventing keycache flush to disk before DROP/TRUNCATE TABLE for myisam (for review) in file:///Users/bell/maria/bzr/work-mysql-keycache-5.0/

 

At file:///Users/bell/maria/bzr/work-mysql-keycache-5.0/

------------------------------------------------------------
revno: 2791
revision-id: sanja@xxxxxxxxxxxx-20090902145945-0rif23n1nth7naj7
parent: sanja@xxxxxxxxxxxx-20090828183603-gvbl4vmd8buph91m
committer: sanja@xxxxxxxxxxxx
branch nick: work-mysql-keycache-5.0
timestamp: Wed 2009-09-02 17:59:45 +0300
message:
  Preventing keycache flush to disk before DROP/TRUNCATE TABLE for myisam (for review)
=== modified file 'include/my_base.h'
--- a/include/my_base.h	2009-07-17 08:43:53 +0000
+++ b/include/my_base.h	2009-09-02 14:59:45 +0000
@@ -173,7 +173,9 @@
     Inform handler that an "INSERT...ON DUPLICATE KEY UPDATE" will be
     executed. This condition is unset by HA_EXTRA_NO_IGNORE_DUP_KEY.
   */
-  HA_EXTRA_INSERT_WITH_UPDATE
+  HA_EXTRA_INSERT_WITH_UPDATE,
+  /* We are going to drop the table */
+  HA_EXTRA_PREPARE_FOR_DROP
 };
 
 	/* The following is parameter to ha_panic() */

=== modified file 'myisam/mi_close.c'
--- a/myisam/mi_close.c	2009-03-20 09:18:14 +0000
+++ b/myisam/mi_close.c	2009-09-02 14:59:45 +0000
@@ -63,8 +63,9 @@
   {
     if (share->kfile >= 0 &&
 	flush_key_blocks(share->key_cache, share->kfile,
-			 share->temporary ? FLUSH_IGNORE_CHANGED :
-			 FLUSH_RELEASE))
+			 (share->temporary || share->deleting) ?
+                         FLUSH_IGNORE_CHANGED :
+                         FLUSH_RELEASE))
       error=my_errno;
     if (share->kfile >= 0)
     {

=== modified file 'myisam/mi_extra.c'
--- a/myisam/mi_extra.c	2007-07-27 09:30:25 +0000
+++ b/myisam/mi_extra.c	2009-09-02 14:59:45 +0000
@@ -276,9 +276,9 @@
     pthread_mutex_unlock(&THR_LOCK_myisam);
     break;
   case HA_EXTRA_PREPARE_FOR_DELETE:
+    DBUG_PRINT("info", ("HA_EXTRA_PREPARE_FOR_DELETE"));
     pthread_mutex_lock(&THR_LOCK_myisam);
     share->last_version= 0L;			/* Impossible version */
-#ifdef __WIN__REMOVE_OBSOLETE_WORKAROUND
     /* Close the isam and data files as Win32 can't drop an open table */
     pthread_mutex_lock(&share->intern_lock);
     if (flush_key_blocks(share->key_cache, share->kfile,
@@ -295,6 +295,8 @@
       info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
       error=end_io_cache(&info->rec_cache);
     }
+    pthread_mutex_unlock(&share->intern_lock);
+#ifdef __WIN__REMOVE_OBSOLETE_WORKAROUND
     if (info->lock_type != F_UNLCK && ! info->was_locked)
     {
       info->was_locked=info->lock_type;
@@ -322,7 +324,6 @@
       }
     }
     share->kfile= -1;				/* Files aren't open anymore */
-    pthread_mutex_unlock(&share->intern_lock);
 #endif
     pthread_mutex_unlock(&THR_LOCK_myisam);
     break;
@@ -366,6 +367,11 @@
   case HA_EXTRA_CHANGE_KEY_TO_DUP:
     mi_extra_keyflag(info, function);
     break;
+  case HA_EXTRA_PREPARE_FOR_DROP:
+    /* Signals about intent to delete this table */
+    share->deleting= TRUE;
+    _mi_mark_file_changed(info);
+    break;
   case HA_EXTRA_KEY_CACHE:
   case HA_EXTRA_NO_KEY_CACHE:
   default:

=== modified file 'myisam/mi_locking.c'
--- a/myisam/mi_locking.c	2007-01-03 07:52:50 +0000
+++ b/myisam/mi_locking.c	2009-09-02 14:59:45 +0000
@@ -547,7 +547,7 @@
   {
     uint old_lock=info->lock_type;
     share->global_changed=0;
-    lock_error=mi_lock_database(info,F_WRLCK);
+    lock_error= my_disable_locking ? 0 : mi_lock_database(info,F_WRLCK);
     /* Its not fatal even if we couldn't get the lock ! */
     if (share->state.open_count > 0)
     {
@@ -557,7 +557,7 @@
 			    sizeof(share->state.header),
 			    MYF(MY_NABP));
     }
-    if (!lock_error)
+    if (!lock_error && !my_disable_locking)
       lock_error=mi_lock_database(info,old_lock);
   }
   return test(lock_error || write_error);

=== modified file 'myisam/myisamdef.h'
--- a/myisam/myisamdef.h	2009-01-15 10:48:31 +0000
+++ b/myisam/myisamdef.h	2009-09-02 14:59:45 +0000
@@ -203,6 +203,7 @@
     not_flushed,
     temporary,delay_key_write,
     concurrent_insert;
+  my_bool deleting;                     /* we are going to delete this table */
 #ifdef THREAD
   THR_LOCK lock;
   pthread_mutex_t intern_lock;		/* Locking for use with _locking */

=== modified file 'sql/lock.cc'
--- a/sql/lock.cc	2009-04-14 17:20:13 +0000
+++ b/sql/lock.cc	2009-09-02 14:59:45 +0000
@@ -907,10 +907,12 @@
     DBUG_RETURN(-1);
 
   table_list->table= table;
+  table->s->deleting= table_list->deleting;
 
   /* Return 1 if table is in use */
   DBUG_RETURN(test(remove_table_from_cache(thd, db, table_list->table_name,
-                                           RTFC_NO_FLAG)));
+                                           RTFC_NO_FLAG,
+                                           table_list->deleting)));
 }
 
 

=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h	2009-05-27 10:20:57 +0000
+++ b/sql/mysql_priv.h	2009-09-02 14:59:45 +0000
@@ -1187,7 +1187,7 @@
 #define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
 #define RTFC_CHECK_KILLED_FLAG      0x0004
 bool remove_table_from_cache(THD *thd, const char *db, const char *table,
-                             uint flags);
+                             uint flags, my_bool deleting);
 
 bool close_cached_tables(THD *thd, bool wait_for_refresh, TABLE_LIST *tables);
 void copy_field_from_tmp_record(Field *field,int offset);

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2009-07-16 12:19:22 +0000
+++ b/sql/sql_base.cc	2009-09-02 14:59:45 +0000
@@ -342,7 +342,7 @@
     for (TABLE_LIST *table= tables; table; table= table->next_local)
     {
       if (remove_table_from_cache(thd, table->db, table->table_name,
-                                  RTFC_OWNED_BY_THD_FLAG))
+                                  RTFC_OWNED_BY_THD_FLAG, table->deleting))
 	found=1;
     }
     if (!found)
@@ -6099,7 +6099,7 @@
 */
 
 bool remove_table_from_cache(THD *thd, const char *db, const char *table_name,
-                             uint flags)
+                             uint flags, my_bool deleting)
 {
   char key[MAX_DBKEY_LENGTH];
   uint key_length;
@@ -6166,7 +6166,10 @@
         result= result || (flags & RTFC_OWNED_BY_THD_FLAG);
     }
     while (unused_tables && !unused_tables->s->version)
+    {
+      unused_tables->s->deleting= deleting;
       VOID(hash_delete(&open_cache,(byte*) unused_tables));
+    }
     if (result && (flags & RTFC_WAIT_OTHER_THREAD_FLAG))
     {
       /*

=== modified file 'sql/sql_delete.cc'
--- a/sql/sql_delete.cc	2009-07-13 15:11:16 +0000
+++ b/sql/sql_delete.cc	2009-09-02 14:59:45 +0000
@@ -920,6 +920,7 @@
   HA_CREATE_INFO create_info;
   char path[FN_REFLEN];
   TABLE **table_ptr;
+  TABLE_LIST *table;
   bool error;
   DBUG_ENTER("mysql_truncate");
 
@@ -967,6 +968,10 @@
     }
     if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE))
       goto trunc_by_del;
+
+    for (table= table_list; table; table= table->next_local)
+      table->deleting= TRUE; /* to trigger HA_PREPARE_FOR_DROP */
+
     if (lock_and_wait_for_table_name(thd, table_list))
       DBUG_RETURN(TRUE);
   }

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2009-06-29 13:17:01 +0000
+++ b/sql/sql_table.cc	2009-09-02 14:59:45 +0000
@@ -228,6 +228,9 @@
 
   LINT_INIT(alias);
 
+  for (table= tables; table; table= table->next_local)
+    table->deleting= TRUE;
+
   if (!drop_temporary && lock_table_names(thd, tables))
     DBUG_RETURN(1);
 
@@ -252,7 +255,7 @@
       abort_locked_tables(thd, db, table->table_name);
       remove_table_from_cache(thd, db, table->table_name,
 	                      RTFC_WAIT_OTHER_THREAD_FLAG |
-			      RTFC_CHECK_KILLED_FLAG);
+			      RTFC_CHECK_KILLED_FLAG, FALSE);
       drop_locked_tables(thd, db, table->table_name);
       if (thd->killed)
       {
@@ -1966,7 +1969,8 @@
 
   /* Wait until all there are no other threads that has this table open */
   remove_table_from_cache(thd, table->s->db,
-                          table->s->table_name, RTFC_WAIT_OTHER_THREAD_FLAG);
+                          table->s->table_name,
+                          RTFC_WAIT_OTHER_THREAD_FLAG, FALSE);
   DBUG_VOID_RETURN;
 }
 
@@ -2365,7 +2369,7 @@
       remove_table_from_cache(thd, table->table->s->db,
                               table->table->s->table_name,
                               RTFC_WAIT_OTHER_THREAD_FLAG |
-                              RTFC_CHECK_KILLED_FLAG);
+                              RTFC_CHECK_KILLED_FLAG, FALSE);
       thd->exit_cond(old_message);
       if (thd->killed)
 	goto err;
@@ -2586,7 +2590,8 @@
         {
           pthread_mutex_lock(&LOCK_open);
           remove_table_from_cache(thd, table->table->s->db,
-                                  table->table->s->table_name, RTFC_NO_FLAG);
+                                  table->table->s->table_name, RTFC_NO_FLAG,
+                                  FALSE);
           pthread_mutex_unlock(&LOCK_open);
         }
         /* May be something modified consequently we have to invalidate cache */
@@ -3996,7 +4001,7 @@
     {
       VOID(table->file->extra(HA_EXTRA_FORCE_REOPEN)); // Use new file
       /* Mark in-use copies old */
-      remove_table_from_cache(thd,db,table_name,RTFC_NO_FLAG);
+      remove_table_from_cache(thd, db, table_name, RTFC_NO_FLAG, FALSE);
       /* end threads waiting on lock */
       mysql_lock_abort(thd,table);
     }

=== modified file 'sql/table.cc'
--- a/sql/table.cc	2009-06-17 13:54:01 +0000
+++ b/sql/table.cc	2009-09-02 14:59:45 +0000
@@ -993,7 +993,12 @@
   int error=0;
   DBUG_ENTER("closefrm");
   if (table->db_stat)
-    error=table->file->close();
+  {
+    if (table->s->deleting)
+      table->file->extra(HA_EXTRA_PREPARE_FOR_DROP);
+    error= table->file->close();
+  }
+
   my_free((char*) table->alias, MYF(MY_ALLOW_ZERO_PTR));
   table->alias= 0;
   if (table->field)

=== modified file 'sql/table.h'
--- a/sql/table.h	2009-06-17 13:54:01 +0000
+++ b/sql/table.h	2009-09-02 14:59:45 +0000
@@ -202,6 +202,7 @@
     locking of this table for writing. FALSE - otherwise.
   */
   my_bool system_table;
+  bool deleting;                        /* going to delete this table */
 } TABLE_SHARE;
 
 
@@ -713,6 +714,7 @@
     ... SELECT implementation).
   */
   bool          create;
+  bool          deleting; /* going to delete this table */
 
   /**
     Indicates what triggers we need to pre-load for this TABLE_LIST