From cdb2208cd64d1ad4e6a902ab84591c4f3fff0f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 19 Mar 2019 11:09:53 +0200 Subject: [PATCH] MDEV-18966 Transaction recovery may be broken after upgrade to 10.3 This bug was introduced by MDEV-12288, which made InnoDB use a single undo log for persistent transactions, instead of maintaining separate insert_undo and update_undo logs. trx_undo_reuse_cached(): Initialize the TRX_UNDO_PAGE_TYPE after reusing a cached undo log page for undo log. Failure to do so can cause trx_undo_mem_create_at_db_start() to misclassify new undo log records as TRX_UNDO_INSERT. This in turn would trigger an assertion failure in trx_roll_pop_top_rec_of_trx() due to undo==insert. --- storage/innobase/trx/trx0undo.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/storage/innobase/trx/trx0undo.cc b/storage/innobase/trx/trx0undo.cc index 61ba65ebc1980..354d3c8d848c9 100644 --- a/storage/innobase/trx/trx0undo.cc +++ b/storage/innobase/trx/trx0undo.cc @@ -1352,6 +1352,15 @@ trx_undo_reuse_cached(trx_t* trx, trx_rseg_t* rseg, trx_undo_t** pundo, *pundo = undo; ulint offset = trx_undo_header_create(block->frame, trx->id, mtr); + /* Reset the TRX_UNDO_PAGE_TYPE in case this page is being + repurposed after upgrading to MariaDB 10.3. */ + if (ut_d(ulint type =) UNIV_UNLIKELY( + mach_read_from_2(TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_TYPE + + block->frame))) { + ut_ad(type == TRX_UNDO_INSERT || type == TRX_UNDO_UPDATE); + mlog_write_ulint(TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_TYPE + + block->frame, 0, MLOG_2BYTES, mtr); + } trx_undo_header_add_space_for_xid(block->frame, block->frame + offset, mtr);