{"record":{"id":"9badf51b11f092a0","repo":"apache/hadoop","slug":"failed-to-copy-srcfile-to-destfile-due-to-fail","errorCode":null,"errorMessage":"Failed to copy {srcFile} to {destFile} due to failure in NativeIO#copyFileUnbuffered(). {e}","messagePattern":"Failed to copy (.+?) to (.+?) due to failure in NativeIO#copyFileUnbuffered\\(\\)\\. (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java","lineNumber":1363,"sourceCode":"        throw new IOException(\"Destination '\" + parentFile\n            + \"' directory cannot be created\");\n      }\n    }\n    if (destFile.exists()) {\n      if (FileUtil.canWrite(destFile) == false) {\n        throw new IOException(\"Destination '\" + destFile\n            + \"' exists but is read-only\");\n      } else {\n        if (destFile.delete() == false) {\n          throw new IOException(\"Destination '\" + destFile\n              + \"' exists but cannot be deleted\");\n        }\n      }\n    }\n    try {\n      NativeIO.copyFileUnbuffered(srcFile, destFile);\n    } catch (NativeIOException e) {\n      throw new IOException(\"Failed to copy \" + srcFile.getCanonicalPath()\n          + \" to \" + destFile.getCanonicalPath()\n          + \" due to failure in NativeIO#copyFileUnbuffered(). \"\n          + e.toString());\n    }\n    if (srcFile.length() != destFile.length()) {\n      throw new IOException(\"Failed to copy full contents from '\" + srcFile\n          + \"' to '\" + destFile + \"'\");\n    }\n    if (preserveFileDate) {\n      if (destFile.setLastModified(srcFile.lastModified()) == false) {\n        LOG.debug(\"Failed to preserve last modified date from'{}' to '{}'\",\n            srcFile, destFile);\n      }\n    }\n  }\n\n  /**\n   * Recursively delete all the content of the directory first and then ","sourceCodeStart":1345,"sourceCodeEnd":1381,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/Storage.java#L1345-L1381","documentation":"Storage.nativeCopyFileUnbuffered calls NativeIO.copyFileUnbuffered (sendfile/copy_file_range on Linux, CopyFile on Windows); a NativeIOException from that syscall is rewrapped here with both canonical paths and the original error text. The errno embedded in the message is the real diagnosis: ENOSPC (disk full), EIO (device error), EACCES, or ENOENT if the source vanished mid-copy.","triggerScenarios":"Destination disk full (errno 28/ENOSPC); failing disk or controller (EIO); source removed by a concurrent process during the copy; permission revoked between the pre-checks and the syscall.","commonSituations":"Checkpoint image copies filling a small name-dir volume; dying disks during fsimage transfer; concurrent cleanup scripts deleting in-flight files.","solutions":["Read the errno in the message: ENOSPC -> free space or enlarge the volume; EIO -> check dmesg/RAID health","Retry the copy after resolving the transient cause (space freed, source stabilized)","Ensure no concurrent process deletes or chmods the source during checkpointing"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"long free = dst.getParentFile().getUsableSpace();\nif (free > 0 && free < srcFile.length()) {\n  throw new IOException(\"insufficient space for copy: need \" + srcFile.length() + \", have \" + free);\n}","typeGuard":null,"tryCatchPattern":"for (int i = 0; i < 3; i++) {\n  try {\n    Storage.nativeCopyFileUnbuffered(src, dst, true);\n    break;\n  } catch (IOException e) {\n    if (!isTransient(e.getMessage())) throw e; // ENOSPC/EACCES are not transient\n    sleepBackoff(i);\n  }\n}","preventionTips":["Monitor free space on name/checkpoint volumes; ENOSPC (errno 28) is the most common cause","Retry only genuinely transient errors (EIO on flaky hardware, brief races), never permission errors","Keep antivirus and backup tools from holding storage files during checkpoints"],"tags":["hdfs","file-copy","native-io","disk-full","io-error"],"backgroundTag":"file-copy-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}