grpclb: pick_first delegation#12568
Merged
shivaspeaks merged 6 commits intogrpc:masterfrom Dec 23, 2025
Merged
Conversation
Contributor
kannanjgithub
left a comment
There was a problem hiding this comment.
Some deleted code still needs to be restored.
kannanjgithub
requested changes
Dec 19, 2025
Contributor
kannanjgithub
left a comment
There was a problem hiding this comment.
Have a closer look at deleted statements due to trying plain verify which would have failed without inOrder.
kannanjgithub
approved these changes
Dec 22, 2025
jdcormie
pushed a commit
to jdcormie/grpc-java
that referenced
this pull request
Feb 11, 2026
**Summary of Changes**
This pull request refactors the grpclb load balancer's PICK_FIRST mode
to delegate its logic to a standard pick_first load balancing policy.
The key changes are as follows:
1. **`grpclb/build.gradle`**
Added dependency on `grpc-util` module to access
`ForwardingLoadBalancerHelper`
2. **`grpclb/src/main/java/io/grpc/grpclb/GrpclbState.java`**
- New imports:
LoadBalancer, LoadBalancerProvider, LoadBalancerRegistry,
ResolvedAddresses, FixedResultPicker, ForwardingLoadBalancerHelper
- New fields for PICK_FIRST delegation:
- pickFirstLbProvider - Provider for creating child pick_first LB
- pickFirstLb - The child LoadBalancer instance
- pickFirstLbState / pickFirstLbPicker - Track child LB's state and
picker
- currentPickFirstLoadRecorder - Load recorder for token attachment
- Key behavioral changes:
- updateServerList() PICK_FIRST case: Instead of creating a single
subchannel, it now:
- Creates the child pick_first LB once and then updates it with new
addresses on subsequent updates.
- Passes addresses to child LB via acceptResolvedAddresses()
- maybeUpdatePicker() PICK_FIRST case: Uses child LB's state and picker
wrapped with ChildLbPickerEntry
- RoundRobinEntry.picked() signature change: Changed from
picked(Metadata) to picked(PickSubchannelArgs) to allow child picker
delegation
- New ChildLbPickerEntry class: Wraps child LB's picker and attaches
TokenAttachingTracerFactory for token propagation
- New PickFirstLbHelper class: Forwarding helper that intercepts
updateBalancingState() to store child state and trigger grpclb picker
updates
- Updated shutdown(), requestConnection(), maybeUseFallbackBackends():
Handle the new child LB delegation model
3. **`grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java`**
- Updated tests to reflect the new delegation behavior:
- Initial state is now CONNECTING (not IDLE) since standard pick_first
eagerly connects
- Tests now verify the child LB is created only once and then handles
address updates internally.
- Adjusted verification expectations for the new flow
- Key Behavioral Changes:
- Delegation to child LB: The grpclb state no longer directly manages
subchannels for PICK_FIRST mode; the child pick_first LB handles this
internally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
This pull request refactors the grpclb load balancer's PICK_FIRST mode to delegate its logic to a standard pick_first load balancing policy.
The key changes are as follows:
grpclb/build.gradleAdded dependency on
grpc-utilmodule to accessForwardingLoadBalancerHelpergrpclb/src/main/java/io/grpc/grpclb/GrpclbState.javaLoadBalancer, LoadBalancerProvider, LoadBalancerRegistry, ResolvedAddresses, FixedResultPicker, ForwardingLoadBalancerHelper
grpclb/src/test/java/io/grpc/grpclb/GrpclbLoadBalancerTest.java