public NoSuchTxnException deepCopy() { return new NoSuchTxnException(this); }
private void heartbeatTxn(Connection dbConn, long txnid) throws NoSuchTxnException, TxnAbortedException, SQLException, MetaException { // If the txnid is 0, then there are no transactions in this heartbeat if (txnid == 0) return; Statement stmt = null; try { stmt = dbConn.createStatement(); long now = getDbTime(dbConn); String s = "update TXNS set txn_last_heartbeat = " + now + " where txn_id = " + txnid + " and txn_state = '" + TXN_OPEN + "'"; LOG.debug("Going to execute update <" + s + ">"); int rc = stmt.executeUpdate(s); if (rc < 1) { ensureValidTxn(dbConn, txnid, stmt); // This should now throw some useful exception. LOG.warn("Can neither heartbeat txn nor confirm it as invalid."); dbConn.rollback(); throw new NoSuchTxnException("No such txn: " + txnid); } LOG.debug("Going to commit"); dbConn.commit(); } finally { closeStmt(stmt); } }
/** * Used to raise an informative error when the caller expected a txn in a particular TxnStatus * but found it in some other status */ private static void raiseTxnUnexpectedState(TxnStatus actualStatus, long txnid) throws NoSuchTxnException, TxnAbortedException { switch (actualStatus) { case ABORTED: throw new TxnAbortedException("Transaction " + JavaUtils.txnIdToString(txnid) + " already aborted"); case COMMITTED: throw new NoSuchTxnException("Transaction " + JavaUtils.txnIdToString(txnid) + " is already committed."); case UNKNOWN: throw new NoSuchTxnException("No such transaction " + JavaUtils.txnIdToString(txnid)); case OPEN: throw new NoSuchTxnException(JavaUtils.txnIdToString(txnid) + " is " + TxnStatus.OPEN); default: throw new IllegalArgumentException("Unknown TxnStatus " + actualStatus); } } /**
if (alreadyCommitted) { throw new NoSuchTxnException("Transaction " + JavaUtils.txnIdToString(txnid) + " is already committed."); throw new NoSuchTxnException("No such transaction " + JavaUtils.txnIdToString(txnid));
@Test public void testRunHeartbeatFailsNoSuchTxnException() throws Exception { NoSuchTxnException exception = new NoSuchTxnException(); doThrow(exception).when(mockMetaStoreClient).heartbeat(TRANSACTION_ID, LOCK_ID); task.run(); verify(mockListener).lockFailed(LOCK_ID, TRANSACTION_ID, Arrays.asList("DB.TABLE"), exception); }
@Test public void testHeartbeatFailsNoSuchTxnException() throws Exception { Throwable t = new NoSuchTxnException(); doThrow(t).when(mockMetaStoreClient).heartbeat(TRANSACTION_ID, LOCK_ID); HeartbeatTimerTask task = new HeartbeatTimerTask(mockMetaStoreClient, mockListener, TRANSACTION_ID, SOURCES, LOCK_ID); task.run(); verify(mockListener).lockFailed(LOCK_ID, TRANSACTION_ID, Lock.asStrings(SOURCES), t); }
public NoSuchTxnException deepCopy() { return new NoSuchTxnException(this); }
public NoSuchTxnException deepCopy() { return new NoSuchTxnException(this); }
public NoSuchTxnException deepCopy() { return new NoSuchTxnException(this); }
LOG.debug("Going to rollback"); dbConn.rollback(); throw new NoSuchTxnException("No such transaction: " + txnid);
LOG.debug("Going to rollback"); dbConn.rollback(); throw new NoSuchTxnException("No such transaction: " + txnid);
public void abortTxn(AbortTxnRequest rqst) throws NoSuchTxnException, MetaException { long txnid = rqst.getTxnid(); try { Connection dbConn = null; try { dbConn = getDbConn(Connection.TRANSACTION_SERIALIZABLE); if (abortTxns(dbConn, Collections.singletonList(txnid)) != 1) { LOG.debug("Going to rollback"); dbConn.rollback(); throw new NoSuchTxnException("No such transaction: " + txnid); } LOG.debug("Going to commit"); dbConn.commit(); } catch (SQLException e) { LOG.debug("Going to rollback"); rollbackDBConn(dbConn); checkRetryable(dbConn, e, "abortTxn(" + rqst + ")"); throw new MetaException("Unable to update transaction database " + StringUtils.stringifyException(e)); } finally { closeDbConn(dbConn); } } catch (RetryException e) { abortTxn(rqst); } }
public void abortTxn(AbortTxnRequest rqst) throws NoSuchTxnException, MetaException { long txnid = rqst.getTxnid(); try { Connection dbConn = null; try { dbConn = getDbConn(Connection.TRANSACTION_SERIALIZABLE); if (abortTxns(dbConn, Collections.singletonList(txnid)) != 1) { LOG.debug("Going to rollback"); dbConn.rollback(); throw new NoSuchTxnException("No such transaction: " + txnid); } LOG.debug("Going to commit"); dbConn.commit(); } catch (SQLException e) { LOG.debug("Going to rollback"); rollbackDBConn(dbConn); checkRetryable(dbConn, e, "abortTxn(" + rqst + ")"); throw new MetaException("Unable to update transaction database " + StringUtils.stringifyException(e)); } finally { closeDbConn(dbConn); } } catch (RetryException e) { abortTxn(rqst); } }