Connection getDbConn(int isolationLevel) throws SQLException { return getDbConn(isolationLevel, connPool); } private Connection getDbConn(int isolationLevel, DataSource connPool) throws SQLException {
/** * For testing only, do not use. */ @VisibleForTesting public int numLocksInLockTable() throws SQLException, MetaException { Connection dbConn = null; Statement stmt = null; ResultSet rs = null; try { dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED); stmt = dbConn.createStatement(); String s = "select count(*) from HIVE_LOCKS"; LOG.debug("Going to execute query <" + s + ">"); rs = stmt.executeQuery(s); rs.next(); int rc = rs.getInt(1); // Necessary to clean up the transaction in the db. dbConn.rollback(); return rc; } finally { close(rs, stmt, dbConn); } }
try { try { dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED); stmt = dbConn.createStatement(); String s = "select count(*) from TXNS where txn_state = '" + TXN_OPEN + "'";
ResultSet rs = null; try { dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED); stmt = dbConn.createStatement(); rs = stmt.executeQuery("select ntxn_next - 1 from NEXT_TXN_ID");
private enum LockAction {ACQUIRE, WAIT, KEEP_LOOKING}
try { lockInternal(); dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED); stmt = dbConn.createStatement();
dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED);
try { lockInternal(); dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED); String s = "update MATERIALIZATION_REBUILD_LOCKS" + " set mrl_last_heartbeat = " + Instant.now().toEpochMilli() +
@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); } }
Connection dbConn = null; try { dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED); int numAborted = abortTxns(dbConn, txnids, false); if (numAborted != txnids.size()) {
try { try { dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED); stmt = dbConn.createStatement(); String s = "select cq_database, cq_table, cq_partition, cq_state, cq_type, cq_worker_id, " +
dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED);
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); } } /**
dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED); MetaStoreListenerNotifier.notifyEventWithDirectSql(transactionalListeners, EventMessage.EventType.ACID_WRITE, acidWriteEvent, dbConn, sqlGenerator);
try { lockInternal(); dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED);
try { lockInternal(); dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED); stmt = dbConn.createStatement();
dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED);
dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED); determineDatabaseProduct(dbConn); sqlGenerator = new SQLGenerator(dbProduct, conf);
/** * {@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
try { lockInternal(); dbConn = getDbConn(Connection.TRANSACTION_READ_COMMITTED);