Search in sources :

Example 1 with BigInteger

use of java.math.BigInteger in project storm by apache.

the class RotatingTransactionalState method getState.

public Object getState(BigInteger txid, StateInitializer init) {
    if (!_curr.containsKey(txid)) {
        SortedMap<BigInteger, Object> prevMap = _curr.headMap(txid);
        SortedMap<BigInteger, Object> afterMap = _curr.tailMap(txid);
        BigInteger prev = null;
        if (!prevMap.isEmpty())
            prev = prevMap.lastKey();
        if (_strictOrder) {
            if (prev == null && !txid.equals(TransactionalSpoutCoordinator.INIT_TXID)) {
                throw new IllegalStateException("Trying to initialize transaction for which there should be a previous state");
            }
            if (prev != null && !prev.equals(txid.subtract(BigInteger.ONE))) {
                throw new IllegalStateException("Expecting previous txid state to be the previous transaction");
            }
            if (!afterMap.isEmpty()) {
                throw new IllegalStateException("Expecting tx state to be initialized in strict order but there are txids after that have state");
            }
        }
        Object data;
        if (afterMap.isEmpty()) {
            Object prevData;
            if (prev != null) {
                prevData = _curr.get(prev);
            } else {
                prevData = null;
            }
            data = init.init(txid, prevData);
        } else {
            data = null;
        }
        _curr.put(txid, data);
        _state.setData(txPath(txid), data);
    }
    return _curr.get(txid);
}
Also used : BigInteger(java.math.BigInteger)

Example 2 with BigInteger

use of java.math.BigInteger in project storm by apache.

the class RotatingTransactionalState method sync.

private void sync() {
    List<String> txids = _state.list(_subdir);
    for (String txid_s : txids) {
        Object data = _state.getData(txPath(txid_s));
        _curr.put(new BigInteger(txid_s), data);
    }
}
Also used : BigInteger(java.math.BigInteger)

Example 3 with BigInteger

use of java.math.BigInteger in project storm by apache.

the class RotatingTransactionalState method cleanupBefore.

public void cleanupBefore(BigInteger txid) {
    SortedMap<BigInteger, Object> toDelete = _curr.headMap(txid);
    for (BigInteger tx : new HashSet<BigInteger>(toDelete.keySet())) {
        _curr.remove(tx);
        _state.delete(txPath(tx));
    }
}
Also used : BigInteger(java.math.BigInteger) HashSet(java.util.HashSet)

Example 4 with BigInteger

use of java.math.BigInteger in project storm by apache.

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(org.apache.storm.topology.FailedException) BigInteger(java.math.BigInteger)

Example 5 with BigInteger

use of java.math.BigInteger in project storm by apache.

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(org.apache.storm.topology.FailedException) Values(org.apache.storm.tuple.Values) BigInteger(java.math.BigInteger)

Aggregations

BigInteger (java.math.BigInteger)8406 Test (org.junit.Test)1314 BigDecimal (java.math.BigDecimal)1100 ArrayList (java.util.ArrayList)617 IOException (java.io.IOException)353 Test (org.junit.jupiter.api.Test)286 HashMap (java.util.HashMap)229 Date (java.util.Date)224 MessageDigest (java.security.MessageDigest)204 List (java.util.List)199 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)189 AionAddress (org.aion.types.AionAddress)189 AionTransaction (org.aion.base.AionTransaction)172 Map (java.util.Map)134 X509Certificate (java.security.cert.X509Certificate)127 SecureRandom (java.security.SecureRandom)119 Test (org.testng.annotations.Test)119 Random (java.util.Random)118 KeyFactory (java.security.KeyFactory)108 HashSet (java.util.HashSet)101