You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/10/21 08:13:42 UTC

[GitHub] [flink] tillrohrmann commented on a change in pull request #13711: [FLINK-19721] [flink-runtime] Support exponential backoff retries in RpcGatewayRetriever

tillrohrmann commented on a change in pull request #13711:
URL: https://github.com/apache/flink/pull/13711#discussion_r509064348



##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/concurrent/ExponentialBackoffRetryStrategy.java
##########
@@ -0,0 +1,64 @@
+/*
+ * 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.flink.runtime.concurrent;
+
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.util.Preconditions;
+
+/**
+ * An implementation of {@link RetryStrategy} that retries that has an exponential backoff with
+ * a cap.
+ */
+public class ExponentialBackoffRetryStrategy implements RetryStrategy {
+	private final int remainingRetries;
+	private final Time currentRetryDelay;
+	private final Time maxRetryDelay;
+
+	/**
+	 * @param remainingRetries number of times to retry
+	 * @param currentRetryDelay the current delay between retries
+	 * @param maxRetryDelay the max delay between retries
+	 */
+	public ExponentialBackoffRetryStrategy(int remainingRetries, Time currentRetryDelay, Time maxRetryDelay) {

Review comment:
       I know that we use `Time` at many places but it is better now to use `java.time.Duration` because `Time` is actually an API class.

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/webmonitor/retriever/impl/RpcGatewayRetriever.java
##########
@@ -42,24 +44,26 @@
 	private final RpcService rpcService;
 	private final Class<T> gatewayType;
 	private final Function<UUID, F> fencingTokenMapper;
-
-	private final int retries;
-	private final Time retryDelay;
+	private final RetryStrategy retryStrategy;
 
 	public RpcGatewayRetriever(
 			RpcService rpcService,
 			Class<T> gatewayType,
 			Function<UUID, F> fencingTokenMapper,
 			int retries,
 			Time retryDelay) {
-		this.rpcService = Preconditions.checkNotNull(rpcService);
+		this(rpcService, gatewayType, fencingTokenMapper, new FixedRetryStrategy(retries, retryDelay));

Review comment:
       I am wondering whether we shouldn't use the exponential backoff strategy by default.

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/concurrent/RetryStrategy.java
##########
@@ -0,0 +1,41 @@
+/*
+ * 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.flink.runtime.concurrent;
+
+import org.apache.flink.api.common.time.Time;
+
+/**
+ * Interface that encapsulates retry logic.  An instances should be immutable.
+ */
+public interface RetryStrategy {
+	/**
+	 * @return the number of remaining retries
+	 */
+	int getNumRemainingRetries();
+
+	/**
+	 * @return the current delay if we need to retry
+	 */
+	Time getRetryDelay();

Review comment:
       ```suggestion
   	Duration getRetryDelay();
   ```

##########
File path: flink-runtime/src/main/java/org/apache/flink/runtime/concurrent/FixedRetryStrategy.java
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.flink.runtime.concurrent;
+
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.util.Preconditions;
+
+/**
+ * An implementation of {@link RetryStrategy} that retries at a fixed delay.
+ */
+public class FixedRetryStrategy implements RetryStrategy {
+	private final int remainingRetries;
+	private final Time retryDelay;
+
+	/**
+	 * @param remainingRetries number of times to retry
+	 * @param retryDelay delay between retries
+	 */
+	public FixedRetryStrategy(int remainingRetries, Time retryDelay) {

Review comment:
       Same here with `Time`. I think it would be better to let the new components use `java.time.Duration`.




----------------------------------------------------------------
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.

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