Search in sources :

Example 1 with NoSuchLockException

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);
    }
}
Also used : NoSuchLockException(org.apache.hadoop.hive.metastore.api.NoSuchLockException) LockComponent(org.apache.hadoop.hive.metastore.api.LockComponent) LockResponse(org.apache.hadoop.hive.metastore.api.LockResponse) ArrayList(java.util.ArrayList) CheckLockRequest(org.apache.hadoop.hive.metastore.api.CheckLockRequest) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) CheckLockRequest(org.apache.hadoop.hive.metastore.api.CheckLockRequest) Test(org.junit.Test)

Example 2 with NoSuchLockException

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) {
    }
}
Also used : NoSuchLockException(org.apache.hadoop.hive.metastore.api.NoSuchLockException) HeartbeatRequest(org.apache.hadoop.hive.metastore.api.HeartbeatRequest) Test(org.junit.Test)

Example 3 with NoSuchLockException

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) {
    }
}
Also used : NoSuchLockException(org.apache.hadoop.hive.metastore.api.NoSuchLockException) CheckLockRequest(org.apache.hadoop.hive.metastore.api.CheckLockRequest) Test(org.junit.Test)

Example 4 with NoSuchLockException

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);
}
Also used : NoSuchLockException(org.apache.hadoop.hive.metastore.api.NoSuchLockException) Test(org.junit.Test)

Example 5 with NoSuchLockException

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());
    }
}
Also used : NoSuchLockException(org.apache.hadoop.hive.metastore.api.NoSuchLockException) ResultSet(java.sql.ResultSet) Savepoint(java.sql.Savepoint)

Aggregations

NoSuchLockException (org.apache.hadoop.hive.metastore.api.NoSuchLockException)9 Test (org.junit.Test)6 CheckLockRequest (org.apache.hadoop.hive.metastore.api.CheckLockRequest)4 ArrayList (java.util.ArrayList)3 LockComponent (org.apache.hadoop.hive.metastore.api.LockComponent)3 LockRequest (org.apache.hadoop.hive.metastore.api.LockRequest)3 LockResponse (org.apache.hadoop.hive.metastore.api.LockResponse)3 Savepoint (java.sql.Savepoint)2 HeartbeatRequest (org.apache.hadoop.hive.metastore.api.HeartbeatRequest)2 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 AbortTxnRequest (org.apache.hadoop.hive.metastore.api.AbortTxnRequest)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1