org.apache.flink.runtime.jobmanager.scheduler.Locality Java Examples

The following examples show how to use org.apache.flink.runtime.jobmanager.scheduler.Locality. 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: SlotSharingManager.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Allocates a {@link SingleTaskSlot} and registers it under the given groupId at
 * this MultiTaskSlot.
 *
 * @param slotRequestId of the new single task slot
 * @param groupId under which the new single task slot is registered
 * @param locality of the allocation
 * @return the newly allocated {@link SingleTaskSlot}
 */
SingleTaskSlot allocateSingleTaskSlot(
		SlotRequestId slotRequestId,
		AbstractID groupId,
		Locality locality) {
	Preconditions.checkState(!super.contains(groupId));

	LOG.debug("Create single task slot [{}] in multi task slot [{}] for group {}.", slotRequestId, getSlotRequestId(), groupId);

	final SingleTaskSlot leaf = new SingleTaskSlot(
		slotRequestId,
		groupId,
		this,
		locality);

	children.put(groupId, leaf);

	// register the newly allocated slot also at the SlotSharingManager
	allTaskSlots.put(slotRequestId, leaf);

	return leaf;
}
 
Example #2
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 #3
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 #4
Source File: SlotSharingGroupAssignment.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a slot suitable for the given task vertex. This method will prefer slots that are local
 * (with respect to {@link ExecutionVertex#getPreferredLocationsBasedOnInputs()}), but will return non local
 * slots if no local slot is available. The method returns null, when this sharing group has
 * no slot available for the given JobVertexID.
 *
 * @param vertexID the vertex id
 * @param locationPreferences location preferences
 *
 * @return A slot to execute the given ExecutionVertex in, or null, if none is available.
 */
public SimpleSlot getSlotForTask(JobVertexID vertexID, Iterable<TaskManagerLocation> locationPreferences) {
	synchronized (lock) {
		Tuple2<SharedSlot, Locality> p = getSharedSlotForTask(vertexID, locationPreferences, false);

		if (p != null) {
			SharedSlot ss = p.f0;
			SimpleSlot slot = ss.allocateSubSlot(vertexID);
			slot.setLocality(p.f1);
			return slot;
		}
		else {
			return null;
		}
	}
}
 
Example #5
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 #6
Source File: ExecutionGraphSchedulingTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Nonnull
static SingleLogicalSlot createSingleLogicalSlot(SlotOwner slotOwner, TaskManagerGateway taskManagerGateway, SlotRequestId slotRequestId) {
	TaskManagerLocation location = new TaskManagerLocation(
		ResourceID.generate(), InetAddress.getLoopbackAddress(), 12345);

	SimpleSlotContext slotContext = new SimpleSlotContext(
		new AllocationID(),
		location,
		0,
		taskManagerGateway);

	return new SingleLogicalSlot(
		slotRequestId,
		slotContext,
		null,
		Locality.LOCAL,
		slotOwner);
}
 
Example #7
Source File: SharedSlotsTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testImmediateReleaseOneLevel() {
	try {
		JobVertexID vid = new JobVertexID();

		SlotSharingGroup sharingGroup = new SlotSharingGroup(vid);
		SlotSharingGroupAssignment assignment = sharingGroup.getTaskAssignment();

		Instance instance = SchedulerTestUtils.getRandomInstance(1);
		
		SharedSlot sharedSlot = instance.allocateSharedSlot(assignment);

		SimpleSlot sub = assignment.addSharedSlotAndAllocateSubSlot(sharedSlot, Locality.UNCONSTRAINED, vid);
		sub.releaseSlot();
		
		assertTrue(sub.isReleased());
		assertTrue(sharedSlot.isReleased());
		
		assertEquals(1, instance.getNumberOfAvailableSlots());
		assertEquals(0, instance.getNumberOfAllocatedSlots());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example #8
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 #9
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 #10
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 #11
Source File: ExecutionGraphSchedulingTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
static SingleLogicalSlot createSingleLogicalSlot(SlotOwner slotOwner, TaskManagerGateway taskManagerGateway, SlotRequestId slotRequestId) {
	TaskManagerLocation location = new TaskManagerLocation(
		ResourceID.generate(), InetAddress.getLoopbackAddress(), 12345);

	SimpleSlotContext slotContext = new SimpleSlotContext(
		new AllocationID(),
		location,
		0,
		taskManagerGateway);

	return new SingleLogicalSlot(
		slotRequestId,
		slotContext,
		null,
		Locality.LOCAL,
		slotOwner);
}
 
Example #12
Source File: SlotSharingManager.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Allocates a {@link SingleTaskSlot} and registers it under the given groupId at
 * this MultiTaskSlot.
 *
 * @param slotRequestId of the new single task slot
 * @param groupId under which the new single task slot is registered
 * @param locality of the allocation
 * @return the newly allocated {@link SingleTaskSlot}
 */
SingleTaskSlot allocateSingleTaskSlot(
		SlotRequestId slotRequestId,
		ResourceProfile resourceProfile,
		AbstractID groupId,
		Locality locality) {
	Preconditions.checkState(!super.contains(groupId));

	LOG.debug("Create single task slot [{}] in multi task slot [{}] for group {}.", slotRequestId, getSlotRequestId(), groupId);

	final SingleTaskSlot leaf = new SingleTaskSlot(
		slotRequestId,
		resourceProfile,
		groupId,
		this,
		locality);

	children.put(groupId, leaf);

	// register the newly allocated slot also at the SlotSharingManager
	allTaskSlots.put(slotRequestId, leaf);

	reserveResource(resourceProfile);

	return leaf;
}
 
Example #13
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 #14
Source File: PreviousAllocationSlotSelectionStrategy.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public Optional<SlotInfoAndLocality> selectBestSlotForProfile(
	@Nonnull Collection<SlotInfoAndResources> availableSlots,
	@Nonnull SlotProfile slotProfile) {

	Collection<AllocationID> priorAllocations = slotProfile.getPreferredAllocations();

	// First, if there was a prior allocation try to schedule to the same/old slot
	if (!priorAllocations.isEmpty()) {
		for (SlotInfoAndResources availableSlot : availableSlots) {
			if (priorAllocations.contains(availableSlot.getSlotInfo().getAllocationId())) {
				return Optional.of(
					SlotInfoAndLocality.of(availableSlot.getSlotInfo(), Locality.LOCAL));
			}
		}
	}

	// Second, select based on location preference, excluding blacklisted allocations
	Set<AllocationID> blackListedAllocations = slotProfile.getPreviousExecutionGraphAllocations();
	Collection<SlotInfoAndResources> availableAndAllowedSlots = computeWithoutBlacklistedSlots(availableSlots, blackListedAllocations);
	return fallbackSlotSelectionStrategy.selectBestSlotForProfile(availableAndAllowedSlots, slotProfile);
}
 
Example #15
Source File: ExecutionGraphSchedulingTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Nonnull
static SingleLogicalSlot createSingleLogicalSlot(SlotOwner slotOwner, TaskManagerGateway taskManagerGateway, SlotRequestId slotRequestId) {
	TaskManagerLocation location = new TaskManagerLocation(
		ResourceID.generate(), InetAddress.getLoopbackAddress(), 12345);

	SimpleSlotContext slotContext = new SimpleSlotContext(
		new AllocationID(),
		location,
		0,
		taskManagerGateway);

	return new SingleLogicalSlot(
		slotRequestId,
		slotContext,
		null,
		Locality.LOCAL,
		slotOwner);
}
 
Example #16
Source File: LocationPreferenceSlotSelectionStrategyTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void returnsNonLocalMatchingIfResourceProfileCanBeFulfilledButNotTheTMLocationPreferences() throws Exception {
	final InetAddress nonHostLocalInetAddress = InetAddress.getByAddress(new byte[]{10, 0, 0, 24});
	final TaskManagerLocation nonLocalTm = new TaskManagerLocation(new ResourceID("non-local-tm"), nonHostLocalInetAddress, 42);
	SlotProfile slotProfile = SlotProfile.preferredLocality(resourceProfile, Collections.singletonList(nonLocalTm));
	Optional<SlotSelectionStrategy.SlotInfoAndLocality> match = runMatching(slotProfile);

	Assert.assertTrue(match.isPresent());
	final SlotSelectionStrategy.SlotInfoAndLocality slotInfoAndLocality = match.get();
	assertThat(candidates, hasItem(withSlotInfo(slotInfoAndLocality.getSlotInfo())));
	assertThat(slotInfoAndLocality, hasLocality(Locality.NON_LOCAL));
}
 
Example #17
Source File: SingleLogicalSlotTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private SingleLogicalSlot createSingleLogicalSlot(SlotOwner slotOwner) {
	return new SingleLogicalSlot(
		new SlotRequestId(),
		new DummySlotContext(),
		null,
		Locality.LOCAL,
		slotOwner);
}
 
Example #18
Source File: SlotSharingManagerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that we can create nested slots.
 */
@Test
public void testNestedSlotCreation() {
	final TestingAllocatedSlotActions allocatedSlotActions = new TestingAllocatedSlotActions();

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

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

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

	AbstractID multiTaskSlotGroupId = new AbstractID();
	SlotRequestId multiTaskSlotRequestId = new SlotRequestId();
	SlotSharingManager.MultiTaskSlot multiTaskSlot = rootSlot.allocateMultiTaskSlot(
		multiTaskSlotRequestId,
		multiTaskSlotGroupId);

	assertTrue(Objects.equals(singleTaskSlotRequestId, singleTaskSlot.getSlotRequestId()));
	assertTrue(Objects.equals(multiTaskSlotRequestId, multiTaskSlot.getSlotRequestId()));

	assertTrue(rootSlot.contains(singleTaskSlotGroupId));
	assertTrue(rootSlot.contains(multiTaskSlotGroupId));

	assertTrue(slotSharingManager.contains(singleTaskSlotRequestId));
	assertTrue(slotSharingManager.contains(multiTaskSlotRequestId));
}
 
Example #19
Source File: SlotSharingManagerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetUnresolvedSlot() {
	final TestingAllocatedSlotActions allocatedSlotActions = new TestingAllocatedSlotActions();

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

	SlotSharingManager.MultiTaskSlot rootSlot1 = slotSharingManager.createRootSlot(
		new SlotRequestId(),
		new CompletableFuture<>(),
		new SlotRequestId());

	final AbstractID groupId = new AbstractID();
	SlotSharingManager.MultiTaskSlot unresolvedRootSlot = slotSharingManager.getUnresolvedRootSlot(groupId);

	assertNotNull(unresolvedRootSlot);
	assertEquals(rootSlot1.getSlotRequestId(), unresolvedRootSlot.getSlotRequestId());

	// occupy the unresolved slot
	unresolvedRootSlot.allocateSingleTaskSlot(
		new SlotRequestId(),
		groupId,
		Locality.UNKNOWN);

	SlotSharingManager.MultiTaskSlot unresolvedRootSlot1 = slotSharingManager.getUnresolvedRootSlot(groupId);

	// we should no longer have a free unresolved root slot
	assertNull(unresolvedRootSlot1);
}
 
Example #20
Source File: SlotSharingManagerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetUnresolvedSlot() {
	SlotSharingManager slotSharingManager = createTestingSlotSharingManager();

	SlotSharingManager.MultiTaskSlot rootSlot1 = slotSharingManager.createRootSlot(
		new SlotRequestId(),
		new CompletableFuture<>(),
		new SlotRequestId());

	final AbstractID groupId = new AbstractID();
	SlotSharingManager.MultiTaskSlot unresolvedRootSlot = slotSharingManager.getUnresolvedRootSlot(groupId);

	assertNotNull(unresolvedRootSlot);
	assertEquals(rootSlot1.getSlotRequestId(), unresolvedRootSlot.getSlotRequestId());

	// occupy the unresolved slot
	unresolvedRootSlot.allocateSingleTaskSlot(
		new SlotRequestId(),
		ResourceProfile.UNKNOWN,
		groupId,
		Locality.UNKNOWN);

	SlotSharingManager.MultiTaskSlot unresolvedRootSlot1 = slotSharingManager.getUnresolvedRootSlot(groupId);

	// we should no longer have a free unresolved root slot
	assertNull(unresolvedRootSlot1);
}
 
Example #21
Source File: SharedSlotsTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testImmediateReleaseTwoLevel() {
	try {
		JobVertexID vid = new JobVertexID();
		JobVertex vertex = new JobVertex("vertex", vid);
		
		SlotSharingGroup sharingGroup = new SlotSharingGroup(vid);
		SlotSharingGroupAssignment assignment = sharingGroup.getTaskAssignment();

		CoLocationGroup coLocationGroup = new CoLocationGroup(vertex);
		CoLocationConstraint constraint = coLocationGroup.getLocationConstraint(0);
		
		Instance instance = SchedulerTestUtils.getRandomInstance(1);
		
		SharedSlot sharedSlot = instance.allocateSharedSlot(assignment);

		SimpleSlot sub = assignment.addSharedSlotAndAllocateSubSlot(sharedSlot, Locality.UNCONSTRAINED, constraint);
		
		assertNull(sub.getGroupID());
		assertEquals(constraint.getSharedSlot(), sub.getParent());
		
		sub.releaseSlot();

		assertTrue(sub.isReleased());
		assertTrue(sharedSlot.isReleased());

		assertEquals(1, instance.getNumberOfAvailableSlots());
		assertEquals(0, instance.getNumberOfAllocatedSlots());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example #22
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 #23
Source File: SingleLogicalSlotTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private SingleLogicalSlot createSingleLogicalSlot(SlotOwner slotOwner) {
	return new SingleLogicalSlot(
		new SlotRequestId(),
		createSlotContext(),
		null,
		Locality.LOCAL,
		slotOwner);
}
 
Example #24
Source File: SlotSharingManagerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that we can create nested slots.
 */
@Test
public void testNestedSlotCreation() {
	final TestingAllocatedSlotActions allocatedSlotActions = new TestingAllocatedSlotActions();

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

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

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

	AbstractID multiTaskSlotGroupId = new AbstractID();
	SlotRequestId multiTaskSlotRequestId = new SlotRequestId();
	SlotSharingManager.MultiTaskSlot multiTaskSlot = rootSlot.allocateMultiTaskSlot(
		multiTaskSlotRequestId,
		multiTaskSlotGroupId);

	assertTrue(Objects.equals(singleTaskSlotRequestId, singleTaskSlot.getSlotRequestId()));
	assertTrue(Objects.equals(multiTaskSlotRequestId, multiTaskSlot.getSlotRequestId()));

	assertTrue(rootSlot.contains(singleTaskSlotGroupId));
	assertTrue(rootSlot.contains(multiTaskSlotGroupId));

	assertTrue(slotSharingManager.contains(singleTaskSlotRequestId));
	assertTrue(slotSharingManager.contains(multiTaskSlotRequestId));
}
 
Example #25
Source File: SlotSharingManagerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that we can release inner slots and that this triggers the slot release for all
 * its children.
 */
@Test
public void testInnerSlotRelease() {
	final TestingAllocatedSlotActions allocatedSlotActions = new TestingAllocatedSlotActions();

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

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

	SlotSharingManager.MultiTaskSlot multiTaskSlot = rootSlot.allocateMultiTaskSlot(
		new SlotRequestId(),
		new AbstractID());

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

	SlotSharingManager.MultiTaskSlot multiTaskSlot1 = multiTaskSlot.allocateMultiTaskSlot(
		new SlotRequestId(),
		new AbstractID());

	assertTrue(slotSharingManager.contains(multiTaskSlot1.getSlotRequestId()));
	assertTrue(slotSharingManager.contains(singleTaskSlot1.getSlotRequestId()));
	assertTrue(slotSharingManager.contains(multiTaskSlot.getSlotRequestId()));

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

	assertFalse(slotSharingManager.contains(multiTaskSlot1.getSlotRequestId()));
	assertFalse(slotSharingManager.contains(singleTaskSlot1.getSlotRequestId()));
	assertFalse(slotSharingManager.contains(multiTaskSlot.getSlotRequestId()));
	assertTrue(singleTaskSlot1.getLogicalSlotFuture().isCompletedExceptionally());
}
 
Example #26
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 #27
Source File: SingleLogicalSlotTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private SingleLogicalSlot createSingleLogicalSlot(SlotOwner slotOwner) {
	return new SingleLogicalSlot(
		new SlotRequestId(),
		createSlotContext(),
		null,
		Locality.LOCAL,
		slotOwner);
}
 
Example #28
Source File: DefaultLocationPreferenceSlotSelectionStrategy.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
protected Optional<SlotInfoAndLocality> selectWithoutLocationPreference(@Nonnull Collection<SlotInfoAndResources> availableSlots, @Nonnull ResourceProfile resourceProfile) {
	for (SlotInfoAndResources candidate : availableSlots) {
		if (candidate.getRemainingResources().isMatching(resourceProfile)) {
			return Optional.of(SlotInfoAndLocality.of(candidate.getSlotInfo(), Locality.UNCONSTRAINED));
		}
	}
	return Optional.empty();
}
 
Example #29
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 #30
Source File: SlotSharingManagerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testTaskExecutorUtilizationCalculation() {
	final TestingAllocatedSlotActions allocatedSlotActions = new TestingAllocatedSlotActions();
	final TaskManagerLocation firstTaskExecutorLocation = new LocalTaskManagerLocation();
	final TaskManagerLocation secondTaskExecutorLocation = new LocalTaskManagerLocation();

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

	final SlotSharingManager.MultiTaskSlot firstRootSlot = createRootSlot(firstTaskExecutorLocation, slotSharingManager);
	createRootSlot(firstTaskExecutorLocation, slotSharingManager);
	createRootSlot(secondTaskExecutorLocation, slotSharingManager);

	final AbstractID groupId = new AbstractID();

	firstRootSlot.allocateSingleTaskSlot(new SlotRequestId(), ResourceProfile.UNKNOWN, groupId, Locality.UNCONSTRAINED);

	final Collection<SlotSelectionStrategy.SlotInfoAndResources> slotInfoAndResources = slotSharingManager.listResolvedRootSlotInfo(groupId);

	assertThat(slotInfoAndResources, hasSize(2));

	final Map<TaskManagerLocation, Double> utilizationPerTaskExecutor = slotInfoAndResources.stream()
		.collect(
			Collectors.toMap(
				slot -> slot.getSlotInfo().getTaskManagerLocation(),
				SlotSelectionStrategy.SlotInfoAndResources::getTaskExecutorUtilization));

	assertThat(utilizationPerTaskExecutor.get(firstTaskExecutorLocation), is(closeTo(1.0 / 2, 0.1)));
	assertThat(utilizationPerTaskExecutor.get(secondTaskExecutorLocation), is(closeTo(0, 0.1)));
}