Skip to content

HBASE-28660 list_namespace not working after an incorrect user input#7931

Open
arvindKandpal-ksolves wants to merge 2 commits intoapache:masterfrom
arvindKandpal-ksolves:HBASE-28660
Open

HBASE-28660 list_namespace not working after an incorrect user input#7931
arvindKandpal-ksolves wants to merge 2 commits intoapache:masterfrom
arvindKandpal-ksolves:HBASE-28660

Conversation

@arvindKandpal-ksolves
Copy link

Why are the changes needed?

As reported in HBASE-28660, when a user enters an incorrect command like list_namespace, 'ns.*', the JRuby parser mistakenly creates a local variable named list_namespace initialized to nil before throwing a SyntaxError. Because Ruby prioritizes local variables over method calls, subsequent valid list_namespace commands return empty/nil instead of executing the actual shell command.

How does this PR fix the problem?

  • Added a cleanup mechanism inside hirb.rb's eval_input loop.
  • After evaluating a line, it checks if any newly created local variables match the names of registered HBase shell commands.
  • If a collision (shadowing) is detected, it outputs a warning message to the user (WARN: '<command>' is a reserved HBase command. Local variable assignment ignored.).
  • It then safely discards the polluted binding, creates a fresh workspace binding, and restores only the non-conflicting user variables.
  • Added comprehensive test cases in general_test_cluster.rb to cover direct assignments, syntax errors, and safe variable preservations.

Tests run

Ran the shell tests locally and verified that the behavior works as expected without regressions.
mvn test -Dtest=TestShell -pl hbase-shell (All tests passed).

Fixes an issue where mistakenly parsed local variables shadow HBase shell commands. Added cleanup logic in IRB eval loop to replace polluted bindings, along with a warning message for the user. Added relevant test cases in general_test_cluster.rb.
Copy link
Contributor

@vaijosh vaijosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I have tested this features and verified that it works fine.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses HBASE-28660 by preventing HBase shell commands (e.g., list, list_namespace) from being shadowed by local variables created during IRB evaluation, and adds a regression test to ensure reserved command names cannot persist as locals.

Changes:

  • Add an ensure block in IRB::HIRB#eval_input to detect and remove local variables that conflict with HBase command names, rehydrating a clean workspace binding.
  • Emit warnings when reserved command names are detected as locals.
  • Add a shell test that simulates IRB input and asserts reserved command locals are not preserved while normal locals are preserved.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
hbase-shell/src/test/ruby/shell/general_test_cluster.rb Adds a regression test using a mock IRB input method to validate reserved-command shadowing prevention.
hbase-shell/src/main/ruby/irb/hirb.rb Implements the reserved-command local-variable detection/removal logic inside HIRB#eval_input.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@arvindKandpal-ksolves
Copy link
Author

Hi @liuxiaocs7 , I have applied copilot suggestions , Please take a look.

@arvindKandpal-ksolves
Copy link
Author

Just a gentle follow-up on this PR. I have addressed all the review comments and verified that the local tests are passing. Please let me know if anything else is needed or if this is good to go.

cc @liuxiaocs7 @vaijosh @Apache9

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants