From 93688e953115cbd32789bd7f8be8ef50a4124748 Mon Sep 17 00:00:00 2001 From: Julia Kreger Date: Tue, 23 May 2023 10:39:20 -0700 Subject: [PATCH] Explicitly use a session for DB version check The db field value version check, which is a preflight to major upgrades (to detect if a prior upgrade was not completed) was using model_query, which could orphan an open transaction in the same process until the python interpretter went and took out the perverable trash. We now use an explicit session which structurally ensures we close any open transactions which allows a metadata lock to be obtained to perform a schema update.. Change-Id: Id51419bc50af5a756bb7b0ca451df1936dd6f904 --- ironic/db/sqlalchemy/api.py | 11 ++++++----- ...ove-model-query-from-upgrade-af227b6c8a5d654a.yaml | 9 +++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/remove-model-query-from-upgrade-af227b6c8a5d654a.yaml diff --git a/ironic/db/sqlalchemy/api.py b/ironic/db/sqlalchemy/api.py index 6658a8ef1b..96f2dc45fd 100644 --- a/ironic/db/sqlalchemy/api.py +++ b/ironic/db/sqlalchemy/api.py @@ -1798,11 +1798,12 @@ class Connection(api.Connection): # compatible with its (old) DB representation. # NOTE(rloo): .notin_ does not handle null: # http://docs.sqlalchemy.org/en/latest/core/sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.notin_ - query = model_query(model.version).filter( - sql.or_(model.version == sql.null(), - model.version.notin_(supported_versions))) - if query.count(): - return False + with _session_for_read() as session: + query = session.query(model.version).filter( + sql.or_(model.version == sql.null(), + model.version.notin_(supported_versions))) + if query.count(): + return False return True diff --git a/releasenotes/notes/remove-model-query-from-upgrade-af227b6c8a5d654a.yaml b/releasenotes/notes/remove-model-query-from-upgrade-af227b6c8a5d654a.yaml new file mode 100644 index 0000000000..270dc85c26 --- /dev/null +++ b/releasenotes/notes/remove-model-query-from-upgrade-af227b6c8a5d654a.yaml @@ -0,0 +1,9 @@ +--- +fixes: + - | + Fixes an issue where the database upgrade can hang on Python 3.10. + This was because open transactions could become orphaned awaiting + the Python runtime to clean up their memory references due to the + way the overall database query was being intiiated to pre-flight + check the upgrade. We have structurally changed the behavior + to remedy this case.