List:Commits« Previous MessageNext Message »
From:rsomla Date:November 30 2007 7:45pm
Subject:bk commit into 6.0 tree (rafal:1.2712) WL#4060
View as plain text  
Below is the list of changes that have just been committed into a local
6.0 repository of rafal. When rafal does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-11-30 20:44:54+01:00, rafal@quant.(none) +3 -0
  WL#4060 (backup kernel updates)
  
  This patch adds checks to the backup kernel so that it will not execute two BACKUP/RESTORE commands at the
  same time. If second such command is issued an error is reported.

  sql/backup/kernel.cc@stripped, 2007-11-30 20:44:49+01:00, rafal@quant.(none) +66 -0
    Add start_backup_or_restore() and finish_backup_or_restore() and wrap execution 
    of BACKUP/RESTORE commands into them.

  sql/mysqld.cc@stripped, 2007-11-30 20:44:49+01:00, rafal@quant.(none) +3 -0
    Adding global LOCK_backup mutex.

  sql/share/errmsg.txt@stripped, 2007-11-30 20:44:49+01:00, rafal@quant.(none) +2 -0
    New error message.

diff -Nrup a/sql/backup/kernel.cc b/sql/backup/kernel.cc
--- a/sql/backup/kernel.cc	2007-11-30 19:20:34 +01:00
+++ b/sql/backup/kernel.cc	2007-11-30 20:44:49 +01:00
@@ -36,6 +36,9 @@ namespace backup {
 static IStream* open_for_read(const Location&);
 static OStream* open_for_write(const Location&);
 
+static int start_backup_or_restore();
+static void finish_backup_or_restore();
+
 /*
   Report errors. The main error code and optional arguments for its description
   are given plus a logger object which can contain stored errors.
@@ -93,7 +96,10 @@ execute_backup_command(THD *thd, LEX *le
     Check access for SUPER rights. If user does not have SUPER, fail with error.
   */
   if (check_global_access(thd, SUPER_ACL))
+  {
+    my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR,MYF(0));
     DBUG_RETURN(ER_SPECIFIC_ACCESS_DENIED_ERROR);
+  }
 
   Location *loc= Location::find(lex->backup_dir);
 
@@ -103,9 +109,28 @@ execute_backup_command(THD *thd, LEX *le
     DBUG_RETURN(ER_BACKUP_INVALID_LOC);
   }
 
+  /*
+    Start_backup_or_restore() will check if another BACKUP/RESTORE command is 
+    running now and inform us about that. If this is the case we report error.
+   */ 
+  if ((lex->sql_command == SQLCOM_RESTORE) 
+      || (lex->sql_command == SQLCOM_BACKUP))
+    if(start_backup_or_restore())
+    {
+      my_error(ER_BACKUP_RUNNING,MYF(0));
+      DBUG_RETURN(ER_BACKUP_RUNNING);
+    }
+
   prepare_stream_memory();
   int res= 0;
 
+  /*
+    Important: above start_backup_or_restore() and prepare_stream_memory() 
+    *must* be matched by finish_backup_or_restore() and free_stream_memory(),
+    respectively. Therefore be careful with early return with DBUG_RETURN() - 
+    use "goto backup/restore_error" instead.
+   */ 
+
   switch (lex->sql_command) {
 
   case SQLCOM_SHOW_ARCHIVE:
@@ -354,6 +379,7 @@ execute_backup_command(THD *thd, LEX *le
 
   loc->free();
   free_stream_memory();
+  finish_backup_or_restore();
 
   DBUG_RETURN(res);
 }
@@ -1876,6 +1902,46 @@ int silent_exec_query(THD *thd, ::String
   }
 
   return 0;
+}
+
+} // backup namespace
+
+extern pthread_mutex_t LOCK_backup;
+
+namespace backup {
+  
+static bool backup_or_restore_is_running= FALSE;
+
+/**
+  Indicate that BACKUP/RESTORE operation has started.
+  
+  @returns 0 if it is OK to continue or non-zero if another BACKUP/RESTORE
+  command is running and it is not possible to execute enather one now.
+ */ 
+int start_backup_or_restore()
+{
+  bool running;
+  
+  pthread_mutex_lock(&::LOCK_backup);
+  running= backup_or_restore_is_running;
+  if (!running)
+    backup_or_restore_is_running= TRUE;
+  pthread_mutex_unlock(&::LOCK_backup);
+
+  return running;
+}
+
+/**
+  Indicate that BACKUP/RESTORE operation has finished.
+  
+  This function should be called only if an earlier call to 
+  start_backup_or_restore() was successful.
+ */ 
+void finish_backup_or_restore()
+{
+  pthread_mutex_lock(&::LOCK_backup);
+  backup_or_restore_is_running= FALSE;
+  pthread_mutex_unlock(&::LOCK_backup);
 }
 
 } // backup namespace
diff -Nrup a/sql/mysqld.cc b/sql/mysqld.cc
--- a/sql/mysqld.cc	2007-11-30 02:37:40 +01:00
+++ b/sql/mysqld.cc	2007-11-30 20:44:49 +01:00
@@ -588,6 +588,7 @@ pthread_mutex_t THR_LOCK_DDL_blocker; 
 pthread_mutex_t THR_LOCK_DDL_is_blocked; 
 pthread_cond_t COND_DDL_blocker;
 pthread_cond_t COND_process_blocked;
+pthread_mutex_t LOCK_backup;
 
 /*
   The below lock protects access to two global server variables:
@@ -1349,6 +1350,7 @@ static void clean_up_mutexes()
   (void) pthread_mutex_destroy(&LOCK_user_conn);
   (void) pthread_mutex_destroy(&THR_LOCK_DDL_blocker);
   (void) pthread_mutex_destroy(&THR_LOCK_DDL_is_blocked);
+  (void) pthread_mutex_destroy(&LOCK_backup);
   (void) pthread_cond_destroy(&COND_DDL_blocker);
   (void) pthread_cond_destroy(&COND_process_blocked);
   Events::destroy_mutexes();
@@ -3104,6 +3106,7 @@ static int init_thread_environment()
   (void) pthread_mutex_init(&LOCK_uuid_generator, MY_MUTEX_INIT_FAST);
   (void) pthread_mutex_init(&THR_LOCK_DDL_blocker, MY_MUTEX_INIT_FAST);
   (void) pthread_mutex_init(&THR_LOCK_DDL_is_blocked, MY_MUTEX_INIT_FAST);
+  (void) pthread_mutex_init(&LOCK_backup, MY_MUTEX_INIT_FAST);
   (void) pthread_cond_init(&COND_DDL_blocker, NULL);
   (void) pthread_cond_init(&COND_process_blocked, NULL);
 #ifdef HAVE_OPENSSL
diff -Nrup a/sql/share/errmsg.txt b/sql/share/errmsg.txt
--- a/sql/share/errmsg.txt	2007-11-23 16:59:32 +01:00
+++ b/sql/share/errmsg.txt	2007-11-30 20:44:49 +01:00
@@ -6118,6 +6118,8 @@ ER_BACKUP_BACKUP
         eng "Error during backup operation - server's error log contains more information about the error"
 ER_BACKUP_RESTORE
         eng "Error during restore operation - server's error log contains more information about the error"
+ER_BACKUP_RUNNING
+        eng "Can't execute this command because another BACKUP/RESTORE operation is in progress"
 ER_BACKUP_BACKUP_PREPARE
         eng "Error when preparing for backup operation"
 ER_BACKUP_RESTORE_PREPARE
Thread
bk commit into 6.0 tree (rafal:1.2712) WL#4060rsomla30 Nov