@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(); } }
/** * Aborts the given transaction, and rolls back all data set changes. If rollback fails, * the transaction is invalidated. If an exception is caught during rollback, the exception * is rethrown wrapped in a TransactionFailureException, after all remaining TransactionAwares have * completed rollback. * * @throws TransactionFailureException for any exception that is encountered. */ public void abort() throws TransactionFailureException { abort(null); }
private void commit() throws TransactionFailureException { try { txClient.commitOrThrow(currentTx); } catch (TransactionFailureException e) { abort(e); // abort will rethrow this exception } catch (Throwable e) { String message = String.format("Exception from commit for transaction %d.", currentTx.getTransactionId()); abort(new TransactionFailureException(message, e)); // abort will throw that exception } }
public Result[] get(List<Get> gets) throws IOException { try { transactionContext.start(); Result[] result = transactionAwareHTable.get(gets); transactionContext.finish(); return result; } catch (Exception e) { try { transactionContext.abort(); } catch (TransactionFailureException e1) { throw new IOException("Could not rollback transaction", e1); } } return null; }
public Result[] get(List<Get> gets) throws IOException { try { transactionContext.start(); Result[] result = transactionAwareHTable.get(gets); transactionContext.finish(); return result; } catch (Exception e) { try { transactionContext.abort(); } catch (TransactionFailureException e1) { throw new IOException("Could not rollback transaction", e1); } } return null; }
public Result[] get(List<Get> gets) throws IOException { try { transactionContext.start(); Result[] result = transactionAwareHTable.get(gets); transactionContext.finish(); return result; } catch (Exception e) { try { transactionContext.abort(); } catch (TransactionFailureException e1) { throw new IOException("Could not rollback transaction", e1); } } return null; }
public Result[] get(List<Get> gets) throws IOException { try { transactionContext.start(); Result[] result = transactionAwareHTable.get(gets); transactionContext.finish(); return result; } catch (Exception e) { try { transactionContext.abort(); } catch (TransactionFailureException e1) { throw new IOException("Could not rollback transaction", e1); } } return null; }
public Result[] get(List<Get> gets) throws IOException { try { transactionContext.start(); Result[] result = transactionAwareHTable.get(gets); transactionContext.finish(); return result; } catch (Exception e) { try { transactionContext.abort(); } catch (TransactionFailureException e1) { throw new IOException("Could not rollback transaction", e1); } } return null; }
private void finishExecute(TransactionContext txContext, TxRunnable runnable) throws TransactionFailureException { try { runnable.run(datasetCache); } catch (Exception e) { txContext.abort(new TransactionFailureException("Exception raised from TxRunnable.run() " + runnable, e)); } // The call the txContext.abort above will always have exception thrown // Hence we'll only reach here if and only if the runnable.run() returns normally. txContext.finish(); } }
private void persist() throws TransactionFailureException { for (TransactionAware txAware : txAwares) { boolean success = false; Throwable cause = null; try { success = txAware.commitTx(); } catch (Throwable e) { cause = e; } if (!success) { TransactionFailureException tfe = createTransactionFailure("persist changes of", txAware, cause); LOG.warn(tfe.getMessage()); // abort will throw that exception abort(tfe); } } }
public void execute(Runnable runnable) throws TransactionFailureException { TransactionContext txCtx = new TransactionContext(txSystemClient, (TransactionAware) dataset); txCtx.start(); try { runnable.run(); } catch (Throwable t) { txCtx.abort(new TransactionFailureException("runnable failed", t)); } txCtx.finish(); } }
public void execute(Runnable runnable) throws TransactionFailureException { TransactionContext txCtx = new TransactionContext(txSystemClient, (TransactionAware) dataset); txCtx.start(); try { runnable.run(); } catch (Throwable t) { txCtx.abort(new TransactionFailureException("runnable failed", t)); } txCtx.finish(); } }
private void finishExecute(TransactionContext txContext, TxRunnable runnable) throws TransactionFailureException { try { runnable.run(datasetCache); } catch (Exception e) { txContext.abort(new TransactionFailureException("Exception raised from TxRunnable.run() " + runnable, e)); } // The call the txContext.abort above will always have exception thrown // Hence we'll only reach here if and only if the runnable.run() returns normally. txContext.finish(); } }
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 = txContextFactory.newTransactionContext(); 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 something goes wrong txContext.finish(); return o; } }
private <I, O> O executeOnce(Function<I, O> function, I input) throws TransactionFailureException { TransactionContext txContext = txContextFactory.newTransactionContext(); 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 something goes wrong txContext.finish(); return o; } }
@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(); } }
@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(); } }
@Test public void testRollbackOfPartitionCreateThenDelete() throws Exception { PartitionedFileSet pfs = dsFrameworkUtil.getInstance(pfsInstance); TransactionContext txContext = new TransactionContext(txClient, (TransactionAware) pfs); txContext.start(); Assert.assertNull(pfs.getPartition(PARTITION_KEY)); Location outputLocation = createPartition(pfs, PARTITION_KEY, "file"); Assert.assertNotNull(pfs.getPartition(PARTITION_KEY)); pfs.dropPartition(PARTITION_KEY); txContext.abort(); // the file shouldn't exist because the transaction was aborted (AND because it was dropped at the end of the tx) Assert.assertFalse(outputLocation.exists()); }
@Test public void testRollbackOnTransactionAbort() throws Exception { PartitionedFileSet pfs = dsFrameworkUtil.getInstance(pfsInstance); TransactionContext txContext = new TransactionContext(txClient, (TransactionAware) pfs); txContext.start(); Location outputLocation = createPartition(pfs, PARTITION_KEY, "file");; Assert.assertNotNull(pfs.getPartition(PARTITION_KEY)); Assert.assertTrue(pfs.getPartition(PARTITION_KEY).getLocation().exists()); txContext.abort(); // because the previous transaction aborted, the partition as well as the file will not exist txContext.start(); Assert.assertNull(pfs.getPartition(PARTITION_KEY)); Assert.assertFalse(outputLocation.exists()); txContext.finish(); }