Package org.apache.tajo.master.event

Examples of org.apache.tajo.master.event.TaskRequestEvent


    public void assignToLeafTasks(List<TaskRequestEvent> taskRequests) {
      Collections.shuffle(taskRequests);
      Iterator<TaskRequestEvent> it = taskRequests.iterator();

      TaskRequestEvent taskRequest;
      while (it.hasNext() && leafTasks.size() > 0) {
        taskRequest = it.next();
        LOG.debug("assignToLeafTasks: " + taskRequest.getExecutionBlockId() + "," +
            "containerId=" + taskRequest.getContainerId());
        ContainerProxy container = context.getResourceAllocator().getContainer(taskRequest.getContainerId());
        if(container == null) {
          continue;
        }
        String host = container.getTaskHostName();

        QueryUnitAttemptId attemptId = null;
        LinkedList<QueryUnitAttemptId> list = null;

        // local disk allocation
        if(!leafTaskHostMapping.containsKey(host)){
          host = NetUtils.normalizeHost(host);
        }

        TaskBlockLocation taskBlockLocation = leafTaskHostMapping.get(host);
        if (taskBlockLocation != null) {
          list = taskBlockLocation.getQueryUnitAttemptIdList(taskRequest.getContainerId());
        }

        while (list != null && list.size() > 0) {
          QueryUnitAttemptId tId = list.removeFirst();

          if (leafTasks.contains(tId)) {
            leafTasks.remove(tId);
            attemptId = tId;
            //LOG.info(attemptId + " Assigned based on host match " + hostName);
            hostLocalAssigned++;
            break;
          }
        }

        // rack allocation
        if (attemptId == null) {
          String rack = RackResolver.resolve(host).getNetworkLocation();
          list = leafTasksRackMapping.get(rack);
          while(list != null && list.size() > 0) {

            QueryUnitAttemptId tId = list.removeFirst();

            if (leafTasks.contains(tId)) {
              leafTasks.remove(tId);
              attemptId = tId;
              //LOG.info(attemptId + "Assigned based on rack match " + rack);
              rackLocalAssigned++;
              break;
            }
          }

          // random allocation
          if (attemptId == null && leafTaskNum() > 0) {
            attemptId = leafTasks.iterator().next();
            leafTasks.remove(attemptId);
            //LOG.info(attemptId + " Assigned based on * match");
          }
        }

        SubQuery subQuery = context.getQuery().getSubQuery(attemptId.getQueryUnitId().getExecutionBlockId());

        if (attemptId != null) {
          QueryUnit task = subQuery.getQueryUnit(attemptId.getQueryUnitId());
          QueryUnitRequest taskAssign = new QueryUnitRequestImpl(
              attemptId,
              new ArrayList<Fragment>(task.getAllFragments()),
              "",
              false,
              task.getLogicalPlan().toJson(),
              context.getQueryContext(),
              subQuery.getDataChannel(), subQuery.getBlock().getEnforcer());
          if (!subQuery.getBlock().isRoot()) {
            taskAssign.setInterQuery();
          }

          context.getEventHandler().handle(new TaskAttemptAssignedEvent(attemptId,
              taskRequest.getContainerId(),
              host, container.getTaskPort()));
          assignedRequest.add(attemptId);

          totalAssigned++;
          taskRequest.getCallback().run(taskAssign.getProto());
        } else {
          throw new RuntimeException("Illegal State!!!!!!!!!!!!!!!!!!!!!");
        }
      }

View Full Code Here


    }

    public void assignToNonLeafTasks(List<TaskRequestEvent> taskRequests) {
      Iterator<TaskRequestEvent> it = taskRequests.iterator();

      TaskRequestEvent taskRequest;
      while (it.hasNext()) {
        taskRequest = it.next();
        LOG.debug("assignToNonLeafTasks: " + taskRequest.getExecutionBlockId());

        QueryUnitAttemptId attemptId;
        // random allocation
        if (nonLeafTasks.size() > 0) {
          attemptId = nonLeafTasks.iterator().next();
          nonLeafTasks.remove(attemptId);
          LOG.debug("Assigned based on * match");

          QueryUnit task;
          SubQuery subQuery = context.getSubQuery(attemptId.getQueryUnitId().getExecutionBlockId());
          task = subQuery.getQueryUnit(attemptId.getQueryUnitId());
          QueryUnitRequest taskAssign = new QueryUnitRequestImpl(
              attemptId,
              Lists.newArrayList(task.getAllFragments()),
              "",
              false,
              task.getLogicalPlan().toJson(),
              context.getQueryContext(),
              subQuery.getDataChannel(),
              subQuery.getBlock().getEnforcer());
          if (!subQuery.getBlock().isRoot()) {
            taskAssign.setInterQuery();
          }
          for (ScanNode scan : task.getScanNodes()) {
            Collection<URI> fetches = task.getFetch(scan);
            if (fetches != null) {
              for (URI fetch : fetches) {
                taskAssign.addFetch(scan.getTableName(), fetch);
              }
            }
          }

          ContainerProxy container = context.getResourceAllocator().getContainer(
              taskRequest.getContainerId());
          context.getEventHandler().handle(new TaskAttemptAssignedEvent(attemptId,
              taskRequest.getContainerId(), container.getTaskHostName(), container.getTaskPort()));
          taskRequest.getCallback().run(taskAssign.getProto());
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.tajo.master.event.TaskRequestEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.