Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-27059

page_zip_dir_insert() may corrupt ROW_FORMAT=COMPRESSED tables

    XMLWordPrintable

    Details

      Description

      A data corruption bug that affects ROW_FORMAT=COMPRESSED tables was found by RQG testing:

      mysqld: /data/Server/bb-10.6-markoO/storage/innobase/row/row0purge.cc:208: bool row_purge_remove_clust_if_poss_low(purge_node_t*, ulint): Assertion `rec_get_deleted_flag(rec, rec_offs_comp(offsets))' failed.
      

      The cause turned out to be corruption that had been introduced in page_zip_dir_insert() before the server had been killed and restarted. After the following fix had been applied, this assertion was not seen again:

      diff --git a/storage/innobase/page/page0zip.cc b/storage/innobase/page/page0zip.cc
      index f1da35d12ec..959256bf105 100644
      --- a/storage/innobase/page/page0zip.cc
      +++ b/storage/innobase/page/page0zip.cc
      @@ -4248,8 +4248,13 @@ page_zip_dir_insert(
       	}
       
       	/* Write the entry for the inserted record.
      -	The "owned" and "deleted" flags must be zero. */
      -	mach_write_to_2(slot_rec - PAGE_ZIP_DIR_SLOT_SIZE, page_offset(rec));
      +	The "owned" flag must be zero. */
      +	uint16_t offs = page_offset(rec);
      +	if (rec_get_deleted_flag(rec, true)) {
      +		offs |= PAGE_ZIP_DIR_SLOT_DEL;
      +	}
      +
      +	mach_write_to_2(slot_rec - PAGE_ZIP_DIR_SLOT_SIZE, offs);
       	mtr->zmemcpy(*cursor->block, slot_rec - page_zip->data
       		     - PAGE_ZIP_DIR_SLOT_SIZE, PAGE_ZIP_DIR_SLOT_SIZE);
       }
      

      It turns out that btr_cur_pessimistic_update() may invoke this function on a delete-marked record. The scenario involved ROLLBACK. I did not examine it deeper, but I suspect that a purgeable delete-marked record had been "resurrected" by an insert that was executed as delete-unmarking the record. Either the test deleted and later inserted the same record, or it updated a PRIMARY KEY value back and forth.

      We failed to create a test case for this.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              marko Marko Mäkelä
              Reporter:
              marko Marko Mäkelä
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.