{"record":{"id":"0c72028b5e58ee03","repo":"apache/hadoop","slug":"can-t-combine-recover-with-other-startup-options","errorCode":null,"errorMessage":"Can't combine -recover with other startup options.","messagePattern":"Can't combine -recover with other startup options\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java","lineNumber":1765,"sourceCode":"      } else if (StartupOption.BOOTSTRAPSTANDBY.getName().equalsIgnoreCase(cmd)) {\n        startOpt = StartupOption.BOOTSTRAPSTANDBY;\n        return startOpt;\n      } else if (StartupOption.INITIALIZESHAREDEDITS.getName().equalsIgnoreCase(cmd)) {\n        startOpt = StartupOption.INITIALIZESHAREDEDITS;\n        for (i = i + 1 ; i < argsLen; i++) {\n          if (StartupOption.NONINTERACTIVE.getName().equals(args[i])) {\n            startOpt.setInteractiveFormat(false);\n          } else if (StartupOption.FORCE.getName().equals(args[i])) {\n            startOpt.setForceFormat(true);\n          } else {\n            LOG.error(\"Invalid argument: \" + args[i]);\n            return null;\n          }\n        }\n        return startOpt;\n      } else if (StartupOption.RECOVER.getName().equalsIgnoreCase(cmd)) {\n        if (startOpt != StartupOption.REGULAR) {\n          throw new RuntimeException(\"Can't combine -recover with \" +\n              \"other startup options.\");\n        }\n        startOpt = StartupOption.RECOVER;\n        while (++i < argsLen) {\n          if (args[i].equalsIgnoreCase(\n                StartupOption.FORCE.getName())) {\n            startOpt.setForce(MetaRecoveryContext.FORCE_FIRST_CHOICE);\n          } else {\n            throw new RuntimeException(\"Error parsing recovery options: \" + \n              \"can't understand option \\\"\" + args[i] + \"\\\"\");\n          }\n        }\n      } else if (StartupOption.METADATAVERSION.getName().equalsIgnoreCase(cmd)) {\n        startOpt = StartupOption.METADATAVERSION;\n      } else {\n        return null;\n      }\n    }","sourceCodeStart":1747,"sourceCodeEnd":1783,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNode.java#L1747-L1783","documentation":"While parsing NameNode command-line arguments, the '-recover' branch (StartupOption.RECOVER) throws RuntimeException if any other startup option was parsed first (startOpt != REGULAR). Recovery mode - which interactively picks edit-log choices to recover corrupt metadata - is mutually exclusive with every other startup option.","triggerScenarios":"Invoking the NameNode with '-recover' combined with another option, e.g. 'hdfs namenode -format -recover', 'hdfs namenode -upgrade -recover', '-rollback -recover'; the option parser rejects the combination before the NN starts.","commonSituations":"Operators chaining flags out of caution during incident recovery ('it just had an upgrade, so also recover'); copy-pasted command lines; scripts appending flags conditionally until one run includes both.","solutions":["Run '-recover' alone: 'hdfs namenode -recover' (optionally '-recover -force').","Perform the other operation (format/upgrade/rollback/bootstrapStandby) as a separate command invocation.","Check 'hdfs namenode -h' / the official docs for which options each mode accepts."],"exampleFix":"# before\nhdfs namenode -format -recover\n\n# after\nhdfs namenode -recover   # recovery mode accepts no other startup options; run other operations separately","handlingStrategy":"validation","validationCode":"# validate the command line before invoking the NN\nif args contains '-recover' and (len(args) > 2 or any of\n    ['-format','-upgrade','-rollback','-bootstrapStandby','-initializeSharedEdits'] in args):\n    abort(\"-recover must be the only startup option\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run 'hdfs namenode -recover [-force]' as a standalone command - never append other startup options.","Keep operational runbooks one-operation-per-command so flags never accumulate.","Test recovery procedures on a sandbox so the exact syntax is already validated before an incident."],"tags":["hdfs","namenode","cli","arguments","recovery","startup-options"],"backgroundTag":"invalid-cli-arguments","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}