You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by tr...@apache.org on 2019/07/30 18:26:45 UTC
[flink] branch master updated (e29cd17 -> 70fe6aa)
This is an automated email from the ASF dual-hosted git repository.
trohrmann pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git.
from e29cd17 [FLINK-13399][legal] Update NOTICE-binary for new table uber jars
new b4a2269 [hotfix] Fix checkstyle violations in StandaloneResourceManagerTest
new 052599d [hotfix][runtime] Extract SlotManager interface
new 0f9d095 [FLINK-13408][runtime] Let StandaloneResourceManager start startup period upon granting leadership
new a3ac577 [hotfix] Make TestingSlotManager#setFailUnfulfillableRequestConsumer non-nullable
new 22a9644 [hotfix] Remove polling loops from StandaloneResourceManagerTest
new 70fe6aa [hotfix] Rename TestingSlotManagerFactory into TestingSlotManagerBuilder
The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../clusterframework/MesosResourceManager.java | 1 -
.../runtime/resourcemanager/ResourceManager.java | 11 +-
.../ResourceManagerRuntimeServices.java | 3 +-
.../resourcemanager/StandaloneResourceManager.java | 30 +-
.../resourcemanager/slotmanager/SlotManager.java | 1105 +-------------------
.../{SlotManager.java => SlotManagerImpl.java} | 43 +-
.../StandaloneResourceManagerTest.java | 85 +-
.../slotmanager/SlotManagerBuilder.java | 6 +-
.../SlotManagerFailUnfulfillableTest.java | 6 +-
.../slotmanager/SlotManagerTest.java | 46 +-
.../TaskManagerReleaseInSlotManagerTest.java | 12 +-
.../slotmanager/TestingSlotManager.java | 127 +++
.../slotmanager/TestingSlotManagerBuilder.java} | 18 +-
.../utils/MockResourceManagerRuntimeServices.java | 20 +-
.../org/apache/flink/yarn/YarnResourceManager.java | 1 -
15 files changed, 303 insertions(+), 1211 deletions(-)
mode change 100755 => 100644 flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManager.java
copy flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/{SlotManager.java => SlotManagerImpl.java} (97%)
create mode 100644 flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TestingSlotManager.java
copy flink-runtime/src/{main/java/org/apache/flink/runtime/resourcemanager/slotmanager/TaskManagerSlotId.java => test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TestingSlotManagerBuilder.java} (61%)
[flink] 05/06: [hotfix] Remove polling loops from
StandaloneResourceManagerTest
Posted by tr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
trohrmann pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 22a96442d911ee1d35b59abeebfc16fd8b0a9542
Author: Till Rohrmann <tr...@apache.org>
AuthorDate: Tue Jul 30 14:54:19 2019 +0200
[hotfix] Remove polling loops from StandaloneResourceManagerTest
---
.../StandaloneResourceManagerTest.java | 61 +++++-----------------
1 file changed, 14 insertions(+), 47 deletions(-)
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManagerTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManagerTest.java
index 89b6fa6..39d06a0 100755
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManagerTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManagerTest.java
@@ -18,7 +18,6 @@
package org.apache.flink.runtime.resourcemanager;
-import org.apache.flink.api.common.time.Deadline;
import org.apache.flink.api.common.time.Time;
import org.apache.flink.runtime.clusterframework.types.ResourceID;
import org.apache.flink.runtime.entrypoint.ClusterInformation;
@@ -35,18 +34,17 @@ import org.apache.flink.runtime.rpc.RpcService;
import org.apache.flink.runtime.rpc.TestingRpcServiceResource;
import org.apache.flink.runtime.util.TestingFatalErrorHandler;
import org.apache.flink.util.TestLogger;
-import org.apache.flink.util.function.SupplierWithException;
import org.junit.ClassRule;
import org.junit.Test;
-import java.time.Duration;
import java.util.UUID;
import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
/**
* Tests for the Standalone Resource Manager.
@@ -56,7 +54,7 @@ public class StandaloneResourceManagerTest extends TestLogger {
@ClassRule
public static final TestingRpcServiceResource RPC_SERVICE = new TestingRpcServiceResource();
- private static final Time TIMEOUT = Time.seconds(10);
+ private static final Time TIMEOUT = Time.seconds(10L);
private final TestingFatalErrorHandler fatalErrorHandler = new TestingFatalErrorHandler();
@@ -64,14 +62,12 @@ public class StandaloneResourceManagerTest extends TestLogger {
public void testStartupPeriod() throws Exception {
final LinkedBlockingQueue<Boolean> setFailUnfulfillableRequestInvokes = new LinkedBlockingQueue<>();
final SlotManager slotManager = new TestingSlotManagerFactory()
- .setSetFailUnfulfillableRequestConsumer(invoke -> setFailUnfulfillableRequestInvokes.add(invoke))
+ .setSetFailUnfulfillableRequestConsumer(setFailUnfulfillableRequestInvokes::add)
.createSlotManager();
final TestingStandaloneResourceManager rm = createResourceManager(Time.milliseconds(1L), slotManager);
- final Deadline deadline = Deadline.fromNow(Duration.ofSeconds(1));
- assertHappensUntil(() -> setFailUnfulfillableRequestInvokes.size() == 2, deadline);
- assertThat(setFailUnfulfillableRequestInvokes.poll(), is(false));
- assertThat(setFailUnfulfillableRequestInvokes.poll(), is(true));
+ assertThat(setFailUnfulfillableRequestInvokes.take(), is(false));
+ assertThat(setFailUnfulfillableRequestInvokes.take(), is(true));
rm.close();
}
@@ -80,14 +76,12 @@ public class StandaloneResourceManagerTest extends TestLogger {
public void testNoStartupPeriod() throws Exception {
final LinkedBlockingQueue<Boolean> setFailUnfulfillableRequestInvokes = new LinkedBlockingQueue<>();
final SlotManager slotManager = new TestingSlotManagerFactory()
- .setSetFailUnfulfillableRequestConsumer(invoke -> setFailUnfulfillableRequestInvokes.add(invoke))
+ .setSetFailUnfulfillableRequestConsumer(setFailUnfulfillableRequestInvokes::add)
.createSlotManager();
final TestingStandaloneResourceManager rm = createResourceManager(Time.milliseconds(-1L), slotManager);
- final Deadline deadline = Deadline.fromNow(Duration.ofSeconds(1));
- assertNotHappens(() -> setFailUnfulfillableRequestInvokes.size() > 1, deadline);
- assertThat(setFailUnfulfillableRequestInvokes.size(), is(1));
- assertThat(setFailUnfulfillableRequestInvokes.poll(), is(false));
+ assertThat(setFailUnfulfillableRequestInvokes.take(), is(false));
+ assertThat(setFailUnfulfillableRequestInvokes.poll(50L, TimeUnit.MILLISECONDS), is(nullValue()));
rm.close();
}
@@ -96,22 +90,18 @@ public class StandaloneResourceManagerTest extends TestLogger {
public void testStartUpPeriodAfterLeadershipSwitch() throws Exception {
final LinkedBlockingQueue<Boolean> setFailUnfulfillableRequestInvokes = new LinkedBlockingQueue<>();
final SlotManager slotManager = new TestingSlotManagerFactory()
- .setSetFailUnfulfillableRequestConsumer(invoke -> setFailUnfulfillableRequestInvokes.add(invoke))
+ .setSetFailUnfulfillableRequestConsumer(setFailUnfulfillableRequestInvokes::add)
.createSlotManager();
final TestingStandaloneResourceManager rm = createResourceManager(Time.milliseconds(1L), slotManager);
- final Deadline deadline1 = Deadline.fromNow(Duration.ofSeconds(1));
- assertHappensUntil(() -> setFailUnfulfillableRequestInvokes.size() == 2, deadline1);
- assertThat(setFailUnfulfillableRequestInvokes.poll(), is(false));
- assertThat(setFailUnfulfillableRequestInvokes.poll(), is(true));
+ assertThat(setFailUnfulfillableRequestInvokes.take(), is(false));
+ assertThat(setFailUnfulfillableRequestInvokes.take(), is(true));
rm.rmServices.revokeLeadership();
rm.rmServices.grantLeadership();
- final Deadline deadline2 = Deadline.fromNow(Duration.ofSeconds(1L));
- assertHappensUntil(() -> setFailUnfulfillableRequestInvokes.size() == 2, deadline2);
- assertThat(setFailUnfulfillableRequestInvokes.poll(), is(false));
- assertThat(setFailUnfulfillableRequestInvokes.poll(), is(true));
+ assertThat(setFailUnfulfillableRequestInvokes.take(), is(false));
+ assertThat(setFailUnfulfillableRequestInvokes.take(), is(true));
}
private TestingStandaloneResourceManager createResourceManager(Time startupPeriod, SlotManager slotManager) throws Exception {
@@ -142,29 +132,6 @@ public class StandaloneResourceManagerTest extends TestLogger {
return rm;
}
- private static void assertHappensUntil(
- SupplierWithException<Boolean, InterruptedException> condition,
- Deadline until) throws InterruptedException {
- while (!condition.get()) {
- if (!until.hasTimeLeft()) {
- fail("condition was not fulfilled before the deadline");
- }
- Thread.sleep(2);
- }
- }
-
- private static void assertNotHappens(
- SupplierWithException<Boolean, InterruptedException> condition,
- Deadline until) throws InterruptedException {
- while (!condition.get()) {
- if (!until.hasTimeLeft()) {
- return;
- }
- Thread.sleep(2);
- }
- fail("condition was fulfilled before the deadline");
- }
-
private static class TestingStandaloneResourceManager extends StandaloneResourceManager {
private final MockResourceManagerRuntimeServices rmServices;
[flink] 01/06: [hotfix] Fix checkstyle violations in
StandaloneResourceManagerTest
Posted by tr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
trohrmann pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit b4a2269574514a0540620f5ecb4f81fe86e7266a
Author: Till Rohrmann <tr...@apache.org>
AuthorDate: Tue Jul 30 14:55:52 2019 +0200
[hotfix] Fix checkstyle violations in StandaloneResourceManagerTest
---
.../flink/runtime/resourcemanager/StandaloneResourceManagerTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManagerTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManagerTest.java
index ede2359..37dbccc 100755
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManagerTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManagerTest.java
@@ -33,9 +33,9 @@ import org.apache.flink.runtime.rpc.FatalErrorHandler;
import org.apache.flink.runtime.rpc.RpcService;
import org.apache.flink.runtime.rpc.TestingRpcServiceResource;
import org.apache.flink.runtime.util.TestingFatalErrorHandler;
-
import org.apache.flink.util.TestLogger;
import org.apache.flink.util.function.SupplierWithException;
+
import org.junit.ClassRule;
import org.junit.Test;
[flink] 04/06: [hotfix] Make
TestingSlotManager#setFailUnfulfillableRequestConsumer non-nullable
Posted by tr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
trohrmann pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit a3ac577da3187121ba55ac246dec0dadab5a35f2
Author: Till Rohrmann <tr...@apache.org>
AuthorDate: Tue Jul 30 14:52:26 2019 +0200
[hotfix] Make TestingSlotManager#setFailUnfulfillableRequestConsumer non-nullable
---
.../resourcemanager/slotmanager/TestingSlotManager.java | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TestingSlotManager.java b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TestingSlotManager.java
index a07846e..a892aa1 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TestingSlotManager.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TestingSlotManager.java
@@ -26,8 +26,6 @@ import org.apache.flink.runtime.resourcemanager.SlotRequest;
import org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection;
import org.apache.flink.runtime.taskexecutor.SlotReport;
-import javax.annotation.Nullable;
-
import java.util.concurrent.Executor;
import java.util.function.Consumer;
@@ -38,7 +36,7 @@ public class TestingSlotManager implements SlotManager {
private final Consumer<Boolean> setFailUnfulfillableRequestConsumer;
- public TestingSlotManager(@Nullable Consumer<Boolean> setFailUnfulfillableRequestConsumer) {
+ TestingSlotManager(Consumer<Boolean> setFailUnfulfillableRequestConsumer) {
this.setFailUnfulfillableRequestConsumer = setFailUnfulfillableRequestConsumer;
}
@@ -83,7 +81,7 @@ public class TestingSlotManager implements SlotManager {
}
@Override
- public boolean registerSlotRequest(SlotRequest slotRequest) throws SlotManagerException {
+ public boolean registerSlotRequest(SlotRequest slotRequest) {
return false;
}
@@ -114,9 +112,7 @@ public class TestingSlotManager implements SlotManager {
@Override
public void setFailUnfulfillableRequest(boolean failUnfulfillableRequest) {
- if (setFailUnfulfillableRequestConsumer != null) {
- setFailUnfulfillableRequestConsumer.accept(failUnfulfillableRequest);
- }
+ setFailUnfulfillableRequestConsumer.accept(failUnfulfillableRequest);
}
@Override
[flink] 02/06: [hotfix][runtime] Extract SlotManager interface
Posted by tr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
trohrmann pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 052599d9a5f6c96eb2ba546d5b66453c8d09ed2f
Author: Xintong Song <to...@gmail.com>
AuthorDate: Tue Jul 30 11:25:16 2019 +0200
[hotfix][runtime] Extract SlotManager interface
Rename SlotManager -> SlotManagerImpl and let it implement the SlotManager interface
---
.../ResourceManagerRuntimeServices.java | 3 +-
.../resourcemanager/slotmanager/SlotManager.java | 1105 +-------------------
.../{SlotManager.java => SlotManagerImpl.java} | 40 +-
.../slotmanager/SlotManagerBuilder.java | 6 +-
.../slotmanager/SlotManagerTest.java | 46 +-
.../TaskManagerReleaseInSlotManagerTest.java | 12 +-
6 files changed, 77 insertions(+), 1135 deletions(-)
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManagerRuntimeServices.java b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManagerRuntimeServices.java
index 0c0ba89..f2cf015 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManagerRuntimeServices.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManagerRuntimeServices.java
@@ -22,6 +22,7 @@ import org.apache.flink.runtime.concurrent.ScheduledExecutor;
import org.apache.flink.runtime.highavailability.HighAvailabilityServices;
import org.apache.flink.runtime.resourcemanager.slotmanager.SlotManager;
import org.apache.flink.runtime.resourcemanager.slotmanager.SlotManagerConfiguration;
+import org.apache.flink.runtime.resourcemanager.slotmanager.SlotManagerImpl;
import org.apache.flink.util.Preconditions;
/**
@@ -54,7 +55,7 @@ public class ResourceManagerRuntimeServices {
final SlotManagerConfiguration slotManagerConfiguration = configuration.getSlotManagerConfiguration();
- final SlotManager slotManager = new SlotManager(
+ final SlotManager slotManager = new SlotManagerImpl(
scheduledExecutor,
slotManagerConfiguration.getTaskManagerRequestTimeout(),
slotManagerConfiguration.getSlotRequestTimeout(),
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManager.java b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManager.java
old mode 100755
new mode 100644
index 71f3df6..5b709d3
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManager.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManager.java
@@ -19,47 +19,16 @@
package org.apache.flink.runtime.resourcemanager.slotmanager;
import org.apache.flink.annotation.VisibleForTesting;
-import org.apache.flink.api.common.JobID;
-import org.apache.flink.api.common.time.Time;
import org.apache.flink.runtime.clusterframework.types.AllocationID;
import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
import org.apache.flink.runtime.clusterframework.types.SlotID;
-import org.apache.flink.runtime.clusterframework.types.TaskManagerSlot;
-import org.apache.flink.runtime.concurrent.ScheduledExecutor;
import org.apache.flink.runtime.instance.InstanceID;
-import org.apache.flink.runtime.messages.Acknowledge;
import org.apache.flink.runtime.resourcemanager.ResourceManagerId;
import org.apache.flink.runtime.resourcemanager.SlotRequest;
-import org.apache.flink.runtime.resourcemanager.exceptions.ResourceManagerException;
import org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection;
import org.apache.flink.runtime.taskexecutor.SlotReport;
-import org.apache.flink.runtime.taskexecutor.SlotStatus;
-import org.apache.flink.runtime.taskexecutor.TaskExecutorGateway;
-import org.apache.flink.runtime.taskexecutor.exceptions.SlotAllocationException;
-import org.apache.flink.runtime.taskexecutor.exceptions.SlotOccupiedException;
-import org.apache.flink.util.FlinkException;
-import org.apache.flink.util.Preconditions;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
-import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
/**
* The slot manager is responsible for maintaining a view on all registered task manager slots,
@@ -72,142 +41,20 @@ import java.util.concurrent.TimeoutException;
* slots are currently not used) and pending slot requests time out triggering their release and
* failure, respectively.
*/
-public class SlotManager implements AutoCloseable {
- private static final Logger LOG = LoggerFactory.getLogger(SlotManager.class);
-
- /** Scheduled executor for timeouts. */
- private final ScheduledExecutor scheduledExecutor;
-
- /** Timeout for slot requests to the task manager. */
- private final Time taskManagerRequestTimeout;
-
- /** Timeout after which an allocation is discarded. */
- private final Time slotRequestTimeout;
-
- /** Timeout after which an unused TaskManager is released. */
- private final Time taskManagerTimeout;
-
- /** Map for all registered slots. */
- private final HashMap<SlotID, TaskManagerSlot> slots;
-
- /** Index of all currently free slots. */
- private final LinkedHashMap<SlotID, TaskManagerSlot> freeSlots;
+public interface SlotManager extends AutoCloseable {
+ int getNumberRegisteredSlots();
- /** All currently registered task managers. */
- private final HashMap<InstanceID, TaskManagerRegistration> taskManagerRegistrations;
+ int getNumberRegisteredSlotsOf(InstanceID instanceId);
- /** Map of fulfilled and active allocations for request deduplication purposes. */
- private final HashMap<AllocationID, SlotID> fulfilledSlotRequests;
+ int getNumberFreeSlots();
- /** Map of pending/unfulfilled slot allocation requests. */
- private final HashMap<AllocationID, PendingSlotRequest> pendingSlotRequests;
+ int getNumberFreeSlotsOf(InstanceID instanceId);
- private final HashMap<TaskManagerSlotId, PendingTaskManagerSlot> pendingSlots;
+ int getNumberPendingTaskManagerSlots();
- /** ResourceManager's id. */
- private ResourceManagerId resourceManagerId;
+ int getNumberPendingSlotRequests();
- /** Executor for future callbacks which have to be "synchronized". */
- private Executor mainThreadExecutor;
-
- /** Callbacks for resource (de-)allocations. */
- private ResourceActions resourceActions;
-
- private ScheduledFuture<?> taskManagerTimeoutCheck;
-
- private ScheduledFuture<?> slotRequestTimeoutCheck;
-
- /** True iff the component has been started. */
- private boolean started;
-
- /** Release task executor only when each produced result partition is either consumed or failed. */
- private final boolean waitResultConsumedBeforeRelease;
-
- /**
- * If true, fail unfulfillable slot requests immediately. Otherwise, allow unfulfillable request to pend.
- *
- * A slot request is considered unfulfillable if it cannot be fulfilled by neither a slot that is already registered
- * (including allocated ones) nor a pending slot that the {@link ResourceActions} can allocate.
- * */
- private boolean failUnfulfillableRequest = false;
-
- public SlotManager(
- ScheduledExecutor scheduledExecutor,
- Time taskManagerRequestTimeout,
- Time slotRequestTimeout,
- Time taskManagerTimeout,
- boolean waitResultConsumedBeforeRelease) {
-
- this.scheduledExecutor = Preconditions.checkNotNull(scheduledExecutor);
- this.taskManagerRequestTimeout = Preconditions.checkNotNull(taskManagerRequestTimeout);
- this.slotRequestTimeout = Preconditions.checkNotNull(slotRequestTimeout);
- this.taskManagerTimeout = Preconditions.checkNotNull(taskManagerTimeout);
- this.waitResultConsumedBeforeRelease = waitResultConsumedBeforeRelease;
-
- slots = new HashMap<>(16);
- freeSlots = new LinkedHashMap<>(16);
- taskManagerRegistrations = new HashMap<>(4);
- fulfilledSlotRequests = new HashMap<>(16);
- pendingSlotRequests = new HashMap<>(16);
- pendingSlots = new HashMap<>(16);
-
- resourceManagerId = null;
- resourceActions = null;
- mainThreadExecutor = null;
- taskManagerTimeoutCheck = null;
- slotRequestTimeoutCheck = null;
-
- started = false;
- }
-
- public int getNumberRegisteredSlots() {
- return slots.size();
- }
-
- public int getNumberRegisteredSlotsOf(InstanceID instanceId) {
- TaskManagerRegistration taskManagerRegistration = taskManagerRegistrations.get(instanceId);
-
- if (taskManagerRegistration != null) {
- return taskManagerRegistration.getNumberRegisteredSlots();
- } else {
- return 0;
- }
- }
-
- public int getNumberFreeSlots() {
- return freeSlots.size();
- }
-
- public int getNumberFreeSlotsOf(InstanceID instanceId) {
- TaskManagerRegistration taskManagerRegistration = taskManagerRegistrations.get(instanceId);
-
- if (taskManagerRegistration != null) {
- return taskManagerRegistration.getNumberFreeSlots();
- } else {
- return 0;
- }
- }
-
- public int getNumberPendingTaskManagerSlots() {
- return pendingSlots.size();
- }
-
- public int getNumberPendingSlotRequests() {
- return pendingSlotRequests.size();
- }
-
- public boolean isFailingUnfulfillableRequest() {
- return failUnfulfillableRequest;
- }
-
- @VisibleForTesting
- int getNumberAssignedPendingTaskManagerSlots() {
- return (int) pendingSlots.values().stream().filter(slot -> slot.getAssignedPendingSlotRequest() != null).count();
- }
-
- // ---------------------------------------------------------------------------------------------
- // Component lifecycle methods
- // ---------------------------------------------------------------------------------------------
+ boolean isFailingUnfulfillableRequest();
/**
* Starts the slot manager with the given leader id and resource manager actions.
@@ -216,79 +63,12 @@ public class SlotManager implements AutoCloseable {
* @param newMainThreadExecutor to use to run code in the ResourceManager's main thread
* @param newResourceActions to use for resource (de-)allocations
*/
- public void start(ResourceManagerId newResourceManagerId, Executor newMainThreadExecutor, ResourceActions newResourceActions) {
- LOG.info("Starting the SlotManager.");
-
- this.resourceManagerId = Preconditions.checkNotNull(newResourceManagerId);
- mainThreadExecutor = Preconditions.checkNotNull(newMainThreadExecutor);
- resourceActions = Preconditions.checkNotNull(newResourceActions);
-
- started = true;
-
- taskManagerTimeoutCheck = scheduledExecutor.scheduleWithFixedDelay(
- () -> mainThreadExecutor.execute(
- () -> checkTaskManagerTimeouts()),
- 0L,
- taskManagerTimeout.toMilliseconds(),
- TimeUnit.MILLISECONDS);
-
- slotRequestTimeoutCheck = scheduledExecutor.scheduleWithFixedDelay(
- () -> mainThreadExecutor.execute(
- () -> checkSlotRequestTimeouts()),
- 0L,
- slotRequestTimeout.toMilliseconds(),
- TimeUnit.MILLISECONDS);
- }
+ void start(ResourceManagerId newResourceManagerId, Executor newMainThreadExecutor, ResourceActions newResourceActions);
/**
* Suspends the component. This clears the internal state of the slot manager.
*/
- public void suspend() {
- LOG.info("Suspending the SlotManager.");
-
- // stop the timeout checks for the TaskManagers and the SlotRequests
- if (taskManagerTimeoutCheck != null) {
- taskManagerTimeoutCheck.cancel(false);
- taskManagerTimeoutCheck = null;
- }
-
- if (slotRequestTimeoutCheck != null) {
- slotRequestTimeoutCheck.cancel(false);
- slotRequestTimeoutCheck = null;
- }
-
- for (PendingSlotRequest pendingSlotRequest : pendingSlotRequests.values()) {
- cancelPendingSlotRequest(pendingSlotRequest);
- }
-
- pendingSlotRequests.clear();
-
- ArrayList<InstanceID> registeredTaskManagers = new ArrayList<>(taskManagerRegistrations.keySet());
-
- for (InstanceID registeredTaskManager : registeredTaskManagers) {
- unregisterTaskManager(registeredTaskManager);
- }
-
- resourceManagerId = null;
- resourceActions = null;
- started = false;
- }
-
- /**
- * Closes the slot manager.
- *
- * @throws Exception if the close operation fails
- */
- @Override
- public void close() throws Exception {
- LOG.info("Closing the SlotManager.");
-
- suspend();
- }
-
- // ---------------------------------------------------------------------------------------------
- // Public API
- // ---------------------------------------------------------------------------------------------
+ void suspend();
/**
* Requests a slot with the respective resource profile.
@@ -297,30 +77,7 @@ public class SlotManager implements AutoCloseable {
* @return true if the slot request was registered; false if the request is a duplicate
* @throws SlotManagerException if the slot request failed (e.g. not enough resources left)
*/
- public boolean registerSlotRequest(SlotRequest slotRequest) throws SlotManagerException {
- checkInit();
-
- if (checkDuplicateRequest(slotRequest.getAllocationId())) {
- LOG.debug("Ignoring a duplicate slot request with allocation id {}.", slotRequest.getAllocationId());
-
- return false;
- } else {
- PendingSlotRequest pendingSlotRequest = new PendingSlotRequest(slotRequest);
-
- pendingSlotRequests.put(slotRequest.getAllocationId(), pendingSlotRequest);
-
- try {
- internalRequestSlot(pendingSlotRequest);
- } catch (ResourceManagerException e) {
- // requesting the slot failed --> remove pending slot request
- pendingSlotRequests.remove(slotRequest.getAllocationId());
-
- throw new SlotManagerException("Could not fulfill slot request " + slotRequest.getAllocationId() + '.', e);
- }
-
- return true;
- }
- }
+ boolean registerSlotRequest(SlotRequest slotRequest) throws SlotManagerException;
/**
* Cancels and removes a pending slot request with the given allocation id. If there is no such
@@ -329,23 +86,7 @@ public class SlotManager implements AutoCloseable {
* @param allocationId identifying the pending slot request
* @return True if a pending slot request was found; otherwise false
*/
- public boolean unregisterSlotRequest(AllocationID allocationId) {
- checkInit();
-
- PendingSlotRequest pendingSlotRequest = pendingSlotRequests.remove(allocationId);
-
- if (null != pendingSlotRequest) {
- LOG.debug("Cancel slot request {}.", allocationId);
-
- cancelPendingSlotRequest(pendingSlotRequest);
-
- return true;
- } else {
- LOG.debug("No pending slot request with allocation id {} found. Ignoring unregistration request.", allocationId);
-
- return false;
- }
- }
+ boolean unregisterSlotRequest(AllocationID allocationId);
/**
* Registers a new task manager at the slot manager. This will make the task managers slots
@@ -354,40 +95,7 @@ public class SlotManager implements AutoCloseable {
* @param taskExecutorConnection for the new task manager
* @param initialSlotReport for the new task manager
*/
- public void registerTaskManager(final TaskExecutorConnection taskExecutorConnection, SlotReport initialSlotReport) {
- checkInit();
-
- LOG.debug("Registering TaskManager {} under {} at the SlotManager.", taskExecutorConnection.getResourceID(), taskExecutorConnection.getInstanceID());
-
- // we identify task managers by their instance id
- if (taskManagerRegistrations.containsKey(taskExecutorConnection.getInstanceID())) {
- reportSlotStatus(taskExecutorConnection.getInstanceID(), initialSlotReport);
- } else {
- // first register the TaskManager
- ArrayList<SlotID> reportedSlots = new ArrayList<>();
-
- for (SlotStatus slotStatus : initialSlotReport) {
- reportedSlots.add(slotStatus.getSlotID());
- }
-
- TaskManagerRegistration taskManagerRegistration = new TaskManagerRegistration(
- taskExecutorConnection,
- reportedSlots);
-
- taskManagerRegistrations.put(taskExecutorConnection.getInstanceID(), taskManagerRegistration);
-
- // next register the new slots
- for (SlotStatus slotStatus : initialSlotReport) {
- registerSlot(
- slotStatus.getSlotID(),
- slotStatus.getAllocationID(),
- slotStatus.getJobID(),
- slotStatus.getResourceProfile(),
- taskExecutorConnection);
- }
- }
-
- }
+ void registerTaskManager(TaskExecutorConnection taskExecutorConnection, SlotReport initialSlotReport);
/**
* Unregisters the task manager identified by the given instance id and its associated slots
@@ -396,23 +104,7 @@ public class SlotManager implements AutoCloseable {
* @param instanceId identifying the task manager to unregister
* @return True if there existed a registered task manager with the given instance id
*/
- public boolean unregisterTaskManager(InstanceID instanceId) {
- checkInit();
-
- LOG.debug("Unregister TaskManager {} from the SlotManager.", instanceId);
-
- TaskManagerRegistration taskManagerRegistration = taskManagerRegistrations.remove(instanceId);
-
- if (null != taskManagerRegistration) {
- internalUnregisterTaskManager(taskManagerRegistration);
-
- return true;
- } else {
- LOG.debug("There is no task manager registered with instance ID {}. Ignoring this message.", instanceId);
-
- return false;
- }
- }
+ boolean unregisterTaskManager(InstanceID instanceId);
/**
* Reports the current slot allocations for a task manager identified by the given instance id.
@@ -421,26 +113,7 @@ public class SlotManager implements AutoCloseable {
* @param slotReport containing the status for all of its slots
* @return true if the slot status has been updated successfully, otherwise false
*/
- public boolean reportSlotStatus(InstanceID instanceId, SlotReport slotReport) {
- checkInit();
-
- LOG.debug("Received slot report from instance {}: {}.", instanceId, slotReport);
-
- TaskManagerRegistration taskManagerRegistration = taskManagerRegistrations.get(instanceId);
-
- if (null != taskManagerRegistration) {
-
- for (SlotStatus slotStatus : slotReport) {
- updateSlot(slotStatus.getSlotID(), slotStatus.getAllocationID(), slotStatus.getJobID());
- }
-
- return true;
- } else {
- LOG.debug("Received slot report for unknown task manager with instance id {}. Ignoring this report.", instanceId);
-
- return false;
- }
- }
+ boolean reportSlotStatus(InstanceID instanceId, SlotReport slotReport);
/**
* Free the given slot from the given allocation. If the slot is still allocated by the given
@@ -449,752 +122,10 @@ public class SlotManager implements AutoCloseable {
* @param slotId identifying the slot to free
* @param allocationId with which the slot is presumably allocated
*/
- public void freeSlot(SlotID slotId, AllocationID allocationId) {
- checkInit();
-
- TaskManagerSlot slot = slots.get(slotId);
-
- if (null != slot) {
- if (slot.getState() == TaskManagerSlot.State.ALLOCATED) {
- if (Objects.equals(allocationId, slot.getAllocationId())) {
-
- TaskManagerRegistration taskManagerRegistration = taskManagerRegistrations.get(slot.getInstanceId());
-
- if (taskManagerRegistration == null) {
- throw new IllegalStateException("Trying to free a slot from a TaskManager " +
- slot.getInstanceId() + " which has not been registered.");
- }
-
- updateSlotState(slot, taskManagerRegistration, null, null);
- } else {
- LOG.debug("Received request to free slot {} with expected allocation id {}, " +
- "but actual allocation id {} differs. Ignoring the request.", slotId, allocationId, slot.getAllocationId());
- }
- } else {
- LOG.debug("Slot {} has not been allocated.", allocationId);
- }
- } else {
- LOG.debug("Trying to free a slot {} which has not been registered. Ignoring this message.", slotId);
- }
- }
-
- public void setFailUnfulfillableRequest(boolean failUnfulfillableRequest) {
- if (!this.failUnfulfillableRequest && failUnfulfillableRequest) {
- // fail unfulfillable pending requests
- Iterator<Map.Entry<AllocationID, PendingSlotRequest>> slotRequestIterator = pendingSlotRequests.entrySet().iterator();
- while (slotRequestIterator.hasNext()) {
- PendingSlotRequest pendingSlotRequest = slotRequestIterator.next().getValue();
- if (pendingSlotRequest.getAssignedPendingTaskManagerSlot() != null) {
- continue;
- }
- if (!isFulfillableByRegisteredSlots(pendingSlotRequest.getResourceProfile())) {
- slotRequestIterator.remove();
- resourceActions.notifyAllocationFailure(
- pendingSlotRequest.getJobId(),
- pendingSlotRequest.getAllocationId(),
- new ResourceManagerException("Could not fulfill slot request " + pendingSlotRequest.getAllocationId() + ". "
- + "Requested resource profile (" + pendingSlotRequest.getResourceProfile() + ") is unfulfillable.")
- );
- }
- }
- }
- this.failUnfulfillableRequest = failUnfulfillableRequest;
- }
-
- // ---------------------------------------------------------------------------------------------
- // Behaviour methods
- // ---------------------------------------------------------------------------------------------
-
- /**
- * Finds a matching slot request for a given resource profile. If there is no such request,
- * the method returns null.
- *
- * <p>Note: If you want to change the behaviour of the slot manager wrt slot allocation and
- * request fulfillment, then you should override this method.
- *
- * @param slotResourceProfile defining the resources of an available slot
- * @return A matching slot request which can be deployed in a slot with the given resource
- * profile. Null if there is no such slot request pending.
- */
- protected PendingSlotRequest findMatchingRequest(ResourceProfile slotResourceProfile) {
-
- for (PendingSlotRequest pendingSlotRequest : pendingSlotRequests.values()) {
- if (!pendingSlotRequest.isAssigned() && slotResourceProfile.isMatching(pendingSlotRequest.getResourceProfile())) {
- return pendingSlotRequest;
- }
- }
-
- return null;
- }
-
- /**
- * Finds a matching slot for a given resource profile. A matching slot has at least as many
- * resources available as the given resource profile. If there is no such slot available, then
- * the method returns null.
- *
- * <p>Note: If you want to change the behaviour of the slot manager wrt slot allocation and
- * request fulfillment, then you should override this method.
- *
- * @param requestResourceProfile specifying the resource requirements for the a slot request
- * @return A matching slot which fulfills the given resource profile. Null if there is no such
- * slot available.
- */
- protected TaskManagerSlot findMatchingSlot(ResourceProfile requestResourceProfile) {
- Iterator<Map.Entry<SlotID, TaskManagerSlot>> iterator = freeSlots.entrySet().iterator();
-
- while (iterator.hasNext()) {
- TaskManagerSlot taskManagerSlot = iterator.next().getValue();
-
- // sanity check
- Preconditions.checkState(
- taskManagerSlot.getState() == TaskManagerSlot.State.FREE,
- "TaskManagerSlot %s is not in state FREE but %s.",
- taskManagerSlot.getSlotId(), taskManagerSlot.getState());
-
- if (taskManagerSlot.getResourceProfile().isMatching(requestResourceProfile)) {
- iterator.remove();
- return taskManagerSlot;
- }
- }
-
- return null;
- }
-
- // ---------------------------------------------------------------------------------------------
- // Internal slot operations
- // ---------------------------------------------------------------------------------------------
-
- /**
- * Registers a slot for the given task manager at the slot manager. The slot is identified by
- * the given slot id. The given resource profile defines the available resources for the slot.
- * The task manager connection can be used to communicate with the task manager.
- *
- * @param slotId identifying the slot on the task manager
- * @param allocationId which is currently deployed in the slot
- * @param resourceProfile of the slot
- * @param taskManagerConnection to communicate with the remote task manager
- */
- private void registerSlot(
- SlotID slotId,
- AllocationID allocationId,
- JobID jobId,
- ResourceProfile resourceProfile,
- TaskExecutorConnection taskManagerConnection) {
-
- if (slots.containsKey(slotId)) {
- // remove the old slot first
- removeSlot(slotId);
- }
-
- final TaskManagerSlot slot = createAndRegisterTaskManagerSlot(slotId, resourceProfile, taskManagerConnection);
-
- final PendingTaskManagerSlot pendingTaskManagerSlot;
-
- if (allocationId == null) {
- pendingTaskManagerSlot = findExactlyMatchingPendingTaskManagerSlot(resourceProfile);
- } else {
- pendingTaskManagerSlot = null;
- }
-
- if (pendingTaskManagerSlot == null) {
- updateSlot(slotId, allocationId, jobId);
- } else {
- pendingSlots.remove(pendingTaskManagerSlot.getTaskManagerSlotId());
- final PendingSlotRequest assignedPendingSlotRequest = pendingTaskManagerSlot.getAssignedPendingSlotRequest();
-
- if (assignedPendingSlotRequest == null) {
- handleFreeSlot(slot);
- } else {
- assignedPendingSlotRequest.unassignPendingTaskManagerSlot();
- allocateSlot(slot, assignedPendingSlotRequest);
- }
- }
- }
-
- @Nonnull
- private TaskManagerSlot createAndRegisterTaskManagerSlot(SlotID slotId, ResourceProfile resourceProfile, TaskExecutorConnection taskManagerConnection) {
- final TaskManagerSlot slot = new TaskManagerSlot(
- slotId,
- resourceProfile,
- taskManagerConnection);
- slots.put(slotId, slot);
- return slot;
- }
-
- @Nullable
- private PendingTaskManagerSlot findExactlyMatchingPendingTaskManagerSlot(ResourceProfile resourceProfile) {
- for (PendingTaskManagerSlot pendingTaskManagerSlot : pendingSlots.values()) {
- if (pendingTaskManagerSlot.getResourceProfile().equals(resourceProfile)) {
- return pendingTaskManagerSlot;
- }
- }
-
- return null;
- }
-
- /**
- * Updates a slot with the given allocation id.
- *
- * @param slotId to update
- * @param allocationId specifying the current allocation of the slot
- * @param jobId specifying the job to which the slot is allocated
- * @return True if the slot could be updated; otherwise false
- */
- private boolean updateSlot(SlotID slotId, AllocationID allocationId, JobID jobId) {
- final TaskManagerSlot slot = slots.get(slotId);
-
- if (slot != null) {
- final TaskManagerRegistration taskManagerRegistration = taskManagerRegistrations.get(slot.getInstanceId());
-
- if (taskManagerRegistration != null) {
- updateSlotState(slot, taskManagerRegistration, allocationId, jobId);
+ void freeSlot(SlotID slotId, AllocationID allocationId);
- return true;
- } else {
- throw new IllegalStateException("Trying to update a slot from a TaskManager " +
- slot.getInstanceId() + " which has not been registered.");
- }
- } else {
- LOG.debug("Trying to update unknown slot with slot id {}.", slotId);
-
- return false;
- }
- }
-
- private void updateSlotState(
- TaskManagerSlot slot,
- TaskManagerRegistration taskManagerRegistration,
- @Nullable AllocationID allocationId,
- @Nullable JobID jobId) {
- if (null != allocationId) {
- switch (slot.getState()) {
- case PENDING:
- // we have a pending slot request --> check whether we have to reject it
- PendingSlotRequest pendingSlotRequest = slot.getAssignedSlotRequest();
-
- if (Objects.equals(pendingSlotRequest.getAllocationId(), allocationId)) {
- // we can cancel the slot request because it has been fulfilled
- cancelPendingSlotRequest(pendingSlotRequest);
-
- // remove the pending slot request, since it has been completed
- pendingSlotRequests.remove(pendingSlotRequest.getAllocationId());
-
- slot.completeAllocation(allocationId, jobId);
- } else {
- // we first have to free the slot in order to set a new allocationId
- slot.clearPendingSlotRequest();
- // set the allocation id such that the slot won't be considered for the pending slot request
- slot.updateAllocation(allocationId, jobId);
-
- // remove the pending request if any as it has been assigned
- final PendingSlotRequest actualPendingSlotRequest = pendingSlotRequests.remove(allocationId);
-
- if (actualPendingSlotRequest != null) {
- cancelPendingSlotRequest(actualPendingSlotRequest);
- }
-
- // this will try to find a new slot for the request
- rejectPendingSlotRequest(
- pendingSlotRequest,
- new Exception("Task manager reported slot " + slot.getSlotId() + " being already allocated."));
- }
-
- taskManagerRegistration.occupySlot();
- break;
- case ALLOCATED:
- if (!Objects.equals(allocationId, slot.getAllocationId())) {
- slot.freeSlot();
- slot.updateAllocation(allocationId, jobId);
- }
- break;
- case FREE:
- // the slot is currently free --> it is stored in freeSlots
- freeSlots.remove(slot.getSlotId());
- slot.updateAllocation(allocationId, jobId);
- taskManagerRegistration.occupySlot();
- break;
- }
-
- fulfilledSlotRequests.put(allocationId, slot.getSlotId());
- } else {
- // no allocation reported
- switch (slot.getState()) {
- case FREE:
- handleFreeSlot(slot);
- break;
- case PENDING:
- // don't do anything because we still have a pending slot request
- break;
- case ALLOCATED:
- AllocationID oldAllocation = slot.getAllocationId();
- slot.freeSlot();
- fulfilledSlotRequests.remove(oldAllocation);
- taskManagerRegistration.freeSlot();
-
- handleFreeSlot(slot);
- break;
- }
- }
- }
-
- /**
- * Tries to allocate a slot for the given slot request. If there is no slot available, the
- * resource manager is informed to allocate more resources and a timeout for the request is
- * registered.
- *
- * @param pendingSlotRequest to allocate a slot for
- * @throws ResourceManagerException if the resource manager cannot allocate more resource
- */
- private void internalRequestSlot(PendingSlotRequest pendingSlotRequest) throws ResourceManagerException {
- final ResourceProfile resourceProfile = pendingSlotRequest.getResourceProfile();
- TaskManagerSlot taskManagerSlot = findMatchingSlot(resourceProfile);
-
- if (taskManagerSlot != null) {
- allocateSlot(taskManagerSlot, pendingSlotRequest);
- } else {
- Optional<PendingTaskManagerSlot> pendingTaskManagerSlotOptional = findFreeMatchingPendingTaskManagerSlot(resourceProfile);
-
- if (!pendingTaskManagerSlotOptional.isPresent()) {
- pendingTaskManagerSlotOptional = allocateResource(resourceProfile);
- }
-
- if (pendingTaskManagerSlotOptional.isPresent()) {
- assignPendingTaskManagerSlot(pendingSlotRequest, pendingTaskManagerSlotOptional.get());
- }
- else {
- // request can not be fulfilled by any free slot or pending slot that can be allocated,
- // check whether it can be fulfilled by allocated slots
- if (failUnfulfillableRequest && !isFulfillableByRegisteredSlots(pendingSlotRequest.getResourceProfile())) {
- throw new ResourceManagerException("Requested resource profile (" +
- pendingSlotRequest.getResourceProfile() + ") is unfulfillable.");
- }
- }
- }
- }
-
- private Optional<PendingTaskManagerSlot> findFreeMatchingPendingTaskManagerSlot(ResourceProfile requiredResourceProfile) {
- for (PendingTaskManagerSlot pendingTaskManagerSlot : pendingSlots.values()) {
- if (pendingTaskManagerSlot.getAssignedPendingSlotRequest() == null && pendingTaskManagerSlot.getResourceProfile().isMatching(requiredResourceProfile)) {
- return Optional.of(pendingTaskManagerSlot);
- }
- }
-
- return Optional.empty();
- }
-
- private boolean isFulfillableByRegisteredSlots(ResourceProfile resourceProfile) {
- for (TaskManagerSlot slot : slots.values()) {
- if (slot.getResourceProfile().isMatching(resourceProfile)) {
- return true;
- }
- }
- return false;
- }
-
- private Optional<PendingTaskManagerSlot> allocateResource(ResourceProfile resourceProfile) throws ResourceManagerException {
- final Collection<ResourceProfile> requestedSlots = resourceActions.allocateResource(resourceProfile);
-
- if (requestedSlots.isEmpty()) {
- return Optional.empty();
- } else {
- final Iterator<ResourceProfile> slotIterator = requestedSlots.iterator();
- final PendingTaskManagerSlot pendingTaskManagerSlot = new PendingTaskManagerSlot(slotIterator.next());
- pendingSlots.put(pendingTaskManagerSlot.getTaskManagerSlotId(), pendingTaskManagerSlot);
-
- while (slotIterator.hasNext()) {
- final PendingTaskManagerSlot additionalPendingTaskManagerSlot = new PendingTaskManagerSlot(slotIterator.next());
- pendingSlots.put(additionalPendingTaskManagerSlot.getTaskManagerSlotId(), additionalPendingTaskManagerSlot);
- }
-
- return Optional.of(pendingTaskManagerSlot);
- }
- }
-
- private void assignPendingTaskManagerSlot(PendingSlotRequest pendingSlotRequest, PendingTaskManagerSlot pendingTaskManagerSlot) {
- pendingTaskManagerSlot.assignPendingSlotRequest(pendingSlotRequest);
- pendingSlotRequest.assignPendingTaskManagerSlot(pendingTaskManagerSlot);
- }
-
- /**
- * Allocates the given slot for the given slot request. This entails sending a registration
- * message to the task manager and treating failures.
- *
- * @param taskManagerSlot to allocate for the given slot request
- * @param pendingSlotRequest to allocate the given slot for
- */
- private void allocateSlot(TaskManagerSlot taskManagerSlot, PendingSlotRequest pendingSlotRequest) {
- Preconditions.checkState(taskManagerSlot.getState() == TaskManagerSlot.State.FREE);
-
- TaskExecutorConnection taskExecutorConnection = taskManagerSlot.getTaskManagerConnection();
- TaskExecutorGateway gateway = taskExecutorConnection.getTaskExecutorGateway();
-
- final CompletableFuture<Acknowledge> completableFuture = new CompletableFuture<>();
- final AllocationID allocationId = pendingSlotRequest.getAllocationId();
- final SlotID slotId = taskManagerSlot.getSlotId();
- final InstanceID instanceID = taskManagerSlot.getInstanceId();
-
- taskManagerSlot.assignPendingSlotRequest(pendingSlotRequest);
- pendingSlotRequest.setRequestFuture(completableFuture);
-
- returnPendingTaskManagerSlotIfAssigned(pendingSlotRequest);
-
- TaskManagerRegistration taskManagerRegistration = taskManagerRegistrations.get(instanceID);
-
- if (taskManagerRegistration == null) {
- throw new IllegalStateException("Could not find a registered task manager for instance id " +
- instanceID + '.');
- }
-
- taskManagerRegistration.markUsed();
-
- // RPC call to the task manager
- CompletableFuture<Acknowledge> requestFuture = gateway.requestSlot(
- slotId,
- pendingSlotRequest.getJobId(),
- allocationId,
- pendingSlotRequest.getTargetAddress(),
- resourceManagerId,
- taskManagerRequestTimeout);
-
- requestFuture.whenComplete(
- (Acknowledge acknowledge, Throwable throwable) -> {
- if (acknowledge != null) {
- completableFuture.complete(acknowledge);
- } else {
- completableFuture.completeExceptionally(throwable);
- }
- });
-
- completableFuture.whenCompleteAsync(
- (Acknowledge acknowledge, Throwable throwable) -> {
- try {
- if (acknowledge != null) {
- updateSlot(slotId, allocationId, pendingSlotRequest.getJobId());
- } else {
- if (throwable instanceof SlotOccupiedException) {
- SlotOccupiedException exception = (SlotOccupiedException) throwable;
- updateSlot(slotId, exception.getAllocationId(), exception.getJobId());
- } else {
- removeSlotRequestFromSlot(slotId, allocationId);
- }
-
- if (!(throwable instanceof CancellationException)) {
- handleFailedSlotRequest(slotId, allocationId, throwable);
- } else {
- LOG.debug("Slot allocation request {} has been cancelled.", allocationId, throwable);
- }
- }
- } catch (Exception e) {
- LOG.error("Error while completing the slot allocation.", e);
- }
- },
- mainThreadExecutor);
- }
-
- private void returnPendingTaskManagerSlotIfAssigned(PendingSlotRequest pendingSlotRequest) {
- final PendingTaskManagerSlot pendingTaskManagerSlot = pendingSlotRequest.getAssignedPendingTaskManagerSlot();
- if (pendingTaskManagerSlot != null) {
- pendingTaskManagerSlot.unassignPendingSlotRequest();
- pendingSlotRequest.unassignPendingTaskManagerSlot();
- }
- }
-
- /**
- * Handles a free slot. It first tries to find a pending slot request which can be fulfilled.
- * If there is no such request, then it will add the slot to the set of free slots.
- *
- * @param freeSlot to find a new slot request for
- */
- private void handleFreeSlot(TaskManagerSlot freeSlot) {
- Preconditions.checkState(freeSlot.getState() == TaskManagerSlot.State.FREE);
-
- PendingSlotRequest pendingSlotRequest = findMatchingRequest(freeSlot.getResourceProfile());
-
- if (null != pendingSlotRequest) {
- allocateSlot(freeSlot, pendingSlotRequest);
- } else {
- freeSlots.put(freeSlot.getSlotId(), freeSlot);
- }
- }
-
- /**
- * Removes the given set of slots from the slot manager.
- *
- * @param slotsToRemove identifying the slots to remove from the slot manager
- */
- private void removeSlots(Iterable<SlotID> slotsToRemove) {
- for (SlotID slotId : slotsToRemove) {
- removeSlot(slotId);
- }
- }
-
- /**
- * Removes the given slot from the slot manager.
- *
- * @param slotId identifying the slot to remove
- */
- private void removeSlot(SlotID slotId) {
- TaskManagerSlot slot = slots.remove(slotId);
-
- if (null != slot) {
- freeSlots.remove(slotId);
-
- if (slot.getState() == TaskManagerSlot.State.PENDING) {
- // reject the pending slot request --> triggering a new allocation attempt
- rejectPendingSlotRequest(
- slot.getAssignedSlotRequest(),
- new Exception("The assigned slot " + slot.getSlotId() + " was removed."));
- }
-
- AllocationID oldAllocationId = slot.getAllocationId();
-
- if (oldAllocationId != null) {
- fulfilledSlotRequests.remove(oldAllocationId);
-
- resourceActions.notifyAllocationFailure(
- slot.getJobId(),
- oldAllocationId,
- new FlinkException("The assigned slot " + slot.getSlotId() + " was removed."));
- }
- } else {
- LOG.debug("There was no slot registered with slot id {}.", slotId);
- }
- }
-
- // ---------------------------------------------------------------------------------------------
- // Internal request handling methods
- // ---------------------------------------------------------------------------------------------
-
- /**
- * Removes a pending slot request identified by the given allocation id from a slot identified
- * by the given slot id.
- *
- * @param slotId identifying the slot
- * @param allocationId identifying the presumable assigned pending slot request
- */
- private void removeSlotRequestFromSlot(SlotID slotId, AllocationID allocationId) {
- TaskManagerSlot taskManagerSlot = slots.get(slotId);
-
- if (null != taskManagerSlot) {
- if (taskManagerSlot.getState() == TaskManagerSlot.State.PENDING && Objects.equals(allocationId, taskManagerSlot.getAssignedSlotRequest().getAllocationId())) {
-
- TaskManagerRegistration taskManagerRegistration = taskManagerRegistrations.get(taskManagerSlot.getInstanceId());
-
- if (taskManagerRegistration == null) {
- throw new IllegalStateException("Trying to remove slot request from slot for which there is no TaskManager " + taskManagerSlot.getInstanceId() + " is registered.");
- }
-
- // clear the pending slot request
- taskManagerSlot.clearPendingSlotRequest();
-
- updateSlotState(taskManagerSlot, taskManagerRegistration, null, null);
- } else {
- LOG.debug("Ignore slot request removal for slot {}.", slotId);
- }
- } else {
- LOG.debug("There was no slot with {} registered. Probably this slot has been already freed.", slotId);
- }
- }
-
- /**
- * Handles a failed slot request. The slot manager tries to find a new slot fulfilling
- * the resource requirements for the failed slot request.
- *
- * @param slotId identifying the slot which was assigned to the slot request before
- * @param allocationId identifying the failed slot request
- * @param cause of the failure
- */
- private void handleFailedSlotRequest(SlotID slotId, AllocationID allocationId, Throwable cause) {
- PendingSlotRequest pendingSlotRequest = pendingSlotRequests.get(allocationId);
-
- LOG.debug("Slot request with allocation id {} failed for slot {}.", allocationId, slotId, cause);
-
- if (null != pendingSlotRequest) {
- pendingSlotRequest.setRequestFuture(null);
-
- try {
- internalRequestSlot(pendingSlotRequest);
- } catch (ResourceManagerException e) {
- pendingSlotRequests.remove(allocationId);
-
- resourceActions.notifyAllocationFailure(
- pendingSlotRequest.getJobId(),
- allocationId,
- e);
- }
- } else {
- LOG.debug("There was not pending slot request with allocation id {}. Probably the request has been fulfilled or cancelled.", allocationId);
- }
- }
-
- /**
- * Rejects the pending slot request by failing the request future with a
- * {@link SlotAllocationException}.
- *
- * @param pendingSlotRequest to reject
- * @param cause of the rejection
- */
- private void rejectPendingSlotRequest(PendingSlotRequest pendingSlotRequest, Exception cause) {
- CompletableFuture<Acknowledge> request = pendingSlotRequest.getRequestFuture();
-
- if (null != request) {
- request.completeExceptionally(new SlotAllocationException(cause));
- } else {
- LOG.debug("Cannot reject pending slot request {}, since no request has been sent.", pendingSlotRequest.getAllocationId());
- }
- }
-
- /**
- * Cancels the given slot request.
- *
- * @param pendingSlotRequest to cancel
- */
- private void cancelPendingSlotRequest(PendingSlotRequest pendingSlotRequest) {
- CompletableFuture<Acknowledge> request = pendingSlotRequest.getRequestFuture();
-
- returnPendingTaskManagerSlotIfAssigned(pendingSlotRequest);
-
- if (null != request) {
- request.cancel(false);
- }
- }
-
- // ---------------------------------------------------------------------------------------------
- // Internal timeout methods
- // ---------------------------------------------------------------------------------------------
+ void setFailUnfulfillableRequest(boolean failUnfulfillableRequest);
@VisibleForTesting
- void checkTaskManagerTimeouts() {
- if (!taskManagerRegistrations.isEmpty()) {
- long currentTime = System.currentTimeMillis();
-
- ArrayList<TaskManagerRegistration> timedOutTaskManagers = new ArrayList<>(taskManagerRegistrations.size());
-
- // first retrieve the timed out TaskManagers
- for (TaskManagerRegistration taskManagerRegistration : taskManagerRegistrations.values()) {
- if (currentTime - taskManagerRegistration.getIdleSince() >= taskManagerTimeout.toMilliseconds()) {
- // we collect the instance ids first in order to avoid concurrent modifications by the
- // ResourceActions.releaseResource call
- timedOutTaskManagers.add(taskManagerRegistration);
- }
- }
-
- // second we trigger the release resource callback which can decide upon the resource release
- for (TaskManagerRegistration taskManagerRegistration : timedOutTaskManagers) {
- if (waitResultConsumedBeforeRelease) {
- releaseTaskExecutorIfPossible(taskManagerRegistration);
- } else {
- releaseTaskExecutor(taskManagerRegistration.getInstanceId());
- }
- }
- }
- }
-
- private void releaseTaskExecutorIfPossible(TaskManagerRegistration taskManagerRegistration) {
- long idleSince = taskManagerRegistration.getIdleSince();
- taskManagerRegistration
- .getTaskManagerConnection()
- .getTaskExecutorGateway()
- .canBeReleased()
- .thenAcceptAsync(
- canBeReleased -> {
- InstanceID timedOutTaskManagerId = taskManagerRegistration.getInstanceId();
- boolean stillIdle = idleSince == taskManagerRegistration.getIdleSince();
- if (stillIdle && canBeReleased) {
- releaseTaskExecutor(timedOutTaskManagerId);
- }
- },
- mainThreadExecutor);
- }
-
- private void releaseTaskExecutor(InstanceID timedOutTaskManagerId) {
- final FlinkException cause = new FlinkException("TaskExecutor exceeded the idle timeout.");
- LOG.debug("Release TaskExecutor {} because it exceeded the idle timeout.", timedOutTaskManagerId);
- resourceActions.releaseResource(timedOutTaskManagerId, cause);
- }
-
- private void checkSlotRequestTimeouts() {
- if (!pendingSlotRequests.isEmpty()) {
- long currentTime = System.currentTimeMillis();
-
- Iterator<Map.Entry<AllocationID, PendingSlotRequest>> slotRequestIterator = pendingSlotRequests.entrySet().iterator();
-
- while (slotRequestIterator.hasNext()) {
- PendingSlotRequest slotRequest = slotRequestIterator.next().getValue();
-
- if (currentTime - slotRequest.getCreationTimestamp() >= slotRequestTimeout.toMilliseconds()) {
- slotRequestIterator.remove();
-
- if (slotRequest.isAssigned()) {
- cancelPendingSlotRequest(slotRequest);
- }
-
- resourceActions.notifyAllocationFailure(
- slotRequest.getJobId(),
- slotRequest.getAllocationId(),
- new TimeoutException("The allocation could not be fulfilled in time."));
- }
- }
- }
- }
-
- // ---------------------------------------------------------------------------------------------
- // Internal utility methods
- // ---------------------------------------------------------------------------------------------
-
- private void internalUnregisterTaskManager(TaskManagerRegistration taskManagerRegistration) {
- Preconditions.checkNotNull(taskManagerRegistration);
-
- removeSlots(taskManagerRegistration.getSlots());
- }
-
- private boolean checkDuplicateRequest(AllocationID allocationId) {
- return pendingSlotRequests.containsKey(allocationId) || fulfilledSlotRequests.containsKey(allocationId);
- }
-
- private void checkInit() {
- Preconditions.checkState(started, "The slot manager has not been started.");
- }
-
- // ---------------------------------------------------------------------------------------------
- // Testing methods
- // ---------------------------------------------------------------------------------------------
-
- @VisibleForTesting
- TaskManagerSlot getSlot(SlotID slotId) {
- return slots.get(slotId);
- }
-
- @VisibleForTesting
- PendingSlotRequest getSlotRequest(AllocationID allocationId) {
- return pendingSlotRequests.get(allocationId);
- }
-
- @VisibleForTesting
- boolean isTaskManagerIdle(InstanceID instanceId) {
- TaskManagerRegistration taskManagerRegistration = taskManagerRegistrations.get(instanceId);
-
- if (null != taskManagerRegistration) {
- return taskManagerRegistration.isIdle();
- } else {
- return false;
- }
- }
-
- @VisibleForTesting
- public void unregisterTaskManagersAndReleaseResources() {
- Iterator<Map.Entry<InstanceID, TaskManagerRegistration>> taskManagerRegistrationIterator =
- taskManagerRegistrations.entrySet().iterator();
-
- while (taskManagerRegistrationIterator.hasNext()) {
- TaskManagerRegistration taskManagerRegistration =
- taskManagerRegistrationIterator.next().getValue();
-
- taskManagerRegistrationIterator.remove();
-
- internalUnregisterTaskManager(taskManagerRegistration);
-
- resourceActions.releaseResource(taskManagerRegistration.getInstanceId(), new FlinkException("Triggering of SlotManager#unregisterTaskManagersAndReleaseResources."));
- }
- }
+ void unregisterTaskManagersAndReleaseResources();
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManager.java b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerImpl.java
similarity index 97%
copy from flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManager.java
copy to flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerImpl.java
index 71f3df6..376d030 100755
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManager.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerImpl.java
@@ -62,18 +62,10 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
- * The slot manager is responsible for maintaining a view on all registered task manager slots,
- * their allocation and all pending slot requests. Whenever a new slot is registered or and
- * allocated slot is freed, then it tries to fulfill another pending slot request. Whenever there
- * are not enough slots available the slot manager will notify the resource manager about it via
- * {@link ResourceActions#allocateResource(ResourceProfile)}.
- *
- * <p>In order to free resources and avoid resource leaks, idling task managers (task managers whose
- * slots are currently not used) and pending slot requests time out triggering their release and
- * failure, respectively.
+ * Implementation of {@link SlotManager}.
*/
-public class SlotManager implements AutoCloseable {
- private static final Logger LOG = LoggerFactory.getLogger(SlotManager.class);
+public class SlotManagerImpl implements SlotManager {
+ private static final Logger LOG = LoggerFactory.getLogger(SlotManagerImpl.class);
/** Scheduled executor for timeouts. */
private final ScheduledExecutor scheduledExecutor;
@@ -129,9 +121,9 @@ public class SlotManager implements AutoCloseable {
* A slot request is considered unfulfillable if it cannot be fulfilled by neither a slot that is already registered
* (including allocated ones) nor a pending slot that the {@link ResourceActions} can allocate.
* */
- private boolean failUnfulfillableRequest = false;
+ private boolean failUnfulfillableRequest = true;
- public SlotManager(
+ public SlotManagerImpl(
ScheduledExecutor scheduledExecutor,
Time taskManagerRequestTimeout,
Time slotRequestTimeout,
@@ -160,10 +152,12 @@ public class SlotManager implements AutoCloseable {
started = false;
}
+ @Override
public int getNumberRegisteredSlots() {
return slots.size();
}
+ @Override
public int getNumberRegisteredSlotsOf(InstanceID instanceId) {
TaskManagerRegistration taskManagerRegistration = taskManagerRegistrations.get(instanceId);
@@ -174,10 +168,12 @@ public class SlotManager implements AutoCloseable {
}
}
+ @Override
public int getNumberFreeSlots() {
return freeSlots.size();
}
+ @Override
public int getNumberFreeSlotsOf(InstanceID instanceId) {
TaskManagerRegistration taskManagerRegistration = taskManagerRegistrations.get(instanceId);
@@ -188,20 +184,23 @@ public class SlotManager implements AutoCloseable {
}
}
+ @Override
public int getNumberPendingTaskManagerSlots() {
return pendingSlots.size();
}
+ @Override
public int getNumberPendingSlotRequests() {
return pendingSlotRequests.size();
}
+ @Override
public boolean isFailingUnfulfillableRequest() {
return failUnfulfillableRequest;
}
@VisibleForTesting
- int getNumberAssignedPendingTaskManagerSlots() {
+ public int getNumberAssignedPendingTaskManagerSlots() {
return (int) pendingSlots.values().stream().filter(slot -> slot.getAssignedPendingSlotRequest() != null).count();
}
@@ -216,7 +215,9 @@ public class SlotManager implements AutoCloseable {
* @param newMainThreadExecutor to use to run code in the ResourceManager's main thread
* @param newResourceActions to use for resource (de-)allocations
*/
- public void start(ResourceManagerId newResourceManagerId, Executor newMainThreadExecutor, ResourceActions newResourceActions) {
+ @Override
+ public void start(ResourceManagerId newResourceManagerId, Executor newMainThreadExecutor,
+ ResourceActions newResourceActions) {
LOG.info("Starting the SlotManager.");
this.resourceManagerId = Preconditions.checkNotNull(newResourceManagerId);
@@ -243,6 +244,7 @@ public class SlotManager implements AutoCloseable {
/**
* Suspends the component. This clears the internal state of the slot manager.
*/
+ @Override
public void suspend() {
LOG.info("Suspending the SlotManager.");
@@ -297,6 +299,7 @@ public class SlotManager implements AutoCloseable {
* @return true if the slot request was registered; false if the request is a duplicate
* @throws SlotManagerException if the slot request failed (e.g. not enough resources left)
*/
+ @Override
public boolean registerSlotRequest(SlotRequest slotRequest) throws SlotManagerException {
checkInit();
@@ -329,6 +332,7 @@ public class SlotManager implements AutoCloseable {
* @param allocationId identifying the pending slot request
* @return True if a pending slot request was found; otherwise false
*/
+ @Override
public boolean unregisterSlotRequest(AllocationID allocationId) {
checkInit();
@@ -354,6 +358,7 @@ public class SlotManager implements AutoCloseable {
* @param taskExecutorConnection for the new task manager
* @param initialSlotReport for the new task manager
*/
+ @Override
public void registerTaskManager(final TaskExecutorConnection taskExecutorConnection, SlotReport initialSlotReport) {
checkInit();
@@ -396,6 +401,7 @@ public class SlotManager implements AutoCloseable {
* @param instanceId identifying the task manager to unregister
* @return True if there existed a registered task manager with the given instance id
*/
+ @Override
public boolean unregisterTaskManager(InstanceID instanceId) {
checkInit();
@@ -421,6 +427,7 @@ public class SlotManager implements AutoCloseable {
* @param slotReport containing the status for all of its slots
* @return true if the slot status has been updated successfully, otherwise false
*/
+ @Override
public boolean reportSlotStatus(InstanceID instanceId, SlotReport slotReport) {
checkInit();
@@ -449,6 +456,7 @@ public class SlotManager implements AutoCloseable {
* @param slotId identifying the slot to free
* @param allocationId with which the slot is presumably allocated
*/
+ @Override
public void freeSlot(SlotID slotId, AllocationID allocationId) {
checkInit();
@@ -478,6 +486,7 @@ public class SlotManager implements AutoCloseable {
}
}
+ @Override
public void setFailUnfulfillableRequest(boolean failUnfulfillableRequest) {
if (!this.failUnfulfillableRequest && failUnfulfillableRequest) {
// fail unfulfillable pending requests
@@ -1181,6 +1190,7 @@ public class SlotManager implements AutoCloseable {
}
}
+ @Override
@VisibleForTesting
public void unregisterTaskManagersAndReleaseResources() {
Iterator<Map.Entry<InstanceID, TaskManagerRegistration>> taskManagerRegistrationIterator =
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerBuilder.java b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerBuilder.java
index cc99370..15b65ed 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerBuilder.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerBuilder.java
@@ -22,7 +22,7 @@ import org.apache.flink.api.common.time.Time;
import org.apache.flink.runtime.concurrent.ScheduledExecutor;
import org.apache.flink.runtime.testingUtils.TestingUtils;
-/** Builder for {@link SlotManager}. */
+/** Builder for {@link SlotManagerImpl}. */
public class SlotManagerBuilder {
private ScheduledExecutor scheduledExecutor;
private Time taskManagerRequestTimeout;
@@ -67,8 +67,8 @@ public class SlotManagerBuilder {
return this;
}
- public SlotManager build() {
- return new SlotManager(
+ public SlotManagerImpl build() {
+ return new SlotManagerImpl(
scheduledExecutor,
taskManagerRequestTimeout,
slotRequestTimeout,
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerTest.java
index c358866..b155ed6 100755
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerTest.java
@@ -95,7 +95,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
- * Tests for the {@link SlotManager}.
+ * Tests for the {@link SlotManagerImpl}.
*/
public class SlotManagerTest extends TestLogger {
@@ -118,7 +118,7 @@ public class SlotManagerTest extends TestLogger {
final SlotStatus slotStatus2 = new SlotStatus(slotId2, resourceProfile);
final SlotReport slotReport = new SlotReport(Arrays.asList(slotStatus1, slotStatus2));
- try (SlotManager slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
+ try (SlotManagerImpl slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
slotManager.registerTaskManager(taskManagerConnection, slotReport);
assertTrue("The number registered slots does not equal the expected number.", 2 == slotManager.getNumberRegisteredSlots());
@@ -162,7 +162,7 @@ public class SlotManagerTest extends TestLogger {
resourceProfile,
"foobar");
- try (SlotManager slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
+ try (SlotManagerImpl slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
slotManager.registerTaskManager(taskManagerConnection, slotReport);
assertTrue("The number registered slots does not equal the expected number.", 2 == slotManager.getNumberRegisteredSlots());
@@ -265,7 +265,7 @@ public class SlotManagerTest extends TestLogger {
ResourceActions resourceManagerActions = new TestingResourceActionsBuilder().build();
- try (SlotManager slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
+ try (SlotManagerImpl slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
final CompletableFuture<Tuple5<SlotID, JobID, AllocationID, String, ResourceManagerId>> requestFuture = new CompletableFuture<>();
// accept an incoming slot request
final TaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder()
@@ -318,7 +318,7 @@ public class SlotManagerTest extends TestLogger {
final TaskExecutorConnection taskManagerConnection = new TaskExecutorConnection(resourceID, taskExecutorGateway);
- try (SlotManager slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
+ try (SlotManagerImpl slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
slotManager.registerTaskManager(taskManagerConnection, slotReport);
TaskManagerSlot slot = slotManager.getSlot(slotId);
@@ -375,7 +375,7 @@ public class SlotManagerTest extends TestLogger {
final SlotStatus slotStatus = new SlotStatus(slotId, resourceProfile);
final SlotReport slotReport = new SlotReport(slotStatus);
- try (SlotManager slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
+ try (SlotManagerImpl slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
assertTrue("The slot request should be accepted", slotManager.registerSlotRequest(slotRequest));
@@ -415,7 +415,7 @@ public class SlotManagerTest extends TestLogger {
final SlotStatus slotStatus = new SlotStatus(slotId, resourceProfile, jobId, allocationId);
final SlotReport slotReport = new SlotReport(slotStatus);
- try (SlotManager slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
+ try (SlotManagerImpl slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
slotManager.registerTaskManager(
taskExecutorConnection,
@@ -521,7 +521,7 @@ public class SlotManagerTest extends TestLogger {
final SlotStatus slotStatus = new SlotStatus(slotId, resourceProfile1);
final SlotReport slotReport = new SlotReport(slotStatus);
- try (SlotManager slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
+ try (SlotManagerImpl slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
slotManager.registerTaskManager(taskManagerConnection, slotReport);
assertTrue(slotManager.registerSlotRequest(slotRequest1));
@@ -563,7 +563,7 @@ public class SlotManagerTest extends TestLogger {
final SlotStatus slotStatus = new SlotStatus(slotId, new ResourceProfile(2.0, 2));
final SlotReport slotReport = new SlotReport(slotStatus);
- try (SlotManager slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
+ try (SlotManagerImpl slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
slotManager.registerTaskManager(taskManagerConnection, slotReport);
assertTrue(slotManager.registerSlotRequest(slotRequest1));
@@ -641,7 +641,7 @@ public class SlotManagerTest extends TestLogger {
final TaskExecutorGateway taskExecutorGateway = mock(TaskExecutorGateway.class);
final TaskExecutorConnection taskManagerConnection = new TaskExecutorConnection(resourceId, taskExecutorGateway);
- try (SlotManager slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
+ try (SlotManagerImpl slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
// check that we don't have any slots registered
assertTrue(0 == slotManager.getNumberRegisteredSlots());
@@ -747,7 +747,7 @@ public class SlotManagerTest extends TestLogger {
final SlotStatus slotStatus2 = new SlotStatus(slotId2, resourceProfile);
final SlotReport slotReport = new SlotReport(Arrays.asList(slotStatus1, slotStatus2));
- try (SlotManager slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
+ try (SlotManagerImpl slotManager = createSlotManager(resourceManagerId, resourceManagerActions)) {
slotManager.registerTaskManager(taskManagerConnection, slotReport);
@@ -827,7 +827,7 @@ public class SlotManagerTest extends TestLogger {
final Executor mainThreadExecutor = TestingUtils.defaultExecutor();
- try (final SlotManager slotManager = SlotManagerBuilder.newBuilder().build()) {
+ try (final SlotManagerImpl slotManager = SlotManagerBuilder.newBuilder().build()) {
slotManager.start(resourceManagerId, mainThreadExecutor, resourceManagerActions);
@@ -943,7 +943,7 @@ public class SlotManagerTest extends TestLogger {
final Executor mainThreadExecutor = TestingUtils.defaultExecutor();
- try (final SlotManager slotManager = SlotManagerBuilder.newBuilder()
+ try (final SlotManagerImpl slotManager = SlotManagerBuilder.newBuilder()
.setTaskManagerTimeout(Time.of(taskManagerTimeout, TimeUnit.MILLISECONDS))
.build()) {
@@ -1046,7 +1046,7 @@ public class SlotManagerTest extends TestLogger {
final TestingTaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().createTestingTaskExecutorGateway();
final TaskExecutorConnection taskExecutorConnection = new TaskExecutorConnection(taskManagerId, taskExecutorGateway);
- try (final SlotManager slotManager = SlotManagerBuilder.newBuilder().build()) {
+ try (final SlotManagerImpl slotManager = SlotManagerBuilder.newBuilder().build()) {
slotManager.start(ResourceManagerId.generate(), Executors.directExecutor(), resourceActions);
@@ -1095,7 +1095,7 @@ public class SlotManagerTest extends TestLogger {
*/
@Test
public void testSlotRequestFailure() throws Exception {
- try (final SlotManager slotManager = createSlotManager(ResourceManagerId.generate(),
+ try (final SlotManagerImpl slotManager = createSlotManager(ResourceManagerId.generate(),
new TestingResourceActionsBuilder().build())) {
final SlotRequest slotRequest = new SlotRequest(new JobID(), new AllocationID(), ResourceProfile.UNKNOWN, "foobar");
@@ -1150,7 +1150,7 @@ public class SlotManagerTest extends TestLogger {
*/
@Test
public void testSlotRequestRemovedIfTMReportAllocation() throws Exception {
- try (final SlotManager slotManager = createSlotManager(ResourceManagerId.generate(),
+ try (final SlotManagerImpl slotManager = createSlotManager(ResourceManagerId.generate(),
new TestingResourceActionsBuilder().build())) {
final JobID jobID = new JobID();
@@ -1326,8 +1326,8 @@ public class SlotManagerTest extends TestLogger {
return new SlotRequest(jobId, new AllocationID(), resourceProfile, "foobar1");
}
- private SlotManager createSlotManager(ResourceManagerId resourceManagerId, ResourceActions resourceManagerActions) {
- SlotManager slotManager = SlotManagerBuilder.newBuilder().build();
+ private SlotManagerImpl createSlotManager(ResourceManagerId resourceManagerId, ResourceActions resourceManagerActions) {
+ SlotManagerImpl slotManager = SlotManagerBuilder.newBuilder().build();
slotManager.start(resourceManagerId, Executors.directExecutor(), resourceManagerActions);
return slotManager;
}
@@ -1348,7 +1348,7 @@ public class SlotManagerTest extends TestLogger {
}))
.build();
- try (final SlotManager slotManager = createSlotManager(
+ try (final SlotManagerImpl slotManager = createSlotManager(
ResourceManagerId.generate(),
testingResourceActions)) {
@@ -1377,7 +1377,7 @@ public class SlotManagerTest extends TestLogger {
final TestingResourceActions resourceActions = new TestingResourceActionsBuilder()
.setAllocateResourceFunction(convert(value -> numberSlots))
.build();
- try (final SlotManager slotManager = createSlotManager(ResourceManagerId.generate(), resourceActions)) {
+ try (final SlotManagerImpl slotManager = createSlotManager(ResourceManagerId.generate(), resourceActions)) {
final JobID jobId = new JobID();
final SlotRequest slotRequest = createSlotRequest(jobId);
@@ -1403,7 +1403,7 @@ public class SlotManagerTest extends TestLogger {
.setAllocateResourceFunction(convert(value -> numberSlots))
.build();
- try (final SlotManager slotManager = createSlotManager(ResourceManagerId.generate(), resourceActions)) {
+ try (final SlotManagerImpl slotManager = createSlotManager(ResourceManagerId.generate(), resourceActions)) {
final JobID jobId = new JobID();
assertThat(slotManager.registerSlotRequest(createSlotRequest(jobId)), is(true));
@@ -1438,7 +1438,7 @@ public class SlotManagerTest extends TestLogger {
.setAllocateResourceFunction(convert(value -> numberSlots))
.build();
- try (final SlotManager slotManager = createSlotManager(ResourceManagerId.generate(), resourceActions)) {
+ try (final SlotManagerImpl slotManager = createSlotManager(ResourceManagerId.generate(), resourceActions)) {
final JobID jobId = new JobID();
final ResourceProfile requestedSlotProfile = new ResourceProfile(1.0, 1);
@@ -1469,7 +1469,7 @@ public class SlotManagerTest extends TestLogger {
.setAllocateResourceFunction(convert(value -> numberSlots))
.build();
- try (final SlotManager slotManager = createSlotManager(ResourceManagerId.generate(), resourceActions)) {
+ try (final SlotManagerImpl slotManager = createSlotManager(ResourceManagerId.generate(), resourceActions)) {
final JobID jobId = new JobID();
assertThat(slotManager.registerSlotRequest(createSlotRequest(jobId)), is(true));
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TaskManagerReleaseInSlotManagerTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TaskManagerReleaseInSlotManagerTest.java
index 25f7ccb..8252c48 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TaskManagerReleaseInSlotManagerTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TaskManagerReleaseInSlotManagerTest.java
@@ -104,7 +104,7 @@ public class TaskManagerReleaseInSlotManagerTest extends TestLogger {
*/
@Test
public void testTaskManagerIsNotReleasedBeforeItCanBe() throws Exception {
- try (SlotManager slotManager = createAndStartSlotManagerWithTM()) {
+ try (SlotManagerImpl slotManager = createAndStartSlotManagerWithTM()) {
checkTaskManagerTimeoutWithCustomCanBeReleasedResponse(slotManager, false);
verifyTmReleased(false);
@@ -118,7 +118,7 @@ public class TaskManagerReleaseInSlotManagerTest extends TestLogger {
*/
@Test
public void testTaskManagerIsNotReleasedInCaseOfConcurrentAllocation() throws Exception {
- try (SlotManager slotManager = createAndStartSlotManagerWithTM()) {
+ try (SlotManagerImpl slotManager = createAndStartSlotManagerWithTM()) {
checkTaskManagerTimeoutWithCustomCanBeReleasedResponse(slotManager, true, () -> {
// Allocate and free slot between triggering TM.canBeReleased request and receiving response.
// There can be potentially newly unreleased partitions, therefore TM can not be released yet.
@@ -134,8 +134,8 @@ public class TaskManagerReleaseInSlotManagerTest extends TestLogger {
}
}
- private SlotManager createAndStartSlotManagerWithTM() {
- SlotManager slotManager = SlotManagerBuilder
+ private SlotManagerImpl createAndStartSlotManagerWithTM() {
+ SlotManagerImpl slotManager = SlotManagerBuilder
.newBuilder()
.setScheduledExecutor(mainThreadExecutor)
.setTaskManagerTimeout(Time.milliseconds(0L))
@@ -146,13 +146,13 @@ public class TaskManagerReleaseInSlotManagerTest extends TestLogger {
}
private void checkTaskManagerTimeoutWithCustomCanBeReleasedResponse(
- SlotManager slotManager,
+ SlotManagerImpl slotManager,
boolean canBeReleased) throws Exception {
checkTaskManagerTimeoutWithCustomCanBeReleasedResponse(slotManager, canBeReleased, () -> {});
}
private void checkTaskManagerTimeoutWithCustomCanBeReleasedResponse(
- SlotManager slotManager,
+ SlotManagerImpl slotManager,
boolean canBeReleased,
RunnableWithException doAfterCheckTriggerBeforeCanBeReleasedResponse) throws Exception {
canBeReleasedFuture.set(new CompletableFuture<>());
[flink] 06/06: [hotfix] Rename TestingSlotManagerFactory into
TestingSlotManagerBuilder
Posted by tr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
trohrmann pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 70fe6aa747ad021bbb8dd8cdc0beecc863f010be
Author: Till Rohrmann <tr...@apache.org>
AuthorDate: Tue Jul 30 14:55:24 2019 +0200
[hotfix] Rename TestingSlotManagerFactory into TestingSlotManagerBuilder
---
.../runtime/resourcemanager/StandaloneResourceManagerTest.java | 8 ++++----
...tingSlotManagerFactory.java => TestingSlotManagerBuilder.java} | 6 +++---
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManagerTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManagerTest.java
index 39d06a0..c39c14d 100755
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManagerTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManagerTest.java
@@ -27,7 +27,7 @@ import org.apache.flink.runtime.metrics.MetricRegistry;
import org.apache.flink.runtime.metrics.groups.JobManagerMetricGroup;
import org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups;
import org.apache.flink.runtime.resourcemanager.slotmanager.SlotManager;
-import org.apache.flink.runtime.resourcemanager.slotmanager.TestingSlotManagerFactory;
+import org.apache.flink.runtime.resourcemanager.slotmanager.TestingSlotManagerBuilder;
import org.apache.flink.runtime.resourcemanager.utils.MockResourceManagerRuntimeServices;
import org.apache.flink.runtime.rpc.FatalErrorHandler;
import org.apache.flink.runtime.rpc.RpcService;
@@ -61,7 +61,7 @@ public class StandaloneResourceManagerTest extends TestLogger {
@Test
public void testStartupPeriod() throws Exception {
final LinkedBlockingQueue<Boolean> setFailUnfulfillableRequestInvokes = new LinkedBlockingQueue<>();
- final SlotManager slotManager = new TestingSlotManagerFactory()
+ final SlotManager slotManager = new TestingSlotManagerBuilder()
.setSetFailUnfulfillableRequestConsumer(setFailUnfulfillableRequestInvokes::add)
.createSlotManager();
final TestingStandaloneResourceManager rm = createResourceManager(Time.milliseconds(1L), slotManager);
@@ -75,7 +75,7 @@ public class StandaloneResourceManagerTest extends TestLogger {
@Test
public void testNoStartupPeriod() throws Exception {
final LinkedBlockingQueue<Boolean> setFailUnfulfillableRequestInvokes = new LinkedBlockingQueue<>();
- final SlotManager slotManager = new TestingSlotManagerFactory()
+ final SlotManager slotManager = new TestingSlotManagerBuilder()
.setSetFailUnfulfillableRequestConsumer(setFailUnfulfillableRequestInvokes::add)
.createSlotManager();
final TestingStandaloneResourceManager rm = createResourceManager(Time.milliseconds(-1L), slotManager);
@@ -89,7 +89,7 @@ public class StandaloneResourceManagerTest extends TestLogger {
@Test
public void testStartUpPeriodAfterLeadershipSwitch() throws Exception {
final LinkedBlockingQueue<Boolean> setFailUnfulfillableRequestInvokes = new LinkedBlockingQueue<>();
- final SlotManager slotManager = new TestingSlotManagerFactory()
+ final SlotManager slotManager = new TestingSlotManagerBuilder()
.setSetFailUnfulfillableRequestConsumer(setFailUnfulfillableRequestInvokes::add)
.createSlotManager();
final TestingStandaloneResourceManager rm = createResourceManager(Time.milliseconds(1L), slotManager);
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TestingSlotManagerFactory.java b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TestingSlotManagerBuilder.java
similarity index 87%
rename from flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TestingSlotManagerFactory.java
rename to flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TestingSlotManagerBuilder.java
index a3e6ab4..f0c1c90 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TestingSlotManagerFactory.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TestingSlotManagerBuilder.java
@@ -23,11 +23,11 @@ import java.util.function.Consumer;
/**
* Factory for {@link TestingSlotManager}.
*/
-public class TestingSlotManagerFactory {
+public class TestingSlotManagerBuilder {
- private Consumer<Boolean> setFailUnfulfillableRequestConsumer;
+ private Consumer<Boolean> setFailUnfulfillableRequestConsumer = ignored -> {};
- public TestingSlotManagerFactory setSetFailUnfulfillableRequestConsumer(Consumer<Boolean> setFailUnfulfillableRequestConsumer) {
+ public TestingSlotManagerBuilder setSetFailUnfulfillableRequestConsumer(Consumer<Boolean> setFailUnfulfillableRequestConsumer) {
this.setFailUnfulfillableRequestConsumer = setFailUnfulfillableRequestConsumer;
return this;
}
[flink] 03/06: [FLINK-13408][runtime] Let StandaloneResourceManager
start startup period upon granting leadership
Posted by tr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
trohrmann pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 0f9d0952cd89a9866d17b9d00b5ff69738974f87
Author: Xintong Song <to...@gmail.com>
AuthorDate: Fri Jul 26 11:48:50 2019 +0200
[FLINK-13408][runtime] Let StandaloneResourceManager start startup period upon granting leadership
During the startup period, the StandaloneResourceManager won't fail slot requests if it cannot allocate new
containers.
[FLINK-13408][runtime][test] Add StandaloneResourceManagerTest#testStartUpPeriodAfterLeadershipSwitch validates that StandaloneResourceManager applies a startup period whenever the leadership is acquired.
[FLINK-13408][runtime] StandaloneResourceManager#startStartupPeriod uses RpcEndpoint#scheduleRunAsync.
This closes #9242.
---
.../clusterframework/MesosResourceManager.java | 1 -
.../runtime/resourcemanager/ResourceManager.java | 11 +-
.../resourcemanager/StandaloneResourceManager.java | 30 +++--
.../resourcemanager/slotmanager/SlotManager.java | 2 -
.../slotmanager/SlotManagerImpl.java | 5 -
.../StandaloneResourceManagerTest.java | 86 ++++++++++----
.../SlotManagerFailUnfulfillableTest.java | 6 +-
.../slotmanager/TestingSlotManager.java | 131 +++++++++++++++++++++
.../slotmanager/TestingSlotManagerFactory.java | 38 ++++++
.../utils/MockResourceManagerRuntimeServices.java | 20 +++-
.../org/apache/flink/yarn/YarnResourceManager.java | 1 -
11 files changed, 277 insertions(+), 54 deletions(-)
diff --git a/flink-mesos/src/main/java/org/apache/flink/mesos/runtime/clusterframework/MesosResourceManager.java b/flink-mesos/src/main/java/org/apache/flink/mesos/runtime/clusterframework/MesosResourceManager.java
index 0bb8d41..4604507 100755
--- a/flink-mesos/src/main/java/org/apache/flink/mesos/runtime/clusterframework/MesosResourceManager.java
+++ b/flink-mesos/src/main/java/org/apache/flink/mesos/runtime/clusterframework/MesosResourceManager.java
@@ -197,7 +197,6 @@ public class MesosResourceManager extends ResourceManager<RegisteredMesosWorkerN
this.workersBeingReturned = new HashMap<>(8);
this.slotsPerWorker = createWorkerSlotProfiles(flinkConfig);
- setFailUnfulfillableRequest(true);
}
protected ActorRef createSelfActor() {
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManager.java b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManager.java
index 1a77a98..ec71e85 100755
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManager.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManager.java
@@ -926,9 +926,7 @@ public abstract class ResourceManager<WorkerType extends ResourceIDRetrievable>
setFencingToken(newResourceManagerId);
- startHeartbeatServices();
-
- slotManager.start(getFencingToken(), getMainThreadExecutor(), new ResourceActionsImpl());
+ startServicesOnLeadership();
return prepareLeadershipAsync().thenApply(ignored -> true);
} else {
@@ -936,6 +934,12 @@ public abstract class ResourceManager<WorkerType extends ResourceIDRetrievable>
}
}
+ protected void startServicesOnLeadership() {
+ startHeartbeatServices();
+
+ slotManager.start(getFencingToken(), getMainThreadExecutor(), new ResourceActionsImpl());
+ }
+
/**
* Callback method when current resourceManager loses leadership.
*/
@@ -952,6 +956,7 @@ public abstract class ResourceManager<WorkerType extends ResourceIDRetrievable>
slotManager.suspend();
stopHeartbeatServices();
+
});
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManager.java b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManager.java
index bc0e8df..cab53d3 100755
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManager.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManager.java
@@ -80,16 +80,7 @@ public class StandaloneResourceManager extends ResourceManager<ResourceID> {
@Override
protected void initialize() throws ResourceManagerException {
- final long startupPeriodMillis = startupPeriodTime.toMilliseconds();
-
- if (startupPeriodMillis > 0) {
- getRpcService().getScheduledExecutor().schedule(
- () -> getMainThreadExecutor().execute(
- () -> setFailUnfulfillableRequest(true)),
- startupPeriodMillis,
- TimeUnit.MILLISECONDS
- );
- }
+ // nothing to initialize
}
@Override
@@ -112,4 +103,23 @@ public class StandaloneResourceManager extends ResourceManager<ResourceID> {
return resourceID;
}
+ @Override
+ protected void startServicesOnLeadership() {
+ super.startServicesOnLeadership();
+ startStartupPeriod();
+ }
+
+ private void startStartupPeriod() {
+ setFailUnfulfillableRequest(false);
+
+ final long startupPeriodMillis = startupPeriodTime.toMilliseconds();
+
+ if (startupPeriodMillis > 0) {
+ scheduleRunAsync(
+ () -> setFailUnfulfillableRequest(true),
+ startupPeriodMillis,
+ TimeUnit.MILLISECONDS
+ );
+ }
+ }
}
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManager.java b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManager.java
index 5b709d3..0bdbc5b 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManager.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManager.java
@@ -54,8 +54,6 @@ public interface SlotManager extends AutoCloseable {
int getNumberPendingSlotRequests();
- boolean isFailingUnfulfillableRequest();
-
/**
* Starts the slot manager with the given leader id and resource manager actions.
*
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerImpl.java b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerImpl.java
index 376d030..4e4124b 100755
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerImpl.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerImpl.java
@@ -194,11 +194,6 @@ public class SlotManagerImpl implements SlotManager {
return pendingSlotRequests.size();
}
- @Override
- public boolean isFailingUnfulfillableRequest() {
- return failUnfulfillableRequest;
- }
-
@VisibleForTesting
public int getNumberAssignedPendingTaskManagerSlots() {
return (int) pendingSlots.values().stream().filter(slot -> slot.getAssignedPendingSlotRequest() != null).count();
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManagerTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManagerTest.java
index 37dbccc..89b6fa6 100755
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManagerTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/StandaloneResourceManagerTest.java
@@ -28,6 +28,7 @@ import org.apache.flink.runtime.metrics.MetricRegistry;
import org.apache.flink.runtime.metrics.groups.JobManagerMetricGroup;
import org.apache.flink.runtime.metrics.groups.UnregisteredMetricGroups;
import org.apache.flink.runtime.resourcemanager.slotmanager.SlotManager;
+import org.apache.flink.runtime.resourcemanager.slotmanager.TestingSlotManagerFactory;
import org.apache.flink.runtime.resourcemanager.utils.MockResourceManagerRuntimeServices;
import org.apache.flink.runtime.rpc.FatalErrorHandler;
import org.apache.flink.runtime.rpc.RpcService;
@@ -41,7 +42,7 @@ import org.junit.Test;
import java.time.Duration;
import java.util.UUID;
-import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.LinkedBlockingQueue;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@@ -61,33 +62,64 @@ public class StandaloneResourceManagerTest extends TestLogger {
@Test
public void testStartupPeriod() throws Exception {
- final TestingStandaloneResourceManager rm = createResourceManager(Time.milliseconds(1L));
- final Deadline deadline = Deadline.fromNow(Duration.ofSeconds(10L));
+ final LinkedBlockingQueue<Boolean> setFailUnfulfillableRequestInvokes = new LinkedBlockingQueue<>();
+ final SlotManager slotManager = new TestingSlotManagerFactory()
+ .setSetFailUnfulfillableRequestConsumer(invoke -> setFailUnfulfillableRequestInvokes.add(invoke))
+ .createSlotManager();
+ final TestingStandaloneResourceManager rm = createResourceManager(Time.milliseconds(1L), slotManager);
- assertHappensUntil(() -> rm.isFailingUnfulfillableRequestAsync().join(), deadline);
+ final Deadline deadline = Deadline.fromNow(Duration.ofSeconds(1));
+ assertHappensUntil(() -> setFailUnfulfillableRequestInvokes.size() == 2, deadline);
+ assertThat(setFailUnfulfillableRequestInvokes.poll(), is(false));
+ assertThat(setFailUnfulfillableRequestInvokes.poll(), is(true));
rm.close();
}
@Test
public void testNoStartupPeriod() throws Exception {
- final TestingStandaloneResourceManager rm = createResourceManager(Time.milliseconds(-1L));
+ final LinkedBlockingQueue<Boolean> setFailUnfulfillableRequestInvokes = new LinkedBlockingQueue<>();
+ final SlotManager slotManager = new TestingSlotManagerFactory()
+ .setSetFailUnfulfillableRequestConsumer(invoke -> setFailUnfulfillableRequestInvokes.add(invoke))
+ .createSlotManager();
+ final TestingStandaloneResourceManager rm = createResourceManager(Time.milliseconds(-1L), slotManager);
- // startup includes initialization and granting leadership, so by the time we are
- // here, the initialization method scheduling the startup period will have been executed.
-
- assertThat(fatalErrorHandler.hasExceptionOccurred(), is(false));
-
- assertThat(rm.isFailingUnfulfillableRequestAsync().join(), is(false));
+ final Deadline deadline = Deadline.fromNow(Duration.ofSeconds(1));
+ assertNotHappens(() -> setFailUnfulfillableRequestInvokes.size() > 1, deadline);
+ assertThat(setFailUnfulfillableRequestInvokes.size(), is(1));
+ assertThat(setFailUnfulfillableRequestInvokes.poll(), is(false));
rm.close();
}
- private TestingStandaloneResourceManager createResourceManager(Time startupPeriod) throws Exception {
+ @Test
+ public void testStartUpPeriodAfterLeadershipSwitch() throws Exception {
+ final LinkedBlockingQueue<Boolean> setFailUnfulfillableRequestInvokes = new LinkedBlockingQueue<>();
+ final SlotManager slotManager = new TestingSlotManagerFactory()
+ .setSetFailUnfulfillableRequestConsumer(invoke -> setFailUnfulfillableRequestInvokes.add(invoke))
+ .createSlotManager();
+ final TestingStandaloneResourceManager rm = createResourceManager(Time.milliseconds(1L), slotManager);
+
+ final Deadline deadline1 = Deadline.fromNow(Duration.ofSeconds(1));
+ assertHappensUntil(() -> setFailUnfulfillableRequestInvokes.size() == 2, deadline1);
+ assertThat(setFailUnfulfillableRequestInvokes.poll(), is(false));
+ assertThat(setFailUnfulfillableRequestInvokes.poll(), is(true));
+
+ rm.rmServices.revokeLeadership();
+ rm.rmServices.grantLeadership();
+
+ final Deadline deadline2 = Deadline.fromNow(Duration.ofSeconds(1L));
+ assertHappensUntil(() -> setFailUnfulfillableRequestInvokes.size() == 2, deadline2);
+ assertThat(setFailUnfulfillableRequestInvokes.poll(), is(false));
+ assertThat(setFailUnfulfillableRequestInvokes.poll(), is(true));
+ }
+
+ private TestingStandaloneResourceManager createResourceManager(Time startupPeriod, SlotManager slotManager) throws Exception {
final MockResourceManagerRuntimeServices rmServices = new MockResourceManagerRuntimeServices(
RPC_SERVICE.getTestingRpcService(),
- TIMEOUT);
+ TIMEOUT,
+ slotManager);
final TestingStandaloneResourceManager rm = new TestingStandaloneResourceManager(
rmServices.rpcService,
@@ -101,7 +133,8 @@ public class StandaloneResourceManagerTest extends TestLogger {
new ClusterInformation("localhost", 1234),
fatalErrorHandler,
UnregisteredMetricGroups.createUnregisteredJobManagerMetricGroup(),
- startupPeriod);
+ startupPeriod,
+ rmServices);
rm.start();
rmServices.grantLeadership();
@@ -120,8 +153,20 @@ public class StandaloneResourceManagerTest extends TestLogger {
}
}
+ private static void assertNotHappens(
+ SupplierWithException<Boolean, InterruptedException> condition,
+ Deadline until) throws InterruptedException {
+ while (!condition.get()) {
+ if (!until.hasTimeLeft()) {
+ return;
+ }
+ Thread.sleep(2);
+ }
+ fail("condition was fulfilled before the deadline");
+ }
+
private static class TestingStandaloneResourceManager extends StandaloneResourceManager {
- private final SlotManager slotManagerForTest;
+ private final MockResourceManagerRuntimeServices rmServices;
private TestingStandaloneResourceManager(
RpcService rpcService,
@@ -135,7 +180,8 @@ public class StandaloneResourceManagerTest extends TestLogger {
ClusterInformation clusterInformation,
FatalErrorHandler fatalErrorHandler,
JobManagerMetricGroup jobManagerMetricGroup,
- Time startupPeriodTime) {
+ Time startupPeriodTime,
+ MockResourceManagerRuntimeServices rmServices) {
super(
rpcService,
resourceManagerEndpointId,
@@ -149,13 +195,7 @@ public class StandaloneResourceManagerTest extends TestLogger {
fatalErrorHandler,
jobManagerMetricGroup,
startupPeriodTime);
- slotManagerForTest = slotManager;
- }
-
- private CompletableFuture<Boolean> isFailingUnfulfillableRequestAsync() {
- return CompletableFuture.supplyAsync(
- slotManagerForTest::isFailingUnfulfillableRequest,
- getMainThreadExecutor());
+ this.rmServices = rmServices;
}
}
}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerFailUnfulfillableTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerFailUnfulfillableTest.java
index cda07fe..cc4a2c1 100755
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerFailUnfulfillableTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/SlotManagerFailUnfulfillableTest.java
@@ -54,6 +54,7 @@ public class SlotManagerFailUnfulfillableTest extends TestLogger {
final ResourceProfile fulfillableProfile = new ResourceProfile(1.0, 100);
final SlotManager slotManager = createSlotManagerNotStartingNewTMs();
+ slotManager.setFailUnfulfillableRequest(false);
registerFreeSlot(slotManager, availableProfile);
slotManager.registerSlotRequest(slotRequest(fulfillableProfile));
@@ -74,6 +75,7 @@ public class SlotManagerFailUnfulfillableTest extends TestLogger {
final List<AllocationID> allocationFailures = new ArrayList<>();
final SlotManager slotManager = createSlotManagerNotStartingNewTMs(allocationFailures);
+ slotManager.setFailUnfulfillableRequest(false);
registerFreeSlot(slotManager, availableProfile);
// test
@@ -94,6 +96,7 @@ public class SlotManagerFailUnfulfillableTest extends TestLogger {
final ResourceProfile newTmProfile = new ResourceProfile(2.0, 200);
final SlotManager slotManager = createSlotManagerStartingNewTMs();
+ slotManager.setFailUnfulfillableRequest(false);
registerFreeSlot(slotManager, availableProfile);
// test
@@ -111,7 +114,6 @@ public class SlotManagerFailUnfulfillableTest extends TestLogger {
final SlotManager slotManager = createSlotManagerNotStartingNewTMs();
registerFreeSlot(slotManager, availableProfile);
- slotManager.setFailUnfulfillableRequest(true);
// test
slotManager.registerSlotRequest(slotRequest(availableProfile));
@@ -130,7 +132,6 @@ public class SlotManagerFailUnfulfillableTest extends TestLogger {
final List<AllocationID> notifiedAllocationFailures = new ArrayList<>();
final SlotManager slotManager = createSlotManagerNotStartingNewTMs(notifiedAllocationFailures);
registerFreeSlot(slotManager, availableProfile);
- slotManager.setFailUnfulfillableRequest(true);
// test
try {
@@ -152,7 +153,6 @@ public class SlotManagerFailUnfulfillableTest extends TestLogger {
final SlotManager slotManager = createSlotManagerStartingNewTMs();
registerFreeSlot(slotManager, availableProfile);
- slotManager.setFailUnfulfillableRequest(true);
// test
slotManager.registerSlotRequest(slotRequest(newTmProfile));
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TestingSlotManager.java b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TestingSlotManager.java
new file mode 100644
index 0000000..a07846e
--- /dev/null
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TestingSlotManager.java
@@ -0,0 +1,131 @@
+/*
+ * 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.resourcemanager.slotmanager;
+
+import org.apache.flink.runtime.clusterframework.types.AllocationID;
+import org.apache.flink.runtime.clusterframework.types.SlotID;
+import org.apache.flink.runtime.instance.InstanceID;
+import org.apache.flink.runtime.resourcemanager.ResourceManagerId;
+import org.apache.flink.runtime.resourcemanager.SlotRequest;
+import org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection;
+import org.apache.flink.runtime.taskexecutor.SlotReport;
+
+import javax.annotation.Nullable;
+
+import java.util.concurrent.Executor;
+import java.util.function.Consumer;
+
+/**
+ * Implementation of {@link SlotManager} for testing purpose.
+ */
+public class TestingSlotManager implements SlotManager {
+
+ private final Consumer<Boolean> setFailUnfulfillableRequestConsumer;
+
+ public TestingSlotManager(@Nullable Consumer<Boolean> setFailUnfulfillableRequestConsumer) {
+ this.setFailUnfulfillableRequestConsumer = setFailUnfulfillableRequestConsumer;
+ }
+
+ @Override
+ public int getNumberRegisteredSlots() {
+ return 0;
+ }
+
+ @Override
+ public int getNumberRegisteredSlotsOf(InstanceID instanceId) {
+ return 0;
+ }
+
+ @Override
+ public int getNumberFreeSlots() {
+ return 0;
+ }
+
+ @Override
+ public int getNumberFreeSlotsOf(InstanceID instanceId) {
+ return 0;
+ }
+
+ @Override
+ public int getNumberPendingTaskManagerSlots() {
+ return 0;
+ }
+
+ @Override
+ public int getNumberPendingSlotRequests() {
+ return 0;
+ }
+
+ @Override
+ public void start(ResourceManagerId newResourceManagerId, Executor newMainThreadExecutor, ResourceActions newResourceActions) {
+
+ }
+
+ @Override
+ public void suspend() {
+
+ }
+
+ @Override
+ public boolean registerSlotRequest(SlotRequest slotRequest) throws SlotManagerException {
+ return false;
+ }
+
+ @Override
+ public boolean unregisterSlotRequest(AllocationID allocationId) {
+ return false;
+ }
+
+ @Override
+ public void registerTaskManager(TaskExecutorConnection taskExecutorConnection, SlotReport initialSlotReport) {
+
+ }
+
+ @Override
+ public boolean unregisterTaskManager(InstanceID instanceId) {
+ return false;
+ }
+
+ @Override
+ public boolean reportSlotStatus(InstanceID instanceId, SlotReport slotReport) {
+ return false;
+ }
+
+ @Override
+ public void freeSlot(SlotID slotId, AllocationID allocationId) {
+
+ }
+
+ @Override
+ public void setFailUnfulfillableRequest(boolean failUnfulfillableRequest) {
+ if (setFailUnfulfillableRequestConsumer != null) {
+ setFailUnfulfillableRequestConsumer.accept(failUnfulfillableRequest);
+ }
+ }
+
+ @Override
+ public void unregisterTaskManagersAndReleaseResources() {
+
+ }
+
+ @Override
+ public void close() throws Exception {
+
+ }
+}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TestingSlotManagerFactory.java b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TestingSlotManagerFactory.java
new file mode 100644
index 0000000..a3e6ab4
--- /dev/null
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/slotmanager/TestingSlotManagerFactory.java
@@ -0,0 +1,38 @@
+/*
+ * 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.resourcemanager.slotmanager;
+
+import java.util.function.Consumer;
+
+/**
+ * Factory for {@link TestingSlotManager}.
+ */
+public class TestingSlotManagerFactory {
+
+ private Consumer<Boolean> setFailUnfulfillableRequestConsumer;
+
+ public TestingSlotManagerFactory setSetFailUnfulfillableRequestConsumer(Consumer<Boolean> setFailUnfulfillableRequestConsumer) {
+ this.setFailUnfulfillableRequestConsumer = setFailUnfulfillableRequestConsumer;
+ return this;
+ }
+
+ public TestingSlotManager createSlotManager() {
+ return new TestingSlotManager(setFailUnfulfillableRequestConsumer);
+ }
+}
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/utils/MockResourceManagerRuntimeServices.java b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/utils/MockResourceManagerRuntimeServices.java
index 0b1a9bf..737decd 100755
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/utils/MockResourceManagerRuntimeServices.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/resourcemanager/utils/MockResourceManagerRuntimeServices.java
@@ -52,19 +52,23 @@ public class MockResourceManagerRuntimeServices {
public final SlotManager slotManager;
public MockResourceManagerRuntimeServices(RpcService rpcService, Time timeout) {
+ this(rpcService, timeout, SlotManagerBuilder.newBuilder()
+ .setScheduledExecutor(new ScheduledExecutorServiceAdapter(new DirectScheduledExecutorService()))
+ .setTaskManagerRequestTimeout(Time.seconds(10))
+ .setSlotRequestTimeout(Time.seconds(10))
+ .setTaskManagerTimeout(Time.minutes(1))
+ .build());
+ }
+
+ public MockResourceManagerRuntimeServices(RpcService rpcService, Time timeout, SlotManager slotManager) {
this.rpcService = checkNotNull(rpcService);
this.timeout = checkNotNull(timeout);
+ this.slotManager = slotManager;
highAvailabilityServices = new TestingHighAvailabilityServices();
rmLeaderElectionService = new TestingLeaderElectionService();
highAvailabilityServices.setResourceManagerLeaderElectionService(rmLeaderElectionService);
heartbeatServices = new TestingHeartbeatServices();
metricRegistry = NoOpMetricRegistry.INSTANCE;
- slotManager = SlotManagerBuilder.newBuilder()
- .setScheduledExecutor(new ScheduledExecutorServiceAdapter(new DirectScheduledExecutorService()))
- .setTaskManagerRequestTimeout(Time.seconds(10))
- .setSlotRequestTimeout(Time.seconds(10))
- .setTaskManagerTimeout(Time.minutes(1))
- .build();
jobLeaderIdService = new JobLeaderIdService(
highAvailabilityServices,
rpcService.getScheduledExecutor(),
@@ -75,4 +79,8 @@ public class MockResourceManagerRuntimeServices {
UUID rmLeaderSessionId = UUID.randomUUID();
rmLeaderElectionService.isLeader(rmLeaderSessionId).get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
}
+
+ public void revokeLeadership() {
+ rmLeaderElectionService.notLeader();
+ }
}
diff --git a/flink-yarn/src/main/java/org/apache/flink/yarn/YarnResourceManager.java b/flink-yarn/src/main/java/org/apache/flink/yarn/YarnResourceManager.java
index e9a1f2d..c7cb064 100755
--- a/flink-yarn/src/main/java/org/apache/flink/yarn/YarnResourceManager.java
+++ b/flink-yarn/src/main/java/org/apache/flink/yarn/YarnResourceManager.java
@@ -185,7 +185,6 @@ public class YarnResourceManager extends ResourceManager<YarnWorkerNode> impleme
this.resource = Resource.newInstance(defaultTaskManagerMemoryMB, defaultCpus);
this.slotsPerWorker = createWorkerSlotProfiles(flinkConfig);
- setFailUnfulfillableRequest(true);
}
protected AMRMClientAsync<AMRMClient.ContainerRequest> createAndStartResourceManagerClient(