Search in sources :

Example 41 with LockResponse

use of org.apache.hadoop.hive.metastore.api.LockResponse in project hive by apache.

the class TestTxnHandler method testMultipleLock.

@Test
public void testMultipleLock() throws Exception {
    // Test more than one lock can be handled in a lock request
    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>(2);
    components.add(comp);
    comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setPartitionname("anotherpartition");
    comp.setOperationType(DataOperationType.NO_TXN);
    components.add(comp);
    LockRequest req = new LockRequest(components, "me", "localhost");
    LockResponse res = txnHandler.lock(req);
    long lockid = res.getLockid();
    assertTrue(res.getState() == LockState.ACQUIRED);
    res = txnHandler.checkLock(new CheckLockRequest(lockid));
    assertTrue(res.getState() == LockState.ACQUIRED);
    txnHandler.unlock(new UnlockRequest(lockid));
    assertEquals(0, txnHandler.numLocksInLockTable());
}
Also used : 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) UnlockRequest(org.apache.hadoop.hive.metastore.api.UnlockRequest) Test(org.junit.Test)

Example 42 with LockResponse

use of org.apache.hadoop.hive.metastore.api.LockResponse in project hive by apache.

the class TestTxnHandler method testLockSameTable.

@Test
public void testLockSameTable() throws Exception {
    // Test that two different tables don't collide on their locks
    LockComponent comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    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);
    comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setOperationType(DataOperationType.NO_TXN);
    components.clear();
    components.add(comp);
    req = new LockRequest(components, "me", "localhost");
    res = txnHandler.lock(req);
    assertTrue(res.getState() == LockState.WAITING);
}
Also used : LockComponent(org.apache.hadoop.hive.metastore.api.LockComponent) LockResponse(org.apache.hadoop.hive.metastore.api.LockResponse) ArrayList(java.util.ArrayList) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) CheckLockRequest(org.apache.hadoop.hive.metastore.api.CheckLockRequest) Test(org.junit.Test)

Example 43 with LockResponse

use of org.apache.hadoop.hive.metastore.api.LockResponse in project hive by apache.

the class TestTxnHandler method testMultipleLockWait.

@Test
public void testMultipleLockWait() throws Exception {
    // Test that two shared read locks can share a partition
    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>(2);
    components.add(comp);
    comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setPartitionname("anotherpartition");
    comp.setOperationType(DataOperationType.NO_TXN);
    components.add(comp);
    LockRequest req = new LockRequest(components, "me", "localhost");
    LockResponse res = txnHandler.lock(req);
    long lockid1 = res.getLockid();
    assertTrue(res.getState() == LockState.ACQUIRED);
    comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setPartitionname("mypartition");
    comp.setOperationType(DataOperationType.NO_TXN);
    components = new ArrayList<LockComponent>(1);
    components.add(comp);
    req = new LockRequest(components, "me", "localhost");
    res = txnHandler.lock(req);
    long lockid2 = res.getLockid();
    assertTrue(res.getState() == LockState.WAITING);
    txnHandler.unlock(new UnlockRequest(lockid1));
    res = txnHandler.checkLock(new CheckLockRequest(lockid2));
    assertTrue(res.getState() == LockState.ACQUIRED);
}
Also used : 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) UnlockRequest(org.apache.hadoop.hive.metastore.api.UnlockRequest) Test(org.junit.Test)

Example 44 with LockResponse

use of org.apache.hadoop.hive.metastore.api.LockResponse in project hive by apache.

the class TestTxnHandler method testCheckLockTxnAborted.

@Test
public void testCheckLockTxnAborted() throws Exception {
    // Test that when a transaction is aborted, the heartbeat fails
    long txnid = openTxn();
    LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setPartitionname("mypartition");
    comp.setOperationType(DataOperationType.DELETE);
    List<LockComponent> components = new ArrayList<LockComponent>(1);
    components.add(comp);
    LockRequest req = new LockRequest(components, "me", "localhost");
    req.setTxnid(txnid);
    LockResponse res = txnHandler.lock(req);
    long lockid = res.getLockid();
    txnHandler.abortTxn(new AbortTxnRequest(txnid));
    try {
        // This will throw NoSuchLockException (even though it's the
        // transaction we've closed) because that will have deleted the lock.
        txnHandler.checkLock(new CheckLockRequest(lockid));
        fail("Allowed to check lock on aborted transaction.");
    } catch (NoSuchLockException e) {
    }
}
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) AbortTxnRequest(org.apache.hadoop.hive.metastore.api.AbortTxnRequest) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) CheckLockRequest(org.apache.hadoop.hive.metastore.api.CheckLockRequest) Test(org.junit.Test)

Example 45 with LockResponse

use of org.apache.hadoop.hive.metastore.api.LockResponse in project hive by apache.

the class TestTxnHandler method testCheckLockAcquireAfterWaiting.

@Test
public void testCheckLockAcquireAfterWaiting() throws Exception {
    LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setPartitionname("mypartition");
    comp.setOperationType(DataOperationType.DELETE);
    List<LockComponent> components = new ArrayList<LockComponent>(1);
    components.add(comp);
    LockRequest req = new LockRequest(components, "me", "localhost");
    long txnId = openTxn();
    req.setTxnid(txnId);
    LockResponse res = txnHandler.lock(req);
    long lockid1 = res.getLockid();
    assertTrue(res.getState() == LockState.ACQUIRED);
    comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setPartitionname("mypartition");
    comp.setOperationType(DataOperationType.UPDATE);
    components.clear();
    components.add(comp);
    req = new LockRequest(components, "me", "localhost");
    req.setTxnid(openTxn());
    res = txnHandler.lock(req);
    long lockid2 = res.getLockid();
    assertTrue(res.getState() == LockState.WAITING);
    txnHandler.abortTxn(new AbortTxnRequest(txnId));
    res = txnHandler.checkLock(new CheckLockRequest(lockid2));
    assertTrue(res.getState() == LockState.ACQUIRED);
}
Also used : 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) AbortTxnRequest(org.apache.hadoop.hive.metastore.api.AbortTxnRequest) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) CheckLockRequest(org.apache.hadoop.hive.metastore.api.CheckLockRequest) Test(org.junit.Test)

Aggregations

LockResponse (org.apache.hadoop.hive.metastore.api.LockResponse)64 LockRequest (org.apache.hadoop.hive.metastore.api.LockRequest)61 LockComponent (org.apache.hadoop.hive.metastore.api.LockComponent)60 Test (org.junit.Test)60 ArrayList (java.util.ArrayList)58 CheckLockRequest (org.apache.hadoop.hive.metastore.api.CheckLockRequest)33 Table (org.apache.hadoop.hive.metastore.api.Table)24 ShowCompactRequest (org.apache.hadoop.hive.metastore.api.ShowCompactRequest)22 ShowCompactResponse (org.apache.hadoop.hive.metastore.api.ShowCompactResponse)22 ShowCompactResponseElement (org.apache.hadoop.hive.metastore.api.ShowCompactResponseElement)17 CommitTxnRequest (org.apache.hadoop.hive.metastore.api.CommitTxnRequest)15 AbortTxnRequest (org.apache.hadoop.hive.metastore.api.AbortTxnRequest)11 Partition (org.apache.hadoop.hive.metastore.api.Partition)11 UnlockRequest (org.apache.hadoop.hive.metastore.api.UnlockRequest)6 CompactionRequest (org.apache.hadoop.hive.metastore.api.CompactionRequest)5 NoSuchLockException (org.apache.hadoop.hive.metastore.api.NoSuchLockException)4 OpenTxnRequest (org.apache.hadoop.hive.metastore.api.OpenTxnRequest)4 CompactionInfo (org.apache.hadoop.hive.metastore.txn.CompactionInfo)4 GetOpenTxnsResponse (org.apache.hadoop.hive.metastore.api.GetOpenTxnsResponse)3 OpenTxnsResponse (org.apache.hadoop.hive.metastore.api.OpenTxnsResponse)3