Uploaded image for project: 'HBase'
  1. HBase
  2. HBASE-26469

correct HBase shell exit behavior to match code passed to exit

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • 2.5.0, 3.0.0-alpha-2, 2.4.8
    • 2.5.0, 3.0.0-alpha-3, 2.4.10
    • shell
    • None
    • Incompatible change
    • Hide
      <!-- markdown -->
      User input handling has been refactored to make use of IRB sessions directly and the HBase shell attempts to ensure user provided calls to exit are able to convey failure and success.

      Those scripting use of the HBase shell should be aware that the exit code may have changed:
          * a 0 code, or no code, passed to a call to exit from stdin in non-interactive mode will now exit cleanly. in prior versions this would have exited with an error and non-zero exit code. (note that in HBase 2.4.x this call will still result in a non-zero exit code)
          * for other combinations of passing in an initialization script or reading from stdin with using the non-interactive flag, the exit code being 0 or non-0 should now line up with releases prior to 2.4, which is a change in behavior compared to versions 2.4.0 - 2.4.9.

      Please see the issue details for a table of expected exit codes.
      Show
      <!-- markdown --> User input handling has been refactored to make use of IRB sessions directly and the HBase shell attempts to ensure user provided calls to exit are able to convey failure and success. Those scripting use of the HBase shell should be aware that the exit code may have changed:     * a 0 code, or no code, passed to a call to exit from stdin in non-interactive mode will now exit cleanly. in prior versions this would have exited with an error and non-zero exit code. (note that in HBase 2.4.x this call will still result in a non-zero exit code)     * for other combinations of passing in an initialization script or reading from stdin with using the non-interactive flag, the exit code being 0 or non-0 should now line up with releases prior to 2.4, which is a change in behavior compared to versions 2.4.0 - 2.4.9. Please see the issue details for a table of expected exit codes.

    Description

      The HBase shell has changed behavior in a way that breaks being able to exit properly.

      Two example scripts to act as stand ins for hbase shell scripts to "do something simple then exit":

      tmp % echo "list\nexit" > clean_exit.rb
      tmp % echo "list\nexit 1" > error_exit.rb
      

      Giving these two scripts is possible:

      • passed as a cli argument
      • via redirected stdin

      Additionally the shell invocation can be:

      • in the default compatibility mode
      • with the "non interactive" flag that gives an exit code that reflects runtime errors

      I'll post logs of the details as attachments but here are some tables of the exit codes.

      The clean_exit.rb invocations ought to exit with success, exit code 0.

        1.4.14 1.7.1 2.0.6 2.1.9 2.2.7 2.3.7 2.4.8 master
      cli, default 0 0 0 0 0 0 1 1*
      cli, -n 0 0 0 0 0 0 1 hang
      stdin, default 0 0 0 0 0 0 0 0
      stdin, -n 1 1 1 1 1 1 1* 1*

      The error_exit.rb invocation should return a non-zero exit code, unless we're specifically trying to match a normal hbase shell session.

        1.4.14 1.7.1 2.0.6 2.1.9 2.2.7 2.3.7 2.4.8 master
      cli, default 1 1 1 1 1 1 1* 1*
      cli, -n 1 1 1 1 1 1 1* hang
      stdin, default 0 0 0 0 0 0 0 0
      stdin, -n 1 1 1 1 1 1 1* 1*

      In cases marked with * the error details are different.

      The biggest concern are the new-to-2.4 non-zero exit code when we should have a success and the hanging.

      The former looks like this:

      ERROR NoMethodError: private method `exit' called for nil:NilClass
      

      The change in error details for the error exit script also shows this same detail.

      This behavior appears to be a side effect of HBASE-11686. As far as I can tell, the IRB handling of 'exit' calls fail because we implement our own handling of sessoins rather than rely on the intended session interface. We never set a current session, and IRB's exit implementation presumes there will be one.

      Running in debug shows this in a stacktrace:

      Took 0.4563 seconds
      ERROR NoMethodError: private method `exit' called for nil:NilClass
      NoMethodError: private method `exit' called for nil:NilClass
                           irb_exit at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/irb/extend-command.rb:30
                           evaluate at stdin:2
                               eval at org/jruby/RubyKernel.java:1048
                           evaluate at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/irb/workspace.rb:85
                            eval_io at uri:classloader:/shell.rb:327
           each_top_level_statement at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/irb/ruby-lex.rb:246
                               loop at org/jruby/RubyKernel.java:1442
           each_top_level_statement at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/irb/ruby-lex.rb:232
                              catch at org/jruby/RubyKernel.java:1189
           each_top_level_statement at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/irb/ruby-lex.rb:231
                            eval_io at uri:classloader:/shell.rb:326
        classpath:/jar-bootstrap.rb at classpath:/jar-bootstrap.rb:194
                  exception_handler at uri:classloader:/shell.rb:339
                             <main> at classpath:/jar-bootstrap.rb:194
      

      And in our version of IRB (0.9.6) line 30 for extend-commands corresponds to this code:

          # Quits the current irb context
          #
          # +ret+ is the optional signal or message to send to Context#exit
          #
          # Same as <code>IRB.CurrentContext.exit</code>.
          def irb_exit(ret = 0)
            irb_context.exit(ret)
          end
      

      Attachments

        1. hbase-1.4.14-exit-behavior.log
          7 kB
          Sean Busbey
        2. hbase-1.7.1-exit-behavior.log
          7 kB
          Sean Busbey
        3. hbase-2.0.6-exit-behavior.log
          8 kB
          Sean Busbey
        4. hbase-2.1.9-exit-behavior.log
          8 kB
          Sean Busbey
        5. hbase-2.2.7-exit-behavior.log
          8 kB
          Sean Busbey
        6. hbase-2.3.7-exit-behavior.log
          11 kB
          Sean Busbey
        7. hbase-2.4.8-exit-behavior.log
          11 kB
          Sean Busbey
        8. hbase-3.0.0-alpha-2-exit-behavior.log
          11 kB
          Sean Busbey

        Issue Links

          Activity

            People

              busbey Sean Busbey
              busbey Sean Busbey
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: