/** * Wraps the given {@link Throwable} as a {@link TransactionFailureException} if it is not already an instance of * {@link TransactionFailureException}. * * @param t the original exception * @param message the exception message to use in case wrapping is needed */ public static TransactionFailureException asTransactionFailure(Throwable t, String message) { if (t instanceof TransactionFailureException) { return (TransactionFailureException) t; } return new TransactionFailureException(message, t); }
@Override public void run(TxRunnable runnable) throws TransactionException { try { transactional.execute( datasetContext -> runnable.run(new NoSqlStructuredTableContext(datasetContext, tableAdmin)) ); } catch (TransactionFailureException e) { throw new TransactionException("Failure executing NoSql transaction:", e.getCause() == null ? e : e.getCause()); } } }
@Override public void abort() throws SQLException { if (txContext == null || !isTransactionRunning()) { return; } try { txContext.abort(); } catch (TransactionFailureException e) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.TRANSACTION_FAILED) .setMessage(e.getMessage()).setRootCause(e).build() .buildException(); } }
private void postCommit() throws TransactionFailureException { TransactionFailureException cause = null; for (TransactionAware txAware : txAwares) { try { txAware.postTxCommit(); } catch (Throwable t) { TransactionFailureException tfe = createTransactionFailure("perform post-commit for", txAware, t); LOG.warn(tfe.getMessage()); if (cause == null) { cause = tfe; } else { cause.addSuppressed(tfe); } } } if (cause != null) { throw cause; } }
protected TransactionFailureException createTransactionFailure(String action, TransactionAware txAware, Throwable cause) { String txAwareName; Throwable thrownForName = null; try { txAwareName = txAware.getTransactionAwareName(); } catch (Throwable t) { thrownForName = t; txAwareName = "unknown"; } TransactionFailureException tfe = new TransactionFailureException( String.format("Unable to %s transaction-aware '%s' for transaction %d", action, txAwareName, currentTx.getTransactionId()), cause); if (thrownForName != null) { tfe.addSuppressed(thrownForName); } return tfe; } }
} catch (Throwable t) { TransactionFailureException tfe = createTransactionFailure("roll back changes in", txAware, t); LOG.warn(tfe.getMessage()); if (cause == null) { cause = tfe; } else { cause.addSuppressed(tfe); cause = new TransactionFailureException( String.format("Error while calling transaction service to %s transaction %d.", success ? "abort" : "invalidate", currentTx.getTransactionId())); } else { cause.addSuppressed(t);
private void checkForConflicts() throws TransactionFailureException { Collection<byte[]> changes = Lists.newArrayList(); for (TransactionAware txAware : txAwares) { try { changes.addAll(txAware.getTxChanges()); } catch (Throwable t) { TransactionFailureException tfe = createTransactionFailure("retrieve changes from", txAware, t); LOG.warn(tfe.getMessage()); // abort will throw that exception abort(tfe); } } try { txClient.canCommitOrThrow(currentTx, changes); } catch (TransactionFailureException e) { abort(e); // abort will rethrow this exception } catch (Throwable e) { String message = String.format("Exception from canCommit for transaction %d.", currentTx.getTransactionId()); abort(new TransactionFailureException(message, e)); // abort will throw that exception } }
throw new DataSetException("Unable to disable and enable Explore", e.getCause()); } catch (RuntimeException e) { if (e.getCause() instanceof TransactionFailureException) { "Make sure that no other programs are using this dataset at the same time."); } catch (TransactionFailureException e) { throw new DataSetException("Transaction failure: " + e.getMessage(), e.getCause()); } catch (RuntimeException e) {
/** * Calls the {@link TransactionAware#postTxCommit()} on all {@link TransactionAware}. */ private void postCommit() throws TransactionFailureException { TransactionFailureException cause = null; for (TransactionAware txAware : getTransactionAwares()) { try { txAware.postTxCommit(); } catch (Throwable t) { TransactionFailureException tfe = createTransactionFailure("perform post-commit for", txAware, t); if (cause == null) { cause = tfe; } else { cause.addSuppressed(tfe); } } } if (cause != null) { throw cause; } }
private TransactionFailureException createTransactionFailure(String action, TransactionAware txAware, Throwable cause) { String txAwareName; Throwable thrownForName = null; try { txAwareName = txAware.getTransactionAwareName(); } catch (Throwable t) { thrownForName = t; txAwareName = "unknown"; } TransactionFailureException tfe = new TransactionFailureException( String.format("Unable to %s transaction-aware '%s' for transaction %d", action, txAwareName, currentTx.getTransactionId()), cause); if (thrownForName != null) { tfe.addSuppressed(thrownForName); } return tfe; } }
throw new DataSetException("Unable to disable and enable Explore", e.getCause()); } catch (RuntimeException e) { if (e.getCause() instanceof TransactionFailureException) { "Make sure that no other programs are using this dataset at the same time."); } catch (TransactionFailureException e) { throw new DataSetException("Transaction failure: " + e.getMessage(), e.getCause()); } catch (RuntimeException e) {
/** * Calls the {@link TransactionAware#postTxCommit()} on all {@link TransactionAware}. */ private void postCommit() throws TransactionFailureException { TransactionFailureException cause = null; for (TransactionAware txAware : getTransactionAwares()) { try { txAware.postTxCommit(); } catch (Throwable t) { TransactionFailureException tfe = createTransactionFailure("perform post-commit for", txAware, t); if (cause == null) { cause = tfe; } else { cause.addSuppressed(tfe); } } } if (cause != null) { throw cause; } }
@Override public void execute(int timeoutInSeconds, TxRunnable runnable) throws TransactionFailureException { throw new TransactionFailureException("Attempted to start a transaction within a MapReduce transaction"); }
/** * Execute a new transaction and attempt a nested transaction form there. * The nested transaction can be executed through a different transactional. */ static void executeAttemptNestedTransaction(Transactional txnl, final Transactional nestingTxnl, final String row, final String key) { try { txnl.execute(new TxRunnable() { @Override public void run(DatasetContext ctext) throws Exception { attemptNestedTransaction(nestingTxnl, row, key); } }); } catch (TransactionFailureException e) { throw Throwables.propagate(e.getCause() == null ? e : e.getCause()); } }
protected TransactionFailureException createTransactionFailure(String action, TransactionAware txAware, Throwable cause) { String txAwareName; Throwable thrownForName = null; try { txAwareName = txAware.getTransactionAwareName(); } catch (Throwable t) { thrownForName = t; txAwareName = "unknown"; } TransactionFailureException tfe = new TransactionFailureException( String.format("Unable to %s transaction-aware '%s' for transaction %d", action, txAwareName, currentTx.getTransactionId()), cause); if (thrownForName != null) { tfe.addSuppressed(thrownForName); } return tfe; } }
@Override public void commit() throws SQLException { if (txContext == null || !isTransactionRunning()) { return; } try { txContext.finish(); } catch (TransactionFailureException e) { if (e instanceof TransactionConflictException) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.TRANSACTION_CONFLICT_EXCEPTION) .setMessage(e.getMessage()).setRootCause(e).build() .buildException(); } throw new SQLExceptionInfo.Builder( SQLExceptionCode.TRANSACTION_FAILED) .setMessage(e.getMessage()).setRootCause(e).build() .buildException(); } }
/** * Wraps the given {@link Throwable} as a {@link TransactionFailureException} if it is not already an instance of * {@link TransactionFailureException}. * * @param t the original exception * @param message the exception message to use in case wrapping is needed */ public static TransactionFailureException asTransactionFailure(Throwable t, String message) { if (t instanceof TransactionFailureException) { return (TransactionFailureException) t; } return new TransactionFailureException(message, t); }
cause = tfe; } else { cause.addSuppressed(tfe); cause = new TransactionFailureException( String.format("Error while calling transaction service to %s transaction %d.", success ? "abort" : "invalidate", currentTx.getTransactionId())); } else { cause.addSuppressed(t);
@Override public void begin() throws SQLException { if (txContext == null) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.NULL_TRANSACTION_CONTEXT).build() .buildException(); } try { txContext.start(); } catch (TransactionFailureException e) { throw new SQLExceptionInfo.Builder( SQLExceptionCode.TRANSACTION_FAILED) .setMessage(e.getMessage()).setRootCause(e).build() .buildException(); } }