case TIMEDOUT: case ERROR: if (OperationState.CLOSED.equals(newState)) { return;
public boolean isTimedOut(long current) { if (operationTimeout == 0) { return false; } if (operationTimeout > 0) { // check only when it's in terminal state return state.isTerminal() && lastAccessTime + operationTimeout <= current; } return lastAccessTime + -operationTimeout <= current; }
public void validateTransition(OperationState newState) throws HiveSQLException { validateTransition(this, newState); }
/** * Cancel the running operation unless it is already in a terminal state * @param opHandle operation handle * @param errMsg error message * @throws HiveSQLException */ public void cancelOperation(OperationHandle opHandle, String errMsg) throws HiveSQLException { Operation operation = getOperation(opHandle); OperationState opState = operation.getStatus().getState(); if (opState.isTerminal()) { // Cancel should be a no-op in either cases LOG.debug(opHandle + ": Operation is already aborted in state - " + opState); } else { LOG.debug(opHandle + ": Attempting to cancel from state - " + opState); OperationState operationState = OperationState.CANCELED; operationState.setErrorMessage(errMsg); operation.cancel(operationState); if (operation instanceof SQLOperation) { removeSafeQueryInfo(opHandle); } } }
cliService.getOperationStatus(operationHandle, req.isGetProgressUpdate()); if (operationStatus.getState().equals(OperationState.FINISHED)) { long numModifiedRows = operationStatus.getNumModifiedRows(); resp.setNumModifiedRows(numModifiedRows); resp.setOperationState(operationStatus.getState().toTOperationState()); resp.setErrorMessage(operationStatus.getState().getErrorMessage()); HiveSQLException opException = operationStatus.getOperationException(); resp.setTaskStatus(operationStatus.getTaskStatus());
public static OperationState getOperationState(TOperationState tOperationState) { return OperationState.values()[tOperationState.getValue()]; }
@Override public OperationStatus getOperationStatus(OperationHandle opHandle, boolean getProgressUpdate) throws HiveSQLException { try { TGetOperationStatusReq req = new TGetOperationStatusReq(opHandle.toTOperationHandle()); req.setGetProgressUpdate(getProgressUpdate); TGetOperationStatusResp resp = cliService.GetOperationStatus(req); // Checks the status of the RPC call, throws an exception in case of error checkStatus(resp.getStatus()); OperationState opState = OperationState.getOperationState(resp.getOperationState()); HiveSQLException opException = null; if (opState == OperationState.ERROR) { opException = new HiveSQLException(resp.getErrorMessage(), resp.getSqlState(), resp.getErrorCode()); } return new OperationStatus(opState, resp.getTaskStatus(), resp.getOperationStarted(), resp.getOperationCompleted(), resp.isSetHasResultSet() ? resp.isHasResultSet() : null, opException); } catch (HiveSQLException e) { throw e; } catch (Exception e) { throw new HiveSQLException(e); } }
@Override public TGetOperationStatusResp GetOperationStatus(TGetOperationStatusReq req) throws TException { TGetOperationStatusResp resp = new TGetOperationStatusResp(); try { OperationStatus operationStatus = cliService.getOperationStatus( new OperationHandle(req.getOperationHandle())); resp.setOperationState(operationStatus.getState().toTOperationState()); HiveSQLException opException = operationStatus.getOperationException(); if (opException != null) { resp.setSqlState(opException.getSQLState()); resp.setErrorCode(opException.getErrorCode()); resp.setErrorMessage(opException.getMessage()); } resp.setStatus(OK_STATUS); } catch (Exception e) { LOG.warn("Error getting operation status: ", e); resp.setStatus(HiveSQLException.toTStatus(e)); } return resp; }
private Operation removeTimedOutOperation(OperationHandle operationHandle) { Operation operation = handleToOperation.get(operationHandle); if (operation != null && operation.isTimedOut(System.currentTimeMillis())) { LOG.info("Operation is timed out,operation=" + operation.getHandle() + ",state=" + operation.getState().toString()); Metrics metrics = MetricsFactory.getInstance(); if (metrics != null) { try { metrics.decrementCounter(MetricsConstant.OPEN_OPERATIONS); } catch (Exception e) { LOG.warn("Error decrementing open_operations metric, reported values may be incorrect", e); } } return removeOperation(operationHandle); } return null; }
OperationStatus operationStatus = cliService.getOperationStatus(operationHandle, req.isGetProgressUpdate()); resp.setOperationState(operationStatus.getState().toTOperationState()); resp.setErrorMessage(operationStatus.getState().getErrorMessage()); HiveSQLException opException = operationStatus.getOperationException(); resp.setTaskStatus(operationStatus.getTaskStatus());
public static OperationState getOperationState(TOperationState tOperationState) { return OperationState.values()[tOperationState.getValue()]; }
@Override public OperationStatus getOperationStatus(OperationHandle opHandle) throws HiveSQLException { try { TGetOperationStatusReq req = new TGetOperationStatusReq(opHandle.toTOperationHandle()); TGetOperationStatusResp resp = cliService.GetOperationStatus(req); // Checks the status of the RPC call, throws an exception in case of error checkStatus(resp.getStatus()); OperationState opState = OperationState.getOperationState(resp.getOperationState()); HiveSQLException opException = null; if (opState == OperationState.ERROR) { opException = new HiveSQLException(resp.getErrorMessage(), resp.getSqlState(), resp.getErrorCode()); } return new OperationStatus(opState, opException); } catch (HiveSQLException e) { throw e; } catch (Exception e) { throw new HiveSQLException(e); } }
@Override public TGetOperationStatusResp GetOperationStatus(TGetOperationStatusReq req) throws TException { TGetOperationStatusResp resp = new TGetOperationStatusResp(); try { OperationStatus operationStatus = cliService.getOperationStatus( new OperationHandle(req.getOperationHandle())); resp.setOperationState(operationStatus.getState().toTOperationState()); HiveSQLException opException = operationStatus.getOperationException(); if (opException != null) { resp.setSqlState(opException.getSQLState()); resp.setErrorCode(opException.getErrorCode()); resp.setErrorMessage(opException.getMessage()); } resp.setStatus(OK_STATUS); } catch (Exception e) { LOG.warn("Error getting operation status: ", e); resp.setStatus(HiveSQLException.toTStatus(e)); } return resp; }
/** * Cancel the running operation unless it is already in a terminal state * @param opHandle operation handle * @param errMsg error message * @throws HiveSQLException */ public void cancelOperation(OperationHandle opHandle, String errMsg) throws HiveSQLException { Operation operation = getOperation(opHandle); OperationState opState = operation.getStatus().getState(); if (opState.isTerminal()) { // Cancel should be a no-op in either cases LOG.debug(opHandle + ": Operation is already aborted in state - " + opState); } else { LOG.debug(opHandle + ": Attempting to cancel from state - " + opState); OperationState operationState = OperationState.CANCELED; operationState.setErrorMessage(errMsg); operation.cancel(operationState); if (operation instanceof SQLOperation) { removeSafeQueryInfo(opHandle); } } }
public SQLOperation(HiveSession parentSession, String statement, Map<String, String> confOverlay, boolean runInBackground, long queryTimeout) { // TODO: call setRemoteUser in ExecuteStatementOperation or higher. super(parentSession, statement, confOverlay, runInBackground); this.runAsync = runInBackground; this.queryTimeout = queryTimeout; long timeout = HiveConf.getTimeVar(queryState.getConf(), HiveConf.ConfVars.HIVE_QUERY_TIMEOUT_SECONDS, TimeUnit.SECONDS); if (timeout > 0 && (queryTimeout <= 0 || timeout < queryTimeout)) { this.queryTimeout = timeout; } this.operationLogCleanupDelayMs = HiveConf.getTimeVar(queryState.getConf(), HiveConf.ConfVars.HIVE_SERVER2_OPERATION_LOG_CLEANUP_DELAY, TimeUnit.MILLISECONDS); setupSessionIO(parentSession.getSessionState()); queryInfo = new QueryInfo(getState().toString(), getParentSession().getUserName(), getExecutionEngine(), getHandle().getHandleIdentifier().toString()); Metrics metrics = MetricsFactory.getInstance(); if (metrics != null) { submittedQryScp = metrics.createScope(MetricsConstant.HS2_SUBMITTED_QURIES); } }
public boolean isFailed() { return OperationState.ERROR.equals(state); }
public boolean isDone() { return state.isTerminal(); }
protected final OperationState setState(OperationState newState) throws HiveSQLException { state.validateTransition(newState); OperationState prevState = state; this.state = newState; currentStateScope = updateOperationStateMetrics(currentStateScope, MetricsConstant.OPERATION_PREFIX, MetricsConstant.COMPLETED_OPERATION_PREFIX, state); onNewState(state, prevState); this.lastAccessTime = System.currentTimeMillis(); return this.state; }
public static OperationState getOperationState(TOperationState tOperationState) { return OperationState.values()[tOperationState.getValue()]; }
@Override public OperationStatus getOperationStatus(OperationHandle opHandle) throws HiveSQLException { try { TGetOperationStatusReq req = new TGetOperationStatusReq(opHandle.toTOperationHandle()); TGetOperationStatusResp resp = cliService.GetOperationStatus(req); // Checks the status of the RPC call, throws an exception in case of error checkStatus(resp.getStatus()); OperationState opState = OperationState.getOperationState(resp.getOperationState()); HiveSQLException opException = null; if (opState == OperationState.ERROR) { opException = new HiveSQLException(resp.getErrorMessage(), resp.getSqlState(), resp.getErrorCode()); } return new OperationStatus(opState, opException); } catch (HiveSQLException e) { throw e; } catch (Exception e) { throw new HiveSQLException(e); } }