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); } }
public static TransactionStatus fromString(final String text) { if (StringUtils.isNotBlank(text)) { for (TransactionStatus transactionStatus : TransactionStatus.values()) { if (text.equalsIgnoreCase(transactionStatus.name())) { return transactionStatus; } } } return null; }
@Override public void ack(Object msgId) { TransactionAttempt tx = (TransactionAttempt) msgId; TransactionStatus status = _activeTx.get(tx.getTransactionId()); if (status != null && tx.equals(status.attempt)) { if (status.status == AttemptStatus.PROCESSING) { status.status = AttemptStatus.PROCESSED; } else if (status.status == AttemptStatus.COMMITTING) { _activeTx.remove(tx.getTransactionId()); _coordinatorState.cleanupBefore(tx.getTransactionId()); _currTransaction = nextTransactionId(tx.getTransactionId()); _state.setData(CURRENT_TX, _currTransaction); } sync(); } }
public static Transaction fromBlotterCursor(Cursor c) { long id = c.getLong(BlotterColumns._id.ordinal()); Transaction t = new Transaction(); t.id = id; t.parentId = c.getLong(BlotterColumns.parent_id.ordinal()); t.fromAccountId = c.getLong(BlotterColumns.from_account_id.ordinal()); t.toAccountId = c.getLong(BlotterColumns.to_account_id.ordinal()); t.categoryId = c.getLong(BlotterColumns.category_id.ordinal()); t.projectId = c.getLong(BlotterColumns.project_id.ordinal()); t.payeeId = c.getLong(BlotterColumns.payee_id.ordinal()); t.note = c.getString(BlotterColumns.note.ordinal()); t.fromAmount = c.getLong(BlotterColumns.from_amount.ordinal()); t.toAmount = c.getLong(BlotterColumns.to_amount.ordinal()); t.dateTime = c.getLong(BlotterColumns.datetime.ordinal()); t.originalCurrencyId = c.getLong(BlotterColumns.original_currency_id.ordinal()); t.originalFromAmount = c.getLong(BlotterColumns.original_from_amount.ordinal()); t.locationId = c.getLong(BlotterColumns.location_id.ordinal()); // t.provider = c.getString(BlotterColumns.provider.ordinal()); // t.accuracy = c.getFloat(BlotterColumns.accuracy.ordinal()); // t.latitude = c.getDouble(BlotterColumns.latitude.ordinal()); // t.longitude = c.getDouble(BlotterColumns.longitude.ordinal()); t.isTemplate = c.getInt(BlotterColumns.is_template.ordinal()); t.templateName = c.getString(BlotterColumns.template_name.ordinal()); t.recurrence = c.getString(BlotterColumns.recurrence.ordinal()); t.notificationOptions = c.getString(BlotterColumns.notification_options.ordinal()); t.status = TransactionStatus.valueOf(c.getString(BlotterColumns.status.ordinal())); t.attachedPicture = c.getString(BlotterColumns.attached_picture.ordinal()); t.isCCardPayment = c.getInt(BlotterColumns.is_ccard_payment.ordinal()); t.lastRecurrence = c.getLong(BlotterColumns.last_recurrence.ordinal()); return t; }
public void setStatusForTransaction(long transactionId, TransactionStatus status) { Put update = new Put(getRow(transactionId)); update.add(STATUS_COLUMN_BYTES, HConstants.LATEST_TIMESTAMP, Bytes.toBytes(status.name())); try { table.put(update); } catch (IOException e) { throw new RuntimeException(e); } }
protected ConsumeConcurrentlyStatus exceptionConsumeConcurrentlyStatus( TransactionStatus status, Throwable e, MsgObj msgObj, int maxRetryCount) { logger.error("mq consume failed", e); status.setRollbackOnly(); if (msgObj.getReconsumeTimes() >= maxRetryCount) { logger.error( "retryCount: {}, msgs: {}, context: {}", maxRetryCount, msgObj, msgObj.getContext()); msgObj.setErrorMsg(e.getMessage()); doLogErrorConsumeMessage(msgObj); return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; } else { return ConsumeConcurrentlyStatus.RECONSUME_LATER; } }
public TransactionStatus getStatusForTransaction(long transactionId) { try { Result result = table.get(new Get(getRow(transactionId))); if (result == null || result.isEmpty()) { return null; } byte[] statusCell = result.getValue(STATUS_COLUMN_BYTES); if (statusCell == null) { throw new RuntimeException("No status cell for row " + transactionId); } String statusString = Bytes.toString(statusCell); return TransactionStatus.valueOf(statusString); } catch (IOException e) { throw new RuntimeException(e); } }