Repository navigation
Description
A merge stream that is not in its merge comparator's order produces a misordered index without failing anything. Three times now it has surfaced only as a lookup that quietly finds nothing:
- language ids, Bulk import stores duplicate triples — RDF set semantics violated on both import paths #1651 (
f5b7d4eca) - subject/string ids remapped over an existing dictionary, feat: bulk import into a new named graph of an existing ledger #2232 (
e905972f9) - triple-term handles in the bulk SPOT merge, Graph import carries annotations and triple terms on next #2263 (
9605f8d28)
In each case a remap that is not monotone broke a stream's order.
Proposal
Add a debug-build assertion in KWayMerge::next_record (fluree-db-indexer/src/run_index/build/merge.rs), right where the winning stream advances:
if let Some(next) = self.streams[stream_idx].peek() {
debug_assert_ne!(
(self.cmp)(&winner, next),
Ordering::Greater,
"merge stream {stream_idx} yielded a record below the one before it"
);
}With #2263's re-sort removed, this fires on both of that PR's ordering tests.
Blocker: the full rebuild's stats pass
The check can't land as-is. It also fires today, on main too, in five existing tests, all in the full rebuild's stats pass (fluree-db-indexer/src/build/rebuild.rs, the SpotClassStatsCollector block). That pass merges V1SpoolMergeAdapter streams with cmp_v2_g_spot:
- The V1
.fscorder (run_record.rs, SPOT comparator) ignores language and list index. - V2's
o_typeorders by language.
As a result, one subject's values of one predicate in two languages come out backwards, e.g. LANG_STRING(2) o_key 7 before LANG_STRING(1) o_key 8. Only stats are affected.
Done when
- The stats pass is fed in V2 order (or merged with a comparator its V1 streams satisfy).
- The debug assertion is in
KWayMerge::next_record, and the full test suite is green with it.
Activity