List:Commits« Previous MessageNext Message »
From:msvensson Date:February 9 2006 2:19pm
Subject:bk commit into 4.1 tree (msvensson:1.2474) BUG#14057
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of msvensson. When msvensson 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
  1.2474 06/02/09 14:19:44 msvensson@neptunus.(none) +5 -0
  Bug#14057 mysql_ping() handles TCP and UNIX socket connections in different ways
   - Detect that connection to server has been broken in "net_clear". Since 
  net_clear is always called before we send command to server, we can be sure
  that server has not received to command.   

  sql/net_serv.cc
    1.76 06/02/09 14:19:42 msvensson@neptunus.(none) +36 -11
    Make "net_clear" detect if connection with server has been broken by 
    performing a select. If the select returns that there are data to read but
    no data can be read, that means the connection is broken. Signal disconnected
    to "write" functions by setting error to 2. 

  mysql-test/t/wait_timeout.test
    1.2 06/02/09 14:19:42 msvensson@neptunus.(none) +41 -2
    Decease sleep times
    Add test for wait_timeout also on a TCP connection
    Add test for mysql_ping on socket and TCP connection.

  mysql-test/t/wait_timeout-master.opt
    1.2 06/02/09 14:19:42 msvensson@neptunus.(none) +1 -1
    Decrease wait-timeout so the sleeps in test can be minimized

  mysql-test/r/wait_timeout.result
    1.2 06/02/09 14:19:42 msvensson@neptunus.(none) +9 -0
    Update test result

  client/mysqltest.c
    1.190 06/02/09 14:19:41 msvensson@neptunus.(none) +12 -1
    Make ping detect if mysql_ping commadn fails.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	msvensson
# Host:	neptunus.(none)
# Root:	/home/msvensson/mysql/bug14057/my41-bug14057

--- 1.75/sql/net_serv.cc	2005-09-07 12:59:02 +02:00
+++ 1.76/sql/net_serv.cc	2006-02-09 14:19:42 +01:00
@@ -191,25 +191,50 @@
   DBUG_RETURN(0);
 }
 
-	/* Remove unwanted characters from connection */
+
+static my_bool net_data_is_ready(my_socket fd)
+{
+  fd_set sfds;
+  struct timeval tv;
+  int res;
+
+  FD_ZERO(&sfds);
+  FD_SET(fd, &sfds);
+
+  tv.tv_sec= tv.tv_usec= 0;
+
+  if ((res= select(fd+1, &sfds, NULL, NULL, &tv)) < 0)
+    return FALSE;
+  else
+    return test(res ? FD_ISSET(fd, &sfds) : 0);
+}
+
+
+/* Remove unwanted characters from connection
+   and check if disconnected */
 
 void net_clear(NET *net)
 {
+  int count;
   DBUG_ENTER("net_clear");
-#if !defined(EXTRA_DEBUG) && !defined(EMBEDDED_LIBRARY)
+#if !defined(EMBEDDED_LIBRARY)
+  while(net_data_is_ready(net->vio->sd))
   {
-    int count;					/* One may get 'unused' warn */
-    my_bool old_mode;
-    if (!vio_blocking(net->vio, FALSE, &old_mode))
+    /* The socket is ready */
+    if ((count= vio_read(net->vio, (char*) (net->buff),
+                         (uint32) net->max_packet)) > 0)
+    {
+      DBUG_PRINT("info",("skipped %d bytes from file: %s",
+                         count, vio_description(net->vio)));
+    }
+    else
     {
-      while ((count = vio_read(net->vio, (char*) (net->buff),
-			       (uint32) net->max_packet)) > 0)
-	DBUG_PRINT("info",("skipped %d bytes from file: %s",
-			   count, vio_description(net->vio)));
-      vio_blocking(net->vio, TRUE, &old_mode);
+      DBUG_PRINT("info",("socket ready but no data to read - disconnected"));
+      net->error= 2;
+      break;
     }
   }
-#endif /* EXTRA_DEBUG */
+#endif
   net->pkt_nr=net->compress_pkt_nr=0;		/* Ready for new command */
   net->write_pos=net->buff;
   DBUG_VOID_RETURN;

--- 1.1/mysql-test/r/wait_timeout.result	2005-10-11 18:12:10 +02:00
+++ 1.2/mysql-test/r/wait_timeout.result	2006-02-09 14:19:42 +01:00
@@ -6,3 +6,12 @@
 select 3;
 3
 3
+select 1;
+1
+1
+select 2;
+ERROR HY000: MySQL server has gone away
+select 3;
+3
+3
+test of bug14057 completed

--- 1.1/mysql-test/t/wait_timeout-master.opt	2005-10-11 18:12:10 +02:00
+++ 1.2/mysql-test/t/wait_timeout-master.opt	2006-02-09 14:19:42 +01:00
@@ -1 +1 @@
---wait-timeout=2
+--wait-timeout=1

--- 1.1/mysql-test/t/wait_timeout.test	2005-10-11 18:12:10 +02:00
+++ 1.2/mysql-test/t/wait_timeout.test	2006-02-09 14:19:42 +01:00
@@ -3,9 +3,48 @@
 #
 --disable_reconnect
 select 1;
-# wait_timeout is 2, so we should get disconnected now
---sleep 5
+# wait_timeout is 1, so we should get disconnected now
+--sleep 2
+# When the connection is lost the error code will depend on
+# the type of the connection(socket, TCP) used between the client and server
+# see bug#2845 for an explanation
 --error 2006
 select 2;
 --enable_reconnect
 select 3;
+
+# Do the same test as above on a TCP connection
+connect (con1,127.0.0.1,root,,test,$MASTER_MYPORT,);
+--disable_reconnect
+select 1;
+# wait_timeout is 1, so we should get disconnected now
+--sleep 2
+--error 2006
+select 2;
+--enable_reconnect
+select 3;
+disconnect con1;
+
+#
+# Bug #14057 mysql_ping() handles TCP and UNIX socket connections
+# in different ways
+#
+# Connect with socket
+connect (con2,localhost,root,,);
+--sleep 2
+--ping
+--ping
+--ping
+disconnect con2;
+
+# Connect with TCP
+connect (con3,127.0.0.1,root,,test,$MASTER_MYPORT,);
+--sleep 2
+--ping
+--ping
+--ping
+
+disconnect con3;
+connection default;
+
+echo test of bug14057 completed;

--- 1.189/client/mysqltest.c	2005-10-31 13:23:52 +01:00
+++ 1.190/client/mysqltest.c	2006-02-09 14:19:41 +01:00
@@ -1301,6 +1301,17 @@
   return 0;
 }
 
+int do_ping(struct st_query *command)
+{
+  MYSQL* mysql= &cur_con->mysql;
+  if (mysql_ping(mysql))
+    die("mysql_ping failed: %d: %s",
+        mysql_errno(mysql), mysql_error(mysql));
+
+  command->last_argument= command->end;
+  return 0;
+}
+
 
 /*
   Print the content between echo and <delimiter> to result file.
@@ -4005,7 +4016,7 @@
         q->last_argument= q->end;
 	break;
       case Q_PING:
-	(void) mysql_ping(&cur_con->mysql);
+        do_ping(q);
 	break;
       case Q_EXEC:
 	do_exec(q);
Thread
bk commit into 4.1 tree (msvensson:1.2474) BUG#14057msvensson9 Feb