We have the first example of scheduler deadlock in the willd for MySQL for the new scheduler:

https://github.com/apache/airflow/pull/8550/checks?check_run_id=1258193958#step:6:1439

Would be great to track it down and fix before the prod release:

**NOTE**  For now the issue has been mitigated (according to the documentation of MySQL) by applying restarts (with exponential back-off) in #12046. This should help with beta-testing of Airlfow by the users and to see if the retries on deadlock has some potential negative effects (according to the documentation - they might have if they happen frequently enough). 

Some more analysis might be performed between now and 2.0.0 which might result in deciding that this issue does not need any more fixes than the current mitigation or some actual changes in the code that might result in preventing the deadlocks.


airflow/models/dagbag.py
"""Prints a report around DagBag loading stats"""
        stats = self.dagbag_stats
        dag_folder = self.dag_folder
        duration = sum([o.duration for o in stats], timedelta()).total_seconds()
        dag_num = sum([o.dag_num for o in stats])
        task_num = sum([o.task_num for o in stats])
        table = tabulate(stats, headers="keys")
        report = textwrap.dedent(f"""\n
        -------------------------------------------------------------------
        DagBag loading stats for {dag_folder}
        -------------------------------------------------------------------
        Number of DAGs: {dag_num}
        Total task number: {task_num}
        DagBag parsing time: {duration}
        {table}
        """)
        return report
    @provide_session
    def sync_to_db(self, session: Optional[Session] = None):
        """Save attributes about list of DAG to the DB."""
        
        from airflow.models.dag import DAG
        from airflow.models.serialized_dag import SerializedDagModel
        self.log.debug("Calling the DAG.bulk_sync_to_db method")
        DAG.bulk_write_to_db(self.dags.values(), session=session)
        
        self.log.debug("Calling the SerializedDagModel.bulk_sync_to_db method")
        SerializedDagModel.bulk_sync_to_db(self.dags.values(), session=session)