• Andrei's avatar
    MDEV-15393 gtid_slave_pos duplicate key errors after mysqldump restore · b8f92ade
    Andrei authored
    When mysqldump is run to dump the `mysql` system database, it generates
    INSERT statements into the table `mysql.gtid_slave_pos`.
    After running the backup script
    those inserts did not produce the expected gtid state on slave. In
    particular the maximum of mysql.gtid_slave_pos.sub_id did not make
    into
       rpl_global_gtid_slave_state.last_sub_id
    
    an in-memory object that is supposed to match the current state of the
    table. And that was regardless of whether --gtid option was specified
    or not. Later when the backup recipient server starts as slave
    in *non-gtid* mode this desychronization may lead to a duplicate key
    error.
    
    This effect is corrected for --gtid mode mysqldump/mariadb-dump only
    as the following.  The fixes ensure the insert block of the dump
    script is followed with a "summing-up" SET @global.gtid_slave_pos
    assignment.
    
    For the implemenation part, note a deferred print-out of
    SET-gtid_slave_pos and associated comments is prefered over relocating
    of the entire blocks if (opt_master,slave_data &&
    do_show_master,slave_status) ...  because of compatiblity
    concern. Namely an error inside do_show_*() is handled in the new code
    the same way, as early as, as before.
    
    A regression test can be run in how-to-reproduce mode as well.
    One affected mtr test observed.
    rpl_mysqldump_slave.result "mismatch" shows now the new deferring print
    of SET-gtid_slave_pos policy in action.
    b8f92ade
rpl_mysqldump_slave.result 9.32 KB