From fdfad1d063ae9fa48429a4f0fd536d084a92ebb7 Mon Sep 17 00:00:00 2001
From: "msvensson@neptunus.(none)" <>
Date: Thu, 27 Jul 2006 10:54:04 +0200
Subject: [PATCH] Bug#21297  rpl_insert fails randomly  - Add loop in mysqlslap
 that tries to connect up to 10 times if connect    in thread fails.

---
 client/mysqlslap.c        | 21 ++++++++++++++++++---
 mysql-test/t/disabled.def |  1 -
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/client/mysqlslap.c b/client/mysqlslap.c
index c061433178b..9c8585915a9 100644
--- a/client/mysqlslap.c
+++ b/client/mysqlslap.c
@@ -1113,6 +1113,7 @@ run_scheduler(stats *sptr, statement *stmts, uint concur, ulonglong limit)
   DBUG_RETURN(0);
 }
 
+
 int
 run_task(thread_context *con)
 {
@@ -1137,13 +1138,27 @@ run_task(thread_context *con)
   my_lock(lock_file, F_RDLCK, 0, F_TO_EOF, MYF(0));
   if (!opt_only_print)
   {
-    if (!(mysql_real_connect(mysql, host, user, opt_password,
+    /* Connect to server */
+    static ulong connection_retry_sleep= 100000; /* Microseconds */
+    int i, connect_error= 1;
+    for (i= 0; i < 10; i++)
+    {
+      if (mysql_real_connect(mysql, host, user, opt_password,
                              create_schema_string,
                              opt_mysql_port,
                              opt_mysql_unix_port,
-                             connect_flags)))
+                             connect_flags))
+      {
+        /* Connect suceeded */
+        connect_error= 0;
+        break;
+      }
+      my_sleep(connection_retry_sleep);
+    }
+    if (connect_error)
     {
-      fprintf(stderr,"%s: %s\n",my_progname,mysql_error(mysql));
+      fprintf(stderr,"%s: Error when connecting to server: %d %s\n",
+              my_progname, mysql_errno(mysql), mysql_error(mysql));
       goto end;
     }
   }
diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def
index 521f79fb8f7..2845a638b07 100644
--- a/mysql-test/t/disabled.def
+++ b/mysql-test/t/disabled.def
@@ -38,7 +38,6 @@ rpl_sp_effects           : BUG#19862 2006-06-15 mkindahl
 
 # the below testcase have been reworked to avoid the bug, test contains comment, keep bug open
 #ndb_binlog_ddl_multi     : BUG#18976 2006-04-10 kent    CRBR: multiple binlog, second binlog may miss schema log events
-rpl_insert               : BUG#21297 2006-07-26 msvensson
 rpl_ndb_idempotent       : BUG#21298 2006-07-27 msvensson
 rpl_row_basic_7ndb       : BUG#21298 2006-07-27 msvensson
 rpl_truncate_7ndb        : BUG#21298 2006-07-27 msvensson
-- 
2.30.9