@Override public void canCommitOrThrow(Transaction tx, Collection<byte[]> changeIds) throws TransactionFailureException { delegate.canCommitOrThrow(tx, changeIds); }
@Override public void canCommitOrThrow(Transaction tx, Collection<byte[]> changeIds) throws TransactionFailureException { delegate.canCommitOrThrow(tx, changeIds); }
@Override public void canCommitOrThrow(Transaction tx, Collection<byte[]> changeIds) throws TransactionFailureException { delegate.canCommitOrThrow(tx, changeIds); }
@Override public void canCommitOrThrow(Transaction tx, Collection<byte[]> changeIds) throws TransactionFailureException { delegate.canCommitOrThrow(tx, changeIds); }
@Override public void canCommitOrThrow(Transaction tx, Collection<byte[]> changeIds) throws TransactionFailureException { delegate.canCommitOrThrow(tx, changeIds); }
@Override public void canCommitOrThrow(Transaction tx, Collection<byte[]> changeIds) throws TransactionFailureException { delegate.canCommitOrThrow(tx, changeIds); }
@Override public void canCommitOrThrow(Transaction tx, Collection<byte[]> changeIds) throws TransactionFailureException { try { delegate.canCommitOrThrow(tx, changeIds); } catch (RuntimeException e) { throw handleException(e); } }
@Override public void canCommitOrThrow(Transaction tx, Collection<byte[]> changeIds) throws TransactionFailureException { try { delegate.canCommitOrThrow(tx, changeIds); } catch (RuntimeException e) { throw handleException(e); } }
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 } }
/** * Collects the set of changes across all {@link TransactionAware}s by calling {@link TransactionAware#getTxChanges()} * and checks if conflicts will arise when the transaction is going to be committed. */ private void checkForConflicts() throws TransactionFailureException { Set<byte[]> changes = new TreeSet<>(Bytes.BYTES_COMPARATOR); for (TransactionAware txAware : getTransactionAwares()) { try { changes.addAll(txAware.getTxChanges()); } catch (Throwable t) { abort(createTransactionFailure("retrieve changes from", txAware, t)); } } // If there is no changes, no need to call canCommit if (changes.isEmpty()) { return; } try { txClient.canCommitOrThrow(currentTx, changes); } catch (TransactionFailureException e) { abort(e); } catch (Throwable e) { abort(new TransactionFailureException( String.format("Exception from canCommit for transaction %d.", currentTx.getTransactionId()), e)); } }
/** * Collects the set of changes across all {@link TransactionAware}s by calling {@link TransactionAware#getTxChanges()} * and checks if conflicts will arise when the transaction is going to be committed. */ private void checkForConflicts() throws TransactionFailureException { Set<byte[]> changes = new TreeSet<>(Bytes.BYTES_COMPARATOR); for (TransactionAware txAware : getTransactionAwares()) { try { changes.addAll(txAware.getTxChanges()); } catch (Throwable t) { abort(createTransactionFailure("retrieve changes from", txAware, t)); } } // If there is no changes, no need to call canCommit if (changes.isEmpty()) { return; } try { txClient.canCommitOrThrow(currentTx, changes); } catch (TransactionFailureException e) { abort(e); } catch (Throwable e) { abort(new TransactionFailureException( String.format("Exception from canCommit for transaction %d.", currentTx.getTransactionId()), e)); } }
private void commitAndAssertSuccess(Transaction tx, TransactionAware txAware) throws Exception { txClient.canCommitOrThrow(tx, txAware.getTxChanges()); Assert.assertTrue(txAware.commitTx()); txClient.commitOrThrow(tx); }
table1.put(R1, a(C1), a(V1)); Collection<byte []> tx1Changes = table1.getTxChanges(); txClient.canCommitOrThrow(tx1, tx1Changes); Assert.assertTrue(table1.commitTx()); txClient.commitOrThrow(tx1); table2.put(R1, a(C1), a(V1)); Collection<byte []> tx2Changes = table2.getTxChanges(); txClient.canCommitOrThrow(tx2, tx2Changes); Assert.assertTrue(table2.commitTx()); txClient.commitOrThrow(tx2);
txClient.canCommitOrThrow(tx1, ((TransactionAware) table).getTxChanges()); Assert.assertTrue(((TransactionAware) table).commitTx()); txClient.commitOrThrow(tx1);
((TransactionAware) table).startTx(tx0); table.put(R1, a(C1), a(V1)); txClient.canCommitOrThrow(tx0, ((TransactionAware) table).getTxChanges()); Assert.assertTrue(((TransactionAware) table).commitTx()); txClient.commitOrThrow(tx0); ((TransactionAware) table2).startTx(tx2); table2.put(R1, a(C2), a(V2)); txClient.canCommitOrThrow(tx2, ((TransactionAware) table2).getTxChanges()); Assert.assertTrue(((TransactionAware) table2).commitTx()); txClient.commitOrThrow(tx2); ((TransactionAware) table2).startTx(tx4); table2.put(R1, a(C3), a(V3)); txClient.canCommitOrThrow(tx4, ((TransactionAware) table2).getTxChanges()); Assert.assertTrue(((TransactionAware) table2).commitTx()); txClient.commitOrThrow(tx4);
@Test public void testBatchWritableKeyIsIgnored() throws Exception { String tableName = "batchWritableTable"; getTableAdmin(CONTEXT1, tableName).create(); try { // write in a transaction, three times, with key = null, a, q, always Put with row = a Transaction tx = txClient.startShort(); Table table = getTable(CONTEXT1, tableName); ((TransactionAware) table).startTx(tx); table.write(null, new Put("a").add("x", "x")); table.write(new byte[]{'q'}, new Put("a").add("y", "y")); table.write(new byte[]{'a'}, new Put("a").add("z", "z")); txClient.canCommitOrThrow(tx, ((TransactionAware) table).getTxChanges()); ((TransactionAware) table).commitTx(); txClient.commitOrThrow(tx); // validate that all writes went to row a, and row q was not written tx = txClient.startShort(); ((TransactionAware) table).startTx(tx); Assert.assertTrue(table.get(new Get("q")).isEmpty()); Row row = table.get(new Get("a")); Assert.assertEquals(3, row.getColumns().size()); Assert.assertEquals("x", row.getString("x")); Assert.assertEquals("y", row.getString("y")); Assert.assertEquals("z", row.getString("z")); ((TransactionAware) table).commitTx(); txClient.abort(tx); } finally { getTableAdmin(CONTEXT1, tableName).drop(); } }
myTable1.put(R1, a(C1, C2, C3, C4, C5), a(V1, V2, V3, V4, V5)); myTable1.put(R2, a(C1), a(V2)); txClient.canCommitOrThrow(tx1, ((TransactionAware) myTable1).getTxChanges()); Assert.assertTrue(((TransactionAware) myTable1).commitTx()); txClient.commitOrThrow(tx1); myTable2.delete(R1, a(C4)); txClient.canCommitOrThrow(tx2, ((TransactionAware) myTable2).getTxChanges()); Assert.assertTrue(((TransactionAware) myTable2).commitTx()); txClient.commitOrThrow(tx2); myTable1.get(R1, C2, C5, Integer.MAX_VALUE)); txClient.canCommitOrThrow(tx3, ((TransactionAware) myTable1).getTxChanges()); Assert.assertTrue(((TransactionAware) myTable1).commitTx()); txClient.commitOrThrow(tx3);
txClient.canCommitOrThrow(tx1, ((TransactionAware) myTable1).getTxChanges()); Assert.assertTrue(((TransactionAware) myTable1).commitTx()); txClient.commitOrThrow(tx1); txClient.canCommitOrThrow(tx2, ((TransactionAware) myTable1).getTxChanges()); Assert.assertTrue(((TransactionAware) myTable1).commitTx()); txClient.commitOrThrow(tx2); txClient.canCommitOrThrow(tx3, ((TransactionAware) myTable1).getTxChanges()); Assert.assertTrue(((TransactionAware) myTable1).commitTx()); txClient.commitOrThrow(tx3);
myTable1.put(R4, a(C4), a(V4)); myTable1.put(R5, a(C5), a(V5)); txClient.canCommitOrThrow(tx1, ((TransactionAware) myTable1).getTxChanges()); Assert.assertTrue(((TransactionAware) myTable1).commitTx()); txClient.commitOrThrow(tx1); myTable2.delete(R3, a(C4)); txClient.canCommitOrThrow(tx2, ((TransactionAware) myTable2).getTxChanges()); Assert.assertTrue(((TransactionAware) myTable2).commitTx()); txClient.commitOrThrow(tx2); myTable1, new Scan(R2, R5)); txClient.canCommitOrThrow(tx3, ((TransactionAware) myTable1).getTxChanges()); Assert.assertTrue(((TransactionAware) myTable1).commitTx()); txClient.commitOrThrow(tx3);
((TransactionAware) myTable0).startTx(tx0); myTable0.put(R2, a(C2), a(V2)); txClient.canCommitOrThrow(tx0, ((TransactionAware) myTable0).getTxChanges()); Assert.assertTrue(((TransactionAware) myTable0).commitTx()); txClient.commitOrThrow(tx0);