• Marko Mäkelä's avatar
    MDEV-15132 Avoid accessing the TRX_SYS page · c7d04487
    Marko Mäkelä authored
    InnoDB maintains an internal persistent sequence of transaction
    identifiers. This sequence is used for assigning both transaction
    start identifiers (DB_TRX_ID=trx->id) and end identifiers (trx->no)
    as well as end identifiers for the mysql.transaction_registry table
    that was introduced in MDEV-12894.
    
    TRX_SYS_TRX_ID_WRITE_MARGIN: Remove. After this many updates of
    the sequence we used to update the TRX_SYS page. We can avoid accessing
    the TRX_SYS page if we modify the InnoDB startup so that resurrecting
    the sequence from other pages of the transaction system.
    
    TRX_SYS_TRX_ID_STORE: Deprecate. The field only exists for the purpose
    of upgrading from an earlier version of MySQL or MariaDB.
    
    Starting with this fix, MariaDB will rely on the fields
    TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO in the undo log header page of
    each non-committed transaction, and on the new field
    TRX_RSEG_MAX_TRX_ID in rollback segment header pages.
    
    Because of this change, setting innodb_force_recovery=5 or 6 may cause
    the system to recover with trx_sys.get_max_trx_id()==0. We must adjust
    checks for invalid DB_TRX_ID and PAGE_MAX_TRX_ID accordingly.
    
    We will change the startup and shutdown messages to display the
    trx_sys.get_max_trx_id() in addition to the log sequence number.
    
    trx_sys_t::flush_max_trx_id(): Remove.
    
    trx_undo_mem_create_at_db_start(), trx_undo_lists_init():
    Add an output parameter max_trx_id, to be updated from
    TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO.
    
    TRX_RSEG_MAX_TRX_ID: New field, for persisting
    trx_sys.get_max_trx_id() at the time of the latest transaction commit.
    Startup is not reading the undo log pages of committed transactions.
    We want to avoid additional page accesses on startup, as well as
    trouble when all undo logs have been emptied.
    On startup, we will simply determine the maximum value from all pages
    that are being read anyway.
    
    TRX_RSEG_FORMAT: Redefined from TRX_RSEG_MAX_SIZE.
    
    Old versions of InnoDB wrote uninitialized garbage to unused data fields.
    Because of this, we cannot simply introduce a new field in the
    rollback segment pages and expect it to be always zero, like it would
    if the database was created by a recent enough InnoDB version.
    
    Luckily, it looks like the field TRX_RSEG_MAX_SIZE was always written
    as 0xfffffffe. We will indicate a new subformat of the page by writing
    0 to this field. This has the nice side effect that after a downgrade
    to older versions of InnoDB, transactions should fail to allocate any
    undo log, that is, writes will be blocked. So, there is no problem of
    getting corrupted transaction identifiers after downgrading.
    
    trx_rseg_t::max_size: Remove.
    
    trx_rseg_header_create(): Remove the parameter max_size=ULINT_MAX.
    
    trx_purge_add_undo_to_history(): Update TRX_RSEG_MAX_SIZE
    (and TRX_RSEG_FORMAT if needed). This is invoked on transaction commit.
    
    trx_rseg_mem_restore(): If TRX_RSEG_FORMAT contains 0,
    read TRX_RSEG_MAX_SIZE.
    
    trx_rseg_array_init(): Invoke trx_sys.init_max_trx_id(max_trx_id + 1)
    where max_trx_id was the maximum that was encountered in the rollback
    segment pages and the undo log pages of recovered active, XA PREPARE,
    or some committed transactions. (See trx_purge_add_undo_to_history()
    which invokes trx_rsegf_set_nth_undo(..., FIL_NULL, ...);
    not all committed transactions will be immediately detached from the
    rollback segment header.)
    c7d04487
trx0sys.h 28.5 KB