mirror of https://github.com/grpc/grpc-java.git
api: deprecate Helper.updateSubchannelAddresses() and add equivalent on Subchannel (#5802)
Resolves #5676
This commit is contained in:
parent
9b4c958201
commit
af2c16d301
|
|
@ -963,7 +963,9 @@ public abstract class LoadBalancer {
|
||||||
* href="https://github.com/grpc/grpc-java/issues/5015">#5015</a> for the background.
|
* href="https://github.com/grpc/grpc-java/issues/5015">#5015</a> for the background.
|
||||||
*
|
*
|
||||||
* @since 1.4.0
|
* @since 1.4.0
|
||||||
|
* @deprecated use {@link Subchannel#updateAddresses} instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public final void updateSubchannelAddresses(
|
public final void updateSubchannelAddresses(
|
||||||
Subchannel subchannel, EquivalentAddressGroup addrs) {
|
Subchannel subchannel, EquivalentAddressGroup addrs) {
|
||||||
checkNotNull(addrs, "addrs");
|
checkNotNull(addrs, "addrs");
|
||||||
|
|
@ -982,7 +984,9 @@ public abstract class LoadBalancer {
|
||||||
* @throws IllegalArgumentException if {@code subchannel} was not returned from {@link
|
* @throws IllegalArgumentException if {@code subchannel} was not returned from {@link
|
||||||
* #createSubchannel} or {@code addrs} is empty
|
* #createSubchannel} or {@code addrs} is empty
|
||||||
* @since 1.14.0
|
* @since 1.14.0
|
||||||
|
* @deprecated use {@link Subchannel#updateAddresses} instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public void updateSubchannelAddresses(
|
public void updateSubchannelAddresses(
|
||||||
Subchannel subchannel, List<EquivalentAddressGroup> addrs) {
|
Subchannel subchannel, List<EquivalentAddressGroup> addrs) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
|
@ -1301,6 +1305,19 @@ public abstract class LoadBalancer {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces the existing addresses used with this {@code Subchannel}. If the new and old
|
||||||
|
* addresses overlap, the Subchannel can continue using an existing connection.
|
||||||
|
*
|
||||||
|
* <p>It must be called from the Synchronization Context or will throw.
|
||||||
|
*
|
||||||
|
* @throws IllegalArgumentException if {@code addrs} is empty
|
||||||
|
* @since 1.22.0
|
||||||
|
*/
|
||||||
|
public void updateAddresses(List<EquivalentAddressGroup> addrs) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (Internal use only) returns an object that represents the underlying subchannel that is used
|
* (Internal use only) returns an object that represents the underlying subchannel that is used
|
||||||
* by the Channel for sending RPCs when this {@link Subchannel} is picked. This is an opaque
|
* by the Channel for sending RPCs when this {@link Subchannel} is picked. This is an opaque
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,7 @@ public class LoadBalancerTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
@Test
|
@Test
|
||||||
public void helper_updateSubchannelAddresses_delegates() {
|
public void helper_updateSubchannelAddresses_delegates() {
|
||||||
class OverrideUpdateSubchannel extends NoopHelper {
|
class OverrideUpdateSubchannel extends NoopHelper {
|
||||||
|
|
@ -187,6 +188,7 @@ public class LoadBalancerTest {
|
||||||
assertThat(helper.ran).isTrue();
|
assertThat(helper.ran).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
@Test(expected = UnsupportedOperationException.class)
|
@Test(expected = UnsupportedOperationException.class)
|
||||||
public void helper_updateSubchannelAddressesList_throws() {
|
public void helper_updateSubchannelAddressesList_throws() {
|
||||||
new NoopHelper().updateSubchannelAddresses(null, Arrays.asList(eag));
|
new NoopHelper().updateSubchannelAddresses(null, Arrays.asList(eag));
|
||||||
|
|
|
||||||
|
|
@ -1127,6 +1127,7 @@ final class ManagedChannelImpl extends ManagedChannel implements
|
||||||
syncContext.execute(new LoadBalancerRefreshNameResolution());
|
syncContext.execute(new LoadBalancerRefreshNameResolution());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public void updateSubchannelAddresses(
|
public void updateSubchannelAddresses(
|
||||||
LoadBalancer.Subchannel subchannel, List<EquivalentAddressGroup> addrs) {
|
LoadBalancer.Subchannel subchannel, List<EquivalentAddressGroup> addrs) {
|
||||||
|
|
@ -1621,6 +1622,12 @@ final class ManagedChannelImpl extends ManagedChannel implements
|
||||||
public ChannelLogger getChannelLogger() {
|
public ChannelLogger getChannelLogger() {
|
||||||
return subchannelLogger;
|
return subchannelLogger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateAddresses(List<EquivalentAddressGroup> addrs) {
|
||||||
|
syncContext.throwIfNotInThisSynchronizationContext();
|
||||||
|
subchannel.updateAddresses(addrs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ final class PickFirstLoadBalancer extends LoadBalancer {
|
||||||
helper.updateBalancingState(CONNECTING, new Picker(PickResult.withSubchannel(subchannel)));
|
helper.updateBalancingState(CONNECTING, new Picker(PickResult.withSubchannel(subchannel)));
|
||||||
subchannel.requestConnection();
|
subchannel.requestConnection();
|
||||||
} else {
|
} else {
|
||||||
helper.updateSubchannelAddresses(subchannel, servers);
|
subchannel.updateAddresses(servers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ public abstract class ForwardingLoadBalancerHelper extends LoadBalancer.Helper {
|
||||||
return delegate().createSubchannel(args);
|
return delegate().createSubchannel(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public void updateSubchannelAddresses(
|
public void updateSubchannelAddresses(
|
||||||
Subchannel subchannel, List<EquivalentAddressGroup> addrs) {
|
Subchannel subchannel, List<EquivalentAddressGroup> addrs) {
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,11 @@ public abstract class ForwardingSubchannel extends LoadBalancer.Subchannel {
|
||||||
return delegate().getInternalSubchannel();
|
return delegate().getInternalSubchannel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateAddresses(List<EquivalentAddressGroup> addrs) {
|
||||||
|
delegate().updateAddresses(addrs);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return MoreObjects.toStringHelper(this).add("delegate", delegate()).toString();
|
return MoreObjects.toStringHelper(this).add("delegate", delegate()).toString();
|
||||||
|
|
|
||||||
|
|
@ -549,7 +549,7 @@ public class ManagedChannelImplIdlenessTest {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
helper.updateSubchannelAddresses(subchannel, addrs);
|
subchannel.updateAddresses(Collections.singletonList(addrs));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -184,7 +184,16 @@ public class ManagedChannelImplTest {
|
||||||
return "test-addr";
|
return "test-addr";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
private final SocketAddress socketAddress2 =
|
||||||
|
new SocketAddress() {
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "test-addr";
|
||||||
|
}
|
||||||
|
};
|
||||||
private final EquivalentAddressGroup addressGroup = new EquivalentAddressGroup(socketAddress);
|
private final EquivalentAddressGroup addressGroup = new EquivalentAddressGroup(socketAddress);
|
||||||
|
private final EquivalentAddressGroup addressGroup2 =
|
||||||
|
new EquivalentAddressGroup(Arrays.asList(socketAddress, socketAddress2));
|
||||||
private final FakeClock timer = new FakeClock();
|
private final FakeClock timer = new FakeClock();
|
||||||
private final FakeClock executor = new FakeClock();
|
private final FakeClock executor = new FakeClock();
|
||||||
private final FakeClock balancerRpcExecutor = new FakeClock();
|
private final FakeClock balancerRpcExecutor = new FakeClock();
|
||||||
|
|
@ -1322,6 +1331,11 @@ public class ManagedChannelImplTest {
|
||||||
.newClientTransport(
|
.newClientTransport(
|
||||||
eq(socketAddress), eq(clientTransportOptions), isA(TransportLogger.class));
|
eq(socketAddress), eq(clientTransportOptions), isA(TransportLogger.class));
|
||||||
|
|
||||||
|
// updateAddresses()
|
||||||
|
updateAddressesSafely(helper, sub1, Collections.singletonList(addressGroup2));
|
||||||
|
assertThat(((InternalSubchannel) sub1.getInternalSubchannel()).getAddressGroups())
|
||||||
|
.isEqualTo(Collections.singletonList(addressGroup2));
|
||||||
|
|
||||||
// shutdown() has a delay
|
// shutdown() has a delay
|
||||||
shutdownSafely(helper, sub1);
|
shutdownSafely(helper, sub1);
|
||||||
timer.forwardTime(ManagedChannelImpl.SUBCHANNEL_SHUTDOWN_DELAY_SECONDS - 1, TimeUnit.SECONDS);
|
timer.forwardTime(ManagedChannelImpl.SUBCHANNEL_SHUTDOWN_DELAY_SECONDS - 1, TimeUnit.SECONDS);
|
||||||
|
|
@ -4116,6 +4130,17 @@ public class ManagedChannelImplTest {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void updateAddressesSafely(
|
||||||
|
Helper helper, final Subchannel subchannel, final List<EquivalentAddressGroup> addrs) {
|
||||||
|
helper.getSynchronizationContext().execute(
|
||||||
|
new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
subchannel.updateAddresses(addrs);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private static void shutdownSafely(
|
private static void shutdownSafely(
|
||||||
final Helper helper, final Subchannel subchannel) {
|
final Helper helper, final Subchannel subchannel) {
|
||||||
helper.getSynchronizationContext().execute(
|
helper.getSynchronizationContext().execute(
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,7 @@ public class PickFirstLoadBalancerTest {
|
||||||
verify(mockSubchannel).requestConnection();
|
verify(mockSubchannel).requestConnection();
|
||||||
loadBalancer.handleResolvedAddresses(
|
loadBalancer.handleResolvedAddresses(
|
||||||
ResolvedAddresses.newBuilder().setAddresses(servers).setAttributes(affinity).build());
|
ResolvedAddresses.newBuilder().setAddresses(servers).setAttributes(affinity).build());
|
||||||
|
verify(mockSubchannel).updateAddresses(eq(servers));
|
||||||
verifyNoMoreInteractions(mockSubchannel);
|
verifyNoMoreInteractions(mockSubchannel);
|
||||||
|
|
||||||
verify(mockHelper).createSubchannel(createArgsCaptor.capture());
|
verify(mockHelper).createSubchannel(createArgsCaptor.capture());
|
||||||
|
|
@ -179,8 +180,7 @@ public class PickFirstLoadBalancerTest {
|
||||||
verify(mockHelper)
|
verify(mockHelper)
|
||||||
.updateBalancingState(isA(ConnectivityState.class), isA(SubchannelPicker.class));
|
.updateBalancingState(isA(ConnectivityState.class), isA(SubchannelPicker.class));
|
||||||
// Updating the subchannel addresses is unnecessary, but doesn't hurt anything
|
// Updating the subchannel addresses is unnecessary, but doesn't hurt anything
|
||||||
verify(mockHelper).updateSubchannelAddresses(
|
verify(mockSubchannel).updateAddresses(ArgumentMatchers.<EquivalentAddressGroup>anyList());
|
||||||
eq(mockSubchannel), ArgumentMatchers.<EquivalentAddressGroup>anyList());
|
|
||||||
|
|
||||||
verifyNoMoreInteractions(mockHelper);
|
verifyNoMoreInteractions(mockHelper);
|
||||||
}
|
}
|
||||||
|
|
@ -191,7 +191,7 @@ public class PickFirstLoadBalancerTest {
|
||||||
List<EquivalentAddressGroup> newServers =
|
List<EquivalentAddressGroup> newServers =
|
||||||
Lists.newArrayList(new EquivalentAddressGroup(socketAddr));
|
Lists.newArrayList(new EquivalentAddressGroup(socketAddr));
|
||||||
|
|
||||||
InOrder inOrder = inOrder(mockHelper);
|
InOrder inOrder = inOrder(mockHelper, mockSubchannel);
|
||||||
|
|
||||||
loadBalancer.handleResolvedAddresses(
|
loadBalancer.handleResolvedAddresses(
|
||||||
ResolvedAddresses.newBuilder().setAddresses(servers).setAttributes(affinity).build());
|
ResolvedAddresses.newBuilder().setAddresses(servers).setAttributes(affinity).build());
|
||||||
|
|
@ -205,7 +205,7 @@ public class PickFirstLoadBalancerTest {
|
||||||
|
|
||||||
loadBalancer.handleResolvedAddresses(
|
loadBalancer.handleResolvedAddresses(
|
||||||
ResolvedAddresses.newBuilder().setAddresses(newServers).setAttributes(affinity).build());
|
ResolvedAddresses.newBuilder().setAddresses(newServers).setAttributes(affinity).build());
|
||||||
inOrder.verify(mockHelper).updateSubchannelAddresses(eq(mockSubchannel), eq(newServers));
|
inOrder.verify(mockSubchannel).updateAddresses(eq(newServers));
|
||||||
|
|
||||||
verifyNoMoreInteractions(mockSubchannel);
|
verifyNoMoreInteractions(mockSubchannel);
|
||||||
verifyNoMoreInteractions(mockHelper);
|
verifyNoMoreInteractions(mockHelper);
|
||||||
|
|
|
||||||
|
|
@ -438,7 +438,7 @@ final class GrpclbState {
|
||||||
} else {
|
} else {
|
||||||
checkState(subchannels.size() == 1, "Unexpected Subchannel count: %s", subchannels);
|
checkState(subchannels.size() == 1, "Unexpected Subchannel count: %s", subchannels);
|
||||||
subchannel = subchannels.values().iterator().next();
|
subchannel = subchannels.values().iterator().next();
|
||||||
helper.updateSubchannelAddresses(subchannel, eagList);
|
subchannel.updateAddresses(eagList);
|
||||||
}
|
}
|
||||||
subchannels = Collections.singletonMap(eagList, subchannel);
|
subchannels = Collections.singletonMap(eagList, subchannel);
|
||||||
newBackendList.add(
|
newBackendList.add(
|
||||||
|
|
|
||||||
|
|
@ -1776,8 +1776,7 @@ public class GrpclbLoadBalancerTest {
|
||||||
// createSubchannel() has ever been called only once
|
// createSubchannel() has ever been called only once
|
||||||
verify(helper, times(1)).createSubchannel(any(List.class), any(Attributes.class));
|
verify(helper, times(1)).createSubchannel(any(List.class), any(Attributes.class));
|
||||||
assertThat(mockSubchannels).isEmpty();
|
assertThat(mockSubchannels).isEmpty();
|
||||||
inOrder.verify(helper).updateSubchannelAddresses(
|
verify(subchannel).updateAddresses(
|
||||||
same(subchannel),
|
|
||||||
eq(Arrays.asList(
|
eq(Arrays.asList(
|
||||||
new EquivalentAddressGroup(backends2.get(0).addr, eagAttrsWithToken("token0001")),
|
new EquivalentAddressGroup(backends2.get(0).addr, eagAttrsWithToken("token0001")),
|
||||||
new EquivalentAddressGroup(backends2.get(2).addr,
|
new EquivalentAddressGroup(backends2.get(2).addr,
|
||||||
|
|
@ -1874,8 +1873,7 @@ public class GrpclbLoadBalancerTest {
|
||||||
// createSubchannel() has ever been called only once
|
// createSubchannel() has ever been called only once
|
||||||
verify(helper, times(1)).createSubchannel(any(List.class), any(Attributes.class));
|
verify(helper, times(1)).createSubchannel(any(List.class), any(Attributes.class));
|
||||||
assertThat(mockSubchannels).isEmpty();
|
assertThat(mockSubchannels).isEmpty();
|
||||||
inOrder.verify(helper).updateSubchannelAddresses(
|
verify(subchannel).updateAddresses(
|
||||||
same(subchannel),
|
|
||||||
eq(Arrays.asList(
|
eq(Arrays.asList(
|
||||||
new EquivalentAddressGroup(backends1.get(0).addr, eagAttrsWithToken("token0001")),
|
new EquivalentAddressGroup(backends1.get(0).addr, eagAttrsWithToken("token0001")),
|
||||||
new EquivalentAddressGroup(backends1.get(1).addr,
|
new EquivalentAddressGroup(backends1.get(1).addr,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue