segmented_changelog: check that parents are assigned smaller ids

Summary:
The most important invariant for IdDag is that parent nodes have ids that are
smaller than child nodes. We had a couple of issues that resulted in failing
this invariant so we are adding these extra checks. They will help us diagnose
issues faster and proctect protect production data against faulty updates.

Reviewed By: quark-zju

Differential Revision: D27092204

fbshipit-source-id: 1f052b290a494e267fac2f551ba51582baa67973
This commit is contained in:
Stefan Filip 2021-03-18 09:49:59 -07:00 committed by Facebook GitHub Bot
parent 014b80dc5d
commit ef294cb359

View File

@ -132,10 +132,40 @@ pub fn assign_ids(
}
}
}
let head_vertex = mem_idmap
.find_vertex(head)
.or_else(|| start_state.assignments.find_vertex(head))
.ok_or_else(|| format_err!("error assigning ids; failed to assign head {}", head))?;
let cs_to_v = |cs| {
mem_idmap
.find_vertex(cs)
.or_else(|| start_state.assignments.find_vertex(cs))
.ok_or_else(|| {
format_err!(
"error assingning ids; failed to find assignment for changeset {}",
cs
)
})
};
for (v, cs) in mem_idmap.iter() {
if let Some(parents) = start_state.parents.get(&cs) {
for p in parents {
let pv = cs_to_v(*p)?;
if pv >= v {
return Err(format_err!(
"error assigning ids; parent >= vertex: {} >= {} ({} >= {})",
pv,
v,
p,
cs
));
}
}
}
}
Ok((mem_idmap, head_vertex))
}