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

DB_TRX_ID is not always reset when the history is removed

    Details

      Description

      When an InnoDB transaction is about to update a record, two steps will be performed before the modification of the clustered index tree can start:

      1. the transaction must be able to acquire an exclusive lock on the record
      2. writing an undo log record for rolling back the operation must succeed

      This bug is about the undo log processing. We can get to that phase only if the record was last modified by a committed transaction.

      In the scenario of this bug, that committed transaction would still exist in the system in the purge queue, and the record would still carry a nonzero DB_TRX_ID.

      If the old transaction is purgeable, then we should write DB_TRX_ID=0 to the undo log record, so that in case our transaction is rolled back, the history will be reset at rollback.
      TODO: Write a test case for this scenario.

      If the old transaction is accessible in some transaction’s read view, then we must write the old DB_TRX_ID,DB_ROLL_PTR to the undo log record, so that the other read views can still correctly reach the correct old version of the record.
      The following test patch demonstrates that currently, the DB_TRX_ID will never be reset:

      diff --git a/mysql-test/suite/innodb/t/dml_purge.test b/mysql-test/suite/innodb/t/dml_purge.test
      index 720acfb1577..fdab8687886 100644
      --- a/mysql-test/suite/innodb/t/dml_purge.test
      +++ b/mysql-test/suite/innodb/t/dml_purge.test
      @@ -13,9 +13,20 @@ SET GLOBAL innodb_purge_rseg_truncate_frequency = 1;
       
       CREATE TABLE t1(a INT PRIMARY KEY, b INT NOT NULL)
       ROW_FORMAT=REDUNDANT ENGINE=InnoDB;
      +
      +--connect (con1,localhost,root)
      +START TRANSACTION WITH CONSISTENT SNAPSHOT;
      +
      +--connection default
       INSERT INTO t1 VALUES(1,2),(3,4);
       UPDATE t1 SET b=-3 WHERE a=3;
       
      +--connection con1
      +UPDATE t1 SET b=4 WHERE a=3;
      +COMMIT;
      +--disconnect con1
      +
      +--connection default
       # Initiate a full purge, which should reset all DB_TRX_ID.
       SET GLOBAL innodb_fast_shutdown=0;
       --source include/shutdown_mysqld.inc
      

      With this change to the test, the DB_TRX_ID,DB_ROLL_PTR will not be reset by purge.

        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: