summaryrefslogtreecommitdiff
path: root/nova/db
diff options
context:
space:
mode:
authorMark Goddard <mark@stackhpc.com>2019-11-20 12:01:33 +0000
committerLee Yarwood <lyarwood@redhat.com>2021-08-20 14:57:47 +0100
commit2383cbb4a518821d245fce316b3778c8ba8e5246 (patch)
tree5b7b20a3fa57db7b12bd7354a0ebd181e7885b1e /nova/db
parenta8492e88783b40f6dc61888fada232f0d00d6acf (diff)
downloadnova-2383cbb4a518821d245fce316b3778c8ba8e5246.tar.gz
Fix inactive session error in compute node creation
In the fix for bug 1839560 [1][2], soft-deleted compute nodes may be restored, to ensure we can reuse ironic node UUIDs as compute node UUIDs. While this seems to largely work, it results in some nasty errors being generated [3]: InvalidRequestError This session is in 'inactive' state, due to the SQL transaction being rolled back; no further SQL can be emitted within this transaction. This happens because compute_node_create is decorated with pick_context_manager_writer, which begins a transaction. While _compute_node_get_and_update_deleted claims that calling a second pick_context_manager_writer decorated function will begin a new subtransaction, this does not appear to be the case. This change removes pick_context_manager_writer from the compute_node_create function, and adds a new _compute_node_create function which ensures the transaction is finished if _compute_node_get_and_update_deleted is called. The new unit test added here fails without this change. This change marks the removal of the final FIXME from the functional test added in [4]. [1] https://bugs.launchpad.net/nova/+bug/1839560 [2] https://git.openstack.org/cgit/openstack/nova/commit/?id=89dd74ac7f1028daadf86cb18948e27fe9d1d411 [3] http://paste.openstack.org/show/786350/ [4] https://review.opendev.org/#/c/695012/ Change-Id: Iae119ea8776bc7f2e5dbe2e502a743217beded73 Closes-Bug: #1853159 Related-Bug: #1853009
Diffstat (limited to 'nova/db')
-rw-r--r--nova/db/main/api.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/nova/db/main/api.py b/nova/db/main/api.py
index 57570ddc41..0ae9a453b8 100644
--- a/nova/db/main/api.py
+++ b/nova/db/main/api.py
@@ -768,7 +768,7 @@ def compute_node_search_by_hypervisor(context, hypervisor_match):
@pick_context_manager_writer
-def compute_node_create(context, values):
+def _compute_node_create(context, values):
"""Create a compute node from the values dictionary.
:param context: The security context
@@ -781,8 +781,21 @@ def compute_node_create(context, values):
compute_node_ref = models.ComputeNode()
compute_node_ref.update(values)
+ compute_node_ref.save(context.session)
+ return compute_node_ref
+
+
+# NOTE(mgoddard): We avoid decorating this with @pick_context_manager_writer,
+# so that we get a separate transaction in the exception handler. This avoids
+# an error message about inactive DB sessions during a transaction rollback.
+# See https://bugs.launchpad.net/nova/+bug/1853159.
+def compute_node_create(context, values):
+ """Creates a new ComputeNode and populates the capacity fields
+ with the most recent data. Will restore a soft deleted compute node if a
+ UUID has been explicitly requested.
+ """
try:
- compute_node_ref.save(context.session)
+ compute_node_ref = _compute_node_create(context, values)
except db_exc.DBDuplicateEntry:
with excutils.save_and_reraise_exception(logger=LOG) as err_ctx:
# Check to see if we have a (soft) deleted ComputeNode with the