private void postCommit() throws TransactionFailureException { TransactionFailureException cause = null; for (TransactionAware txAware : txAwares) { try { txAware.postTxCommit(); } catch (Throwable e) { String message = String.format("Unable to perform post-commit in transaction-aware '%s' for transaction %d. ", txAware.getTransactionAwareName(), currentTx.getTransactionId()); LOG.warn(message, e); cause = new TransactionFailureException(message, e); } } if (cause != null) { throw cause; } } }
private void postCommit() throws TransactionFailureException { TransactionFailureException cause = null; for (TransactionAware txAware : txAwares) { try { txAware.postTxCommit(); } catch (Throwable e) { String message = String.format("Unable to perform post-commit in transaction-aware '%s' for transaction %d. ", txAware.getTransactionAwareName(), currentTx.getTransactionId()); LOG.warn(message, e); cause = new TransactionFailureException(message, e); } } if (cause != null) { throw cause; } } }
private void initFlowlet() throws InterruptedException { final TransactionContext txContext = flowletContext.createTransactionContext(); try { txContext.start(); try { LOG.info("Initializing flowlet: " + flowletContext); flowlet.initialize(flowletContext); LOG.info("Flowlet initialized: " + flowletContext); } catch (Throwable t) { LOG.error("User code exception. Aborting transaction.", t); txContext.abort(new TransactionFailureException("User code exception. Aborting transaction", t)); throw Throwables.propagate(t); } txContext.finish(); } catch (TransactionFailureException e) { LOG.error("Flowlet throws exception during flowlet initialize: " + flowletContext, e); throw Throwables.propagate(e); } }
private void destroyFlowlet() { final TransactionContext txContext = flowletContext.createTransactionContext(); try { txContext.start(); try { LOG.info("Destroying flowlet: " + flowletContext); flowlet.destroy(); LOG.info("Flowlet destroyed: " + flowletContext); } catch (Throwable t) { LOG.error("User code exception. Aborting transaction.", t); txContext.abort(new TransactionFailureException("User code exception. Aborting transaction", t)); // No need to propagate, as it is shutting down. } txContext.finish(); } catch (TransactionFailureException e) { LOG.error("Flowlet throws exception during flowlet destroy: " + flowletContext, e); // No need to propagate, as it is shutting down. } }
private void commit() throws TransactionFailureException { boolean commitSuccess = false; try { commitSuccess = txClient.commit(currentTx); } catch (TransactionNotInProgressException e) { String message = String.format("Transaction %d is not in progress.", currentTx.getTransactionId()); LOG.warn(message, e); abort(new TransactionFailureException(message, e)); // abort will throw that exception } catch (Throwable e) { String message = String.format("Exception from commit for transaction %d.", currentTx.getTransactionId()); LOG.warn(message, e); abort(new TransactionFailureException(message, e)); // abort will throw that exception } if (!commitSuccess) { String message = String.format("Conflict detected for transaction %d.", currentTx.getTransactionId()); abort(new TransactionConflictException(message)); // abort will throw } }
private void persist() throws TransactionFailureException { for (TransactionAware txAware : txAwares) { boolean success; Throwable cause = null; try { success = txAware.commitTx(); } catch (Throwable e) { success = false; cause = e; } if (!success) { String message = String.format("Unable to persist changes of transaction-aware '%s' for transaction %d. ", txAware.getTransactionAwareName(), currentTx.getTransactionId()); if (cause == null) { LOG.warn(message); } else { LOG.warn(message, cause); } abort(new TransactionFailureException(message, cause)); // abort will throw that exception } } }
private void persist() throws TransactionFailureException { for (TransactionAware txAware : txAwares) { boolean success; Throwable cause = null; try { success = txAware.commitTx(); } catch (Throwable e) { success = false; cause = e; } if (!success) { String message = String.format("Unable to persist changes of transaction-aware '%s' for transaction %d. ", txAware.getTransactionAwareName(), currentTx.getTransactionId()); if (cause == null) { LOG.warn(message); } else { LOG.warn(message, cause); } abort(new TransactionFailureException(message, cause)); // abort will throw that exception } } }
private void commit() throws TransactionFailureException { boolean commitSuccess = false; try { commitSuccess = txClient.commit(currentTx); } catch (TransactionNotInProgressException e) { String message = String.format("Transaction %d is not in progress.", currentTx.getTransactionId()); LOG.warn(message, e); abort(new TransactionFailureException(message, e)); // abort will throw that exception } catch (Throwable e) { String message = String.format("Exception from commit for transaction %d.", currentTx.getTransactionId()); LOG.warn(message, e); abort(new TransactionFailureException(message, e)); // abort will throw that exception } if (!commitSuccess) { String message = String.format("Conflict detected for transaction %d.", currentTx.getTransactionId()); abort(new TransactionConflictException(message)); // abort will throw } }
String message = String.format("Transaction %d is not in progress.", currentTx.getTransactionId()); LOG.warn(message, e); abort(new TransactionFailureException(message, e)); abort(new TransactionFailureException(message, e));
String message = String.format("Transaction %d is not in progress.", currentTx.getTransactionId()); LOG.warn(message, e); abort(new TransactionFailureException(message, e)); abort(new TransactionFailureException(message, e));
txAware.getTransactionAwareName(), currentTx.getTransactionId()); LOG.warn(message, e); abort(new TransactionFailureException(message, e)); String message = String.format("Transaction %d is not in progress.", currentTx.getTransactionId()); LOG.warn(message, e); abort(new TransactionFailureException(message, e)); abort(new TransactionFailureException(message, e));
txAware.getTransactionAwareName(), currentTx.getTransactionId()); LOG.warn(message, e); abort(new TransactionFailureException(message, e)); String message = String.format("Transaction %d is not in progress.", currentTx.getTransactionId()); LOG.warn(message, e); abort(new TransactionFailureException(message, e)); abort(new TransactionFailureException(message, e));
/** * Starts a new transaction. Calling this will initiate a new transaction using the {@link TransactionSystemClient}, * and pass the returned transaction to {@link TransactionAware#startTx(Transaction)} for each registered * TransactionAware. If an exception is encountered, the transaction will be aborted and a * {@code TransactionFailureException} wrapping the root cause will be thrown. * * @throws TransactionFailureException if an exception occurs starting the transaction with any registered * TransactionAware */ public void start() throws TransactionFailureException { currentTx = txClient.startShort(); for (TransactionAware txAware : txAwares) { try { txAware.startTx(currentTx); } catch (Throwable e) { String message = String.format("Unable to start transaction-aware '%s' for transaction %d. ", txAware.getTransactionAwareName(), currentTx.getTransactionId()); LOG.warn(message, e); txClient.abort(currentTx); throw new TransactionFailureException(message, e); } } }
/** * Starts a new transaction. Calling this will initiate a new transaction using the {@link TransactionSystemClient}, * and pass the returned transaction to {@link TransactionAware#startTx(Transaction)} for each registered * TransactionAware. If an exception is encountered, the transaction will be aborted and a * {@code TransactionFailureException} wrapping the root cause will be thrown. * * @throws TransactionFailureException if an exception occurs starting the transaction with any registered * TransactionAware */ public void start() throws TransactionFailureException { currentTx = txClient.startShort(); for (TransactionAware txAware : txAwares) { try { txAware.startTx(currentTx); } catch (Throwable e) { String message = String.format("Unable to start transaction-aware '%s' for transaction %d. ", txAware.getTransactionAwareName(), currentTx.getTransactionId()); LOG.warn(message, e); txClient.abort(currentTx); throw new TransactionFailureException(message, e); } } }
private <I, O> O executeOnce(Function<I, O> function, I input) throws TransactionFailureException { TransactionContext txContext = new TransactionContext(txClient, txAwares); txContext.start(); O o = null; try { o = function.apply(input); } catch (Throwable e) { txContext.abort(new TransactionFailureException("Transaction function failure for transaction. ", e)); // abort will throw } // will throw if smth goes wrong txContext.finish(); return o; } }
private <I, O> O executeOnce(Function<I, O> function, I input) throws TransactionFailureException { TransactionContext txContext = new TransactionContext(txClient, txAwares); txContext.start(); O o = null; try { o = function.apply(input); } catch (Throwable e) { txContext.abort(new TransactionFailureException("Transaction function failure for transaction. ", e)); // abort will throw } // will throw if smth goes wrong txContext.finish(); return o; } }
LOG.warn(message, e); if (cause == null) { cause = new TransactionFailureException(message, e);
LOG.warn(message, e); if (cause == null) { cause = new TransactionFailureException(message, e);