use of org.apache.hadoop.hive.metastore.api.ShowLocksResponse in project hive by apache.
the class TestAcidOnTez method testGetSplitsLocks.
@Test
public void testGetSplitsLocks() throws Exception {
// Need to test this with LLAP settings, which requires some additional configurations set.
HiveConf modConf = new HiveConf(hiveConf);
setupTez(modConf);
modConf.setVar(ConfVars.HIVE_EXECUTION_ENGINE, "tez");
modConf.setVar(ConfVars.HIVEFETCHTASKCONVERSION, "more");
modConf.setVar(HiveConf.ConfVars.LLAP_DAEMON_SERVICE_HOSTS, "localhost");
// SessionState/Driver needs to be restarted with the Tez conf settings.
restartSessionAndDriver(modConf);
TxnStore txnHandler = TxnUtils.getTxnStore(modConf);
try {
// Request LLAP splits for a table.
String queryParam = "select * from " + Table.ACIDTBL;
runStatementOnDriver("select get_splits(\"" + queryParam + "\", 1)");
// The get_splits call should have resulted in a lock on ACIDTBL
ShowLocksResponse slr = txnHandler.showLocks(new ShowLocksRequest());
TestDbTxnManager2.checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", Table.ACIDTBL.name, null, slr.getLocks());
assertEquals(1, slr.getLocksSize());
// Try another table.
queryParam = "select * from " + Table.ACIDTBLPART;
runStatementOnDriver("select get_splits(\"" + queryParam + "\", 1)");
// Should now have new lock on ACIDTBLPART
slr = txnHandler.showLocks(new ShowLocksRequest());
TestDbTxnManager2.checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "default", Table.ACIDTBLPART.name, null, slr.getLocks());
assertEquals(2, slr.getLocksSize());
// There should be different txn IDs associated with each lock.
Set<Long> txnSet = new HashSet<Long>();
for (ShowLocksResponseElement lockResponseElem : slr.getLocks()) {
txnSet.add(lockResponseElem.getTxnid());
}
assertEquals(2, txnSet.size());
List<String> rows = runStatementOnDriver("show transactions");
// Header row + 2 transactions = 3 rows
assertEquals(3, rows.size());
} finally {
// Close the session which should free up the TxnHandler/locks held by the session.
// Done in the finally block to make sure we free up the locks; otherwise
// the cleanup in tearDown() will get stuck waiting on the lock held here on ACIDTBL.
restartSessionAndDriver(hiveConf);
}
// Lock should be freed up now.
ShowLocksResponse slr = txnHandler.showLocks(new ShowLocksRequest());
assertEquals(0, slr.getLocksSize());
List<String> rows = runStatementOnDriver("show transactions");
// Transactions should be committed.
// No transactions - just the header row
assertEquals(1, rows.size());
}
Aggregations