MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Chad MILLER Date:July 1 2008 4:06pm
Subject:bzr commit into mysql-5.1 branch (chad:2677) Bug#21358
View as plain text  
#At file:///home/cmiller/work/mysqlbzr/mysql-5.1-bugteam--bug21358/

 2677 Chad MILLER	2008-07-01
      Bug#21358: mysqlslap does not report error properly
      
      In a thread that connects to the server, if it fails, we only
      return from that function (and thereby destroy the thread), and
      the main thread continues operating as if the operations were
      complete.  It should instead halt and signal an error to the
      executor.
      
      Now, check for fatal errors in threads and have the main process
      behave correctly.
      
      Also, fix some of the more egregious problems with a spawned
      thread killing the entire process with the exit syscall.
      
      Also, start to use the exit value to tell the user where the
      error is -- locally or near the SQL server.  0=no error  1=local
      2=server  (This could be made into bit flags later, too.)
modified:
  client/mysqlslap.c

=== modified file 'client/mysqlslap.c'
--- a/client/mysqlslap.c	2008-02-08 11:13:33 +0000
+++ b/client/mysqlslap.c	2008-07-01 16:01:54 +0000
@@ -108,11 +108,13 @@ static char *shared_memory_base_name=0;
 /* Global Thread counter */
 uint thread_counter;
 pthread_mutex_t counter_mutex;
+pthread_mutex_t threads_errors_counter_mutex;
 pthread_cond_t count_threshhold;
 uint master_wakeup;
 pthread_mutex_t sleeper_mutex;
 pthread_cond_t sleep_threshhold;
 
+uint threads_fatal_errors_count;
 static char **defaults_argv;
 
 char **primary_keys;
@@ -352,6 +354,7 @@ int main(int argc, char **argv)
     }
   }
 
+  VOID(pthread_mutex_init(&threads_errors_counter_mutex, NULL));
   VOID(pthread_mutex_init(&counter_mutex, NULL));
   VOID(pthread_cond_init(&count_threshhold, NULL));
   VOID(pthread_mutex_init(&sleeper_mutex, NULL));
@@ -1707,6 +1710,8 @@ run_scheduler(stats *sptr, statement *st
   con.stmt= stmts;
   con.limit= limit;
 
+  threads_fatal_errors_count= 0;
+
   pthread_attr_init(&attr);
   pthread_attr_setdetachstate(&attr,
 		  PTHREAD_CREATE_DETACHED);
@@ -1725,7 +1730,7 @@ run_scheduler(stats *sptr, statement *st
     {
       fprintf(stderr,"%s: Could not create thread\n",
               my_progname);
-      exit(0);
+      exit(1);
     }
     thread_counter++;
   }
@@ -1752,6 +1757,9 @@ run_scheduler(stats *sptr, statement *st
   }
   pthread_mutex_unlock(&counter_mutex);
 
+  if (threads_fatal_errors_count > 0)
+    exit(2);
+
   gettimeofday(&end_time, NULL);
 
 
@@ -1773,6 +1781,7 @@ pthread_handler_t run_task(void *p)
   MYSQL_ROW row;
   statement *ptr;
   thread_context *con= (thread_context *)p;
+  unsigned int error_count;
 
   DBUG_ENTER("run_task");
   DBUG_PRINT("info", ("task script \"%s\"", con->stmt ? con->stmt->string : ""));
@@ -1788,14 +1797,14 @@ pthread_handler_t run_task(void *p)
   {
     fprintf(stderr,"%s: mysql_init() failed ERROR : %s\n",
             my_progname, mysql_error(mysql));
-    exit(0);
+    exit(1);
   }
 
   if (mysql_thread_init())
   {
     fprintf(stderr,"%s: mysql_thread_init() failed ERROR : %s\n",
             my_progname, mysql_error(mysql));
-    exit(0);
+    exit(1);
   }
 
   DBUG_PRINT("info", ("trying to connect to host %s as user %s", host, user));
@@ -1803,7 +1812,10 @@ pthread_handler_t run_task(void *p)
   if (!opt_only_print)
   {
     if (slap_connect(mysql))
-      goto end;
+    {
+      error_count++;
+      goto quit_thread;
+    }
   }
 
   DBUG_PRINT("info", ("connected."));
@@ -1828,11 +1840,15 @@ limit_not_met:
         {
           fprintf(stderr,"%s: mysql_init() failed ERROR : %s\n",
                   my_progname, mysql_error(mysql));
-          exit(0);
+          error_count++;
+          goto quit_thread;
         }
 
         if (slap_connect(mysql))
-          goto end;
+        {
+          error_count++;
+          goto quit_thread;
+        }
       }
 
       /* 
@@ -1868,7 +1884,8 @@ limit_not_met:
           {
             fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
                     my_progname, (uint)length, buffer, mysql_error(mysql));
-            exit(0);
+            error_count++;
+            goto quit_thread;
           }
         }
       }
@@ -1878,7 +1895,8 @@ limit_not_met:
         {
           fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
                   my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
-          exit(0);
+          error_count++;
+          goto quit_thread;
         }
       }
 
@@ -1901,19 +1919,27 @@ limit_not_met:
       }
 
       if (con->limit && queries == con->limit)
-        goto end;
+        goto finish_and_close;
     }
 
     if (con->limit && queries < con->limit)
       goto limit_not_met;
 
-end:
+finish_and_close:
   if (commit_rate)
     run_query(mysql, "COMMIT", strlen("COMMIT"));
 
   if (!opt_only_print) 
     mysql_close(mysql);
 
+quit_thread:
+  if (error_count > 0)
+  {
+    pthread_mutex_lock(&threads_errors_counter_mutex);
+    threads_fatal_errors_count+= error_count;
+    pthread_mutex_unlock(&threads_errors_counter_mutex);
+  }
+
   my_thread_end();
 
   pthread_mutex_lock(&counter_mutex);

Thread
bzr commit into mysql-5.1 branch (chad:2677) Bug#21358Chad MILLER1 Jul