[GitHub] [kafka] cmccabe commented on a diff in pull request #13153: MINOR: startup timeouts for KRaft integration tests

2023-01-27 Thread via GitHub


cmccabe commented on code in PR #13153:
URL: https://github.com/apache/kafka/pull/13153#discussion_r1089524563


##
clients/src/main/java/org/apache/kafka/common/utils/Time.java:
##
@@ -86,4 +89,30 @@ default Timer timer(Duration timeout) {
 return timer(timeout.toMillis());
 }
 
+/**
+ * Wait for a future to complete, or time out.
+ *
+ * @param futureThe future to wait for.
+ * @param deadlineNsThe time in the future, in monotonic nanoseconds, 
to time out.
+ * @return  The result of the future.
+ * @paramThe type of the future.
+ */
+default  T waitForFuture(
+CompletableFuture future,
+long deadlineNs

Review Comment:
   Can't use that here since `:clients` doesn't depend on `:server-common`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [kafka] cmccabe commented on a diff in pull request #13153: MINOR: startup timeouts for KRaft integration tests

2023-01-27 Thread via GitHub


cmccabe commented on code in PR #13153:
URL: https://github.com/apache/kafka/pull/13153#discussion_r1089524442


##
server-common/src/main/java/org/apache/kafka/server/util/Deadline.java:
##
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.util;
+
+import org.apache.kafka.common.utils.Time;
+
+import java.math.BigInteger;
+import java.util.Date;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+
+
+public class Deadline {
+private final long nanoseconds;
+
+public static Deadline fromMonotonicNanoseconds(
+long nanoseconds
+) {
+return new Deadline(nanoseconds);
+}
+
+public static Deadline fromDelay(
+Time time,
+long delay,
+TimeUnit timeUnit
+) {
+return fromDelay(time.nanoseconds(), delay, timeUnit);
+}
+
+public static Deadline fromDelay(

Review Comment:
   I'll remove it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [kafka] cmccabe commented on a diff in pull request #13153: MINOR: startup timeouts for KRaft integration tests

2023-01-27 Thread via GitHub


cmccabe commented on code in PR #13153:
URL: https://github.com/apache/kafka/pull/13153#discussion_r1089352604


##
core/src/main/scala/kafka/server/KafkaConfig.scala:
##
@@ -1153,6 +1157,8 @@ object KafkaConfig {
   .define(MetadataMaxRetentionBytesProp, LONG, 
Defaults.MetadataMaxRetentionBytes, null, HIGH, MetadataMaxRetentionBytesDoc)
   .define(MetadataMaxRetentionMillisProp, LONG, 
LogConfig.DEFAULT_RETENTION_MS, null, HIGH, MetadataMaxRetentionMillisDoc)
   .define(MetadataMaxIdleIntervalMsProp, INT, 
Defaults.MetadataMaxIdleIntervalMs, atLeast(0), LOW, 
MetadataMaxIdleIntervalMsDoc)
+  .defineInternal(BrokerServerMaxStartupTimeMs, LONG, 
Defaults.BrokerServerMaxStartupTimeMs, atLeast(0), MEDIUM, 
BrokerServerMaxStartupTimeMsDoc)

Review Comment:
   yeah



##
server-common/src/main/java/org/apache/kafka/server/util/FutureUtils.java:
##
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.server.util;
+
+import org.apache.kafka.common.utils.Time;
+import org.slf4j.Logger;
+
+import java.math.BigInteger;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeoutException;
+
+
+public class FutureUtils {
+/**
+ * Based on the current time and a delay, computes a monotonic deadline in 
the future.
+ *
+ * @param nowNs The current time in monotonic nanoseconds.
+ * @param delayMs   The delay in milliseconds.
+ * @return  The monotonic deadline in the future. This value is 
capped at
+ *  Long.MAX_VALUE.
+ */
+public static long getDeadlineNsFromDelayMs(
+long nowNs,
+long delayMs
+) {
+if (delayMs < 0) {
+throw new RuntimeException("Negative delays are not allowed.");
+}
+BigInteger delayNs = 
BigInteger.valueOf(delayMs).multiply(BigInteger.valueOf(1_000_000));
+BigInteger deadlineNs = BigInteger.valueOf(nowNs).add(delayNs);
+if (deadlineNs.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) >= 0) {
+return Long.MAX_VALUE;
+} else {
+return deadlineNs.longValue();
+}
+}
+
+/**
+ * Wait for a future until a specific time in the future, with copious 
logging.
+ *
+ * @param log   The slf4j object to use to log success and failure.
+ * @param actionThe action we are waiting for.
+ * @param futureThe future we are waiting for.
+ * @param deadlineNsThe deadline in the future we are waiting for.
+ * @param time  The clock object.
+ * @return  The result of the future.
+ * @paramThe type of the future.
+ *
+ * @throws java.util.concurrent.TimeoutException If the future times out.
+ * @throws Throwable If the future fails. Note: we unwrap 
ExecutionException here.
+ */
+public static  T waitWithLogging(
+Logger log,
+String action,
+CompletableFuture future,
+long deadlineNs,

Review Comment:
   I will create a Deadline class to help with this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



[GitHub] [kafka] cmccabe commented on a diff in pull request #13153: MINOR: startup timeouts for KRaft integration tests

2023-01-27 Thread via GitHub


cmccabe commented on code in PR #13153:
URL: https://github.com/apache/kafka/pull/13153#discussion_r1089313497


##
clients/src/main/java/org/apache/kafka/common/utils/Time.java:
##
@@ -86,4 +89,30 @@ default Timer timer(Duration timeout) {
 return timer(timeout.toMillis());
 }
 
+/**
+ * Wait for a future to complete, or time out.
+ *
+ * @param futureThe future to wait for.
+ * @param deadlineNsThe time in the future, in monotonic nanoseconds, 
to time out.
+ * @return  The result of the future.
+ * @paramThe type of the future.
+ */
+default  T waitForFuture(
+CompletableFuture future,
+long deadlineNs
+) throws TimeoutException, InterruptedException, ExecutionException  {
+TimeoutException timeoutException = null;
+while (true) {

Review Comment:
   It's a bit unclear. It's traditional for condition variables to allow 
spurious wakeups, and probably this is implemented with a condition variable. 
The JavaDoc for `get` just says that it will wait "at most the given time" 
which doesn't really clarify matters. In any case, the loop certainly does no 
harm.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org