XComp commented on code in PR #28999:
URL: https://github.com/apache/flink/pull/28999#discussion_r3955531392
##########
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/MockRestartingContext.java:
##########
@@ -44,31 +45,37 @@ class MockRestartingContext extends
MockStateWithExecutionGraphContext
private final StateValidator<ExecutingTest.CancellingArguments>
cancellingStateValidator =
new StateValidator<>("Cancelling");
- private final StateValidator<ExecutionGraph>
waitingForResourcesStateValidator =
+ private final StateValidator<WaitingForResourcesArguments>
waitingForResourcesStateValidator =
new StateValidator<>("WaitingForResources");
private final StateValidator<ExecutionGraph>
creatingExecutionGraphStateValidator =
new StateValidator<>("CreatingExecutionGraph");
- @Nullable private VertexParallelism availableVertexParallelism;
+ @Nullable private VertexParallelism freeSlotVertexParallelism;
private boolean hasDesiredResources = false;
public void
setExpectCancelling(Consumer<ExecutingTest.CancellingArguments> asserter) {
cancellingStateValidator.expectInput(asserter);
}
- public void setExpectWaitingForResources() {
- waitingForResourcesStateValidator.expectInput(assertNonNull());
+ public void setExpectWaitingForResources(
+ @Nullable VertexParallelism expectedTargetVertexParallelism) {
+ waitingForResourcesStateValidator.expectInput(
+ arguments -> {
+ assertNonNull().accept(arguments);
Review Comment:
```suggestion
assertThat(arguments.getExecutionGraph()).isNotNull();
```
The initial implementation validated that the executionGraph isn't null
##########
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/WaitingForResources.java:
##########
@@ -143,6 +162,29 @@ public ScheduledFuture<?> scheduleOperation(Runnable
callback, Duration delay) {
return context.runIfState(this, callback, delay);
}
+ private boolean isFreeSlotVertexParallelismAtLeast(VertexParallelism
target) {
Review Comment:
```suggestion
private boolean hasFreeSlotsFor(VertexParallelism target) {
```
nit: what about that method name? Otherwise, maybe
`isAtLeastFreeSlotVertexParallelism`
##########
flink-runtime/src/test/java/org/apache/flink/runtime/scheduler/adaptive/AdaptiveSchedulerRescaleRestartTimingTest.java:
##########
@@ -0,0 +1,200 @@
+/*
+ * 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, even though 1 slot is already "sufficient"
to run the job at a
+ // lower parallelism. No sleep is needed here: offerSlots() runs
synchronously on the main
+ // thread executor, and no stabilization work gets scheduled while
desired resources
+ // (gated on the restart target) aren't met, so the state is already
final by the time it
+ // returns.
+
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);
+
+ // short enough to keep the test fast, but comfortably longer than the
offerSlots() call
+ // below so the fallback can only be triggered by the timeout, not by
a race with it.
+ final Duration rescaleResourceStabilizationTimeout =
Duration.ofMillis(300);
+ scheduler =
+ prepareScheduler(jobGraph, declarativeSlotPool,
rescaleResourceStabilizationTimeout)
+ .build();
+
+ final int requiredParallelism = 2;
+ final SubmissionBufferingTaskManagerGateway taskManagerGateway =
+ new SubmissionBufferingTaskManagerGateway(requiredParallelism
- 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(requiredParallelism);
+ runInMainThread(
+ () ->
+ scheduler.goToWaitingForResources(
+ new StateTrackingMockExecutionGraph(),
restartTarget));
+
+
assertThat(scheduler.getState()).isInstanceOf(WaitingForResources.class);
+
+ // only 1 of the 2 targeted slots is ever offered.
+ offerSlots(declarativeSlotPool, taskManagerGateway,
requiredParallelism - 1);
+
+ // the target is never reached, but the stabilization timeout must
still force the
+ // transition once it elapses, rather than waiting forever.
+ CommonTestUtils.waitUntilCondition(
+ () -> scheduler.getState() instanceof CreatingExecutionGraph,
Review Comment:
```suggestion
() -> !(scheduler.getState() instanceof WaitingForResources).
```
AdaptiveScheduler is transitioning to Executing eventually which might make
this condition time out occasionally if we miss the time window of the
CreatingExecutionGraph state
##########
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptive/Restarting.java:
##########
@@ -218,7 +226,7 @@ public Restarting getState() {
operatorCoordinatorHandler,
log,
backoffTime,
- restartWithParallelism,
+ targetVertexParallelism,
Review Comment:
```suggestion
restartWithParallelism,
```
We have to be consistent here - I'm ok with either leaving
`restartWithParallelism` in the `Restarting` class because it's actually
covering the restarting context. Or we rename all the occurrences to
`targetVertexParallelism`.
##########
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:
Can you reference the FLINK Jira issue?
--
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]