@Override protected void startTransaction(TransactionContext txContext) throws TransactionFailureException { txContext.start(defaultTimeout); } };
/** * Starts a short transaction with default timeout. Subclasses can override this to change the default. */ protected void startTransaction(TransactionContext txContext) throws TransactionFailureException { txContext.start(); }
@Override protected void startTransaction(TransactionContext txContext) throws TransactionFailureException { txContext.start(defaultTimeout); } };
/** * Starts a short transaction with default timeout. Subclasses can override this to change the default. */ protected void startTransaction(TransactionContext txContext) throws TransactionFailureException { txContext.start(); }
@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(); } }
@Override public void flush() { try { if (txContext != null) { txContext.finish(); txContext.start(); } } catch (TransactionFailureException e) { throw Throwables.propagate(e); } }
@Override public void flush() { try { if (txContext != null) { txContext.finish(); txContext.start(); } } catch (TransactionFailureException e) { throw Throwables.propagate(e); } }
private void startTx(TransactionContext txContext) throws TransactionFailureException { txContext.start(flowletContext.getDefaultTxTimeout()); }
@Override public void execute(int timeout, TxRunnable runnable) throws TransactionFailureException { TransactionContext txContext = datasetCache.newTransactionContext(); txContext.start(timeout); finishExecute(txContext, runnable); }
@Override public void execute(int timeout, TxRunnable runnable) throws TransactionFailureException { TransactionContext txContext = datasetCache.newTransactionContext(); txContext.start(timeout); finishExecute(txContext, runnable); }
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 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 <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; } }
@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(); }
@Test public void testAbortFailureThrowsFailureException() throws TransactionFailureException { TransactionContext context = new SimpleTransactionContext(new FailingTxClient(txManager)); context.start(); Assert.assertTrue(context.addTransactionAware(ds1)); ds1.addChange(A); try { context.finish(); Assert.fail("Finish should have failed - exception should be thrown"); } catch (TransactionFailureException e) { // expected } }
@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()); }