Search in sources :

Example 56 with LockRequest

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

the class TestLockRequestBuilder method testExSRPart.

// Test that existing exclusive partition with new shared_read coalesces to
// exclusive
@Test
public void testExSRPart() {
    LockRequestBuilder bldr = new LockRequestBuilder();
    LockComponent comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setPartitionname("mypart");
    bldr.addLockComponent(comp);
    comp = new LockComponent(LockType.SHARED_READ, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setPartitionname("mypart");
    bldr.addLockComponent(comp).setUser("fred");
    LockRequest req = bldr.build();
    List<LockComponent> locks = req.getComponent();
    Assert.assertEquals(1, locks.size());
    Assert.assertEquals(LockType.EXCLUSIVE, locks.get(0).getType());
}
Also used : LockComponent(org.apache.hadoop.hive.metastore.api.LockComponent) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) Test(org.junit.Test)

Example 57 with LockRequest

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

the class TestLockRequestBuilder method testSWSWPart.

// Test that existing shared_write partition with new shared_write coalesces to
// shared_write
@Test
public void testSWSWPart() {
    LockRequestBuilder bldr = new LockRequestBuilder();
    LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setPartitionname("mypart");
    bldr.addLockComponent(comp);
    comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setPartitionname("mypart");
    bldr.addLockComponent(comp).setUser("fred");
    LockRequest req = bldr.build();
    List<LockComponent> locks = req.getComponent();
    Assert.assertEquals(1, locks.size());
    Assert.assertEquals(LockType.SHARED_WRITE, locks.get(0).getType());
}
Also used : LockComponent(org.apache.hadoop.hive.metastore.api.LockComponent) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) Test(org.junit.Test)

Example 58 with LockRequest

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

the class TestLockRequestBuilder method testExExPart.

// Test that 2 exclusive partition locks coalesce to one
@Test
public void testExExPart() {
    LockRequestBuilder bldr = new LockRequestBuilder();
    LockComponent comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setPartitionname("mypart");
    bldr.addLockComponent(comp);
    comp = new LockComponent(LockType.EXCLUSIVE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setPartitionname("mypart");
    bldr.addLockComponent(comp).setUser("fred");
    LockRequest req = bldr.build();
    List<LockComponent> locks = req.getComponent();
    Assert.assertEquals(1, locks.size());
}
Also used : LockComponent(org.apache.hadoop.hive.metastore.api.LockComponent) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) Test(org.junit.Test)

Example 59 with LockRequest

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

the class TestLockRequestBuilder method testSWSRPart.

// Test that existing shared_write partition with new shared_read coalesces to
// shared_write
@Test
public void testSWSRPart() {
    LockRequestBuilder bldr = new LockRequestBuilder();
    LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setPartitionname("mypart");
    bldr.addLockComponent(comp);
    comp = new LockComponent(LockType.SHARED_READ, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setPartitionname("mypart");
    bldr.addLockComponent(comp).setUser("fred");
    LockRequest req = bldr.build();
    List<LockComponent> locks = req.getComponent();
    Assert.assertEquals(1, locks.size());
    Assert.assertEquals(LockType.SHARED_WRITE, locks.get(0).getType());
}
Also used : LockComponent(org.apache.hadoop.hive.metastore.api.LockComponent) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) Test(org.junit.Test)

Example 60 with LockRequest

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

the class TestCompactionTxnHandler method testMarkCleanedCleansTxnsAndTxnComponents.

// TODO test changes to mark cleaned to clean txns and txn_components
@Test
public void testMarkCleanedCleansTxnsAndTxnComponents() throws Exception {
    long txnid = openTxn();
    LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb");
    comp.setTablename("mytable");
    comp.setOperationType(DataOperationType.INSERT);
    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));
    txnid = openTxn();
    comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb");
    comp.setTablename("yourtable");
    comp.setOperationType(DataOperationType.DELETE);
    components = new ArrayList<LockComponent>(1);
    components.add(comp);
    req = new LockRequest(components, "me", "localhost");
    req.setTxnid(txnid);
    res = txnHandler.lock(req);
    assertTrue(res.getState() == LockState.ACQUIRED);
    txnHandler.abortTxn(new AbortTxnRequest(txnid));
    txnid = openTxn();
    comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb");
    comp.setTablename("foo");
    comp.setPartitionname("bar");
    comp.setOperationType(DataOperationType.UPDATE);
    components = new ArrayList<LockComponent>(1);
    components.add(comp);
    req = new LockRequest(components, "me", "localhost");
    req.setTxnid(txnid);
    res = txnHandler.lock(req);
    assertTrue(res.getState() == LockState.ACQUIRED);
    comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.DB, "mydb");
    comp.setTablename("foo");
    comp.setPartitionname("baz");
    comp.setOperationType(DataOperationType.UPDATE);
    components = new ArrayList<LockComponent>(1);
    components.add(comp);
    req = new LockRequest(components, "me", "localhost");
    req.setTxnid(txnid);
    res = txnHandler.lock(req);
    assertTrue(res.getState() == LockState.ACQUIRED);
    txnHandler.abortTxn(new AbortTxnRequest(txnid));
    CompactionInfo ci = new CompactionInfo();
    // Now clean them and check that they are removed from the count.
    CompactionRequest rqst = new CompactionRequest("mydb", "mytable", CompactionType.MAJOR);
    txnHandler.compact(rqst);
    assertEquals(0, txnHandler.findReadyToClean().size());
    ci = txnHandler.findNextToCompact("fred");
    assertNotNull(ci);
    txnHandler.markCompacted(ci);
    List<CompactionInfo> toClean = txnHandler.findReadyToClean();
    assertEquals(1, toClean.size());
    txnHandler.markCleaned(ci);
    // Check that we are cleaning up the empty aborted transactions
    GetOpenTxnsResponse txnList = txnHandler.getOpenTxns();
    assertEquals(3, txnList.getOpen_txnsSize());
    txnHandler.cleanEmptyAbortedTxns();
    txnList = txnHandler.getOpenTxns();
    assertEquals(2, txnList.getOpen_txnsSize());
    rqst = new CompactionRequest("mydb", "foo", CompactionType.MAJOR);
    rqst.setPartitionname("bar");
    txnHandler.compact(rqst);
    assertEquals(0, txnHandler.findReadyToClean().size());
    ci = txnHandler.findNextToCompact("fred");
    assertNotNull(ci);
    txnHandler.markCompacted(ci);
    toClean = txnHandler.findReadyToClean();
    assertEquals(1, toClean.size());
    txnHandler.markCleaned(ci);
    txnHandler.openTxns(new OpenTxnRequest(1, "me", "localhost"));
    txnHandler.cleanEmptyAbortedTxns();
    txnList = txnHandler.getOpenTxns();
    assertEquals(3, txnList.getOpen_txnsSize());
}
Also used : 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) GetOpenTxnsResponse(org.apache.hadoop.hive.metastore.api.GetOpenTxnsResponse) OpenTxnRequest(org.apache.hadoop.hive.metastore.api.OpenTxnRequest) CompactionRequest(org.apache.hadoop.hive.metastore.api.CompactionRequest) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) Test(org.junit.Test)

Aggregations

LockRequest (org.apache.hadoop.hive.metastore.api.LockRequest)96 LockComponent (org.apache.hadoop.hive.metastore.api.LockComponent)94 Test (org.junit.Test)94 LockResponse (org.apache.hadoop.hive.metastore.api.LockResponse)59 ArrayList (java.util.ArrayList)57 CheckLockRequest (org.apache.hadoop.hive.metastore.api.CheckLockRequest)32 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)10 CompactionRequest (org.apache.hadoop.hive.metastore.api.CompactionRequest)6 UnlockRequest (org.apache.hadoop.hive.metastore.api.UnlockRequest)5 NoSuchLockException (org.apache.hadoop.hive.metastore.api.NoSuchLockException)4 CompactionInfo (org.apache.hadoop.hive.metastore.txn.CompactionInfo)4 GetOpenTxnsResponse (org.apache.hadoop.hive.metastore.api.GetOpenTxnsResponse)3 OpenTxnRequest (org.apache.hadoop.hive.metastore.api.OpenTxnRequest)3 HashMap (java.util.HashMap)2