apache/hadoop · error · RuntimeException

failed to create tmp file

Error message

failed to create tmp file

What it means

FileStore.createTmpFile() stages every write through a hidden '.tmp.<random-uuid>' file next to the destination and throws this RuntimeException when createNewFile() returns false or throws IOException — i.e. the staging file could not be created in the destination's directory. Because all writes (put, part uploads, completeUpload) go through this helper, any failure to create a temp file surfaces here.

Source

Thrown at hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/object/FileStore.java:204

      if (contentLength == 0) {
        throw new NotAppendableException(String.format(
            "%s is not appendable because append non-existed object with "
                + "zero byte is not supported.", key));
      }
      return put(key, streamProvider, contentLength);
    } else {
      appendInputStreamToFile(streamProvider.newStream(), destFile, contentLength);
      return ObjectInfo.isDir(key) ? Constants.MAGIC_CHECKSUM : getFileChecksum(destFile.toPath());
    }
  }

  private static File createTmpFile(File destFile) {
    String tmpFilename = ".tmp." + UUIDUtils.random();
    File file = new File(destFile.getParentFile(), tmpFilename);

    try {
      if (!file.exists() && !file.createNewFile()) {
        throw new RuntimeException("failed to create tmp file");
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    return file;
  }

  @Override
  public void delete(String key) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(key), "Key should not be empty.");
    File file = path(encode(key)).toFile();
    if (file.exists()) {
      try {
        if (file.isDirectory()) {
          FileUtils.deleteDirectory(file);
        } else {
          Files.delete(file.toPath());
        }

View on GitHub (pinned to 2add963021)

Solutions

  1. Check free space and open-file limits on the volume backing the store root: df -h <root>, ulimit -n
  2. Ensure the store root (and nothing else) owns the __STAGING__ subtree and it is writable: ls -ld <root>/__STAGING__
  3. Restart the operation after cleaning stale .tmp.* files left by crashed runs: find <root> -name '.tmp.*' -delete
  4. Verify no concurrent code deletes the root/staging directory while uploads are active (e.g. @After cleanup racing with async writers)
Defensive patterns

Strategy: validation

Validate before calling

java.io.File rootDir = new java.io.File(
    conf.get("fs.filestore.endpoint", System.getenv("FILE_STORAGE_ROOT")));
if (!rootDir.isDirectory() || !rootDir.canWrite()) {
  throw new IOException("filestore root missing or not writable: " + rootDir);
}
if (rootDir.getUsableSpace() < REQUIRED_FREE_BYTES) {
  throw new IOException("low disk under filestore root: " + rootDir);
}

Prevention

When it happens

Trigger: put()/uploadPart()/completeUpload() reaching createTmpFile() when the destination's parent directory does not exist, is not writable, the filesystem is full, the process hit its open-file limit, or (rarely) the random name already exists and the exists() check raced.

Common situations: Filestore root or __STAGING__ subtree left in a bad state after a crashed run; test containers with a tiny tmpfs that fills up; ulimit -n exhausted by leaky test code; root directory deleted concurrently by cleanup code while uploads are in flight.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/4cd9f456322ca6a4. Report an issue: GitHub.