{"record":{"id":"b117a8e37d11cee7","repo":"apache/hadoop","slug":"providedreplica-does-not-yet-support-copy-metadata","errorCode":null,"errorMessage":"ProvidedReplica does not yet support copy metadata","messagePattern":"ProvidedReplica does not yet support copy metadata","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/ProvidedReplica.java","lineNumber":336,"sourceCode":"      return (int) (info.getBlockLength() - getNumBytes());\n    }\n  }\n\n  @Override\n  public void truncateBlock(long newLength) throws IOException {\n    throw new UnsupportedOperationException(\n        \"ProvidedReplica does not yet support truncate\");\n  }\n\n  @Override\n  public void updateWithReplica(StorageLocation replicaLocation) {\n    throw new UnsupportedOperationException(\n        \"ProvidedReplica does not yet support update\");\n  }\n\n  @Override\n  public void copyMetadata(URI destination) throws IOException {\n    throw new UnsupportedOperationException(\n        \"ProvidedReplica does not yet support copy metadata\");\n  }\n\n  @Override\n  public void copyBlockdata(URI destination) throws IOException {\n    throw new UnsupportedOperationException(\n        \"ProvidedReplica does not yet support copy data\");\n  }\n\n  @VisibleForTesting\n  public void setPathHandle(PathHandle pathHandle) {\n    this.pathHandle = pathHandle;\n  }\n}\n","sourceCodeStart":318,"sourceCodeEnd":351,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/ProvidedReplica.java#L318-L351","documentation":"copyMetadata(URI destination) copies a replica's checksum meta file alongside its data when a block is copied into this DataNode (FsDatasetImpl.copyBlock). ProvidedReplica throws UnsupportedOperationException because its 'metadata' is the synthesized NULL_CHECKSUM_ARRAY - there is no meta file to copy to a destination URI.","triggerScenarios":"Block replication delivers a block to a DataNode and the volume chooser picks a PROVIDED volume; FsDatasetImpl.copyBlock calls copyMetadata(destination) on the newly created FinalizedProvidedReplica to duplicate the source's meta stream.","commonSituations":"Provided storage configured alongside local volumes, and the NameNode schedules a replication pipeline whose target datanode lands the copy on the provided volume; also custom tests calling copyMetadata directly on ProvidedReplica.","solutions":["Ensure PROVIDED volumes are never chosen as replication-landing targets (they only serve pre-existing aliased data).","Check instanceof ProvidedReplica / volume type before copyMetadata and abort the copy with a clear error.","Fix the volume-choosing policy (available space / supported writes) so writes go to local volumes.","Catch UnsupportedOperationException in the copy path and free any partially-created replica before rethrowing."],"exampleFix":"// before\nreplica.copyMetadata(destUri);\n\n// after\nif (replica instanceof ProvidedReplica) {\n  throw new IOException(\"Cannot copy metadata into read-only PROVIDED replica\");\n}\nreplica.copyMetadata(destUri);","handlingStrategy":"validation","validationCode":"if (replica instanceof ProvidedReplica) {\n  throw new IOException(\"Cannot copy metadata into read-only PROVIDED replica\");\n}\nreplica.copyMetadata(destUri);","typeGuard":"static boolean isProvided(ReplicaInfo r) {\n  return r instanceof ProvidedReplica;\n}","tryCatchPattern":"try {\n  replica.copyMetadata(destUri);\n} catch (UnsupportedOperationException e) {\n  // roll back the partially created replica, then fail the copy\n  dataset.invalidate(bpid, replica.getBlock());\n  throw new IOException(\"PROVIDED volume cannot receive metadata copies\", e);\n}","preventionTips":["Never allow PROVIDED volumes as replication targets (volume chooser policy).","Check the target volume type before starting a copyBlock flow.","Roll back partial replicas when the copy path throws."],"tags":["hdfs","datanode","provided-storage","block-replication","metadata"],"backgroundTag":"unsupported-operation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}