Skip to content

Commit d514de3

Browse files
committed
em: recover orphaned ua_target_resources on restart
When the EM-builder creates a ua_target_resource but the subsequent em_resources.target_resource update is lost (crash, restart), the next run finds em_resources.target_resource=NULL but ua_target_resources already holds a record for the same deterministic res_uuid. The previous code called insert() unconditionally, which triggered a ConflictRecords exception and aborted the DB transaction. Any query in the same session after the abort also failed, so em_resources was never updated — creating an infinite recovery loop that blocked actualization of all dependent resources. Fix: check for an existing record by res_uuid before inserting. If found, link it to em_resources and return so the next iteration can compare hashes normally.
1 parent 37fac47 commit d514de3

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

exordos_core/elements/dm/models.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,23 @@ def actualize(self):
845845
full_hash=self.full_hash,
846846
tracked_at=self.updated_at,
847847
)
848+
orphaned = list(
849+
sdk_models.TargetResource.objects.get_all(
850+
filters={"res_uuid": ra_filters.EQ(res_uuid)}
851+
)
852+
)
853+
if orphaned:
854+
# Target resource exists in ua_target_resources but
855+
# em_resources.target_resource is NULL (update was lost on a
856+
# previous run). Recover the link so the next iteration can
857+
# compare hashes normally.
858+
LOG.warning(
859+
"Target resource %s already exists (orphaned). Recovering link.",
860+
res_uuid,
861+
)
862+
self.target_resource = orphaned[0]
863+
self.update()
864+
return
848865
target_resource.insert()
849866
self.target_resource = target_resource
850867
self.update()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dependencies = [
2222
"oslo.config>=3.22.2,<10.0.0", # Apache-2.0
2323
"bjoern>=3.2.2", # BSD License (BSD-3-Clause)
2424
"gcl_looper>=1.2.3,<2.0.0", # Apache-2.0
25-
"restalchemy>=15.0.1,<16.0.0", # Apache-2.0
25+
"restalchemy>=15.1.1,<16.0.0", # Apache-2.0
2626
"libvirt-python>=11.0.0,<13.0.0", # GNU Lesser General Public License v2 or later (LGPLv2+)
2727
"Authlib>=1.3.2,<2.0.0", # BSD License (BSD-3-Clause)
2828
"bazooka>=1.3.0,<2.0.0", # Apache-2.0

uv.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)