Skip to content

Let relation identifiers locate edges of sort-keyed labels - #5149

Draft
batrived wants to merge 1 commit into
JanusGraph:masterfrom
batrived:feat/4923-relation-id-sort-key
Draft

batrived wants to merge 1 commit into
JanusGraph:masterfrom
batrived:feat/4923-relation-id-sort-key

Conversation

@batrived

Copy link
Copy Markdown
Contributor

Fixes #4923.

For a MULTI label with a sort key, the edge column is [type+dir][sortKey][adjacent][relationId], but RelationIdentifier has no sort-key values. So resolving an edge id (g.E(id), mixed and composite edge index hits) slices only [type+dir] and reads every edge of the label on the vertex.

Change

  • New option graph.relation-id-sort-key (MASKABLE, default false; nothing changes unless enabled). With it on, ids of such edges carry their encoded sort-key values and resolve with a single-column read. A miss falls back to the scan, so a wrong sort key cannot hide an edge.
  • Id formats: optional fifth string token K<hex>, and two new GraphBinary in-vertex markers. Both are written only when a sort key is present. equals/hashCode are unchanged. Gryo/Java serialization keep their format.
  • Mixed index: deletes and reindex remove the document under either id form, so instances can run with different settings during a rollout. Composite edge index entries append the sort key after the in-vertex id; existing readers ignore it.
  • FORK labels, sort keys over 64 encoded bytes, and ids taken after the edge's transaction closed keep the old form.
  • Bug fix: EdgeSerializer.getQuery reassigned keyEndPos per implicit key. With sort key + adjacent + relation id constrained on a DESC label, that flipped the adjacent vertex bytes and the slice never matched. Happy to split this into its own PR.

Tests

  • JanusGraphOperationCountingTest: with 100 edges of one label on a vertex, resolving one edge reads 1 edgestore entry with the sort key and ≥100 without. Covered for ASC, DESC and a two-key sort key, via g.E(id), the string form and composite index hits.
  • JanusGraphIndexTest: mixed index hits (ASC/DESC) read one column; delete and reindex remove either doc id form.
  • Unit tests for the id string and GraphBinary formats, plus EdgeSerializerTest for the DESC query (fails without the fix).
  • Ran locally: InMemoryGraphTest, BerkeleyGraphTest, BerkeleyLuceneTest, BerkeleyOperationCountingTest. Not run locally: ES, CQL.

For all changes:

  • Is there an issue associated with this PR? Is it referenced in the commit message?
  • Does your PR body contain #xyz where xyz is the issue number you are trying to resolve?
  • Has your PR been rebased against the latest commit within the target branch (typically master)?
  • Is your initial contribution a single, squashed commit?

For code changes:

  • Have you written and/or updated unit tests to verify your changes?
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE.txt file, including the main LICENSE.txt file in the root of this repository?
  • If applicable, have you updated the NOTICE.txt file, including the main NOTICE.txt file found in the root of this repository?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

🤖 Generated with Claude Code

An edge of a MULTI label with a sort key is stored under the column
[type+dir][sortKey][adjacentVertex][relationId], but RelationIdentifier
carries only relationId, outVertexId, typeId and inVertexId. Resolving an
identifier (g.E(id), mixed and composite edge index hits) could therefore
only slice [type+dir] and read every edge of the label on the vertex.

With the new option graph.relation-id-sort-key (MASKABLE, default false),
identifiers of such edges carry their encoded sort-key values, and
resolving them reads a single column. A lookup that misses falls back to
the scan. The string form gains an optional fifth token K<hex> and
GraphBinary two new in-vertex markers; ids without a sort key keep their
exact format, and equals/hashCode are unchanged. Mixed index deletes and
reindex remove documents under either id form, and composite edge index
entries append the sort key after the in-vertex id.

Also fixes EdgeSerializer.getQuery reassigning keyEndPos on every
implicit-key position, which flipped the adjacent vertex bytes for DESC
labels when the sort key, adjacent vertex and relation id were all
constrained, so the query never matched the stored column.

Fixes JanusGraph#4923

Signed-off-by: Balmukund Trivedi <btrivedipublic@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Edge materialization from a mixed index scans the full adjacency when the edge label has a sort key (seek is defeated)

1 participant