Skip to content

Super-node promotion silently changes edge iteration order: interleave the stripe chains instead of concatenating them #6044

Description

@lvca

Problem

Super-node promotion (#5156, StripedEdgeList) silently changes the order in which a vertex's edges are iterated. That is a behaviour change no reader opts into and none can detect.

On the classic layout the order is exact newest-first: MutableEdgeSegment.add() prepends inside the head chunk, and when a chunk fills the new chunk becomes the head, so EdgeIterator walks newest chunk → oldest chunk, newest entry → oldest entry.

Once a vertex crosses GRAPH_SUPERNODE_THRESHOLD (default 4096) its list is promoted to N stripe chains (default 16). Each chain is still newest-first internally, but StripedEdgeList.edgeIterator() composes them with a MultiIterator, i.e. it concatenates: the whole of stripe 0, then the whole of stripe 1, and so on. Since the stripe is hash(neighbour RID) % stripes, the global order becomes effectively random, and the error is proportional to the vertex degree — it gets worse as the graph grows.

The practical effect: any reader that takes the first N edges of a vertex to mean "the N most recent" — an extremely common pattern, and the only thing the classic layout ever did — starts returning near-arbitrary rows the moment the vertex passes 4096 edges. No exception, no log line, no way to notice except a user reporting that a record they just created is missing from a list.

We hit exactly this in production: a listing paging the newest 100 chats attached to a location vertex stopped showing newly created ones. It reproduces trivially in the engine — 2000 chats on one location, threshold lowered to force promotion:

layout position of the newest edge in the iteration
classic 0
striped 116

Why it is worth fixing in the engine

Promotion is an internal, automatic, degree-triggered optimisation for write throughput. It should be invisible to readers. Right now it is a silent, data-dependent semantic change that fires on precisely the vertices where it hurts most (the biggest ones), and every application built against the classic behaviour is exposed.

Callers can and should stop depending on storage order where correctness matters (we are moving the listing above onto an indexed ORDER BY). But "the first N edges are roughly the newest N" is a reasonable property for the engine to preserve across a transparent layout change, and preserving it costs very little.

Proposal: round-robin the stripe chains

Instead of concatenating the chains, interleave them: take entry 0 of every chain, then entry 1 of every chain, and so on. Each chain is already newest-first, and edges are distributed across stripes by a uniform hash, so depth k in a chain corresponds to global rank ≈ k × stripes. Round-robin therefore reconstructs an approximate newest-first order, and — the important part — the error becomes proportional to the rank asked for, not to the vertex degree.

Simulation with the real StripeDirectory.stripeOf hash, 16 stripes, asking for the first 100:

degree order newest edge at position of the true newest 100, how many are in the first 100 worst-placed of those 100
5,000 concatenated (today) 2197 10 position 4680
5,000 round-robin 7 85 position 157
20,000 concatenated (today) 7483 6 position 18751
20,000 round-robin 6 82 position 158

Note the last two columns are the same at 5k and 20k: the round-robin figures are independent of degree, while the concatenated ones degrade without bound. The newest edge is also guaranteed to land within the first stripes positions, since it is at the head of its own chain.

How I would implement it

  1. Add a round-robin mode to the multi-iterator used by StripedEdgeList (or a small dedicated InterleavedEdgeIterator): hold one cursor per chain, emit from each in turn, drop a chain from the rotation when it is exhausted. hasNext() is true while any cursor has a next.
  2. Use it in the read iterators only — edgeIterator() / vertexIterator() (and the entryIterator() behind them). Leave the maintenance walks (delete, GraphDatabaseChecker, export) on plain concatenation: they consume the whole chain, order is irrelevant to them, and concatenation has strictly better locality.
  3. Keep the existing per-chain semantics untouched, including the read-side rule that a chain whose head cannot be read is skipped.
  4. Document the guarantee honestly in the StripedEdgeList javadoc: approximately newest-first globally, exactly newest-first within a stripe, with the newest edge always inside the first stripes entries. Applications needing an exact order must sort or use an index — that should be written down rather than inferred from the classic layout's behaviour.

Read-side only: no on-disk format change, no HASH_VERSION bump, no migration.

Costs to weigh

  • Locality. 16 live cursors instead of 1 means 16 resident chunk pages and touching 16 files per 16 edges. Negligible for a paged read of the first N; worse for a full walk, which is why step 2 keeps the maintenance paths on concatenation.
  • It is an approximation, not an ordering guarantee. It restores parity with the classic layout for "the newest few", and nothing more — which is the point.

Test

A test that lowers GRAPH_SUPERNODE_THRESHOLD, appends enough edges to force promotion, and asserts that (a) the most recently added edge appears within the first stripes entries, and (b) an edge of global rank r appears at a position bounded by a small multiple of r — the property concatenation violates and the one applications actually rely on.

Activity

  1. self-assigned this
    on Aug 10, 2026
  2. added theissue type on Aug 10, 2026
  3. added this to the 26.9.1 milestone on Aug 10, 2026
  4. added a commit that references this issue on Aug 10, 2026
  5. added 3 commits that reference this issue on Aug 11, 2026
  6. added
    engine
    storage
    on Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugenginestorage

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions