Search in sources :

Example 11 with AbortTxnRequest

use of org.apache.hadoop.hive.metastore.api.AbortTxnRequest 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 12 with AbortTxnRequest

use of org.apache.hadoop.hive.metastore.api.AbortTxnRequest 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)

Example 13 with AbortTxnRequest

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

the class TestTxnHandler method testUnlockOnAbort.

@Test
public void testUnlockOnAbort() throws Exception {
    // Test that committing unlocks
    long txnid = openTxn();
    LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb");
    comp.setOperationType(DataOperationType.UPDATE);
    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);
    assertTrue(res.getState() == LockState.ACQUIRED);
    txnHandler.abortTxn(new AbortTxnRequest(txnid));
    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) 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 14 with AbortTxnRequest

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

the class TestTxnHandler method testHeartbeatTxnAborted.

@Test
public void testHeartbeatTxnAborted() throws Exception {
    // Test that when a transaction is aborted, the heartbeat fails
    openTxn();
    txnHandler.abortTxn(new AbortTxnRequest(1));
    HeartbeatRequest h = new HeartbeatRequest();
    h.setTxnid(1);
    try {
        txnHandler.heartbeat(h);
        fail("Told there was a txn, when it should have been aborted.");
    } catch (TxnAbortedException e) {
    }
}
Also used : TxnAbortedException(org.apache.hadoop.hive.metastore.api.TxnAbortedException) AbortTxnRequest(org.apache.hadoop.hive.metastore.api.AbortTxnRequest) HeartbeatRequest(org.apache.hadoop.hive.metastore.api.HeartbeatRequest) Test(org.junit.Test)

Example 15 with AbortTxnRequest

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

the class TestInitiator method majorCompactOnPartitionTooManyAborts.

@Test
public void majorCompactOnPartitionTooManyAborts() throws Exception {
    Table t = newTable("default", "mcoptma", true);
    Partition p = newPartition(t, "today");
    HiveConf.setIntVar(conf, HiveConf.ConfVars.HIVE_COMPACTOR_ABORTEDTXN_THRESHOLD, 10);
    for (int i = 0; i < 11; i++) {
        long txnid = openTxn();
        LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.TABLE, "default");
        comp.setTablename("mcoptma");
        comp.setPartitionname("ds=today");
        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);
        txnHandler.abortTxn(new AbortTxnRequest(txnid));
    }
    startInitiator();
    ShowCompactResponse rsp = txnHandler.showCompact(new ShowCompactRequest());
    List<ShowCompactResponseElement> compacts = rsp.getCompacts();
    Assert.assertEquals(1, compacts.size());
    Assert.assertEquals("initiated", compacts.get(0).getState());
    Assert.assertEquals("mcoptma", compacts.get(0).getTablename());
    Assert.assertEquals("ds=today", compacts.get(0).getPartitionname());
    Assert.assertEquals(CompactionType.MAJOR, compacts.get(0).getType());
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) Table(org.apache.hadoop.hive.metastore.api.Table) LockComponent(org.apache.hadoop.hive.metastore.api.LockComponent) ArrayList(java.util.ArrayList) AbortTxnRequest(org.apache.hadoop.hive.metastore.api.AbortTxnRequest) LockResponse(org.apache.hadoop.hive.metastore.api.LockResponse) ShowCompactResponse(org.apache.hadoop.hive.metastore.api.ShowCompactResponse) ShowCompactRequest(org.apache.hadoop.hive.metastore.api.ShowCompactRequest) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) ShowCompactResponseElement(org.apache.hadoop.hive.metastore.api.ShowCompactResponseElement) Test(org.junit.Test)

Aggregations

AbortTxnRequest (org.apache.hadoop.hive.metastore.api.AbortTxnRequest)16 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)12 LockComponent (org.apache.hadoop.hive.metastore.api.LockComponent)11 LockRequest (org.apache.hadoop.hive.metastore.api.LockRequest)11 LockResponse (org.apache.hadoop.hive.metastore.api.LockResponse)11 Table (org.apache.hadoop.hive.metastore.api.Table)7 ShowCompactRequest (org.apache.hadoop.hive.metastore.api.ShowCompactRequest)6 ShowCompactResponse (org.apache.hadoop.hive.metastore.api.ShowCompactResponse)6 GetOpenTxnsResponse (org.apache.hadoop.hive.metastore.api.GetOpenTxnsResponse)4 CheckLockRequest (org.apache.hadoop.hive.metastore.api.CheckLockRequest)3 OpenTxnRequest (org.apache.hadoop.hive.metastore.api.OpenTxnRequest)3 ShowCompactResponseElement (org.apache.hadoop.hive.metastore.api.ShowCompactResponseElement)3 HashMap (java.util.HashMap)2 CommitTxnRequest (org.apache.hadoop.hive.metastore.api.CommitTxnRequest)2 CompactionRequest (org.apache.hadoop.hive.metastore.api.CompactionRequest)2 GetOpenTxnsInfoResponse (org.apache.hadoop.hive.metastore.api.GetOpenTxnsInfoResponse)2 NoSuchTxnException (org.apache.hadoop.hive.metastore.api.NoSuchTxnException)2 Partition (org.apache.hadoop.hive.metastore.api.Partition)2 AddDynamicPartitions (org.apache.hadoop.hive.metastore.api.AddDynamicPartitions)1