From 67356efe87000f439dd001e30a89e644e2037723 Mon Sep 17 00:00:00 2001 From: Amit Balode Date: Mon, 9 Mar 2026 04:05:37 +0530 Subject: [PATCH 1/3] HDFS-17809. hdfs diskbalancer -help shows only generic help. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With Apache Commons CLI's optionalArg(true), a space-separated argument after the option name (e.g. -help plan) is NOT captured as the option's value — only the equals-sign form (--help=plan) works. As a result, cmd.getOptionValue("help") always returned null and HelpCommand printed the generic usage summary instead of the per-command details. Fix: after getOptionValue("help") returns null, fall back to cmd.getArgs()[0] (the first positional leftover) as the sub-command name. This makes "-help plan", "-help execute", "-help query", "-help cancel", and "-help report" all display the correct command-specific help text. Test: TestDiskBalancerCommand#testHelpCommandWithSubCommand iterates all five sub-commands and asserts the output contains the sub-command keyword. Co-Authored-By: Claude Sonnet 4.6 --- .../diskbalancer/command/HelpCommand.java | 9 +++++++ .../command/TestDiskBalancerCommand.java | 27 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/command/HelpCommand.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/command/HelpCommand.java index ec180538a9843..a3b6df61bd784 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/command/HelpCommand.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/diskbalancer/command/HelpCommand.java @@ -56,6 +56,15 @@ public void execute(CommandLine cmd) throws Exception { Preconditions.checkState(cmd.hasOption(DiskBalancerCLI.HELP)); verifyCommandOptions(DiskBalancerCLI.HELP, cmd); String helpCommand = cmd.getOptionValue(DiskBalancerCLI.HELP); + if (helpCommand == null || helpCommand.isEmpty()) { + // With optionalArg(true), space-separated form "-help " leaves the + // sub-command as a positional arg rather than the option's value. + // Fall back to the first leftover arg so "-help plan" works as expected. + String[] leftoverArgs = cmd.getArgs(); + if (leftoverArgs != null && leftoverArgs.length > 0) { + helpCommand = leftoverArgs[0]; + } + } if (helpCommand == null || helpCommand.isEmpty()) { this.printHelp(); return; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/command/TestDiskBalancerCommand.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/command/TestDiskBalancerCommand.java index 7f9c05a6a721e..e88aac28ab72e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/command/TestDiskBalancerCommand.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/command/TestDiskBalancerCommand.java @@ -756,6 +756,33 @@ public void testHelpCommand() throws Exception { runCommand(cmdLine); } + /** + * HDFS-17809: "-help " must display command-specific help text, + * not just the generic usage summary. + */ + @Test + @Timeout(value = 60) + public void testHelpCommandWithSubCommand() throws Exception { + // Each sub-command help should contain its own option/keyword. + String[][] subCommands = { + {PLAN, "plan"}, + {EXECUTE, "execute"}, + {QUERY, "query"}, + {CANCEL, "cancel"}, + {REPORT, "report"}, + }; + for (String[] pair : subCommands) { + String subCmd = pair[0]; + String expectedToken = pair[1]; + String cmdLine = String.format("hdfs diskbalancer -%s %s", HELP, subCmd); + List output = runCommand(cmdLine); + String joined = String.join("\n", output).toLowerCase(); + assertTrue(joined.contains(expectedToken), + "Expected '" + expectedToken + "' in help output for '-help " + + subCmd + "', got:\n" + joined); + } + } + @Test public void testPrintFullPathOfPlan() throws Exception { From 62d7e93fd4899e0bd381c904690f39a713099352 Mon Sep 17 00:00:00 2001 From: Amit Balode Date: Thu, 19 Mar 2026 17:05:15 +0530 Subject: [PATCH 2/3] retrigger CI From 0e06726445e92b97b1fb6ed2f3cacaf72151e8c2 Mon Sep 17 00:00:00 2001 From: Amit Balode Date: Fri, 20 Mar 2026 17:13:48 +0530 Subject: [PATCH 3/3] retrigger CI