use of com.twitter.heron.common.utils.tuple.TupleImpl in project heron by twitter.
the class BoltOutputCollectorImpl method admitFailTuple.
private void admitFailTuple(Tuple tuple) {
long latency = 0;
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 = System.nanoTime() - tuplImpl.getCreationTime();
}
}
// Invoke user-defined boltFail task hook
helper.getTopologyContext().invokeHookBoltFail(tuple, latency);
boltMetrics.failedTuple(tuple.getSourceStreamId(), tuple.getSourceComponent(), latency);
}
use of com.twitter.heron.common.utils.tuple.TupleImpl in project heron by twitter.
the class BoltInstance method handleDataTuple.
private void handleDataTuple(HeronTuples.HeronDataTuple dataTuple, TopologyAPI.StreamId stream) {
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);
long deserializedTime = System.nanoTime();
// Delegate to the use defined bolt
bolt.execute(t);
long executeLatency = System.nanoTime() - 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);
}
use of com.twitter.heron.common.utils.tuple.TupleImpl in project heron by twitter.
the class BoltOutputCollectorImpl method admitBoltTuple.
/////////////////////////////////////////////////////////
// Following private methods are internal implementations
/////////////////////////////////////////////////////////
private List<Integer> admitBoltTuple(String streamId, Collection<Tuple> anchors, List<Object> tuple) {
// First check whether this tuple is sane
helper.checkOutputSchema(streamId, tuple);
// customGroupingTargetTaskIds will be null if this stream is not CustomStreamGrouping
List<Integer> customGroupingTargetTaskIds = helper.chooseTasksForCustomStreamGrouping(streamId, tuple);
// Invoke user-defined emit task hook
helper.getTopologyContext().invokeHookEmit(tuple, streamId, customGroupingTargetTaskIds);
// Start construct the data tuple
HeronTuples.HeronDataTuple.Builder bldr = HeronTuples.HeronDataTuple.newBuilder();
// set the key. This is mostly ignored
bldr.setKey(0);
if (customGroupingTargetTaskIds != null) {
// It is a CustomStreamGrouping
for (Integer taskId : customGroupingTargetTaskIds) {
bldr.addDestTaskIds(taskId);
}
}
// Set the anchors for a tuple
if (anchors != null) {
// This message is rooted
Set<HeronTuples.RootId> mergedRoots = new HashSet<HeronTuples.RootId>();
for (Tuple tpl : anchors) {
if (tpl instanceof TupleImpl) {
TupleImpl t = (TupleImpl) tpl;
mergedRoots.addAll(t.getRoots());
}
}
for (HeronTuples.RootId rt : mergedRoots) {
bldr.addRoots(rt);
}
}
long tupleSizeInBytes = 0;
long startTime = System.nanoTime();
// Serialize it
for (Object obj : tuple) {
byte[] b = serializer.serialize(obj);
ByteString bstr = ByteString.copyFrom(b);
bldr.addValues(bstr);
tupleSizeInBytes += b.length;
}
long latency = System.nanoTime() - startTime;
boltMetrics.serializeDataTuple(streamId, latency);
// submit to outputter
outputter.addDataTuple(streamId, bldr, tupleSizeInBytes);
// Update metrics
boltMetrics.emittedTuple(streamId);
// TODO:- remove this after changing the api
return null;
}
use of com.twitter.heron.common.utils.tuple.TupleImpl in project heron by twitter.
the class BoltOutputCollectorImpl method admitFailTuple.
private void admitFailTuple(Tuple tuple) {
if (tuple instanceof TupleImpl) {
TupleImpl tuplImpl = (TupleImpl) tuple;
if (ackEnabled) {
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);
}
long latency = System.nanoTime() - tuplImpl.getCreationTime();
// Invoke user-defined boltFail task hook
helper.getTopologyContext().invokeHookBoltFail(tuple, latency);
boltMetrics.failedTuple(tuple.getSourceStreamId(), tuple.getSourceComponent(), latency);
}
}
use of com.twitter.heron.common.utils.tuple.TupleImpl in project incubator-heron by apache.
the class BoltOutputCollectorImpl method admitBoltTuple.
// ///////////////////////////////////////////////////////
// Following private methods are internal implementations
// ///////////////////////////////////////////////////////
private List<Integer> admitBoltTuple(String streamId, Collection<Tuple> anchors, List<Object> tuple, Integer emitDirectTaskId) {
if (getPhysicalPlanHelper().isTerminatedComponent()) {
// No need to handle this tuple
return null;
}
// Start construct the data tuple
HeronTuples.HeronDataTuple.Builder bldr = initTupleBuilder(streamId, tuple, emitDirectTaskId);
// Set the anchors for a tuple
if (anchors != null) {
// This message is rooted
Set<HeronTuples.RootId> mergedRoots = new HashSet<>();
for (Tuple tpl : anchors) {
if (tpl instanceof TupleImpl) {
TupleImpl t = (TupleImpl) tpl;
mergedRoots.addAll(t.getRoots());
}
}
for (HeronTuples.RootId rt : mergedRoots) {
bldr.addRoots(rt);
}
}
sendTuple(bldr, streamId, tuple);
// TODO:- remove this after changing the api
return null;
}
Aggregations