Search in sources :

Example 11 with FailedException

use of backtype.storm.topology.FailedException in project jstorm by alibaba.

the class CoordinatedBolt method handlePrepareCommit.

public void handlePrepareCommit(Tuple tuple) {
    basicCollector.setContext(tuple);
    try {
        BatchId id = (BatchId) tuple.getValue(0);
        ((IPrepareCommit) delegate).prepareCommit(id, basicCollector);
        collector.ack(tuple);
    } catch (FailedException e) {
        if (e instanceof ReportedFailedException) {
            collector.reportError(e);
        }
        collector.fail(tuple);
    }
}
Also used : IPrepareCommit(com.alibaba.jstorm.batch.IPrepareCommit) ReportedFailedException(backtype.storm.topology.ReportedFailedException) FailedException(backtype.storm.topology.FailedException) ReportedFailedException(backtype.storm.topology.ReportedFailedException) BatchId(com.alibaba.jstorm.batch.BatchId)

Example 12 with FailedException

use of backtype.storm.topology.FailedException in project jstorm by alibaba.

the class TridentBoltExecutor method execute.

@Override
public void execute(Tuple tuple) {
    if (TupleUtils.isTick(tuple)) {
        long now = System.currentTimeMillis();
        if (now - _lastRotate > _messageTimeoutMs) {
            _batches.rotate();
            _lastRotate = now;
        }
        return;
    }
    String batchGroup = _batchGroupIds.get(tuple.getSourceGlobalStreamid());
    if (batchGroup == null) {
        // this is so we can do things like have simple DRPC that doesn't need to use batch processing
        _coordCollector.setCurrBatch(null);
        _bolt.execute(null, tuple);
        _collector.ack(tuple);
        return;
    }
    IBatchID id = (IBatchID) tuple.getValue(0);
    //get transaction id
    //if it already exissts and attempt id is greater than the attempt there
    TrackedBatch tracked = (TrackedBatch) _batches.get(id.getId());
    // failures happen you don't get an explosion in memory usage in the tasks
    if (tracked != null) {
        if (id.getAttemptId() > tracked.attemptId) {
            _batches.remove(id.getId());
            tracked = null;
        } else if (id.getAttemptId() < tracked.attemptId) {
            // no reason to try to execute a previous attempt than we've already seen
            return;
        }
    }
    if (tracked == null) {
        tracked = new TrackedBatch(new BatchInfo(batchGroup, id, _bolt.initBatchState(batchGroup, id)), _coordConditions.get(batchGroup), id.getAttemptId());
        _batches.put(id.getId(), tracked);
    }
    _coordCollector.setCurrBatch(tracked);
    //System.out.println("TRACKED: " + tracked + " " + tuple);
    TupleType t = getTupleType(tuple, tracked);
    if (t == TupleType.COMMIT) {
        tracked.receivedCommit = true;
        checkFinish(tracked, tuple, t);
    } else if (t == TupleType.COORD) {
        int count = tuple.getInteger(1);
        tracked.reportedTasks++;
        tracked.expectedTupleCount += count;
        checkFinish(tracked, tuple, t);
    } else {
        tracked.receivedTuples++;
        boolean success = true;
        try {
            _bolt.execute(tracked.info, tuple);
            if (tracked.condition.expectedTaskReports == 0) {
                success = finishBatch(tracked, tuple);
            }
        } catch (FailedException e) {
            failBatch(tracked, e);
        }
        if (success) {
            _collector.ack(tuple);
        } else {
            _collector.fail(tuple);
        }
    }
    _coordCollector.setCurrBatch(null);
}
Also used : IBatchID(storm.trident.spout.IBatchID) FailedException(backtype.storm.topology.FailedException) ReportedFailedException(backtype.storm.topology.ReportedFailedException)

Example 13 with FailedException

use of backtype.storm.topology.FailedException in project jstorm by alibaba.

the class TridentBoltExecutor method finishBatch.

private boolean finishBatch(TrackedBatch tracked, Tuple finishTuple) {
    boolean success = true;
    try {
        _bolt.finishBatch(tracked.info);
        String stream = COORD_STREAM(tracked.info.batchGroup);
        _collector.flush();
        for (Integer task : tracked.condition.targetTasks) {
            _collector.emitDirect(task, stream, finishTuple, new Values(tracked.info.batchId, Utils.get(tracked.taskEmittedTuples, task, 0)));
        }
        if (tracked.delayedAck != null) {
            _collector.ack(tracked.delayedAck);
            tracked.delayedAck = null;
        }
    } catch (FailedException e) {
        failBatch(tracked, e);
        success = false;
    }
    _batches.remove(tracked.info.batchId.getId());
    return success;
}
Also used : FailedException(backtype.storm.topology.FailedException) ReportedFailedException(backtype.storm.topology.ReportedFailedException) Values(backtype.storm.tuple.Values)

Example 14 with FailedException

use of backtype.storm.topology.FailedException in project storm by nathanmarz.

the class TridentBoltExecutor method finishBatch.

private boolean finishBatch(TrackedBatch tracked, Tuple finishTuple) {
    boolean success = true;
    try {
        _bolt.finishBatch(tracked.info);
        String stream = COORD_STREAM(tracked.info.batchGroup);
        for (Integer task : tracked.condition.targetTasks) {
            _collector.emitDirect(task, stream, finishTuple, new Values(tracked.info.batchId, Utils.get(tracked.taskEmittedTuples, task, 0)));
        }
        if (tracked.delayedAck != null) {
            _collector.ack(tracked.delayedAck);
            tracked.delayedAck = null;
        }
    } catch (FailedException e) {
        failBatch(tracked, e);
        success = false;
    }
    _batches.remove(tracked.info.batchId.getId());
    return success;
}
Also used : ReportedFailedException(backtype.storm.topology.ReportedFailedException) FailedException(backtype.storm.topology.FailedException) Values(backtype.storm.tuple.Values)

Example 15 with FailedException

use of backtype.storm.topology.FailedException in project storm by nathanmarz.

the class TridentBoltExecutor method execute.

@Override
public void execute(Tuple tuple) {
    if (tuple.getSourceStreamId().equals(Constants.SYSTEM_TICK_STREAM_ID)) {
        long now = System.currentTimeMillis();
        if (now - _lastRotate > _messageTimeoutMs) {
            _batches.rotate();
            _lastRotate = now;
        }
        return;
    }
    String batchGroup = _batchGroupIds.get(tuple.getSourceGlobalStreamid());
    if (batchGroup == null) {
        // this is so we can do things like have simple DRPC that doesn't need to use batch processing
        _coordCollector.setCurrBatch(null);
        _bolt.execute(null, tuple);
        _collector.ack(tuple);
        return;
    }
    IBatchID id = (IBatchID) tuple.getValue(0);
    //get transaction id
    //if it already exissts and attempt id is greater than the attempt there
    TrackedBatch tracked = (TrackedBatch) _batches.get(id.getId());
    // failures happen you don't get an explosion in memory usage in the tasks
    if (tracked != null) {
        if (id.getAttemptId() > tracked.attemptId) {
            _batches.remove(id.getId());
            tracked = null;
        } else if (id.getAttemptId() < tracked.attemptId) {
            // no reason to try to execute a previous attempt than we've already seen
            return;
        }
    }
    if (tracked == null) {
        tracked = new TrackedBatch(new BatchInfo(batchGroup, id, _bolt.initBatchState(batchGroup, id)), _coordConditions.get(batchGroup), id.getAttemptId());
        _batches.put(id.getId(), tracked);
    }
    _coordCollector.setCurrBatch(tracked);
    //System.out.println("TRACKED: " + tracked + " " + tuple);
    TupleType t = getTupleType(tuple, tracked);
    if (t == TupleType.COMMIT) {
        tracked.receivedCommit = true;
        checkFinish(tracked, tuple, t);
    } else if (t == TupleType.COORD) {
        int count = tuple.getInteger(1);
        tracked.reportedTasks++;
        tracked.expectedTupleCount += count;
        checkFinish(tracked, tuple, t);
    } else {
        tracked.receivedTuples++;
        boolean success = true;
        try {
            _bolt.execute(tracked.info, tuple);
            if (tracked.condition.expectedTaskReports == 0) {
                success = finishBatch(tracked, tuple);
            }
        } catch (FailedException e) {
            failBatch(tracked, e);
        }
        if (success) {
            _collector.ack(tuple);
        } else {
            _collector.fail(tuple);
        }
    }
    _coordCollector.setCurrBatch(null);
}
Also used : IBatchID(storm.trident.spout.IBatchID) ReportedFailedException(backtype.storm.topology.ReportedFailedException) FailedException(backtype.storm.topology.FailedException)

Aggregations

FailedException (backtype.storm.topology.FailedException)18 Values (backtype.storm.tuple.Values)6 ReportedFailedException (backtype.storm.topology.ReportedFailedException)5 BigInteger (java.math.BigInteger)4 Tuple (backtype.storm.tuple.Tuple)2 MQClientException (com.alibaba.rocketmq.client.exception.MQClientException)2 Iterator (java.util.Iterator)2 IBatchID (storm.trident.spout.IBatchID)2 TransactionAttempt (storm.trident.topology.TransactionAttempt)2 TridentTuple (storm.trident.tuple.TridentTuple)2 BatchId (com.alibaba.jstorm.batch.BatchId)1 IPrepareCommit (com.alibaba.jstorm.batch.IPrepareCommit)1 HashSet (java.util.HashSet)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IllegalClassException (org.apache.commons.lang.IllegalClassException)1 ElasticSearchException (org.elasticsearch.ElasticSearchException)1 IndicesExistsRequest (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)1 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)1 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)1