From 82000e48ecdaa5738f6a7e69d94386977e714493 Mon Sep 17 00:00:00 2001 From: dparalen Date: Tue, 26 Sep 2017 16:09:13 +0200 Subject: [PATCH] Generate version_id upon add_node The version_id isn't set during add_node() call. This function is called when introspection starts for both "new" and existing node_info records. As a result, race conditions can appear in an HA inspector deployment (see the refered bug). This patch makes sure a version_id is generated during the add_node() call so stale record updates can be detected through the version_id mismatch between the inspector memory and the DB record. Change-Id: I422473e888e5e49abb3e598fc2cf2f330620bdcd Closes-Bug: #1719627 --- ironic_inspector/node_cache.py | 5 ++++- .../notes/add_node-with-version_id-24f51e5888480aa0.yaml | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/add_node-with-version_id-24f51e5888480aa0.yaml diff --git a/ironic_inspector/node_cache.py b/ironic_inspector/node_cache.py index d0da5634e..5919660f6 100644 --- a/ironic_inspector/node_cache.py +++ b/ironic_inspector/node_cache.py @@ -686,9 +686,12 @@ def add_node(uuid, state, **attributes): started_at = timeutils.utcnow() with db.ensure_transaction() as session: _delete_node(uuid) - db.Node(uuid=uuid, state=state, started_at=started_at).save(session) + version_id = uuidutils.generate_uuid() + db.Node(uuid=uuid, state=state, version_id=version_id, + started_at=started_at).save(session) node_info = NodeInfo(uuid=uuid, state=state, started_at=started_at, + version_id=version_id, ironic=attributes.pop('ironic', None)) for (name, value) in attributes.items(): if not value: diff --git a/releasenotes/notes/add_node-with-version_id-24f51e5888480aa0.yaml b/releasenotes/notes/add_node-with-version_id-24f51e5888480aa0.yaml new file mode 100644 index 000000000..76162ea98 --- /dev/null +++ b/releasenotes/notes/add_node-with-version_id-24f51e5888480aa0.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + A ``version_id`` is now explicitly generated during the + ``node_cache.start_introspection/.add_node`` call to avoid race conditions + such as in case of the `two concurrent introspection calls bug`_. + + .. _two concurrent introspection calls bug: https://bugs.launchpad.net/ironic-inspector/+bug/1719627