You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by se...@apache.org on 2018/05/03 21:58:48 UTC
[1/2] flink git commit: [hotfix] [runtime] Minor code cleanup in
SlotPool
Repository: flink
Updated Branches:
refs/heads/master b13c70b60 -> e8315c504
[hotfix] [runtime] Minor code cleanup in SlotPool
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/e8315c50
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/e8315c50
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/e8315c50
Branch: refs/heads/master
Commit: e8315c504021d97859b08aaea5f47ec8fdb7b523
Parents: bbaf82e
Author: Stephan Ewen <se...@apache.org>
Authored: Thu May 3 22:25:17 2018 +0200
Committer: Stephan Ewen <se...@apache.org>
Committed: Thu May 3 23:58:05 2018 +0200
----------------------------------------------------------------------
.../jobmaster/slotpool/AllocatedSlot.java | 8 +++
.../runtime/jobmaster/slotpool/SlotPool.java | 58 +++++++++-----------
2 files changed, 35 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/e8315c50/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 a560ebc..d3b2ab2 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
@@ -21,6 +21,7 @@ package org.apache.flink.runtime.jobmaster.slotpool;
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.SlotID;
import org.apache.flink.runtime.jobmanager.slots.TaskManagerGateway;
import org.apache.flink.runtime.jobmaster.SlotContext;
import org.apache.flink.runtime.taskmanager.TaskManagerLocation;
@@ -80,6 +81,13 @@ public class AllocatedSlot implements SlotContext {
// ------------------------------------------------------------------------
/**
+ * Gets the Slot's unique ID defined by its TaskManager.
+ */
+ public SlotID getSlotId() {
+ return new SlotID(getTaskManagerId(), physicalSlotNumber);
+ }
+
+ /**
* Gets the ID under which the slot is allocated, which uniquely identifies the slot.
*
* @return The ID under which the slot is allocated
http://git-wip-us.apache.org/repos/asf/flink/blob/e8315c50/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 4ee7c6d..2b78656 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
@@ -26,6 +26,7 @@ import org.apache.flink.runtime.akka.AkkaUtils;
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.SlotID;
import org.apache.flink.runtime.clusterframework.types.SlotProfile;
import org.apache.flink.runtime.concurrent.FutureUtils;
import org.apache.flink.runtime.executiongraph.ExecutionGraph;
@@ -875,17 +876,12 @@ public class SlotPool extends RpcEndpoint implements SlotPoolGateway, AllocatedS
List<CompletableFuture<Optional<SlotOffer>>> acceptedSlotOffers = offers.stream().map(
offer -> {
CompletableFuture<Optional<SlotOffer>> acceptedSlotOffer = offerSlot(
- taskManagerLocation,
- taskManagerGateway,
- offer)
+ taskManagerLocation,
+ taskManagerGateway,
+ offer)
.thenApply(
- (acceptedSlot) -> {
- if (acceptedSlot) {
- return Optional.of(offer);
- } else {
- return Optional.empty();
- }
- });
+ (acceptedSlot) -> acceptedSlot ? Optional.of(offer) : Optional.empty()
+ );
return acceptedSlotOffer;
}
@@ -893,18 +889,9 @@ public class SlotPool extends RpcEndpoint implements SlotPoolGateway, AllocatedS
CompletableFuture<Collection<Optional<SlotOffer>>> optionalSlotOffers = FutureUtils.combineAll(acceptedSlotOffers);
- CompletableFuture<Collection<SlotOffer>> resultingSlotOffers = optionalSlotOffers.thenApply(
- collection -> {
- Collection<SlotOffer> slotOffers = collection
- .stream()
- .flatMap(
- opt -> opt.map(Stream::of).orElseGet(Stream::empty))
- .collect(Collectors.toList());
-
- return slotOffers;
- });
-
- return resultingSlotOffers;
+ return optionalSlotOffers.thenApply(collection -> collection.stream()
+ .flatMap(opt -> opt.map(Stream::of).orElseGet(Stream::empty))
+ .collect(Collectors.toList()));
}
/**
@@ -923,6 +910,7 @@ public class SlotPool extends RpcEndpoint implements SlotPoolGateway, AllocatedS
final TaskManagerLocation taskManagerLocation,
final TaskManagerGateway taskManagerGateway,
final SlotOffer slotOffer) {
+
validateRunsInMainThread();
// check if this TaskManager is valid
@@ -936,21 +924,29 @@ public class SlotPool extends RpcEndpoint implements SlotPoolGateway, AllocatedS
}
// check whether we have already using this slot
- AllocatedSlot preSlot = allocatedSlots.get(allocationID);
- if (preSlot == null) {
- preSlot = availableSlots.get(allocationID);
- }
- if (preSlot != null) {
- if (preSlot.getTaskManagerId().equals(taskManagerLocation.getResourceID())
- && preSlot.getPhysicalSlotNumber() == slotOffer.getSlotIndex()) {
+ AllocatedSlot existingSlot;
+ if ((existingSlot = allocatedSlots.get(allocationID)) != null ||
+ (existingSlot = availableSlots.get(allocationID)) != null) {
+
+ // we need to figure out if this is a repeated offer for the exact same slot,
+ // or another offer that comes from a different TaskManager after the ResourceManager
+ // re-tried the request
+
+ // we write this in terms of comparing slot IDs, because the Slot IDs are the identifiers of
+ // the actual slots on the TaskManagers
+ // Note: The slotOffer should have the SlotID
+ final SlotID existingSlotId = existingSlot.getSlotId();
+ final SlotID newSlotId = new SlotID(taskManagerLocation.getResourceID(), slotOffer.getSlotIndex());
+
+ if (existingSlotId.equals(newSlotId)) {
log.info("Received repeated offer for slot [{}]. Ignoring.", allocationID);
// return true here so that the sender will get a positive acknowledgement to the retry
// and mark the offering as a success
return CompletableFuture.completedFuture(true);
} else {
- // the allocation has been fulfilled by another slot, reject the offer so task executor
- // will offer the slot to resource manager
+ // the allocation has been fulfilled by another slot, reject the offer so the task executor
+ // will offer the slot to the resource manager
return CompletableFuture.completedFuture(false);
}
}
[2/2] flink git commit: [FLINK-9293] [runtime] SlotPool should check
slot id when accepting a slot offer with existing allocation id
Posted by se...@apache.org.
[FLINK-9293] [runtime] SlotPool should check slot id when accepting a slot offer with existing allocation id
This closes #5951
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/bbaf82eb
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/bbaf82eb
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/bbaf82eb
Branch: refs/heads/master
Commit: bbaf82ebe245d4758e73aa928d79a3708c816311
Parents: b13c70b
Author: shuai.xus <sh...@alibaba-inc.com>
Authored: Thu May 3 17:13:08 2018 +0800
Committer: Stephan Ewen <se...@apache.org>
Committed: Thu May 3 23:58:05 2018 +0200
----------------------------------------------------------------------
.../runtime/jobmaster/slotpool/SlotPool.java | 32 ++++++++++++++++----
.../jobmaster/slotpool/SlotPoolTest.java | 11 +++++++
2 files changed, 37 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/bbaf82eb/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 a4db46c..4ee7c6d 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
@@ -936,12 +936,23 @@ public class SlotPool extends RpcEndpoint implements SlotPoolGateway, AllocatedS
}
// check whether we have already using this slot
- if (allocatedSlots.contains(allocationID) || availableSlots.contains(allocationID)) {
- log.debug("Received repeated offer for slot [{}]. Ignoring.", allocationID);
-
- // return true here so that the sender will get a positive acknowledgement to the retry
- // and mark the offering as a success
- return CompletableFuture.completedFuture(true);
+ AllocatedSlot preSlot = allocatedSlots.get(allocationID);
+ if (preSlot == null) {
+ preSlot = availableSlots.get(allocationID);
+ }
+ if (preSlot != null) {
+ if (preSlot.getTaskManagerId().equals(taskManagerLocation.getResourceID())
+ && preSlot.getPhysicalSlotNumber() == slotOffer.getSlotIndex()) {
+ log.info("Received repeated offer for slot [{}]. Ignoring.", allocationID);
+
+ // return true here so that the sender will get a positive acknowledgement to the retry
+ // and mark the offering as a success
+ return CompletableFuture.completedFuture(true);
+ } else {
+ // the allocation has been fulfilled by another slot, reject the offer so task executor
+ // will offer the slot to resource manager
+ return CompletableFuture.completedFuture(false);
+ }
}
final AllocatedSlot allocatedSlot = new AllocatedSlot(
@@ -1384,6 +1395,15 @@ public class SlotPool extends RpcEndpoint implements SlotPoolGateway, AllocatedS
return availableSlots.containsKey(slotId);
}
+ AllocatedSlot get(AllocationID allocationID) {
+ SlotAndTimestamp slotAndTimestamp = availableSlots.get(allocationID);
+ if (slotAndTimestamp != null) {
+ return slotAndTimestamp.slot();
+ } else {
+ return null;
+ }
+ }
+
/**
* Poll a slot which matches the required resource profile. The polling tries to satisfy the
* location preferences, by TaskManager and by host.
http://git-wip-us.apache.org/repos/asf/flink/blob/bbaf82eb/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 f025bc8..eae5238 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
@@ -321,9 +321,20 @@ public class SlotPoolTest extends TestLogger {
assertTrue(slotPoolGateway.offerSlot(taskManagerLocation, taskManagerGateway, slotOffer).get());
assertTrue(slot.isAlive());
+ final SlotOffer anotherSlotOfferWithSameAllocationId = new SlotOffer(
+ slotRequest.getAllocationId(),
+ 1,
+ DEFAULT_TESTING_PROFILE);
+ assertFalse(slotPoolGateway.offerSlot(taskManagerLocation, taskManagerGateway, anotherSlotOfferWithSameAllocationId).get());
+
+ TaskManagerLocation anotherTaskManagerLocation = new LocalTaskManagerLocation();
+ assertFalse(slotPoolGateway.offerSlot(anotherTaskManagerLocation, taskManagerGateway, slotOffer).get());
+
// duplicated offer with free slot
slot.releaseSlot();
assertTrue(slotPoolGateway.offerSlot(taskManagerLocation, taskManagerGateway, slotOffer).get());
+ assertFalse(slotPoolGateway.offerSlot(taskManagerLocation, taskManagerGateway, anotherSlotOfferWithSameAllocationId).get());
+ assertFalse(slotPoolGateway.offerSlot(anotherTaskManagerLocation, taskManagerGateway, slotOffer).get());
} finally {
slotPool.shutDown();
}