{"record":{"id":"4cfdaa626402a5dc","repo":"apache/hadoop","slug":"unable-to-create-aliasmap-snapshot-directory-newl","errorCode":null,"errorMessage":"Unable to create aliasmap snapshot directory {newLevelDBDir}","messagePattern":"Unable to create aliasmap snapshot directory (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/aliasmap/InMemoryAliasMap.java","lineNumber":290,"sourceCode":"    }\n  }\n\n  /**\n   * Create a new LevelDB store which is a snapshot copy of the original\n   * aliasmap.\n   *\n   * @param aliasMap original aliasmap.\n   * @return the {@link File} where the snapshot is created.\n   * @throws IOException\n   */\n  static File createSnapshot(InMemoryAliasMap aliasMap) throws IOException {\n    File originalAliasMapDir = new File(aliasMap.aliasMapURI);\n    String bpid = originalAliasMapDir.getName();\n    File snapshotDir =\n        new File(originalAliasMapDir.getParent(), SNAPSHOT_COPY_DIR);\n    File newLevelDBDir = new File(snapshotDir, bpid);\n    if (!newLevelDBDir.mkdirs()) {\n      throw new IOException(\n          \"Unable to create aliasmap snapshot directory \" + newLevelDBDir);\n    }\n    // get a snapshot for the original DB.\n    DB originalDB = aliasMap.levelDb;\n    try (Snapshot snapshot = originalDB.getSnapshot()) {\n      // create a new DB for the snapshot and copy all K,V pairs.\n      Options options = new Options();\n      options.createIfMissing(true);\n      try (DB snapshotDB = JniDBFactory.factory.open(newLevelDBDir, options)) {\n        try (DBIterator iterator =\n            originalDB.iterator(new ReadOptions().snapshot(snapshot))) {\n          iterator.seekToFirst();\n          while (iterator.hasNext()) {\n            Map.Entry<byte[], byte[]> entry = iterator.next();\n            snapshotDB.put(entry.getKey(), entry.getValue());\n          }\n        }\n      }","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/aliasmap/InMemoryAliasMap.java#L272-L308","documentation":"InMemoryAliasMap.createSnapshot throws IOException when mkdirs() on the target snapshot LevelDB directory fails. The snapshot path is <aliasmap-parent>/aliasmap_snapshot/<bpid>; if that dir cannot be created — usually because it already exists from a previous failed snapshot run, or because of missing permissions — the copy of the LevelDB store cannot proceed.","triggerScenarios":"createSnapshot(aliasMap) computes newLevelDBDir = <parent>/aliasmap_snapshot/<bpid> and newLevelDBDir.mkdirs() returns false. Dominant cause: the directory already exists (leftover from an earlier aborted snapshot/compress run); otherwise standard mkdirs failures (permissions, file in the way).","commonSituations":"Re-running a bootstrap-transfer after a previous attempt crashed midway, leaving aliasmap_snapshot/<bpid> behind; permission drift on the aliasmap parent; concurrent snapshot attempts by two processes.","solutions":["Remove the stale snapshot tree first: rm -rf <parent>/aliasmap_snapshot/<bpid> (or the whole aliasmap_snapshot dir) and retry the snapshot/bootstrap.","Ensure only one process performs aliasmap snapshotting at a time (serialize NN-side bootstrap operations).","Check write permissions on <parent> for the service user.","If it recurs, look for the earlier failure in logs that abandoned the snapshot and fix that root cause first."],"exampleFix":"# before\n# IOException: Unable to create aliasmap snapshot directory /data/aliasmap_snapshot/BP-1234\nls /data/aliasmap_snapshot/BP-1234   # leftover from previous aborted run\n\n# after\nrm -rf /data/aliasmap_snapshot\n# rerun the aliasmap snapshot / bootstrap-transfer","handlingStrategy":"validation","validationCode":"File snapDir = new File(originalDir.getParent(), \"aliasmap_snapshot\");\nFile target = new File(snapDir, bpid);\nif (target.exists()) {\n  FileUtil.fullyDelete(target); // clear stale snapshot from a prior aborted run\n}\nFile snap = InMemoryAliasMap.createSnapshot(aliasMap);","typeGuard":null,"tryCatchPattern":"try {\n  snapshot = InMemoryAliasMap.createSnapshot(aliasMap);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Unable to create aliasmap snapshot\")) {\n    FileUtil.fullyDelete(new File(parent, \"aliasmap_snapshot\"));\n    snapshot = InMemoryAliasMap.createSnapshot(aliasMap); // one retry after cleanup\n  } else { throw e; }\n}","preventionTips":["Delete aliasmap_snapshot leftovers before re-running a bootstrap after any failure.","Serialize snapshot/bootstrap operations so two runs never race on the same dir.","Verify write permissions on the aliasmap parent before starting the flow."],"tags":["hdfs","provided-storage","aliasmap","snapshot","leveldb"],"backgroundTag":"directory-create-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}