QueryFragmentInfo registerFragment(QueryIdentifier queryIdentifier, String appIdString, String dagIdString,
    String dagName, String hiveQueryIdString, int dagIdentifier, String vertexName, int fragmentNumber,
    int attemptNumber,
    String user, SignableVertexSpec vertex, Token<JobTokenIdentifier> appToken,
      String fragmentIdString, LlapTokenInfo tokenInfo, final LlapNodeId amNodeId,
      ContainerRunnerImpl.UgiPool ugiPool) throws IOException {

    ReadWriteLock dagLock = getDagLock(queryIdentifier);
    // Note: This is a readLock to prevent a race with queryComplete. Operations
    // and mutations within this lock need to be on concurrent structures.
    dagLock.readLock().lock();
    try {
      if (completedDagMap.contains(queryIdentifier)) {
        // Cleanup the dag lock here, since it may have been created after the query completed
        dagSpecificLocks.remove(queryIdentifier);
        String message = "Dag " + dagName + " already complete. Rejecting fragment ["
            + vertexName + ", " + fragmentNumber + ", " + attemptNumber + "]";
        LOG.info(message);
        throw new RuntimeException(message);
      }
      // TODO: for now, we get the secure username out of UGI... after signing, we can take it
      //       out of the request provided that it's signed.
      if (tokenInfo == null) {
        tokenInfo = LlapTokenChecker.getTokenInfo(clusterId);
      }
      boolean isExistingQueryInfo = true;
      QueryInfo queryInfo = queryInfoMap.get(queryIdentifier);
      if (queryInfo == null) {
        if (UserGroupInformation.isSecurityEnabled()) {
          Preconditions.checkNotNull(tokenInfo.userName);
        }
        queryInfo =
            new QueryInfo(queryIdentifier, appIdString, dagIdString, dagName, hiveQueryIdString,
                dagIdentifier, user,
                getSourceCompletionMap(queryIdentifier), localDirsBase, localFs,
                tokenInfo.userName, tokenInfo.appId, amNodeId, vertex.getTokenIdentifier(), appToken,
                vertex.getIsExternalSubmission(), ugiPool);
        QueryInfo old = queryInfoMap.putIfAbsent(queryIdentifier, queryInfo);
        if (old != null) {
          queryInfo = old;
        } else {
          isExistingQueryInfo = false;
        }
      }
      if (isExistingQueryInfo) {
        // We already retrieved the incoming info, check without UGI.
        LlapTokenChecker.checkPermissions(tokenInfo, queryInfo.getTokenUserName(),
            queryInfo.getTokenAppId(), queryInfo.getQueryIdentifier());
      }

      queryIdentifierToHiveQueryId.putIfAbsent(queryIdentifier, hiveQueryIdString);

      LOG.debug("Registering request for {} with the ShuffleHandler", queryIdentifier);
      if (!vertex.getIsExternalSubmission()) {
        String[] localDirs = (ShuffleHandler.get().isDirWatcherEnabled()) ? queryInfo.getLocalDirs() : null;
        ShuffleHandler.get()
            .registerDag(appIdString, dagIdentifier, appToken, user, localDirs);
      }

      return queryInfo.registerFragment(
          vertexName, fragmentNumber, attemptNumber, vertex, fragmentIdString);
    } finally {
      dagLock.readLock().unlock();
    }
  }
Register a new fragment for a specific query
llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/QueryTracker.java