Search in sources :

Example 16 with ShowLocksResponse

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());
}
Also used : ShowLocksRequest(org.apache.hadoop.hive.metastore.api.ShowLocksRequest) HiveConf(org.apache.hadoop.hive.conf.HiveConf) TxnStore(org.apache.hadoop.hive.metastore.txn.TxnStore) ShowLocksResponse(org.apache.hadoop.hive.metastore.api.ShowLocksResponse) HashSet(java.util.HashSet) ShowLocksResponseElement(org.apache.hadoop.hive.metastore.api.ShowLocksResponseElement) Test(org.junit.Test)

Aggregations

ShowLocksResponse (org.apache.hadoop.hive.metastore.api.ShowLocksResponse)16 ShowLocksRequest (org.apache.hadoop.hive.metastore.api.ShowLocksRequest)13 Test (org.junit.Test)10 ShowLocksResponseElement (org.apache.hadoop.hive.metastore.api.ShowLocksResponseElement)7 ArrayList (java.util.ArrayList)4 TxnStore (org.apache.hadoop.hive.metastore.txn.TxnStore)4 DbLockManager (org.apache.hadoop.hive.ql.lockmgr.DbLockManager)3 SQLException (java.sql.SQLException)2 HashSet (java.util.HashSet)2 HiveConf (org.apache.hadoop.hive.conf.HiveConf)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 HiveLockManager (org.apache.hadoop.hive.ql.lockmgr.HiveLockManager)2 DataOutputStream (java.io.DataOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 ExecutionException (java.util.concurrent.ExecutionException)1