use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.
the class TestDbTxnManager2 method testCompletedTxnComponents.
@Test
public void testCompletedTxnComponents() throws Exception {
dropTable(new String[] { "TAB1", "tab_not_acid2" });
CommandProcessorResponse cpr = driver.run("create table if not exists tab1 (a int, b int) partitioned by (p string) " + "clustered by (a) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')");
checkCmdOnDriver(cpr);
cpr = driver.run("create table if not exists tab_not_acid2 (a int, b int)");
checkCmdOnDriver(cpr);
checkCmdOnDriver(driver.run("insert into tab_not_acid2 values(1,1),(2,2)"));
// writing both acid and non-acid resources in the same txn
// txnid:1
checkCmdOnDriver(driver.run("from tab_not_acid2 insert into tab1 partition(p='two')(a,b) select a,b insert into tab_not_acid2(a,b) select a,b "));
Assert.assertEquals(TxnDbUtil.queryToString(conf, "select * from COMPLETED_TXN_COMPONENTS"), 1, TxnDbUtil.countQueryAgent(conf, "select count(*) from COMPLETED_TXN_COMPONENTS"));
// only expect transactional components to be in COMPLETED_TXN_COMPONENTS
Assert.assertEquals(TxnDbUtil.queryToString(conf, "select * from COMPLETED_TXN_COMPONENTS"), 1, TxnDbUtil.countQueryAgent(conf, "select count(*) from COMPLETED_TXN_COMPONENTS where ctc_txnid=6 and ctc_table='tab1'"));
}
use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.
the class TestDbTxnManager2 method insertOverwritePartitionedCreate.
@Test
public void insertOverwritePartitionedCreate() throws Exception {
dropTable(new String[] { "T4" });
CommandProcessorResponse cpr = driver.run("create table if not exists T4 (name string, gpa double) partitioned by (age int)");
checkCmdOnDriver(cpr);
cpr = driver.run("create table if not exists T5(name string, age int, gpa double)");
checkCmdOnDriver(cpr);
cpr = driver.compileAndRespond("INSERT OVERWRITE TABLE T4 PARTITION (age) SELECT name, age, gpa FROM T5");
checkCmdOnDriver(cpr);
txnMgr.acquireLocks(driver.getPlan(), ctx, "Fifer");
List<ShowLocksResponseElement> locks = getLocks();
Assert.assertEquals("Unexpected lock count", 2, locks.size());
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "T5", null, locks);
checkLock(LockType.EXCLUSIVE, LockState.ACQUIRED, "default", "T4", null, locks);
txnMgr.commitTxn();
Assert.assertEquals("Lock remained", 0, getLocks().size());
cpr = driver.run("drop table if exists T5");
checkCmdOnDriver(cpr);
cpr = driver.run("drop table if exists T4");
checkCmdOnDriver(cpr);
}
use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.
the class TestDbTxnManager2 method testWriteSetTracking6.
/**
* check that read query concurrent with txn works ok
*/
@Test
public void testWriteSetTracking6() throws Exception {
dropTable(new String[] { "TAB2" });
Assert.assertEquals(0, TxnDbUtil.countQueryAgent(conf, "select count(*) from WRITE_SET"));
CommandProcessorResponse cpr = driver.run("create table if not exists TAB2(a int, b int) clustered " + "by (a) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')");
checkCmdOnDriver(cpr);
checkCmdOnDriver(driver.compileAndRespond("select * from TAB2 where a = 113"));
txnMgr.acquireLocks(driver.getPlan(), ctx, "Works");
List<ShowLocksResponseElement> locks = getLocks(txnMgr);
Assert.assertEquals("Unexpected lock count", 1, locks.size());
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "TAB2", null, locks);
HiveTxnManager txnMgr2 = TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
swapTxnManager(txnMgr2);
checkCmdOnDriver(driver.compileAndRespond("update TAB2 set b = 17 where a = 101"));
txnMgr2.acquireLocks(driver.getPlan(), ctx, "Horton");
Assert.assertEquals(0, TxnDbUtil.countQueryAgent(conf, "select count(*) from WRITE_SET"));
locks = getLocks(txnMgr);
Assert.assertEquals("Unexpected lock count", 2, locks.size());
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "TAB2", null, locks);
checkLock(LockType.SHARED_WRITE, LockState.ACQUIRED, "default", "TAB2", null, locks);
// no conflict
txnMgr2.commitTxn();
Assert.assertEquals(1, TxnDbUtil.countQueryAgent(conf, "select count(*) from WRITE_SET"));
locks = getLocks(txnMgr);
Assert.assertEquals("Unexpected lock count", 1, locks.size());
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "TAB2", null, locks);
txnMgr.commitTxn();
MetastoreTaskThread writeSetService = new AcidWriteSetService();
writeSetService.setConf(conf);
writeSetService.run();
Assert.assertEquals(0, TxnDbUtil.countQueryAgent(conf, "select count(*) from WRITE_SET"));
}
use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.
the class TestDbTxnManager2 method testLockRetryLimit.
@Test
public void testLockRetryLimit() throws Exception {
dropTable(new String[] { "T9" });
conf.setIntVar(HiveConf.ConfVars.HIVE_LOCK_NUMRETRIES, 2);
conf.setBoolVar(HiveConf.ConfVars.TXN_MGR_DUMP_LOCK_STATE_ON_ACQUIRE_TIMEOUT, true);
CommandProcessorResponse cpr = driver.run("create table T9(a int)");
checkCmdOnDriver(cpr);
cpr = driver.compileAndRespond("select * from T9");
checkCmdOnDriver(cpr);
txnMgr.acquireLocks(driver.getPlan(), ctx, "Vincent Vega");
List<ShowLocksResponseElement> locks = getLocks();
Assert.assertEquals("Unexpected lock count", 1, locks.size());
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "T9", null, locks);
HiveTxnManager txnMgr2 = TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
swapTxnManager(txnMgr2);
cpr = driver.compileAndRespond("drop table T9");
checkCmdOnDriver(cpr);
try {
txnMgr2.acquireLocks(driver.getPlan(), ctx, "Winston Winnfield");
} catch (LockException ex) {
Assert.assertEquals("Got wrong lock exception", ErrorMsg.LOCK_ACQUIRE_TIMEDOUT, ex.getCanonicalErrorMsg());
}
locks = getLocks(txnMgr);
Assert.assertEquals("Unexpected lock count", 1, locks.size());
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "T9", null, locks);
txnMgr2.closeTxnManager();
}
use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.
the class TestDbTxnManager2 method testWriteSetTracking3.
/**
* txns overlap and update the same resource - can't commit 2nd txn
*/
@Test
public void testWriteSetTracking3() throws Exception {
dropTable(new String[] { "TAB_PART" });
CommandProcessorResponse cpr = driver.run("create table if not exists TAB_PART (a int, b int) " + "partitioned by (p string) clustered by (a) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')");
checkCmdOnDriver(cpr);
checkCmdOnDriver(driver.run("insert into TAB_PART partition(p='blah') values(1,2)"));
checkCmdOnDriver(driver.compileAndRespond("update TAB_PART set b = 7 where p = 'blah'"));
long txnId = txnMgr.getCurrentTxnId();
txnMgr.acquireLocks(driver.getPlan(), ctx, "Known");
List<ShowLocksResponseElement> locks = getLocks(txnMgr);
Assert.assertEquals("Unexpected lock count", 1, locks.size());
checkLock(LockType.SHARED_WRITE, LockState.ACQUIRED, "default", "TAB_PART", "p=blah", locks);
HiveTxnManager txnMgr2 = TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
swapTxnManager(txnMgr2);
checkCmdOnDriver(driver.compileAndRespond("update TAB_PART set b = 7 where p = 'blah'"));
long txnId2 = txnMgr2.getCurrentTxnId();
((DbTxnManager) txnMgr2).acquireLocks(driver.getPlan(), ctx, "Unknown", false);
// should not matter which txnMgr is used here
locks = getLocks(txnMgr2);
Assert.assertEquals("Unexpected lock count", 2, locks.size());
checkLock(LockType.SHARED_WRITE, LockState.ACQUIRED, "default", "TAB_PART", "p=blah", locks);
checkLock(LockType.SHARED_WRITE, LockState.WAITING, "default", "TAB_PART", "p=blah", locks);
long writeId = txnMgr.getTableWriteId("default", "TAB_PART");
AddDynamicPartitions adp = new AddDynamicPartitions(txnId, writeId, "default", "TAB_PART", Collections.singletonList("p=blah"));
adp.setOperationType(DataOperationType.UPDATE);
txnHandler.addDynamicPartitions(adp);
txnMgr.commitTxn();
adp.setTxnid(txnId2);
writeId = txnMgr2.getTableWriteId("default", "TAB_PART");
adp.setWriteid(writeId);
txnHandler.addDynamicPartitions(adp);
LockException expectedException = null;
try {
// with HIVE-15032 this should use static parts and thus not need addDynamicPartitions
txnMgr2.commitTxn();
} catch (LockException e) {
expectedException = e;
}
Assert.assertTrue("Didn't get exception", expectedException != null);
Assert.assertEquals("Got wrong message code", ErrorMsg.TXN_ABORTED, expectedException.getCanonicalErrorMsg());
Assert.assertEquals("Exception msg didn't match", "Aborting [txnid:" + txnId2 + "," + txnId2 + "] due to a write conflict on default/TAB_PART/p=blah committed by [txnid:" + txnId + "," + txnId2 + "] u/u", expectedException.getCause().getMessage());
}
Aggregations