When we rotate the binlog, we first close the old log file, which marks the
file as "not crashed". We then create the new log file, and last add it to the
binlog index file.
Suppose we crash after closing the old file but before the new file is added
to the index. And suppose further than at least one transaction had time to
enter the "prepared inside InnoDB" status before we crashed.
Then on next server restart, the binlog code will not realise that we crashed,
as the last file in the binlog index is closed properly. And ha_recover in
handler.cc will fail the startup due to finding a prepared innodb transaction
in a no-crash scenario:
120615 14:41:02 [ERROR] Found 1 prepared transactions! It means that mysqld was not shut down properly last time and critical recovery information (last binlog or tc.log file) was manually deleted after a crash. You have to start mysqld with --tc-heuristic-recover switch to commit or rollback pending transactions.
To reproduce, apply following patch (to get needed debug_sync points) and run
attached test case.