{"record":{"id":"e611d3d75d1d246b","repo":"apache/hadoop","slug":"storage-directory-is-in-use","errorCode":null,"errorMessage":"Storage directory is in use.","messagePattern":"Storage directory is in use\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"warning","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataStorage.java","lineNumber":330,"sourceCode":"   * to the volume. If the volume cannot be added, it is OK to discard the\n   * builder later.\n   *\n   * @param datanode DataNode object.\n   * @param location the StorageLocation for the storage directory.\n   * @param nsInfos an array of namespace infos.\n   * @return a VolumeBuilder that holds the metadata of this storage directory\n   * and can be added to DataStorage later.\n   * @throws IOException if encounters I/O errors.\n   *\n   * Note that if there is IOException, the state of DataStorage is not modified.\n   */\n  public VolumeBuilder prepareVolume(DataNode datanode,\n      StorageLocation location, List<NamespaceInfo> nsInfos)\n          throws IOException {\n    if (containsStorageDir(location)) {\n      final String errorMessage = \"Storage directory is in use.\";\n      LOG.warn(errorMessage);\n      throw new IOException(errorMessage);\n    }\n\n    StorageDirectory sd = loadStorageDirectory(\n        datanode, nsInfos.get(0), location, StartupOption.HOTSWAP, null);\n    VolumeBuilder builder =\n        new VolumeBuilder(this, sd);\n    for (NamespaceInfo nsInfo : nsInfos) {\n      location.makeBlockPoolDir(nsInfo.getBlockPoolID(), datanode.getConf());\n\n      final BlockPoolSliceStorage bpStorage = getBlockPoolSliceStorage(nsInfo);\n      final List<StorageDirectory> dirs = bpStorage.loadBpStorageDirectories(\n          nsInfo, location, StartupOption.HOTSWAP, null, datanode.getConf());\n      builder.addBpStorageDirectories(nsInfo.getBlockPoolID(), dirs);\n    }\n    return builder;\n  }\n\n  static int getParallelVolumeLoadThreadsNum(int dataDirs, Configuration conf) {","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataStorage.java#L312-L348","documentation":"DataStorage.prepareVolume is the runtime hot-swap path for adding volumes. containsStorageDir(location) returns true when the location is already registered in this DataStorage, so re-adding it would corrupt volume bookkeeping; the call fails fast with 'Storage directory is in use.' before touching the disk.","triggerScenarios":"Reconfiguring dfs.datanode.data.dir at runtime (dfsadmin -reconfig datanode ...) with a location that is already part of the running volume set - duplicated entry, replayed add request, or a symlink resolving to an existing volume's path.","commonSituations":"Reconfig payloads that append to the old list instead of replacing it; retrying a volume-add that already succeeded; /mnt vs /media style symlink aliases pointing at the same device.","solutions":["Diff the new dfs.datanode.data.dir against the DN's currently effective config and add only genuinely new paths","If the volume is already active, no action is needed - the error just confirms it is in use","Resolve canonical paths before comparing so the same device is not added twice"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before dfsadmin -reconfig, diff current vs new data.dir\nSet<String> current = getCurrentDataDirsFromDnJmx();   // Hadoop:service=DataNode,name=DataNodeInfo\nSet<String> requested = parse(newPropertyValue);\nfor (String added : Sets.difference(requested, current)) {\n  if (current.contains(Paths.get(added).toRealPath().toString())) {\n    throw new IllegalStateException(\"Volume already in use: \" + added);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build reconfig payloads by explicit replace/diff, never blind append","Canonicalize paths (resolve symlinks) when comparing volume lists","Treat this error as benign when the volume is already active - skip re-adding it"],"tags":["hadoop","hdfs","datanode","storage","hot-swap","reconfig"],"backgroundTag":"resource-already-in-use","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}