Commit graph

954 commits

Author SHA1 Message Date
Venkatesh Duggirala
2870bd7423 Bug#17283409 4-WAY DEADLOCK: ZOMBIES, PURGING BINLOGS,
SHOW PROCESSLIST, SHOW BINLOGS

Problem:  A deadlock was occurring when 4 threads were
involved in acquiring locks in the following way
Thread 1: Dump thread ( Slave is reconnecting, so on
              Master, a new dump thread is trying kill
              zombie dump threads. It acquired thread's
              LOCK_thd_data and it is about to acquire
              mysys_var->current_mutex ( which LOCK_log)
Thread 2: Application thread is executing show binlogs and
               acquired LOCK_log and it is about to acquire
               LOCK_index.
Thread 3: Application thread is executing Purge binary logs
               and acquired LOCK_index and it is about to
               acquire LOCK_thread_count.
Thread 4: Application thread is executing show processlist
               and acquired LOCK_thread_count and it is
               about to acquire zombie dump thread's
               LOCK_thd_data.
Deadlock Cycle:
     Thread 1 -> Thread 2 -> Thread 3-> Thread 4 ->Thread 1

The same above deadlock was observed even when thread 4 is
executing 'SELECT * FROM information_schema.processlist' command and
acquired LOCK_thread_count and it is about to acquire zombie
dump thread's LOCK_thd_data.

Analysis:
There are four locks involved in the deadlock.  LOCK_log,
LOCK_thread_count, LOCK_index and LOCK_thd_data.
LOCK_log, LOCK_thread_count, LOCK_index are global mutexes
where as LOCK_thd_data is local to a thread.
We can divide these four locks in two groups.
Group 1 consists of LOCK_log and LOCK_index and the order
should be LOCK_log followed by LOCK_index.
Group 2 consists of other two mutexes
LOCK_thread_count, LOCK_thd_data and the order should
be LOCK_thread_count followed by LOCK_thd_data.
Unfortunately, there is no specific predefined lock order defined
to follow in the MySQL system when it comes to locks across these
two groups. In the above problematic example,
there is no problem in the way we are acquiring the locks
if you see each thread individually.
But If you combine all 4 threads, they end up in a deadlock.

Fix: 
Since everything seems to be fine in the way threads are taking locks,
In this patch We are changing the duration of the locks in Thread 4
to break the deadlock. i.e., before the patch, Thread 4
('show processlist' command) mysqld_list_processes()
function acquires LOCK_thread_count for the complete duration
of the function and it also acquires/releases
each thread's LOCK_thd_data.

LOCK_thread_count is used to protect addition and
deletion of threads in global threads list. While show
process list is looping through all the existing threads,
it will be a problem if a thread is exited but there is no problem
if a new thread is added to the system. Hence a new mutex is
introduced "LOCK_thd_remove" which will protect deletion
of a thread from global threads list. All threads which are
getting exited should acquire LOCK_thd_remove
followed by LOCK_thread_count. (It should take LOCK_thread_count
also because other places of the code still thinks that exit thread
is protected with LOCK_thread_count. In this fix, we are changing
only 'show process list' query logic )
(Eg: unlink_thd logic will be protected with
LOCK_thd_remove).

Logic of mysqld_list_processes(or file_schema_processlist)
will now be protected with 'LOCK_thd_remove' instead of
'LOCK_thread_count'.

Now the new locking order after this patch is:
LOCK_thd_remove -> LOCK_thd_data -> LOCK_log ->
LOCK_index -> LOCK_thread_count
2014-05-08 18:13:01 +05:30
Murthy Narkedimilli
c92223e198 Updated/added copyright headers 2014-01-06 10:52:35 +05:30
Ashish Agarwal
e879caf845 WL#7076: Backporting wl6715 to support both formats in 5.5, 5.6, 5.7
Backporting wl6715 to mysql-5.5
2013-07-02 11:58:39 +05:30
Murthy Narkedimilli
8afe262ae5 Fix for Bug 16395495 - OLD FSF ADDRESS IN GPL HEADER 2013-03-19 15:53:48 +01:00
Rohit Kalhans
4802faad3f upmerge to bug#14548159 2012-09-22 18:07:04 +05:30
Rohit Kalhans
5530c5e38d BUG#14548159: NUMEROUS CASES OF INCORRECT IDENTIFIER
QUOTING IN REPLICATION 

Problem: Misquoting or unquoted identifiers may lead to
incorrect statements to be logged to the binary log.

Fix: we use specialized functions to append quoted identifiers in
the statements generated by the server.
2012-09-22 17:50:51 +05:30
Sujatha Sivakumar
8d5c44c9dd merge from 5.1 to 5.5 2012-09-17 11:53:34 +05:30
Sujatha Sivakumar
5cbdb90827 Bug#11750014:ASSERTION TRX_DATA->EMPTY() IN BINLOG_CLOSE_CONNECTION
Problem:
=======

trx_data->empty() assert happens at `binlog_close_connection'

Analysis:
========

trx_data->empty() function checks for no pending events
and the transaction cache to be empty.This function returns
"true" if no pending events are present and cache is empty.
Otherwise it returns false. `binlog_close_connection' call
expects the above function to return true. But if the
return value is false then assert is raised.

This bug was reproducible in a diskfull scenario. In this
disk full scenario try to do an insert operation so that
a new pending event is created and flushing this pending
event fails. Due to this failure the server goes down
and invokes `binlog_close_connection' for clean closure.
Since the pending event still remains the assert is caused.
This assert is caused only in non transactional databases.


Fix:
===

In a disk full scenario when the insertion fails the
transaction is rolled back and `binlog_end_trans`
is called to flush the pending events. But flush operation
fails as the disk is full and the function simply returns
`1' without taking any action to delete the pending event.

This leaves the event to remain till the closure of
connection.  `delete pending' statement has been added to 
do the required clean up action.

sql/log.cc:
  Added "delete pending" statement to clean pending event
2012-09-17 11:48:02 +05:30
Sujatha Sivakumar
03993d03a7 Bug#13961678:MULTI-STATEMENT TRANSACTION REQUIRED MORE THAN
'MAX_BINLOG_CACHE_SIZE' ERROR
      
Problem:
=======
MySQL returns following error in win64.
"ERROR 1197 (HY000): Multi-statement transaction required more than
'max_binlog_cache_size' bytes of storage; increase this mysqld variable
and try again" when user tries to load >4G file even if
max_binlog_cache_size set to maximum value. On Linux everything
works fine.
      
Analysis:
========
The `max_binlog_cache_size' variable is of type `ulonglong'.  This
value is set to `ULONGLONG_MAX' at the time of server start up. The
above value is stored in an intermediate variable named
`saved_max_binlog_cache_size' which is of type `ulong'. In visual
c++ complier the `ulong' type is of 4bytes in size and hence the value
is getting truncated to '4GB' and the cache is not able to grow beyond
4GB size. The same limitation is observed with 
"max_binlog_stmt_cache_size" as well. Similar fix has been applied.
      
Fix:
===
As part of fix the type "ulong" is replaced with "my_off_t" which is of
type "ulonglong". 

mysys/mf_iocache.c:
  Added debug statement to simulate a scenario where the cache
  file's current position is set to >4GB
sql/log.cc:
  Replaced the type of `saved_max_binlog_cache_size' from "ulong" to
  "my_off_t", which is a type def for "ulonglong".
2012-07-24 16:26:16 +05:30
Sujatha Sivakumar
2e84cf8674 merge from 5.1 to 5.5 2012-07-10 14:37:35 +05:30
Sujatha Sivakumar
13f7f00288 BUG#11762670:MY_B_WRITE RETURN VALUE IGNORED
Problem:
=======
The return value from my_b_write is ignored by: `my_b_write_quoted',
`my_b_write_bit',`Query_log_event::print_query_header'

Most callers of `my_b_printf' ignore the return value. `log_event.cc' 
has many calls to it. 

Analysis:
========
`my_b_write' is used to write data into a file. If the write fails it
sets appropriate error number and error message through my_error()
function call and sets the IO_CACHE::error == -1.
`my_b_printf' function is also used to write data into a file, it
internally invokes my_b_write to do the write operation. Upon
success it returns number of characters written to file and on error
it returns -1 and sets the error through my_error() and also sets
IO_CACHE::error == -1.  Most of the event specific print functions
for example `Create_file_log_event::print', `Execute_load_log_event::print'
etc are the ones which make several calls to the above two functions and
they do not check for the return value after the 'print' call. All the above 
mentioned abuse cases deal with the client side.

Fix:
===
As part of bug fix a check for IO_CACHE::error == -1 has been added at 
a very high level after the call to the 'print' function.  There are 
few more places where the return value of "my_b_write" is ignored
those are mentioned below.

+++ mysys/mf_iocache2.c    2012-06-04 07:03:15 +0000
@@ -430,7 +430,8 @@
           memset(buffz, '0', minimum_width - length2);
         else
           memset(buffz, ' ', minimum_width - length2);
-        my_b_write(info, buffz, minimum_width - length2);

+++ sql/log.cc	2012-06-08 09:04:46 +0000
@@ -2388,7 +2388,12 @@
     {
       end= strxmov(buff, "# administrator command: ", NullS);
       buff_len= (ulong) (end - buff);
-      my_b_write(&log_file, (uchar*) buff, buff_len);

At these places appropriate return value handlers have been added.

client/mysqlbinlog.cc:
  check for IO_CACHE::error == -1 has been added after the call to
  the event specific print functions
mysys/mf_iocache2.c:
  Added handler to check the written value of `my_b_write'
sql/log.cc:
  Added handler to check the written value of `my_b_write'
sql/log_event.cc:
  Added error simulation statements in `Create_file_log_event::print`
  and `Execute_load_query_log_event::print'
sql/rpl_utility.h:
  Removed the extra ';'
2012-07-10 14:23:17 +05:30
Nuno Carvalho
367de4de2d BUG#14135691: MISSING INITIALIZATION OF MYSQL_BIN_LOG::SYNC_COUNTER
MYSQL_BIN_LOG::sync_counter is not initialized on MYSQL_BIN_LOG object
creation.

Added missing sync_counter initialization.
2012-05-30 14:55:13 +01:00
Luis Soares
549a5fa249 BUG#12400313
Manual merge from mysql-5.1 into mysql-5.5.

CONFLICTS
=========
  Text conflict in sql/log.cc
  Text conflict in sql/slave.cc
2012-03-12 22:02:50 +00:00
Luis Soares
4a6c4d8603 BUG#12400313 RELAY_LOG_SPACE_LIMIT IS NOT WORKING IN MANY CASES
BUG#64503: mysql frequently ignores --relay-log-space-limit

When the SQL thread goes to sleep, waiting for more events, it sets
the flag ignore_log_space_limit to true. This gives the IO thread a
chance to queue some more events and ultimately the SQL thread will be
able to purge the log once it is rotated. By then the SQL thread
resets the ignore_log_space_limit to false. However, between the time
the SQL thread has set the ignore flag and the time it resets it, the
IO thread will be queuing events in the relay log, possibly going way
over the limit.

This patch makes the IO and SQL thread to synchronize when they reach
the space limit and only ask for one event at a time. Thus the SQL
thread sets ignore_log_space_limit flag and the IO thread resets it to
false everytime it processes one more event. In addition, everytime
the SQL thread processes the next event, and the limit has been
reached, it checks if the IO thread should rotate. If it should, it
instructs the IO thread to rotate, giving the SQL thread a chance to
purge the logs (freeing space). Finally, this patch removes the
resetting of the ignore_log_space_limit flag from purge_first_log,
because this is now reset by the IO thread every time it processes the
next event when the limit has been reached.

If the SQL thread is in a transaction, it cannot purge so, there is no
point in asking the IO thread to rotate. The only thing it can do is
to ask for more events until the transaction is over (then it can ask
the IO to rotate and purge the log right away). Otherwise, there would
be a deadlock (SQL would not be able to purge and IO thread would not
be able to queue events so that the SQL would finish the transaction).
2012-03-12 12:28:27 +00:00
Tor Didriksen
98adda5095 Build broken for gcc 4.5.1 in optimized mode.
readline.cc: In function char* batch_readline(LINE_BUFFER*):
readline.cc:60:9: error: out_length may be used uninitialized in this function
log.cc: In function int find_uniq_filename(char*):
log.cc:1857:8: error: number may be used uninitialized in this function
2011-11-29 15:52:47 +01:00
Luis Soares
eec4836a1b BUG#11745230: 12133: MASTER.INDEX FILE KEEPS MYSQLD FROM STARTING IF
BIN LOG HAS BEEN MOVED 

When moving the binary/relay log files from one location to
another and restarting the server with a different log-bin or
relay-log paths, would cause the startup process to abort. The
root cause was that the server would not be able to find the log
files because it would consider old paths for entries in the
index file instead of the new location.  What's even worse, the
relative paths would not be considered relative to the path
provided in log-bin and relay-log, but to mysql_data_dir.
      
We fix the cases where the server contains relative paths. When
the server is reading from the index file, it checks whether the
entry contains relative paths. If it does, we replace it with the
absolute path set in log-bin/relay-log option. Absolute paths
remain unchanged and the index must be manually edited to
consider the new log-bin and/or relay-log path (this should be
documented). This is a fix for a GA version, that does not break
behavior (that much).
      
For development versions, we should go with Zhenxing's approach 
that removes paths altogether from index files.

mysql-test/include/begin_include_file.inc:
  Added parameter to keep the begin_include_file.inc silent. Useful when 
  including scripts that contain platform dependent parameters, for example:
  
  --let $rpl_server_parameters=--log-bin=$tmpdir/slave-bin --relay-log=$tmpdir/slave-relay-bin
  --let $keep_include_silent=1
  source include/rpl_start_server.inc;
  --let $keep_include_silent=0
  
  We want the paths ($tmpdir/slave-bin and $tmpdir/slave-relay-bin) not to be in the 
  result file.
mysql-test/suite/rpl/t/rpl_binlog_index.test:
  Test case.
sql/log.cc:
  When finding the corresponding log entry in the index file, we first 
  normalize the paths before doing the comparison. This will make relative
  paths to be turned into absolute paths (based on the opt_bin_logname or
  opt_relay_logname) and then compared against also, expanded paths entered, 
  through CHANGE MASTER for instance.
sql/log.h:
  Added normalize_binlog_name, which turns relative paths, into absolute paths
  given the parameter: is_relay_log ? opt_relay_logname : opt_bin_logname .
sql/mysqld.cc:
  Exposing opt_bin_logname.
sql/mysqld.h:
  Exposing opt_bin_logname.
2011-11-24 17:15:58 +00:00
Andrei Elkin
95fdeb89c2 Bug#11763573 - 56299: MUTEX DEADLOCK WITH COM_BINLOG_DUMP, BINLOG PURGE, AND PROCESSLIST/KILL
The bug case is similar to one fixed earlier bug_49536.
Deadlock involving LOCK_log appears to be possible because the purge running thread
is holding LOCK_log whereas there is no sense of doing that and which fact was
exploited by the earlier bug fixes.

Fixed with small reengineering of rotate_and_purge(), adding two new methods and
setting up a policy to execute those instead of the former
rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED).
The policy for using rotate(), purge() is that if the caller acquires LOCK_log itself,
it should call rotate(), release the mutex and run purge().

Side effect of this patch is refining error message of bug@11747416 to print
the whole path.



mysql-test/suite/rpl/r/rpl_cant_read_event_incident.result:
  the file name printing is changed to a relative path instead of just the file name.
mysql-test/suite/rpl/r/rpl_log_pos.result:
  the file name printing is changed to a relative path instead of just the file name.
mysql-test/suite/rpl/r/rpl_manual_change_index_file.result:
  the file name printing is changed to a relative path instead of just the file name.
mysql-test/suite/rpl/r/rpl_packet.result:
  the file name printing is changed to a relative path instead of just the file name.
mysql-test/suite/rpl/r/rpl_rotate_purge_deadlock.result:
  new result file is added.
mysql-test/suite/rpl/t/rpl_cant_read_event_incident.test:
  The test of that bug can't satisfy windows and unix backslash interpretation so windows
  execution is chosen to bypass.
mysql-test/suite/rpl/t/rpl_rotate_purge_deadlock-master.opt:
  new opt file is added.
mysql-test/suite/rpl/t/rpl_rotate_purge_deadlock.test:
  regression test is added as well as verification of a 
  possible side effect of the fixes is tried.
sql/log.cc:
  LOCK_log is never taken during execution of log purging routine.
  The former MYSQL_BIN_LOG::rotate_and_purge is made to necessarily 
  acquiring and releasing LOCK_log. 
  If caller takes the mutex itself it has to use a new rotate(), purge() 
  methods combination and to never let purge() be run with LOCK_log grabbed.
  
  
  
  split apart to allow
  the caller to chose either it
  Simulation of concurrently rotating/purging threads is added.
sql/log.h:
  new rotate(), purge() methods are added to be used instead of
  the former rotate_and_purge(RP_LOCK_LOG_IS_ALREADY_LOCKED).
  rotate_and_purge() signature is changed. Caller should not call rotate_and_purge()
  but rather {rotate(), purge()} if LOCK_log is acquired by it.
sql/rpl_injector.cc:
  changes to reflect the new rotate_and_purge() signature.
sql/sql_class.h:
  unnecessary constants are removed.
sql/sql_parse.cc:
  changes to reflect the new rotate_and_purge() signature.
sql/sql_reload.cc:
  changes to reflect the new rotate_and_purge() signature.
sql/sql_repl.cc:
  followup for bug@11747416: the file name printing is changed to a relative 
  path instead of just the file name.
2011-10-27 17:14:41 +03:00
Mats Kindahl
cf5e5f837a Merging into mysql-5.5.16-release. 2011-08-15 20:12:11 +02:00
Sven Sandberg
add86aaddc Merged BUG#12574820 from 5.1 to 5.5
Two conflicts resolved manually:
Text conflict in sql/log.cc
Text conflict in sql/mysqld.cc
2011-05-26 12:56:17 +02:00
Sven Sandberg
de3776819c BUG#12574820: binlog.binlog_tmp_table timing out in daily and weekly trunk run
Problem: MYSQL_BIN_LOG::reset_logs acquires mutexes in wrong order.
The correct order is first LOCK_thread_count and then LOCK_log. This function
does it the other way around. This leads to deadlock when run in parallel
with a thread that takes the two locks in correct order. For example, a thread
that disconnects will take the locks in the correct order.
Fix: change order of the locks in MYSQL_BIN_LOG::reset_logs:
first LOCK_thread_count and then LOCK_log.


mysql-test/suite/binlog/r/binlog_reset_master.result:
  added result file
mysql-test/suite/binlog/t/binlog_reset_master.test:
  Added test case that demonstrates deadlock because of wrong mutex order.
  The deadlock is between two threads:
   - RESET MASTER acquires mutexes in wrong order.
   - client thread shutdown code acquires mutexes in right order.
  Actually, this test case does not produce deadlock in 5.1, probably
  the client thread shutdown code does not hold both mutexes at the same
  time. However, the bug existed in 5.1 (mutexes are taken in the wrong
  order) so we push the test case to 5.1 too, to prevent future
  regressions.
sql/log.cc:
  Change mutex acquisition to the correct order:
  first LOCK_thread_count, then LOCK_log.
sql/mysqld.cc:
  Add debug code to synchronize test case.
2011-05-26 12:50:43 +02:00
Mikael Ronström
a537c106f0 merge 2011-05-12 20:35:31 +02:00
Jon Olav Hauglid
e9b8feef32 Bug#12346411 SQL/LOG.CC:6509: ASSERTION `PREPARED_XIDS > 0' FAILED
This assert could be triggered during two phase commit if binary
log was used as transaction coordinator log. The triggered assert
checks that the same number of transaction IDs are processed in
the prepare and commit phases.

The reason it was triggered, was that the transaction consisted
of an INSERT/UPDATE IGNORE that had an ignorable error. Since it
had an error, no row log events were made and therefore
prepared_xids was 0. However, since it was an IGNORE statement,
the statement started a read/write statement transaction, committed
it and completed successfully.

This patch fixes the problem by adjusting the assert to take
this possibility into account.

Test case added to binlog.binlog_innodb_row.test.
2011-05-12 14:56:00 +02:00
Mikael Ronström
70ed67e1cc Merge 5.5 2011-04-15 15:46:11 +02:00
Marc Alff
5ee9001844 Bug#11766528 PERFORMANCE_SCHEMA TRACKS BOTH BINARY AND RELAY LOGS IN THE SAME EVENTS
Before this fix, all the performance schema instrumentation for both the binary log
and the relay log would use the following instruments:
- wait/io/file/sql/binlog
- wait/io/file/sql/binlog_index
- wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_index
- wait/synch/cond/sql/MYSQL_BIN_LOG::update_cond

This instrumentation is too general and can be more specific.

With this fix, the binlog instrumentation is identical,
and the relay log instrumentation is changed to:
- wait/io/file/sql/relaylog
- wait/io/file/sql/relaylog_index
- wait/synch/mutex/sql/MYSQL_RELAY_LOG::LOCK_index
- wait/synch/cond/sql/MYSQL_RELAY_LOG::update_cond

With this change, the performance instrumentation for the binary log and the relay log,
which share the same structure but have different uses, is more detailed.
This is especially important for hosts in the middle of a replication chain,
that are both masters (binlog) and slaves (relaylog).
2011-03-01 17:39:28 +01:00
Mikael Ronström
e3f89e5dba merge 2011-02-10 18:15:19 +01:00
Karen Langford
de3c4428b8 Updating header copyright/README in source for 2011 2011-01-25 15:42:40 +01:00
Mikael Ronstrom
14a46479b6 BUG#59549, fix compiler error on Windows 2011-01-17 13:25:31 +01:00
Georgi Kodinov
4e523ad68d weave merge from mysql-5.1 to mysql-5.5
Resolved an innodb conflict thanks to vasil.
2011-02-08 17:47:33 +02:00
Davi Arnaut
d4ffbd3ee0 Merge of mysql-5.1 into mysql-5.5. 2011-01-07 17:30:52 -02:00
Davi Arnaut
998065c3a6 Bug#51023: Mysql server crashes on SIGHUP and destroys InnoDB files
From a user perspective, the problem is that a FLUSH LOGS or SIGHUP
signal could end up associating the stdout and stderr to random
files. In the case of this bug report, the streams would end up
associated to InnoDB ibd files.

The freopen(3) function is not thread-safe on FreeBSD. What this
means is that if another thread calls open(2) during freopen()
is executing that another thread's fd returned by open(2) may get
re-associated with the file being passed to freopen(3). See FreeBSD
PR number 79887 for reference:

  http://www.freebsd.org/cgi/query-pr.cgi?pr=79887

This problem is worked around by substituting a internal hook within
the FILE structure. This avoids the loss of atomicity by not having
the original fd closed before its duplicated.

Patch based on the original work by Vasil Dimov.

include/my_sys.h:
  Export my_freopen.
mysys/my_fopen.c:
  Add a my_freopen abstraction to workaround bugs in specific OSes.
  Add a prototype for getosreldate() as older FreeBSD versions did
  not define one.
sql/log.cc:
  Move freopen abstraction code over to mysys.
  The streams are now only reopened for writing.
2011-01-07 16:33:36 -02:00
Luis Soares
246b4be056 BUG#46166
Automerge from mysql-5.1-bugteam.
2010-12-17 01:29:53 +00:00
Luis Soares
4c0c552582 BUG#46166
Post-push fixes:

  - fixed platform dependent result files
  - appeasing valgrind warnings:
   
    Fault injection was also uncovering a previously existing 
    potential mem leaks. For BUG#46166 testing purposes, fixed 
    by forcing handling the leak when injecting faults.
2010-12-17 01:17:03 +00:00
Luis Soares
b0e77d62f3 BUG#46166
Merging to latest mysql-5.5-bugteam.
2010-12-16 19:12:31 +00:00
Davi Arnaut
4ccb32c09a Bug#58953: 5.5 does not build with -DWITHOUT_PERFSCHEMA_STORAGE_ENGINE=1
The MYSQL_LOG::open member function does not take a PSI
key file argument when the PSI interface is not present.
2010-12-15 20:38:43 -02:00
Luis Soares
16b2ca1f65 BUG#46166
Post merge fixes for mysql-5.5-bugteam.
2010-12-07 16:55:25 +00:00
Luis Soares
26ee8f532e BUG#46166
Manual merge from mysql-5.1-bugteam into mysql-5.5-bugteam.

Conflicts
=========

Text conflict in sql/log.cc
Text conflict in sql/log.h
Text conflict in sql/slave.cc
Text conflict in sql/sql_parse.cc
Text conflict in sql/sql_priv.h
2010-12-07 16:11:13 +00:00
Luis Soares
ffc16a2d06 BUG#46166
Post merge fix. In write_incident, check if binlog file is
opened before actually trying to write the incident event.
2010-12-07 15:48:18 +00:00
Alfranio Correia
b28d2c25a7 merge mysql-5.5-bugteam(local) --> mysql-5.5-bugteam 2010-12-03 01:06:56 +00:00
Luis Soares
647c619393 BUG#46166: MYSQL_BIN_LOG::new_file_impl is not propagating error
when generating new name.
      
If find_uniq_filename returns an error, then this error is not
being propagated upwards, and execution does not report error to
the user (although a entry in the error log is generated).
                  
Additionally, some more errors were ignored in new_file_impl:
- when writing the rotate event
- when reopening the index and binary log file
                  
This patch addresses this by propagating the error up in the
execution stack. Furthermore, when rotation of the binary log
fails, an incident event is written, because there may be a
chance that some changes for a given statement, were not properly
logged. For example, in SBR, LOAD DATA INFILE statement requires
more than one event to be logged, should rotation fail while
logging part of the LOAD DATA events, then the logged data would
become inconsistent with the data in the storage engine.

mysql-test/include/restart_mysqld.inc:
  Refactored restart_mysqld so that it is not hardcoded for
  mysqld.1, but rather for the current server.
mysql-test/suite/binlog/t/binlog_index.test:
  The error on open of index and binary log on new_file_impl 
  is now caught. Thence the user will get an error message. 
  We need to accomodate this change in the test case for the
  failing FLUSH LOGS.
mysql-test/suite/rpl/t/rpl_binlog_errors-master.opt:
  Sets max_binlog_size to 4096.
mysql-test/suite/rpl/t/rpl_binlog_errors.test:
  Added some test cases for asserting that the error is found 
  and reported.
sql/handler.cc:
  Catching error now returned by unlog (in ha_commit_trans) and 
  returning it.
sql/log.cc:
  Propagating errors from new_file_impl upwards. The errors that
  new_file_impl catches now are:
  - error on generate_new_name
  - error on writing the rotate event
  - error when opening the index or the binary log file.
sql/log.h:
  Changing declaration of:
  - rotate_and_purge
  - new_file
  - new_file_without_locking
  - new_file_impl
  - unlog
  They now return int instead of void.
sql/mysql_priv.h:
  Change signature of reload_acl_and_cache so that write_to_binlog
  is an int instead of bool.
sql/mysqld.cc:
  Redeclaring not_used var as int instead of bool.
sql/rpl_injector.cc:
  Changes to catch the return from rotate_and_purge.
sql/slave.cc:
  Changes to catch the return values for new_file and rotate_relay_log.
sql/slave.h:
  Changes to rotate_relay_log declaration (now returns int 
  instead of void).
sql/sql_load.cc:
  In SBR, some logging of LOAD DATA events goes through
  IO_CACHE_CALLBACK invocation at mf_iocache.c:_my_b_get. The
  IO_CACHE implementation is ignoring the return value for from
  these callbacks (pre_read and post_read), so we need to find out
  at the end of the execution if the error is set or not in THD.
sql/sql_parse.cc:
  Catching the rotate_relay_log and rotate_and_purge return values.
  Semantic change in reload_acl_and_cache so that we report errors
  in binlog interactions through the write_to_binlog output parameter.
  If there was any failure while rotating the binary log, we should
  then report the error to the client when handling SQLCOMM_FLUSH.
2010-11-30 23:32:51 +00:00
Luis Soares
a542943c91 BUG 57288: automerged mysql-5.1-bugteam into mysql-5.5-bugteam. 2010-11-30 18:17:06 +00:00
Luis Soares
b009422734 BUG#57288: binlog_tmp_table fails sporadically: "Failed to write
the DROP statement ..."
      
Problem: When using temporary tables and closing a session, an
implicit DROP TEMPORARY TABLE IF EXISTS is written to the binary
log (while cleaning up the context of the session THD - see:
sql_class.cc:THD::cleanup which calls close_temporary_tables).
     
close_temporary_tables, first checks if the binary log is opened
and then proceeds to creating the DROP statements. Then, such
statements, are written to the binary log through
MYSQL_BIN_LOG::write(Log_event *). Inside, there is another check
if the binary log is opened and if not an error is returned. This
is where the faulty behavior is triggered. Given that the test
case replays a binary log, with temp tables statements, and right
after it issues RESET MASTER, there is a chance that is_open will
report false (when the mysql session is closed and the temporary
tables are written).
      
is_open may return false, because MYSQL_BIN_LOG::reset_logs is
not setting the correct flag (LOG_CLOSE_TO_BE_OPENED), on the
MYSQL_LOG_BIN::log_state (instead it sets just the
LOG_CLOSE_INDEX flag, leaving the log_state to
LOG_CLOSED). Thence, when writing the DROP statement as part of
the THD::cleanup, the thread could get a return value of false
for is_open - inside MYSQL_BIN_LOG::write, ultimately reporting
that it can't write the event to the binary log.
      
Fix: We fix this by adding the correct flag, missing in the
second close.
2010-11-30 16:55:28 +00:00
Marc Alff
41dc34d60b Bug#58052 Binary log IO not being accounted for properly
Before this fix, file io for the binary log file was not accounted properly,
and showed no io at all.

This bug was due to the following issues:

1) file io for the binlog was instrumented:
- sometime as "wait/io/file/sql/binlog"
- sometime as "wait/io/file/sql/MYSQL_LOG"
leading to inconsistent event_names.

2) the binlog file itself was using an IO_CACHE,
but the IO_CACHE implementation in mysys/mf_iocache.c was
not instrumented to make performance schema calls to record file io.

3) The "wait/io/file/sql/MYSQL_LOG" instrumentation was used
for several log files, such as:
- the binary log
- the slow log
- the query log
which caused file io in these different log files to be accounted
against the same instrument.
The instrumentation needs to have a finer grain and report io
in different event_names, because each file really serves a different purpose.

With this fix:
- the IO_CACHE implementation is now instrumented
- the "wait/io/file/sql/MYSQL_LOG" instrument has been removed
- binlog io is now always instrumented with "wait/io/file/sql/binlog"
- the slow log is instrumented with a new name, "wait/io/file/sql/slow_log"
- the query log is instrumented with a new name, "wait/io/file/sql/query_log"
2010-11-12 07:23:26 +01:00
Alfranio Correia
3f5a9c7ea0 BUG#57275 binlog_cache_size affects trx- and stmt-cache and gets twice the expected memory
After the WL#2687, the binlog_cache_size and max_binlog_cache_size affect both the
stmt-cache and the trx-cache. This means that the resource used is twice the amount
expected/defined by the user.
      
The binlog_cache_use is incremented when the stmt-cache or the trx-cache is used
and binlog_cache_disk_use is incremented when the disk space from the stmt-cache or the
trx-cache is used. This behavior does not allow to distinguish which cache may be harming
performance due to the extra disk accesses and needs to have its in-memory cache
increased.
      
To fix the problem, we introduced two new options and status variables related to the
stmt-cache:
      
  Options:
      
    . binlog_stmt_cache_size
    . max_binlog_stmt_cache_size
      
    Status Variables:
      
    . binlog_stmt_cache_use
    . binlog_stmt_cache_disk_use

So there are

  . binlog_cache_size that defines the size of the transactional cache for
  updates to transactional engines for the binary log.

  . binlog_stmt_cache_size that defines the size of the statement cache for
  updates to non-transactional engines for the binary log.

  . max_binlog_cache_size that sets the total size of the transactional
  cache.

  . max_binlog_stmt_cache_size that sets the total size of the statement
  cache.

  . binlog_cache_use that identifies the number of transactions that used the
  temporary transactional binary log cache.

  . binlog_cache_disk_use that identifies the number of transactions that used
  the temporary transactional binary log cache but that exceeded the value of
  binlog_cache_size.

  . binlog_stmt_cache_use that identifies the number of statements that used the
  temporary non-transactional binary log cache.

  . binlog_stmt_cache_disk_use that identifies the number of statements that used
  the temporary non-transactional binary log cache but that exceeded the value of
  binlog_stmt_cache_size.

include/my_sys.h:
  Updated message on disk_writes' usage.
mysql-test/extra/binlog_tests/binlog_cache_stat.test:
  Updated the test case and added code to check the new status variables
  binlog_stmt_cache_use and binlog_stmt_cache_disk_use.
mysql-test/extra/rpl_tests/rpl_binlog_max_cache_size.test:
  Updated the test case to use the new system variables max_binlog_stmt_cache_size and binlog_stmt_cache_size.
mysql-test/r/mysqld--help-notwin.result:
  Updated the result file.
mysql-test/suite/binlog/r/binlog_mixed_cache_stat.result:
  Updated the result file.
mysql-test/suite/binlog/r/binlog_row_cache_stat.result:
  Updated the result file.
mysql-test/suite/binlog/r/binlog_stm_cache_stat.result:
  Updated the result file.
mysql-test/suite/rpl/r/rpl_mixed_binlog_max_cache_size.result:
  Update the result file.
mysql-test/suite/rpl/r/rpl_row_binlog_max_cache_size.result:
  Update the result file.
mysql-test/suite/rpl/r/rpl_stm_binlog_max_cache_size.result:
  Updated the result file.
mysql-test/suite/sys_vars/inc/binlog_stmt_cache_size_basic.inc:
  Added a test case to check the binlog_stmt_cache_size.
mysql-test/suite/sys_vars/r/binlog_stmt_cache_size_basic_32.result:
  Updated the result file.
mysql-test/suite/sys_vars/r/binlog_stmt_cache_size_basic_64.result:
  Updated the result file.
mysql-test/suite/sys_vars/r/max_binlog_stmt_cache_size_basic.result:
  Updated the result file.
mysql-test/suite/sys_vars/t/binlog_stmt_cache_size_basic_32.test:
  Added a test case to check the binlog_stmt_cache_size.
mysql-test/suite/sys_vars/t/binlog_stmt_cache_size_basic_64.test:
  Added a test case to check the binlog_stmt_cache_size.
mysql-test/suite/sys_vars/t/max_binlog_cache_size_func-master.opt:
  Removed because there is no test case max_binlog_cache_size_func.
mysql-test/suite/sys_vars/t/max_binlog_stmt_cache_size_basic.test:
  Added a test case to check the system variable max_binlog_stmt_cache_size.
sql/log.cc:
  There two main changes in here:
  
    . Changed the set_write_error() as an error message is set according
    to the type of the cache.
  
    . Created the function set_binlog_cache_info where references to the
    appropriate status and system variables are set and the server can
    smoothly compute statistics and set the maximum size for each cache.
sql/log.h:
  Changed the signature of the function in order to identify the error message
  to be printed out as there is a different error code for each type of cache.
sql/mysqld.cc:
  Added new status variables binlog_stmt_cache_use and binlog_stmt_cache_disk_use.
sql/mysqld.h:
  Added new system variables max_binlog_stmt_cache_size and binlog_stmt_cache_size.
sql/share/errmsg-utf8.txt:
  Added new error message related to the statement cache.
sql/sys_vars.cc:
  Added new system variables max_binlog_stmt_cache_size and binlog_stmt_cache_size.
2010-11-05 17:42:37 +00:00
Alfranio Correia
2d84c1553c BUG#56343 binlog_cache_use status is bigger than expected
The binlog_cache_use is incremented twice when changes to a transactional table
are committed, i.e. TC_LOG_BINLOG::log_xid calls is called. The problem happens
because log_xid calls both binlog_flush_stmt_cache and binlog_flush_trx_cache
without checking if such caches are empty thus unintentionally increasing the
binlog_cache_use value twice.

Although not explicitly mentioned in the bug, the binlog_cache_disk_use presents
the same problem.

The binlog_cache_use and binlog_cache_disk_use are status variables that are
incremented when transactional (i.e. trx-cache) or non-transactional (i.e.
stmt-cache) changes are committed. They are used to compute the ratio between
the use of disk and memory while gathering updates for a transaction.

The problem reported is fixed by avoiding incrementing the binlog_cache_use
and binlog_cache_disk_use if a cache is empty. We also have decided to increment
both variables when a cache is truncated as the cache is used although its
content is discarded and is not written to the binary log.

In this patch, we take the opportunity to re-organize the code around the
function binlog_flush_trx_cache and binlog_flush_stmt_cache.

mysql-test/extra/binlog_tests/binlog_cache_stat.test:
  Updated the test case with comments and additional tests to check both
  transactional and non-transactional changes and what happens when a 
  is transaction either committed or aborted.
mysql-test/suite/binlog/r/binlog_innodb.result:
  Updated the result file.
mysql-test/suite/binlog/r/binlog_mixed_cache_stat.result:
  Updated the result file.
mysql-test/suite/binlog/r/binlog_row_cache_stat.result:
  Updated the result file.
mysql-test/suite/binlog/r/binlog_stm_cache_stat.result:
  Updated the result file.
mysql-test/suite/binlog/t/binlog_mixed_cache_stat.test:
  Updated the test case with a new source file.
mysql-test/suite/binlog/t/binlog_row_cache_stat.test:
  Updated the test case with a new source file.
mysql-test/suite/binlog/t/binlog_stm_cache_stat.test:
  Updated the test case with a new source file.
sql/log.cc:
  There are four changes in here:
  
    . Computed statistics on binlog_cache_use and binlog_cache_disk_use while
    resting the cache.
  
    . Refactored the code so binlog_flush_cache handles both the trx-cache and
    stmt-cache.
  
    . There are functions that encapsulate the calls to binlog_flush_cache and
    make easier to read the code.
  
    . binlog_commit_flush_stmt_cache is now taking into account the result:
    success or error.
sql/log_event.h:
  Guaranteed Xid_log_event is always classified as a transactional event.
2010-11-05 13:58:05 +00:00
Davi Arnaut
6997cff459 Merge of mysql-5.1-bugteam into mysql-5.5-bugteam. 2010-10-20 17:02:59 -02:00
Davi Arnaut
3e9c52250a Bug#45288: pb2 returns a lot of compilation warnings
Fix assorted warnings that are generated in optimized builds.
Most of it is silencing variables that are set but unused.

This patch also introduces the MY_ASSERT_UNREACHABLE macro
which helps the compiler to deduce that a certain piece of
code is unreachable.

include/my_compiler.h:
  Use GCC's __builtin_unreachable if available. It allows
  GCC to deduce the unreachability of certain code paths,
  thus avoiding warnings that, for example, accused that a
  variable could be used without being initialized (due to
  unreachable code paths).
2010-10-20 16:21:40 -02:00
Tor Didriksen
f0e2d8ecd8 Bug#52172 test binlog.binlog_index needs --skip-core-file to avoid leaving core files
For crash testing: kill the server without generating core file.

include/my_dbug.h
  Use kill(getpid(), SIGKILL) which cannot be caught by signal handlers.
  All DBUG_XXX macros should be no-ops in optimized mode, do that for DBUG_ABORT as well.
sql/handler.cc
  Kill server without generating core.
sql/log.cc
  Kill server without generating core.
2010-10-18 13:27:52 +02:00
Tor Didriksen
9074307102 Bug#52172 test binlog.binlog_index needs --skip-core-file to avoid leaving core files
For crash testing: kill the server without generating core file.

include/my_dbug.h
  Use kill(getpid(), SIGKILL) which cannot be caught by signal handlers.
  All DBUG_XXX macros should be no-ops in optimized mode, do that for DBUG_ABORT as well.
sql/handler.cc
  Kill server without generating core.
sql/log.cc
  Kill server without generating core.
2010-10-18 13:24:34 +02:00
Alfranio Correia
8504580ced BUG#56343 binlog_cache_use status is bigger than expected
The binlog_cache_use is incremented twice when changes to a transactional table
are committed, i.e. TC_LOG_BINLOG::log_xid calls is called. The problem happens
because log_xid calls both binlog_flush_stmt_cache and binlog_flush_trx_cache
without checking if such caches are empty thus unintentionally increasing the
binlog_cache_use value twice.

To fix the problem we avoided incrementing the binlog_cache_use if the cache is
empty. We also decided to increment binlog_cache_use when the cache is truncated
as the cache is used although its content is discarded and is not written to the
binary log.

Note that binlog_cache_use is incremented for both types of cache, transactional
and non-transactional and that the behavior presented in this patch also applies
to the binlog_cache_disk_use.

Finally, we re-organized the code around the functions binlog_flush_trx_cache and
binlog_flush_stmt_cache.

mysql-test/extra/binlog_tests/binlog_cache_stat.test:
  Updated the test case with comments and additional tests to check both
  transactional and non-transactional changes and what happens when a 
  is transaction either committed or aborted.
mysql-test/suite/binlog/r/binlog_innodb.result:
  Updated the result file.
mysql-test/suite/binlog/r/binlog_mixed_cache_stat.result:
  Updated the result file.
mysql-test/suite/binlog/r/binlog_row_cache_stat.result:
  Updated the result file.
mysql-test/suite/binlog/r/binlog_stm_cache_stat.result:
  Updated the result file.
mysql-test/suite/binlog/t/binlog_mixed_cache_stat.test:
  Updated the test case with a new source file.
mysql-test/suite/binlog/t/binlog_row_cache_stat.test:
  Updated the test case with a new source file.
mysql-test/suite/binlog/t/binlog_stm_cache_stat.test:
  Updated the test case with a new source file.
sql/log_event.cc:
  Introduced debug information to check if Query_log_event("BEGIN"),
  Query_log_event("COMMIT") and Query_log_event("ROLLBACK").
sql/log_event.h:
  Guaranteed Xid_log_event is always classified as a transactional event.
2010-10-06 09:34:49 +01:00
Alexander Nozdrin
94e726ae3d Auto-merge from mysql-5.5-merge. 2010-09-28 19:15:58 +04:00