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;
}
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);
}
}
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();
}
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;
}
Aggregations