apache/hadoop · error · UnsupportedOperationException

ProvidedReplica does not yet support truncate

Error message

ProvidedReplica does not yet support truncate

What it means

truncateBlock(long) shortens a replica's data (and meta) file when a client truncates a file. ProvidedReplica throws UnsupportedOperationException because the bytes live in an immutable external store; the DataNode cannot rewrite them to a new length.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/ProvidedReplica.java:324

      throws UnsupportedOperationException {
    throw new UnsupportedOperationException(
        "ProvidedReplica does not yet support writes");
  }

  @Override
  public int compareWith(ScanInfo info) {
    if (info.getFileRegion().equals(
        new FileRegion(this.getBlockId(), new Path(getRemoteURI()),
            fileOffset, this.getNumBytes(), this.getGenerationStamp()))) {
      return 0;
    } else {
      return (int) (info.getBlockLength() - getNumBytes());
    }
  }

  @Override
  public void truncateBlock(long newLength) throws IOException {
    throw new UnsupportedOperationException(
        "ProvidedReplica does not yet support truncate");
  }

  @Override
  public void updateWithReplica(StorageLocation replicaLocation) {
    throw new UnsupportedOperationException(
        "ProvidedReplica does not yet support update");
  }

  @Override
  public void copyMetadata(URI destination) throws IOException {
    throw new UnsupportedOperationException(
        "ProvidedReplica does not yet support copy metadata");
  }

  @Override
  public void copyBlockdata(URI destination) throws IOException {
    throw new UnsupportedOperationException(

View on GitHub (pinned to 2add963021)

Solutions

  1. Do not issue truncate against files on provided storage; enforce this at the application/job layer or via namespace permissions.
  2. If truncation is genuinely needed, copy the file to local HDFS storage first, truncate there, and write back as a new object.
  3. Pre-check replica type (instanceof ProvidedReplica / volume SupportedOperation) before truncateBlock and fail with a descriptive IOException.
  4. Catch UnsupportedOperationException at the truncation worker boundary and surface a clear 'read-only provided storage' error to the client.

Example fix

// before
replica.truncateBlock(newLength);

// after
if (replica instanceof ProvidedReplica) {
  throw new IOException("PROVIDED replica " + replica.getBlockId()
      + " is read-only; truncate is not supported");
}
replica.truncateBlock(newLength);
Defensive patterns

Strategy: validation

Validate before calling

if (replica instanceof ProvidedReplica) {
  throw new IOException("PROVIDED replica " + replica.getBlockId()
      + " is read-only; truncate is not supported");
}
replica.truncateBlock(newLength);

Type guard

static boolean isProvided(ReplicaInfo r) {
  return r instanceof ProvidedReplica;
}

Try / catch

try {
  replica.truncateBlock(newLength);
} catch (UnsupportedOperationException e) {
  throw new IOException("Cannot truncate file on provided storage", e);
}

Prevention

When it happens

Trigger: A client calls DistributedFileSystem.truncate() (or HdfsDataOutputStream-level truncate APIs) on a file whose blocks resolve to PROVIDED replicas; the DataNode-side truncate path reaches truncateBlock on a ProvidedReplica and throws.

Common situations: Read-only provided mounts (e.g. S3HDFS/aliased imports) exposed as writable-looking namespaces; users run compaction or truncation jobs against them. Also custom FsDataset tests that call truncateBlock on every replica type.

Related errors


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