Skip to content

Commit

Permalink
MDEV-31642: Upgrade may crash if innodb_log_file_buffering=OFF
Browse files Browse the repository at this point in the history
recv_log_recover_10_5(): Make reads aligned by 4096 bytes, to avoid
any trouble in case the file was opened in O_DIRECT mode and
the physical block size is larger than 512 bytes.
Because innodb_log_file_size used to be defined in whole megabytes,
reading multiples of 4096 bytes instead of 512 should not be an issue.
  • Loading branch information
dr-m committed Jul 10, 2023
1 parent 0df3463 commit c358e21
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions mysql-test/suite/innodb/t/log_corruption.test
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,11 @@ print OUT pack("x[470]N", 0x677700cf);
# invalid (all-zero) checkpoint page 1 and an empty log page
print OUT chr(0) x 1024;
# valid checkpoint block 2
print OUT pack("x[12]NNNx[264]", 0x12860c, 0, 0x80c);
print OUT pack("x[12]NNNx[264]", 0x12860c, 0, 0x120c);
# pointer to the FILE_CHECKPOINT record, and checkpoint page checksum
print OUT pack("H*x[204]NNN", "590DBAACFE922582", 0x128612, 0, 0x101741b);
print OUT pack("H*x[204]NNN", "590DBAACFE922582", 0x128612, 0, 0x3b4ce62d);
# log page
print OUT pack("NnnNx[496]N", 0x80000944, 12, 12, 1, 0x46c8a2a2);
print OUT pack("x[2560]NnnNx[496]N", 0x80000944, 12, 12, 1, 0x46c8a2a2);
close OUT or die;
EOF

Expand Down
7 changes: 5 additions & 2 deletions storage/innobase/log/log0recv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,10 @@ static dberr_t recv_log_recover_10_5(lsn_t lsn_offset)
if (lsn_offset < (log_sys.is_pmem() ? log_sys.file_size : 4096))
memcpy_aligned<512>(buf, &log_sys.buf[lsn_offset & ~511], 512);
else
recv_sys.read(lsn_offset & ~lsn_t{511}, {buf, 512});
{
recv_sys.read(lsn_offset & ~lsn_t{4095}, {buf, 4096});
buf+= lsn_offset & 0xe00;
}

if (!recv_check_log_block(buf))
{
Expand Down Expand Up @@ -1757,7 +1760,7 @@ dberr_t recv_sys_t::find_checkpoint()
if (dberr_t err= recv_log_recover_pre_10_2())
return err;
upgrade:
memset_aligned<512>(const_cast<byte*>(field_ref_zero), 0, 512);
memset_aligned<4096>(const_cast<byte*>(field_ref_zero), 0, 4096);
/* Mark the redo log for upgrading. */
log_sys.last_checkpoint_lsn= log_sys.next_checkpoint_lsn;
log_sys.set_recovered_lsn(log_sys.next_checkpoint_lsn);
Expand Down

0 comments on commit c358e21

Please sign in to comment.