Search in sources :

Example 6 with OpenTxnRequest

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

the class TestTxnHandler method testValidTxnsNoneOpen.

@Test
public void testValidTxnsNoneOpen() throws Exception {
    txnHandler.openTxns(new OpenTxnRequest(2, "me", "localhost"));
    txnHandler.commitTxn(new CommitTxnRequest(1));
    txnHandler.commitTxn(new CommitTxnRequest(2));
    GetOpenTxnsInfoResponse txnsInfo = txnHandler.getOpenTxnsInfo();
    assertEquals(2L, txnsInfo.getTxn_high_water_mark());
    assertEquals(0, txnsInfo.getOpen_txns().size());
    GetOpenTxnsResponse txns = txnHandler.getOpenTxns();
    assertEquals(2L, txns.getTxn_high_water_mark());
    assertEquals(0, txns.getOpen_txns().size());
}
Also used : CommitTxnRequest(org.apache.hadoop.hive.metastore.api.CommitTxnRequest) GetOpenTxnsResponse(org.apache.hadoop.hive.metastore.api.GetOpenTxnsResponse) OpenTxnRequest(org.apache.hadoop.hive.metastore.api.OpenTxnRequest) GetOpenTxnsInfoResponse(org.apache.hadoop.hive.metastore.api.GetOpenTxnsInfoResponse) Test(org.junit.Test)

Example 7 with OpenTxnRequest

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

the class TestCleaner method blockedByLockPartition.

@Test
public void blockedByLockPartition() throws Exception {
    Table t = newTable("default", "bblp", true);
    Partition p = newPartition(t, "today");
    addBaseFile(t, p, 20L, 20);
    addDeltaFile(t, p, 21L, 22L, 2);
    addDeltaFile(t, p, 23L, 24L, 2);
    addDeltaFile(t, p, 21L, 24L, 4);
    burnThroughTransactions(25);
    CompactionRequest rqst = new CompactionRequest("default", "bblp", CompactionType.MINOR);
    rqst.setPartitionname("ds=today");
    txnHandler.compact(rqst);
    CompactionInfo ci = txnHandler.findNextToCompact("fred");
    txnHandler.markCompacted(ci);
    txnHandler.setRunAs(ci.id, System.getProperty("user.name"));
    LockComponent comp = new LockComponent(LockType.SHARED_WRITE, LockLevel.PARTITION, "default");
    comp.setTablename("bblp");
    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");
    OpenTxnsResponse resp = txnHandler.openTxns(new OpenTxnRequest(1, "Dracula", "Transylvania"));
    req.setTxnid(resp.getTxn_ids().get(0));
    LockResponse res = txnHandler.lock(req);
    startCleaner();
    // Check there are no compactions requests left.
    ShowCompactResponse rsp = txnHandler.showCompact(new ShowCompactRequest());
    List<ShowCompactResponseElement> compacts = rsp.getCompacts();
    Assert.assertEquals(1, compacts.size());
    Assert.assertEquals("ready for cleaning", compacts.get(0).getState());
    Assert.assertEquals("bblp", compacts.get(0).getTablename());
    Assert.assertEquals("ds=today", compacts.get(0).getPartitionname());
    Assert.assertEquals(CompactionType.MINOR, 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) LockResponse(org.apache.hadoop.hive.metastore.api.LockResponse) ShowCompactResponse(org.apache.hadoop.hive.metastore.api.ShowCompactResponse) CompactionInfo(org.apache.hadoop.hive.metastore.txn.CompactionInfo) OpenTxnRequest(org.apache.hadoop.hive.metastore.api.OpenTxnRequest) ShowCompactRequest(org.apache.hadoop.hive.metastore.api.ShowCompactRequest) CompactionRequest(org.apache.hadoop.hive.metastore.api.CompactionRequest) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) ShowCompactResponseElement(org.apache.hadoop.hive.metastore.api.ShowCompactResponseElement) OpenTxnsResponse(org.apache.hadoop.hive.metastore.api.OpenTxnsResponse) Test(org.junit.Test)

Example 8 with OpenTxnRequest

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

the class TestTxnCommands2 method testOpenTxnsCounter.

@Test
public void testOpenTxnsCounter() throws Exception {
    hiveConf.setIntVar(HiveConf.ConfVars.HIVE_MAX_OPEN_TXNS, 3);
    hiveConf.setTimeVar(HiveConf.ConfVars.HIVE_COUNT_OPEN_TXNS_INTERVAL, 10, TimeUnit.MILLISECONDS);
    TxnStore txnHandler = TxnUtils.getTxnStore(hiveConf);
    OpenTxnsResponse openTxnsResponse = txnHandler.openTxns(new OpenTxnRequest(3, "me", "localhost"));
    AcidOpenTxnsCounterService openTxnsCounterService = new AcidOpenTxnsCounterService();
    // will update current number of open txns to 3
    runHouseKeeperService(openTxnsCounterService, hiveConf);
    MetaException exception = null;
    // This should fail once it finds out the threshold has been reached
    try {
        txnHandler.openTxns(new OpenTxnRequest(1, "you", "localhost"));
    } catch (MetaException e) {
        exception = e;
    }
    Assert.assertNotNull("Opening new transaction shouldn't be allowed", exception);
    Assert.assertTrue(exception.getMessage().equals("Maximum allowed number of open transactions has been reached. See hive.max.open.txns."));
    // new transactions should be allowed to open
    for (long txnid : openTxnsResponse.getTxn_ids()) {
        txnHandler.commitTxn(new CommitTxnRequest(txnid));
    }
    // will update current number of open txns back to 0
    runHouseKeeperService(openTxnsCounterService, hiveConf);
    exception = null;
    try {
        txnHandler.openTxns(new OpenTxnRequest(1, "him", "localhost"));
    } catch (MetaException e) {
        exception = e;
    }
    Assert.assertNull(exception);
}
Also used : CommitTxnRequest(org.apache.hadoop.hive.metastore.api.CommitTxnRequest) OpenTxnRequest(org.apache.hadoop.hive.metastore.api.OpenTxnRequest) TxnStore(org.apache.hadoop.hive.metastore.txn.TxnStore) AcidOpenTxnsCounterService(org.apache.hadoop.hive.ql.txn.AcidOpenTxnsCounterService) OpenTxnsResponse(org.apache.hadoop.hive.metastore.api.OpenTxnsResponse) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) Test(org.junit.Test)

Aggregations

OpenTxnRequest (org.apache.hadoop.hive.metastore.api.OpenTxnRequest)8 Test (org.junit.Test)8 CommitTxnRequest (org.apache.hadoop.hive.metastore.api.CommitTxnRequest)5 GetOpenTxnsResponse (org.apache.hadoop.hive.metastore.api.GetOpenTxnsResponse)5 GetOpenTxnsInfoResponse (org.apache.hadoop.hive.metastore.api.GetOpenTxnsInfoResponse)4 OpenTxnsResponse (org.apache.hadoop.hive.metastore.api.OpenTxnsResponse)4 ArrayList (java.util.ArrayList)3 AbortTxnRequest (org.apache.hadoop.hive.metastore.api.AbortTxnRequest)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 AddDynamicPartitions (org.apache.hadoop.hive.metastore.api.AddDynamicPartitions)2 CompactionRequest (org.apache.hadoop.hive.metastore.api.CompactionRequest)2 TreeSet (java.util.TreeSet)1 DataOperationType (org.apache.hadoop.hive.metastore.api.DataOperationType)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 NoSuchTxnException (org.apache.hadoop.hive.metastore.api.NoSuchTxnException)1 Partition (org.apache.hadoop.hive.metastore.api.Partition)1 ShowCompactRequest (org.apache.hadoop.hive.metastore.api.ShowCompactRequest)1 ShowCompactResponse (org.apache.hadoop.hive.metastore.api.ShowCompactResponse)1