Commit 90444a4f authored by Kristian Nielsen's avatar Kristian Nielsen

Revert: MDEV-22351 InnoDB may recover wrong information after RESET MASTER

This commit can cause the wrong (old) binlog position to be recovered by
mariabackup --prepare. It implements that the value of the FIL_PAGE_LSN is
compared to determine which binlog position is the last one and should be
recoved. However, it some cases it is seen that the FIL_PAGE_LSN order does
not match the binlog position commit order, as is assumed by the code.

In one example, the recovery first encountered this in trx_rseg_mem_restore():

  lsn=27282754  binlog position (./master-bin.000001, 472908)

and then later:

  lsn=27282699  binlog position (./master-bin.000001, 477164)

The last one 477164 is the correct position. However, because the LSN
encountered for the first one is higher, that position is recovered instead.
This results in too old binlog position, and a newly provisioned slave will
start replicating too early and get duplicate key error or similar.
Signed-off-by: default avatarKristian Nielsen <knielsen@knielsen-hq.org>
parent 74a04912
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, 2021, MariaDB Corporation.
Copyright (c) 2017, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
......@@ -848,8 +848,6 @@ class trx_sys_t
uint64_t recovered_binlog_offset;
/** Latest recovered binlog file name */
char recovered_binlog_filename[TRX_SYS_MYSQL_LOG_NAME_LEN];
/** FIL_PAGE_LSN of the page with the latest recovered binlog metadata */
lsn_t recovered_binlog_lsn;
/**
......
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, 2021, MariaDB Corporation.
Copyright (c) 2017, 2020, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
......@@ -443,13 +443,8 @@ static
void
trx_rseg_mem_restore(trx_rseg_t* rseg, trx_id_t& max_trx_id, mtr_t* mtr)
{
/* This is based on trx_rsegf_get_new().
We need to access buf_block_t. */
buf_block_t *block = buf_page_get(
page_id_t(rseg->space->id, rseg->page_no), 0, RW_S_LATCH, mtr);
buf_block_dbg_add_level(block, SYNC_RSEG_HEADER_NEW);
const trx_rsegf_t* rseg_header = TRX_RSEG + block->frame;
trx_rsegf_t* rseg_header = trx_rsegf_get_new(
rseg->space->id, rseg->page_no, mtr);
if (mach_read_from_4(rseg_header + TRX_RSEG_FORMAT) == 0) {
trx_id_t id = mach_read_from_8(rseg_header
......@@ -460,20 +455,32 @@ trx_rseg_mem_restore(trx_rseg_t* rseg, trx_id_t& max_trx_id, mtr_t* mtr)
}
if (rseg_header[TRX_RSEG_BINLOG_NAME]) {
lsn_t lsn = std::max(block->page.newest_modification,
mach_read_from_8(FIL_PAGE_LSN
+ block->frame));
const char* binlog_name = reinterpret_cast<const char*>
(rseg_header) + TRX_RSEG_BINLOG_NAME;
compile_time_assert(TRX_RSEG_BINLOG_NAME_LEN == sizeof
trx_sys.recovered_binlog_filename);
if (lsn > trx_sys.recovered_binlog_lsn) {
trx_sys.recovered_binlog_lsn = lsn;
trx_sys.recovered_binlog_offset
= mach_read_from_8(
rseg_header
+ TRX_RSEG_BINLOG_OFFSET);
memcpy(trx_sys.recovered_binlog_filename,
rseg_header + TRX_RSEG_BINLOG_NAME,
TRX_RSEG_BINLOG_NAME_LEN);
int cmp = *trx_sys.recovered_binlog_filename
? strncmp(binlog_name,
trx_sys.recovered_binlog_filename,
TRX_RSEG_BINLOG_NAME_LEN)
: 1;
if (cmp >= 0) {
uint64_t binlog_offset = mach_read_from_8(
rseg_header + TRX_RSEG_BINLOG_OFFSET);
if (cmp) {
memcpy(trx_sys.
recovered_binlog_filename,
binlog_name,
TRX_RSEG_BINLOG_NAME_LEN);
trx_sys.recovered_binlog_offset
= binlog_offset;
} else if (binlog_offset >
trx_sys.recovered_binlog_offset) {
trx_sys.recovered_binlog_offset
= binlog_offset;
}
}
#ifdef WITH_WSREP
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment