ErrorCode LogParser::processFileCreationEntry()

in util/TransferLogManager.cpp [814:869]


ErrorCode LogParser::processFileCreationEntry(char *buf, int64_t size) {
  if (!headerParsed_) {
    WLOG(ERROR)
        << "Invalid log: File creation entry found before transfer log header";
    return INVALID_LOG;
  }
  int64_t timestamp, seqId, fileSize;
  string fileName;
  if (!encoderDecoder_.decodeFileCreationEntry(buf, size, timestamp, fileName,
                                               seqId, fileSize)) {
    return INVALID_LOG;
  }
  if (parseOnly_) {
    std::cout << getFormattedTimestamp(timestamp) << " File created "
              << fileName << " seq-id " << seqId << " file-size " << fileSize
              << std::endl;
    return OK;
  }
  if (options_.resume_using_dir_tree) {
    WLOG(ERROR) << "Can not have a file creation entry in directory based "
                   "resumption mode "
                << fileName << " " << seqId << " " << fileSize;
    return INVALID_LOG;
  }
  if (fileInfoMap_.find(seqId) != fileInfoMap_.end() ||
      invalidSeqIds_.find(seqId) != invalidSeqIds_.end()) {
    WLOG(ERROR) << "Multiple FILE_CREATION entry for same sequence-id "
                << fileName << " " << seqId << " " << fileSize;
    return INVALID_LOG;
  }
  // verify size
  bool sizeVerificationSuccess = false;
  struct stat buffer;
  string fullPath;
  folly::toAppend(rootDir_, fileName, &fullPath);
  if (stat(fullPath.c_str(), &buffer) != 0) {
    WPLOG(ERROR) << "stat failed for " << fileName;
  } else {
    if (options_.shouldPreallocateFiles()) {
      sizeVerificationSuccess = (buffer.st_size >= fileSize);
    } else {
      sizeVerificationSuccess = true;
    }
  }

  if (sizeVerificationSuccess) {
    fileInfoMap_.emplace(seqId,
                         FileChunksInfo(seqId, fileName, buffer.st_size));
    seqIdToSizeMap_.emplace(seqId, fileSize);
  } else {
    WLOG(INFO) << "Sanity check failed for " << fileName << " seq-id " << seqId
               << " file-size " << fileSize;
    invalidSeqIds_.insert(seqId);
  }
  return OK;
}