Search in sources :

Example 11 with TupleImpl

use of com.twitter.heron.common.utils.tuple.TupleImpl in project incubator-heron by apache.

the class BoltOutputCollectorImpl method admitFailTuple.

private void admitFailTuple(Tuple tuple) {
    Duration latency = Duration.ZERO;
    if (ackEnabled) {
        if (tuple instanceof TupleImpl) {
            TupleImpl tuplImpl = (TupleImpl) tuple;
            HeronTuples.AckTuple.Builder bldr = HeronTuples.AckTuple.newBuilder();
            bldr.setAckedtuple(tuplImpl.getTupleKey());
            long tupleSizeInBytes = 0;
            for (HeronTuples.RootId rt : tuplImpl.getRoots()) {
                bldr.addRoots(rt);
                tupleSizeInBytes += rt.getSerializedSize();
            }
            outputter.addFailTuple(bldr, tupleSizeInBytes);
            latency = Duration.ofNanos(System.nanoTime()).minusNanos(tuplImpl.getCreationTime());
        }
    }
    // Invoke user-defined boltFail task hook
    getPhysicalPlanHelper().getTopologyContext().invokeHookBoltFail(tuple, latency);
    boltMetrics.failedTuple(tuple.getSourceStreamId(), tuple.getSourceComponent(), latency.toNanos());
}
Also used : Duration(java.time.Duration) TupleImpl(com.twitter.heron.common.utils.tuple.TupleImpl) HeronTuples(com.twitter.heron.proto.system.HeronTuples)

Example 12 with TupleImpl

use of com.twitter.heron.common.utils.tuple.TupleImpl in project incubator-heron by apache.

the class BoltInstance method readTuplesAndExecute.

@Override
public void readTuplesAndExecute(Communicator<Message> inQueue) {
    TopologyContextImpl topologyContext = helper.getTopologyContext();
    Duration instanceExecuteBatchTime = systemConfig.getInstanceExecuteBatchTime();
    long startOfCycle = System.nanoTime();
    // Read data from in Queues
    while (!inQueue.isEmpty()) {
        Message msg = inQueue.poll();
        if (msg instanceof CheckpointManager.InitiateStatefulCheckpoint) {
            String checkpointId = ((CheckpointManager.InitiateStatefulCheckpoint) msg).getCheckpointId();
            persistState(checkpointId);
        }
        if (msg instanceof HeronTuples.HeronTupleSet) {
            HeronTuples.HeronTupleSet tuples = (HeronTuples.HeronTupleSet) msg;
            // Handle the tuples
            if (tuples.hasControl()) {
                throw new RuntimeException("Bolt cannot get acks/fails from other components");
            }
            // Get meta data of tuples
            TopologyAPI.StreamId stream = tuples.getData().getStream();
            int nValues = topologyContext.getComponentOutputFields(stream.getComponentName(), stream.getId()).size();
            int sourceTaskId = tuples.getSrcTaskId();
            for (HeronTuples.HeronDataTuple dataTuple : tuples.getData().getTuplesList()) {
                long startExecuteTuple = System.nanoTime();
                // Create the value list and fill the value
                List<Object> values = new ArrayList<>(nValues);
                for (int i = 0; i < nValues; i++) {
                    values.add(serializer.deserialize(dataTuple.getValues(i).toByteArray()));
                }
                // Decode the tuple
                TupleImpl t = new TupleImpl(topologyContext, stream, dataTuple.getKey(), dataTuple.getRootsList(), values, startExecuteTuple, false, sourceTaskId);
                // Delegate to the use defined bolt
                bolt.execute(t);
                // record the end of a tuple execution
                long endExecuteTuple = System.nanoTime();
                long executeLatency = endExecuteTuple - startExecuteTuple;
                // Invoke user-defined execute task hook
                topologyContext.invokeHookBoltExecute(t, Duration.ofNanos(executeLatency));
                // Update metrics
                boltMetrics.executeTuple(stream.getId(), stream.getComponentName(), executeLatency);
            }
            // To avoid spending too much time
            long currentTime = System.nanoTime();
            if (currentTime - startOfCycle - instanceExecuteBatchTime.toNanos() > 0) {
                break;
            }
        }
    }
}
Also used : Message(com.google.protobuf.Message) TopologyContextImpl(com.twitter.heron.common.utils.topology.TopologyContextImpl) ArrayList(java.util.ArrayList) Duration(java.time.Duration) HeronTuples(com.twitter.heron.proto.system.HeronTuples) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) TupleImpl(com.twitter.heron.common.utils.tuple.TupleImpl)

Example 13 with TupleImpl

use of com.twitter.heron.common.utils.tuple.TupleImpl in project incubator-heron by apache.

the class BoltInstance method handleDataTuple.

private void handleDataTuple(HeronTuples.HeronDataTuple dataTuple, TopologyAPI.StreamId stream, int srcTaskId) {
    long startTime = System.nanoTime();
    List<Object> values = new ArrayList<>();
    for (ByteString b : dataTuple.getValuesList()) {
        values.add(serializer.deserialize(b.toByteArray()));
    }
    // Decode the tuple
    TupleImpl t = new TupleImpl(helper.getTopologyContext(), stream, dataTuple.getKey(), dataTuple.getRootsList(), values, srcTaskId);
    long deserializedTime = System.nanoTime();
    // Delegate to the use defined bolt
    bolt.execute(t);
    Duration executeLatency = Duration.ofNanos(System.nanoTime()).minusNanos(deserializedTime);
    // Invoke user-defined execute task hook
    helper.getTopologyContext().invokeHookBoltExecute(t, executeLatency);
    boltMetrics.deserializeDataTuple(stream.getId(), stream.getComponentName(), deserializedTime - startTime);
    // Update metrics
    boltMetrics.executeTuple(stream.getId(), stream.getComponentName(), executeLatency.toNanos());
}
Also used : ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) Duration(java.time.Duration) TupleImpl(com.twitter.heron.common.utils.tuple.TupleImpl)

Aggregations

TupleImpl (com.twitter.heron.common.utils.tuple.TupleImpl)13 HeronTuples (com.twitter.heron.proto.system.HeronTuples)11 ByteString (com.google.protobuf.ByteString)4 Duration (java.time.Duration)4 ArrayList (java.util.ArrayList)4 Tuple (com.twitter.heron.api.tuple.Tuple)3 HashSet (java.util.HashSet)3 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)2 TopologyContextImpl (com.twitter.heron.common.utils.topology.TopologyContextImpl)2 Message (com.google.protobuf.Message)1