@Override public long getTransactionId() { Transaction tx = getCurrentTransaction(); return tx == null ? HConstants.LATEST_TIMESTAMP : tx.getTransactionId(); // First write pointer - won't change with checkpointing }
@Override public void canCommitOrThrow(Transaction tx, Collection<byte[]> changeIds) throws TransactionFailureException { if (!changeIds.isEmpty()) { txManager.canCommit(tx.getTransactionId(), changeIds); } }
@Override public long getTransactionId() { Transaction tx = getCurrentTransaction(); return tx == null ? HConstants.LATEST_TIMESTAMP : tx.getTransactionId(); // First write pointer - won't change with checkpointing }
private Location getQuarantineLocation() throws IOException { // each transaction must not share its quarantine directory with another transaction return files.getBaseLocation().append(QUARANTINE_DIR + "." + tx.getTransactionId()); }
private Location getQuarantineLocation() throws IOException { // each transaction must not share its quarantine directory with another transaction return files.getBaseLocation().append(QUARANTINE_DIR + "." + tx.getTransactionId()); }
@Override public long getTransactionId() { Transaction tx = getCurrentTransaction(); return tx == null ? HConstants.LATEST_TIMESTAMP : tx.getTransactionId(); // First write pointer - won't change with checkpointing }
@Override public Collection<byte[]> getTxChanges() { if (tx == null) { throw new IllegalStateException("Transaction has not started yet"); } return Collections.singleton(Bytes.concat(fenceId, Longs.toByteArray(tx.getTransactionId()))); }
@Override public Void execute(TransactionServiceThriftClient client) throws Exception { client.commit(tx.getTransactionId(), tx.getWritePointer()); return null; } });
@Override public void commitOrThrow(Transaction tx) throws TransactionFailureException { txManager.commit(tx.getTransactionId(), tx.getWritePointer()); }
/** * Commits the current transaction. */ private void commit() throws TransactionFailureException { try { txClient.commitOrThrow(currentTx); } catch (TransactionFailureException e) { abort(e); } catch (Throwable e) { abort(new TransactionFailureException( String.format("Exception from commit for transaction %d.", currentTx.getTransactionId()), e)); } }
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 } }
/** * Commits the current transaction. */ private void commit() throws TransactionFailureException { try { txClient.commitOrThrow(currentTx); } catch (TransactionFailureException e) { abort(e); } catch (Throwable e) { abort(new TransactionFailureException( String.format("Exception from commit for transaction %d.", currentTx.getTransactionId()), e)); } }
@Override public TransactionContext newTransactionContext() throws TransactionFailureException { if (txContext != null && txContext.getCurrentTransaction() != null) { throw new TransactionFailureException("Attempted to start a transaction within active transaction " + txContext.getCurrentTransaction().getTransactionId()); } dismissTransactionContext(); txContext = new DelayedDiscardingTransactionContext(txClient, activeTxAwares.values()); return txContext; }
@Override public TransactionContext newTransactionContext() throws TransactionFailureException { if (txContext != null && txContext.getCurrentTransaction() != null) { throw new TransactionFailureException("Attempted to start a transaction within active transaction " + txContext.getCurrentTransaction().getTransactionId()); } dismissTransactionContext(); txContext = new DelayedDiscardingTransactionContext(txClient, activeTxAwares.values()); return txContext; }
private Transaction startTx(Iterable<TransactionAware> txAwares) throws TransactionFailureException { Transaction transaction = txClient.startLong(); for (TransactionAware txAware : txAwares) { try { txAware.startTx(transaction); } catch (Throwable t) { txClient.abort(transaction); throw new TransactionFailureException( String.format("Unable to start transaction-aware '%s' for transaction %d. ", txAware.getTransactionAwareName(), transaction.getTransactionId()), t); } } return transaction; }
private Transaction startTx(Iterable<TransactionAware> txAwares) throws TransactionFailureException { Transaction transaction = txClient.startLong(); for (TransactionAware txAware : txAwares) { try { txAware.startTx(transaction); } catch (Throwable t) { txClient.abort(transaction); throw new TransactionFailureException( String.format("Unable to start transaction-aware '%s' for transaction %d. ", txAware.getTransactionAwareName(), transaction.getTransactionId()), t); } } return transaction; }
@Override public void canCommitOrThrow(Transaction tx, Collection<byte[]> changeIds) throws TransactionFailureException { if (failCanCommitOnce) { failCanCommitOnce = false; throw new TransactionConflictException(tx.getTransactionId(), null, null); } else { super.canCommitOrThrow(tx, changeIds); } }
@Override public void commitOrThrow(Transaction tx) throws TransactionFailureException { if (failCommits-- > 0) { throw new TransactionConflictException(tx.getTransactionId(), null, null); } else { state = CommitState.Committed; super.commitOrThrow(tx); } }
/** * Creates a new transaction for a checkpoint operation, copying all members from the original transaction, * with the updated checkpoint write pointers. * * @param toCopy the original transaction containing the state to copy * @param writePointer the new write pointer to use for the transaction * @param checkpointPointers the list of write pointers added from checkpoints on the transaction */ public Transaction(Transaction toCopy, long writePointer, long[] checkpointPointers) { this(toCopy.getReadPointer(), toCopy.getTransactionId(), writePointer, toCopy.getInvalids(), toCopy.getInProgress(), toCopy.getFirstShortInProgress(), toCopy.getType(), checkpointPointers, toCopy.getVisibilityLevel()); }
public static TTransaction wrap(Transaction tx) { return new TTransaction(tx.getTransactionId(), tx.getReadPointer(), Longs.asList(tx.getInvalids()), Longs.asList(tx.getInProgress()), tx.getFirstShortInProgress(), getTTransactionType(tx.getType()), tx.getWritePointer(), Longs.asList(tx.getCheckpointWritePointers()), getTVisibilityLevel(tx.getVisibilityLevel())); }