Skip to content

GraphIndexBuilder::addGraphNode must iterate all graph levels to estimate used bytes#521

Merged
tlwillke merged 1 commit intodatastax:mainfrom
michaeljmarshall:fix-graph-node-byte-estimate
Sep 17, 2025
Merged

GraphIndexBuilder::addGraphNode must iterate all graph levels to estimate used bytes#521
tlwillke merged 1 commit intodatastax:mainfrom
michaeljmarshall:fix-graph-node-byte-estimate

Conversation

@michaeljmarshall
Copy link
Member

The current implementation for GraphIndexBuilder::addGraphNode has a bug in the byte estimation logic. It calls IntStream.range(0, nodeLevel.level), which in turn calls:

    public static IntStream range(int startInclusive, int endExclusive) {
        if (startInclusive >= endExclusive) {
            return empty();
        } else {
            return StreamSupport.intStream(
                    new Streams.RangeIntSpliterator(startInclusive, endExclusive, false), false);
        }
    }

This is problematic because the nodeLevel.level is inclusive while the right bound of the range is exclusive.

The end result is an estimate that systematically misses the numerically highest level of the graph, thereby under counting bytes used. In reviewing the IntStream api, it seems most appropriate to use the rangeClosed method to achieve the desired semantics.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Fixes a bug in GraphIndexBuilder::addGraphNode byte estimation logic where the highest graph level was systematically excluded from calculations due to using IntStream.range() with inclusive level values but exclusive upper bounds.

  • Replaces IntStream.range() with IntStream.rangeClosed() to properly include all graph levels in byte calculations
  • Adds a test case to verify the byte estimation correctness

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
GraphIndexBuilder.java Changes IntStream.range to rangeClosed to fix inclusive level boundary issue
GraphIndexBuilderTest.java Adds test case to verify byte estimation works correctly

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@marianotepper marianotepper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Looks good.

Copy link
Collaborator

@tlwillke tlwillke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice catch indeed. LGTM

@tlwillke tlwillke merged commit 63db005 into datastax:main Sep 17, 2025
8 checks passed
@michaeljmarshall michaeljmarshall deleted the fix-graph-node-byte-estimate branch September 17, 2025 16:12
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.

4 participants