private Connection getDbConn(int isolationLevel, DataSource connPool) throws SQLException { int rc = doRetryOnConnPool ? 10 : 1; Connection dbConn = null; while (true) { try { dbConn = connPool.getConnection(); dbConn.setAutoCommit(false); dbConn.setTransactionIsolation(isolationLevel); return dbConn; } catch (SQLException e){ closeDbConn(dbConn); if ((--rc) <= 0) throw e; LOG.error("There is a problem with a connection from the pool, retrying(rc=" + rc + "): " + getMessage(e), e); } } }
/** * Close all 3 JDBC artifacts in order: {@code rs stmt dbConn} */ static void close(ResultSet rs, Statement stmt, Connection dbConn) { close(rs); closeStmt(stmt); closeDbConn(dbConn); }
closeDbConn(dbConn);
@Override @RetrySemantics.Idempotent public long getTargetTxnId(String replPolicy, long sourceTxnId) throws MetaException { try { Connection dbConn = null; try { lockInternal(); dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED); List<Long> targetTxnIds = getTargetTxnIdList(replPolicy, Collections.singletonList(sourceTxnId), dbConn); if (targetTxnIds.isEmpty()) { LOG.info("Txn {} not present for repl policy {}", sourceTxnId, replPolicy); return -1; } assert (targetTxnIds.size() == 1); return targetTxnIds.get(0); } catch (SQLException e) { LOG.debug("Going to rollback"); rollbackDBConn(dbConn); checkRetryable(dbConn, e, "getTargetTxnId(" + replPolicy + sourceTxnId + ")"); throw new MetaException("Unable to get target transaction id " + StringUtils.stringifyException(e)); } finally { closeDbConn(dbConn); unlockInternal(); } } catch (RetryException e) { return getTargetTxnId(replPolicy, sourceTxnId); } }
+ StringUtils.stringifyException(e)); } finally { closeDbConn(dbConn);
} finally { closeStmt(pst); closeDbConn(dbConn);
} finally { closeStmt(stmt); closeDbConn(dbConn);
closeStmt(pst); closeStmt(stmt); closeDbConn(dbConn); if(handle != null) { handle.releaseLocks();
} finally { closeStmt(stmt); closeDbConn(dbConn);
private LockResponse checkLockWithRetry(Connection dbConn, long extLockId, long txnId) throws NoSuchLockException, NoSuchTxnException, TxnAbortedException, MetaException { try { try { lockInternal(); if(dbConn.isClosed()) { //should only get here if retrying this op dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED); } return checkLock(dbConn, extLockId); } catch (SQLException e) { LOG.debug("Going to rollback"); rollbackDBConn(dbConn); checkRetryable(dbConn, e, "checkLockWithRetry(" + extLockId + "," + txnId + ")"); throw new MetaException("Unable to update transaction database " + StringUtils.stringifyException(e)); } finally { unlockInternal(); closeDbConn(dbConn); } } catch(RetryException e) { return checkLockWithRetry(dbConn, extLockId, txnId); } } /**
throw new MetaException("Unable to add write notification event " + StringUtils.stringifyException(e)); } finally{ closeDbConn(dbConn); unlockInternal();
"'scooby.com')"); conn.commit(); tHndlr.closeDbConn(conn); } finally { conn1.rollback(); tHndlr.closeDbConn(conn1); conn2.rollback(); tHndlr.closeDbConn(conn2);
+ StringUtils.stringifyException(e)); } finally { closeDbConn(dbConn);
throw new RuntimeException(e); } finally { closeDbConn(dbConn);
/** * {@code ids} should only have txnid or lockid but not both, ideally. * Currently DBTxnManager.heartbeat() enforces this. */ @Override @RetrySemantics.SafeToRetry public void heartbeat(HeartbeatRequest ids) throws NoSuchTxnException, NoSuchLockException, TxnAbortedException, MetaException { try { Connection dbConn = null; try { dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED); heartbeatLock(dbConn, ids.getLockid()); heartbeatTxn(dbConn, ids.getTxnid()); } catch (SQLException e) { LOG.debug("Going to rollback"); rollbackDBConn(dbConn); checkRetryable(dbConn, e, "heartbeat(" + ids + ")"); throw new MetaException("Unable to select from transaction database " + StringUtils.stringifyException(e)); } finally { closeDbConn(dbConn); } } catch (RetryException e) { heartbeat(ids); } } @Override
closeDbConn(dbConn);
closeDbConn(dbConn);
JavaUtils.lockIdToString(extLockId) + " " + StringUtils.stringifyException(e)); } finally { closeDbConn(dbConn); unlockInternal();
/** * Close all 3 JDBC artifacts in order: {@code rs stmt dbConn} */ void close(ResultSet rs, Statement stmt, Connection dbConn) { close(rs); closeStmt(stmt); closeDbConn(dbConn); } /**
/** * Close all 3 JDBC artifacts in order: {@code rs stmt dbConn} */ void close(ResultSet rs, Statement stmt, Connection dbConn) { close(rs); closeStmt(stmt); closeDbConn(dbConn); } /**