Skip to content

Debug-check stream order where it enters a k-way merge #2336

Open

Description

@bplatz

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:

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 .fsc order (run_record.rs, SPOT comparator) ignores language and list index.
  • V2's o_type orders 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

  1. added
    P3
    area:storage
    on Nov 11, 2026
  2. added this to the 5.0.0 milestone on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area:storage

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions