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);
}
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);
}
}
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));
}
}
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);
}
}
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);
}
}
Aggregations