Blame SOURCES/mysql-log-fifo.patch

80384c
MySQL port of the following MariaDB patch:
80384c
80384c
commit 8e781601f46938cb4228bd9a966a9d6871c06859
80384c
Author: Sergei Golubchik <serg@mariadb.org>
80384c
Date:   Fri Apr 24 21:41:00 2015 +0200
80384c
80384c
    MDEV-6870 Not possible to use FIFO file as a general_log file
80384c
    
80384c
    Remove the too restrictive bugfix for bug#67088.
80384c
    FIFO can be used for general/slow logs, but lseek() and fsync() on
80384c
    FIFO fail. And open() needs to be non-blocking, in case the other
80384c
    end isn't reading.
80384c
80384c
RHBZ: #1219496
80384c
743cec
diff -rup mysql-5.6.33.orig/mysql-test/r/log_errchk.result mysql-5.6.33/mysql-test/r/log_errchk.result
743cec
--- mysql-5.6.33.orig/mysql-test/r/log_errchk.result	2016-08-26 13:22:35.000000000 +0200
743cec
+++ mysql-5.6.33/mysql-test/r/log_errchk.result	2016-10-06 16:13:15.102478779 +0200
80384c
@@ -1,5 +1,4 @@
80384c
-call mtr.add_suppression("Could not open");
80384c
-# Case 1: Setting fife file to general_log_file and slow_query_log_file
80384c
+# Case 1: Setting fifo file to general_log_file and slow_query_log_file
80384c
 #         system variable.
80384c
 SET GLOBAL general_log_file="MYSQLTEST_VARDIR/tmp/general_log.fifo";;
80384c
 ERROR 42000: Variable 'general_log_file' can't be set to the value of 'MYSQLTEST_VARDIR/tmp/general_log.fifo'
80384c
@@ -7,4 +6,6 @@ SET GLOBAL slow_query_log_file="MYSQLTES
80384c
 ERROR 42000: Variable 'slow_query_log_file' can't be set to the value of 'MYSQLTEST_VARDIR/tmp/slow_log.fifo'
80384c
 # Case 2: Starting server with fifo file as general log file
80384c
 #         and slow query log file.
80384c
+call mtr.add_suppression("Could not open .* for logging \\(error 6\\)");
80384c
+call mtr.add_suppression("File '.*' not found \\(Errcode: 6\\)");
80384c
 Setting fifo file as general log file and slow query log failed.
743cec
diff -rup mysql-5.6.33.orig/mysql-test/t/log_errchk.test mysql-5.6.33/mysql-test/t/log_errchk.test
743cec
--- mysql-5.6.33.orig/mysql-test/t/log_errchk.test	2016-08-26 13:22:35.000000000 +0200
743cec
+++ mysql-5.6.33/mysql-test/t/log_errchk.test	2016-10-06 16:16:23.130667809 +0200
80384c
@@ -7,8 +7,8 @@
80384c
 # Bug#14757009 : WHEN THE GENERAL_LOG IS A SOCKET AND THE READER GOES AWAY,
80384c
 #                MYSQL QUITS WORKING.
80384c
 #
80384c
-call mtr.add_suppression("Could not open");
80384c
-
80384c
+# MariaDB: MDEV-6870 Not possible to use FIFO file as a general_log file
80384c
+#
80384c
 --let $gen_log_file= $MYSQLTEST_VARDIR/tmp/general_log.fifo
80384c
 --let $slow_query_log_file= $MYSQLTEST_VARDIR/tmp/slow_log.fifo
80384c
 --let GREP_FILE=$MYSQLTEST_VARDIR/log/mysqld.1.err
80384c
@@ -16,10 +16,9 @@ call mtr.add_suppression("Could not open
80384c
 --exec mkfifo $gen_log_file
80384c
 --exec mkfifo $slow_query_log_file
80384c
 
80384c
---echo # Case 1: Setting fife file to general_log_file and slow_query_log_file
80384c
+--echo # Case 1: Setting fifo file to general_log_file and slow_query_log_file
80384c
 --echo #         system variable.
80384c
-# Only regular files can be set to general log. Setting fifo file to general log
80384c
-# reports an error.
80384c
+# Setting fifo file to general log reports an error because the other end is closed
80384c
 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
80384c
 --error ER_WRONG_VALUE_FOR_VAR
80384c
 --eval SET GLOBAL general_log_file="$gen_log_file";
80384c
@@ -39,11 +38,12 @@ call mtr.add_suppression("Could not open
80384c
 --exec echo "restart: --general-log-file=$gen_log_file --slow-query-log-file=$slow_query_log_file" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
80384c
 --source include/wait_until_connected_again.inc
80384c
 
80384c
-# With fix error should be reported in the error log file if file is not a
80384c
-# regular file.
80384c
+# Error 6 is reported, because the other end is closed
80384c
+call mtr.add_suppression("Could not open .* for logging \\(error 6\\)");
80384c
+call mtr.add_suppression("File '.*' not found \\(Errcode: 6\\)");
80384c
 --perl
80384c
   my $file= $ENV{'GREP_FILE'};
80384c
-  my $pattern= "Turning logging off for the whole duration";
80384c
+  my $pattern= "for logging \\(error 6\\)\\. Turning logging off for the whole duration";
80384c
   open(FILE, "$file") or die("Unable to open $file: $!\n");
80384c
   my $count = 0;
80384c
   while (<FILE>) {
743cec
diff -rup mysql-5.6.33.orig/sql/log.cc mysql-5.6.33/sql/log.cc
743cec
--- mysql-5.6.33.orig/sql/log.cc	2016-08-26 13:22:35.000000000 +0200
743cec
+++ mysql-5.6.33/sql/log.cc	2016-10-06 16:44:57.683152679 +0200
743cec
@@ -1598,6 +1598,7 @@ bool MYSQL_LOG::open(
80384c
   MY_STAT f_stat;
80384c
   File file= -1;
80384c
   my_off_t pos= 0;
80384c
+  bool is_fifo = false;
80384c
   int open_flags= O_CREAT | O_BINARY;
80384c
   DBUG_ENTER("MYSQL_LOG::open");
80384c
   DBUG_PRINT("enter", ("log_type: %d", (int) log_type_arg));
743cec
@@ -1615,15 +1616,17 @@ bool MYSQL_LOG::open(
80384c
       DBUG_EVALUATE_IF("fault_injection_init_name", log_type == LOG_BIN, 0))
80384c
     goto err;
80384c
 
80384c
-  /* File is regular writable file */
80384c
-  if (my_stat(log_file_name, &f_stat, MYF(0)) && !MY_S_ISREG(f_stat.st_mode))
80384c
-    goto err;
80384c
+  is_fifo = my_stat(log_file_name, &f_stat, MYF(0)) &&
80384c
+            MY_S_ISFIFO(f_stat.st_mode);
80384c
 
80384c
   if (io_cache_type == SEQ_READ_APPEND)
80384c
     open_flags |= O_RDWR | O_APPEND;
80384c
   else
80384c
     open_flags |= O_WRONLY | (log_type == LOG_BIN ? 0 : O_APPEND);
80384c
 
80384c
+  if (is_fifo)
80384c
+    open_flags |= O_NONBLOCK;
80384c
+
80384c
   db[0]= 0;
80384c
 
80384c
 #ifdef HAVE_PSI_INTERFACE
743cec
@@ -1648,7 +1651,9 @@ bool MYSQL_LOG::open(
80384c
     goto err;
743cec
 #endif // _WIN32
80384c
 
80384c
-  if ((pos= mysql_file_tell(file, MYF(MY_WME))) == MY_FILEPOS_ERROR)
80384c
+  if (is_fifo)
80384c
+    pos= 0;
80384c
+  else if ((pos= mysql_file_tell(file, MYF(MY_WME))) == MY_FILEPOS_ERROR)
80384c
   {
80384c
     if (my_errno == ESPIPE)
80384c
       pos= 0;
743cec
@@ -1756,7 +1761,7 @@ void MYSQL_LOG::close(uint exiting)
80384c
   {
80384c
     end_io_cache(&log_file);
80384c
 
80384c
-    if (mysql_file_sync(log_file.file, MYF(MY_WME)) && ! write_error)
80384c
+    if (log_type == LOG_BIN && mysql_file_sync(log_file.file, MYF(MY_WME)) && ! write_error)
80384c
     {
80384c
       char errbuf[MYSYS_STRERROR_SIZE];
80384c
       write_error= 1;