You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2018/12/10 18:11:16 UTC
hbase git commit: HBASE-21567 Allow overriding configs starting up
the shell
Repository: hbase
Updated Branches:
refs/heads/master 79d90c87b -> da9508d42
HBASE-21567 Allow overriding configs starting up the shell
Adds support for -D as option to 'hbase shell'
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/da9508d4
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/da9508d4
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/da9508d4
Branch: refs/heads/master
Commit: da9508d4271ea12410e289692f10791b0e05266b
Parents: 79d90c8
Author: stack <st...@apache.org>
Authored: Thu Dec 6 23:05:21 2018 -0800
Committer: stack <st...@apache.org>
Committed: Sat Dec 8 15:08:19 2018 -0800
----------------------------------------------------------------------
bin/hirb.rb | 40 ++++++++++++++++++++++++-----
src/main/asciidoc/_chapters/shell.adoc | 16 ++++++++++++
2 files changed, 49 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/da9508d4/bin/hirb.rb
----------------------------------------------------------------------
diff --git a/bin/hirb.rb b/bin/hirb.rb
index 790ecdc..e857db7 100644
--- a/bin/hirb.rb
+++ b/bin/hirb.rb
@@ -54,21 +54,47 @@ $LOAD_PATH.unshift Pathname.new(sources)
cmdline_help = <<HERE # HERE document output as shell usage
Usage: shell [OPTIONS] [SCRIPTFILE [ARGUMENTS]]
- -d | --debug Set DEBUG log levels.
- -h | --help This help.
- -n | --noninteractive Do not run within an IRB session
- and exit with non-zero status on
- first error.
+ -d | --debug Set DEBUG log levels.
+ -h | --help This help.
+ -n | --noninteractive Do not run within an IRB session and exit with non-zero
+ status on 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
+
+# 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 = []
script2run = nil
log_level = org.apache.log4j.Level::ERROR
@shell_debug = false
interactive = true
-for arg in ARGV
+_configuration = nil
+D_ARG = '-D'
+while (arg = ARGV.shift)
if arg == '-h' || arg == '--help'
puts cmdline_help
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'
log_level = org.apache.log4j.Level::DEBUG
$fullBackTrace = true
@@ -111,7 +137,7 @@ require 'shell'
require 'shell/formatter'
# Setup the HBase module. Create a configuration.
-@hbase = Hbase::Hbase.new
+@hbase = _configuration.nil? ? Hbase::Hbase.new : Hbase::Hbase.new(_configuration)
# Setup console
@shell = Shell::Shell.new(@hbase, interactive)
http://git-wip-us.apache.org/repos/asf/hbase/blob/da9508d4/src/main/asciidoc/_chapters/shell.adoc
----------------------------------------------------------------------
diff --git a/src/main/asciidoc/_chapters/shell.adoc b/src/main/asciidoc/_chapters/shell.adoc
index 5612e1d..cdfa828 100644
--- a/src/main/asciidoc/_chapters/shell.adoc
+++ b/src/main/asciidoc/_chapters/shell.adoc
@@ -58,6 +58,7 @@ To run one of these files, do as follows:
$ ./bin/hbase org.jruby.Main PATH_TO_SCRIPT
----
+
== 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)].
@@ -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
----
+== 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
=== Table variables