/** * 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); }
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); } }
private LockInfo getTxnIdFromLockId(Connection dbConn, long extLockId) throws NoSuchLockException, MetaException, SQLException { Statement stmt = null; ResultSet rs = null; try { stmt = dbConn.createStatement(); String s = "select hl_lock_ext_id, hl_lock_int_id, hl_db, hl_table, " + "hl_partition, hl_lock_state, hl_lock_type, hl_txnid from HIVE_LOCKS where " + "hl_lock_ext_id = " + extLockId; LOG.debug("Going to execute query <" + s + ">"); rs = stmt.executeQuery(s); if (!rs.next()) { return null; } LockInfo info = new LockInfo(rs); LOG.debug("getTxnIdFromLockId(" + extLockId + ") Return " + JavaUtils.txnIdToString(info.txnId)); return info; } finally { close(rs); closeStmt(stmt); } }
/** * Heartbeats on the lock table. This commits, so do not enter it with any state. * Should not be called on a lock that belongs to transaction. */ private void heartbeatLock(Connection dbConn, long extLockId) throws NoSuchLockException, SQLException, MetaException { // If the lock id is 0, then there are no locks in this heartbeat if (extLockId == 0) return; Statement stmt = null; try { stmt = dbConn.createStatement(); long now = getDbTime(dbConn); String s = "update HIVE_LOCKS set hl_last_heartbeat = " + now + " where hl_lock_ext_id = " + extLockId; LOG.debug("Going to execute update <" + s + ">"); int rc = stmt.executeUpdate(s); if (rc < 1) { LOG.debug("Going to rollback"); dbConn.rollback(); throw new NoSuchLockException("No such lock: " + JavaUtils.lockIdToString(extLockId)); } LOG.debug("Going to commit"); dbConn.commit(); } finally { closeStmt(stmt); } }
private List<LockInfo> getLockInfoFromLockId(Connection dbConn, long extLockId) throws NoSuchLockException, MetaException, SQLException { Statement stmt = null; try { stmt = dbConn.createStatement(); String s = "select hl_lock_ext_id, hl_lock_int_id, hl_db, hl_table, " + "hl_partition, hl_lock_state, hl_lock_type, hl_txnid from HIVE_LOCKS where " + "hl_lock_ext_id = " + extLockId; LOG.debug("Going to execute query <" + s + ">"); ResultSet rs = stmt.executeQuery(s); boolean sawAtLeastOne = false; List<LockInfo> ourLockInfo = new ArrayList<>(); while (rs.next()) { ourLockInfo.add(new LockInfo(rs)); sawAtLeastOne = true; } if (!sawAtLeastOne) { throw new MetaException("This should never happen! We already " + "checked the lock(" + JavaUtils.lockIdToString(extLockId) + ") existed but now we can't find it!"); } return ourLockInfo; } finally { closeStmt(stmt); } }
} finally { close(rs); closeStmt(stmt);
throw new MetaException(msg); } finally { closeStmt(stmt);
closeStmt(stmt);
closeStmt(stmt); closeDbConn(dbConn);
closeStmt(pst); pst = sqlGenerator.prepareStmtWithParameters(dbConn, s, params); LOG.debug("Going to execute query<" + s.replaceAll("\\?", "{}") + ">", closeStmt(pst); pst = sqlGenerator.prepareStmtWithParameters(dbConn, s, params); LOG.debug("Going to execute query<" + s.replaceAll("\\?", "{}") + ">", closeStmt(pst); close(rs);
StringUtils.stringifyException(e)); } finally { closeStmt(pst); closeDbConn(dbConn);
StringUtils.stringifyException(e)); } finally { closeStmt(stmt); closeDbConn(dbConn);
"(mrl_txn_id, mrl_db_name, mrl_tbl_name, mrl_last_heartbeat) values (" + txnId + ", ?, ?, " + Instant.now().toEpochMilli() + ")"; closeStmt(pst); pst = sqlGenerator.prepareStmtWithParameters(dbConn, insertQ, params); LOG.debug("Going to execute update <" + insertQ.replaceAll("\\?", "{}") + ">",
JavaUtils.lockIdToString(extLockId) + " " + StringUtils.stringifyException(e)); } finally { closeStmt(stmt); closeDbConn(dbConn);
closeStmt(pStmt); pStmt = sqlGenerator.prepareStmtWithParameters(dbConn, sql, params); LOG.debug("Going to execute insert <" + sql.replaceAll("\\?", "{}") + ">", if (insertPreparedStmts != null) { for (PreparedStatement pst : insertPreparedStmts) { closeStmt(pst); closeStmt(pStmt); close(rs, stmt, dbConn); if(handle != null) {
if (insertPreparedStmts != null) { for(PreparedStatement pst : insertPreparedStmts) { closeStmt(pst);
closeStmt(stmt); closeDbConn(dbConn);