You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/07/01 12:37:39 UTC

[GitHub] [airflow] anitakar commented on a change in pull request #16311: Prevent running `airflow db init` migrations and setup in parallel.

anitakar commented on a change in pull request #16311:
URL: https://github.com/apache/airflow/pull/16311#discussion_r662250999



##########
File path: airflow/utils/session.py
##########
@@ -70,3 +70,29 @@ def wrapper(*args, **kwargs) -> RT:
                 return func(*args, session=session, **kwargs)
 
     return wrapper
+
+
+@provide_session
+@contextlib.contextmanager
+def create_global_lock(session=None, pg_lock_id=1, mysql_lock_name='init', mysql_lock_timeout=1800):
+    """Contextmanager that will create and teardown a global db lock."""
+    dialect = session.connection().dialect
+    if dialect.name == 'postgresql':
+        session.connection().execute(f'select PG_ADVISORY_LOCK({pg_lock_id});')
+
+    if dialect.name == 'mysql' and dialect.server_version_info >= (
+        5,
+        6,
+    ):
+        session.connection().execute(f"select GET_LOCK('{mysql_lock_name}',{mysql_lock_timeout});")

Review comment:
       Sure. Will need some time to prepare local setup for mssql




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org