use of io.trino.execution.ScheduledSplit in project trino by trinodb.
the class HttpRemoteTask method getSplitAssignment.
private synchronized SplitAssignment getSplitAssignment(PlanNodeId planNodeId) {
Set<ScheduledSplit> splits = pendingSplits.get(planNodeId);
boolean pendingNoMoreSplits = Boolean.TRUE.equals(this.noMoreSplits.get(planNodeId));
boolean noMoreSplits = this.noMoreSplits.containsKey(planNodeId);
Set<Lifespan> noMoreSplitsForLifespan = pendingNoMoreSplitsForLifespan.get(planNodeId);
SplitAssignment assignment = null;
if (!splits.isEmpty() || !noMoreSplitsForLifespan.isEmpty() || pendingNoMoreSplits) {
assignment = new SplitAssignment(planNodeId, splits, noMoreSplitsForLifespan, noMoreSplits);
}
return assignment;
}
use of io.trino.execution.ScheduledSplit in project trino by trinodb.
the class Driver method processNewSources.
@GuardedBy("exclusiveLock")
private void processNewSources() {
checkLockHeld("Lock must be held to call processNewSources");
// only update if the driver is still alive
if (state.get() != State.ALIVE) {
return;
}
SplitAssignment splitAssignment = pendingSplitAssignmentUpdates.getAndSet(null);
if (splitAssignment == null) {
return;
}
// merge the current assignment and the specified assignment
SplitAssignment newAssignment = currentSplitAssignment.update(splitAssignment);
// if the update contains no new data, just return
if (newAssignment == currentSplitAssignment) {
return;
}
// determine new splits to add
Set<ScheduledSplit> newSplits = Sets.difference(newAssignment.getSplits(), currentSplitAssignment.getSplits());
// add new splits
SourceOperator sourceOperator = this.sourceOperator.orElseThrow(VerifyException::new);
for (ScheduledSplit newSplit : newSplits) {
Split split = newSplit.getSplit();
Supplier<Optional<UpdatablePageSource>> pageSource = sourceOperator.addSplit(split);
deleteOperator.ifPresent(deleteOperator -> deleteOperator.setPageSource(pageSource));
updateOperator.ifPresent(updateOperator -> updateOperator.setPageSource(pageSource));
}
// set no more splits
if (newAssignment.isNoMoreSplits()) {
sourceOperator.noMoreSplits();
}
currentSplitAssignment = newAssignment;
}
use of io.trino.execution.ScheduledSplit in project trino by trinodb.
the class TestMemoryBlocking method testTableScanMemoryBlocking.
@Test
public void testTableScanMemoryBlocking() {
PlanNodeId sourceId = new PlanNodeId("source");
List<Type> types = ImmutableList.of(VARCHAR);
TableScanOperator source = new TableScanOperator(driverContext.addOperatorContext(1, new PlanNodeId("test"), "values"), sourceId, (session, split, table, columns, dynamicFilter) -> new FixedPageSource(rowPagesBuilder(types).addSequencePage(10, 1).addSequencePage(10, 1).addSequencePage(10, 1).addSequencePage(10, 1).addSequencePage(10, 1).build()), TEST_TABLE_HANDLE, ImmutableList.of(), DynamicFilter.EMPTY);
PageConsumerOperator sink = createSinkOperator(types);
Driver driver = Driver.createDriver(driverContext, source, sink);
assertSame(driver.getDriverContext(), driverContext);
assertFalse(driver.isFinished());
Split testSplit = new Split(new CatalogName("test"), new TestSplit(), Lifespan.taskWide());
driver.updateSplitAssignment(new SplitAssignment(sourceId, ImmutableSet.of(new ScheduledSplit(0, sourceId, testSplit)), true));
ListenableFuture<Void> blocked = driver.processFor(new Duration(1, NANOSECONDS));
// the driver shouldn't block in the first call as it will be able to move a page between source and the sink operator
// but the operator should be blocked
assertTrue(blocked.isDone());
assertFalse(source.getOperatorContext().isWaitingForMemory().isDone());
// and they should stay blocked until more memory becomes available
for (int i = 0; i < 10; i++) {
blocked = driver.processFor(new Duration(1, NANOSECONDS));
assertFalse(blocked.isDone());
assertFalse(source.getOperatorContext().isWaitingForMemory().isDone());
}
// free up some memory
memoryPool.free(QUERY_ID, "test", memoryPool.getReservedBytes());
// the operator should be unblocked
assertTrue(source.getOperatorContext().isWaitingForMemory().isDone());
// the driver shouldn't be blocked
blocked = driver.processFor(new Duration(1, NANOSECONDS));
assertTrue(blocked.isDone());
}
use of io.trino.execution.ScheduledSplit in project trino by trinodb.
the class HttpRemoteTask method processTaskUpdate.
private synchronized void processTaskUpdate(TaskInfo newValue, List<SplitAssignment> splitAssignments) {
updateTaskInfo(newValue);
// remove acknowledged splits, which frees memory
for (SplitAssignment assignment : splitAssignments) {
PlanNodeId planNodeId = assignment.getPlanNodeId();
boolean isPartitionedSource = planFragment.isPartitionedSources(planNodeId);
int removed = 0;
long removedWeight = 0;
for (ScheduledSplit split : assignment.getSplits()) {
if (pendingSplits.remove(planNodeId, split)) {
if (isPartitionedSource) {
removed++;
removedWeight = addExact(removedWeight, split.getSplit().getSplitWeight().getRawValue());
}
}
}
if (assignment.isNoMoreSplits()) {
noMoreSplits.put(planNodeId, false);
}
for (Lifespan lifespan : assignment.getNoMoreSplitsForLifespan()) {
pendingNoMoreSplitsForLifespan.remove(planNodeId, lifespan);
}
if (isPartitionedSource) {
pendingSourceSplitCount -= removed;
pendingSourceSplitsWeight -= removedWeight;
}
}
// Update node level split tracker before split queue space to ensure it's up to date before waking up the scheduler
partitionedSplitCountTracker.setPartitionedSplits(getPartitionedSplitsInfo());
updateSplitQueueSpace();
}
use of io.trino.execution.ScheduledSplit in project trino by trinodb.
the class HttpRemoteTask method addSplits.
@Override
public synchronized void addSplits(Multimap<PlanNodeId, Split> splitsBySource) {
requireNonNull(splitsBySource, "splitsBySource is null");
// only add pending split if not done
if (getTaskStatus().getState().isDone()) {
return;
}
boolean needsUpdate = false;
for (Entry<PlanNodeId, Collection<Split>> entry : splitsBySource.asMap().entrySet()) {
PlanNodeId sourceId = entry.getKey();
Collection<Split> splits = entry.getValue();
boolean isPartitionedSource = planFragment.isPartitionedSources(sourceId);
checkState(!noMoreSplits.containsKey(sourceId), "noMoreSplits has already been set for %s", sourceId);
int added = 0;
long addedWeight = 0;
for (Split split : splits) {
if (pendingSplits.put(sourceId, new ScheduledSplit(nextSplitId.getAndIncrement(), sourceId, split))) {
if (isPartitionedSource) {
added++;
addedWeight = addExact(addedWeight, split.getSplitWeight().getRawValue());
}
}
}
if (isPartitionedSource) {
pendingSourceSplitCount += added;
pendingSourceSplitsWeight = addExact(pendingSourceSplitsWeight, addedWeight);
partitionedSplitCountTracker.setPartitionedSplits(getPartitionedSplitsInfo());
}
needsUpdate = true;
}
updateSplitQueueSpace();
if (needsUpdate) {
triggerUpdate();
}
}
Aggregations