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

slave_run_triggers_for_rbr enabled slave ignores after-insert trigger's error

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Fixed
    • 10.11, 11.8, 12.3
    • 12.3.4, 13.1.2
    • Replication
    • None
    • Can result in unexpected behaviour

    Description

      The following test hangs at wait_for_slave_sql_error line starting from
      MDEV-15990 commits.

      --source include/have_binlog_format_row.inc
      --source include/have_innodb.inc
      --source include/master-slave.inc
       
      --connection slave
      call mtr.add_suppression("Can.t update table 'aud' in stored function/trigger");
      call mtr.add_suppression("Slave: At line 1 in test.ai Error_code: 4094");
      call mtr.add_suppression("Could not execute Write_rows");
      call mtr.add_suppression("Error running query, slave SQL thread aborted");
      source include/stop_slave.inc;
      SET @sav= @@global.slave_run_triggers_for_rbr;
      SET @@global.slave_run_triggers_for_rbr= ENFORCE;
      source include/start_slave.inc;
       
      --connection master
      CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY) ENGINE=InnoDB;
      CREATE TABLE aud (a INT) ENGINE=InnoDB;
      CREATE TRIGGER ai AFTER INSERT ON t1 FOR EACH ROW INSERT INTO aud VALUES (NEW.a);
      --sync_slave_with_master
       
      --connection master
      INSERT INTO t1 VALUES (1);
       
      --echo # the slave must stop with an error at trying to "re-"exectute the trigger.
      --connection slave
      let $slave_sql_errno = 1442;
      source include/wait_for_slave_sql_error.inc;
       
      # Recover the slave that
      SET @@global.slave_run_triggers_for_rbr = NO;
      source include/start_slave.inc;
       
      # now must catch up.
      --connection master
      --sync_slave_with_master
       
      SELECT a FROM t1 ORDER BY a;
      --echo # ENFORCE re-runs the master's trigger on the slave, but the audit row
      --echo # was not going to be written twice.
      SELECT COUNT(*) AS aud_rows_on_slave FROM aud;
       
      # --- cleanup ---
      --connection slave
      source include/stop_slave.inc;
      SET @@global.slave_run_triggers_for_rbr = @sav;
      source include/start_slave.inc;
      --connection master
      DROP TRIGGER ai;
      DROP TABLE t1, aud;
      --sync_slave_with_master
      --source include/rpl_end.inc
      
      

      The test correctly expects an error from a trigger that the slave applier can't pass.

      Additionally it is verified that the expected error-stop by slave indeed took place for pre-MDEV-15990 version.

      The reason of the hang is the block

         error= m_write_record->write_record();
       
          DBUG_RETURN(error ? m_write_record->last_errno() : 0);
      

      ignored an after-trigger error which has legitimate zero code in m_write_record.

      The following diff fixes the issue

      @@ -7734,9 +7734,13 @@ Write_rows_log_event::write_row(rpl_group_info *rgi,
           error= update_sequence();
         else
         {
      +    int ret_err;
           error= m_write_record->write_record();
      +    ret_err= error ?
      +	     (m_write_record->last_errno() ?
      +	      m_write_record->last_errno() : HA_ERR_GENERIC): 0;
       
      -    DBUG_RETURN(error ? m_write_record->last_errno() : 0);
      +    DBUG_RETURN(ret_err);
         }
      
      

      Attachments

        Activity

          People

            Elkin Andrei Elkin
            Elkin Andrei Elkin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 0d
                0d
                Remaining:
                Remaining Estimate - 0d
                0d
                Logged:
                Time Spent - 1d
                1d

                Git Integration

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