Search in sources :

Example 16 with FailedException

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

the class TransactionalSpoutBatchExecutor method execute.

@Override
public void execute(Tuple input) {
    TransactionAttempt attempt = (TransactionAttempt) input.getValue(0);
    try {
        if (input.getSourceStreamId().equals(TransactionalSpoutCoordinator.TRANSACTION_COMMIT_STREAM_ID)) {
            if (attempt.equals(_activeTransactions.get(attempt.getTransactionId()))) {
                ((ICommitterTransactionalSpout.Emitter) _emitter).commit(attempt);
                _activeTransactions.remove(attempt.getTransactionId());
                _collector.ack(input);
            } else {
                _collector.fail(input);
            }
        } else {
            _emitter.emitBatch(attempt, input.getValue(1), _collector);
            _activeTransactions.put(attempt.getTransactionId(), attempt);
            _collector.ack(input);
            BigInteger committed = (BigInteger) input.getValue(2);
            if (committed != null) {
                // valid to delete before what's been committed since 
                // those batches will never be accessed again
                _activeTransactions.headMap(committed).clear();
                _emitter.cleanupBefore(committed);
            }
        }
    } catch (FailedException e) {
        LOG.warn("Failed to emit batch for transaction", e);
        _collector.fail(input);
    }
}
Also used : FailedException(backtype.storm.topology.FailedException) BigInteger(java.math.BigInteger)

Example 17 with FailedException

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

the class TransactionalSpoutCoordinator method sync.

private void sync() {
    // note that sometimes the tuples active may be less than max_spout_pending, e.g.
    // max_spout_pending = 3
    // tx 1, 2, 3 active, tx 2 is acked. there won't be a commit for tx 2 (because tx 1 isn't committed yet),
    // and there won't be a batch for tx 4 because there's max_spout_pending tx active
    TransactionStatus maybeCommit = _activeTx.get(_currTransaction);
    if (maybeCommit != null && maybeCommit.status == AttemptStatus.PROCESSED) {
        maybeCommit.status = AttemptStatus.COMMITTING;
        _collector.emit(TRANSACTION_COMMIT_STREAM_ID, new Values(maybeCommit.attempt), maybeCommit.attempt);
    }
    try {
        if (_activeTx.size() < _maxTransactionActive) {
            BigInteger curr = _currTransaction;
            for (int i = 0; i < _maxTransactionActive; i++) {
                if ((_coordinatorState.hasCache(curr) || _coordinator.isReady()) && !_activeTx.containsKey(curr)) {
                    TransactionAttempt attempt = new TransactionAttempt(curr, _rand.nextLong());
                    Object state = _coordinatorState.getState(curr, _initializer);
                    _activeTx.put(curr, new TransactionStatus(attempt));
                    _collector.emit(TRANSACTION_BATCH_STREAM_ID, new Values(attempt, state, previousTransactionId(_currTransaction)), attempt);
                }
                curr = nextTransactionId(curr);
            }
        }
    } catch (FailedException e) {
        LOG.warn("Failed to get metadata for a transaction", e);
    }
}
Also used : FailedException(backtype.storm.topology.FailedException) Values(backtype.storm.tuple.Values) BigInteger(java.math.BigInteger)

Example 18 with FailedException

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

the class TridentSpoutExecutor method execute.

@Override
public void execute(BatchInfo info, Tuple input) {
    // there won't be a BatchInfo for the success stream
    TransactionAttempt attempt = (TransactionAttempt) input.getValue(0);
    if (input.getSourceStreamId().equals(MasterBatchCoordinator.COMMIT_STREAM_ID)) {
        if (attempt.equals(_activeBatches.get(attempt.getTransactionId()))) {
            ((ICommitterTridentSpout.Emitter) _emitter).commit(attempt);
            _activeBatches.remove(attempt.getTransactionId());
        } else {
            throw new FailedException("Received commit for different transaction attempt");
        }
    } else if (input.getSourceStreamId().equals(MasterBatchCoordinator.SUCCESS_STREAM_ID)) {
        // valid to delete before what's been committed since 
        // those batches will never be accessed again
        _activeBatches.headMap(attempt.getTransactionId()).clear();
        _emitter.success(attempt);
    } else {
        _collector.setBatch(info.batchId);
        _emitter.emitBatch(attempt, input.getValue(1), _collector);
        _activeBatches.put(attempt.getTransactionId(), attempt);
    }
}
Also used : FailedException(backtype.storm.topology.FailedException) TransactionAttempt(storm.trident.topology.TransactionAttempt)

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