uranusjr commented on a change in pull request #16311:
URL: https://github.com/apache/airflow/pull/16311#discussion_r649845538
##########
File path: airflow/utils/db.py
##########
@@ -702,9 +727,33 @@ def upgradedb():
for err in errs:
log.error("Automatic migration is not available\n%s", err)
return
+
+ dialect = session.connection().dialect
+ if dialect.name == 'postgresql':
+ log.info('Acquiring lock on database for upgrade')
+ session.connection().execute('select PG_ADVISORY_LOCK(2);')
+
+ if dialect.name == 'mysql' and dialect.server_version_info >= (
+ 5,
+ 6,
+ ):
+ log.info('Acquiring lock on database for upgrade')
+ session.connection().execute("select GET_LOCK('db_upgrade',1800);")
+
command.upgrade(config, 'heads')
add_default_pool_if_not_exists()
+ if dialect.name == 'postgresql':
+ log.info('Releasing lock on database for upgrade')
+ session.connection().execute('select PG_ADVISORY_UNLOCK(2);')
+
+ if dialect.name == 'mysql' and dialect.server_version_info >= (
+ 5,
+ 6,
+ ):
+ log.info('Releasing lock on database for upgrade')
+ session.connection().execute("select RELEASE_LOCK('db_upgrade');")
Review comment:
This being duplicated three times makes me think we should wrap the
logic, maybe into a context manager.
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]