Skip to content

autosharding: implement the sliceMap - #9380

Open
easwars wants to merge 3 commits into
grpc:masterfrom
easwars:autosharding_slice_map_implementation
Open

autosharding: implement the sliceMap#9380
easwars wants to merge 3 commits into
grpc:masterfrom
easwars:autosharding_slice_map_implementation

Conversation

@easwars

@easwars easwars commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

This PR only contains the implementation of the sliceMap. My plan is to make a few small PRs initially with things that can be separated out, before a bigger PR that contains the rest of the implementation of the LB policy. The implementation of the sliceMap follows the spec very closely, so should be reviewable even without the rest of the changes.

RELEASE NOTES: none

@easwars easwars added the Type: Feature New features or improvements in behavior label Aug 27, 2026
@easwars easwars added this to the 1.85 Release milestone Aug 27, 2026
@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.56%. Comparing base (6d697e4) to head (4eb4c26).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9380      +/-   ##
==========================================
+ Coverage   87.54%   87.56%   +0.01%     
==========================================
  Files         429      430       +1     
  Lines       30622    30661      +39     
==========================================
+ Hits        26807    26847      +40     
+ Misses       3814     3813       -1     
  Partials        1        1              
Files with missing lines Coverage Δ
balancer/autosharding/autosharding.go 92.30% <ø> (ø)
balancer/autosharding/slice_map.go 100.00% <100.00%> (ø)

... and 25 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread balancer/autosharding/slice_map.go Outdated
sort.Slice(states, func(i, j int) bool {
return states[i].index < states[j].index
})
sm.fallbackPool = make([]int, len(states))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are we creating a temporary states populating it , sorting and then storing indexes in fallback. Cant we just store the indexes in fallback and then sort ? Or am I missing something ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread balancer/autosharding/slice_map.go
Comment thread balancer/autosharding/slice_map_test.go
Comment thread balancer/autosharding/slice_map_test.go Outdated
{
name: "valid-assignment",
assignment: &assignment{
endpointNames: []string{"hostA", "hostB", "hostC", "hostD"},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just curious : Here "hostD" is also unknown right ??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, you are right. Removed it.

@easwars easwars assigned eshitachandwani and unassigned easwars Sep 1, 2026
}
}

sm.slices = append(sm.slices, entry)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We need to add one more entry here, example
if assignment are

[1,2, ]
[2,6, ]
[6,8, ]

SliceMap has to be
[-inf , 1) -> Fallback
[1, 2) - >
[2,6) - >
[6, 8) ->
[8, +inf) -> fallback

I you are keeping just start key -inf case can be handled in logic, but you need one more entry for last +inf case where you need to insert an entry in map.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let me know if that make sense. Or I am misreading logic here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The AssignmentProvider would take care of ensuring that there are no gaps in the assignments, so that the sliceMap implementation does not have to worry about it.

I've also expanded the docstring on the assignment type to clarify this a little.

@eshitachandwani eshitachandwani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM , with 2 very minor nits.

return &autoshardingBalancer{}
}

// slice represents a key range and its assigned endpoints.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit :

Suggested change
// slice represents a key range and its assigned endpoints.
// slice represents a key range and indices of its assigned endpoints.

endpoints []int // Indices into list[PickerEndpoint] in the Picker
}

// sliceMap is a data structure optimized for lookups. Given a key, it returns a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: Can we remove / reword the second sentence here ? It makes it seem like a function and makes it a little confusing

Comment thread balancer/autosharding/slice_map.go
Comment thread balancer/autosharding/slice_map_test.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Feature New features or improvements in behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants