Exemplo n.º 1
0
  static void writeToIndexFile(
      String logLocation,
      TaskAttemptID currentTaskid,
      boolean isCleanup,
      Map<LogName, Long[]> lengths)
      throws IOException {
    // To ensure atomicity of updates to index file, write to temporary
    // index
    // file first and then rename.
    File tmpIndexFile = getTmpIndexFile(currentTaskid, isCleanup);

    BufferedOutputStream bos =
        new BufferedOutputStream(SecureIOUtils.createForWrite(tmpIndexFile, 0644));
    DataOutputStream dos = new DataOutputStream(bos);
    // the format of the index file is
    // LOG_DIR: <the dir where the task logs are really stored>
    // STDOUT: <start-offset in the stdout file> <length>
    // STDERR: <start-offset in the stderr file> <length>
    // SYSLOG: <start-offset in the syslog file> <length>
    dos.writeBytes(LogFileDetail.LOCATION + logLocation + "\n");
    for (LogName logName : LOGS_TRACKED_BY_INDEX_FILES) {
      Long[] lens = lengths.get(logName);
      dos.writeBytes(
          logName.toString()
              + ":"
              + lens[0].toString()
              + " "
              + Long.toString(lens[1].longValue() - lens[0].longValue())
              + "\n");
    }
    dos.close();

    File indexFile = getIndexFile(currentTaskid, isCleanup);
    Path indexFilePath = new Path(indexFile.getAbsolutePath());
    Path tmpIndexFilePath = new Path(tmpIndexFile.getAbsolutePath());

    if (localFS == null) { // set localFS once
      localFS = FileSystem.getLocal(new Configuration());
    }
    localFS.rename(tmpIndexFilePath, indexFilePath);
  }