Search in sources :

Example 1 with Operation

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

the class CLIService method getOperationStatus.

/* (non-Javadoc)
   * @see org.apache.hive.service.cli.ICLIService#getOperationStatus(org.apache.hive.service.cli.OperationHandle)
   */
@Override
public OperationStatus getOperationStatus(OperationHandle opHandle, boolean getProgressUpdate) throws HiveSQLException {
    Operation operation = sessionManager.getOperationManager().getOperation(opHandle);
    /**
     * If this is a background operation run asynchronously,
     * we block for a duration determined by a step function, before we return
     * However, if the background operation is complete, we return immediately.
     */
    HiveConf conf = operation.getParentSession().getHiveConf();
    if (operation.shouldRunAsync()) {
        long maxTimeout = HiveConf.getTimeVar(conf, HiveConf.ConfVars.HIVE_SERVER2_LONG_POLLING_TIMEOUT, TimeUnit.MILLISECONDS);
        final long elapsed = System.currentTimeMillis() - operation.getBeginTime();
        // A step function to increase the polling timeout by 500 ms every 10 sec,
        // starting from 500 ms up to HIVE_SERVER2_LONG_POLLING_TIMEOUT
        final long timeout = Math.min(maxTimeout, (elapsed / TimeUnit.SECONDS.toMillis(10) + 1) * 500);
        try {
            operation.getBackgroundHandle().get(timeout, TimeUnit.MILLISECONDS);
        } catch (TimeoutException e) {
            // No Op, return to the caller since long polling timeout has expired
            LOG.trace(opHandle + ": Long polling timed out");
        } catch (CancellationException e) {
            // The background operation thread was cancelled
            LOG.trace(opHandle + ": The background operation was cancelled", e);
        } catch (ExecutionException e) {
            // Note: Hive ops do not use the normal Future failure path, so this will not happen
            // in case of actual failure; the Future will just be done.
            // The background operation thread was aborted
            LOG.warn(opHandle + ": The background operation was aborted", e);
        } catch (InterruptedException e) {
        // No op, this thread was interrupted
        // In this case, the call might return sooner than long polling timeout
        }
    }
    OperationStatus opStatus = operation.getStatus();
    LOG.debug(opHandle + ": getOperationStatus()");
    opStatus.setJobProgressUpdate(progressUpdateLog(getProgressUpdate, operation, conf));
    return opStatus;
}
Also used : CancellationException(java.util.concurrent.CancellationException) HiveConf(org.apache.hadoop.hive.conf.HiveConf) Operation(org.apache.hive.service.cli.operation.Operation) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with Operation

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

the class KillQueryImpl method killQuery.

@Override
public void killQuery(String queryId, String errMsg) throws HiveException {
    try {
        Operation operation = operationManager.getOperationByQueryId(queryId);
        if (operation == null) {
            LOG.info("Query not found: " + queryId);
        } else {
            OperationHandle handle = operation.getHandle();
            operationManager.cancelOperation(handle, errMsg);
        }
    } catch (HiveSQLException e) {
        throw new HiveException(e);
    }
}
Also used : HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) Operation(org.apache.hive.service.cli.operation.Operation) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Example 3 with Operation

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

the class ThriftCLIService method getProgressedPercentage.

private double getProgressedPercentage(OperationHandle opHandle) throws HiveSQLException {
    checkArgument(OperationType.EXECUTE_STATEMENT.equals(opHandle.getOperationType()));
    Operation operation = cliService.getSessionManager().getOperationManager().getOperation(opHandle);
    SessionState state = operation.getParentSession().getSessionState();
    ProgressMonitor monitor = state.getProgressMonitor();
    return monitor == null ? 0.0 : monitor.progressedPercentage();
}
Also used : ProgressMonitor(org.apache.hadoop.hive.common.log.ProgressMonitor) SessionState(org.apache.hadoop.hive.ql.session.SessionState) Operation(org.apache.hive.service.cli.operation.Operation)

Example 4 with Operation

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

the class CLIService method getQueryId.

@Override
public String getQueryId(TOperationHandle opHandle) throws HiveSQLException {
    Operation operation = sessionManager.getOperationManager().getOperation(new OperationHandle(opHandle));
    final String queryId = operation.getParentSession().getHiveConf().getVar(ConfVars.HIVEQUERYID);
    LOG.debug(opHandle + ": getQueryId() " + queryId);
    return queryId;
}
Also used : Operation(org.apache.hive.service.cli.operation.Operation) TOperationHandle(org.apache.hive.service.rpc.thrift.TOperationHandle)

Aggregations

Operation (org.apache.hive.service.cli.operation.Operation)4 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 ProgressMonitor (org.apache.hadoop.hive.common.log.ProgressMonitor)1 HiveConf (org.apache.hadoop.hive.conf.HiveConf)1 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)1 SessionState (org.apache.hadoop.hive.ql.session.SessionState)1 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)1 OperationHandle (org.apache.hive.service.cli.OperationHandle)1 TOperationHandle (org.apache.hive.service.rpc.thrift.TOperationHandle)1