Skip to content

Commit

Permalink
loadbalancer: Some style cleanups for the new LB (#2748)
Browse files Browse the repository at this point in the history
Motivation:

There are some style and naming inconsistencies that
can be cleaned up.

Modifications:

- rename `BaseSelector.noActiveHostsException` to `noActiveHosts`.
- Enforce constructor arguments to be non-null in `DefaultHost`.
  • Loading branch information
bryce-anderson authored Nov 9, 2023
1 parent 34da727 commit b42e9c4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected final String getTargetResource() {
return targetResource;
}

protected final Single<C> noActiveHostsException(List<Host<ResolvedAddress, C>> usedHosts) {
protected final Single<C> noActiveHosts(List<Host<ResolvedAddress, C>> usedHosts) {
return failed(Exceptions.StacklessNoActiveHostException.newInstance("Failed to pick an active host for " +
getTargetResource() + ". Either all are busy, expired, or unhealthy: " + usedHosts,
this.getClass(), "selectConnection(...)"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import static io.servicetalk.concurrent.api.Single.succeeded;
import static io.servicetalk.concurrent.internal.FlowControlUtils.addWithOverflowProtection;
import static java.lang.Math.min;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater;
import static java.util.stream.Collectors.toList;

Expand Down Expand Up @@ -99,13 +100,14 @@ private enum State {
private final ListenableAsyncCloseable closeable;
private volatile ConnState connState = ACTIVE_EMPTY_CONN_STATE;

DefaultHost(String lbDescription, Addr address, ConnectionFactory<Addr, ? extends C> connectionFactory,
DefaultHost(final String lbDescription, final Addr address,
final ConnectionFactory<Addr, ? extends C> connectionFactory,
int linearSearchSpace, @Nullable HealthCheckConfig healthCheckConfig) {
this.lbDescription = lbDescription;
this.address = address;
this.healthCheckConfig = healthCheckConfig;
this.connectionFactory = connectionFactory;
this.lbDescription = requireNonNull(lbDescription, "lbDescription");
this.address = requireNonNull(address, "address");
this.linearSearchSpace = linearSearchSpace;
this.connectionFactory = requireNonNull(connectionFactory, "connectionFactory");
this.healthCheckConfig = healthCheckConfig;
this.closeable = toAsyncCloseable(graceful ->
graceful ? doClose(AsyncCloseable::closeAsyncGracefully) : doClose(AsyncCloseable::closeAsync));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Single<C> selectConnection(
// try to make a new one if the host is healthy. If it's not healthy, we fail
// and let the higher level retries decide what to do.
if (!host.isActiveAndHealthy()) {
return noActiveHostsException(hosts);
return noActiveHosts(hosts);
}
return host.newConnection(selector, forceNewConnectionAndReserve, context);
default:
Expand Down Expand Up @@ -127,7 +127,7 @@ private Single<C> p2c(int size, List<Host<ResolvedAddress, C>> hosts, Random ran
// Neither are healthy and capable of making a connection: fall through, perhaps for another attempt.
}
// Max effort exhausted. We failed to find a healthy and active host.
return noActiveHostsException(hosts);
return noActiveHosts(hosts);
}

private Random getRandom() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Single<C> selectConnection(
}
}
if (pickedHost == null) {
return noActiveHostsException(usedHosts);
return noActiveHosts(usedHosts);
}
// We have a host but no connection was selected: create a new one.
return pickedHost.newConnection(selector, forceNewConnectionAndReserve, context);
Expand Down

0 comments on commit b42e9c4

Please sign in to comment.