Search in sources :

Example 6 with FailedException

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

the class MetaSimpleClient method commit.

@Override
public byte[] commit(BatchId id) throws FailedException {
    try {
        updateOffsetToZk(currentOffsets);
        switchOffsetMap();
    } catch (Exception e) {
        LOG.warn("Failed to update offset to ZK", e);
        throw new FailedException(e);
    }
    return null;
}
Also used : FailedException(backtype.storm.topology.FailedException) FailedException(backtype.storm.topology.FailedException) MQClientException(com.alibaba.rocketmq.client.exception.MQClientException)

Example 7 with FailedException

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

the class CoordinatedBolt method checkFinishId.

private boolean checkFinishId(Tuple tup, TupleType type) {
    _collector.flush();
    Object id = tup.getValue(0);
    boolean failed = false;
    synchronized (_tracked) {
        TrackingInfo track = _tracked.get(id);
        try {
            if (track != null) {
                boolean delayed = false;
                if (_idStreamSpec == null && type == TupleType.COORD || _idStreamSpec != null && type == TupleType.ID) {
                    track.ackTuples.add(tup);
                    delayed = true;
                }
                if (track.failed) {
                    failed = true;
                    for (Tuple t : track.ackTuples) {
                        _collector.fail(t);
                    }
                    _tracked.remove(id);
                } else if (track.receivedId && (_sourceArgs.isEmpty() || track.reportCount == _numSourceReports && track.expectedTupleCount == track.receivedTuples)) {
                    if (_delegate instanceof FinishedCallback) {
                        ((FinishedCallback) _delegate).finishedId(id);
                    }
                    if (!(_sourceArgs.isEmpty() || type != TupleType.REGULAR)) {
                        throw new IllegalStateException("Coordination condition met on a non-coordinating tuple. Should be impossible");
                    }
                    Iterator<Integer> outTasks = _countOutTasks.iterator();
                    _collector.flush();
                    while (outTasks.hasNext()) {
                        int task = outTasks.next();
                        int numTuples = get(track.taskEmittedTuples, task, 0);
                        _collector.emitDirect(task, Constants.COORDINATED_STREAM_ID, tup, new Values(id, numTuples));
                    }
                    for (Tuple t : track.ackTuples) {
                        _collector.ack(t);
                    }
                    track.finished = true;
                    _tracked.remove(id);
                }
                if (!delayed && type != TupleType.REGULAR) {
                    if (track.failed) {
                        _collector.fail(tup);
                    } else {
                        _collector.ack(tup);
                    }
                }
            } else {
                if (type != TupleType.REGULAR)
                    _collector.fail(tup);
            }
        } catch (FailedException e) {
            LOG.error("Failed to finish batch", e);
            for (Tuple t : track.ackTuples) {
                _collector.fail(t);
            }
            _tracked.remove(id);
            failed = true;
        } finally {
            _collector.flush();
        }
    }
    return failed;
}
Also used : FailedException(backtype.storm.topology.FailedException) Iterator(java.util.Iterator) Values(backtype.storm.tuple.Values) Tuple(backtype.storm.tuple.Tuple)

Example 8 with FailedException

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

the class WindowsStateUpdater method updateState.

@Override
public void updateState(WindowsState state, List<TridentTuple> tuples, TridentCollector collector) {
    Long currentTxId = state.getCurrentTxId();
    LOG.debug("Removing triggers using WindowStateUpdater, txnId: [{}] ", currentTxId);
    for (TridentTuple tuple : tuples) {
        try {
            Object fieldValue = tuple.getValueByField(WindowTridentProcessor.TRIGGER_FIELD_NAME);
            if (!(fieldValue instanceof WindowTridentProcessor.TriggerInfo)) {
                throw new IllegalClassException(WindowTridentProcessor.TriggerInfo.class, fieldValue.getClass());
            }
            WindowTridentProcessor.TriggerInfo triggerInfo = (WindowTridentProcessor.TriggerInfo) fieldValue;
            String triggerCompletedKey = WindowTridentProcessor.getWindowTriggerInprocessIdPrefix(triggerInfo.windowTaskId) + currentTxId;
            LOG.debug("Removing trigger key [{}] and trigger completed key [{}] from store: [{}]", triggerInfo, triggerCompletedKey, windowsStore);
            windowsStore.removeAll(Lists.newArrayList(triggerInfo.generateTriggerKey(), triggerCompletedKey));
        } catch (Exception ex) {
            LOG.warn(ex.getMessage());
            collector.reportError(ex);
            throw new FailedException(ex);
        }
    }
}
Also used : FailedException(backtype.storm.topology.FailedException) IllegalClassException(org.apache.commons.lang.IllegalClassException) FailedException(backtype.storm.topology.FailedException) IllegalClassException(org.apache.commons.lang.IllegalClassException) TridentTuple(storm.trident.tuple.TridentTuple)

Example 9 with FailedException

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

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 10 with FailedException

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

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;
        LOG.debug("send commit stream {}", maybeCommit);
        _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));
                    LOG.debug("send batch stream {}", 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)

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