• Alfranio Correia's avatar
    BUG#45292 orphan binary log created when starting server twice · a4c50983
    Alfranio Correia authored
    This patch fixes three bugs as follows. First, aborting the server while purging
    binary logs might generate orphan files due to how the purge operation was
    implemented:
    
              (purge routine - sql/log.cc - MYSQL_BIN_LOG::purge_logs)
    
          1 - register the files to be removed in a temporary buffer.
          2 - update the log-bin.index.
          3 - flush the log-bin.index.
          4 - erase the files whose names where register in the temporary buffer
          in step 1.
    
    Thus a failure while  executing step 4 would generate an orphan file. Second,
    a similar issue might happen while creating a new binary as follows:
    
              (create routine - sql/log.cc - MYSQL_BIN_LOG::open)
    
          1 - open the new log-bin.
          2 - update the log-bin.index.
    
    Thus a failure while executing step 1 would generate an orphan file.
    
    To fix these issues, we record the files to be purged or created before really
    removing or adding them. So if a failure happens such records can be used to
    automatically remove dangling files. The new steps might be outlined as follows:
    
              (purge routine - sql/log.cc - MYSQL_BIN_LOG::purge_logs)
    
          1 - register the files to be removed in the log-bin.~rec~ placed in
          the data directory.
          2 - update the log-bin.index.
          3 - flush the log-bin.index.
          4 - delete the log-bin.~rec~.
    
              (create routine - sql/log.cc - MYSQL_BIN_LOG::open)
    
          1 - register the file to be created in the log-bin.~rec~
          placed in the data directory.
          2 - open the new log-bin.
          3 - update the log-bin.index.
          4 - delete the log-bin.~rec~.
    
              (recovery routine - sql/log.cc - MYSQL_BIN_LOG::open_index_file)
    
          1 - open the log-bin.index.
          2 - open the log-bin.~rec~.
          3 - for each file in log-bin.~rec~.
            3.1 Check if the file is in the log-bin.index and if so ignore it.
            3.2 Otherwise, delete it.
    
    The third issue can be described as follows. The purge operation was allowing
    to remove a file in use thus leading to the loss of data and possible
    inconsistencies between the master and slave. Roughly, the routine was only
    taking into account the dump threads and so if a slave was not connect the
    file might be delete even though it was in use.
    a4c50983
binlog_index.result 4.46 KB