-
Notifications
You must be signed in to change notification settings - Fork 4k
grpclb: pick_first delegation #12568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
kannanjgithub
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review comments.
| // One subchannel is created by the child LB | ||
| assertThat(mockSubchannels).hasSize(1); | ||
| Subchannel subchannel = mockSubchannels.poll(); | ||
| assertThat(picker0.dropList).containsExactly(null, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add assertion for picker0.dropList size 1 and is instance of ChildLbPickerEntry.
| // Only one subchannel is created | ||
| // One subchannel is created by the child LB | ||
| assertThat(mockSubchannels).hasSize(1); | ||
| Subchannel subchannel = mockSubchannels.poll(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
verify(subchannel).requestConnection();
| inOrder.verify(helper).updateBalancingState(eq(READY), pickerCaptor.capture()); | ||
| RoundRobinPicker picker3 = (RoundRobinPicker) pickerCaptor.getValue(); | ||
| assertThat(picker3.dropList).containsExactly(null, null); | ||
| assertThat(picker3.pickList).containsExactly( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly here, don't remove the assertion for the pickList with the fake subchannel, assert using accessor in ChildLbPickerEntry for use by the test.
| // TRANSIENT_FAILURE | ||
| Status error = Status.UNAVAILABLE.withDescription("Simulated connection error"); | ||
| deliverSubchannelState(subchannel, ConnectivityStateInfo.forTransientFailure(error)); | ||
| inOrder.verify(helper).updateBalancingState(eq(TRANSIENT_FAILURE), pickerCaptor.capture()); | ||
| RoundRobinPicker picker2 = (RoundRobinPicker) pickerCaptor.getValue(); | ||
| assertThat(picker2.dropList).containsExactly(null, null); | ||
| assertThat(picker2.pickList).containsExactly(new ErrorEntry(error)); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not remove the testing for simulated transient failure.
Now we cannot directly do
assertThat(picker2.pickList).containsExactly(new ErrorEntry(error));
as the ErorrEntry is wrapped in a ChildLbPickerEntry. Create accessor for the wrapped entry for use in the unit test so we can assert using that.
| assertThat(mockSubchannels).isEmpty(); | ||
| verify(subchannel).updateAddresses( | ||
| eq(Arrays.asList( | ||
| new EquivalentAddressGroup(backends1.get(0).addr, eagAttrsWithToken("token0001")), | ||
| new EquivalentAddressGroup(backends1.get(1).addr, | ||
| eagAttrsWithToken("token0002"))))); | ||
| inOrder.verify(helper).updateBalancingState(eq(READY), pickerCaptor.capture()); | ||
| RoundRobinPicker picker2 = (RoundRobinPicker) pickerCaptor.getValue(); | ||
| assertThat(picker2.dropList).containsExactly(null, null); | ||
| assertThat(picker2.pickList).containsExactly( | ||
| new BackendEntry(subchannel, new TokenAttachingTracerFactory(getLoadRecorder()))); | ||
| // the same child LB is updated with new addresses. We expect | ||
| // only one subchannel to be created for the whole test. The child LB will call | ||
| // updateAddresses() internally, so we remove the verifications for recreation. | ||
| verify(helper, times(1)).createSubchannel(any(CreateSubchannelArgs.class)); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PF behavior may be done by a different code now but the behavior should still be the same. Why remove the test for it?
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