HBASE-21567 Allow overriding configs starting up the shell
Adds support for -D as option to 'hbase shell'
This commit is contained in:
parent
0094335c52
commit
a226ceae3a
40
bin/hirb.rb
40
bin/hirb.rb
@ -54,21 +54,47 @@ $LOAD_PATH.unshift Pathname.new(sources)
|
|||||||
cmdline_help = <<HERE # HERE document output as shell usage
|
cmdline_help = <<HERE # HERE document output as shell usage
|
||||||
Usage: shell [OPTIONS] [SCRIPTFILE [ARGUMENTS]]
|
Usage: shell [OPTIONS] [SCRIPTFILE [ARGUMENTS]]
|
||||||
|
|
||||||
-d | --debug Set DEBUG log levels.
|
-d | --debug Set DEBUG log levels.
|
||||||
-h | --help This help.
|
-h | --help This help.
|
||||||
-n | --noninteractive Do not run within an IRB session
|
-n | --noninteractive Do not run within an IRB session and exit with non-zero
|
||||||
and exit with non-zero status on
|
status on first error.
|
||||||
first error.
|
-Dkey=value Pass hbase-*.xml Configuration overrides. For example, to
|
||||||
|
use an alternate zookeeper ensemble, pass:
|
||||||
|
-Dhbase.zookeeper.quorum=zookeeper.example.org
|
||||||
|
For faster fail, pass the below and vary the values:
|
||||||
|
-Dhbase.client.retries.number=7
|
||||||
|
-Dhbase.ipc.client.connect.max.retries=3
|
||||||
HERE
|
HERE
|
||||||
|
|
||||||
|
# Takes configuration and an arg that is expected to be key=value format.
|
||||||
|
# If c is empty, creates one and returns it
|
||||||
|
def add_to_configuration(c, arg)
|
||||||
|
kv = arg.split('=')
|
||||||
|
kv.length == 2 || (raise "Expected parameter #{kv} in key=value format")
|
||||||
|
c = org.apache.hadoop.hbase.HBaseConfiguration.create if c.nil?
|
||||||
|
c.set(kv[0], kv[1])
|
||||||
|
c
|
||||||
|
end
|
||||||
|
|
||||||
found = []
|
found = []
|
||||||
script2run = nil
|
script2run = nil
|
||||||
log_level = org.apache.log4j.Level::ERROR
|
log_level = org.apache.log4j.Level::ERROR
|
||||||
@shell_debug = false
|
@shell_debug = false
|
||||||
interactive = true
|
interactive = true
|
||||||
for arg in ARGV
|
_configuration = nil
|
||||||
|
D_ARG = '-D'
|
||||||
|
while (arg = ARGV.shift)
|
||||||
if arg == '-h' || arg == '--help'
|
if arg == '-h' || arg == '--help'
|
||||||
puts cmdline_help
|
puts cmdline_help
|
||||||
exit
|
exit
|
||||||
|
elsif arg == D_ARG
|
||||||
|
argValue = ARGV.shift || (raise "#{D_ARG} takes a 'key=value' parameter")
|
||||||
|
_configuration = add_to_configuration(_configuration, argValue)
|
||||||
|
found.push(arg)
|
||||||
|
found.push(argValue)
|
||||||
|
elsif arg.start_with? D_ARG
|
||||||
|
_configuration = add_to_configuration(_configuration, arg[2..-1])
|
||||||
|
found.push(arg)
|
||||||
elsif arg == '-d' || arg == '--debug'
|
elsif arg == '-d' || arg == '--debug'
|
||||||
log_level = org.apache.log4j.Level::DEBUG
|
log_level = org.apache.log4j.Level::DEBUG
|
||||||
$fullBackTrace = true
|
$fullBackTrace = true
|
||||||
@ -111,7 +137,7 @@ require 'shell'
|
|||||||
require 'shell/formatter'
|
require 'shell/formatter'
|
||||||
|
|
||||||
# Setup the HBase module. Create a configuration.
|
# Setup the HBase module. Create a configuration.
|
||||||
@hbase = Hbase::Hbase.new
|
@hbase = _configuration.nil? ? Hbase::Hbase.new : Hbase::Hbase.new(_configuration)
|
||||||
|
|
||||||
# Setup console
|
# Setup console
|
||||||
@shell = Shell::Shell.new(@hbase, interactive)
|
@shell = Shell::Shell.new(@hbase, interactive)
|
||||||
|
@ -58,6 +58,7 @@ To run one of these files, do as follows:
|
|||||||
$ ./bin/hbase org.jruby.Main PATH_TO_SCRIPT
|
$ ./bin/hbase org.jruby.Main PATH_TO_SCRIPT
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
||||||
== Running the Shell in Non-Interactive Mode
|
== Running the Shell in Non-Interactive Mode
|
||||||
|
|
||||||
A new non-interactive mode has been added to the HBase Shell (link:https://issues.apache.org/jira/browse/HBASE-11658[HBASE-11658)].
|
A new non-interactive mode has been added to the HBase Shell (link:https://issues.apache.org/jira/browse/HBASE-11658[HBASE-11658)].
|
||||||
@ -213,6 +214,21 @@ $ HBASE_SHELL_OPTS="-verbose:gc -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCD
|
|||||||
-XX:+PrintGCDetails -Xloggc:$HBASE_HOME/logs/gc-hbase.log" ./bin/hbase shell
|
-XX:+PrintGCDetails -Xloggc:$HBASE_HOME/logs/gc-hbase.log" ./bin/hbase shell
|
||||||
----
|
----
|
||||||
|
|
||||||
|
== Overriding configuration starting the HBase Shell
|
||||||
|
|
||||||
|
As of hbase-2.0.5/hbase-2.1.3/hbase-2.2.0/hbase-1.4.10/hbase-1.5.0, you can
|
||||||
|
pass or override hbase configuration as specified in `hbase-*.xml` by passing
|
||||||
|
your key/values prefixed with `-D` on the command-line as follows:
|
||||||
|
[source,bash]
|
||||||
|
----
|
||||||
|
$ ./bin/hbase shell -Dhbase.zookeeper.quorum=ZK0.remote.cluster.example.org,ZK1.remote.cluster.example.org,ZK2.remote.cluster.example.org -Draining=false
|
||||||
|
...
|
||||||
|
hbase(main):001:0> @shell.hbase.configuration.get("hbase.zookeeper.quorum")
|
||||||
|
=> "ZK0.remote.cluster.example.org,ZK1.remote.cluster.example.org,ZK2.remote.cluster.example.org"
|
||||||
|
hbase(main):002:0> @shell.hbase.configuration.get("raining")
|
||||||
|
=> "false"
|
||||||
|
----
|
||||||
|
|
||||||
== Shell Tricks
|
== Shell Tricks
|
||||||
|
|
||||||
=== Table variables
|
=== Table variables
|
||||||
|
Loading…
x
Reference in New Issue
Block a user