Search in sources :

Example 16 with DataMovementEvent

use of org.apache.tez.runtime.api.events.DataMovementEvent in project tez by apache.

the class ShuffleInputEventHandlerImpl method handleEvent.

private void handleEvent(Event event) throws IOException {
    if (event instanceof DataMovementEvent) {
        numDmeEvents.incrementAndGet();
        DataMovementEvent dmEvent = (DataMovementEvent) event;
        DataMovementEventPayloadProto shufflePayload;
        try {
            shufflePayload = DataMovementEventPayloadProto.parseFrom(ByteString.copyFrom(dmEvent.getUserPayload()));
        } catch (InvalidProtocolBufferException e) {
            throw new TezUncheckedException("Unable to parse DataMovementEvent payload", e);
        }
        BitSet emptyPartitionsBitSet = null;
        if (shufflePayload.hasEmptyPartitions()) {
            try {
                byte[] emptyPartitions = TezCommonUtils.decompressByteStringToByteArray(shufflePayload.getEmptyPartitions(), inflater);
                emptyPartitionsBitSet = TezUtilsInternal.fromByteArray(emptyPartitions);
            } catch (IOException e) {
                throw new TezUncheckedException("Unable to set the empty partition to succeeded", e);
            }
        }
        processDataMovementEvent(dmEvent, shufflePayload, emptyPartitionsBitSet);
        shuffleManager.updateEventReceivedTime();
    } else if (event instanceof CompositeRoutedDataMovementEvent) {
        CompositeRoutedDataMovementEvent crdme = (CompositeRoutedDataMovementEvent) event;
        DataMovementEventPayloadProto shufflePayload;
        try {
            shufflePayload = DataMovementEventPayloadProto.parseFrom(ByteString.copyFrom(crdme.getUserPayload()));
        } catch (InvalidProtocolBufferException e) {
            throw new TezUncheckedException("Unable to parse DataMovementEvent payload", e);
        }
        BitSet emptyPartitionsBitSet = null;
        if (shufflePayload.hasEmptyPartitions()) {
            try {
                byte[] emptyPartitions = TezCommonUtils.decompressByteStringToByteArray(shufflePayload.getEmptyPartitions(), inflater);
                emptyPartitionsBitSet = TezUtilsInternal.fromByteArray(emptyPartitions);
            } catch (IOException e) {
                throw new TezUncheckedException("Unable to set the empty partition to succeeded", e);
            }
        }
        if (compositeFetch) {
            numDmeEvents.addAndGet(crdme.getCount());
            processCompositeRoutedDataMovementEvent(crdme, shufflePayload, emptyPartitionsBitSet);
        } else {
            for (int offset = 0; offset < crdme.getCount(); offset++) {
                numDmeEvents.incrementAndGet();
                processDataMovementEvent(crdme.expand(offset), shufflePayload, emptyPartitionsBitSet);
            }
        }
        shuffleManager.updateEventReceivedTime();
    } else if (event instanceof InputFailedEvent) {
        numObsoletionEvents.incrementAndGet();
        processInputFailedEvent((InputFailedEvent) event);
    } else {
        throw new TezUncheckedException("Unexpected event type: " + event.getClass().getName());
    }
    if (numDmeEvents.get() + numObsoletionEvents.get() > nextToLogEventCount.get()) {
        logProgress(false);
        // Log every 50 events seen.
        nextToLogEventCount.addAndGet(50);
    }
}
Also used : InputFailedEvent(org.apache.tez.runtime.api.events.InputFailedEvent) TezUncheckedException(org.apache.tez.dag.api.TezUncheckedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) BitSet(java.util.BitSet) DataMovementEventPayloadProto(org.apache.tez.runtime.library.shuffle.impl.ShuffleUserPayloads.DataMovementEventPayloadProto) CompositeRoutedDataMovementEvent(org.apache.tez.runtime.api.events.CompositeRoutedDataMovementEvent) DataMovementEvent(org.apache.tez.runtime.api.events.DataMovementEvent) IOException(java.io.IOException) CompositeRoutedDataMovementEvent(org.apache.tez.runtime.api.events.CompositeRoutedDataMovementEvent)

Example 17 with DataMovementEvent

use of org.apache.tez.runtime.api.events.DataMovementEvent in project tez by apache.

the class TezEvent method serializeEvent.

private void serializeEvent(DataOutput out) throws IOException {
    if (event == null) {
        out.writeBoolean(false);
        return;
    }
    out.writeBoolean(true);
    out.writeInt(eventType.ordinal());
    out.writeLong(eventReceivedTime);
    if (eventType.equals(EventType.TASK_STATUS_UPDATE_EVENT)) {
        // TODO NEWTEZ convert to PB
        TaskStatusUpdateEvent sEvt = (TaskStatusUpdateEvent) event;
        sEvt.write(out);
    } else {
        AbstractMessage message;
        switch(eventType) {
            case CUSTOM_PROCESSOR_EVENT:
                message = ProtoConverters.convertCustomProcessorEventToProto((CustomProcessorEvent) event);
                break;
            case DATA_MOVEMENT_EVENT:
                message = ProtoConverters.convertDataMovementEventToProto((DataMovementEvent) event);
                break;
            case COMPOSITE_ROUTED_DATA_MOVEMENT_EVENT:
                message = ProtoConverters.convertCompositeRoutedDataMovementEventToProto((CompositeRoutedDataMovementEvent) event);
                break;
            case COMPOSITE_DATA_MOVEMENT_EVENT:
                message = ProtoConverters.convertCompositeDataMovementEventToProto((CompositeDataMovementEvent) event);
                break;
            case VERTEX_MANAGER_EVENT:
                message = ProtoConverters.convertVertexManagerEventToProto((VertexManagerEvent) event);
                break;
            case INPUT_READ_ERROR_EVENT:
                InputReadErrorEvent ideEvt = (InputReadErrorEvent) event;
                message = InputReadErrorEventProto.newBuilder().setIndex(ideEvt.getIndex()).setDiagnostics(ideEvt.getDiagnostics()).setVersion(ideEvt.getVersion()).build();
                break;
            case TASK_ATTEMPT_FAILED_EVENT:
                TaskAttemptFailedEvent tfEvt = (TaskAttemptFailedEvent) event;
                message = TaskAttemptFailedEventProto.newBuilder().setDiagnostics(tfEvt.getDiagnostics()).setTaskFailureType(TezConverterUtils.failureTypeToProto(tfEvt.getTaskFailureType())).build();
                break;
            case TASK_ATTEMPT_KILLED_EVENT:
                TaskAttemptKilledEvent tkEvent = (TaskAttemptKilledEvent) event;
                message = TaskAttemptKilledEventProto.newBuilder().setDiagnostics(tkEvent.getDiagnostics()).build();
                break;
            case TASK_ATTEMPT_COMPLETED_EVENT:
                message = TaskAttemptCompletedEventProto.newBuilder().build();
                break;
            case INPUT_FAILED_EVENT:
                InputFailedEvent ifEvt = (InputFailedEvent) event;
                message = InputFailedEventProto.newBuilder().setTargetIndex(ifEvt.getTargetIndex()).setVersion(ifEvt.getVersion()).build();
                break;
            case ROOT_INPUT_DATA_INFORMATION_EVENT:
                message = ProtoConverters.convertRootInputDataInformationEventToProto((InputDataInformationEvent) event);
                break;
            case ROOT_INPUT_INITIALIZER_EVENT:
                message = ProtoConverters.convertRootInputInitializerEventToProto((InputInitializerEvent) event);
                break;
            default:
                throw new TezUncheckedException("Unknown TezEvent" + ", type=" + eventType);
        }
        if (out instanceof OutputStream) {
            // DataOutputBuffer extends DataOutputStream
            int serializedSize = message.getSerializedSize();
            out.writeInt(serializedSize);
            int buffersize = serializedSize < CodedOutputStream.DEFAULT_BUFFER_SIZE ? serializedSize : CodedOutputStream.DEFAULT_BUFFER_SIZE;
            CodedOutputStream codedOut = CodedOutputStream.newInstance((OutputStream) out, buffersize);
            message.writeTo(codedOut);
            codedOut.flush();
        } else {
            byte[] eventBytes = message.toByteArray();
            out.writeInt(eventBytes.length);
            out.write(eventBytes);
        }
    }
}
Also used : InputFailedEvent(org.apache.tez.runtime.api.events.InputFailedEvent) AbstractMessage(com.google.protobuf.AbstractMessage) TezUncheckedException(org.apache.tez.dag.api.TezUncheckedException) CodedOutputStream(com.google.protobuf.CodedOutputStream) OutputStream(java.io.OutputStream) CodedOutputStream(com.google.protobuf.CodedOutputStream) InputReadErrorEvent(org.apache.tez.runtime.api.events.InputReadErrorEvent) TaskStatusUpdateEvent(org.apache.tez.runtime.api.events.TaskStatusUpdateEvent) CompositeRoutedDataMovementEvent(org.apache.tez.runtime.api.events.CompositeRoutedDataMovementEvent) CompositeDataMovementEvent(org.apache.tez.runtime.api.events.CompositeDataMovementEvent) DataMovementEvent(org.apache.tez.runtime.api.events.DataMovementEvent) CompositeRoutedDataMovementEvent(org.apache.tez.runtime.api.events.CompositeRoutedDataMovementEvent) TaskAttemptFailedEvent(org.apache.tez.runtime.api.events.TaskAttemptFailedEvent) VertexManagerEvent(org.apache.tez.runtime.api.events.VertexManagerEvent) InputInitializerEvent(org.apache.tez.runtime.api.events.InputInitializerEvent) CompositeDataMovementEvent(org.apache.tez.runtime.api.events.CompositeDataMovementEvent) CustomProcessorEvent(org.apache.tez.runtime.api.events.CustomProcessorEvent) TaskAttemptKilledEvent(org.apache.tez.runtime.api.events.TaskAttemptKilledEvent) InputDataInformationEvent(org.apache.tez.runtime.api.events.InputDataInformationEvent)

Example 18 with DataMovementEvent

use of org.apache.tez.runtime.api.events.DataMovementEvent in project tez by apache.

the class Edge method sendTezEventToDestinationTasks.

public void sendTezEventToDestinationTasks(TezEvent tezEvent) throws AMUserCodeException {
    if (!bufferEvents.get()) {
        boolean isDataMovementEvent = true;
        switch(tezEvent.getEventType()) {
            case COMPOSITE_DATA_MOVEMENT_EVENT:
                handleCompositeDataMovementEvent(tezEvent);
                break;
            case INPUT_FAILED_EVENT:
            case DATA_MOVEMENT_EVENT:
                if (tezEvent.getEventType().equals(EventType.INPUT_FAILED_EVENT)) {
                    isDataMovementEvent = false;
                }
                Map<Integer, List<Integer>> destTaskAndInputIndices = Maps.newHashMap();
                TezTaskAttemptID srcAttemptId = tezEvent.getSourceInfo().getTaskAttemptID();
                int srcTaskIndex = srcAttemptId.getTaskID().getId();
                boolean routingRequired = routingNeeded;
                if (routingRequired) {
                    try {
                        if (isDataMovementEvent) {
                            DataMovementEvent dmEvent = (DataMovementEvent) tezEvent.getEvent();
                            edgeManager.routeDataMovementEventToDestination(dmEvent, srcTaskIndex, dmEvent.getSourceIndex(), destTaskAndInputIndices);
                        } else {
                            edgeManager.routeInputSourceTaskFailedEventToDestination(srcTaskIndex, destTaskAndInputIndices);
                        }
                    } catch (Exception e) {
                        throw new AMUserCodeException(Source.EdgeManager, "Fail to sendTezEventToDestinationTasks, event:" + tezEvent.getEvent() + ", sourceInfo:" + tezEvent.getSourceInfo() + ", destinationInfo:" + tezEvent.getDestinationInfo() + ", " + getEdgeInfo(), e);
                    }
                } else {
                    LOG.info("Not routing events since destination vertex has 0 tasks" + generateCommonDebugString(srcTaskIndex, tezEvent));
                }
                if (!destTaskAndInputIndices.isEmpty()) {
                    sendDmEventOrIfEventToTasks(tezEvent, srcTaskIndex, isDataMovementEvent, destTaskAndInputIndices);
                } else if (routingRequired) {
                    throw new TezUncheckedException("Event must be routed." + generateCommonDebugString(srcTaskIndex, tezEvent));
                }
                break;
            default:
                throw new TezUncheckedException("Unhandled tez event type: " + tezEvent.getEventType());
        }
    } else {
        destinationEventBuffer.add(tezEvent);
    }
}
Also used : TezUncheckedException(org.apache.tez.dag.api.TezUncheckedException) ArrayList(java.util.ArrayList) List(java.util.List) CompositeRoutedDataMovementEvent(org.apache.tez.runtime.api.events.CompositeRoutedDataMovementEvent) CompositeDataMovementEvent(org.apache.tez.runtime.api.events.CompositeDataMovementEvent) DataMovementEvent(org.apache.tez.runtime.api.events.DataMovementEvent) TezUncheckedException(org.apache.tez.dag.api.TezUncheckedException) TezException(org.apache.tez.dag.api.TezException) TezTaskAttemptID(org.apache.tez.dag.records.TezTaskAttemptID)

Example 19 with DataMovementEvent

use of org.apache.tez.runtime.api.events.DataMovementEvent in project tez by apache.

the class Edge method maybeAddTezEventForDestinationTask.

// return false is event could be routed but ran out of space in the list
public boolean maybeAddTezEventForDestinationTask(TezEvent tezEvent, TezTaskAttemptID attemptID, int srcTaskIndex, List<TezEvent> listToAdd, int listMaxSize, PendingEventRouteMetadata pendingRoutes) throws AMUserCodeException {
    if (!routingNeeded) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Not routing events since destination vertex has 0 tasks" + generateCommonDebugString(srcTaskIndex, tezEvent));
        }
        return true;
    } else {
        try {
            EdgeManagerPluginOnDemand edgeManagerOnDemand = (EdgeManagerPluginOnDemand) edgeManager;
            int taskIndex = attemptID.getTaskID().getId();
            switch(tezEvent.getEventType()) {
                case COMPOSITE_DATA_MOVEMENT_EVENT:
                    {
                        CompositeDataMovementEvent compEvent = (CompositeDataMovementEvent) tezEvent.getEvent();
                        CompositeEventRouteMetadata routeMeta = edgeManagerOnDemand.routeCompositeDataMovementEventToDestination(srcTaskIndex, taskIndex);
                        if (routeMeta != null) {
                            CompositeRoutedDataMovementEvent edme = compEvent.expandRouted(routeMeta);
                            TezEvent tezEventToSend = new TezEvent(edme, tezEvent.getSourceInfo(), tezEvent.getEventReceivedTime());
                            tezEventToSend.setDestinationInfo(destinationMetaInfo);
                            listToAdd.add(tezEventToSend);
                        }
                    }
                    break;
                case INPUT_FAILED_EVENT:
                    {
                        InputFailedEvent ifEvent = (InputFailedEvent) tezEvent.getEvent();
                        EventRouteMetadata routeMeta;
                        int numEventsDone;
                        if (pendingRoutes != null) {
                            routeMeta = pendingRoutes.getRouteMeta();
                            numEventsDone = pendingRoutes.getNumEventsRouted();
                        } else {
                            routeMeta = edgeManagerOnDemand.routeInputSourceTaskFailedEventToDestination(srcTaskIndex, taskIndex);
                            numEventsDone = 0;
                        }
                        if (routeMeta != null) {
                            int listSize = listToAdd.size();
                            int numEvents = routeMeta.getNumEvents();
                            int[] targetIndices = routeMeta.getTargetIndices();
                            while (numEventsDone < numEvents && listSize++ < listMaxSize) {
                                InputFailedEvent e = ifEvent.makeCopy(targetIndices[numEventsDone]);
                                numEventsDone++;
                                TezEvent tezEventToSend = new TezEvent(e, tezEvent.getSourceInfo(), tezEvent.getEventReceivedTime());
                                tezEventToSend.setDestinationInfo(destinationMetaInfo);
                                listToAdd.add(tezEventToSend);
                            }
                            if (numEventsDone < numEvents) {
                                pendingEvents.put(attemptID, new PendingEventRouteMetadata(routeMeta, tezEvent, numEventsDone));
                                return false;
                            }
                        }
                    }
                    break;
                case DATA_MOVEMENT_EVENT:
                    {
                        DataMovementEvent dmEvent = (DataMovementEvent) tezEvent.getEvent();
                        EventRouteMetadata routeMeta;
                        int numEventsDone;
                        if (pendingRoutes != null) {
                            routeMeta = pendingRoutes.getRouteMeta();
                            numEventsDone = pendingRoutes.getNumEventsRouted();
                        } else {
                            routeMeta = edgeManagerOnDemand.routeDataMovementEventToDestination(srcTaskIndex, dmEvent.getSourceIndex(), taskIndex);
                            numEventsDone = 0;
                        }
                        if (routeMeta != null) {
                            int listSize = listToAdd.size();
                            int numEvents = routeMeta.getNumEvents();
                            int[] targetIndices = routeMeta.getTargetIndices();
                            while (numEventsDone < numEvents && listSize++ < listMaxSize) {
                                DataMovementEvent e = dmEvent.makeCopy(targetIndices[numEventsDone]);
                                numEventsDone++;
                                TezEvent tezEventToSend = new TezEvent(e, tezEvent.getSourceInfo(), tezEvent.getEventReceivedTime());
                                tezEventToSend.setDestinationInfo(destinationMetaInfo);
                                listToAdd.add(tezEventToSend);
                            }
                            if (numEventsDone < numEvents) {
                                pendingEvents.put(attemptID, new PendingEventRouteMetadata(routeMeta, tezEvent, numEventsDone));
                                return false;
                            }
                        }
                    }
                    break;
                default:
                    throw new TezUncheckedException("Unhandled tez event type: " + tezEvent.getEventType());
            }
        } catch (Exception e) {
            throw new AMUserCodeException(Source.EdgeManager, "Fail to maybeAddTezEventForDestinationTask, event:" + tezEvent.getEvent() + ", sourceInfo:" + tezEvent.getSourceInfo() + ", destinationInfo:" + tezEvent.getDestinationInfo() + ", " + getEdgeInfo(), e);
        }
    }
    return true;
}
Also used : InputFailedEvent(org.apache.tez.runtime.api.events.InputFailedEvent) TezUncheckedException(org.apache.tez.dag.api.TezUncheckedException) EdgeManagerPluginOnDemand(org.apache.tez.dag.api.EdgeManagerPluginOnDemand) CompositeRoutedDataMovementEvent(org.apache.tez.runtime.api.events.CompositeRoutedDataMovementEvent) CompositeRoutedDataMovementEvent(org.apache.tez.runtime.api.events.CompositeRoutedDataMovementEvent) CompositeDataMovementEvent(org.apache.tez.runtime.api.events.CompositeDataMovementEvent) DataMovementEvent(org.apache.tez.runtime.api.events.DataMovementEvent) TezUncheckedException(org.apache.tez.dag.api.TezUncheckedException) TezException(org.apache.tez.dag.api.TezException) CompositeEventRouteMetadata(org.apache.tez.dag.api.EdgeManagerPluginOnDemand.CompositeEventRouteMetadata) CompositeDataMovementEvent(org.apache.tez.runtime.api.events.CompositeDataMovementEvent) TezEvent(org.apache.tez.runtime.api.impl.TezEvent) EventRouteMetadata(org.apache.tez.dag.api.EdgeManagerPluginOnDemand.EventRouteMetadata) CompositeEventRouteMetadata(org.apache.tez.dag.api.EdgeManagerPluginOnDemand.CompositeEventRouteMetadata)

Example 20 with DataMovementEvent

use of org.apache.tez.runtime.api.events.DataMovementEvent in project tez by apache.

the class TestInput method handleEvents.

@Override
public void handleEvents(List<Event> inputEvents) throws Exception {
    for (Event event : inputEvents) {
        if (event instanceof DataMovementEvent) {
            DataMovementEvent dmEvent = (DataMovementEvent) event;
            numCompletedInputs++;
            LOG.info(getContext().getSourceVertexName() + " Received DataMovement event sourceId : " + dmEvent.getSourceIndex() + " targetId: " + dmEvent.getTargetIndex() + " version: " + dmEvent.getVersion() + " numInputs: " + getNumPhysicalInputs() + " numCompletedInputs: " + numCompletedInputs);
            this.completedInputVersion[dmEvent.getTargetIndex()] = dmEvent.getVersion();
            this.inputValues[dmEvent.getTargetIndex()] = dmEvent.getUserPayload().getInt();
        } else if (event instanceof InputFailedEvent) {
            InputFailedEvent ifEvent = (InputFailedEvent) event;
            if (this.completedInputVersion[ifEvent.getTargetIndex()] == ifEvent.getVersion()) {
                numCompletedInputs--;
            }
            LOG.info("Received InputFailed event targetId: " + ifEvent.getTargetIndex() + " version: " + ifEvent.getVersion() + " numInputs: " + getNumPhysicalInputs() + " numCompletedInputs: " + numCompletedInputs);
        }
    }
    if (numCompletedInputs == getNumPhysicalInputs()) {
        int maxInputVersionSeen = -1;
        for (int i = 0; i < getNumPhysicalInputs(); ++i) {
            if (completedInputVersion[i] < 0) {
                LOG.info("Not received completion for input " + i);
                return;
            } else if (maxInputVersionSeen < completedInputVersion[i]) {
                maxInputVersionSeen = completedInputVersion[i];
            }
        }
        LOG.info("Received all inputs");
        synchronized (inputReady) {
            inputReady.set(maxInputVersionSeen);
            LOG.info("Notifying done with " + maxInputVersionSeen);
            inputReady.notifyAll();
        }
    }
}
Also used : InputFailedEvent(org.apache.tez.runtime.api.events.InputFailedEvent) InputFailedEvent(org.apache.tez.runtime.api.events.InputFailedEvent) InputReadErrorEvent(org.apache.tez.runtime.api.events.InputReadErrorEvent) DataMovementEvent(org.apache.tez.runtime.api.events.DataMovementEvent) Event(org.apache.tez.runtime.api.Event) DataMovementEvent(org.apache.tez.runtime.api.events.DataMovementEvent)

Aggregations

DataMovementEvent (org.apache.tez.runtime.api.events.DataMovementEvent)22 CompositeDataMovementEvent (org.apache.tez.runtime.api.events.CompositeDataMovementEvent)14 TezEvent (org.apache.tez.runtime.api.impl.TezEvent)10 Test (org.junit.Test)10 CompositeRoutedDataMovementEvent (org.apache.tez.runtime.api.events.CompositeRoutedDataMovementEvent)8 TezUncheckedException (org.apache.tez.dag.api.TezUncheckedException)6 EventMetaData (org.apache.tez.runtime.api.impl.EventMetaData)6 Task (org.apache.tez.dag.app.dag.Task)5 Event (org.apache.tez.runtime.api.Event)5 InputFailedEvent (org.apache.tez.runtime.api.events.InputFailedEvent)5 ByteBuffer (java.nio.ByteBuffer)4 ArrayList (java.util.ArrayList)4 BitSet (java.util.BitSet)4 List (java.util.List)4 ByteString (com.google.protobuf.ByteString)3 StateChangeNotifierForTest (org.apache.tez.dag.app.dag.TestStateChangeNotifier.StateChangeNotifierForTest)3 VertexEventRouteEvent (org.apache.tez.dag.app.dag.event.VertexEventRouteEvent)3 TezTaskAttemptID (org.apache.tez.dag.records.TezTaskAttemptID)3 VertexManagerEvent (org.apache.tez.runtime.api.events.VertexManagerEvent)3 DataMovementEventPayloadProto (org.apache.tez.runtime.library.shuffle.impl.ShuffleUserPayloads.DataMovementEventPayloadProto)3