private static void shouldNeverHappen(long txnid, long extLockId, long intLockId) { throw new RuntimeException("This should never happen: " + JavaUtils.txnIdToString(txnid) + " " + JavaUtils.lockIdToString(extLockId) + " " + intLockId); }
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); } }
/** * 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); } }
@Override public String toString() { return JavaUtils.lockIdToString(extLockId) + " intLockId:" + intLockId + " " + JavaUtils.txnIdToString(txnId) + " db:" + db + " table:" + table + " partition:" + partition + " state:" + (state == null ? "null" : state.toString()) + " type:" + (type == null ? "null" : type.toString()); } private boolean isDbLock() {
dbConn.rollback(); StringBuilder sb = new StringBuilder("No such lock(s): (" + JavaUtils.lockIdToString(extLockId) + ":"); ResultSet rs = stmt.executeQuery("select hl_lock_int_id from HIVE_LOCKS where hl_lock_ext_id = " + extLockId); while(rs.next()) {
LOG.debug("checkLock(): Setting savepoint. extLockId=" + JavaUtils.lockIdToString(extLockId)); Savepoint save = dbConn.setSavepoint(); StringBuilder query = new StringBuilder("select hl_lock_ext_id, " + if(writeSet.get(0).txnId == 0) { throw new IllegalStateException("Found Write lock for " + JavaUtils.lockIdToString(extLockId) + " but no txnid");
JavaUtils.lockIdToString(rqst.getLockid()) + ")"); checkRetryable(dbConn, e, "unlock(" + rqst + ")"); throw new MetaException("Unable to update transaction database " + JavaUtils.lockIdToString(extLockId) + " " + StringUtils.stringifyException(e)); } finally { closeStmt(stmt);
throw new NoSuchLockException("No such lock " + JavaUtils.lockIdToString(extLockId)); checkRetryable(dbConn, e, "checkLock(" + rqst + " )"); throw new MetaException("Unable to update transaction database " + JavaUtils.lockIdToString(extLockId) + " " + StringUtils.stringifyException(e)); } finally { closeDbConn(dbConn);