Skip to content

Commit f5a4934

Browse files
committed
xds: Address review comments for RingHash proactive connection
1 parent f22dd7b commit f5a4934

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

xds/src/main/java/io/grpc/xds/RingHashLoadBalancer.java

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -214,39 +214,28 @@ protected void updateOverallBalancingState() {
214214
overallState = TRANSIENT_FAILURE;
215215
}
216216

217-
// gRFC A61: trigger lazy initialization outside picker when no READY child exists,
218-
// at least one child is in TRANSIENT_FAILURE, and no child is currently CONNECTING
219-
maybeTriggerIdleChildConnection(numReady, numTF, numConnecting, numIdle);
217+
// gRFC A61: if the aggregated connectivity state is TRANSIENT_FAILURE or CONNECTING and
218+
// there are no endpoints in CONNECTING state, the ring_hash policy will choose one of
219+
// the endpoints in IDLE state (if any) to trigger a connection attempt on
220+
if (numReady == 0 && numTF > 0 && numConnecting == 0 && numIdle > 0) {
221+
triggerIdleChildConnection();
222+
}
220223

221224
RingHashPicker picker =
222225
new RingHashPicker(syncContext, ring, getChildLbStates(), requestHashHeaderKey, random);
223226
getHelper().updateBalancingState(overallState, picker);
224227
this.currentConnectivityState = overallState;
225228
}
226229

230+
227231
/**
228-
* Triggers proactive connection of an IDLE child load balancer when the following conditions are
229-
* met.
230-
*
231-
* <ul>
232-
* <li>there is no READY child
233-
* <li>at least one child is in TRANSIENT_FAILURE
234-
* <li>no child is currently CONNECTING
235-
* <li>there exists at least one IDLE child
236-
* </ul>
237-
*
238-
* <p>This corresponds to the proactive connection logic described in gRFC A61, where recovery
239-
* from TRANSIENT_FAILURE must be triggered outside the picker when no active connection attempt
240-
* is in progress.
232+
* Triggers a connection attempt for the first IDLE child load balancer.
241233
*/
242-
private void maybeTriggerIdleChildConnection(
243-
int numReady, int numTF, int numConnecting, int numIdle) {
244-
if (numReady == 0 && numTF > 0 && numConnecting == 0 && numIdle > 0) {
245-
for (ChildLbState child : getChildLbStates()) {
246-
if (child.getCurrentState() == ConnectivityState.IDLE) {
247-
child.getLb().requestConnection();
248-
return;
249-
}
234+
private void triggerIdleChildConnection() {
235+
for (ChildLbState child : getChildLbStates()) {
236+
if (child.getCurrentState() == ConnectivityState.IDLE) {
237+
child.getLb().requestConnection();
238+
return;
250239
}
251240
}
252241
}

xds/src/test/java/io/grpc/xds/RingHashLoadBalancerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,8 @@ public void firstSubchannelFailure() {
806806
assertThat(result.getStatus().isOk()).isTrue();
807807
assertThat(result.getSubchannel()).isNull();
808808
verify(subchannelList.get(0), never()).requestConnection(); // In TF
809+
verify(subchannelList.get(1)).requestConnection();
810+
verify(subchannelList.get(2), never()).requestConnection(); // Not one of the first 2
809811
}
810812

811813
@Test

0 commit comments

Comments
 (0)