use of org.apache.hadoop.hive.metastore.api.NoSuchLockException in project hive by apache.
the class TestTxnHandler method testLockTimeout.
@Test
public void testLockTimeout() throws Exception {
long timeout = txnHandler.setTimeout(1);
try {
LockComponent comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
comp.setTablename("mytable");
comp.setPartitionname("mypartition");
comp.setOperationType(DataOperationType.NO_TXN);
List<LockComponent> components = new ArrayList<LockComponent>(1);
components.add(comp);
LockRequest req = new LockRequest(components, "me", "localhost");
LockResponse res = txnHandler.lock(req);
assertTrue(res.getState() == LockState.ACQUIRED);
Thread.sleep(10);
txnHandler.performTimeOuts();
txnHandler.checkLock(new CheckLockRequest(res.getLockid()));
fail("Told there was a lock, when it should have timed out.");
} catch (NoSuchLockException e) {
} finally {
txnHandler.setTimeout(timeout);
}
}
use of org.apache.hadoop.hive.metastore.api.NoSuchLockException in project hive by apache.
the class TestTxnHandler method testHeartbeatNoLock.
@Test
public void testHeartbeatNoLock() throws Exception {
HeartbeatRequest h = new HeartbeatRequest();
h.setLockid(29389839L);
try {
txnHandler.heartbeat(h);
fail("Told there was a lock, when there wasn't.");
} catch (NoSuchLockException e) {
}
}
use of org.apache.hadoop.hive.metastore.api.NoSuchLockException in project hive by apache.
the class TestTxnHandler method testCheckLockNoSuchLock.
@Test
public void testCheckLockNoSuchLock() throws Exception {
try {
txnHandler.checkLock(new CheckLockRequest(23L));
fail("Allowed to check lock on non-existent lock");
} catch (NoSuchLockException e) {
}
}
use of org.apache.hadoop.hive.metastore.api.NoSuchLockException in project hive by apache.
the class TestHeartbeatTimerTask method testRunHeartbeatFailsNoSuchLockException.
@Test
public void testRunHeartbeatFailsNoSuchLockException() throws Exception {
NoSuchLockException exception = new NoSuchLockException();
doThrow(exception).when(mockMetaStoreClient).heartbeat(TRANSACTION_ID, LOCK_ID);
task.run();
verify(mockListener).lockFailed(LOCK_ID, TRANSACTION_ID, Arrays.asList("DB.TABLE"), exception);
}
use of org.apache.hadoop.hive.metastore.api.NoSuchLockException in project hive by apache.
the class TxnHandler method acquire.
private void acquire(Connection dbConn, Statement stmt, List<LockInfo> locksBeingChecked) throws SQLException, NoSuchLockException, MetaException {
if (locksBeingChecked == null || locksBeingChecked.isEmpty()) {
return;
}
long txnId = locksBeingChecked.get(0).txnId;
long extLockId = locksBeingChecked.get(0).extLockId;
long now = getDbTime(dbConn);
String s = "update HIVE_LOCKS set hl_lock_state = '" + LOCK_ACQUIRED + "', " + // if lock is part of txn, heartbeat info is in txn record
"hl_last_heartbeat = " + (isValidTxn(txnId) ? 0 : now) + ", hl_acquired_at = " + now + ",HL_BLOCKEDBY_EXT_ID=NULL,HL_BLOCKEDBY_INT_ID=null" + " where hl_lock_ext_id = " + extLockId;
LOG.debug("Going to execute update <" + s + ">");
int rc = stmt.executeUpdate(s);
if (rc < locksBeingChecked.size()) {
LOG.debug("Going to rollback acquire(Connection dbConn, Statement stmt, List<LockInfo> locksBeingChecked)");
dbConn.rollback();
/*select all locks for this ext ID and see which ones are missing*/
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()) {
int intLockId = rs.getInt(1);
int idx = 0;
for (; idx < locksBeingChecked.size(); idx++) {
LockInfo expectedLock = locksBeingChecked.get(idx);
if (expectedLock != null && expectedLock.intLockId == intLockId) {
locksBeingChecked.set(idx, null);
break;
}
}
}
for (LockInfo expectedLock : locksBeingChecked) {
if (expectedLock != null) {
sb.append(expectedLock.intLockId).append(",");
}
}
sb.append(") ").append(JavaUtils.txnIdToString(txnId));
close(rs);
throw new NoSuchLockException(sb.toString());
}
}
Aggregations