コード例 #1
0
ファイル: Query.java プロジェクト: hyunsik/incubator-tajo
    @Override
    public void transition(Query query, QueryEvent event) {
      try {
        query.completedSubQueryCount++;
        SubQueryCompletedEvent castEvent = (SubQueryCompletedEvent) event;

        if (castEvent.getState() == SubQueryState.SUCCEEDED) {
          query.successedSubQueryCount++;
        } else if (castEvent.getState() == SubQueryState.KILLED) {
          query.killedSubQueryCount++;
        } else if (castEvent.getState() == SubQueryState.FAILED) {
          query.failedSubQueryCount++;
        } else if (castEvent.getState() == SubQueryState.ERROR) {
          query.erroredSubQueryCount++;
        } else {
          LOG.error(
              String.format(
                  "Invalid SubQuery (%s) State %s at %s",
                  castEvent.getExecutionBlockId().toString(),
                  castEvent.getState().name(),
                  query.getState().name()));
          query.eventHandler.handle(
              new QueryEvent(event.getQueryId(), QueryEventType.INTERNAL_ERROR));
        }

        // if a subquery is succeeded and a query is running
        if (castEvent.getState() == SubQueryState.SUCCEEDED
            && // latest subquery succeeded
            query.getState() == QueryState.QUERY_RUNNING
            && // current state is not in KILL_WAIT, FAILED, or ERROR.
            hasNext(query)) { // there remains at least one subquery.
          executeNextBlock(query);
        } else { // if a query is completed due to finished, kill, failure, or error
          query.eventHandler.handle(
              new QueryCompletedEvent(castEvent.getExecutionBlockId(), castEvent.getState()));
        }
      } catch (Throwable t) {
        LOG.error(t);
        query.eventHandler.handle(
            new QueryEvent(event.getQueryId(), QueryEventType.INTERNAL_ERROR));
      }
    }
コード例 #2
0
ファイル: Query.java プロジェクト: hyunsik/incubator-tajo
  @Override
  public void handle(QueryEvent event) {
    LOG.info("Processing " + event.getQueryId() + " of type " + event.getType());
    try {
      writeLock.lock();
      QueryState oldState = getState();
      try {
        getStateMachine().doTransition(event.getType(), event);
      } catch (InvalidStateTransitonException e) {
        LOG.error("Can't handle this event at current state", e);
        eventHandler.handle(new QueryEvent(this.id, QueryEventType.INTERNAL_ERROR));
      }

      // notify the eventhandler of state change
      if (oldState != getState()) {
        LOG.info(id + " Query Transitioned from " + oldState + " to " + getState());
      }
    } finally {
      writeLock.unlock();
    }
  }