Skip to content

Commit ccaeef4

Browse files
committed
fix(migration): handle cases where children IDs have already had their edges migrated
1 parent 55ad3d5 commit ccaeef4

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

pychunkedgraph/graph/edges/__init__.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -369,18 +369,29 @@ def _get_new_edge(edge, parent_ts, padding):
369369
return types.empty_2d.copy()
370370

371371
mask = np.isin(_edges[:, 1], l2ids_b)
372-
parents_a = _edges[mask][:, 0]
373-
children_b = cg.get_children(_edges[mask][:, 1], flatten=True)
374-
parents_b = np.unique(cg.get_parents(children_b, time_stamp=parent_ts))
375-
_cx_edges_d = cg.get_cross_chunk_edges(parents_b, time_stamp=parent_ts)
376-
parents_b = []
377-
for _node, _edges_d in _cx_edges_d.items():
378-
for _edges in _edges_d.values():
379-
_mask = np.isin(_edges[:, 1], parents_a)
380-
if np.any(_mask):
381-
parents_b.append(_node)
382-
383-
parents_b = np.array(parents_b, dtype=basetypes.NODE_ID)
372+
if np.any(mask):
373+
parents_a = _edges[mask][:, 0]
374+
children_b = cg.get_children(_edges[mask][:, 1], flatten=True)
375+
parents_b = np.unique(cg.get_parents(children_b, time_stamp=parent_ts))
376+
_cx_edges_d = cg.get_cross_chunk_edges(parents_b, time_stamp=parent_ts)
377+
parents_b = []
378+
for _node, _edges_d in _cx_edges_d.items():
379+
for _edges in _edges_d.values():
380+
_mask = np.isin(_edges[:, 1], parents_a)
381+
if np.any(_mask):
382+
parents_b.append(_node)
383+
parents_b = np.array(parents_b, dtype=basetypes.NODE_ID)
384+
else:
385+
# if none of `l2ids_b` were found in edges, `l2ids_a` already have new edges
386+
# so get the new identities of `l2ids_b` by using chunk mask
387+
parents_b = _edges[:, 1]
388+
chunks_old = cg.get_chunk_ids_from_node_ids(l2ids_b)
389+
chunks_new = cg.get_chunk_ids_from_node_ids(parents_b)
390+
chunk_mask = np.isin(chunks_new, chunks_old)
391+
parents_b = parents_b[chunk_mask]
392+
_stale_nodes = get_stale_nodes(cg, parents_b, parent_ts=parent_ts)
393+
assert _stale_nodes.size == 0, f"{edge}, {_stale_nodes}, {parent_ts}"
394+
384395
parents_b = np.unique(
385396
cg.get_roots(parents_b, stop_layer=mlayer, ceil=False, time_stamp=parent_ts)
386397
)

0 commit comments

Comments
 (0)