use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.
the class TestDbTxnManager2 method testWriteSetTracking1.
/**
* txns update same resource but do not overlap in time - no conflict
*/
@Test
public void testWriteSetTracking1() 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.compileAndRespond("select * from TAB_PART"));
txnMgr.openTxn(ctx, "Nicholas");
checkCmdOnDriver(driver.compileAndRespond("update TAB_PART set b = 7 where p = 'blah'"));
txnMgr.acquireLocks(driver.getPlan(), ctx, "Nicholas");
HiveTxnManager txnMgr2 = TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
txnMgr.commitTxn();
txnMgr2.openTxn(ctx, "Alexandra");
checkCmdOnDriver(driver.compileAndRespond("update TAB_PART set b = 7 where p = 'blah'"));
txnMgr2.acquireLocks(driver.getPlan(), ctx, "Nicholas");
txnMgr2.commitTxn();
}
use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.
the class TestDbTxnManager2 method testWriteSetTracking8.
/**
* Concurrent updates with partition pruning predicate and w/o one
*/
@Test
public void testWriteSetTracking8() throws Exception {
dropTable(new String[] { "tab1", "TAB1" });
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);
//txnid:1
checkCmdOnDriver(driver.run("insert into tab1 partition(p)(a,b,p) values(1,1,'one'),(2,2,'two')"));
HiveTxnManager txnMgr2 = TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
txnMgr2.openTxn(ctx, "T2");
checkCmdOnDriver(driver.compileAndRespond("update tab1 set b = 7 where b=1"));
txnMgr2.acquireLocks(driver.getPlan(), ctx, "T2");
List<ShowLocksResponseElement> locks = getLocks(txnMgr2);
Assert.assertEquals("Unexpected lock count", 2, locks.size());
checkLock(LockType.SHARED_WRITE, LockState.ACQUIRED, "default", "TAB1", "p=two", locks);
checkLock(LockType.SHARED_WRITE, LockState.ACQUIRED, "default", "TAB1", "p=one", locks);
//now start concurrent txn
txnMgr.openTxn(ctx, "T3");
checkCmdOnDriver(driver.compileAndRespond("update tab1 set b = 7 where p='two'"));
((DbTxnManager) txnMgr).acquireLocks(driver.getPlan(), ctx, "T3", false);
locks = getLocks(txnMgr);
Assert.assertEquals("Unexpected lock count", 3, locks.size());
checkLock(LockType.SHARED_WRITE, LockState.ACQUIRED, "default", "TAB1", "p=two", locks);
checkLock(LockType.SHARED_WRITE, LockState.ACQUIRED, "default", "TAB1", "p=one", locks);
checkLock(LockType.SHARED_WRITE, LockState.WAITING, "default", "TAB1", "p=two", locks);
//this simulates the completion of txnid:2
AddDynamicPartitions adp = new AddDynamicPartitions(txnMgr2.getCurrentTxnId(), "default", "tab1", Collections.singletonList("p=one"));
adp.setOperationType(DataOperationType.UPDATE);
txnHandler.addDynamicPartitions(adp);
//txnid:2
txnMgr2.commitTxn();
//retest WAITING locks (both have same ext id)
((DbLockManager) txnMgr.getLockManager()).checkLock(locks.get(2).getLockid());
locks = getLocks(txnMgr);
Assert.assertEquals("Unexpected lock count", 1, locks.size());
checkLock(LockType.SHARED_WRITE, LockState.ACQUIRED, "default", "TAB1", "p=two", locks);
//completion of txnid:3
adp = new AddDynamicPartitions(txnMgr.getCurrentTxnId(), "default", "tab1", Collections.singletonList("p=two"));
adp.setOperationType(DataOperationType.UPDATE);
txnHandler.addDynamicPartitions(adp);
//txnid:3
txnMgr.commitTxn();
Assert.assertEquals("WRITE_SET mismatch: " + TxnDbUtil.queryToString("select * from WRITE_SET"), 1, TxnDbUtil.countQueryAgent("select count(*) from WRITE_SET where ws_partition='p=one' and ws_operation_type='u' and ws_table='tab1'"));
Assert.assertEquals("WRITE_SET mismatch: " + TxnDbUtil.queryToString("select * from WRITE_SET"), 1, TxnDbUtil.countQueryAgent("select count(*) from WRITE_SET where ws_partition='p=two' and ws_operation_type='u' and ws_table='tab1'"));
Assert.assertEquals("COMPLETED_TXN_COMPONENTS mismatch: " + TxnDbUtil.queryToString("select * from COMPLETED_TXN_COMPONENTS"), 4, TxnDbUtil.countQueryAgent("select count(*) from COMPLETED_TXN_COMPONENTS where ctc_table='tab1' and ctc_partition is not null"));
}
use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.
the class TestDbTxnManager2 method testShowLocksFilterOptions.
@Test
public void testShowLocksFilterOptions() throws Exception {
CommandProcessorResponse cpr = driver.run("drop table if exists db1.t14");
checkCmdOnDriver(cpr);
// Note that db1 and db2 have a table with common name
cpr = driver.run("drop table if exists db2.t14");
checkCmdOnDriver(cpr);
cpr = driver.run("drop table if exists db2.t15");
checkCmdOnDriver(cpr);
cpr = driver.run("drop table if exists db2.t16");
checkCmdOnDriver(cpr);
cpr = driver.run("drop database if exists db1");
checkCmdOnDriver(cpr);
cpr = driver.run("drop database if exists db2");
checkCmdOnDriver(cpr);
cpr = driver.run("create database if not exists db1");
checkCmdOnDriver(cpr);
cpr = driver.run("create database if not exists db2");
checkCmdOnDriver(cpr);
cpr = driver.run("create table if not exists db1.t14 (a int, b int) partitioned by (ds string) clustered by (b) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')");
checkCmdOnDriver(cpr);
cpr = driver.run("create table if not exists db2.t14 (a int, b int) clustered by (b) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')");
checkCmdOnDriver(cpr);
cpr = driver.run("create table if not exists db2.t15 (a int, b int) clustered by (b) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')");
checkCmdOnDriver(cpr);
cpr = driver.run("create table if not exists db2.t16 (a int, b int) clustered by (b) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')");
checkCmdOnDriver(cpr);
// Acquire different locks at different levels
cpr = driver.compileAndRespond("insert into table db1.t14 partition (ds='today') values (1, 2)");
checkCmdOnDriver(cpr);
txnMgr.acquireLocks(driver.getPlan(), ctx, "Tom");
HiveTxnManager txnMgr2 = TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
cpr = driver.compileAndRespond("insert into table db1.t14 partition (ds='tomorrow') values (3, 4)");
checkCmdOnDriver(cpr);
txnMgr2.acquireLocks(driver.getPlan(), ctx, "Jerry");
HiveTxnManager txnMgr3 = TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
cpr = driver.compileAndRespond("select * from db2.t15");
checkCmdOnDriver(cpr);
txnMgr3.acquireLocks(driver.getPlan(), ctx, "Donald");
HiveTxnManager txnMgr4 = TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
cpr = driver.compileAndRespond("select * from db2.t16");
checkCmdOnDriver(cpr);
txnMgr4.acquireLocks(driver.getPlan(), ctx, "Hillary");
HiveTxnManager txnMgr5 = TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
cpr = driver.compileAndRespond("select * from db2.t14");
checkCmdOnDriver(cpr);
txnMgr5.acquireLocks(driver.getPlan(), ctx, "Obama");
// Simulate SHOW LOCKS with different filter options
// SHOW LOCKS (no filter)
List<ShowLocksResponseElement> locks = getLocks();
Assert.assertEquals("Unexpected lock count", 5, locks.size());
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db1", "t14", "ds=today", locks);
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db1", "t14", "ds=tomorrow", locks);
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db2", "t15", null, locks);
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db2", "t16", null, locks);
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db2", "t14", null, locks);
// SHOW LOCKS db2
locks = getLocksWithFilterOptions(txnMgr3, "db2", null, null);
Assert.assertEquals("Unexpected lock count", 3, locks.size());
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db2", "t15", null, locks);
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db2", "t16", null, locks);
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db2", "t14", null, locks);
// SHOW LOCKS t14
cpr = driver.run("use db1");
checkCmdOnDriver(cpr);
locks = getLocksWithFilterOptions(txnMgr, null, "t14", null);
Assert.assertEquals("Unexpected lock count", 2, locks.size());
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db1", "t14", "ds=today", locks);
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db1", "t14", "ds=tomorrow", locks);
// Note that it shouldn't show t14 from db2
// SHOW LOCKS t14 PARTITION ds='today'
Map<String, String> partSpec = new HashMap<String, String>();
partSpec.put("ds", "today");
locks = getLocksWithFilterOptions(txnMgr, null, "t14", partSpec);
Assert.assertEquals("Unexpected lock count", 1, locks.size());
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db1", "t14", "ds=today", locks);
// SHOW LOCKS t15
cpr = driver.run("use db2");
checkCmdOnDriver(cpr);
locks = getLocksWithFilterOptions(txnMgr3, null, "t15", null);
Assert.assertEquals("Unexpected lock count", 1, locks.size());
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db2", "t15", null, locks);
}
use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.
the class TestDbTxnManager2 method createTable.
@Test
public void createTable() throws Exception {
dropTable(new String[] { "T" });
CommandProcessorResponse cpr = driver.compileAndRespond("create table if not exists T (a int, b int)");
checkCmdOnDriver(cpr);
txnMgr.acquireLocks(driver.getPlan(), ctx, "Fifer");
List<ShowLocksResponseElement> locks = getLocks();
Assert.assertEquals("Unexpected lock count", 1, locks.size());
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", null, null, locks);
txnMgr.getLockManager().releaseLocks(ctx.getHiveLocks());
Assert.assertEquals("Lock remained", 0, getLocks().size());
}
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);
HiveTxnManager otherTxnMgr = new DbTxnManager();
((DbTxnManager) otherTxnMgr).setHiveConf(conf);
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(txnMgr);
Assert.assertEquals("Unexpected lock count", 1, locks.size());
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", "T9", null, locks);
cpr = driver.compileAndRespond("drop table T9");
checkCmdOnDriver(cpr);
try {
otherTxnMgr.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);
otherTxnMgr.closeTxnManager();
}
Aggregations