Search in sources :

Example 36 with QueryPlan

use of org.apache.hadoop.hive.ql.QueryPlan in project hive by apache.

the class TestDbTxnManager method testDDLShared.

@Test
public void testDDLShared() throws Exception {
    WriteEntity we = addTableOutput(WriteEntity.WriteType.DDL_SHARED);
    QueryPlan qp = new MockQueryPlan(this, HiveOperation.ALTERTABLE_EXCHANGEPARTITION);
    txnMgr.openTxn(ctx, "fred");
    txnMgr.acquireLocks(qp, ctx, "fred");
    List<HiveLock> locks = ctx.getHiveLocks();
    Assert.assertEquals(1, locks.size());
    Assert.assertEquals(1, TxnDbUtil.countLockComponents(conf, ((DbLockManager.DbHiveLock) locks.get(0)).lockId));
    txnMgr.commitTxn();
    locks = txnMgr.getLockManager().getLocks(false, false);
    Assert.assertEquals(0, locks.size());
}
Also used : QueryPlan(org.apache.hadoop.hive.ql.QueryPlan) WriteEntity(org.apache.hadoop.hive.ql.hooks.WriteEntity) Test(org.junit.Test)

Example 37 with QueryPlan

use of org.apache.hadoop.hive.ql.QueryPlan in project hive by apache.

the class TestDbTxnManager method testLockTimeout.

@Ignore("This seems useless now that we have a txn for everything")
@Test
public void testLockTimeout() throws Exception {
    addPartitionInput(newTable(true));
    QueryPlan qp = new MockQueryPlan(this, HiveOperation.QUERY);
    // make sure it works with nothing to expire
    testLockExpiration(txnMgr, 0, true);
    // create a few read locks, all on the same resource
    for (int i = 0; i < 5; i++) {
        // No heartbeat
        ((DbTxnManager) txnMgr).acquireLocks(qp, ctx, "PeterI" + i, true);
    }
    testLockExpiration(txnMgr, 5, true);
    // create a lot of locks
    for (int i = 0; i < TEST_TIMED_OUT_TXN_ABORT_BATCH_SIZE + 17; i++) {
        // No heartbeat
        ((DbTxnManager) txnMgr).acquireLocks(qp, ctx, "PeterI" + i, true);
    }
    testLockExpiration(txnMgr, TEST_TIMED_OUT_TXN_ABORT_BATCH_SIZE + 17, true);
    // Create a lock, but send the heartbeat with a long delay. The lock will get expired.
    ((DbTxnManager) txnMgr).acquireLocksWithHeartbeatDelay(qp, ctx, "bob", HiveConf.getTimeVar(conf, HiveConf.ConfVars.HIVE_TXN_TIMEOUT, TimeUnit.MILLISECONDS) * 10);
    testLockExpiration(txnMgr, 1, true);
    // Create a lock and trigger a heartbeat. With heartbeat, the lock won't expire.
    txnMgr.acquireLocks(qp, ctx, "peter");
    testLockExpiration(txnMgr, 1, false);
}
Also used : QueryPlan(org.apache.hadoop.hive.ql.QueryPlan) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 38 with QueryPlan

use of org.apache.hadoop.hive.ql.QueryPlan in project hive by apache.

the class TestDbTxnManager method testHeartbeater.

@Test
public void testHeartbeater() throws Exception {
    Assert.assertTrue(txnMgr instanceof DbTxnManager);
    addTableInput();
    LockException exception = null;
    QueryPlan qp = new MockQueryPlan(this, HiveOperation.QUERY);
    // Case 1: If there's no delay for the heartbeat, txn should be able to commit
    txnMgr.openTxn(ctx, "fred");
    // heartbeat started..
    txnMgr.acquireLocks(qp, ctx, "fred");
    runReaper();
    try {
        txnMgr.commitTxn();
    } catch (LockException e) {
        exception = e;
    }
    Assert.assertNull("Txn commit should be successful", exception);
    exception = null;
    // Case 2: If there's delay for the heartbeat, but the delay is within the reaper's tolerance,
    // then txt should be able to commit
    // Start the heartbeat after a delay, which is shorter than  the HIVE_TXN_TIMEOUT
    ((DbTxnManager) txnMgr).openTxn(ctx, "tom", HiveConf.getTimeVar(conf, HiveConf.ConfVars.HIVE_TXN_TIMEOUT, TimeUnit.MILLISECONDS) / 2);
    txnMgr.acquireLocks(qp, ctx, "tom");
    runReaper();
    try {
        txnMgr.commitTxn();
    } catch (LockException e) {
        exception = e;
    }
    Assert.assertNull("Txn commit should also be successful", exception);
    exception = null;
    // Case 3: If there's delay for the heartbeat, and the delay is long enough to trigger the reaper,
    // then the txn will time out and be aborted.
    // Here we just don't send the heartbeat at all - an infinite delay.
    // Start the heartbeat after a delay, which exceeds the HIVE_TXN_TIMEOUT
    ((DbTxnManager) txnMgr).openTxn(ctx, "jerry", HiveConf.getTimeVar(conf, HiveConf.ConfVars.HIVE_TXN_TIMEOUT, TimeUnit.MILLISECONDS) * 2);
    txnMgr.acquireLocks(qp, ctx, "jerry");
    Thread.sleep(HiveConf.getTimeVar(conf, HiveConf.ConfVars.HIVE_TXN_TIMEOUT, TimeUnit.MILLISECONDS));
    runReaper();
    try {
        txnMgr.commitTxn();
    } catch (LockException e) {
        exception = e;
    }
    Assert.assertNotNull("Txn should have been aborted", exception);
    Assert.assertEquals(ErrorMsg.TXN_ABORTED, exception.getCanonicalErrorMsg());
}
Also used : QueryPlan(org.apache.hadoop.hive.ql.QueryPlan) Test(org.junit.Test)

Aggregations

QueryPlan (org.apache.hadoop.hive.ql.QueryPlan)38 Test (org.junit.Test)21 HiveConf (org.apache.hadoop.hive.conf.HiveConf)14 WriteEntity (org.apache.hadoop.hive.ql.hooks.WriteEntity)10 List (java.util.List)7 Driver (org.apache.hadoop.hive.ql.Driver)7 TezTask (org.apache.hadoop.hive.ql.exec.tez.TezTask)6 IOException (java.io.IOException)5 SessionState (org.apache.hadoop.hive.ql.session.SessionState)5 LinkedHashMap (java.util.LinkedHashMap)4 Table (org.apache.hadoop.hive.ql.metadata.Table)4 LogHelper (org.apache.hadoop.hive.ql.session.SessionState.LogHelper)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 FileSystem (org.apache.hadoop.fs.FileSystem)3 Path (org.apache.hadoop.fs.Path)3 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)3 Context (org.apache.hadoop.hive.ql.Context)3 Task (org.apache.hadoop.hive.ql.exec.Task)3