{"record":{"id":"e7e8ce7a3844e404","repo":"apache/hadoop","slug":"namenode-format-aborted-as-reformat-is-disabled-fo","errorCode":null,"errorMessage":"NameNode format aborted as reformat is disabled for this cluster.","messagePattern":"NameNode format aborted as reformat is disabled for this cluster\\.","errorType":"exception","errorClass":"NameNodeFormatException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java","lineNumber":1413,"sourceCode":"      //Generate a new cluster id\n      clusterId = NNStorage.newClusterID();\n    }\n\n    LOG.info(\"Formatting using clusterid: {}\", clusterId);\n    FSNamesystem fsn = null;\n    try (FSImage fsImage = new FSImage(conf, nameDirsToFormat, editDirsToFormat)) {\n      fsn = new FSNamesystem(conf, fsImage);\n      fsImage.getEditLog().initJournalsForWrite();\n\n      // Abort NameNode format if reformat is disabled and if\n      // meta-dir already exists\n      if (conf.getBoolean(DFSConfigKeys.DFS_REFORMAT_DISABLED,\n          DFSConfigKeys.DFS_REFORMAT_DISABLED_DEFAULT)) {\n        force = false;\n        isInteractive = false;\n        for (StorageDirectory sd : fsImage.storage.dirIterable(null)) {\n          if (sd.hasSomeData()) {\n            throw new NameNodeFormatException(\n                \"NameNode format aborted as reformat is disabled for \"\n                    + \"this cluster.\");\n          }\n        }\n      }\n\n      if (!fsImage.confirmFormat(force, isInteractive)) {\n        return true; // aborted\n      }\n\n      fsImage.format(fsn, clusterId, force);\n    } catch (IOException ioe) {\n      LOG.warn(\"Encountered exception during format\", ioe);\n      throw ioe;\n    } finally {\n      if (fsn != null) {\n        fsn.close();\n      }","sourceCodeStart":1395,"sourceCodeEnd":1431,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java#L1395-L1431","documentation":"During 'hdfs namenode -format', if dfs.reformat.disabled=true and any storage directory already has data (sd.hasSomeData()), NameNode.format throws NameNodeFormatException. It is a deliberate safety guard: -force and interactive prompts are neutralized (force=false, isInteractive=false) so an existing cluster's metadata can never be wiped while the guard is on.","triggerScenarios":"Running 'hdfs namenode -format' (with or without -force) on a node where dfs.reformat.disabled=true in hdfs-site.xml and any name dir contains existing fs image/edits/in_use.lock data.","commonSituations":"Production hardening sets dfs.reformat.disabled=true; months later an operator or an automation playbook re-runs the format step and hits the guard; re-provisioning scripts that format on every run.","solutions":["If reformat is genuinely intended, temporarily set dfs.reformat.disabled=false in hdfs-site.xml, run the format, then restore it to true.","Otherwise decommission properly: verify the metadata is disposable, then move/clear the contents of dfs.namenode.name.dir before formatting (or format into fresh, empty directories).","For HA clusters, format on one node and bootstrap the rest with 'hdfs namenode -bootstrapStandby' instead of formatting everywhere."],"exampleFix":"<!-- before: hdfs-site.xml -->\n<property><name>dfs.reformat.disabled</name><value>true</value></property>\nhdfs namenode -format   # aborts: NameNode format aborted as reformat is disabled\n\n<!-- after -->\n<property><name>dfs.reformat.disabled</name><value>false</value></property>\nhdfs namenode -format   # succeeds; then set the guard back to true","handlingStrategy":"validation","validationCode":"// guard a scripted format against the reformat lock\nboolean reformatDisabled = conf.getBoolean(\"dfs.reformat.disabled\", false);\nboolean hasData = Arrays.stream(nameDir.listFiles())\n    .anyMatch(f -> f.getName().matches(\"current|in_use.lock|previous|seen_txid\"));\nif (reformatDisabled && hasData)\n  throw new IllegalStateException(\"refusing to format: dfs.reformat.disabled=true and data exists\");","typeGuard":"boolean isReformatGuard(Throwable t) {\n  return t instanceof NameNodeFormatException\n      && String.valueOf(t.getMessage()).contains(\"reformat is disabled\");\n}","tryCatchPattern":null,"preventionTips":["Make format steps in automation explicit: fail if dfs.reformat.disabled=true instead of overriding silently.","Keep dfs.reformat.disabled=true on all production NNs; treat any need to flip it as a change-review event.","Bootstrap HA peers with -bootstrapStandby instead of reformatting every node."],"tags":["hdfs","namenode","format","configuration","safety-guard"],"backgroundTag":"operation-blocked-by-config","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}