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 2018/05/10 14:21:40 UTC
[1/9] flink git commit: [FLINK-9331] [mesos] Let MesosResourceManager
request new tasks for failed ones
Repository: flink
Updated Branches:
refs/heads/master b7f5c0d30 -> 1b1122fce
[FLINK-9331] [mesos] Let MesosResourceManager request new tasks for failed ones
In order to avoid the problem of not fulfilling allocation requests when a Mesos
tasks dies before it could register at the RM, this commit restarts all failed
Mesos tasks. The downside is that in some cases where the JM notices the failure
of a TM and would fail the job, we request tasks which are not directly needed.
This closes #5986.
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/1b1122fc
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/1b1122fc
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/1b1122fc
Branch: refs/heads/master
Commit: 1b1122fce18eaba4cc3539708fa555dbeafe88b5
Parents: 6b892a6
Author: Till Rohrmann <tr...@apache.org>
Authored: Thu May 10 15:02:38 2018 +0200
Committer: Till Rohrmann <tr...@apache.org>
Committed: Thu May 10 16:18:31 2018 +0200
----------------------------------------------------------------------
.../mesos/runtime/clusterframework/MesosResourceManager.java | 1 +
.../mesos/runtime/clusterframework/MesosResourceManagerTest.java | 3 +++
2 files changed, 4 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/1b1122fc/flink-mesos/src/main/java/org/apache/flink/mesos/runtime/clusterframework/MesosResourceManager.java
----------------------------------------------------------------------
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 4f4a6d1..9b5d50e 100644
--- 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
@@ -616,6 +616,7 @@ public class MesosResourceManager extends ResourceManager<RegisteredMesosWorkerN
assert(launched != null);
LOG.info("Worker {} failed with status: {}, reason: {}, message: {}.",
id, status.getState(), status.getReason(), status.getMessage());
+ startNewWorker(launched.profile());
}
closeTaskManagerConnection(id, new Exception(status.getMessage()));
http://git-wip-us.apache.org/repos/asf/flink/blob/1b1122fc/flink-mesos/src/test/java/org/apache/flink/mesos/runtime/clusterframework/MesosResourceManagerTest.java
----------------------------------------------------------------------
diff --git a/flink-mesos/src/test/java/org/apache/flink/mesos/runtime/clusterframework/MesosResourceManagerTest.java b/flink-mesos/src/test/java/org/apache/flink/mesos/runtime/clusterframework/MesosResourceManagerTest.java
index 5d9a6cf..91647c0 100644
--- a/flink-mesos/src/test/java/org/apache/flink/mesos/runtime/clusterframework/MesosResourceManagerTest.java
+++ b/flink-mesos/src/test/java/org/apache/flink/mesos/runtime/clusterframework/MesosResourceManagerTest.java
@@ -110,6 +110,7 @@ import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -683,6 +684,7 @@ public class MesosResourceManagerTest extends TestLogger {
MesosWorkerStore.Worker worker1launched = MesosWorkerStore.Worker.newWorker(task1).launchWorker(slave1, slave1host);
when(rmServices.workerStore.getFrameworkID()).thenReturn(Option.apply(framework1));
when(rmServices.workerStore.recoverWorkers()).thenReturn(singletonList(worker1launched));
+ when(rmServices.workerStore.newTaskID()).thenReturn(task2);
startResourceManager();
// tell the RM that a task failed
@@ -694,6 +696,7 @@ public class MesosResourceManagerTest extends TestLogger {
verify(rmServices.workerStore).removeWorker(task1);
assertThat(resourceManager.workersInLaunch.entrySet(), empty());
assertThat(resourceManager.workersBeingReturned.entrySet(), empty());
+ assertThat(resourceManager.workersInNew, hasKey(extractResourceID(task2)));
// verify that `closeTaskManagerConnection` was called
assertThat(resourceManager.closedTaskManagerConnections, hasItem(extractResourceID(task1)));
[9/9] flink git commit: [hotfix] [runtime] Add toString() methods to
SlotSharingManager and contained slot classes.
Posted by tr...@apache.org.
[hotfix] [runtime] Add toString() methods to SlotSharingManager and contained slot classes.
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/6ce67c14
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/6ce67c14
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/6ce67c14
Branch: refs/heads/master
Commit: 6ce67c14f7682df7f3c1153b7f8cc5897a5a630c
Parents: 00400e9
Author: Stephan Ewen <se...@apache.org>
Authored: Sat May 5 17:25:15 2018 +0200
Committer: Till Rohrmann <tr...@apache.org>
Committed: Thu May 10 16:18:31 2018 +0200
----------------------------------------------------------------------
.../jobmaster/slotpool/SlotSharingManager.java | 56 +++++++++++++++++++-
1 file changed, 54 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/6ce67c14/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotSharingManager.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotSharingManager.java b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotSharingManager.java
index 8fcf813..e3338fc 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotSharingManager.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotSharingManager.java
@@ -28,6 +28,7 @@ import org.apache.flink.runtime.jobmaster.SlotOwner;
import org.apache.flink.runtime.jobmaster.SlotRequestId;
import org.apache.flink.runtime.taskmanager.TaskManagerLocation;
import org.apache.flink.util.AbstractID;
+import org.apache.flink.util.ExceptionUtils;
import org.apache.flink.util.FlinkException;
import org.apache.flink.util.Preconditions;
@@ -213,6 +214,19 @@ public class SlotSharingManager {
return null;
}
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder("{\n\tgroupId=").append(slotSharingGroupId).append('\n');
+
+ synchronized (lock) {
+ builder.append("\tunresolved=").append(unresolvedRootSlots).append('\n');
+ builder.append("\tresolved=").append(resolvedRootSlots).append('\n');
+ builder.append("\tall=").append(allTaskSlots).append('\n');
+ }
+
+ return builder.append('}').toString();
+ }
+
// ------------------------------------------------------------------------
// Inner classes: TaskSlot hierarchy and helper classes
// ------------------------------------------------------------------------
@@ -499,6 +513,25 @@ public class SlotSharingManager {
}
}
}
+
+ @Override
+ public String toString() {
+ String physicalSlotDescription = "";
+ try {
+ physicalSlotDescription = String.valueOf(slotContextFuture.getNow(null));
+ }
+ catch (Exception e) {
+ physicalSlotDescription = '(' + ExceptionUtils.stripCompletionException(e).getMessage() + ')';
+ }
+
+ return "MultiTaskSlot{"
+ + "requestId=" + getSlotRequestId()
+ + ", allocatedRequestId=" + allocatedSlotRequestId
+ + ", groupId=" + getGroupId()
+ + ", physicalSlot=" + physicalSlotDescription
+ + ", children=" + children.values().toString()
+ + '}';
+ }
}
/**
@@ -540,8 +573,6 @@ public class SlotSharingManager {
public void release(Throwable cause) {
singleLogicalSlotFuture.completeExceptionally(cause);
- boolean pendingLogicalSlotRelease = false;
-
if (singleLogicalSlotFuture.isDone() && !singleLogicalSlotFuture.isCompletedExceptionally()) {
// we have a single task slot which we first have to release
final SingleLogicalSlot singleLogicalSlot = singleLogicalSlotFuture.getNow(null);
@@ -551,6 +582,27 @@ public class SlotSharingManager {
parent.releaseChild(getGroupId());
}
+
+ @Override
+ public String toString() {
+ String logicalSlotString = "(pending)";
+ try {
+ LogicalSlot slot = singleLogicalSlotFuture.getNow(null);
+ if (slot != null) {
+ logicalSlotString = "(requestId=" + slot.getSlotRequestId()
+ + ", allocationId=" + slot.getAllocationId() + ')';
+ }
+ }
+ catch (Exception e) {
+ logicalSlotString = '(' + ExceptionUtils.stripCompletionException(e).getMessage() + ')';
+ }
+
+ return "SingleTaskSlot{"
+ + "logicalSlot=" + logicalSlotString
+ + ", request=" + getSlotRequestId()
+ + ", group=" + getGroupId()
+ + '}';
+ }
}
// ------------------------------------------------------------------------
[7/9] flink git commit: [hotfix] [runtime] Minor code cleanups and
improved comments.
Posted by tr...@apache.org.
[hotfix] [runtime] Minor code cleanups and improved comments.
- Clarify the purposes of AllocationID versus SlotRequestId.
- Remove an unnecessary method indirection
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/00400e92
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/00400e92
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/00400e92
Branch: refs/heads/master
Commit: 00400e9259e11e34a9114f2c3545a3f7475cd92a
Parents: c7eb6ac
Author: Stephan Ewen <se...@apache.org>
Authored: Fri May 4 18:19:10 2018 +0200
Committer: Till Rohrmann <tr...@apache.org>
Committed: Thu May 10 16:18:31 2018 +0200
----------------------------------------------------------------------
.../clusterframework/types/AllocationID.java | 15 ++++++++++-----
.../flink/runtime/jobmaster/SlotRequestId.java | 20 +++++++++++++-------
.../runtime/jobmaster/slotpool/SlotPool.java | 16 +---------------
3 files changed, 24 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/00400e92/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/types/AllocationID.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/types/AllocationID.java b/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/types/AllocationID.java
index 59d8f9d..e722e9f 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/types/AllocationID.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/clusterframework/types/AllocationID.java
@@ -21,11 +21,16 @@ package org.apache.flink.runtime.clusterframework.types;
import org.apache.flink.util.AbstractID;
/**
- * Unique identifier for a slot allocated by a JobManager from a TaskManager.
- * Also identifies a pending allocation request, and is constant across retries.
- *
- * <p>This ID is used for all synchronization of the status of Slots from TaskManagers
- * that are not free (i.e., have been allocated by a job).
+ * Unique identifier for a physical slot allocated by a JobManager via the ResourceManager
+ * from a TaskManager. The ID is assigned once the JobManager (or its SlotPool) first
+ * requests the slot and is constant across retries.
+ *
+ * <p>This ID is used by the TaskManager and ResourceManager to track and synchronize which
+ * slots are allocated to which JobManager and which are free.
+ *
+ * <p>In contrast to this AllocationID, the {@link org.apache.flink.runtime.jobmaster.SlotRequestId}
+ * is used when a task requests a logical slot from the SlotPool. Multiple logical slot requests
+ * can map to one physical slot request (due to slot sharing).
*/
public class AllocationID extends AbstractID {
http://git-wip-us.apache.org/repos/asf/flink/blob/00400e92/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/SlotRequestId.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/SlotRequestId.java b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/SlotRequestId.java
index d3fa775..203139c 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/SlotRequestId.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/SlotRequestId.java
@@ -23,15 +23,21 @@ import org.apache.flink.runtime.jobmaster.slotpool.SlotProvider;
import org.apache.flink.util.AbstractID;
/**
- * Request id identifying slot requests made by the {@link SlotProvider} towards the
- * {@link SlotPool}.
+ * This ID identifies the request for a logical slot from the Execution to the {@link SlotPool}
+ * oe {@link SlotProvider}. The logical slot may be a physical slot or a sub-slot thereof, in
+ * the case of slot sharing.
+ *
+ * <p>This ID serves a different purpose than the
+ * {@link org.apache.flink.runtime.clusterframework.types.AllocationID AllocationID}, which identifies
+ * the request of a physical slot, issued from the SlotPool via the ResourceManager to the TaskManager.
*/
public final class SlotRequestId extends AbstractID {
- private static final long serialVersionUID = -6072105912250154283L;
- public SlotRequestId(long lowerPart, long upperPart) {
- super(lowerPart, upperPart);
- }
+ private static final long serialVersionUID = -6072105912250154283L;
+
+ public SlotRequestId(long lowerPart, long upperPart) {
+ super(lowerPart, upperPart);
+ }
- public SlotRequestId() {}
+ public SlotRequestId() {}
}
http://git-wip-us.apache.org/repos/asf/flink/blob/00400e92/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java
index f53104d..c9366c3 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java
@@ -303,25 +303,11 @@ public class SlotPool extends RpcEndpoint implements SlotPoolGateway, AllocatedS
@Override
public CompletableFuture<LogicalSlot> allocateSlot(
SlotRequestId slotRequestId,
- ScheduledUnit scheduledUnit,
- SlotProfile slotProfile,
- boolean allowQueuedScheduling,
- Time timeout) {
-
- return internalAllocateSlot(
- slotRequestId,
- scheduledUnit,
- slotProfile,
- allowQueuedScheduling,
- timeout);
- }
-
- private CompletableFuture<LogicalSlot> internalAllocateSlot(
- SlotRequestId slotRequestId,
ScheduledUnit task,
SlotProfile slotProfile,
boolean allowQueuedScheduling,
Time allocationTimeout) {
+
final SlotSharingGroupId slotSharingGroupId = task.getSlotSharingGroupId();
if (slotSharingGroupId != null) {
[6/9] flink git commit: [hotfix][yarn] Reduce visibility of fields.
Posted by tr...@apache.org.
[hotfix][yarn] Reduce visibility of fields.
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/90a0a910
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/90a0a910
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/90a0a910
Branch: refs/heads/master
Commit: 90a0a91079a4e271404dadee4cf4106dfd18ad89
Parents: fa11015
Author: gyao <ga...@data-artisans.com>
Authored: Fri Apr 27 15:51:38 2018 +0200
Committer: Till Rohrmann <tr...@apache.org>
Committed: Thu May 10 16:18:31 2018 +0200
----------------------------------------------------------------------
.../src/main/java/org/apache/flink/yarn/YarnResourceManager.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/90a0a910/flink-yarn/src/main/java/org/apache/flink/yarn/YarnResourceManager.java
----------------------------------------------------------------------
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 266c037..c498634 100644
--- a/flink-yarn/src/main/java/org/apache/flink/yarn/YarnResourceManager.java
+++ b/flink-yarn/src/main/java/org/apache/flink/yarn/YarnResourceManager.java
@@ -74,14 +74,14 @@ public class YarnResourceManager extends ResourceManager<YarnWorkerNode> impleme
private final Map<String, String> env;
/** YARN container map. Package private for unit test purposes. */
- final ConcurrentMap<ResourceID, YarnWorkerNode> workerNodeMap;
+ private final ConcurrentMap<ResourceID, YarnWorkerNode> workerNodeMap;
/** The heartbeat interval while the resource master is waiting for containers. */
private static final int FAST_YARN_HEARTBEAT_INTERVAL_MS = 500;
/** Environment variable name of the final container id used by the YarnResourceManager.
* Container ID generation may vary across Hadoop versions. */
- static final String ENV_FLINK_CONTAINER_ID = "_FLINK_CONTAINER_ID";
+ private static final String ENV_FLINK_CONTAINER_ID = "_FLINK_CONTAINER_ID";
/** Environment variable name of the hostname given by the YARN.
* In task executor we use the hostnames given by YARN consistently throughout akka */
[2/9] flink git commit: [hotfix] [runtime] Add toString() and print
methods to SlotPool classes for as debugging/diagnostic helpers
Posted by tr...@apache.org.
[hotfix] [runtime] Add toString() and print methods to SlotPool classes for as debugging/diagnostic helpers
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/1a91bcee
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/1a91bcee
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/1a91bcee
Branch: refs/heads/master
Commit: 1a91bcee251a2a14ff7856b175af88ca726ef1cc
Parents: 6ce67c1
Author: Stephan Ewen <se...@apache.org>
Authored: Sat May 5 17:58:20 2018 +0200
Committer: Till Rohrmann <tr...@apache.org>
Committed: Thu May 10 16:18:31 2018 +0200
----------------------------------------------------------------------
.../runtime/jobmaster/slotpool/SlotPool.java | 50 ++++++++++++++++++++
1 file changed, 50 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/1a91bcee/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java
index c9366c3..6ea74d1 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java
@@ -63,6 +63,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
@@ -308,6 +309,8 @@ public class SlotPool extends RpcEndpoint implements SlotPoolGateway, AllocatedS
boolean allowQueuedScheduling,
Time allocationTimeout) {
+ log.debug("Allocating slot with request {} for task execution {}", slotRequestId, task.getTaskToExecute());
+
final SlotSharingGroupId slotSharingGroupId = task.getSlotSharingGroupId();
if (slotSharingGroupId != null) {
@@ -1135,6 +1138,36 @@ public class SlotPool extends RpcEndpoint implements SlotPoolGateway, AllocatedS
// Methods for tests
// ------------------------------------------------------------------------
+ private String printStatus() {
+ validateRunsInMainThread();
+
+ final StringBuilder builder = new StringBuilder(1024).append("Slot Pool Status:\n");
+
+ builder.append("\tstatus: ");
+ if (resourceManagerGateway != null) {
+ builder.append("connected to ").append(resourceManagerGateway.getAddress()).append('\n');
+ } else {
+ builder.append("unconnected and waiting for ResourceManager ")
+ .append(waitingForResourceManager)
+ .append('\n');
+ }
+
+ builder.append("\tregistered TaskManagers: ").append(registeredTaskManagers).append('\n');
+
+ builder.append("\tavailable slots: ").append(availableSlots.printAllSlots()).append('\n');
+ builder.append("\tallocated slots: ").append(allocatedSlots.printAllSlots()).append('\n');
+
+ builder.append("\tpending requests: ").append(pendingRequests.values()).append('\n');
+
+ builder.append("\tsharing groups: {\n");
+ for (Entry<SlotSharingGroupId, SlotSharingManager> manager : slotSharingManagers.entrySet()) {
+ builder.append("\t -------- ").append(manager.getKey()).append(" --------\n");
+ builder.append(manager.getValue());
+ }
+ builder.append("\t}\n");
+ return builder.toString();
+ }
+
@VisibleForTesting
protected AllocatedSlots getAllocatedSlots() {
return allocatedSlots;
@@ -1291,6 +1324,10 @@ public class SlotPool extends RpcEndpoint implements SlotPoolGateway, AllocatedS
allocatedSlotsByTaskManager.clear();
}
+ String printAllSlots() {
+ return allocatedSlotsByTaskManager.values().toString();
+ }
+
@VisibleForTesting
boolean containResource(final ResourceID resourceID) {
return allocatedSlotsByTaskManager.containsKey(resourceID);
@@ -1480,6 +1517,10 @@ public class SlotPool extends RpcEndpoint implements SlotPoolGateway, AllocatedS
}
}
+ String printAllSlots() {
+ return availableSlots.values().toString();
+ }
+
@VisibleForTesting
boolean containsTaskManager(ResourceID resourceID) {
return availableSlotsByTaskManager.containsKey(resourceID);
@@ -1593,6 +1634,15 @@ public class SlotPool extends RpcEndpoint implements SlotPoolGateway, AllocatedS
public ResourceProfile getResourceProfile() {
return resourceProfile;
}
+
+ @Override
+ public String toString() {
+ return "PendingRequest{" +
+ "slotRequestId=" + slotRequestId +
+ ", resourceProfile=" + resourceProfile +
+ ", allocatedSlotFuture=" + allocatedSlotFuture +
+ '}';
+ }
}
// ------------------------------------------------------------------------
[5/9] flink git commit: [FLINK-9324] Wait for slot release before
completing release future in SingleLogicalSlot
Posted by tr...@apache.org.
[FLINK-9324] Wait for slot release before completing release future in SingleLogicalSlot
This commit properly waits for the completion of the SingleLogicalSlot's release future
until the SlotOwner has acknowledged the release. That way the ExecutionGraph will only
recover after all of its slots have been returned to the SlotPool.
As a side effect, the changes in this commit should reduce the number of redundant release
calls sent to the SlotOwner which cluttered the debug logs.
This closes #5980.
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/c7eb6aca
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/c7eb6aca
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/c7eb6aca
Branch: refs/heads/master
Commit: c7eb6acaf95a6656ec6bd0a0b401c1944473e7f2
Parents: 3c86b6b
Author: Till Rohrmann <tr...@apache.org>
Authored: Wed May 9 15:29:36 2018 +0200
Committer: Till Rohrmann <tr...@apache.org>
Committed: Thu May 10 16:18:31 2018 +0200
----------------------------------------------------------------------
.../jobmanager/slots/SlotAndLocality.java | 60 ----
.../jobmaster/slotpool/AllocatedSlot.java | 22 +-
.../jobmaster/slotpool/SingleLogicalSlot.java | 89 +++--
.../jobmaster/slotpool/SlotAndLocality.java | 59 ++++
.../runtime/jobmaster/slotpool/SlotPool.java | 7 +-
.../jobmaster/slotpool/SlotSharingManager.java | 93 +++---
.../jobmaster/slotpool/AvailableSlotsTest.java | 1 -
.../jobmaster/slotpool/DummyPayload.java | 50 +++
.../slotpool/SingleLogicalSlotTest.java | 323 +++++++++++++++++++
.../jobmaster/slotpool/SlotPoolTest.java | 31 +-
.../slotpool/SlotSharingManagerTest.java | 6 +-
11 files changed, 556 insertions(+), 185 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/c7eb6aca/flink-runtime/src/main/java/org/apache/flink/runtime/jobmanager/slots/SlotAndLocality.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmanager/slots/SlotAndLocality.java b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmanager/slots/SlotAndLocality.java
deleted file mode 100644
index fed26c9..0000000
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmanager/slots/SlotAndLocality.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.jobmanager.slots;
-
-import org.apache.flink.runtime.jobmanager.scheduler.Locality;
-import org.apache.flink.runtime.jobmaster.slotpool.AllocatedSlot;
-
-import javax.annotation.Nonnull;
-
-/**
- * A combination of a {@link AllocatedSlot} and a {@link Locality}.
- */
-public class SlotAndLocality {
-
- @Nonnull
- private final AllocatedSlot slot;
-
- @Nonnull
- private final Locality locality;
-
- public SlotAndLocality(@Nonnull AllocatedSlot slot, @Nonnull Locality locality) {
- this.slot = slot;
- this.locality = locality;
- }
-
- // ------------------------------------------------------------------------
-
- @Nonnull
- public AllocatedSlot getSlot() {
- return slot;
- }
-
- @Nonnull
- public Locality getLocality() {
- return locality;
- }
-
- // ------------------------------------------------------------------------
-
- @Override
- public String toString() {
- return "Slot: " + slot + " (" + locality + ')';
- }
-}
http://git-wip-us.apache.org/repos/asf/flink/blob/c7eb6aca/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/AllocatedSlot.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/AllocatedSlot.java b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/AllocatedSlot.java
index d3b2ab2..75195cd 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/AllocatedSlot.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/AllocatedSlot.java
@@ -42,7 +42,7 @@ import static org.apache.flink.util.Preconditions.checkNotNull;
* an AllocatedSlot was allocated to the JobManager as soon as the TaskManager registered at the
* JobManager. All slots had a default unknown resource profile.
*/
-public class AllocatedSlot implements SlotContext {
+class AllocatedSlot implements SlotContext {
/** The ID under which the slot is allocated. Uniquely identifies the slot. */
private final AllocationID allocationId;
@@ -171,21 +171,13 @@ public class AllocatedSlot implements SlotContext {
* then it is removed from the slot.
*
* @param cause of the release operation
- * @return true if the payload could be released and was removed from the slot, otherwise false
*/
- public boolean releasePayload(Throwable cause) {
+ public void releasePayload(Throwable cause) {
final Payload payload = payloadReference.get();
if (payload != null) {
- if (payload.release(cause)) {
- payloadReference.set(null);
-
- return true;
- } else {
- return false;
- }
- } else {
- return true;
+ payload.release(cause);
+ payloadReference.set(null);
}
}
@@ -222,12 +214,10 @@ public class AllocatedSlot implements SlotContext {
interface Payload {
/**
- * Releases the payload. If the payload could be released, then it returns true,
- * otherwise false.
+ * Releases the payload
*
* @param cause of the payload release
- * @return true if the payload could be released, otherwise false
*/
- boolean release(Throwable cause);
+ void release(Throwable cause);
}
}
http://git-wip-us.apache.org/repos/asf/flink/blob/c7eb6aca/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SingleLogicalSlot.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SingleLogicalSlot.java b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SingleLogicalSlot.java
index 0736b56..9ee4db8 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SingleLogicalSlot.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SingleLogicalSlot.java
@@ -33,6 +33,7 @@ import javax.annotation.Nullable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+import java.util.function.Function;
/**
* Implementation of the {@link LogicalSlot} which is used by the {@link SlotPool}.
@@ -44,6 +45,11 @@ public class SingleLogicalSlot implements LogicalSlot, AllocatedSlot.Payload {
Payload.class,
"payload");
+ private static final AtomicReferenceFieldUpdater<SingleLogicalSlot, State> STATE_UPDATER = AtomicReferenceFieldUpdater.newUpdater(
+ SingleLogicalSlot.class,
+ State.class,
+ "state");
+
private final SlotRequestId slotRequestId;
private final SlotContext slotContext;
@@ -58,6 +64,10 @@ public class SingleLogicalSlot implements LogicalSlot, AllocatedSlot.Payload {
// owner of this slot to which it is returned upon release
private final SlotOwner slotOwner;
+ private final CompletableFuture<Void> releaseFuture;
+
+ private volatile State state;
+
// LogicalSlot.Payload of this slot
private volatile Payload payload;
@@ -72,8 +82,10 @@ public class SingleLogicalSlot implements LogicalSlot, AllocatedSlot.Payload {
this.slotSharingGroupId = slotSharingGroupId;
this.locality = Preconditions.checkNotNull(locality);
this.slotOwner = Preconditions.checkNotNull(slotOwner);
+ this.releaseFuture = new CompletableFuture<>();
- payload = null;
+ this.state = State.ALIVE;
+ this.payload = null;
}
@Override
@@ -93,20 +105,11 @@ public class SingleLogicalSlot implements LogicalSlot, AllocatedSlot.Payload {
@Override
public boolean isAlive() {
- final Payload currentPayload = payload;
-
- if (currentPayload != null) {
- return !currentPayload.getTerminalStateFuture().isDone();
- } else {
- // We are always alive if there is no payload assigned yet.
- // If this slot is released and no payload is assigned, then the TERMINATED_PAYLOAD is assigned
- return true;
- }
+ return state == State.ALIVE;
}
@Override
public boolean tryAssignPayload(Payload payload) {
- Preconditions.checkNotNull(payload);
return PAYLOAD_UPDATER.compareAndSet(this, null, payload);
}
@@ -118,15 +121,12 @@ public class SingleLogicalSlot implements LogicalSlot, AllocatedSlot.Payload {
@Override
public CompletableFuture<?> releaseSlot(@Nullable Throwable cause) {
- // set an already terminated payload if the payload of this slot is still empty
- tryAssignPayload(TERMINATED_PAYLOAD);
-
- // notify the payload that the slot will be released
- payload.fail(cause);
+ if (STATE_UPDATER.compareAndSet(this, State.ALIVE, State.RELEASING)) {
+ final CompletableFuture<?> payloadTerminalStateFuture = signalPayloadRelease(cause);
+ returnSlotToOwner(payloadTerminalStateFuture);
+ }
- // Wait until the payload has been terminated. Only then, we return the slot to its rightful owner
- return payload.getTerminalStateFuture()
- .whenComplete((Object ignored, Throwable throwable) -> slotOwner.returnAllocatedSlot(this));
+ return releaseFuture;
}
@Override
@@ -159,10 +159,55 @@ public class SingleLogicalSlot implements LogicalSlot, AllocatedSlot.Payload {
* the logical slot.
*
* @param cause of the payload release
- * @return true if the logical slot's payload could be released, otherwise false
*/
@Override
- public boolean release(Throwable cause) {
- return releaseSlot(cause).isDone();
+ public void release(Throwable cause) {
+ if (STATE_UPDATER.compareAndSet(this, State.ALIVE, State.RELEASING)) {
+ signalPayloadRelease(cause);
+ }
+ markReleased();
+ releaseFuture.complete(null);
+ }
+
+ private CompletableFuture<?> signalPayloadRelease(Throwable cause) {
+ tryAssignPayload(TERMINATED_PAYLOAD);
+ payload.fail(cause);
+
+ return payload.getTerminalStateFuture();
+ }
+
+ private void returnSlotToOwner(CompletableFuture<?> terminalStateFuture) {
+ final CompletableFuture<Boolean> slotReturnFuture = terminalStateFuture.handle((Object ignored, Throwable throwable) -> {
+ if (state == State.RELEASING) {
+ return slotOwner.returnAllocatedSlot(this);
+ } else {
+ return CompletableFuture.completedFuture(true);
+ }
+ }).thenCompose(Function.identity());
+
+ slotReturnFuture.whenComplete(
+ (Object ignored, Throwable throwable) -> {
+ markReleased();
+
+ if (throwable != null) {
+ releaseFuture.completeExceptionally(throwable);
+ } else {
+ releaseFuture.complete(null);
+ }
+ });
+ }
+
+ private void markReleased() {
+ state = State.RELEASED;
+ }
+
+ // -------------------------------------------------------------------------
+ // Internal classes
+ // -------------------------------------------------------------------------
+
+ enum State {
+ ALIVE,
+ RELEASING,
+ RELEASED
}
}
http://git-wip-us.apache.org/repos/asf/flink/blob/c7eb6aca/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotAndLocality.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotAndLocality.java b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotAndLocality.java
new file mode 100644
index 0000000..4befb51
--- /dev/null
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotAndLocality.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.jobmaster.slotpool;
+
+import org.apache.flink.runtime.jobmanager.scheduler.Locality;
+
+import javax.annotation.Nonnull;
+
+/**
+ * A combination of a {@link AllocatedSlot} and a {@link Locality}.
+ */
+public class SlotAndLocality {
+
+ @Nonnull
+ private final AllocatedSlot slot;
+
+ @Nonnull
+ private final Locality locality;
+
+ public SlotAndLocality(@Nonnull AllocatedSlot slot, @Nonnull Locality locality) {
+ this.slot = slot;
+ this.locality = locality;
+ }
+
+ // ------------------------------------------------------------------------
+
+ @Nonnull
+ public AllocatedSlot getSlot() {
+ return slot;
+ }
+
+ @Nonnull
+ public Locality getLocality() {
+ return locality;
+ }
+
+ // ------------------------------------------------------------------------
+
+ @Override
+ public String toString() {
+ return "Slot: " + slot + " (" + locality + ')';
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/c7eb6aca/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java
index 2b78656..f53104d 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java
@@ -35,7 +35,6 @@ import org.apache.flink.runtime.jobmanager.scheduler.CoLocationConstraint;
import org.apache.flink.runtime.jobmanager.scheduler.Locality;
import org.apache.flink.runtime.jobmanager.scheduler.NoResourceAvailableException;
import org.apache.flink.runtime.jobmanager.scheduler.ScheduledUnit;
-import org.apache.flink.runtime.jobmanager.slots.SlotAndLocality;
import org.apache.flink.runtime.jobmanager.slots.TaskManagerGateway;
import org.apache.flink.runtime.jobmaster.JobMasterId;
import org.apache.flink.runtime.jobmaster.LogicalSlot;
@@ -764,10 +763,8 @@ public class SlotPool extends RpcEndpoint implements SlotPoolGateway, AllocatedS
final AllocatedSlot allocatedSlot = allocatedSlots.remove(slotRequestId);
if (allocatedSlot != null) {
- // sanity check
- if (allocatedSlot.releasePayload(cause)) {
- tryFulfillSlotRequestOrMakeAvailable(allocatedSlot);
- }
+ allocatedSlot.releasePayload(cause);
+ tryFulfillSlotRequestOrMakeAvailable(allocatedSlot);
} else {
log.debug("There is no allocated slot with slot request id {}. Ignoring the release slot request.", slotRequestId);
}
http://git-wip-us.apache.org/repos/asf/flink/blob/c7eb6aca/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotSharingManager.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotSharingManager.java b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotSharingManager.java
index 242d645..8fcf813 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotSharingManager.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotSharingManager.java
@@ -44,6 +44,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
/**
* Manager which is responsible for slot sharing. Slot sharing allows to run different
@@ -281,9 +282,8 @@ public class SlotSharingManager {
* Release the task slot.
*
* @param cause for the release
- * @return true if the slot could be released, otherwise false
*/
- public abstract boolean release(Throwable cause);
+ public abstract void release(Throwable cause);
}
/**
@@ -433,60 +433,51 @@ public class SlotSharingManager {
}
@Override
- public boolean release(Throwable cause) {
+ public void release(Throwable cause) {
releasingChildren = true;
// first release all children and remove them if they could be released immediately
- children.values().removeIf(node -> {
- boolean release = node.release(cause);
+ for (TaskSlot taskSlot : children.values()) {
+ taskSlot.release(cause);
+ allTaskSlots.remove(taskSlot.getSlotRequestId());
+ }
- if (release) {
- allTaskSlots.remove(node.getSlotRequestId());
- }
-
- return release;
- });
+ children.clear();
releasingChildren = false;
- if (children.isEmpty()) {
- if (parent != null) {
- // we remove ourselves from our parent if we no longer have children
- parent.releaseChild(getGroupId());
- } else if (allTaskSlots.remove(getSlotRequestId()) != null) {
- // we are the root node --> remove the root node from the list of task slots
+ if (parent != null) {
+ // we remove ourselves from our parent if we no longer have children
+ parent.releaseChild(getGroupId());
+ } else if (allTaskSlots.remove(getSlotRequestId()) != null) {
+ // we are the root node --> remove the root node from the list of task slots
- if (!slotContextFuture.isDone() || slotContextFuture.isCompletedExceptionally()) {
- synchronized (lock) {
- // the root node should still be unresolved
- unresolvedRootSlots.remove(getSlotRequestId());
- }
- } else {
- // the root node should be resolved --> we can access the slot context
- final SlotContext slotContext = slotContextFuture.getNow(null);
+ if (!slotContextFuture.isDone() || slotContextFuture.isCompletedExceptionally()) {
+ synchronized (lock) {
+ // the root node should still be unresolved
+ unresolvedRootSlots.remove(getSlotRequestId());
+ }
+ } else {
+ // the root node should be resolved --> we can access the slot context
+ final SlotContext slotContext = slotContextFuture.getNow(null);
- if (slotContext != null) {
- synchronized (lock) {
- final Set<MultiTaskSlot> multiTaskSlots = resolvedRootSlots.get(slotContext.getTaskManagerLocation());
+ if (slotContext != null) {
+ synchronized (lock) {
+ final Set<MultiTaskSlot> multiTaskSlots = resolvedRootSlots.get(slotContext.getTaskManagerLocation());
- if (multiTaskSlots != null) {
- multiTaskSlots.remove(this);
+ if (multiTaskSlots != null) {
+ multiTaskSlots.remove(this);
- if (multiTaskSlots.isEmpty()) {
- resolvedRootSlots.remove(slotContext.getTaskManagerLocation());
- }
+ if (multiTaskSlots.isEmpty()) {
+ resolvedRootSlots.remove(slotContext.getTaskManagerLocation());
}
}
}
}
-
- // release the underlying allocated slot
- allocatedSlotActions.releaseSlot(allocatedSlotRequestId, null, cause);
}
- return true;
- } else {
- return false;
+ // release the underlying allocated slot
+ allocatedSlotActions.releaseSlot(allocatedSlotRequestId, null, cause);
}
}
@@ -518,7 +509,7 @@ public class SlotSharingManager {
private final MultiTaskSlot parent;
// future containing a LogicalSlot which is completed once the underlying SlotContext future is completed
- private final CompletableFuture<LogicalSlot> logicalSlotFuture;
+ private final CompletableFuture<SingleLogicalSlot> singleLogicalSlotFuture;
private SingleTaskSlot(
SlotRequestId slotRequestId,
@@ -530,7 +521,7 @@ public class SlotSharingManager {
this.parent = Preconditions.checkNotNull(parent);
Preconditions.checkNotNull(locality);
- logicalSlotFuture = parent.getSlotContextFuture()
+ singleLogicalSlotFuture = parent.getSlotContextFuture()
.thenApply(
(SlotContext slotContext) ->
new SingleLogicalSlot(
@@ -542,29 +533,23 @@ public class SlotSharingManager {
}
CompletableFuture<LogicalSlot> getLogicalSlotFuture() {
- return logicalSlotFuture;
+ return singleLogicalSlotFuture.thenApply(Function.identity());
}
@Override
- public boolean release(Throwable cause) {
- logicalSlotFuture.completeExceptionally(cause);
+ public void release(Throwable cause) {
+ singleLogicalSlotFuture.completeExceptionally(cause);
boolean pendingLogicalSlotRelease = false;
- if (logicalSlotFuture.isDone() && !logicalSlotFuture.isCompletedExceptionally()) {
+ if (singleLogicalSlotFuture.isDone() && !singleLogicalSlotFuture.isCompletedExceptionally()) {
// we have a single task slot which we first have to release
- final LogicalSlot logicalSlot = logicalSlotFuture.getNow(null);
+ final SingleLogicalSlot singleLogicalSlot = singleLogicalSlotFuture.getNow(null);
- if ((logicalSlot != null) && (logicalSlot.isAlive())) {
- pendingLogicalSlotRelease = logicalSlot.releaseSlot(cause).isDone();
- }
- }
-
- if (!pendingLogicalSlotRelease) {
- parent.releaseChild(getGroupId());
+ singleLogicalSlot.release(cause);
}
- return !pendingLogicalSlotRelease;
+ parent.releaseChild(getGroupId());
}
}
http://git-wip-us.apache.org/repos/asf/flink/blob/c7eb6aca/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/AvailableSlotsTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/AvailableSlotsTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/AvailableSlotsTest.java
index ed090d8..4e9ca88 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/AvailableSlotsTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/AvailableSlotsTest.java
@@ -22,7 +22,6 @@ import org.apache.flink.runtime.clusterframework.types.AllocationID;
import org.apache.flink.runtime.clusterframework.types.ResourceID;
import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
import org.apache.flink.runtime.clusterframework.types.SlotProfile;
-import org.apache.flink.runtime.jobmanager.slots.SlotAndLocality;
import org.apache.flink.runtime.jobmanager.slots.TaskManagerGateway;
import org.apache.flink.runtime.taskmanager.TaskManagerLocation;
import org.apache.flink.testutils.category.New;
http://git-wip-us.apache.org/repos/asf/flink/blob/c7eb6aca/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/DummyPayload.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/DummyPayload.java b/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/DummyPayload.java
new file mode 100644
index 0000000..b88c292
--- /dev/null
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/DummyPayload.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.jobmaster.slotpool;
+
+import org.apache.flink.runtime.jobmaster.LogicalSlot;
+import org.apache.flink.util.Preconditions;
+
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * {@link LogicalSlot.Payload} implementation for test purposes.
+ */
+final class DummyPayload implements LogicalSlot.Payload {
+
+ private final CompletableFuture<?> terminalStateFuture;
+
+ DummyPayload() {
+ this(new CompletableFuture<>());
+ }
+
+ DummyPayload(CompletableFuture<?> terminalStateFuture) {
+ this.terminalStateFuture = Preconditions.checkNotNull(terminalStateFuture);
+ }
+
+ @Override
+ public void fail(Throwable cause) {
+ terminalStateFuture.complete(null);
+ }
+
+ @Override
+ public CompletableFuture<?> getTerminalStateFuture() {
+ return terminalStateFuture;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/c7eb6aca/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SingleLogicalSlotTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SingleLogicalSlotTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SingleLogicalSlotTest.java
new file mode 100644
index 0000000..c5beda4
--- /dev/null
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SingleLogicalSlotTest.java
@@ -0,0 +1,323 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.jobmaster.slotpool;
+
+import org.apache.flink.runtime.clusterframework.types.AllocationID;
+import org.apache.flink.runtime.concurrent.FutureUtils;
+import org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway;
+import org.apache.flink.runtime.jobmanager.scheduler.Locality;
+import org.apache.flink.runtime.jobmanager.slots.DummySlotOwner;
+import org.apache.flink.runtime.jobmanager.slots.TaskManagerGateway;
+import org.apache.flink.runtime.jobmaster.LogicalSlot;
+import org.apache.flink.runtime.jobmaster.SlotContext;
+import org.apache.flink.runtime.jobmaster.SlotOwner;
+import org.apache.flink.runtime.jobmaster.SlotRequestId;
+import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation;
+import org.apache.flink.runtime.taskmanager.TaskManagerLocation;
+import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.Preconditions;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.sameInstance;
+
+/**
+ * Tests for the {@link SingleLogicalSlot} class.
+ */
+public class SingleLogicalSlotTest extends TestLogger {
+
+ @Test
+ public void testPayloadAssignment() {
+ final SingleLogicalSlot singleLogicalSlot = createSingleLogicalSlot();
+ final DummyPayload dummyPayload1 = new DummyPayload();
+ final DummyPayload dummyPayload2 = new DummyPayload();
+
+ assertThat(singleLogicalSlot.tryAssignPayload(dummyPayload1), is(true));
+ assertThat(singleLogicalSlot.tryAssignPayload(dummyPayload2), is(false));
+
+ assertThat(singleLogicalSlot.getPayload(), sameInstance(dummyPayload1));
+ }
+
+ private SingleLogicalSlot createSingleLogicalSlot() {
+ return createSingleLogicalSlot(new DummySlotOwner());
+ }
+
+ private SingleLogicalSlot createSingleLogicalSlot(SlotOwner slotOwner) {
+ return new SingleLogicalSlot(
+ new SlotRequestId(),
+ new DummySlotContext(),
+ null,
+ Locality.LOCAL,
+ slotOwner);
+ }
+
+ @Test
+ public void testAlive() throws Exception {
+ final SingleLogicalSlot singleLogicalSlot = createSingleLogicalSlot();
+ final DummyPayload dummyPayload = new DummyPayload();
+
+ assertThat(singleLogicalSlot.isAlive(), is(true));
+
+ assertThat(singleLogicalSlot.tryAssignPayload(dummyPayload), is(true));
+ assertThat(singleLogicalSlot.isAlive(), is(true));
+
+ final CompletableFuture<?> releaseFuture = singleLogicalSlot.releaseSlot(new FlinkException("Test exception"));
+
+ assertThat(singleLogicalSlot.isAlive(), is(false));
+
+ releaseFuture.get();
+
+ assertThat(singleLogicalSlot.isAlive(), is(false));
+ }
+
+ @Test
+ public void testPayloadAssignmentAfterRelease() {
+ final SingleLogicalSlot singleLogicalSlot = createSingleLogicalSlot();
+ final DummyPayload dummyPayload = new DummyPayload();
+
+ singleLogicalSlot.releaseSlot(new FlinkException("Test exception"));
+
+ assertThat(singleLogicalSlot.tryAssignPayload(dummyPayload), is(false));
+ }
+
+ /**
+ * Tests that the {@link AllocatedSlot.Payload#release(Throwable)} does not wait
+ * for the payload to reach a terminal state.
+ */
+ @Test
+ public void testAllocatedSlotRelease() {
+ final CompletableFuture<LogicalSlot> returnSlotFuture = new CompletableFuture<>();
+ final WaitingSlotOwner waitingSlotOwner = new WaitingSlotOwner(returnSlotFuture, new CompletableFuture<>());
+ final SingleLogicalSlot singleLogicalSlot = createSingleLogicalSlot(waitingSlotOwner);
+
+ final CompletableFuture<?> terminalStateFuture = new CompletableFuture<>();
+ final CompletableFuture<?> failFuture = new CompletableFuture<>();
+ final ManualTestingPayload dummyPayload = new ManualTestingPayload(failFuture, terminalStateFuture);
+
+ assertThat(singleLogicalSlot.tryAssignPayload(dummyPayload), is(true));
+
+ singleLogicalSlot.release(new FlinkException("Test exception"));
+
+ assertThat(failFuture.isDone(), is(true));
+ // we don't require the logical slot to return to the owner because
+ // the release call should only come from the owner
+ assertThat(returnSlotFuture.isDone(), is(false));
+ }
+
+ /**
+ * Tests that the slot release is only signaled after the owner has
+ * taken it back.
+ */
+ @Test
+ public void testSlotRelease() {
+ final CompletableFuture<LogicalSlot> returnedSlotFuture = new CompletableFuture<>();
+ final CompletableFuture<Boolean> returnSlotResponseFuture = new CompletableFuture<>();
+ final WaitingSlotOwner waitingSlotOwner = new WaitingSlotOwner(returnedSlotFuture, returnSlotResponseFuture);
+ final CompletableFuture<?> terminalStateFuture = new CompletableFuture<>();
+ final CompletableFuture<?> failFuture = new CompletableFuture<>();
+ final ManualTestingPayload dummyPayload = new ManualTestingPayload(failFuture, terminalStateFuture);
+
+ final SingleLogicalSlot singleLogicalSlot = createSingleLogicalSlot(waitingSlotOwner);
+
+ assertThat(singleLogicalSlot.tryAssignPayload(dummyPayload), is(true));
+
+ final CompletableFuture<?> releaseFuture = singleLogicalSlot.releaseSlot(new FlinkException("Test exception"));
+
+ assertThat(releaseFuture.isDone(), is(false));
+ assertThat(returnedSlotFuture.isDone(), is(false));
+ assertThat(failFuture.isDone(), is(true));
+
+ terminalStateFuture.complete(null);
+
+ assertThat(returnedSlotFuture.isDone(), is(true));
+
+ returnSlotResponseFuture.complete(true);
+
+ assertThat(releaseFuture.isDone(), is(true));
+ }
+
+ /**
+ * Tests that concurrent release operations only trigger the failing of the payload and
+ * the return of the slot once.
+ */
+ @Test
+ public void testConcurrentReleaseOperations() throws Exception {
+ final CountingSlotOwner countingSlotOwner = new CountingSlotOwner();
+ final CountingFailPayload countingFailPayload = new CountingFailPayload();
+ final SingleLogicalSlot singleLogicalSlot = createSingleLogicalSlot(countingSlotOwner);
+
+ singleLogicalSlot.tryAssignPayload(countingFailPayload);
+
+ final ExecutorService executorService = Executors.newFixedThreadPool(4);
+
+ try {
+ final int numberConcurrentOperations = 10;
+ final Collection<CompletableFuture<?>> releaseOperationFutures = new ArrayList<>(numberConcurrentOperations);
+
+ for (int i = 0; i < numberConcurrentOperations; i++) {
+ final CompletableFuture<Void> releaseOperationFuture = CompletableFuture.runAsync(
+ () -> {
+ try {
+ singleLogicalSlot.releaseSlot(new FlinkException("Test exception")).get();
+ } catch (InterruptedException | ExecutionException e) {
+ ExceptionUtils.checkInterrupted(e);
+ throw new CompletionException(e);
+ }
+ });
+
+ releaseOperationFutures.add(releaseOperationFuture);
+ }
+
+ final FutureUtils.ConjunctFuture<Void> releaseOperationsFuture = FutureUtils.waitForAll(releaseOperationFutures);
+
+ releaseOperationsFuture.get();
+
+ assertThat(countingSlotOwner.getReleaseCount(), is(1));
+ assertThat(countingFailPayload.getFailCount(), is(1));
+ } finally {
+ executorService.shutdownNow();
+ }
+ }
+
+ private static final class CountingFailPayload implements LogicalSlot.Payload {
+
+ private final AtomicInteger failCounter = new AtomicInteger(0);
+
+ int getFailCount() {
+ return failCounter.get();
+ }
+
+ @Override
+ public void fail(Throwable cause) {
+ failCounter.incrementAndGet();
+ }
+
+ @Override
+ public CompletableFuture<?> getTerminalStateFuture() {
+ return CompletableFuture.completedFuture(null);
+ }
+ }
+
+ private static final class CountingSlotOwner implements SlotOwner {
+
+ private final AtomicInteger counter;
+
+ private CountingSlotOwner() {
+ this.counter = new AtomicInteger(0);
+ }
+
+ public int getReleaseCount() {
+ return counter.get();
+ }
+
+ @Override
+ public CompletableFuture<Boolean> returnAllocatedSlot(LogicalSlot logicalSlot) {
+ counter.incrementAndGet();
+ return CompletableFuture.completedFuture(true);
+ }
+ }
+
+ private static final class ManualTestingPayload implements LogicalSlot.Payload {
+
+ private final CompletableFuture<?> failFuture;
+
+ private final CompletableFuture<?> terminalStateFuture;
+
+ private ManualTestingPayload(CompletableFuture<?> failFuture, CompletableFuture<?> terminalStateFuture) {
+ this.failFuture = failFuture;
+ this.terminalStateFuture = terminalStateFuture;
+ }
+
+ @Override
+ public void fail(Throwable cause) {
+ failFuture.completeExceptionally(cause);
+ }
+
+ @Override
+ public CompletableFuture<?> getTerminalStateFuture() {
+ return terminalStateFuture;
+ }
+ }
+
+ private static final class WaitingSlotOwner implements SlotOwner {
+
+ private final CompletableFuture<LogicalSlot> returnAllocatedSlotFuture;
+
+ private final CompletableFuture<Boolean> returnAllocatedSlotResponse;
+
+ private WaitingSlotOwner(CompletableFuture<LogicalSlot> returnAllocatedSlotFuture, CompletableFuture<Boolean> returnAllocatedSlotResponse) {
+ this.returnAllocatedSlotFuture = Preconditions.checkNotNull(returnAllocatedSlotFuture);
+ this.returnAllocatedSlotResponse = Preconditions.checkNotNull(returnAllocatedSlotResponse);
+ }
+
+ @Override
+ public CompletableFuture<Boolean> returnAllocatedSlot(LogicalSlot logicalSlot) {
+ returnAllocatedSlotFuture.complete(logicalSlot);
+ return returnAllocatedSlotResponse;
+ }
+ }
+
+ private static final class DummySlotContext implements SlotContext {
+
+ private final AllocationID allocationId;
+
+ private final TaskManagerLocation taskManagerLocation;
+
+ private final TaskManagerGateway taskManagerGateway;
+
+ DummySlotContext() {
+ allocationId = new AllocationID();
+ taskManagerLocation = new LocalTaskManagerLocation();
+ taskManagerGateway = new SimpleAckingTaskManagerGateway();
+ }
+
+ @Override
+ public AllocationID getAllocationId() {
+ return allocationId;
+ }
+
+ @Override
+ public TaskManagerLocation getTaskManagerLocation() {
+ return taskManagerLocation;
+ }
+
+ @Override
+ public int getPhysicalSlotNumber() {
+ return 0;
+ }
+
+ @Override
+ public TaskManagerGateway getTaskManagerGateway() {
+ return taskManagerGateway;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flink/blob/c7eb6aca/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPoolTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPoolTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPoolTest.java
index eae5238..a20332b 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPoolTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPoolTest.java
@@ -25,7 +25,6 @@ import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
import org.apache.flink.runtime.clusterframework.types.SlotProfile;
import org.apache.flink.runtime.concurrent.FutureUtils;
import org.apache.flink.runtime.executiongraph.utils.SimpleAckingTaskManagerGateway;
-import org.apache.flink.runtime.instance.SlotSharingGroupId;
import org.apache.flink.runtime.jobgraph.JobVertexID;
import org.apache.flink.runtime.jobmanager.scheduler.DummyScheduledUnit;
import org.apache.flink.runtime.jobmanager.scheduler.ScheduledUnit;
@@ -58,8 +57,6 @@ import org.junit.experimental.categories.Category;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.Nullable;
-
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
@@ -346,24 +343,7 @@ public class SlotPoolTest extends TestLogger {
resourceManagerGateway.setRequestSlotConsumer(slotRequest -> slotRequestFuture.complete(slotRequest));
- final CompletableFuture<Boolean> slotReturnFuture = new CompletableFuture<>();
-
- final SlotPool slotPool = new SlotPool(rpcService, jobId) {
- @Override
- public CompletableFuture<Acknowledge> releaseSlot(
- SlotRequestId slotRequestId,
- @Nullable SlotSharingGroupId slotSharingGroupId,
- @Nullable Throwable cause) {
- super.releaseSlot(
- slotRequestId,
- slotSharingGroupId,
- cause);
-
- slotReturnFuture.complete(true);
-
- return CompletableFuture.completedFuture(Acknowledge.get());
- }
- };
+ final SlotPool slotPool = new SlotPool(rpcService, jobId);
try {
SlotPoolGateway slotPoolGateway = setupSlotPool(slotPool, resourceManagerGateway);
@@ -396,11 +376,14 @@ public class SlotPoolTest extends TestLogger {
assertTrue(future1.isDone());
assertFalse(future2.isDone());
- slotPoolGateway.releaseTaskManager(taskManagerLocation.getResourceID());
+ final CompletableFuture<?> releaseFuture = new CompletableFuture<>();
+ final DummyPayload dummyPayload = new DummyPayload(releaseFuture);
- // wait until the slot has been returned
- slotReturnFuture.get();
+ slot1.tryAssignPayload(dummyPayload);
+
+ slotPoolGateway.releaseTaskManager(taskManagerLocation.getResourceID());
+ releaseFuture.get();
assertFalse(slot1.isAlive());
// slot released and not usable, second allocation still not fulfilled
http://git-wip-us.apache.org/repos/asf/flink/blob/c7eb6aca/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SlotSharingManagerTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SlotSharingManagerTest.java b/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SlotSharingManagerTest.java
index 4c56c63..9297f59 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SlotSharingManagerTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/SlotSharingManagerTest.java
@@ -105,7 +105,7 @@ public class SlotSharingManagerTest extends TestLogger {
assertTrue(slotSharingManager.contains(slotRequestId));
- assertTrue(rootSlot.release(new FlinkException("Test exception")));
+ rootSlot.release(new FlinkException("Test exception"));
// check that we return the allocated slot
assertEquals(allocatedSlotRequestId, slotReleasedFuture.get());
@@ -194,7 +194,7 @@ public class SlotSharingManagerTest extends TestLogger {
assertFalse(singleTaskSlotFuture.isDone());
FlinkException testException = new FlinkException("Test exception");
- assertTrue(singleTaskSlot.release(testException));
+ singleTaskSlot.release(testException);
// check that we fail the single task slot future
assertTrue(singleTaskSlotFuture.isCompletedExceptionally());
@@ -203,7 +203,7 @@ public class SlotSharingManagerTest extends TestLogger {
// the root slot has still one child
assertTrue(slotSharingManager.contains(rootSlotRequestId));
- assertTrue(multiTaskSlot.release(testException));
+ multiTaskSlot.release(testException);
assertEquals(allocatedSlotRequestId, releasedSlotFuture.get());
assertFalse(slotSharingManager.contains(rootSlotRequestId));
[8/9] flink git commit: [FLINK-9330] [runtime] Add periodic logging
of SlotPool status
Posted by tr...@apache.org.
[FLINK-9330] [runtime] Add periodic logging of SlotPool status
Only happens if log level for the SlotPool is set to DEBUG
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/6b892a63
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/6b892a63
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/6b892a63
Branch: refs/heads/master
Commit: 6b892a6394a3e8e99dbc9b24276edafa2c8285e1
Parents: 1a91bce
Author: Stephan Ewen <se...@apache.org>
Authored: Sat May 5 18:18:36 2018 +0200
Committer: Till Rohrmann <tr...@apache.org>
Committed: Thu May 10 16:18:31 2018 +0200
----------------------------------------------------------------------
.../flink/runtime/jobmaster/slotpool/SlotPool.java | 12 ++++++++++++
1 file changed, 12 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/6b892a63/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java
index 6ea74d1..ebb9aae 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/jobmaster/slotpool/SlotPool.java
@@ -92,6 +92,9 @@ import static org.apache.flink.util.Preconditions.checkNotNull;
*/
public class SlotPool extends RpcEndpoint implements SlotPoolGateway, AllocatedSlotActions {
+ /** The interval (in milliseconds) in which the SlotPool writes its slot distribution on debug level. */
+ private static final int STATUS_LOG_INTERVAL_MS = 60_000;
+
private final JobID jobId;
private final ProviderAndOwner providerAndOwner;
@@ -198,6 +201,10 @@ public class SlotPool extends RpcEndpoint implements SlotPoolGateway, AllocatedS
}
scheduleRunAsync(this::checkIdleSlot, idleSlotTimeout);
+
+ if (log.isDebugEnabled()) {
+ scheduleRunAsync(this::scheduledLogStatus, STATUS_LOG_INTERVAL_MS, TimeUnit.MILLISECONDS);
+ }
}
@Override
@@ -1138,6 +1145,11 @@ public class SlotPool extends RpcEndpoint implements SlotPoolGateway, AllocatedS
// Methods for tests
// ------------------------------------------------------------------------
+ private void scheduledLogStatus() {
+ log.debug(printStatus());
+ scheduleRunAsync(this::scheduledLogStatus, STATUS_LOG_INTERVAL_MS, TimeUnit.MILLISECONDS);
+ }
+
private String printStatus() {
validateRunsInMainThread();
[3/9] flink git commit: [hotfix] [tests] Harden
YarnSessionFIFOITCase#testDetachedMode
Posted by tr...@apache.org.
[hotfix] [tests] Harden YarnSessionFIFOITCase#testDetachedMode
Wait for the completion of the submitted job in order to avoid that we kill
the JM while the TM tries to down load blobs from it.
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/3c86b6b5
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/3c86b6b5
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/3c86b6b5
Branch: refs/heads/master
Commit: 3c86b6b575c64409a1153c56618d6929bd2d49de
Parents: 90a0a91
Author: Till Rohrmann <tr...@apache.org>
Authored: Thu May 10 00:45:12 2018 +0200
Committer: Till Rohrmann <tr...@apache.org>
Committed: Thu May 10 16:18:31 2018 +0200
----------------------------------------------------------------------
.../java/org/apache/flink/yarn/YARNSessionFIFOITCase.java | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/3c86b6b5/flink-yarn-tests/src/test/java/org/apache/flink/yarn/YARNSessionFIFOITCase.java
----------------------------------------------------------------------
diff --git a/flink-yarn-tests/src/test/java/org/apache/flink/yarn/YARNSessionFIFOITCase.java b/flink-yarn-tests/src/test/java/org/apache/flink/yarn/YARNSessionFIFOITCase.java
index bdaf2c6..eee6867 100644
--- a/flink-yarn-tests/src/test/java/org/apache/flink/yarn/YARNSessionFIFOITCase.java
+++ b/flink-yarn-tests/src/test/java/org/apache/flink/yarn/YARNSessionFIFOITCase.java
@@ -177,12 +177,8 @@ public class YARNSessionFIFOITCase extends YarnTestBase {
long startTime = System.nanoTime();
while (System.nanoTime() - startTime < TimeUnit.NANOSECONDS.convert(10, TimeUnit.SECONDS) &&
!(verifyStringsInNamedLogFiles(
- new String[]{isNewMode ? "JobManager successfully registered at ResourceManager"
- : "YARN Application Master started"}, "jobmanager.log") &&
- verifyStringsInNamedLogFiles(
- new String[]{isNewMode ? "Successful registration at job manager"
- : "Starting TaskManager actor"}, "taskmanager.log"))) {
- LOG.info("Still waiting for JM/TM to initialize...");
+ new String[]{"switched from state RUNNING to FINISHED"}, "jobmanager.log"))) {
+ LOG.info("Still waiting for cluster to finish job...");
sleep(500);
}
[4/9] flink git commit: [FLINK-9190][flip6,
yarn] Request new container if container completed unexpectedly.
Posted by tr...@apache.org.
[FLINK-9190][flip6,yarn] Request new container if container completed unexpectedly.
This closes #5931.
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/fa11015d
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/fa11015d
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/fa11015d
Branch: refs/heads/master
Commit: fa11015ddcdb0217da6a8b2be1e2a55efd26d7fa
Parents: b7f5c0d
Author: gyao <ga...@data-artisans.com>
Authored: Fri Apr 27 15:49:31 2018 +0200
Committer: Till Rohrmann <tr...@apache.org>
Committed: Thu May 10 16:18:31 2018 +0200
----------------------------------------------------------------------
.../apache/flink/yarn/YarnResourceManager.java | 44 ++++++++++----------
1 file changed, 23 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/fa11015d/flink-yarn/src/main/java/org/apache/flink/yarn/YarnResourceManager.java
----------------------------------------------------------------------
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 22d0164..266c037 100644
--- a/flink-yarn/src/main/java/org/apache/flink/yarn/YarnResourceManager.java
+++ b/flink-yarn/src/main/java/org/apache/flink/yarn/YarnResourceManager.java
@@ -295,21 +295,16 @@ public class YarnResourceManager extends ResourceManager<YarnWorkerNode> impleme
}
@Override
- public boolean stopWorker(YarnWorkerNode workerNode) {
- if (workerNode != null) {
- Container container = workerNode.getContainer();
- log.info("Stopping container {}.", container.getId());
- // release the container on the node manager
- try {
- nodeManagerClient.stopContainer(container.getId(), container.getNodeId());
- } catch (Throwable t) {
- log.warn("Error while calling YARN Node Manager to stop container", t);
- }
- resourceManagerClient.releaseAssignedContainer(container.getId());
- workerNodeMap.remove(workerNode.getResourceID());
- } else {
- log.error("Can not find container for null workerNode.");
+ public boolean stopWorker(final YarnWorkerNode workerNode) {
+ final Container container = workerNode.getContainer();
+ log.info("Stopping container {}.", container.getId());
+ try {
+ nodeManagerClient.stopContainer(container.getId(), container.getNodeId());
+ } catch (final Exception e) {
+ log.warn("Error while calling YARN Node Manager to stop container", e);
}
+ resourceManagerClient.releaseAssignedContainer(container.getId());
+ workerNodeMap.remove(workerNode.getResourceID());
return true;
}
@@ -329,14 +324,19 @@ public class YarnResourceManager extends ResourceManager<YarnWorkerNode> impleme
}
@Override
- public void onContainersCompleted(List<ContainerStatus> list) {
+ public void onContainersCompleted(final List<ContainerStatus> list) {
runAsync(() -> {
- for (ContainerStatus container : list) {
- if (container.getExitStatus() < 0) {
- closeTaskManagerConnection(new ResourceID(
- container.getContainerId().toString()), new Exception(container.getDiagnostics()));
+ for (final ContainerStatus containerStatus : list) {
+
+ final ResourceID resourceId = new ResourceID(containerStatus.getContainerId().toString());
+ final YarnWorkerNode yarnWorkerNode = workerNodeMap.remove(resourceId);
+
+ if (yarnWorkerNode != null) {
+ // Container completed unexpectedly ~> start a new one
+ final Container container = yarnWorkerNode.getContainer();
+ requestYarnContainer(container.getResource(), yarnWorkerNode.getContainer().getPriority());
+ closeTaskManagerConnection(resourceId, new Exception(containerStatus.getDiagnostics()));
}
- workerNodeMap.remove(new ResourceID(container.getContainerId().toString()));
}
}
);
@@ -355,8 +355,9 @@ public class YarnResourceManager extends ResourceManager<YarnWorkerNode> impleme
numPendingContainerRequests--;
final String containerIdStr = container.getId().toString();
+ final ResourceID resourceId = new ResourceID(containerIdStr);
- workerNodeMap.put(new ResourceID(containerIdStr), new YarnWorkerNode(container));
+ workerNodeMap.put(resourceId, new YarnWorkerNode(container));
try {
// Context information used to start a TaskExecutor Java process
@@ -370,6 +371,7 @@ public class YarnResourceManager extends ResourceManager<YarnWorkerNode> impleme
log.error("Could not start TaskManager in container {}.", container.getId(), t);
// release the failed container
+ workerNodeMap.remove(resourceId);
resourceManagerClient.releaseAssignedContainer(container.getId());
// and ask for a new one
requestYarnContainer(container.getResource(), container.getPriority());