Skip to content
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

loadbalancer-experimental: javadoc cleanup and minor fixes #3138

Merged
merged 4 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more adjustments
  • Loading branch information
idelpivnitskiy committed Dec 13, 2024
commit 98f90de7cd92e5f3331a863e52d8b2ff6adb5292
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ abstract class BaseHostSelector<ResolvedAddress, C extends LoadBalancedConnectio
this.lbDescription = requireNonNull(lbDescription, "lbDescription");
}

protected abstract Single<C> selectConnection0(Predicate<C> selector, @Nullable ContextMap context,
boolean forceNewConnectionAndReserve);
abstract Single<C> selectConnection0(Predicate<C> selector, @Nullable ContextMap context,
boolean forceNewConnectionAndReserve);

@Override
public final Single<C> selectConnection(Predicate<C> selector, @Nullable ContextMap context,
Expand All @@ -60,23 +60,23 @@ public final boolean isHealthy() {
return anyHealthy(hosts);
}

protected final List<? extends Host<ResolvedAddress, C>> hosts() {
final List<? extends Host<ResolvedAddress, C>> hosts() {
return hosts;
}

protected final String lbDescription() {
final String lbDescription() {
return lbDescription;
}

protected final Single<C> noActiveHostsFailure(List<? extends Host<ResolvedAddress, C>> usedHosts) {
final Single<C> noActiveHostsFailure(List<? extends Host<ResolvedAddress, C>> usedHosts) {
return failed(Exceptions.StacklessNoActiveHostException.newInstance(
lbDescription() + ": Failed to pick an active host. Either all are busy, expired, or unhealthy: " +
usedHosts, this.getClass(), "selectConnection(...)"));
}

// This method assumes the host is considered healthy.
@Nullable
protected final Single<C> selectFromHost(Host<ResolvedAddress, C> host, Predicate<C> selector,
final Single<C> selectFromHost(Host<ResolvedAddress, C> host, Predicate<C> selector,
boolean forceNewConnectionAndReserve, @Nullable ContextMap contextMap) {
// First see if we can get an existing connection regardless of health status.
if (!forceNewConnectionAndReserve) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ abstract class DefaultRequestTracker implements RequestTracker, ScoreSupplier {
* The current time in nanoseconds.
* @return the current time in nanoseconds.
*/
protected abstract long currentTimeNanos();
abstract long currentTimeNanos();

@Override
public final long beforeRequestStart() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,9 @@ public LoadBalancerBuilder<ResolvedAddress, C> connectionPoolPolicy(
public LoadBalancerFactory<ResolvedAddress, C> build() {
return delegate.build();
}

@Override
public String toString() {
return this.getClass().getSimpleName() + "{delegate=" + delegate() + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
import io.servicetalk.concurrent.Cancellable;

/**
* An abstraction used by a {@link Host} to interact with the {@link OutlierDetector} currently monitoring
* the host.
* An abstraction used by a {@link Host} to interact with the {@link OutlierDetector} currently monitoring the host.
* <p>
* This abstraction serves as a sort of two-way channel between a host and the health check system: the
* health check system can give the host information about it's perceived health and the host can give the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Single<C> selectConnection(Predicate<C> selector, @Nullable ContextMap context,

/**
* The size of the host candidate pool for this host selector.
* <p>
* Note that this is primarily for observability purposes.
* @return the size of the host candidate pool for this host selector.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
/**
* Provider for {@link LoadBalancerBuilder} that can be registered using {@link java.util.ServiceLoader}.
*/
@FunctionalInterface
public interface LoadBalancerBuilderProvider {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void onConnectError(long beforeConnectStart, ConnectTracker.ErrorClass er
}

@Override
protected long currentTimeNanos() {
long currentTimeNanos() {
return executor.currentTime(TimeUnit.NANOSECONDS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public HostSelector<ResolvedAddress, C> rebuildWithHosts(List<? extends Host<Res
}

@Override
protected Single<C> selectConnection0(Predicate<C> selector, @Nullable ContextMap context,
boolean forceNewConnectionAndReserve) {
Single<C> selectConnection0(final Predicate<C> selector, @Nullable final ContextMap context,
final boolean forceNewConnectionAndReserve) {
final int size = hostSetSize();
switch (size) {
case 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ public Status status() {
* The relative weight this endpoint should be given for load balancing decisions.
* @return the relative weight this endpoint should be given for load balancing decisions.
*/
public double loadBalancingWeight() {
double loadBalancingWeight() {
return weight;
}

/**
* Priority group this endpoint belongs to.
* @return the priority group this endpoint belongs to.
*/
public int priority() {
int priority() {
return priority;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public RoundRobinLoadBalancingPolicyBuilder ignoreWeights(final boolean ignoreWe
* @param <C> the refined type of the {@link LoadBalancedConnection}.
* @return the concrete {@link RoundRobinLoadBalancingPolicy}.
*/
public <ResolvedAddress, C extends LoadBalancedConnection> LoadBalancingPolicy<ResolvedAddress, C>
build() {
public <ResolvedAddress, C extends LoadBalancedConnection> LoadBalancingPolicy<ResolvedAddress, C> build() {
return new RoundRobinLoadBalancingPolicy<>(failOpen, ignoreWeights);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ final class RoundRobinSelector<ResolvedAddress, C extends LoadBalancedConnection
}

@Override
protected Single<C> selectConnection0(
final Predicate<C> selector, @Nullable final ContextMap context,
final boolean forceNewConnectionAndReserve) {
Single<C> selectConnection0(final Predicate<C> selector, @Nullable final ContextMap context,
final boolean forceNewConnectionAndReserve) {
// try one loop over hosts and if all are expired, give up
final int cursor = scheduler.nextHost();
Host<ResolvedAddress, C> failOpenHost = null;
Expand Down Expand Up @@ -141,7 +140,7 @@ private static Scheduler buildScheduler(AtomicInteger index, List<? extends Host
private abstract static class Scheduler {

private final AtomicInteger index;
protected final int hostsSize;
final int hostsSize;

Scheduler(final AtomicInteger index, final int hostsSize) {
this.index = index;
Expand All @@ -151,7 +150,7 @@ private abstract static class Scheduler {
// Get the index of the next host
abstract int nextHost();

protected final long nextIndex() {
final long nextIndex() {
return Integer.toUnsignedLong(index.getAndIncrement());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ interface ExceptionHandler {
this.exceptionHandler = requireNonNull(exceptionHandler, "exceptionHandler");
}

public boolean isCurrentThreadDraining() {
boolean isCurrentThreadDraining() {
// Even though `currentDrainingThread` is not a volatile field this is thread safe:
// the only way that `currentDrainingThread` will ever equal this thread, even if
// we get a stale value, is if _this_ thread set it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,26 @@ abstract class XdsHealthIndicator<ResolvedAddress, C extends LoadBalancedConnect
* Get the current configuration.
* @return the current configuration.
*/
protected abstract OutlierDetectorConfig currentConfig();
abstract OutlierDetectorConfig currentConfig();

/**
* Attempt to mark the host as ejected with the parent XDS health checker.
* @return whether this host was successfully ejected.
*/
protected abstract boolean tryEjectHost();
abstract boolean tryEjectHost();

/**
* Alert the parent {@link XdsOutlierDetector} that this host has transitions from healthy to unhealthy.
*/
protected abstract void hostRevived();
abstract void hostRevived();

/**
* Alert the parent {@link XdsOutlierDetector} that this {@link HealthIndicator} is no longer being used.
*/
protected abstract void doCancel();
abstract void doCancel();

@Override
protected final long currentTimeNanos() {
final long currentTimeNanos() {
return executor.currentTime(TimeUnit.NANOSECONDS);
}

Expand Down Expand Up @@ -197,14 +197,14 @@ private void doOnError(boolean isCancellation) {
}
}

public final void forceRevival() {
final void forceRevival() {
assert sequentialExecutor.isCurrentThreadDraining();
if (!cancelled && evictedUntilNanos != null) {
sequentialRevive();
}
}

public final boolean updateOutlierStatus(OutlierDetectorConfig config, boolean isOutlier) {
final boolean updateOutlierStatus(OutlierDetectorConfig config, boolean isOutlier) {
assert sequentialExecutor.isCurrentThreadDraining();
if (cancelled) {
return false;
Expand Down Expand Up @@ -239,16 +239,16 @@ public final boolean updateOutlierStatus(OutlierDetectorConfig config, boolean i
}
}

public final void resetCounters() {
final void resetCounters() {
successes.set(0);
failures.set(0);
}

public final long getSuccesses() {
final long getSuccesses() {
return successes.get();
}

public final long getFailures() {
final long getFailures() {
return failures.get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private final class XdsHealthIndicatorImpl extends XdsHealthIndicator<ResolvedAd
}

@Override
protected OutlierDetectorConfig currentConfig() {
OutlierDetectorConfig currentConfig() {
return kernel.config;
}

Expand Down
Loading