Skip to content

HDFS-17809. hdfs diskbalancer -help <command> shows only generic help.#8324

Open
balodesecurity wants to merge 1 commit intoapache:trunkfrom
balodesecurity:HDFS-17809
Open

HDFS-17809. hdfs diskbalancer -help <command> shows only generic help.#8324
balodesecurity wants to merge 1 commit intoapache:trunkfrom
balodesecurity:HDFS-17809

Conversation

@balodesecurity
Copy link

Summary

hdfs diskbalancer -help plan (and -help execute, -help query, -help cancel, -help report) always printed the generic usage summary instead of the per-command help text. This is a regression compared to Hadoop 3.1.1.

Root Cause

The --help option is declared with .optionalArg(true) in Apache Commons CLI. With that flag, the option value is only captured when the equals-sign form is used (--help=plan). A space-separated form (-help plan) leaves plan as a positional leftover argument, so cmd.getOptionValue("help") returns null and HelpCommand falls through to printing generic help.

Fix

In HelpCommand.execute(), after getOptionValue("help") returns null, fall back to the first element of cmd.getArgs() as the sub-command name. This makes the natural hdfs diskbalancer -help <cmd> syntax work without requiring the awkward --help=<cmd> form.

Changes

  • HelpCommand.java: add fallback to cmd.getArgs()[0] when the option value is null.
  • TestDiskBalancerCommand.java: add testHelpCommandWithSubCommand which runs -help <cmd> for all five sub-commands and asserts the output contains the expected keyword.

Test plan

  • TestDiskBalancerCommand#testHelpCommandWithSubCommand passes locally ✅
  • Full module build passes (mvn package ... -DskipTests) ✅
  • Existing testHelpCommand (no sub-command) still passes ✅

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 <noreply@anthropic.com>
@hadoop-yetus
Copy link

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 50s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 1s codespell was not available.
+0 🆗 detsecrets 0m 1s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 1 new or modified test files.
_ trunk Compile Tests _
+1 💚 mvninstall 46m 43s trunk passed
+1 💚 compile 1m 43s trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 compile 1m 47s trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 checkstyle 1m 49s trunk passed
+1 💚 mvnsite 1m 55s trunk passed
+1 💚 javadoc 1m 29s trunk passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javadoc 1m 29s trunk passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 spotbugs 4m 20s trunk passed
+1 💚 shadedclient 36m 30s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 1m 24s the patch passed
+1 💚 compile 1m 15s the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javac 1m 15s the patch passed
+1 💚 compile 1m 20s the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 javac 1m 20s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 1m 18s the patch passed
+1 💚 mvnsite 1m 29s the patch passed
+1 💚 javadoc 0m 58s the patch passed with JDK Ubuntu-21.0.10+7-Ubuntu-124.04
+1 💚 javadoc 1m 3s the patch passed with JDK Ubuntu-17.0.18+8-Ubuntu-124.04.1
+1 💚 spotbugs 4m 3s the patch passed
+1 💚 shadedclient 36m 21s patch has no errors when building and testing our client artifacts.
_ Other Tests _
-1 ❌ unit 260m 18s /patch-unit-hadoop-hdfs-project_hadoop-hdfs.txt hadoop-hdfs in the patch passed.
+1 💚 asflicense 0m 47s The patch does not generate ASF License warnings.
406m 38s
Reason Tests
Failed junit tests hadoop.hdfs.server.diskbalancer.command.TestDiskBalancerCommand
hadoop.hdfs.server.datanode.fsdataset.impl.TestFsVolumeList
Subsystem Report/Notes
Docker ClientAPI=1.54 ServerAPI=1.54 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8324/1/artifact/out/Dockerfile
GITHUB PR #8324
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux 6323541b39e4 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 67356ef
Default Java Ubuntu-17.0.18+8-Ubuntu-124.04.1
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.10+7-Ubuntu-124.04 /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.18+8-Ubuntu-124.04.1
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8324/1/testReport/
Max. process+thread count 2443 (vs. ulimit of 5500)
modules C: hadoop-hdfs-project/hadoop-hdfs U: hadoop-hdfs-project/hadoop-hdfs
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8324/1/console
versions git=2.43.0 maven=3.9.11 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants