org.apache.flink.runtime.jobmaster.SlotContext Java Examples

The following examples show how to use org.apache.flink.runtime.jobmaster.SlotContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleSlotProvider.java    From Flink-CEPplus with Apache License 2.0 7 votes vote down vote up
@Override
public CompletableFuture<LogicalSlot> allocateSlot(
		SlotRequestId slotRequestId,
		ScheduledUnit task,
		SlotProfile slotProfile,
		boolean allowQueued,
		Time allocationTimeout) {
	final SlotContext slot;

	synchronized (lock) {
		if (slots.isEmpty()) {
			slot = null;
		} else {
			slot = slots.removeFirst();
		}
		if (slot != null) {
			SimpleSlot result = new SimpleSlot(slot, this, 0);
			allocatedSlots.put(slotRequestId, slot);
			return CompletableFuture.completedFuture(result);
		}
		else {
			return FutureUtils.completedExceptionally(new NoResourceAvailableException());
		}
	}
}
 
Example #2
Source File: SingleLogicalSlot.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public SingleLogicalSlot(
		SlotRequestId slotRequestId,
		SlotContext slotContext,
		@Nullable SlotSharingGroupId slotSharingGroupId,
		Locality locality,
		SlotOwner slotOwner) {
	this.slotRequestId = Preconditions.checkNotNull(slotRequestId);
	this.slotContext = Preconditions.checkNotNull(slotContext);
	this.slotSharingGroupId = slotSharingGroupId;
	this.locality = Preconditions.checkNotNull(locality);
	this.slotOwner = Preconditions.checkNotNull(slotOwner);
	this.releaseFuture = new CompletableFuture<>();

	this.state = State.ALIVE;
	this.payload = null;
}
 
Example #3
Source File: SingleLogicalSlot.java    From flink with Apache License 2.0 6 votes vote down vote up
public SingleLogicalSlot(
		SlotRequestId slotRequestId,
		SlotContext slotContext,
		@Nullable SlotSharingGroupId slotSharingGroupId,
		Locality locality,
		SlotOwner slotOwner,
		boolean willBeOccupiedIndefinitely) {
	this.slotRequestId = Preconditions.checkNotNull(slotRequestId);
	this.slotContext = Preconditions.checkNotNull(slotContext);
	this.slotSharingGroupId = slotSharingGroupId;
	this.locality = Preconditions.checkNotNull(locality);
	this.slotOwner = Preconditions.checkNotNull(slotOwner);
	this.willBeOccupiedIndefinitely = willBeOccupiedIndefinitely;
	this.releaseFuture = new CompletableFuture<>();

	this.state = State.ALIVE;
	this.payload = null;
}
 
Example #4
Source File: SingleLogicalSlot.java    From flink with Apache License 2.0 6 votes vote down vote up
public SingleLogicalSlot(
		SlotRequestId slotRequestId,
		SlotContext slotContext,
		@Nullable SlotSharingGroupId slotSharingGroupId,
		Locality locality,
		SlotOwner slotOwner) {
	this.slotRequestId = Preconditions.checkNotNull(slotRequestId);
	this.slotContext = Preconditions.checkNotNull(slotContext);
	this.slotSharingGroupId = slotSharingGroupId;
	this.locality = Preconditions.checkNotNull(locality);
	this.slotOwner = Preconditions.checkNotNull(slotOwner);
	this.releaseFuture = new CompletableFuture<>();

	this.state = State.ALIVE;
	this.payload = null;
}
 
Example #5
Source File: ExecutionVertexLocalityTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private void initializeLocation(ExecutionVertex vertex, TaskManagerLocation location) throws Exception {
	// we need a bit of reflection magic to initialize the location without going through
	// scheduling paths. we choose to do that, rather than the alternatives:
	//  - mocking the scheduler created fragile tests that break whenever the scheduler is adjusted
	//  - exposing test methods in the ExecutionVertex leads to undesirable setters 

	SlotContext slot = new SimpleSlotContext(
		new AllocationID(),
		location,
		0,
		mock(TaskManagerGateway.class));

	SimpleSlot simpleSlot = new SimpleSlot(slot, mock(SlotOwner.class), 0);

	if (!vertex.getCurrentExecutionAttempt().tryAssignResource(simpleSlot)) {
		throw new FlinkException("Could not assign resource.");
	}
}
 
Example #6
Source File: SlotSharingManager.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the task slot may have enough resource to fulfill the specific
 * request. If the underlying slot is not allocated, the check is skipped.
 *
 * @param resourceProfile The specific request to check.
 * @return Whether the slot is possible to fulfill the request in the future.
 */
boolean mayHaveEnoughResourcesToFulfill(ResourceProfile resourceProfile) {
	if (!slotContextFuture.isDone()) {
		return true;
	}

	MultiTaskSlot root = this;

	while (root.parent != null) {
		root = root.parent;
	}

	SlotContext slotContext = root.getSlotContextFuture().join();

	return slotContext.getResourceProfile().isMatching(
			resourceProfile.merge(root.getReservedResources()));
}
 
Example #7
Source File: SlotSharingManager.java    From flink with Apache License 2.0 6 votes vote down vote up
private SingleTaskSlot(
		SlotRequestId slotRequestId,
		ResourceProfile resourceProfile,
		AbstractID groupId,
		MultiTaskSlot parent,
		Locality locality) {
	super(slotRequestId, groupId);

	this.resourceProfile = Preconditions.checkNotNull(resourceProfile);
	this.parent = Preconditions.checkNotNull(parent);

	Preconditions.checkNotNull(locality);
	singleLogicalSlotFuture = parent.getSlotContextFuture()
		.thenApply(
			(SlotContext slotContext) -> {
				LOG.trace("Fulfill single task slot [{}] with slot [{}].", slotRequestId, slotContext.getAllocationId());
				return new SingleLogicalSlot(
					slotRequestId,
					slotContext,
					slotSharingGroupId,
					locality,
					slotOwner);
			});
}
 
Example #8
Source File: SlotSharingManager.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new root slot with the given {@link SlotRequestId}, {@link SlotContext} future and
 * the {@link SlotRequestId} of the allocated slot.
 *
 * @param slotRequestId of the root slot
 * @param slotContextFuture with which we create the root slot
 * @param allocatedSlotRequestId slot request id of the underlying allocated slot which can be used
 *                               to cancel the pending slot request or release the allocated slot
 * @return New root slot
 */
@Nonnull
MultiTaskSlot createRootSlot(
		SlotRequestId slotRequestId,
		CompletableFuture<? extends SlotContext> slotContextFuture,
		SlotRequestId allocatedSlotRequestId) {
	LOG.debug("Create multi task slot [{}] in slot [{}].", slotRequestId, allocatedSlotRequestId);

	final CompletableFuture<SlotContext> slotContextFutureAfterRootSlotResolution = new CompletableFuture<>();
	final MultiTaskSlot rootMultiTaskSlot = createAndRegisterRootSlot(
		slotRequestId,
		allocatedSlotRequestId,
		slotContextFutureAfterRootSlotResolution);

	FutureUtils.forward(
		slotContextFuture.thenApply(
			(SlotContext slotContext) -> {
				// add the root node to the set of resolved root nodes once the SlotContext future has
				// been completed and we know the slot's TaskManagerLocation
				tryMarkSlotAsResolved(slotRequestId, slotContext);
				return slotContext;
			}),
		slotContextFutureAfterRootSlotResolution);

	return rootMultiTaskSlot;
}
 
Example #9
Source File: ExecutionVertexLocalityTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private void initializeLocation(ExecutionVertex vertex, TaskManagerLocation location) throws Exception {
	// we need a bit of reflection magic to initialize the location without going through
	// scheduling paths. we choose to do that, rather than the alternatives:
	//  - mocking the scheduler created fragile tests that break whenever the scheduler is adjusted
	//  - exposing test methods in the ExecutionVertex leads to undesirable setters 

	SlotContext slotContext = new SimpleSlotContext(
		new AllocationID(),
		location,
		0,
		mock(TaskManagerGateway.class));



	LogicalSlot slot = new SingleLogicalSlot(
		new SlotRequestId(),
		slotContext,
		null,
		Locality.LOCAL,
		mock(SlotOwner.class));

	if (!vertex.getCurrentExecutionAttempt().tryAssignResource(slot)) {
		throw new FlinkException("Could not assign resource.");
	}
}
 
Example #10
Source File: SlotSharingManagerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the root slot are moved from unresolved to resolved once the
 * slot context future is successfully completed.
 */
@Test
public void testRootSlotTransition() {
	SlotSharingManager slotSharingManager = createTestingSlotSharingManager();

	CompletableFuture<SlotContext> slotContextFuture = new CompletableFuture<>();
	SlotSharingManager.MultiTaskSlot rootSlot = slotSharingManager.createRootSlot(
		new SlotRequestId(),
		slotContextFuture,
		new SlotRequestId());

	assertTrue(slotSharingManager.getUnresolvedRootSlots().contains(rootSlot));
	assertFalse(slotSharingManager.getResolvedRootSlots().contains(rootSlot));

	// now complete the slotContextFuture
	slotContextFuture.complete(createSimpleSlotContext());

	assertFalse(slotSharingManager.getUnresolvedRootSlots().contains(rootSlot));
	assertTrue(slotSharingManager.getResolvedRootSlots().contains(rootSlot));
}
 
Example #11
Source File: SlotSharingManager.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the task slot may have enough resource to fulfill the specific
 * request. If the underlying slot is not allocated, the check is skipped.
 *
 * @param resourceProfile The specific request to check.
 * @return Whether the slot is possible to fulfill the request in the future.
 */
boolean mayHaveEnoughResourcesToFulfill(ResourceProfile resourceProfile) {
	if (!slotContextFuture.isDone()) {
		return true;
	}

	MultiTaskSlot root = this;

	while (root.parent != null) {
		root = root.parent;
	}

	SlotContext slotContext = root.getSlotContextFuture().join();

	return slotContext.getResourceProfile().isMatching(
			resourceProfile.merge(root.getReservedResources()));
}
 
Example #12
Source File: SlotSharingManager.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private SingleTaskSlot(
		SlotRequestId slotRequestId,
		AbstractID groupId,
		MultiTaskSlot parent,
		Locality locality) {
	super(slotRequestId, groupId);

	this.parent = Preconditions.checkNotNull(parent);

	Preconditions.checkNotNull(locality);
	singleLogicalSlotFuture = parent.getSlotContextFuture()
		.thenApply(
			(SlotContext slotContext) -> {
				LOG.trace("Fulfill single task slot [{}] with slot [{}].", slotRequestId, slotContext.getAllocationId());
				return new SingleLogicalSlot(
					slotRequestId,
					slotContext,
					slotSharingGroupId,
					locality,
					slotOwner);
			});
}
 
Example #13
Source File: ExecutionVertexLocalityTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private void initializeLocation(ExecutionVertex vertex, TaskManagerLocation location) throws Exception {
	// we need a bit of reflection magic to initialize the location without going through
	// scheduling paths. we choose to do that, rather than the alternatives:
	//  - mocking the scheduler created fragile tests that break whenever the scheduler is adjusted
	//  - exposing test methods in the ExecutionVertex leads to undesirable setters 

	SlotContext slotContext = new SimpleSlotContext(
		new AllocationID(),
		location,
		0,
		mock(TaskManagerGateway.class));



	LogicalSlot slot = new SingleLogicalSlot(
		new SlotRequestId(),
		slotContext,
		null,
		Locality.LOCAL,
		mock(SlotOwner.class));

	if (!vertex.getCurrentExecutionAttempt().tryAssignResource(slot)) {
		throw new FlinkException("Could not assign resource.");
	}
}
 
Example #14
Source File: SlotSharingManager.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private MultiTaskSlot(
		SlotRequestId slotRequestId,
		@Nullable AbstractID groupId,
		@Nullable MultiTaskSlot parent,
		CompletableFuture<? extends SlotContext> slotContextFuture,
		@Nullable SlotRequestId allocatedSlotRequestId) {
	super(slotRequestId, groupId);

	this.parent = parent;
	this.slotContextFuture = Preconditions.checkNotNull(slotContextFuture);
	this.allocatedSlotRequestId = allocatedSlotRequestId;

	this.children = new HashMap<>(16);
	this.releasingChildren = false;

	slotContextFuture.whenComplete(
		(SlotContext ignored, Throwable throwable) -> {
			if (throwable != null) {
				release(throwable);
			}
		});
}
 
Example #15
Source File: SlotSharingManager.java    From flink with Apache License 2.0 6 votes vote down vote up
private SingleTaskSlot(
		SlotRequestId slotRequestId,
		ResourceProfile resourceProfile,
		AbstractID groupId,
		MultiTaskSlot parent,
		Locality locality) {
	super(slotRequestId, groupId);

	this.resourceProfile = Preconditions.checkNotNull(resourceProfile);
	this.parent = Preconditions.checkNotNull(parent);

	Preconditions.checkNotNull(locality);
	singleLogicalSlotFuture = parent.getSlotContextFuture()
		.thenApply(
			(SlotContext slotContext) -> {
				LOG.trace("Fulfill single task slot [{}] with slot [{}].", slotRequestId, slotContext.getAllocationId());
				return new SingleLogicalSlot(
					slotRequestId,
					slotContext,
					slotSharingGroupId,
					locality,
					slotOwner);
			});
}
 
Example #16
Source File: SlotSharingManagerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldResolveRootSlotBeforeCompletingChildSlots() {
	final SlotSharingManager slotSharingManager = createTestingSlotSharingManager();

	final CompletableFuture<SlotContext> slotFuture = new CompletableFuture<>();
	// important to add additional completion stage in order to reverse the execution order of callbacks
	final CompletableFuture<SlotContext> identityFuture = slotFuture.thenApply(Function.identity());

	final SlotSharingManager.MultiTaskSlot rootSlot = slotSharingManager.createRootSlot(
		new SlotRequestId(),
		identityFuture,
		new SlotRequestId());

	final SlotSharingManager.SingleTaskSlot singleTaskSlot = rootSlot.allocateSingleTaskSlot(
		new SlotRequestId(),
		ResourceProfile.UNKNOWN,
		new AbstractID(),
		Locality.UNCONSTRAINED);

	final CompletableFuture<Void> assertionFuture = singleTaskSlot.getLogicalSlotFuture().thenRun(() -> assertThat(
		slotSharingManager.getResolvedRootSlots(),
		contains(rootSlot)));

	slotFuture.complete(createSimpleSlotContext());

	assertionFuture.join();
}
 
Example #17
Source File: SlotSharingManager.java    From flink with Apache License 2.0 5 votes vote down vote up
private MultiTaskSlot(
		SlotRequestId slotRequestId,
		@Nullable AbstractID groupId,
		@Nullable MultiTaskSlot parent,
		CompletableFuture<? extends SlotContext> slotContextFuture,
		@Nullable SlotRequestId allocatedSlotRequestId) {
	super(slotRequestId, groupId);
	Preconditions.checkNotNull(slotContextFuture);

	this.parent = parent;
	this.allocatedSlotRequestId = allocatedSlotRequestId;

	this.children = new HashMap<>(16);
	this.releasingChildren = false;

	this.reservedResources = ResourceProfile.ZERO;

	this.slotContextFuture = slotContextFuture.handle((SlotContext slotContext, Throwable throwable) -> {
		if (throwable != null) {
			// If the underlying resource request failed, we currently fail all the requests
			release(throwable);
			throw new CompletionException(throwable);
		}

		if (parent == null) {
			// sanity check
			releaseSlotIfOversubscribing(slotContext);
		}

		return slotContext;
	});
}
 
Example #18
Source File: SimpleSlotProvider.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<LogicalSlot> allocateSlot(
		SlotRequestId slotRequestId,
		ScheduledUnit task,
		SlotProfile slotProfile,
		Time allocationTimeout) {
	final SlotContext slot;

	synchronized (lock) {
		if (slots.isEmpty()) {
			slot = null;
		} else {
			slot = slots.removeFirst();
		}
		if (slot != null) {
			TestingLogicalSlot result = new TestingLogicalSlotBuilder()
				.setTaskManagerLocation(slot.getTaskManagerLocation())
				.setTaskManagerGateway(slot.getTaskManagerGateway())
				.setSlotNumber(slot.getPhysicalSlotNumber())
				.setAllocationId(slot.getAllocationId())
				.setSlotRequestId(slotRequestId)
				.setSlotSharingGroupId(task.getSlotSharingGroupId())
				.setSlotOwner(this)
				.createTestingLogicalSlot();
			allocatedSlots.put(slotRequestId, slot);
			return CompletableFuture.completedFuture(result);
		} else {
			return FutureUtils.completedExceptionally(new NoResourceAvailableException());
		}
	}
}
 
Example #19
Source File: SlotSharingManagerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testHashEnoughResourceOfMultiTaskSlot() {
	ResourceProfile rp1 = ResourceProfile.fromResources(1.0, 100);
	ResourceProfile rp2 = ResourceProfile.fromResources(2.0, 200);
	ResourceProfile allocatedSlotRp = ResourceProfile.fromResources(2.0, 200);

	SlotSharingManager slotSharingManager = createTestingSlotSharingManager();

	CompletableFuture<SlotContext> slotContextFuture = new CompletableFuture<>();

	SlotSharingManager.MultiTaskSlot unresolvedRootSlot = slotSharingManager.createRootSlot(
			new SlotRequestId(),
			slotContextFuture,
			new SlotRequestId());

	SlotSharingManager.MultiTaskSlot multiTaskSlot =
			unresolvedRootSlot.allocateMultiTaskSlot(new SlotRequestId(), new SlotSharingGroupId());

	SlotSharingManager.SingleTaskSlot firstChild = multiTaskSlot.allocateSingleTaskSlot(
			new SlotRequestId(),
			rp1,
			new SlotSharingGroupId(),
			Locality.LOCAL);

	assertThat(multiTaskSlot.mayHaveEnoughResourcesToFulfill(rp1), is(true));
	assertThat(multiTaskSlot.mayHaveEnoughResourcesToFulfill(rp2), is(true));
	assertThat(multiTaskSlot.mayHaveEnoughResourcesToFulfill(ResourceProfile.UNKNOWN), is(true));

	slotContextFuture.complete(new AllocatedSlot(
			new AllocationID(),
			new TaskManagerLocation(new ResourceID("tm-X"), InetAddress.getLoopbackAddress(), 46),
			0,
			allocatedSlotRp,
			mock(TaskManagerGateway.class)));

	assertThat(multiTaskSlot.mayHaveEnoughResourcesToFulfill(rp1), is(true));
	assertThat(multiTaskSlot.mayHaveEnoughResourcesToFulfill(rp2), is(false));
	assertThat(multiTaskSlot.mayHaveEnoughResourcesToFulfill(ResourceProfile.UNKNOWN), is(true));
}
 
Example #20
Source File: SlotSharingManagerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that slot context future failures will release the root slot.
 */
@Test
public void testSlotContextFutureFailure() {
	SlotSharingManager slotSharingManager = createTestingSlotSharingManager();

	CompletableFuture<SlotContext> slotContextFuture = new CompletableFuture<>();

	assertTrue(slotSharingManager.isEmpty());

	SlotSharingManager.MultiTaskSlot rootSlot = slotSharingManager.createRootSlot(
		new SlotRequestId(),
		slotContextFuture,
		new SlotRequestId());

	SlotSharingManager.SingleTaskSlot singleTaskSlot = rootSlot.allocateSingleTaskSlot(
		new SlotRequestId(),
		ResourceProfile.UNKNOWN,
		new AbstractID(),
		Locality.LOCAL);

	slotContextFuture.completeExceptionally(new FlinkException("Test exception"));

	assertTrue(singleTaskSlot.getLogicalSlotFuture().isCompletedExceptionally());
	assertTrue(slotSharingManager.isEmpty());
	assertTrue(slotSharingManager.getResolvedRootSlots().isEmpty());
	assertTrue(slotSharingManager.getUnresolvedRootSlots().isEmpty());
}
 
Example #21
Source File: SlotSharingManager.java    From flink with Apache License 2.0 5 votes vote down vote up
private void releaseSlotIfOversubscribing(SlotContext slotContext) {
	final ResourceProfile slotResources = slotContext.getResourceProfile();

	if (!slotResources.isMatching(getReservedResources())) {
		release(
			new IllegalStateException(
				"The allocated slot does not have enough resource for all its children. " +
					"This indicates a bug of required resources calculation or slot allocation."));
	}
}
 
Example #22
Source File: SlotSharingManagerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testRootSlotRelease() throws ExecutionException, InterruptedException {
	final CompletableFuture<SlotRequestId> slotReleasedFuture = new CompletableFuture<>();
	final TestingAllocatedSlotActions allocatedSlotActions = new TestingAllocatedSlotActions();

	allocatedSlotActions.setReleaseSlotConsumer(
		tuple3 -> slotReleasedFuture.complete(tuple3.f0));

	final SlotSharingManager slotSharingManager = new SlotSharingManager(
		SLOT_SHARING_GROUP_ID,
		allocatedSlotActions,
		SLOT_OWNER);

	SlotRequestId slotRequestId = new SlotRequestId();
	SlotRequestId allocatedSlotRequestId = new SlotRequestId();

	CompletableFuture<SlotContext> slotContextFuture = new CompletableFuture<>();

	SlotSharingManager.MultiTaskSlot rootSlot = slotSharingManager.createRootSlot(
		slotRequestId,
		slotContextFuture,
		allocatedSlotRequestId);

	assertTrue(slotSharingManager.contains(slotRequestId));

	rootSlot.release(new FlinkException("Test exception"));

	// check that we return the allocated slot
	assertEquals(allocatedSlotRequestId, slotReleasedFuture.get());

	assertFalse(slotSharingManager.contains(slotRequestId));
}
 
Example #23
Source File: SlotSharingManager.java    From flink with Apache License 2.0 5 votes vote down vote up
private MultiTaskSlot(
		SlotRequestId slotRequestId,
		CompletableFuture<? extends SlotContext> slotContextFuture,
		SlotRequestId allocatedSlotRequestId) {
	this(
		slotRequestId,
		null,
		null,
		slotContextFuture,
		allocatedSlotRequestId);
}
 
Example #24
Source File: SimpleSlotProvider.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void cancelSlotRequest(SlotRequestId slotRequestId, @Nullable SlotSharingGroupId slotSharingGroupId, Throwable cause) {
	synchronized (lock) {
		final SlotContext slotContext = allocatedSlots.remove(slotRequestId);

		if (slotContext != null) {
			slots.add(slotContext);
		} else {
			throw new FlinkRuntimeException("Unknown slot request id " + slotRequestId + '.');
		}
	}
}
 
Example #25
Source File: SlotSharingManagerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testRootSlotRelease() throws ExecutionException, InterruptedException {
	final CompletableFuture<SlotRequestId> slotReleasedFuture = new CompletableFuture<>();
	final TestingAllocatedSlotActions allocatedSlotActions = new TestingAllocatedSlotActions();

	allocatedSlotActions.setReleaseSlotConsumer(
		tuple3 -> slotReleasedFuture.complete(tuple3.f0));

	final SlotSharingManager slotSharingManager = new SlotSharingManager(
		SLOT_SHARING_GROUP_ID,
		allocatedSlotActions,
		SLOT_OWNER);

	SlotRequestId slotRequestId = new SlotRequestId();
	SlotRequestId allocatedSlotRequestId = new SlotRequestId();

	CompletableFuture<SlotContext> slotContextFuture = new CompletableFuture<>();

	SlotSharingManager.MultiTaskSlot rootSlot = slotSharingManager.createRootSlot(
		slotRequestId,
		slotContextFuture,
		allocatedSlotRequestId);

	assertTrue(slotSharingManager.contains(slotRequestId));

	rootSlot.release(new FlinkException("Test exception"));

	// check that we return the allocated slot
	assertEquals(allocatedSlotRequestId, slotReleasedFuture.get());

	assertFalse(slotSharingManager.contains(slotRequestId));
}
 
Example #26
Source File: SingleLogicalSlot.java    From flink with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
public SingleLogicalSlot(
	SlotRequestId slotRequestId,
	SlotContext slotContext,
	@Nullable SlotSharingGroupId slotSharingGroupId,
	Locality locality,
	SlotOwner slotOwner) {

	this(slotRequestId, slotContext, slotSharingGroupId, locality, slotOwner, true);
}
 
Example #27
Source File: SimpleSlotProvider.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void cancelSlotRequest(SlotRequestId slotRequestId, @Nullable SlotSharingGroupId slotSharingGroupId, Throwable cause) {
	synchronized (lock) {
		final SlotContext slotContext = allocatedSlots.remove(slotRequestId);

		if (slotContext != null) {
			slots.add(slotContext);
		} else {
			throw new FlinkRuntimeException("Unknown slot request id " + slotRequestId + '.');
		}
	}
}
 
Example #28
Source File: SimpleSlotProvider.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<LogicalSlot> allocateSlot(
		SlotRequestId slotRequestId,
		ScheduledUnit task,
		SlotProfile slotProfile,
		boolean allowQueued,
		Time allocationTimeout) {
	final SlotContext slot;

	synchronized (lock) {
		if (slots.isEmpty()) {
			slot = null;
		} else {
			slot = slots.removeFirst();
		}
		if (slot != null) {
			TestingLogicalSlot result = new TestingLogicalSlotBuilder()
				.setTaskManagerLocation(slot.getTaskManagerLocation())
				.setTaskManagerGateway(slot.getTaskManagerGateway())
				.setSlotNumber(slot.getPhysicalSlotNumber())
				.setAllocationId(slot.getAllocationId())
				.setSlotRequestId(slotRequestId)
				.setSlotOwner(this)
				.createTestingLogicalSlot();
			allocatedSlots.put(slotRequestId, slot);
			return CompletableFuture.completedFuture(result);
		}
		else {
			return FutureUtils.completedExceptionally(new NoResourceAvailableException());
		}
	}
}
 
Example #29
Source File: SlotSharingManagerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that the root slot are moved from unresolved to resolved once the
 * slot context future is successfully completed
 */
@Test
public void testRootSlotTransition() {
	final TestingAllocatedSlotActions allocatedSlotActions = new TestingAllocatedSlotActions();

	SlotSharingManager slotSharingManager = new SlotSharingManager(
		SLOT_SHARING_GROUP_ID,
		allocatedSlotActions,
		SLOT_OWNER);

	CompletableFuture<SlotContext> slotContextFuture = new CompletableFuture<>();
	SlotSharingManager.MultiTaskSlot rootSlot = slotSharingManager.createRootSlot(
		new SlotRequestId(),
		slotContextFuture,
		new SlotRequestId());

	assertTrue(slotSharingManager.getUnresolvedRootSlots().contains(rootSlot));
	assertFalse(slotSharingManager.getResolvedRootSlots().contains(rootSlot));

	// now complete the slotContextFuture
	slotContextFuture.complete(
		new SimpleSlotContext(
			new AllocationID(),
			new LocalTaskManagerLocation(),
			0,
			new SimpleAckingTaskManagerGateway()));

	assertFalse(slotSharingManager.getUnresolvedRootSlots().contains(rootSlot));
	assertTrue(slotSharingManager.getResolvedRootSlots().contains(rootSlot));
}
 
Example #30
Source File: SlotSharingManagerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that slot context future failures will release the root slot
 */
@Test
public void testSlotContextFutureFailure() {
	final TestingAllocatedSlotActions allocatedSlotActions = new TestingAllocatedSlotActions();

	SlotSharingManager slotSharingManager = new SlotSharingManager(
		SLOT_SHARING_GROUP_ID,
		allocatedSlotActions,
		SLOT_OWNER);

	CompletableFuture<SlotContext> slotContextFuture = new CompletableFuture<>();

	assertTrue(slotSharingManager.isEmpty());

	SlotSharingManager.MultiTaskSlot rootSlot = slotSharingManager.createRootSlot(
		new SlotRequestId(),
		slotContextFuture,
		new SlotRequestId());

	SlotSharingManager.SingleTaskSlot singleTaskSlot = rootSlot.allocateSingleTaskSlot(
		new SlotRequestId(),
		ResourceProfile.UNKNOWN,
		new AbstractID(),
		Locality.LOCAL);

	slotContextFuture.completeExceptionally(new FlinkException("Test exception"));

	assertTrue(singleTaskSlot.getLogicalSlotFuture().isCompletedExceptionally());
	assertTrue(slotSharingManager.isEmpty());
	assertTrue(slotSharingManager.getResolvedRootSlots().isEmpty());
	assertTrue(slotSharingManager.getUnresolvedRootSlots().isEmpty());
}