summaryrefslogtreecommitdiffstats
path: root/clustercontroller-core
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2022-09-21 11:07:26 +0200
committerHarald Musum <musum@yahooinc.com>2022-09-21 11:07:26 +0200
commit6a1f9324121ae141c7ad1b7db290fcf25b261750 (patch)
treeaf04ad99bd55f5f5ce673918b3aebf192a2d4618 /clustercontroller-core
parent8a8beeb565815fb71ce8c93cc70c1fc189a53216 (diff)
Make sure we don't call wait() with 0 as argument
wait(0) will wait indefinitely
Diffstat (limited to 'clustercontroller-core')
-rw-r--r--clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/FleetControllerOptions.java3
-rw-r--r--clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/StateWaiter.java11
-rw-r--r--clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/Waiter.java4
3 files changed, 11 insertions, 7 deletions
diff --git a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/FleetControllerOptions.java b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/FleetControllerOptions.java
index 7d2b540c97e..c645c2005b0 100644
--- a/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/FleetControllerOptions.java
+++ b/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/FleetControllerOptions.java
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.core;
+import ai.vespa.validation.Validation;
import com.yahoo.jrt.slobrok.api.BackOffPolicy;
import com.yahoo.vdslib.distribution.ConfiguredNode;
import com.yahoo.vdslib.distribution.Distribution;
@@ -194,7 +195,7 @@ public class FleetControllerOptions {
this.minRatioOfDistributorNodesUp = minRatioOfDistributorNodesUp;
this.minRatioOfStorageNodesUp = minRatioOfStorageNodesUp;
this.minNodeRatioPerGroup = minNodeRatioPerGroup;
- this.cycleWaitTime = cycleWaitTime;
+ this.cycleWaitTime = Validation.requireAtLeast(cycleWaitTime, "cycleWaitTime must be positive", 1);
this.minTimeBeforeFirstSystemStateBroadcast = minTimeBeforeFirstSystemStateBroadcast;
this.nodeStateRequestTimeoutMS = nodeStateRequestTimeoutMS;
this.nodeStateRequestTimeoutEarliestPercentage = nodeStateRequestTimeoutEarliestPercentage;
diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/StateWaiter.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/StateWaiter.java
index d131c330381..32c4ee99c3c 100644
--- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/StateWaiter.java
+++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/StateWaiter.java
@@ -62,7 +62,7 @@ public class StateWaiter implements SystemStateListener {
}
/**
- * WARNING: If timeIntervalToProvokeRetry is set != 0 that means time will can be set far into future
+ * WARNING: If timeIntervalToProvokeRetry is set != 0 that means time will be set far into the future
* and thus hit various unintended timeout periods. Only auto-step time if this is a non-issue.
*/
public void waitForState(String stateRegex, long timeout, long timeIntervalToProvokeRetry) {
@@ -82,9 +82,10 @@ public class StateWaiter implements SystemStateListener {
return;
}
}
- try{
+ try {
if (timeIntervalToProvokeRetry == 0) {
- timer.wait(endTime - startTime);
+ var waitTime = Math.max(1, endTime - startTime);
+ timer.wait(waitTime);
} else {
if (++iteration % 10 == 0) {
timer.advanceTime(timeIntervalToProvokeRetry);
@@ -92,10 +93,10 @@ public class StateWaiter implements SystemStateListener {
timer.wait(10);
}
} catch (InterruptedException e) {
+ throw new RuntimeException(e);
}
}
- startTime = System.currentTimeMillis();
- if (startTime >= endTime) {
+ if (System.currentTimeMillis() >= endTime) {
throw new IllegalStateException("Timeout. Did not find a state matching " + stateRegex + " within timeout of " + timeout + " milliseconds. Current state is " + currentClusterState);
}
}
diff --git a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/Waiter.java b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/Waiter.java
index 5bff101906d..4f79500e84d 100644
--- a/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/Waiter.java
+++ b/clustercontroller-core/src/test/java/com/yahoo/vespa/clustercontroller/core/testutils/Waiter.java
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.core.testutils;
+import ai.vespa.validation.Validation;
import com.yahoo.vdslib.state.ClusterState;
import com.yahoo.vdslib.state.Node;
import com.yahoo.vespa.clustercontroller.core.DummyVdsNode;
@@ -90,6 +91,7 @@ public interface Waiter {
public final void wait(WaitCondition c, WaitTask wt, Duration timeout) {
Objects.requireNonNull(wt, "wait task cannot be null");
+ Validation.requireAtLeast(timeout.toMillis(), "timeout must be positive", 1L);
log.log(Level.INFO, "Waiting for " + c + " with wait task " + wt);
Instant endTime = Instant.now().plus(timeout);
@@ -112,7 +114,7 @@ public interface Waiter {
allowWait = false;
}
Duration timeLeft = Duration.between(Instant.now(), endTime);
- if (timeLeft.isNegative())
+ if (timeLeft.isNegative() || timeLeft.isZero())
throw new IllegalStateException("Timed out waiting max " + timeout + " ms for " + c + "\n with wait task " + wt + ",\n reason: " + reason);
if (allowWait)
data.getMonitor().wait(Math.min(wt.getWaitTaskFrequencyInMillis(), timeLeft.toMillis()));