Skip to content

Commit 6636050

Browse files
committed
MDEV-16168: Resurrect the record MLOG_UNDO_INIT
While the record type MLOG_UNDO_INIT feels redundant, it does save redo log volume, and subtle changes to redo log volume appear to make a big difference for the log_sys.mutex contention. trx_undo_parse_page_init(): Allow type==0, which is what we write since MDEV-12288. Parse type in a simpler way; it always was written as a single byte. trx_undo_page_init(): Write a MLOG_UNDO_INIT record.
1 parent a639eff commit 6636050

File tree

3 files changed

+46
-38
lines changed

3 files changed

+46
-38
lines changed

storage/innobase/include/mtr0types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ enum mlog_id_t {
106106
/** erase an undo log page end (used in MariaDB 10.2) */
107107
MLOG_UNDO_ERASE_END = 21,
108108

109-
/** initialize a page in an undo log (used in MariaDB 10.2) */
109+
/** initialize a page in an undo log */
110110
MLOG_UNDO_INIT = 22,
111111

112112
/** reuse an insert undo log header (used in MariaDB 10.2) */

storage/innobase/include/trx0undo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ bool
272272
trx_undo_truncate_tablespace(
273273
undo::Truncate* undo_trunc);
274274

275-
/** Parse MLOG_UNDO_INIT for crash-upgrade from MariaDB 10.2.
275+
/** Parse MLOG_UNDO_INIT.
276276
@param[in] ptr log record
277277
@param[in] end_ptr end of log record buffer
278278
@param[in,out] page page or NULL

storage/innobase/trx/trx0undo.cc

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,6 @@ of the list and release undo log segments. In stepping through the list,
9696
s-latches on the undo log pages are enough, but in a truncate, x-latches must
9797
be obtained on the rollback segment and individual pages. */
9898

99-
/********************************************************************//**
100-
Initializes the fields in an undo log segment page. */
101-
static
102-
void
103-
trx_undo_page_init(
104-
/*===============*/
105-
page_t* undo_page,/*!< in: undo log segment page */
106-
mtr_t* mtr);/*!< in: mtr */
107-
10899
/********************************************************************//**
109100
Creates and initializes an undo log memory object.
110101
@return own: the undo log memory object */
@@ -384,7 +375,7 @@ trx_undo_get_first_rec(
384375

385376
/*============== UNDO LOG FILE COPY CREATION AND FREEING ==================*/
386377

387-
/** Parse MLOG_UNDO_INIT for crash-upgrade from MariaDB 10.2.
378+
/** Parse MLOG_UNDO_INIT.
388379
@param[in] ptr log record
389380
@param[in] end_ptr end of log record buffer
390381
@param[in,out] page page or NULL
@@ -393,12 +384,19 @@ trx_undo_get_first_rec(
393384
byte*
394385
trx_undo_parse_page_init(const byte* ptr, const byte* end_ptr, page_t* page)
395386
{
396-
ulint type = mach_parse_compressed(&ptr, end_ptr);
387+
if (end_ptr <= ptr) {
388+
return NULL;
389+
}
390+
391+
const ulint type = *ptr++;
397392

398-
if (!ptr) {
399-
} else if (type != 1 && type != 2) {
393+
if (type > TRX_UNDO_UPDATE) {
400394
recv_sys->found_corrupt_log = true;
401395
} else if (page) {
396+
/* Starting with MDEV-12288 in MariaDB 10.3.1, we use
397+
type=0 for the combined insert/update undo log
398+
pages. MariaDB 10.2 would use TRX_UNDO_INSERT or
399+
TRX_UNDO_UPDATE. */
402400
mach_write_to_2(FIL_PAGE_TYPE + page, FIL_PAGE_UNDO_LOG);
403401
mach_write_to_2(TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_TYPE + page,
404402
type);
@@ -459,29 +457,39 @@ trx_undo_parse_page_header_reuse(
459457
return(const_cast<byte*>(ptr));
460458
}
461459

462-
/********************************************************************//**
463-
Initializes the fields in an undo log segment page. */
464-
static
465-
void
466-
trx_undo_page_init(
467-
/*===============*/
468-
page_t* undo_page,/*!< in: undo log segment page */
469-
mtr_t* mtr)/*!< in: mtr */
460+
/** Initialize the fields in an undo log segment page.
461+
@param[in,out] undo_block undo page
462+
@param[in,out] mtr mini-transaction */
463+
static void trx_undo_page_init(buf_block_t* undo_block, mtr_t* mtr)
470464
{
471-
trx_upagef_t* page_hdr;
472-
473-
mlog_write_ulint(undo_page + FIL_PAGE_TYPE,
474-
FIL_PAGE_UNDO_LOG, MLOG_2BYTES, mtr);
475-
compile_time_assert(TRX_UNDO_PAGE_TYPE == 0);
476-
compile_time_assert(TRX_UNDO_PAGE_START == 2);
477-
compile_time_assert(TRX_UNDO_PAGE_NODE == TRX_UNDO_PAGE_FREE + 2);
465+
page_t* page = undo_block->frame;
466+
mach_write_to_2(FIL_PAGE_TYPE + page, FIL_PAGE_UNDO_LOG);
467+
mach_write_to_2(TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_TYPE + page, 0);
468+
mach_write_to_2(TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_START + page,
469+
TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE);
470+
mach_write_to_2(TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_FREE + page,
471+
TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE);
472+
473+
mtr->set_modified();
474+
switch (mtr->get_log_mode()) {
475+
case MTR_LOG_NONE:
476+
case MTR_LOG_NO_REDO:
477+
return;
478+
case MTR_LOG_SHORT_INSERTS:
479+
ut_ad(0);
480+
/* fall through */
481+
case MTR_LOG_ALL:
482+
break;
483+
}
478484

479-
page_hdr = undo_page + TRX_UNDO_PAGE_HDR;
480-
mlog_write_ulint(page_hdr, TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE,
481-
MLOG_4BYTES, mtr);
482-
mlog_write_ulint(page_hdr + TRX_UNDO_PAGE_FREE,
483-
TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_HDR_SIZE,
484-
MLOG_2BYTES, mtr);
485+
byte* log_ptr = mtr->get_log()->open(11 + 1);
486+
log_ptr = mlog_write_initial_log_record_low(
487+
MLOG_UNDO_INIT,
488+
undo_block->page.id.space(),
489+
undo_block->page.id.page_no(),
490+
log_ptr, mtr);
491+
*log_ptr++ = 0;
492+
mlog_close(mtr, log_ptr);
485493
}
486494

487495
/** Create an undo log segment.
@@ -533,7 +541,7 @@ trx_undo_seg_create(fil_space_t* space, trx_rsegf_t* rseg_hdr, ulint* id,
533541

534542
buf_block_dbg_add_level(block, SYNC_TRX_UNDO_PAGE);
535543

536-
trx_undo_page_init(block->frame, mtr);
544+
trx_undo_page_init(block, mtr);
537545

538546
mlog_write_ulint(TRX_UNDO_PAGE_HDR + TRX_UNDO_PAGE_FREE + block->frame,
539547
TRX_UNDO_SEG_HDR + TRX_UNDO_SEG_HDR_SIZE,
@@ -794,7 +802,7 @@ buf_block_t* trx_undo_add_page(trx_undo_t* undo, mtr_t* mtr)
794802
buf_block_dbg_add_level(new_block, SYNC_TRX_UNDO_PAGE);
795803
undo->last_page_no = new_block->page.id.page_no();
796804

797-
trx_undo_page_init(new_block->frame, mtr);
805+
trx_undo_page_init(new_block, mtr);
798806

799807
flst_add_last(TRX_UNDO_SEG_HDR + TRX_UNDO_PAGE_LIST
800808
+ header_page,

0 commit comments

Comments
 (0)