Bug #116574 btr_page_reorganize_low may cause crash recovery failure
Submitted: 7 Nov 2024 3:20 Modified: 7 Nov 2024 10:12
Reporter: Ruyi Zhang (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[7 Nov 2024 3:20] Ruyi Zhang
Description:
In the function btr_page_reorganize_low(innobase):

```
  data_size2 = page_get_data_size(page);
  max_ins_size2 = page_get_max_insert_size_after_reorganize(page, 1);

  if (data_size1 != data_size2 || max_ins_size1 != max_ins_size2) {
    ib::error(ER_IB_MSG_30)
        << "Page old data size " << data_size1 << " new data size "
        << data_size2 << ", page old max ins size " << max_ins_size1
        << " new max ins size " << max_ins_size2;

    ib::error(ER_IB_MSG_31) << BUG_REPORT_MSG;
    ut_d(ut_error);
  } else {
    success = true;
  }

  /* Restore the cursor position. */
  if (pos > 0) {
    cursor->rec = page_rec_get_nth(page, pos);
  } else {
    ut_ad(cursor->rec == page_get_infimum_rec(page));
  }
```

if the data size before and after the page reorganization does not match(page corruption or bugs), the Release version of MySQL will tolerate the error but will not generate the MLOG_PAGE_REORGANIZE log(The MLOG_PAGE_REORGANIZE log will not be generated when the variable success is false). 

If a crash occurs before the rebuilt dirty page is flushed to disk, MySQL will fail to recover from the crash due to the missing MLOG_PAGE_REORGANIZE log before MLOG_REC_INSERT.

How to repeat:
Source code suggestion.

Suggested fix:
Generate the MLOG_PAGE_REORGANIZE log if MySQL tolerates the data size error.
[7 Nov 2024 10:12] MySQL Verification Team
Hi Mr. Zhang,

Thank you for your bug report.

We have carefully analysed the code that you are pointing to and we agree with you.

This is now a verified bug for the version 8.0 and higher.

Thanks again ....