List:Commits« Previous MessageNext Message »
From:Alexey Kopytov Date:March 19 2009 7:19am
Subject:bzr push into mysql-6.0-bugteam branch (Alexey.Kopytov:3130 to 3131)
View as plain text  
 3131 Alexey Kopytov	2009-03-19 [merge]
      Automerge.

 3130 Alexey Kopytov	2009-03-19 [merge]
      Automerge.
      modified:
        mysql-test/include/concurrent.inc
        mysql-test/r/archive.result
        mysql-test/suite/funcs_1/r/is_columns_is.result
        mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result
        mysql-test/suite/funcs_1/r/processlist_val_no_prot.result
        mysql-test/t/archive.test
        mysql-test/t/disabled.def
        mysys/my_error.c
        scripts/mysqld_safe.sh

=== modified file 'client/my_readline.h'
--- a/client/my_readline.h	2007-05-10 09:59:39 +0000
+++ b/client/my_readline.h	2009-03-18 08:27:49 +0000
@@ -29,5 +29,5 @@ typedef struct st_line_buffer
 
 extern LINE_BUFFER *batch_readline_init(ulong max_size,FILE *file);
 extern LINE_BUFFER *batch_readline_command(LINE_BUFFER *buffer, char * str);
-extern char *batch_readline(LINE_BUFFER *buffer);
+extern char *batch_readline(LINE_BUFFER *buffer, bool *truncated);
 extern void batch_readline_end(LINE_BUFFER *buffer);

=== modified file 'client/mysql.cc'
--- a/client/mysql.cc	2009-02-25 10:06:18 +0000
+++ b/client/mysql.cc	2009-03-18 08:29:55 +0000
@@ -115,6 +115,8 @@ extern "C" {
 #define PROMPT_CHAR '\\'
 #define DEFAULT_DELIMITER ";"
 
+#define MAX_BATCH_BUFFER_SIZE (1024L * 1024L)
+
 typedef struct st_status
 {
   int exit_status;
@@ -1049,7 +1051,7 @@ static void fix_history(String *final_co
 
 static COMMANDS *find_command(char *name,char cmd_name);
 static bool add_line(String &buffer,char *line,char *in_string,
-                     bool *ml_comment);
+                     bool *ml_comment, bool truncated);
 static void remove_cntrl(String &buffer);
 static void print_table_data(MYSQL_RES *result);
 static void print_table_data_html(MYSQL_RES *result);
@@ -1124,7 +1126,7 @@ int main(int argc,char *argv[])
     exit(1);
   }
   if (status.batch && !status.line_buff &&
-      !(status.line_buff=batch_readline_init(opt_max_allowed_packet+512,stdin)))
+      !(status.line_buff= batch_readline_init(MAX_BATCH_BUFFER_SIZE, stdin)))
   {
     free_defaults(defaults_argv);
     my_end(0);
@@ -1847,13 +1849,14 @@ static int read_and_execute(bool interac
   ulong line_number=0;
   bool ml_comment= 0;  
   COMMANDS *com;
+  bool truncated= 0;
   status.exit_status=1;
   
   for (;;)
   {
     if (!interactive)
     {
-      line=batch_readline(status.line_buff);
+      line=batch_readline(status.line_buff, &truncated);
       /*
         Skip UTF8 Byte Order Marker (BOM) 0xEFBBBF.
         Editors like "notepad" put this marker in
@@ -1950,7 +1953,7 @@ static int read_and_execute(bool interac
 #endif
       continue;
     }
-    if (add_line(glob_buffer,line,&in_string,&ml_comment))
+    if (add_line(glob_buffer,line,&in_string,&ml_comment, truncated))
       break;
   }
   /* if in batch mode, send last query even if it doesn't end with \g or go */
@@ -2036,7 +2039,7 @@ static COMMANDS *find_command(char *name
 
 
 static bool add_line(String &buffer,char *line,char *in_string,
-                     bool *ml_comment)
+                     bool *ml_comment, bool truncated)
 {
   uchar inchar;
   char buff[80], *pos, *out;
@@ -2284,9 +2287,10 @@ static bool add_line(String &buffer,char
   {
     uint length=(uint) (out-line);
 
-    if (length < 9 || 
-        my_strnncoll (charset_info, 
-                      (uchar *)line, 9, (const uchar *) "delimiter", 9))
+    if (!truncated &&
+        (length < 9 || 
+         my_strnncoll (charset_info, 
+                       (uchar *)line, 9, (const uchar *) "delimiter", 9)))
     {
       /* 
         Don't add a new line in case there's a DELIMITER command to be 
@@ -4018,7 +4022,7 @@ static int com_source(String *buffer, ch
     return put_info(buff, INFO_ERROR, 0);
   }
 
-  if (!(line_buff=batch_readline_init(opt_max_allowed_packet+512,sql_file)))
+  if (!(line_buff= batch_readline_init(MAX_BATCH_BUFFER_SIZE, sql_file)))
   {
     my_fclose(sql_file,MYF(0));
     return put_info("Can't initialize batch_readline", INFO_ERROR, 0);

=== modified file 'client/readline.cc'
--- a/client/readline.cc	2008-06-17 23:37:23 +0000
+++ b/client/readline.cc	2009-03-18 08:29:55 +0000
@@ -24,7 +24,7 @@ static bool init_line_buffer(LINE_BUFFER
 			    ulong max_size);
 static bool init_line_buffer_from_string(LINE_BUFFER *buffer,char * str);
 static size_t fill_buffer(LINE_BUFFER *buffer);
-static char *intern_read_line(LINE_BUFFER *buffer,ulong *out_length);
+static char *intern_read_line(LINE_BUFFER *buffer, ulong *out_length, bool *truncated);
 
 
 LINE_BUFFER *batch_readline_init(ulong max_size,FILE *file)
@@ -42,12 +42,13 @@ LINE_BUFFER *batch_readline_init(ulong m
 }
 
 
-char *batch_readline(LINE_BUFFER *line_buff)
+char *batch_readline(LINE_BUFFER *line_buff, bool *truncated)
 {
   char *pos;
   ulong out_length;
+  DBUG_ASSERT(truncated != NULL);
 
-  if (!(pos=intern_read_line(line_buff,&out_length)))
+  if (!(pos=intern_read_line(line_buff,&out_length, truncated)))
     return 0;
   if (out_length && pos[out_length-1] == '\n')
     if (--out_length && pos[out_length-1] == '\r')  /* Remove '\n' */
@@ -149,6 +150,14 @@ static size_t fill_buffer(LINE_BUFFER *b
     read_count=(buffer->bufread - bufbytes)/IO_SIZE;
     if ((read_count*=IO_SIZE))
       break;
+    if (buffer->bufread * 2 > buffer->max_size)
+    {
+      /*
+        So we must grow the buffer but we cannot due to the max_size limit.
+        Return 0 w/o setting buffer->eof to signal this condition.
+      */
+      return 0;
+    }
     buffer->bufread *= 2;
     if (!(buffer->buffer = (char*) my_realloc(buffer->buffer,
 					      buffer->bufread+1,
@@ -172,11 +181,15 @@ static size_t fill_buffer(LINE_BUFFER *b
 
   DBUG_PRINT("fill_buff", ("Got %lu bytes", (ulong) read_count));
 
-  /* Kludge to pretend every nonempty file ends with a newline. */
-  if (!read_count && bufbytes && buffer->end[-1] != '\n')
+  if (!read_count)
   {
-    buffer->eof = read_count = 1;
-    *buffer->end = '\n';
+    buffer->eof = 1;
+    /* Kludge to pretend every nonempty file ends with a newline. */
+    if (bufbytes && buffer->end[-1] != '\n')
+    {
+      read_count = 1;
+      *buffer->end = '\n';
+    }
   }
   buffer->end_of_line=(buffer->start_of_line=buffer->buffer)+bufbytes;
   buffer->end+=read_count;
@@ -186,7 +199,7 @@ static size_t fill_buffer(LINE_BUFFER *b
 
 
 
-char *intern_read_line(LINE_BUFFER *buffer,ulong *out_length)
+char *intern_read_line(LINE_BUFFER *buffer, ulong *out_length, bool *truncated)
 {
   char *pos;
   size_t length;
@@ -200,14 +213,23 @@ char *intern_read_line(LINE_BUFFER *buff
       pos++;
     if (pos == buffer->end)
     {
-      if ((uint) (pos - buffer->start_of_line) < buffer->max_size)
+      /*
+        fill_buffer() can return 0 either on EOF in which case we abort
+        or when the internal buffer has hit the size limit. In the latter case
+        return what we have read so far and signal string truncation.
+      */
+      if (!(length=fill_buffer(buffer)) || length == (uint) -1)
       {
-	if (!(length=fill_buffer(buffer)) || length == (size_t) -1)
-	  DBUG_RETURN(0);
-	continue;
+        if (buffer->eof)
+          DBUG_RETURN(0);
       }
+      else
+        continue;
       pos--;					/* break line here */
+      *truncated= 1;
     }
+    else
+      *truncated= 0;
     buffer->end_of_line=pos+1;
     *out_length=(ulong) (pos + 1 - buffer->eof - buffer->start_of_line);
     DBUG_RETURN(buffer->start_of_line);

=== modified file 'mysql-test/r/mysql.result'
--- a/mysql-test/r/mysql.result	2009-02-25 10:06:18 +0000
+++ b/mysql-test/r/mysql.result	2009-03-18 08:29:55 +0000
@@ -192,6 +192,17 @@ delimiter
 1
 1
 1
+set @old_max_allowed_packet = @@global.max_allowed_packet;
+set @@global.max_allowed_packet = 2 * 1024 * 1024 + 1024;
+set @@max_allowed_packet = @@global.max_allowed_packet;
+CREATE TABLE t1(data LONGBLOB);
+INSERT INTO t1 SELECT REPEAT('1', 2*1024*1024);
+SELECT LENGTH(data) FROM t1;
+LENGTH(data)
+2097152
+DROP TABLE t1;
+set @@global.max_allowed_packet = @old_max_allowed_packet;
+set @@max_allowed_packet = @@global.max_allowed_packet;
 End of 5.0 tests
 WARNING: --server-arg option not supported in this configuration.
 *************************** 1. row ***************************

=== modified file 'mysql-test/t/mysql.test'
--- a/mysql-test/t/mysql.test	2009-03-02 12:41:56 +0000
+++ b/mysql-test/t/mysql.test	2009-03-19 07:17:14 +0000
@@ -342,6 +342,33 @@ EOF
 
 remove_file $MYSQLTEST_VARDIR/tmp/bug31060.sql;
 
+#  
+# Bug #41486: extra character appears in BLOB for every ~40Mb after   
+#             mysqldump/import   
+#  
+  
+# Have to change the global variable as the mysql client will use 
+# a separate session 
+set @old_max_allowed_packet = @@global.max_allowed_packet; 
+# 2 MB blob length + some space for the rest of INSERT query
+set @@global.max_allowed_packet = 2 * 1024 * 1024 + 1024; 
+set @@max_allowed_packet = @@global.max_allowed_packet;
+
+CREATE TABLE t1(data LONGBLOB);  
+INSERT INTO t1 SELECT REPEAT('1', 2*1024*1024);  
+  
+--exec $MYSQL_DUMP test t1 >$MYSQLTEST_VARDIR/tmp/bug41486.sql  
+# Check that the mysql client does not insert extra newlines when loading  
+# strings longer than client's max_allowed_packet  
+--exec $MYSQL --max_allowed_packet=1M test < $MYSQLTEST_VARDIR/tmp/bug41486.sql 2>&1  
+SELECT LENGTH(data) FROM t1;  
+  
+remove_file $MYSQLTEST_VARDIR/tmp/bug41486.sql; 
+DROP TABLE t1;  
+
+set @@global.max_allowed_packet = @old_max_allowed_packet; 
+set @@max_allowed_packet = @@global.max_allowed_packet;
+ 
 --echo End of 5.0 tests
 
 #

Thread
bzr push into mysql-6.0-bugteam branch (Alexey.Kopytov:3130 to 3131)Alexey Kopytov19 Mar