• sjaakola's avatar
    MDEV-21577 MDL BF-BF conflict · 4d6c6611
    sjaakola authored
    Some DDL statements appear to acquire MDL locks for a table referenced by
    foreign key constraint from the actual affected table of the DDL statement.
    OPTIMIZE, REPAIR and ALTER TABLE belong to this class of DDL statements.
    
    Earlier MariaDB version did not take this in consideration, and appended
    only affected table in the certification key list in write set.
    Because of missing certification information, it could happen that e.g.
    OPTIMIZE table for FK child table could be allowed to apply in parallel
    with DML operating on the foreign key parent table, and this could lead to
    unhandled MDL lock conflicts between two high priority appliers (BF).
    
    The fix in this patch, changes the TOI replication for OPTIMIZE, REPAIR and
    ALTER TABLE statements so that before the execution of respective DDL
    statement, there is foreign key parent search round. This FK parent search
    contains following steps:
    * open and lock the affected table (with permissive shared locks)
    * iterate over foreign key contstraints and collect and array of Fk parent
      table names
    * close all tables open for the THD and release MDL locks
    * do the actual TOI replication with the affected table and FK parent
      table names as key values
    
    The patch contains also new mtr test for verifying that the above mentioned
    DDL statements replicate without problems when operating on FK child table.
    The mtr test scenario #1, which can be used to check if some other DDL
    (on top of OPTIMIZE, REPAIR and ALTER) could cause similar excessive FK
    parent table locking.
    Reviewed-by: default avatarAleksey Midenkov <aleksey.midenkov@mariadb.com>
    Reviewed-by: default avatarJan Lindström <jan.lindstrom@mariadb.com>
    4d6c6611
galera_ddl_fk_conflict.inc 3.98 KB