diff options
author | jonmv <venstad@gmail.com> | 2022-04-29 06:54:10 +0200 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2022-04-29 06:54:10 +0200 |
commit | 25a7bd67a5713646c40938738d4956f9ccd563c5 (patch) | |
tree | ea23f759ab9823e952c3fff27d07bd58f4e7150a /orchestrator | |
parent | e8e9cd5d722af2efa5489b9eb4a17aa4b58303a4 (diff) |
Support dynamic queries instead
Diffstat (limited to 'orchestrator')
2 files changed, 28 insertions, 29 deletions
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClientImpl.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClientImpl.java index 211b9f9ff0a..76f2af43579 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClientImpl.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/ClusterControllerClientImpl.java @@ -30,6 +30,7 @@ import java.io.UncheckedIOException; import java.net.URI; import java.util.Iterator; import java.util.List; +import java.util.stream.Collectors; import static java.nio.charset.StandardCharsets.UTF_8; @@ -59,9 +60,11 @@ public class ClusterControllerClientImpl implements ClusterControllerClient { @Override public boolean setNodeState(OrchestratorContext context, HostName host, int storageNodeIndex, ClusterControllerNodeState wantedState) { try { - Inspector response = client.send(strategyWithTimeout(hosts, context.getClusterControllerTimeouts()), Method.POST) + ClusterControllerClientTimeouts timeouts = context.getClusterControllerTimeouts(); + Inspector response = client.send(strategy(hosts), Method.POST) .at("cluster", "v2", clusterName, "storage", Integer.toString(storageNodeIndex)) - .deadline(context.getClusterControllerTimeouts().readBudget()) + .deadline(timeouts.readBudget()) + .parameters(() -> deadline(timeouts)) .body(stateChangeRequestBytes(wantedState, Condition.SAFE, context.isProbe())) .throwing(retryOnRedirect) .read(SlimeUtils::jsonToSlime).get(); @@ -105,9 +108,11 @@ public class ClusterControllerClientImpl implements ClusterControllerClient { public void setApplicationState(OrchestratorContext context, ApplicationInstanceId applicationId, ClusterControllerNodeState wantedState) throws ApplicationStateChangeDeniedException { try { - Inspector response = client.send(strategyWithTimeout(hosts, context.getClusterControllerTimeouts()), Method.POST) + ClusterControllerClientTimeouts timeouts = context.getClusterControllerTimeouts(); + Inspector response = client.send(strategy(hosts), Method.POST) .at("cluster", "v2", clusterName) - .deadline(context.getClusterControllerTimeouts().readBudget()) + .deadline(timeouts.readBudget()) + .parameters(() -> deadline(timeouts)) .body(stateChangeRequestBytes(wantedState, Condition.FORCE, false)) .throwing(retryOnRedirect) .read(SlimeUtils::jsonToSlime).get(); @@ -142,21 +147,24 @@ public class ClusterControllerClientImpl implements ClusterControllerClient { } /** ᕙ༼◕_◕༽ᕤ hack to vary query parameters with retries ᕙ༼◕_◕༽ᕤ */ - static HostStrategy strategyWithTimeout(List<HostName> hosts, ClusterControllerClientTimeouts timeouts) { - return () -> new Iterator<>() { - final Iterator<HostName> wrapped = hosts.iterator(); - @Override public boolean hasNext() { - return wrapped.hasNext(); - } - @Override public URI next() { - return HttpURL.create(Scheme.http, - DomainName.of(wrapped.next().s()), - 19050, - Path.empty(), - Query.empty().set("timeout", Double.toString(timeouts.getServerTimeoutOrThrow().toMillis() * 1e-3))) - .asURI(); - } - }; + static HostStrategy strategy(List<HostName> hosts) { + return hosts.size() == 1 + // If there's only 1 CC, we'll try that one twice. + ? HostStrategy.repeating(toUrl(hosts.get(0)), 2) + // Otherwise, try each host once: + // * if host 1 responds, it will redirect to master if necessary; otherwise + // * if host 2 responds, it will redirect to master if necessary; otherwise + // * if host 3 responds, it may redirect to master if necessary (if they're up + // after all), but more likely there's no quorum and this will fail too. + : HostStrategy.ordered(hosts.stream().map(ClusterControllerClientImpl::toUrl).collect(Collectors.toList())); + } + + static URI toUrl(HostName host) { + return HttpURL.create(Scheme.http, DomainName.of(host.s()), 19050).asURI(); + } + + static Query deadline(ClusterControllerClientTimeouts timeouts) { + return Query.empty().set("timeout", Double.toString(timeouts.getServerTimeoutOrThrow().toMillis() * 1e-3)); } static final ResponseVerifier retryOnRedirect = new ResponseVerifier() { diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/RetryingClusterControllerClientFactory.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/RetryingClusterControllerClientFactory.java index c98cefc6c86..08cffcc461c 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/RetryingClusterControllerClientFactory.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/controller/RetryingClusterControllerClientFactory.java @@ -35,16 +35,7 @@ public class RetryingClusterControllerClientFactory extends AbstractComponent im @Override public ClusterControllerClient createClient(List<HostName> clusterControllers, String clusterName) { - List<HostName> hosts = clusterControllers.size() == 1 - // If there's only 1 CC, we'll try that one twice. - ? List.of(clusterControllers.get(0), clusterControllers.get(0)) - // Otherwise, try each host once: - // * if host 1 responds, it will redirect to master if necessary; otherwise - // * if host 2 responds, it will redirect to master if necessary; otherwise - // * if host 3 responds, it may redirect to master if necessary (if they're up - // after all), but more likely there's no quorum and this will fail too. - : List.copyOf(clusterControllers); - return new ClusterControllerClientImpl(client, hosts, clusterName); + return new ClusterControllerClientImpl(client, clusterControllers, clusterName); } @Override |