Search in sources :

Example 6 with OperationManager

use of org.apache.hive.service.cli.operation.OperationManager in project hive by apache.

the class HiveSessionImpl method getTableTypes.

@Override
public OperationHandle getTableTypes() throws HiveSQLException {
    acquire(true, true);
    OperationManager operationManager = getOperationManager();
    GetTableTypesOperation operation = operationManager.newGetTableTypesOperation(getSession());
    OperationHandle opHandle = operation.getHandle();
    try {
        addOpHandle(opHandle);
        operation.run();
        return opHandle;
    } catch (HiveSQLException e) {
        removeOpHandle(opHandle);
        operationManager.closeOperation(opHandle);
        throw e;
    } finally {
        release(true, true);
    }
}
Also used : GetTableTypesOperation(org.apache.hive.service.cli.operation.GetTableTypesOperation) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) OperationManager(org.apache.hive.service.cli.operation.OperationManager) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Example 7 with OperationManager

use of org.apache.hive.service.cli.operation.OperationManager in project hive by apache.

the class TestSessionGlobalInitFile method doTestSessionGlobalInitFile.

/**
 * create session, and fetch the property set in global init file. Test if
 * the global init file .hiverc is loaded correctly by checking the expected
 * setting property.
 */
private void doTestSessionGlobalInitFile() throws Exception {
    OperationManager operationManager = service.getService().getSessionManager().getOperationManager();
    SessionHandle sessionHandle = client.openSession(null, null, null);
    // ensure there is no operation related object leak
    Assert.assertEquals("Verifying all operations used for init file are closed", 0, operationManager.getOperations().size());
    verifyInitProperty("a", "1", sessionHandle);
    verifyInitProperty("b", "1", sessionHandle);
    verifyInitProperty("c", "1", sessionHandle);
    verifyInitProperty("hivevar:c", "1", sessionHandle);
    verifyInitProperty("d", "1", sessionHandle);
    /**
     * TODO: client.executeStatement do not support listing resources command
     * (beeline> list jar)
     */
    // Assert.assertEquals("expected uri", api.getAddedResource("jar"));
    Assert.assertEquals("Verifying all operations used for checks are closed", 0, operationManager.getOperations().size());
    client.closeSession(sessionHandle);
}
Also used : SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationManager(org.apache.hive.service.cli.operation.OperationManager)

Example 8 with OperationManager

use of org.apache.hive.service.cli.operation.OperationManager in project hive by apache.

the class TestSessionManagerMetrics method testActiveSessionTimeMetrics.

@Test
public void testActiveSessionTimeMetrics() throws Exception {
    final CyclicBarrier ready = new CyclicBarrier(2);
    CyclicBarrier completed = new CyclicBarrier(2);
    String json = metrics.dumpJson();
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_AVG_ACTIVE_SESSION_TIME, "NaN");
    SessionHandle handle = sm.openSession(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9, "user", "passw", "127.0.0.1", new HashMap<String, String>());
    final HiveSession session = sm.getSession(handle);
    OperationManager operationManager = mock(OperationManager.class);
    when(operationManager.newGetTablesOperation(session, "catalog", "schema", "table", null)).thenReturn(new BlockingOperation(session, OperationType.GET_TABLES, ready, completed));
    session.setOperationManager(operationManager);
    long sessionActivateTime = System.currentTimeMillis();
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                OperationHandle handle = session.getTables("catalog", "schema", "table", null);
                session.closeOperation(handle);
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                try {
                    ready.await();
                } catch (InterruptedException | BrokenBarrierException e) {
                // ignore
                }
            }
        }
    }).start();
    ready.await(2, TimeUnit.SECONDS);
    ready.reset();
    json = metrics.dumpJson();
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_AVG_ACTIVE_SESSION_TIME, (double) System.currentTimeMillis() - sessionActivateTime, 100d);
    completed.await(2, TimeUnit.SECONDS);
    ready.await(2, TimeUnit.SECONDS);
    json = metrics.dumpJson();
    MetricsTestUtils.verifyMetricsJson(json, MetricsTestUtils.GAUGE, MetricsConstant.HS2_AVG_ACTIVE_SESSION_TIME, "NaN");
}
Also used : BrokenBarrierException(java.util.concurrent.BrokenBarrierException) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) TimeoutException(java.util.concurrent.TimeoutException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) CyclicBarrier(java.util.concurrent.CyclicBarrier) OperationManager(org.apache.hive.service.cli.operation.OperationManager) Test(org.junit.Test)

Example 9 with OperationManager

use of org.apache.hive.service.cli.operation.OperationManager in project hive by apache.

the class TestHiveSessionImpl method testLeakOperationHandle.

/**
 * Verifying OperationManager.closeOperation(opHandle) is invoked when
 * get HiveSQLException during sync query
 * @throws HiveSQLException
 */
@Test
public void testLeakOperationHandle() throws HiveSQLException {
    // create HiveSessionImpl object
    TProtocolVersion protocol = TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V2;
    String username = "";
    String password = "";
    HiveConf serverhiveConf = new HiveConf();
    String ipAddress = null;
    HiveSessionImpl session = new HiveSessionImpl(null, protocol, username, password, serverhiveConf, ipAddress, null) {

        @Override
        protected synchronized void acquire(boolean userAccess, boolean isOperation) {
        }

        @Override
        protected synchronized void release(boolean userAccess, boolean isOperation) {
        }
    };
    // mock operationManager for session
    OperationManager operationManager = Mockito.mock(OperationManager.class);
    session.setOperationManager(operationManager);
    // mock operation and opHandle for operationManager
    ExecuteStatementOperation operation = Mockito.mock(ExecuteStatementOperation.class);
    OperationHandle opHandle = Mockito.mock(OperationHandle.class);
    Mockito.when(operation.getHandle()).thenReturn(opHandle);
    Map<String, String> confOverlay = new HashMap<String, String>();
    String hql = "drop table if exists table_not_exists";
    Mockito.when(operationManager.newExecuteStatementOperation(same(session), eq(hql), (Map<String, String>) Mockito.any(), eq(true), eq(0L))).thenReturn(operation);
    try {
        // Running a normal async query with no exceptions,then no need to close opHandle
        session.open(new HashMap<String, String>());
        session.executeStatementAsync(hql, confOverlay);
        Mockito.verify(operationManager, Mockito.times(0)).closeOperation(opHandle);
        // Throw an HiveSqlException when do async calls
        Mockito.doThrow(new HiveSQLException("Fail for clean up test")).when(operation).run();
        session.executeStatementAsync(hql, confOverlay);
        Assert.fail("HiveSqlException expected.");
    } catch (HiveSQLException e) {
        if (!"Fail for clean up test".equals(e.getMessage())) {
            Assert.fail("unexpected exception:" + Arrays.toString(e.getStackTrace()));
        }
        // operationManager.closeOperation() is expected to be invoked once
        Mockito.verify(operationManager, Mockito.times(1)).closeOperation(opHandle);
    }
}
Also used : ExecuteStatementOperation(org.apache.hive.service.cli.operation.ExecuteStatementOperation) TProtocolVersion(org.apache.hive.service.rpc.thrift.TProtocolVersion) HashMap(java.util.HashMap) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) HiveConf(org.apache.hadoop.hive.conf.HiveConf) OperationManager(org.apache.hive.service.cli.operation.OperationManager) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Example 10 with OperationManager

use of org.apache.hive.service.cli.operation.OperationManager in project hive by apache.

the class HiveSessionImpl method getPrimaryKeys.

@Override
public OperationHandle getPrimaryKeys(String catalog, String schema, String table) throws HiveSQLException {
    acquire(true, true);
    OperationManager operationManager = getOperationManager();
    GetPrimaryKeysOperation operation = operationManager.newGetPrimaryKeysOperation(getSession(), catalog, schema, table);
    OperationHandle opHandle = operation.getHandle();
    try {
        addOpHandle(opHandle);
        operation.run();
        return opHandle;
    } catch (HiveSQLException e) {
        removeOpHandle(opHandle);
        operationManager.closeOperation(opHandle);
        throw e;
    } finally {
        release(true, true);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) OperationManager(org.apache.hive.service.cli.operation.OperationManager) GetPrimaryKeysOperation(org.apache.hive.service.cli.operation.GetPrimaryKeysOperation) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Aggregations

OperationManager (org.apache.hive.service.cli.operation.OperationManager)14 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)12 OperationHandle (org.apache.hive.service.cli.OperationHandle)12 SessionHandle (org.apache.hive.service.cli.SessionHandle)3 Test (org.junit.Test)3 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)2 TimeoutException (java.util.concurrent.TimeoutException)2 HiveConf (org.apache.hadoop.hive.conf.HiveConf)2 HashMap (java.util.HashMap)1 ServletContext (javax.servlet.ServletContext)1 IMetaStoreClient (org.apache.hadoop.hive.metastore.IMetaStoreClient)1 QueryInfo (org.apache.hadoop.hive.ql.QueryInfo)1 ExecuteStatementOperation (org.apache.hive.service.cli.operation.ExecuteStatementOperation)1 GetCatalogsOperation (org.apache.hive.service.cli.operation.GetCatalogsOperation)1 GetColumnsOperation (org.apache.hive.service.cli.operation.GetColumnsOperation)1 GetCrossReferenceOperation (org.apache.hive.service.cli.operation.GetCrossReferenceOperation)1 GetFunctionsOperation (org.apache.hive.service.cli.operation.GetFunctionsOperation)1 GetPrimaryKeysOperation (org.apache.hive.service.cli.operation.GetPrimaryKeysOperation)1 GetSchemasOperation (org.apache.hive.service.cli.operation.GetSchemasOperation)1