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());
}
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);
}
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());
}
Aggregations