Java源码示例:org.apache.flink.runtime.instance.SlotSharingGroupId

示例1
private void releaseSharedSlot(
	@Nonnull SlotRequestId slotRequestId,
	@Nonnull SlotSharingGroupId slotSharingGroupId,
	Throwable cause) {

	final SlotSharingManager multiTaskSlotManager = slotSharingManagers.get(slotSharingGroupId);

	if (multiTaskSlotManager != null) {
		final SlotSharingManager.TaskSlot taskSlot = multiTaskSlotManager.getTaskSlot(slotRequestId);

		if (taskSlot != null) {
			taskSlot.release(cause);
		} else {
			log.debug("Could not find slot [{}] in slot sharing group {}. Ignoring release slot request.", slotRequestId, slotSharingGroupId);
		}
	} else {
		log.debug("Could not find slot sharing group {}. Ignoring release slot request.", slotSharingGroupId);
	}
}
 
示例2
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;
}
 
示例3
private void releaseSharedSlot(
	@Nonnull SlotRequestId slotRequestId,
	@Nonnull SlotSharingGroupId slotSharingGroupId,
	Throwable cause) {

	final SlotSharingManager multiTaskSlotManager = slotSharingManagers.get(slotSharingGroupId);

	if (multiTaskSlotManager != null) {
		final SlotSharingManager.TaskSlot taskSlot = multiTaskSlotManager.getTaskSlot(slotRequestId);

		if (taskSlot != null) {
			taskSlot.release(cause);
		} else {
			log.debug("Could not find slot [{}] in slot sharing group {}. Ignoring release slot request.", slotRequestId, slotSharingGroupId);
		}
	} else {
		log.debug("Could not find slot sharing group {}. Ignoring release slot request.", slotSharingGroupId);
	}
}
 
示例4
private void releaseSharedSlot(
	@Nonnull SlotRequestId slotRequestId,
	@Nonnull SlotSharingGroupId slotSharingGroupId,
	Throwable cause) {

	final SlotSharingManager multiTaskSlotManager = slotSharingManagers.get(slotSharingGroupId);

	if (multiTaskSlotManager != null) {
		final SlotSharingManager.TaskSlot taskSlot = multiTaskSlotManager.getTaskSlot(slotRequestId);

		if (taskSlot != null) {
			taskSlot.release(cause);
		} else {
			log.debug("Could not find slot [{}] in slot sharing group {}. Ignoring release slot request.", slotRequestId, slotSharingGroupId);
		}
	} else {
		log.debug("Could not find slot sharing group {}. Ignoring release slot request.", slotSharingGroupId);
	}
}
 
示例5
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;
}
 
示例6
TestingLogicalSlot(
		TaskManagerLocation taskManagerLocation,
		TaskManagerGateway taskManagerGateway,
		int slotNumber,
		AllocationID allocationId,
		SlotRequestId slotRequestId,
		SlotSharingGroupId slotSharingGroupId,
		boolean automaticallyCompleteReleaseFuture,
		SlotOwner slotOwner) {

	this.taskManagerLocation = Preconditions.checkNotNull(taskManagerLocation);
	this.taskManagerGateway = Preconditions.checkNotNull(taskManagerGateway);
	this.payloadReference = new AtomicReference<>();
	this.slotNumber = slotNumber;
	this.allocationId = Preconditions.checkNotNull(allocationId);
	this.slotRequestId = Preconditions.checkNotNull(slotRequestId);
	this.slotSharingGroupId = Preconditions.checkNotNull(slotSharingGroupId);
	this.releaseFuture = new CompletableFuture<>();
	this.automaticallyCompleteReleaseFuture = automaticallyCompleteReleaseFuture;
	this.slotOwner = slotOwner;
}
 
示例7
public int getNumberOfAvailableSlotsForGroup(SlotSharingGroupId slotSharingGroupId, JobVertexID jobVertexId) {
	final SlotSharingManager multiTaskSlotManager = slotSharingManagersMap.get(slotSharingGroupId);

	if (multiTaskSlotManager != null) {
		int availableSlots = 0;

		for (SlotSharingManager.MultiTaskSlot multiTaskSlot : multiTaskSlotManager.getResolvedRootSlots()) {
			if (!multiTaskSlot.contains(jobVertexId)) {
				availableSlots++;
			}
		}

		return availableSlots;
	} else {
		throw new FlinkRuntimeException("No MultiTaskSlotmanager registered under " + slotSharingGroupId + '.');
	}
}
 
示例8
@Override
public void cancelSlotRequest(
	SlotRequestId slotRequestId,
	@Nullable SlotSharingGroupId slotSharingGroupId,
	Throwable cause) {

	componentMainThreadExecutor.assertRunningInMainThread();

	if (slotSharingGroupId != null) {
		releaseSharedSlot(slotRequestId, slotSharingGroupId, cause);
	} else {
		slotPool.releaseSlot(slotRequestId, cause);
	}
}
 
示例9
@Override
public void returnLogicalSlot(LogicalSlot logicalSlot) {
	SlotRequestId slotRequestId = logicalSlot.getSlotRequestId();
	SlotSharingGroupId slotSharingGroupId = logicalSlot.getSlotSharingGroupId();
	FlinkException cause = new FlinkException("Slot is being returned to the SlotPool.");
	cancelSlotRequest(slotRequestId, slotSharingGroupId, cause);
}
 
示例10
@Test
public void testGetResolvedSlotWithResourceConfigured() {
	ResourceProfile rp1 = ResourceProfile.fromResources(1.0, 100);
	ResourceProfile rp2 = ResourceProfile.fromResources(2.0, 200);
	ResourceProfile allocatedSlotRp = ResourceProfile.fromResources(5.0, 500);

	SlotSharingManager slotSharingManager = createTestingSlotSharingManager();

	SlotSharingManager.MultiTaskSlot rootSlot = slotSharingManager.createRootSlot(
			new SlotRequestId(),
			CompletableFuture.completedFuture(
					new SimpleSlotContext(
							new AllocationID(),
							new LocalTaskManagerLocation(),
							0,
							new SimpleAckingTaskManagerGateway(),
							allocatedSlotRp)),
			new SlotRequestId());

	rootSlot.allocateSingleTaskSlot(
			new SlotRequestId(),
			rp1,
			new SlotSharingGroupId(),
			Locality.LOCAL);

	Collection<SlotSelectionStrategy.SlotInfoAndResources> resolvedRoots =
		slotSharingManager.listResolvedRootSlotInfo(new AbstractID());
	assertEquals(1, resolvedRoots.size());
	assertEquals(allocatedSlotRp.subtract(rp1), resolvedRoots.iterator().next().getRemainingResources());

	rootSlot.allocateSingleTaskSlot(
			new SlotRequestId(),
			rp2,
			new SlotSharingGroupId(),
			Locality.LOCAL);
	resolvedRoots = slotSharingManager.listResolvedRootSlotInfo(new AbstractID());
	assertEquals(1, resolvedRoots.size());
	assertEquals(allocatedSlotRp.subtract(rp1).subtract(rp2), resolvedRoots.iterator().next().getRemainingResources());
}
 
示例11
@Test
public void testCreatedSlotRequests() {
	final ExecutionVertexID executionVertexId = new ExecutionVertexID(new JobVertexID(), 0);
	final AllocationID allocationId = new AllocationID();
	final SlotSharingGroupId sharingGroupId = new SlotSharingGroupId();
	final ResourceProfile taskResourceProfile = ResourceProfile.fromResources(0.5, 250);
	final ResourceProfile physicalSlotResourceProfile = ResourceProfile.fromResources(1.0, 300);
	final TaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();

	final TestingStateLocationRetriever stateLocationRetriever = new TestingStateLocationRetriever();
	stateLocationRetriever.setStateLocation(executionVertexId, taskManagerLocation);

	final ExecutionSlotAllocator executionSlotAllocator = createExecutionSlotAllocator(
		stateLocationRetriever,
		new TestingInputsLocationsRetriever.Builder().build());

	final List<ExecutionVertexSchedulingRequirements> schedulingRequirements = Collections.singletonList(
		new ExecutionVertexSchedulingRequirements.Builder()
			.withExecutionVertexId(executionVertexId)
			.withPreviousAllocationId(allocationId)
			.withSlotSharingGroupId(sharingGroupId)
			.withPhysicalSlotResourceProfile(physicalSlotResourceProfile)
			.withTaskResourceProfile(taskResourceProfile)
			.build()
	);

	executionSlotAllocator.allocateSlotsFor(schedulingRequirements);
	assertThat(slotProvider.getSlotRequests(), hasSize(1));

	final SlotProfile requestSlotProfile = slotProvider.getSlotRequests().iterator().next().getSlotProfile();

	assertThat(requestSlotProfile.getPreferredAllocations(), contains(allocationId));
	assertThat(requestSlotProfile.getPreviousExecutionGraphAllocations(), contains(allocationId));
	assertThat(requestSlotProfile.getTaskResourceProfile(), equalTo(taskResourceProfile));
	assertThat(requestSlotProfile.getPreferredLocations(), contains(taskManagerLocation));
	// task resource profile is used instead of slot sharing group resource profile since slot sharing is ignored
	assertThat(requestSlotProfile.getPhysicalSlotResourceProfile(), equalTo(taskResourceProfile));
}
 
示例12
public ScheduledUnit(
		Execution task,
		@Nullable SlotSharingGroupId slotSharingGroupId,
		@Nullable CoLocationConstraint coLocationConstraint) {
	this(
		Preconditions.checkNotNull(task),
		task.getVertex().getJobvertexId(),
		slotSharingGroupId,
		coLocationConstraint);
}
 
示例13
public ScheduledUnit(
		JobVertexID jobVertexId,
		@Nullable SlotSharingGroupId slotSharingGroupId,
		@Nullable CoLocationConstraint coLocationConstraint) {
	this(
		null,
		jobVertexId,
		slotSharingGroupId,
		coLocationConstraint);
}
 
示例14
@Override
public void cancelSlotRequest(
		SlotRequestId slotRequestId,
		@Nullable SlotSharingGroupId slotSharingGroupId,
		Throwable cause) {
	canceledSlotRequests.add(slotRequestId);
}
 
示例15
@Test
public void testSingleQueuedSharedSlotScheduling() throws Exception {
	final CompletableFuture<AllocationID> allocationIdFuture = new CompletableFuture<>();
	final TestingResourceManagerGateway testingResourceManagerGateway = slotPoolResource.getTestingResourceManagerGateway();
	testingResourceManagerGateway.setRequestSlotConsumer(
		(SlotRequest slotRequest) -> allocationIdFuture.complete(slotRequest.getAllocationId()));

	LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
	final SlotPoolImpl slotPool = slotPoolResource.getSlotPool();
	slotPool.registerTaskManager(taskManagerLocation.getResourceID());

	SlotSharingGroupId slotSharingGroupId = new SlotSharingGroupId();
	final SlotProvider slotProvider = slotPoolResource.getSlotProvider();
	CompletableFuture<LogicalSlot> logicalSlotFuture = slotProvider.allocateSlot(
		new ScheduledUnit(
			new JobVertexID(),
			slotSharingGroupId,
			null),
		SlotProfile.noRequirements(),
		TestingUtils.infiniteTime());

	assertFalse(logicalSlotFuture.isDone());

	final AllocationID allocationId = allocationIdFuture.get();

	boolean booleanCompletableFuture = slotPool.offerSlot(
		taskManagerLocation,
		new SimpleAckingTaskManagerGateway(),
		new SlotOffer(
			allocationId,
			0,
			ResourceProfile.ANY));

	assertTrue(booleanCompletableFuture);

	final LogicalSlot logicalSlot = logicalSlotFuture.get();

	assertEquals(slotSharingGroupId, logicalSlot.getSlotSharingGroupId());
}
 
示例16
private ExecutionVertexSchedulingRequirements(
		ExecutionVertexID executionVertexId,
		@Nullable AllocationID previousAllocationId,
		ResourceProfile taskResourceProfile,
		ResourceProfile physicalSlotResourceProfile,
		@Nullable SlotSharingGroupId slotSharingGroupId,
		@Nullable CoLocationConstraint coLocationConstraint) {
	this.executionVertexId = checkNotNull(executionVertexId);
	this.previousAllocationId = previousAllocationId;
	this.taskResourceProfile = checkNotNull(taskResourceProfile);
	this.physicalSlotResourceProfile = checkNotNull(physicalSlotResourceProfile);
	this.slotSharingGroupId = slotSharingGroupId;
	this.coLocationConstraint = coLocationConstraint;
}
 
示例17
@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 + '.');
		}
	}
}
 
示例18
@Override
public void cancelSlotRequest(SlotRequestId slotRequestId, @Nullable SlotSharingGroupId slotSharingGroupId, Throwable cause) {
	final CompletableFuture<LogicalSlot> slotFuture = slotFutures.remove(slotRequestId);
	slotFuture.cancel(false);

	slotCanceller.accept(slotRequestId);
}
 
示例19
public TestingScheduler(
	@Nonnull Map<SlotSharingGroupId, SlotSharingManager> slotSharingManagersMap,
	@Nonnull SlotSelectionStrategy slotSelectionStrategy,
	@Nonnull SlotPool slotPoolGateway) {

	super(slotSelectionStrategy, slotPoolGateway, slotSharingManagersMap);
	this.slotSharingManagersMap = slotSharingManagersMap;
}
 
示例20
public int getNumberOfSharedSlots(SlotSharingGroupId slotSharingGroupId) {
	final SlotSharingManager multiTaskSlotManager = slotSharingManagersMap.get(slotSharingGroupId);

	if (multiTaskSlotManager != null) {
		return multiTaskSlotManager.getResolvedRootSlots().size();
	} else {
		throw new FlinkRuntimeException("No MultiTaskSlotManager registered under " + slotSharingGroupId + '.');
	}
}
 
示例21
@Override
public void cancelSlotRequest(
	SlotRequestId slotRequestId,
	@Nullable SlotSharingGroupId slotSharingGroupId,
	Throwable cause) {

	componentMainThreadExecutor.assertRunningInMainThread();

	if (slotSharingGroupId != null) {
		releaseSharedSlot(slotRequestId, slotSharingGroupId, cause);
	} else {
		slotPool.releaseSlot(slotRequestId, cause);
	}
}
 
示例22
@Test
public void allocateSharedSlot_withNoRequirements_selectsSlotsSoThatWorkloadIsSpreadOut() {
	final int numberSlotsPerTaskExecutor = 2;
	final int numberTaskExecutors = 2;
	final int numberSlots = numberTaskExecutors * numberSlotsPerTaskExecutor;

	registerTaskExecutors(numberTaskExecutors, numberSlotsPerTaskExecutor);

	final JobVertexID sourceJobVertexId = new JobVertexID();
	final JobVertexID sinkJobVertexId = new JobVertexID();
	final SlotSharingGroupId slotSharingGroupId = new SlotSharingGroupId();

	final List<ScheduledUnit> sourceScheduledUnits = IntStream.range(0, numberSlots)
		.mapToObj(ignored -> createSharedSlotRequest(sourceJobVertexId, slotSharingGroupId))
		.collect(Collectors.toList());

	final List<ScheduledUnit> sinkScheduledUnits = IntStream.range(0, numberTaskExecutors)
		.mapToObj(ignored -> createSharedSlotRequest(sinkJobVertexId, slotSharingGroupId))
		.collect(Collectors.toList());

	sourceScheduledUnits.forEach(this::allocateSlot);
	final Set<TaskManagerLocation> sinkLocations = sinkScheduledUnits.stream()
		.map(this::allocateSlot)
		.map(this::getTaskManagerLocation)
		.collect(Collectors.toSet());

	// verify that the sinks have been evenly spread across the available TaskExecutors
	assertThat(sinkLocations, hasSize(numberTaskExecutors));
}
 
示例23
SlotSharingManager(
		SlotSharingGroupId slotSharingGroupId,
		AllocatedSlotActions allocatedSlotActions,
		SlotOwner slotOwner) {
	this.slotSharingGroupId = Preconditions.checkNotNull(slotSharingGroupId);
	this.allocatedSlotActions = Preconditions.checkNotNull(allocatedSlotActions);
	this.slotOwner = Preconditions.checkNotNull(slotOwner);

	allTaskSlots = new HashMap<>(16);
	unresolvedRootSlots = new HashMap<>(16);
	resolvedRootSlots = new HashMap<>(16);
}
 
示例24
private ExecutionVertexSchedulingRequirements(
		ExecutionVertexID executionVertexId,
		@Nullable AllocationID previousAllocationId,
		ResourceProfile resourceProfile,
		@Nullable SlotSharingGroupId slotSharingGroupId,
		@Nullable CoLocationConstraint coLocationConstraint,
		Collection<TaskManagerLocation> preferredLocations) {
	this.executionVertexId = checkNotNull(executionVertexId);
	this.previousAllocationId = previousAllocationId;
	this.resourceProfile = checkNotNull(resourceProfile);
	this.slotSharingGroupId = slotSharingGroupId;
	this.coLocationConstraint = coLocationConstraint;
	this.preferredLocations = checkNotNull(preferredLocations);
}
 
示例25
@Override
public void cancelSlotRequest(
	SlotRequestId slotRequestId,
	@Nullable SlotSharingGroupId slotSharingGroupId,
	Throwable cause) {

	componentMainThreadExecutor.assertRunningInMainThread();

	if (slotSharingGroupId != null) {
		releaseSharedSlot(slotRequestId, slotSharingGroupId, cause);
	} else {
		slotPool.releaseSlot(slotRequestId, cause);
	}
}
 
示例26
public ScheduledUnit(Execution task, @Nullable SlotSharingGroupId slotSharingGroupId) {
	this(
		Preconditions.checkNotNull(task),
		task.getVertex().getJobvertexId(),
		slotSharingGroupId,
		null);
}
 
示例27
public ScheduledUnit(
		Execution task,
		@Nullable SlotSharingGroupId slotSharingGroupId,
		@Nullable CoLocationConstraint coLocationConstraint) {
	this(
		Preconditions.checkNotNull(task),
		task.getVertex().getJobvertexId(),
		slotSharingGroupId,
		coLocationConstraint);
}
 
示例28
public ScheduledUnit(
		JobVertexID jobVertexId,
		@Nullable SlotSharingGroupId slotSharingGroupId,
		@Nullable CoLocationConstraint coLocationConstraint) {
	this(
		null,
		jobVertexId,
		slotSharingGroupId,
		coLocationConstraint);
}
 
示例29
public ScheduledUnit(
	@Nullable Execution task,
	JobVertexID jobVertexId,
	@Nullable SlotSharingGroupId slotSharingGroupId,
	@Nullable CoLocationConstraint coLocationConstraint) {

	this.vertexExecution = task;
	this.jobVertexId = Preconditions.checkNotNull(jobVertexId);
	this.slotSharingGroupId = slotSharingGroupId;
	this.coLocationConstraint = coLocationConstraint;

}
 
示例30
@Override
public void cancelSlotRequest(
		final SlotRequestId slotRequestId,
		@Nullable final SlotSharingGroupId slotSharingGroupId,
		final Throwable cause) {
	cancelledSlotRequestIds.add(slotRequestId);
}