Search in sources :

Example 1 with IPartition

use of org.apache.hyracks.api.partitions.IPartition in project asterixdb by apache.

the class PartitionManager method unregisterPartitions.

public synchronized void unregisterPartitions(JobId jobId, Collection<IPartition> unregisteredPartitions) {
    for (Iterator<Map.Entry<PartitionId, List<IPartition>>> i = availablePartitionMap.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry<PartitionId, List<IPartition>> e = i.next();
        PartitionId pid = e.getKey();
        if (jobId.equals(pid.getJobId())) {
            for (IPartition p : e.getValue()) {
                unregisteredPartitions.add(p);
            }
            i.remove();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) PartitionId(org.apache.hyracks.api.partitions.PartitionId) IPartition(org.apache.hyracks.api.partitions.IPartition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with IPartition

use of org.apache.hyracks.api.partitions.IPartition in project asterixdb by apache.

the class PartitionManager method registerPartitionRequest.

public synchronized void registerPartitionRequest(PartitionId partitionId, NetworkOutputChannel writer) throws HyracksException {
    try {
        List<IPartition> pList = availablePartitionMap.get(partitionId);
        if (pList != null && !pList.isEmpty()) {
            IPartition partition = pList.get(0);
            writer.setFrameSize(partition.getTaskContext().getInitialFrameSize());
            partition.writeTo(writer);
            if (!partition.isReusable()) {
                availablePartitionMap.remove(partitionId);
            }
        } else {
            //throw new HyracksException("Request for unknown partition " + partitionId);
            partitionRequests.put(partitionId, writer);
        }
    } catch (Exception e) {
        throw new HyracksDataException(e);
    }
}
Also used : IPartition(org.apache.hyracks.api.partitions.IPartition) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HyracksException(org.apache.hyracks.api.exceptions.HyracksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 3 with IPartition

use of org.apache.hyracks.api.partitions.IPartition in project asterixdb by apache.

the class PartitionManager method registerPartition.

public synchronized void registerPartition(PartitionId pid, TaskAttemptId taId, IPartition partition, PartitionState state, boolean updateToCC) throws HyracksDataException {
    try {
        /**
             * process pending requests
             */
        NetworkOutputChannel writer = partitionRequests.remove(pid);
        if (writer != null) {
            writer.setFrameSize(partition.getTaskContext().getInitialFrameSize());
            partition.writeTo(writer);
            if (!partition.isReusable()) {
                return;
            }
        }
        /**
             * put a coming available partition into the available partition map
             */
        List<IPartition> pList = availablePartitionMap.get(pid);
        if (pList == null) {
            pList = new ArrayList<>();
            availablePartitionMap.put(pid, pList);
        }
        pList.add(partition);
        /**
             * update to CC only when necessary
             */
        if (updateToCC) {
            updatePartitionState(pid, taId, partition, state);
        }
    } catch (Exception e) {
        throw new HyracksDataException(e);
    }
}
Also used : NetworkOutputChannel(org.apache.hyracks.comm.channels.NetworkOutputChannel) IPartition(org.apache.hyracks.api.partitions.IPartition) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HyracksException(org.apache.hyracks.api.exceptions.HyracksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 4 with IPartition

use of org.apache.hyracks.api.partitions.IPartition in project asterixdb by apache.

the class CleanupJobletWork method run.

@Override
public void run() {
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("Cleaning up after job: " + jobId);
    }
    final List<IPartition> unregisteredPartitions = new ArrayList<IPartition>();
    ncs.getPartitionManager().unregisterPartitions(jobId, unregisteredPartitions);
    ncs.getExecutor().execute(new Runnable() {

        @Override
        public void run() {
            for (IPartition p : unregisteredPartitions) {
                try {
                    // Put deallocate in a try block to make sure that every IPartition is de-allocated.
                    p.deallocate();
                } catch (Exception e) {
                    if (LOGGER.isLoggable(Level.WARNING)) {
                        LOGGER.log(Level.WARNING, e.getMessage(), e);
                    }
                }
            }
        }
    });
    Map<JobId, Joblet> jobletMap = ncs.getJobletMap();
    Joblet joblet = jobletMap.remove(jobId);
    if (joblet != null) {
        joblet.cleanup(status);
    }
}
Also used : ArrayList(java.util.ArrayList) IPartition(org.apache.hyracks.api.partitions.IPartition) JobId(org.apache.hyracks.api.job.JobId) Joblet(org.apache.hyracks.control.nc.Joblet)

Example 5 with IPartition

use of org.apache.hyracks.api.partitions.IPartition in project asterixdb by apache.

the class MaterializedPartitionInputChannel method open.

@Override
public void open(IHyracksCommonContext ctx) throws HyracksDataException {
    for (int i = 0; i < nBuffers; ++i) {
        emptyQueue.add(ctx.allocateFrame());
    }
    IPartition partition = manager.getPartition(pid);
    partition.writeTo(writer);
}
Also used : IPartition(org.apache.hyracks.api.partitions.IPartition)

Aggregations

IPartition (org.apache.hyracks.api.partitions.IPartition)5 ArrayList (java.util.ArrayList)2 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)2 HyracksException (org.apache.hyracks.api.exceptions.HyracksException)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 JobId (org.apache.hyracks.api.job.JobId)1 PartitionId (org.apache.hyracks.api.partitions.PartitionId)1 NetworkOutputChannel (org.apache.hyracks.comm.channels.NetworkOutputChannel)1 Joblet (org.apache.hyracks.control.nc.Joblet)1