XComp commented on code in PR #28999:
URL: https://github.com/apache/flink/pull/28999#discussion_r3925149227


##########
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/MockRestartingContext.java:
##########


Review Comment:
   The validation logic needs to be updated.



##########
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/MockRestartingContext.java:
##########
@@ -66,9 +66,9 @@ public void setExpectCreatingExecutionGraph() {
         creatingExecutionGraphStateValidator.expectInput(assertNonNull());
     }
 
-    public void setAvailableVertexParallelism(
-            @Nullable VertexParallelism availableVertexParallelism) {
-        this.availableVertexParallelism = availableVertexParallelism;
+    public void setAchievableVertexParallelism(

Review Comment:
   Can we use the same naming pattern in the test code that we use in the 
production code (`vertexParallelismBasedOnFreeSlots`)?



##########
docs/layouts/shortcodes/generated/all_jobmanager_section.html:
##########


Review Comment:
   We should not keep the docs change separate because it's correlated with the 
`JobManagerOptions` change of the previous commit. But that's a quick fix by 
just running squash & rebase on the branch when merging



##########
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/AdaptiveSchedulerRescaleRestartTimingTest.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.scheduler.adaptive;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.JobManagerOptions;
+import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
+import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.jobmaster.slotpool.DefaultAllocatedSlotPool;
+import org.apache.flink.runtime.jobmaster.slotpool.DefaultDeclarativeSlotPool;
+import 
org.apache.flink.runtime.scheduler.adaptive.AdaptiveSchedulerTest.SubmissionBufferingTaskManagerGateway;
+import org.apache.flink.runtime.scheduler.adaptive.allocator.VertexParallelism;
+import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation;
+import org.apache.flink.runtime.testutils.CommonTestUtils;
+import org.apache.flink.runtime.util.ResourceCounter;
+
+import org.junit.jupiter.api.Test;
+
+import java.time.Duration;
+import java.util.Collections;
+
+import static 
org.apache.flink.runtime.jobgraph.JobGraphTestUtils.streamingJobGraph;
+import static 
org.apache.flink.runtime.jobmaster.slotpool.SlotPoolTestUtils.createSlotOffersForResourceRequirements;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Integration test proving that {@link WaitingForResources}, driven by the 
real {@link
+ * DefaultStateTransitionManager} (not a no-op test double), correctly gates a 
rescale-triggered
+ * restart on genuinely free slots reaching the pre-restart target, and falls 
back once the
+ * rescale resource-stabilization timeout elapses.
+ *
+ * <p>Kept in its own file, following the precedent set by {@link
+ * AdaptiveSchedulerFreeSlotVertexParallelismTest} and other companion test 
files extracted out of
+ * {@link AdaptiveSchedulerTest}.
+ */
+class AdaptiveSchedulerRescaleRestartTimingTest extends 
AdaptiveSchedulerTestBase {
+
+    private static final int RETRY_INTERVAL_MILLIS = 20;
+    private static final int RETRY_ATTEMPTS = 250;
+
+    @Test
+    void 
testWaitingForResourcesDoesNotTransitionUntilFreeSlotsReachRescaleTarget()
+            throws Exception {
+        final JobGraph jobGraph = createJobGraph();
+        final DefaultDeclarativeSlotPool declarativeSlotPool =
+                createDeclarativeSlotPool(jobGraph.getJobID(), 
singleThreadMainThreadExecutor);
+
+        // long enough that the stabilization timeout cannot fire during this 
test.
+        scheduler =
+                prepareScheduler(jobGraph, declarativeSlotPool, 
Duration.ofSeconds(10)).build();
+
+        final SubmissionBufferingTaskManagerGateway taskManagerGateway =
+                new SubmissionBufferingTaskManagerGateway(2);
+
+        // go straight to the restart-triggered WaitingForResources from the 
initial Created
+        // state, the same way Restarting#goToSubsequentState does - never 
through the plain
+        // submission path (startScheduling()), which would race a second, 
unrelated
+        // WaitingForResources transition using the submission timeout config.
+        final VertexParallelism restartTarget = vertexParallelism(2);
+        runInMainThread(
+                () ->
+                        scheduler.goToWaitingForResources(
+                                new StateTrackingMockExecutionGraph(), 
restartTarget));
+
+        
assertThat(scheduler.getState()).isInstanceOf(WaitingForResources.class);
+
+        offerSlots(declarativeSlotPool, taskManagerGateway, 1);
+
+        // only 1 of the 2 targeted slots is free: must not have shortcut to
+        // CreatingExecutionGraph yet, even though 1 slot is already 
"sufficient" to run the job
+        // at a lower parallelism.
+        Thread.sleep(300);

Review Comment:
   can't we wait here for the state to transition to `WaitingForResources` 
instead of setting a hard-coded sleep?



##########
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/AdaptiveSchedulerRescaleRestartTimingTest.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.scheduler.adaptive;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.JobManagerOptions;
+import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
+import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.jobmaster.slotpool.DefaultAllocatedSlotPool;
+import org.apache.flink.runtime.jobmaster.slotpool.DefaultDeclarativeSlotPool;
+import 
org.apache.flink.runtime.scheduler.adaptive.AdaptiveSchedulerTest.SubmissionBufferingTaskManagerGateway;
+import org.apache.flink.runtime.scheduler.adaptive.allocator.VertexParallelism;
+import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation;
+import org.apache.flink.runtime.testutils.CommonTestUtils;
+import org.apache.flink.runtime.util.ResourceCounter;
+
+import org.junit.jupiter.api.Test;
+
+import java.time.Duration;
+import java.util.Collections;
+
+import static 
org.apache.flink.runtime.jobgraph.JobGraphTestUtils.streamingJobGraph;
+import static 
org.apache.flink.runtime.jobmaster.slotpool.SlotPoolTestUtils.createSlotOffersForResourceRequirements;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Integration test proving that {@link WaitingForResources}, driven by the 
real {@link
+ * DefaultStateTransitionManager} (not a no-op test double), correctly gates a 
rescale-triggered
+ * restart on genuinely free slots reaching the pre-restart target, and falls 
back once the
+ * rescale resource-stabilization timeout elapses.
+ *
+ * <p>Kept in its own file, following the precedent set by {@link
+ * AdaptiveSchedulerFreeSlotVertexParallelismTest} and other companion test 
files extracted out of
+ * {@link AdaptiveSchedulerTest}.
+ */
+class AdaptiveSchedulerRescaleRestartTimingTest extends 
AdaptiveSchedulerTestBase {
+
+    private static final int RETRY_INTERVAL_MILLIS = 20;
+    private static final int RETRY_ATTEMPTS = 250;
+
+    @Test
+    void 
testWaitingForResourcesDoesNotTransitionUntilFreeSlotsReachRescaleTarget()
+            throws Exception {
+        final JobGraph jobGraph = createJobGraph();
+        final DefaultDeclarativeSlotPool declarativeSlotPool =
+                createDeclarativeSlotPool(jobGraph.getJobID(), 
singleThreadMainThreadExecutor);
+
+        // long enough that the stabilization timeout cannot fire during this 
test.
+        scheduler =
+                prepareScheduler(jobGraph, declarativeSlotPool, 
Duration.ofSeconds(10)).build();
+
+        final SubmissionBufferingTaskManagerGateway taskManagerGateway =
+                new SubmissionBufferingTaskManagerGateway(2);
+
+        // go straight to the restart-triggered WaitingForResources from the 
initial Created
+        // state, the same way Restarting#goToSubsequentState does - never 
through the plain
+        // submission path (startScheduling()), which would race a second, 
unrelated
+        // WaitingForResources transition using the submission timeout config.
+        final VertexParallelism restartTarget = vertexParallelism(2);
+        runInMainThread(
+                () ->
+                        scheduler.goToWaitingForResources(
+                                new StateTrackingMockExecutionGraph(), 
restartTarget));
+
+        
assertThat(scheduler.getState()).isInstanceOf(WaitingForResources.class);
+
+        offerSlots(declarativeSlotPool, taskManagerGateway, 1);
+
+        // only 1 of the 2 targeted slots is free: must not have shortcut to
+        // CreatingExecutionGraph yet, even though 1 slot is already 
"sufficient" to run the job
+        // at a lower parallelism.
+        Thread.sleep(300);
+        
assertThat(scheduler.getState()).isInstanceOf(WaitingForResources.class);
+
+        offerSlots(declarativeSlotPool, taskManagerGateway, 1);
+
+        CommonTestUtils.waitUntilCondition(
+                () -> scheduler.getState() instanceof CreatingExecutionGraph,
+                RETRY_INTERVAL_MILLIS,
+                RETRY_ATTEMPTS);
+    }
+
+    @Test
+    void 
testWaitingForResourcesFallsBackAfterRescaleResourceStabilizationTimeoutElapses()
+            throws Exception {
+        final JobGraph jobGraph = createJobGraph();
+        final DefaultDeclarativeSlotPool declarativeSlotPool =
+                createDeclarativeSlotPool(jobGraph.getJobID(), 
singleThreadMainThreadExecutor);
+
+        scheduler =
+                prepareScheduler(jobGraph, declarativeSlotPool, 
Duration.ofMillis(300)).build();
+
+        final SubmissionBufferingTaskManagerGateway taskManagerGateway =
+                new SubmissionBufferingTaskManagerGateway(1);
+
+        // go straight to the restart-triggered WaitingForResources from the 
initial Created
+        // state, as in the test above - never through the plain submission 
path.
+        final VertexParallelism restartTarget = vertexParallelism(2);

Review Comment:
   ```suggestion
           final int requiredParallelism = 2;
           final VertexParallelism restartTarget = 
vertexParallelism(requiredParallelism);
   ```
   If we move that into a variable, we could use `requiredParallelism - 1` when 
offering the slot to show the relationship between the different configuration 
parameters.



##########
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/RestartingTest.java:
##########
@@ -83,12 +83,15 @@ public void 
testTransitionToSubsequentStateWhenResourceChanged(boolean hasDesire
             throws Exception {
         try (MockRestartingContext ctx = new MockRestartingContext()) {
             JobVertexID jobVertexId = new JobVertexID();
-            VertexParallelism availableParallelism =
+            // Only 1 slot is genuinely free (e.g. the slot backing the 
just-cancelled execution
+            // has not been released yet), even though the restart target is 
2: must not shortcut
+            // straight to CreatingExecutionGraph.
+            VertexParallelism parallelismBasedOnFreeSlots =
                     new VertexParallelism(singletonMap(jobVertexId, 1));
             VertexParallelism requiredParallelismForForcedRestart =
                     new VertexParallelism(singletonMap(jobVertexId, 2));
 
-            ctx.setAvailableVertexParallelism(availableParallelism);
+            ctx.setAchievableVertexParallelism(parallelismBasedOnFreeSlots);
             ctx.setHasDesiredResources(hasDesiredResources);

Review Comment:
   Here, I'm wondering whether we're misaligned: We set the parallelism based 
on free slots to 1 even though the job requires parallelism of 2 to transition 
to ExecutionGraph creation.
   
   The ExecutionGraph creation also relies on free slots (see 
[AdaptiveScheduler:1259(https://github.com/apache/flink/blob/e93c3ef695a0f27950623186b369507e05aeeb54/flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/AdaptiveScheduler.java#L1259).
 That backs the observation that we should also rely on free slots for the 
desired resources to avoid creating the EG with less slots again.



##########
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/AdaptiveScheduler.java:
##########
@@ -1269,16 +1285,21 @@ public ArchivedExecutionGraph getArchivedExecutionGraph(
     }
 
     @Override
-    public void goToWaitingForResources(@Nullable ExecutionGraph 
previousExecutionGraph) {
+    public void goToWaitingForResources(
+            @Nullable ExecutionGraph previousExecutionGraph,
+            @Nullable VertexParallelism restartWithParallelism) {

Review Comment:
   ```suggestion
               @Nullable VertexParallelism targetVertexParallelism) {
   ```
   can we align the term? `WaitingForResources` should not use 
`restartWithParallelism` because `WaitingForResources` isn't only triggered in 
the restart context.



##########
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/AdaptiveSchedulerRescaleRestartTimingTest.java:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.scheduler.adaptive;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.JobManagerOptions;
+import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
+import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.jobmaster.slotpool.DefaultAllocatedSlotPool;
+import org.apache.flink.runtime.jobmaster.slotpool.DefaultDeclarativeSlotPool;
+import 
org.apache.flink.runtime.scheduler.adaptive.AdaptiveSchedulerTest.SubmissionBufferingTaskManagerGateway;
+import org.apache.flink.runtime.scheduler.adaptive.allocator.VertexParallelism;
+import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation;
+import org.apache.flink.runtime.testutils.CommonTestUtils;
+import org.apache.flink.runtime.util.ResourceCounter;
+
+import org.junit.jupiter.api.Test;
+
+import java.time.Duration;
+import java.util.Collections;
+
+import static 
org.apache.flink.runtime.jobgraph.JobGraphTestUtils.streamingJobGraph;
+import static 
org.apache.flink.runtime.jobmaster.slotpool.SlotPoolTestUtils.createSlotOffersForResourceRequirements;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Integration test proving that {@link WaitingForResources}, driven by the 
real {@link
+ * DefaultStateTransitionManager} (not a no-op test double), correctly gates a 
rescale-triggered
+ * restart on genuinely free slots reaching the pre-restart target, and falls 
back once the
+ * rescale resource-stabilization timeout elapses.
+ *
+ * <p>Kept in its own file, following the precedent set by {@link
+ * AdaptiveSchedulerFreeSlotVertexParallelismTest} and other companion test 
files extracted out of
+ * {@link AdaptiveSchedulerTest}.
+ */
+class AdaptiveSchedulerRescaleRestartTimingTest extends 
AdaptiveSchedulerTestBase {
+
+    private static final int RETRY_INTERVAL_MILLIS = 20;
+    private static final int RETRY_ATTEMPTS = 250;
+
+    @Test
+    void 
testWaitingForResourcesDoesNotTransitionUntilFreeSlotsReachRescaleTarget()
+            throws Exception {
+        final JobGraph jobGraph = createJobGraph();
+        final DefaultDeclarativeSlotPool declarativeSlotPool =
+                createDeclarativeSlotPool(jobGraph.getJobID(), 
singleThreadMainThreadExecutor);
+
+        // long enough that the stabilization timeout cannot fire during this 
test.
+        scheduler =
+                prepareScheduler(jobGraph, declarativeSlotPool, 
Duration.ofSeconds(10)).build();
+
+        final SubmissionBufferingTaskManagerGateway taskManagerGateway =
+                new SubmissionBufferingTaskManagerGateway(2);
+
+        // go straight to the restart-triggered WaitingForResources from the 
initial Created
+        // state, the same way Restarting#goToSubsequentState does - never 
through the plain
+        // submission path (startScheduling()), which would race a second, 
unrelated
+        // WaitingForResources transition using the submission timeout config.
+        final VertexParallelism restartTarget = vertexParallelism(2);
+        runInMainThread(
+                () ->
+                        scheduler.goToWaitingForResources(
+                                new StateTrackingMockExecutionGraph(), 
restartTarget));
+
+        
assertThat(scheduler.getState()).isInstanceOf(WaitingForResources.class);
+
+        offerSlots(declarativeSlotPool, taskManagerGateway, 1);
+
+        // only 1 of the 2 targeted slots is free: must not have shortcut to
+        // CreatingExecutionGraph yet, even though 1 slot is already 
"sufficient" to run the job
+        // at a lower parallelism.
+        Thread.sleep(300);
+        
assertThat(scheduler.getState()).isInstanceOf(WaitingForResources.class);
+
+        offerSlots(declarativeSlotPool, taskManagerGateway, 1);
+
+        CommonTestUtils.waitUntilCondition(
+                () -> scheduler.getState() instanceof CreatingExecutionGraph,
+                RETRY_INTERVAL_MILLIS,
+                RETRY_ATTEMPTS);
+    }
+
+    @Test
+    void 
testWaitingForResourcesFallsBackAfterRescaleResourceStabilizationTimeoutElapses()
+            throws Exception {
+        final JobGraph jobGraph = createJobGraph();
+        final DefaultDeclarativeSlotPool declarativeSlotPool =
+                createDeclarativeSlotPool(jobGraph.getJobID(), 
singleThreadMainThreadExecutor);
+
+        scheduler =
+                prepareScheduler(jobGraph, declarativeSlotPool, 
Duration.ofMillis(300)).build();

Review Comment:
   Can we explain this magic number in a comment?



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

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to