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



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/DefaultDeclareResourceRequirementServiceConnectionManager.java
##########
@@ -0,0 +1,106 @@
+/*
+ * 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.jobmaster.slotpool;
+
+import org.apache.flink.runtime.concurrent.ExponentialBackoffRetryStrategy;
+import org.apache.flink.runtime.concurrent.FutureUtils;
+import org.apache.flink.runtime.concurrent.ScheduledExecutor;
+import org.apache.flink.runtime.messages.Acknowledge;
+import org.apache.flink.runtime.slots.ResourceRequirements;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+import javax.annotation.concurrent.GuardedBy;
+
+import java.time.Duration;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * Default implementation of {@link 
DeclareResourceRequirementServiceConnectionManager}.
+ *
+ * <p>This connection manager is responsible for sending new
+ * resource requirements to the connected service. In case of faults it 
continues
+ * retrying to send the latest resource requirements to the service with
+ * an exponential backoff strategy.
+ */
+class DefaultDeclareResourceRequirementServiceConnectionManager
+               extends 
AbstractServiceConnectionManager<DeclareResourceRequirementServiceConnectionManager.DeclareResourceRequirementsService>
+               implements DeclareResourceRequirementServiceConnectionManager {
+
+       private static final Logger LOG = 
LoggerFactory.getLogger(DefaultDeclareResourceRequirementServiceConnectionManager.class);
+
+       private final ScheduledExecutor scheduledExecutor;
+
+       @Nullable
+       @GuardedBy("lock")
+       private ResourceRequirements currentResourceRequirements;
+
+       private 
DefaultDeclareResourceRequirementServiceConnectionManager(ScheduledExecutor 
scheduledExecutor) {
+               this.scheduledExecutor = scheduledExecutor;
+       }
+
+       @Override
+       public void declareResourceRequirements(ResourceRequirements 
resourceRequirements) {
+               synchronized (lock) {
+                       checkNotClosed();
+                       if (isConnected()) {
+                               currentResourceRequirements = 
resourceRequirements;
+
+                               
triggerResourceRequirementsSubmission(Duration.ofMillis(1L), 
Duration.ofMillis(10000L), currentResourceRequirements);
+                       }
+               }
+       }
+
+       @GuardedBy("lock")
+       private void triggerResourceRequirementsSubmission(
+                       Duration sleepOnError,
+                       Duration maxSleepOnError,
+                       ResourceRequirements resourceRequirementsToSend) {
+
+               FutureUtils.retryWithDelay(
+                               () -> 
sendResourceRequirements(resourceRequirementsToSend),
+                               new 
ExponentialBackoffRetryStrategy(Integer.MAX_VALUE, sleepOnError, 
maxSleepOnError),
+                               throwable -> !(throwable instanceof 
CancellationException),
+                               scheduledExecutor);
+       }
+
+       @GuardedBy("lock")

Review comment:
       I think this annotation is wrong. `sendResourceRequirements` is not be 
guarded by `lock`. See `FutureUtils.retryWithDelay(() -> 
sendResourceRequirements,....)`.

##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/AbstractServiceConnectionManagerTest.java
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.jobmaster.slotpool;
+
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for the {@link 
DefaultDeclareResourceRequirementServiceConnectionManager}.
+ */
+public class AbstractServiceConnectionManagerTest extends TestLogger {
+
+       @Test
+       public void testIsConnected() {
+               AbstractServiceConnectionManager<Object> connectionManager = 
new TestServiceConnectionManager();
+
+               assertThat(connectionManager.isConnected(), is(false));
+
+               connectionManager.connect(new Object());
+               assertThat(connectionManager.isConnected(), is(true));
+
+               connectionManager.disconnect();
+               assertThat(connectionManager.isConnected(), is(false));
+
+               connectionManager.close();
+               assertThat(connectionManager.isConnected(), is(false));
+       }
+
+       @Test
+       public void testCheckNotClosed() {
+               AbstractServiceConnectionManager<Object> connectionManager = 
new TestServiceConnectionManager();
+
+               connectionManager.checkNotClosed();
+
+               connectionManager.connect(new Object());
+               connectionManager.checkNotClosed();
+
+               connectionManager.disconnect();
+               connectionManager.checkNotClosed();
+
+               connectionManager.close();
+               try {
+                       connectionManager.checkNotClosed();

Review comment:
       `fail` is missing here.




----------------------------------------------------------------
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:
[email protected]


Reply via email to