-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add migration to fix database edges state #5640
base: stable
Are you sure you want to change the base?
Conversation
CodSpeed Performance ReportMerging #5640 will degrade performances by 20.65%Comparing Summary
Benchmarks breakdown
|
083b5df
to
a6518f2
Compare
""" | ||
Fix corrupted state introduced by Migration012 when duplicating a CoreAccount (branch Aware) | ||
being part of a CoreStandardGroup (branch Agnostic). Database is corrupted at multiple points: | ||
- Old CoreAccount node <> group_member node `active` edge has no `to` time (possibly because of #5590). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, #5590 deserves a dedicated migration fixing missing to
time for any couple of deleted
edge on -global-
with an active
edge on another branch.
backend/infrahub/core/migrations/graph/m019_restore_rels_to_time.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a good start
as I say in my comments, I think we should split this into at least 2 migrations
I took a shot at writing a more general version of what I think the first migration should be
backend/infrahub/core/migrations/graph/m019_restore_rels_to_time.py
Outdated
Show resolved
Hide resolved
backend/infrahub/core/migrations/graph/m019_restore_rels_to_time.py
Outdated
Show resolved
Hide resolved
ab99efb
to
4ea0e08
Compare
7828def
to
a842f14
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is most of the way there
some comments on the queries
backend/infrahub/core/migrations/graph/m019_restore_rels_to_time.py
Outdated
Show resolved
Hide resolved
backend/infrahub/core/migrations/graph/m019_restore_rels_to_time.py
Outdated
Show resolved
Hide resolved
backend/infrahub/core/migrations/graph/m019_restore_rels_to_time.py
Outdated
Show resolved
Hide resolved
backend/infrahub/core/migrations/graph/m019_restore_rels_to_time.py
Outdated
Show resolved
Hide resolved
backend/infrahub/core/migrations/graph/m019_restore_rels_to_time.py
Outdated
Show resolved
Hide resolved
backend/infrahub/core/migrations/graph/m019_restore_rels_to_time.py
Outdated
Show resolved
Hide resolved
746e80e
to
699adfb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking great, just a few small comments to go
backend/infrahub/core/migrations/graph/m019_restore_rels_to_time.py
Outdated
Show resolved
Hide resolved
MATCH (rel)-[active_edge {status: "active"}]-(peer_2) | ||
RETURN active_edge.branch as active_edge_branch | ||
LIMIT 1 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if a relationship is created on a branch and then merged into main, there will actually be 2 active
edges between the Node
node and Relationship
node
and it is possible that a node in this situation is deleted on just one of the branches for which it has an active edge
would it work to just use deleted_edge_branch
here instead of trying to get active_edge_branch
? deleted_edge_branch
should be the correct branch to delete, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have added more comments, taking into consideration the fact that relationship and node might not have the same branch support type, we may need to retrieve active branch, in details:
- If res is agnostic, we should delete on global branch (and we do not use deleted_edge_branch)
- If rel is aware and deleted node is aware, we should use deleted edge branch
- If rel is aware and delete node is agnostic, we need to create deleted edges for any branch on which this relationship exists. I did not have in mind situations where there could be multiple active branches, so I think we should actually retrieve any distinct branch for which an active edge exist, instead of a single one as it's currently done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this makes sense to me
699adfb
to
55db64d
Compare
55db64d
to
ea5beef
Compare
|
||
// Note that if an AWARE node has been deleted on a branch and relationship is AGNOSTIC, we do not "delete" this relationship | ||
// right now as this aware node might exist on another branch. Or, should we check there is no existing active is_part_of | ||
// to consider this node completely deleted and so we can also deleted connected agnostic relationships? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ajtmccarty would be glad to have your opinion on this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you have seen this issue during your testing, then I think we should handle it, meaning check if the aware
node is completely deleted and, if so, delete the agnostic
relationship
but if you haven't encountered it, then I think we can leave this as is
this actually sounds like something that we might not have correct handling for in our cypher queries to delete a node, I can look at adding a unit test for deleting an aware
node with an agnostic
relationship to check if we handle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not met that while testing, I let it as is
} | ||
ELSE [] // deleted_node.branch_support = -local- | ||
END | ||
ELSE [] // rel.branch_support = -local- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ajtmccarty, not exactly sure when/why we end up with rel.branch_support = -local-
and/or deleted_node.branch_support = -local-
, we might need to discuss that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's just "local"
, without the hyphens
local
branch support means that an object only exists on the branch where it is created and will not be merged back into main
when a branch is merged
I think that you can treat branch_support = "local"
the same as branch_support = "aware"
nodes and relationships for the purpose of this migration.
so I think this case statement can simplified to check for <> "agnostic"
instead of = "aware"
to handle branch_support = "local"
nodes too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the migration queries look good
just a few test-related comments
RETURN new_node; | ||
""" | ||
|
||
await ts.execute_query(query=query_2, name="query_2", params={"global_branch": GLOBAL_BRANCH_NAME}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be good to validate all the edges are as expected with a cypher query
5270ad0
to
c2b0693
Compare
Fixes IFC-1204
Detail of the issue is within migration code
I updated the PR to have 3 separated queries:
Note that, testing separatily each query might not be relevant as:
NodeListGetRelationshipsQuery
filters on both requested branch AND -global- even for full aware nodes/rels, so setting an edge on global would not break itdeleted
edge.So in the end, a single test has been added reproducing (almost) corrupted state observed on user db.
Note this test does not trigger IFC-1204 bug, but a manual test confirmed this migration fixes it.