{"record":{"id":"698fcb6c2a56156b","repo":"apache/hadoop","slug":"cannot-remove-current-alias-map-aliasmapfile","errorCode":null,"errorMessage":"Cannot remove current alias map: ${aliasMapFile}","messagePattern":"Cannot remove current alias map: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/BootstrapStandby.java","lineNumber":559,"sourceCode":"   * @throws IOException\n   */\n  private int formatAndDownloadAliasMap(String pathAliasMap,\n      RemoteNameNodeInfo proxyInfo) throws IOException {\n    LOG.info(\"Bootstrapping the InMemoryAliasMap from \"\n        + proxyInfo.getHttpAddress());\n    if (pathAliasMap == null) {\n      throw new IOException(\"InMemoryAliasMap enabled with null location\");\n    }\n    File aliasMapFile = new File(pathAliasMap);\n    if (aliasMapFile.exists()) {\n      AliasMapStorageDirectory aliasMapSD =\n          new AliasMapStorageDirectory(aliasMapFile);\n      if (!Storage.confirmFormat(\n          Arrays.asList(aliasMapSD), force, interactive)) {\n        return ERR_CODE_ALREADY_FORMATTED;\n      } else {\n        if (!FileUtil.fullyDelete(aliasMapFile)) {\n          throw new IOException(\n              \"Cannot remove current alias map: \" + aliasMapFile);\n        }\n      }\n    }\n\n    // create the aliasmap location.\n    if (!aliasMapFile.mkdirs()) {\n      throw new IOException(\"Cannot create directory \" + aliasMapFile);\n    }\n    TransferFsImage.downloadAliasMap(proxyInfo.getHttpAddress(), aliasMapFile,\n        true);\n    return 0;\n  }\n\n  @Override\n  public void setConf(Configuration conf) {\n    this.conf = DFSHAAdmin.addSecurityConfiguration(conf);\n  }","sourceCodeStart":541,"sourceCodeEnd":577,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/ha/BootstrapStandby.java#L541-L577","documentation":"During aliasmap bootstrap, after the user confirms formatting, BootstrapStandby calls FileUtil.fullyDelete(aliasMapFile) to clear the existing LevelDB aliasmap directory; if deletion fails it throws IOException with the path. The old aliasmap store could not be removed before re-downloading it.","triggerScenarios":"formatAndDownloadAliasMap() on a standby whose aliasmap dir already exists: fullyDelete fails because files are read-only, owned by another user, still held open by a running process (LevelDB lock file), or the filesystem is read-only.","commonSituations":"Re-running -bootstrapStandby while the standby NameNode/aliasmap process is still up holding the LEVELDB LOCK; aliasmap files owned by root from a previous manual operation; read-only or failing disk.","solutions":["Stop the NameNode/any process using the aliasmap directory (LevelDB holds a LOCK file) before bootstrapping","chown -R <hdfs-user> <aliasmap.dir> and remove read-only bits, or delete the directory manually as the right user","Verify the volume is writable and healthy, then re-run 'hdfs namenode -bootstrapStandby -force'"],"exampleFix":"# before: leftover aliasmap owned by root, delete fails\n$ sudo -u hdfs hdfs namenode -bootstrapStandby -force\nIOException: Cannot remove current alias map: /data/dfs/aliasmap/inmemory\n# after\n$ sudo chown -R hdfs:hadoop /data/dfs/aliasmap/inmemory\n$ sudo -u hdfs hdfs namenode -bootstrapStandby -force","handlingStrategy":"validation","validationCode":"File alias = new File(conf.get(\"dfs.provided.aliasmap.inmemory.leveldb.dir\"));\nif (alias.exists()) {\n  if (!Files.isWritable(alias.toPath())) {\n    throw new IOException(\"Aliasmap dir not deletable: fix ownership of \" + alias);\n  }\n  if (new File(alias, \"LOCK\").exists()) {\n    throw new IOException(\"A process still holds \" + alias + \"/LOCK — stop it first\");\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  runner.run(argv);\n} catch (IOException e) { // \"Cannot remove current alias map: <path>\"\n  // fix ownership / stop the holder of the LevelDB dir, then re-run with -force\n}","preventionTips":["Stop the NameNode and any aliasmap-serving process before re-bootstrapping a node","Provision aliasmap directories owned by the hdfs user so -force re-runs never hit read-only files"],"tags":["hdfs","namenode","bootstrap-standby","aliasmap","leveldb","file-delete-failed","permissions"],"backgroundTag":"file-delete-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}