Revert "HBASE-25368 Filter out more invalid encoded name in isEncodedRegionName(byte...
[hbase.git] / bin / hbase
blobd2307c50c33a582a65da27b7c11e7054019d55d5
1 #! /usr/bin/env bash
3 #/**
4 # * Licensed to the Apache Software Foundation (ASF) under one
5 # * or more contributor license agreements. See the NOTICE file
6 # * distributed with this work for additional information
7 # * regarding copyright ownership. The ASF licenses this file
8 # * to you under the Apache License, Version 2.0 (the
9 # * "License"); you may not use this file except in compliance
10 # * with the License. You may obtain a copy of the License at
11 # *
12 # * http://www.apache.org/licenses/LICENSE-2.0
13 # *
14 # * Unless required by applicable law or agreed to in writing, software
15 # * distributed under the License is distributed on an "AS IS" BASIS,
16 # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # * See the License for the specific language governing permissions and
18 # * limitations under the License.
19 # */
21 # The hbase command script. Based on the hadoop command script putting
22 # in hbase classes, libs and configurations ahead of hadoop's.
24 # TODO: Narrow the amount of duplicated code.
26 # Environment Variables:
28 # JAVA_HOME The java implementation to use. Overrides JAVA_HOME.
30 # HBASE_CLASSPATH Extra Java CLASSPATH entries.
32 # HBASE_CLASSPATH_PREFIX Extra Java CLASSPATH entries that should be
33 # prefixed to the system classpath.
35 # HBASE_HEAPSIZE The maximum amount of heap to use.
36 # Default is unset and uses the JVMs default setting
37 # (usually 1/4th of the available memory).
39 # HBASE_LIBRARY_PATH HBase additions to JAVA_LIBRARY_PATH for adding
40 # native libraries.
42 # HBASE_OPTS Extra Java runtime options.
44 # HBASE_CONF_DIR Alternate conf dir. Default is ${HBASE_HOME}/conf.
46 # HBASE_ROOT_LOGGER The root appender. Default is INFO,console
48 # JRUBY_HOME JRuby path: $JRUBY_HOME/lib/jruby.jar should exist.
49 # Defaults to the jar packaged with HBase.
51 # JRUBY_OPTS Extra options (eg '--1.9') passed to hbase.
52 # Empty by default.
54 # HBASE_SHELL_OPTS Extra options passed to the hbase shell.
55 # Empty by default.
57 bin=`dirname "$0"`
58 bin=`cd "$bin">/dev/null; pwd`
60 read -d '' options_string << EOF
61 Options:
62 --config DIR Configuration direction to use. Default: ./conf
63 --hosts HOSTS Override the list in 'regionservers' file
64 --auth-as-server Authenticate to ZooKeeper using servers configuration
65 --internal-classpath Skip attempting to use client facing jars (WARNING: unstable results between versions)
66 --help or -h Print this help message
67 EOF
68 show_usage() {
69 echo "Usage: hbase [<options>] <command> [<args>]"
70 echo "$options_string"
71 echo ""
72 echo "Commands:"
73 echo "Some commands take arguments. Pass no args or -h for usage."
74 echo " shell Run the HBase shell"
75 echo " hbck Run the HBase 'fsck' tool. Defaults read-only hbck1."
76 echo " Pass '-j /path/to/HBCK2.jar' to run hbase-2.x HBCK2."
77 echo " snapshot Tool for managing snapshots"
78 if [ "${in_omnibus_tarball}" = "true" ]; then
79 echo " wal Write-ahead-log analyzer"
80 echo " hfile Store file analyzer"
81 echo " zkcli Run the ZooKeeper shell"
82 echo " master Run an HBase HMaster node"
83 echo " regionserver Run an HBase HRegionServer node"
84 echo " zookeeper Run a ZooKeeper server"
85 echo " rest Run an HBase REST server"
86 echo " thrift Run the HBase Thrift server"
87 echo " thrift2 Run the HBase Thrift2 server"
88 echo " clean Run the HBase clean up script"
90 echo " classpath Dump hbase CLASSPATH"
91 echo " mapredcp Dump CLASSPATH entries required by mapreduce"
92 echo " pe Run PerformanceEvaluation"
93 echo " ltt Run LoadTestTool"
94 echo " canary Run the Canary tool"
95 echo " version Print the version"
96 echo " backup Backup tables for recovery"
97 echo " restore Restore tables from existing backup image"
98 echo " completebulkload Run BulkLoadHFiles tool"
99 echo " regionsplitter Run RegionSplitter tool"
100 echo " rowcounter Run RowCounter tool"
101 echo " cellcounter Run CellCounter tool"
102 echo " pre-upgrade Run Pre-Upgrade validator tool"
103 echo " hbtop Run HBTop tool"
104 echo " CLASSNAME Run the class named CLASSNAME"
107 if [ "--help" = "$1" ] || [ "-h" = "$1" ]; then
108 show_usage
109 exit 0
112 # This will set HBASE_HOME, etc.
113 . "$bin"/hbase-config.sh
115 cygwin=false
116 case "`uname`" in
117 CYGWIN*) cygwin=true;;
118 esac
120 # Detect if we are in hbase sources dir
121 in_dev_env=false
122 if [ -d "${HBASE_HOME}/target" ]; then
123 in_dev_env=true
126 # Detect if we are in the omnibus tarball
127 in_omnibus_tarball="false"
128 if [ -f "${HBASE_HOME}/bin/hbase-daemons.sh" ]; then
129 in_omnibus_tarball="true"
132 # if no args specified, show usage
133 if [ $# = 0 ]; then
134 show_usage
135 exit 1
138 # get arguments
139 COMMAND=$1
140 shift
142 JAVA=$JAVA_HOME/bin/java
144 # override default settings for this command, if applicable
145 if [ -f "$HBASE_HOME/conf/hbase-env-$COMMAND.sh" ]; then
146 . "$HBASE_HOME/conf/hbase-env-$COMMAND.sh"
149 # establish a default value for HBASE_OPTS if it's not already set. For now,
150 # all we set is the garbage collector.
151 if [ -z "${HBASE_OPTS}" ] ; then
152 major_version_number="$(parse_java_major_version "$(read_java_version)")"
153 case "$major_version_number" in
154 8|9|10)
155 HBASE_OPTS="-XX:+UseConcMarkSweepGC"
157 11|*)
158 HBASE_OPTS="-XX:+UseG1GC"
160 esac
161 export HBASE_OPTS
164 add_size_suffix() {
165 # add an 'm' suffix if the argument is missing one, otherwise use whats there
166 local val="$1"
167 local lastchar=${val: -1}
168 if [[ "mMgG" == *$lastchar* ]]; then
169 echo $val
170 else
171 echo ${val}m
175 if [[ -n "$HBASE_HEAPSIZE" ]]; then
176 JAVA_HEAP_MAX="-Xmx$(add_size_suffix $HBASE_HEAPSIZE)"
179 if [[ -n "$HBASE_OFFHEAPSIZE" ]]; then
180 JAVA_OFFHEAP_MAX="-XX:MaxDirectMemorySize=$(add_size_suffix $HBASE_OFFHEAPSIZE)"
183 # so that filenames w/ spaces are handled correctly in loops below
184 ORIG_IFS=$IFS
185 IFS=
187 # CLASSPATH initially contains $HBASE_CONF_DIR
188 CLASSPATH="${HBASE_CONF_DIR}"
189 CLASSPATH=${CLASSPATH}:$JAVA_HOME/lib/tools.jar
191 add_to_cp_if_exists() {
192 if [ -d "$@" ]; then
193 CLASSPATH=${CLASSPATH}:"$@"
197 # For releases, add hbase & webapps to CLASSPATH
198 # Webapps must come first else it messes up Jetty
199 if [ -d "$HBASE_HOME/hbase-webapps" ]; then
200 add_to_cp_if_exists "${HBASE_HOME}"
202 #add if we are in a dev environment
203 if [ -d "$HBASE_HOME/hbase-server/target/hbase-webapps" ]; then
204 if [ "$COMMAND" = "thrift" ] ; then
205 add_to_cp_if_exists "${HBASE_HOME}/hbase-thrift/target"
206 elif [ "$COMMAND" = "thrift2" ] ; then
207 add_to_cp_if_exists "${HBASE_HOME}/hbase-thrift/target"
208 elif [ "$COMMAND" = "rest" ] ; then
209 add_to_cp_if_exists "${HBASE_HOME}/hbase-rest/target"
210 else
211 add_to_cp_if_exists "${HBASE_HOME}/hbase-server/target"
212 # Needed for GetJavaProperty check below
213 add_to_cp_if_exists "${HBASE_HOME}/hbase-server/target/classes"
217 #If avail, add Hadoop to the CLASSPATH and to the JAVA_LIBRARY_PATH
218 # Allow this functionality to be disabled
219 if [ "$HBASE_DISABLE_HADOOP_CLASSPATH_LOOKUP" != "true" ] ; then
220 HADOOP_IN_PATH=$(PATH="${HADOOP_HOME:-${HADOOP_PREFIX}}/bin:$PATH" which hadoop 2>/dev/null)
223 # Add libs to CLASSPATH
224 declare shaded_jar
226 if [ "${INTERNAL_CLASSPATH}" != "true" ]; then
227 # find our shaded jars
228 declare shaded_client
229 declare shaded_client_byo_hadoop
230 declare shaded_mapreduce
231 for f in "${HBASE_HOME}"/lib/shaded-clients/hbase-shaded-client*.jar; do
232 if [[ "${f}" =~ byo-hadoop ]]; then
233 shaded_client_byo_hadoop="${f}"
234 else
235 shaded_client="${f}"
237 done
238 for f in "${HBASE_HOME}"/lib/shaded-clients/hbase-shaded-mapreduce*.jar; do
239 shaded_mapreduce="${f}"
240 done
242 # If command can use our shaded client, use it
243 declare -a commands_in_client_jar=("classpath" "version" "hbtop")
244 for c in "${commands_in_client_jar[@]}"; do
245 if [ "${COMMAND}" = "${c}" ]; then
246 if [ -n "${HADOOP_IN_PATH}" ] && [ -f "${HADOOP_IN_PATH}" ]; then
247 # If we didn't find a jar above, this will just be blank and the
248 # check below will then default back to the internal classpath.
249 shaded_jar="${shaded_client_byo_hadoop}"
250 else
251 # If we didn't find a jar above, this will just be blank and the
252 # check below will then default back to the internal classpath.
253 shaded_jar="${shaded_client}"
255 break
257 done
259 # If command needs our shaded mapreduce, use it
260 # N.B "mapredcp" is not included here because in the shaded case it skips our built classpath
261 declare -a commands_in_mr_jar=("hbck" "snapshot" "regionsplitter" "pre-upgrade")
262 for c in "${commands_in_mr_jar[@]}"; do
263 if [ "${COMMAND}" = "${c}" ]; then
264 # If we didn't find a jar above, this will just be blank and the
265 # check below will then default back to the internal classpath.
266 shaded_jar="${shaded_mapreduce}"
267 break
269 done
271 # Some commands specifically only can use shaded mapreduce when we'll get a full hadoop classpath at runtime
272 if [ -n "${HADOOP_IN_PATH}" ] && [ -f "${HADOOP_IN_PATH}" ]; then
273 declare -a commands_in_mr_need_hadoop=("backup" "restore" "rowcounter" "cellcounter")
274 for c in "${commands_in_mr_need_hadoop[@]}"; do
275 if [ "${COMMAND}" = "${c}" ]; then
276 # If we didn't find a jar above, this will just be blank and the
277 # check below will then default back to the internal classpath.
278 shaded_jar="${shaded_mapreduce}"
279 break
281 done
286 if [ -n "${shaded_jar}" ] && [ -f "${shaded_jar}" ]; then
287 CLASSPATH="${CLASSPATH}:${shaded_jar}"
288 # fall through to grabbing all the lib jars and hope we're in the omnibus tarball
290 # N.B. shell specifically can't rely on the shaded artifacts because RSGroups is only
291 # available as non-shaded
293 # N.B. pe and ltt can't easily rely on shaded artifacts because they live in hbase-mapreduce:test-jar
294 # and need some other jars that haven't been relocated. Currently enumerating that list
295 # is too hard to be worth it.
297 else
298 for f in $HBASE_HOME/lib/*.jar; do
299 CLASSPATH=${CLASSPATH}:$f;
300 done
301 # make it easier to check for shaded/not later on.
302 shaded_jar=""
304 for f in "${HBASE_HOME}"/lib/client-facing-thirdparty/*.jar; do
305 if [[ ! "${f}" =~ ^.*/htrace-core-3.*\.jar$ ]] && \
306 [ "${f}" != "htrace-core.jar$" ] && \
307 [[ ! "${f}" =~ ^.*/slf4j-log4j.*$ ]]; then
308 CLASSPATH="${CLASSPATH}:${f}"
310 done
312 # default log directory & file
313 if [ "$HBASE_LOG_DIR" = "" ]; then
314 HBASE_LOG_DIR="$HBASE_HOME/logs"
316 if [ "$HBASE_LOGFILE" = "" ]; then
317 HBASE_LOGFILE='hbase.log'
320 function append_path() {
321 if [ -z "$1" ]; then
322 echo "$2"
323 else
324 echo "$1:$2"
328 JAVA_PLATFORM=""
330 # if HBASE_LIBRARY_PATH is defined lets use it as first or second option
331 if [ "$HBASE_LIBRARY_PATH" != "" ]; then
332 JAVA_LIBRARY_PATH=$(append_path "$JAVA_LIBRARY_PATH" "$HBASE_LIBRARY_PATH")
335 #If configured and available, add Hadoop to the CLASSPATH and to the JAVA_LIBRARY_PATH
336 if [ -n "${HADOOP_IN_PATH}" ] && [ -f "${HADOOP_IN_PATH}" ]; then
337 # If built hbase, temporarily add hbase-server*.jar to classpath for GetJavaProperty
338 # Exclude hbase-server*-tests.jar
339 temporary_cp=
340 for f in "${HBASE_HOME}"/lib/hbase-server*.jar; do
341 if [[ ! "${f}" =~ ^.*\-tests\.jar$ ]]; then
342 temporary_cp=":$f"
344 done
345 HADOOP_JAVA_LIBRARY_PATH=$(HADOOP_CLASSPATH="$CLASSPATH${temporary_cp}" "${HADOOP_IN_PATH}" \
346 org.apache.hadoop.hbase.util.GetJavaProperty java.library.path)
347 if [ -n "$HADOOP_JAVA_LIBRARY_PATH" ]; then
348 JAVA_LIBRARY_PATH=$(append_path "${JAVA_LIBRARY_PATH}" "$HADOOP_JAVA_LIBRARY_PATH")
350 CLASSPATH=$(append_path "${CLASSPATH}" "$(${HADOOP_IN_PATH} classpath 2>/dev/null)")
351 else
352 # Otherwise, if we're providing Hadoop we should include htrace 3 if we were built with a version that needs it.
353 for f in "${HBASE_HOME}"/lib/client-facing-thirdparty/htrace-core-3*.jar "${HBASE_HOME}"/lib/client-facing-thirdparty/htrace-core.jar; do
354 if [ -f "${f}" ]; then
355 CLASSPATH="${CLASSPATH}:${f}"
356 break
358 done
359 # Some commands require special handling when using shaded jars. For these cases, we rely on hbase-shaded-mapreduce
360 # instead of hbase-shaded-client* because we make use of some IA.Private classes that aren't in the latter. However,
361 # we don't invoke them using the "hadoop jar" command so we need to ensure there are some Hadoop classes available
362 # when we're not doing runtime hadoop classpath lookup.
364 # luckily the set of classes we need are those packaged in the shaded-client.
365 for c in "${commands_in_mr_jar[@]}"; do
366 if [ "${COMMAND}" = "${c}" ] && [ -n "${shaded_jar}" ]; then
367 CLASSPATH="${CLASSPATH}:${shaded_client:?We couldn\'t find the shaded client jar even though we did find the shaded MR jar. for command ${COMMAND} we need both. please use --internal-classpath as a workaround.}"
368 break
370 done
373 # Add user-specified CLASSPATH last
374 if [ "$HBASE_CLASSPATH" != "" ]; then
375 CLASSPATH=${CLASSPATH}:${HBASE_CLASSPATH}
378 # Add user-specified CLASSPATH prefix first
379 if [ "$HBASE_CLASSPATH_PREFIX" != "" ]; then
380 CLASSPATH=${HBASE_CLASSPATH_PREFIX}:${CLASSPATH}
383 # cygwin path translation
384 if $cygwin; then
385 CLASSPATH=`cygpath -p -w "$CLASSPATH"`
386 HBASE_HOME=`cygpath -d "$HBASE_HOME"`
387 HBASE_LOG_DIR=`cygpath -d "$HBASE_LOG_DIR"`
390 if [ -d "${HBASE_HOME}/build/native" -o -d "${HBASE_HOME}/lib/native" ]; then
391 if [ -z $JAVA_PLATFORM ]; then
392 JAVA_PLATFORM=`CLASSPATH=${CLASSPATH} ${JAVA} org.apache.hadoop.util.PlatformName | sed -e "s/ /_/g"`
394 if [ -d "$HBASE_HOME/build/native" ]; then
395 JAVA_LIBRARY_PATH=$(append_path "$JAVA_LIBRARY_PATH" "${HBASE_HOME}/build/native/${JAVA_PLATFORM}/lib")
398 if [ -d "${HBASE_HOME}/lib/native" ]; then
399 JAVA_LIBRARY_PATH=$(append_path "$JAVA_LIBRARY_PATH" "${HBASE_HOME}/lib/native/${JAVA_PLATFORM}")
403 # cygwin path translation
404 if $cygwin; then
405 JAVA_LIBRARY_PATH=`cygpath -p "$JAVA_LIBRARY_PATH"`
408 # restore ordinary behaviour
409 unset IFS
411 #Set the right GC options based on the what we are running
412 declare -a server_cmds=("master" "regionserver" "thrift" "thrift2" "rest" "avro" "zookeeper")
413 for cmd in ${server_cmds[@]}; do
414 if [[ $cmd == $COMMAND ]]; then
415 server=true
416 break
418 done
420 if [[ $server ]]; then
421 HBASE_OPTS="$HBASE_OPTS $SERVER_GC_OPTS"
422 else
423 HBASE_OPTS="$HBASE_OPTS $CLIENT_GC_OPTS"
426 if [ "$AUTH_AS_SERVER" == "true" ] || [ "$COMMAND" = "hbck" ]; then
427 if [ -n "$HBASE_SERVER_JAAS_OPTS" ]; then
428 HBASE_OPTS="$HBASE_OPTS $HBASE_SERVER_JAAS_OPTS"
429 else
430 HBASE_OPTS="$HBASE_OPTS $HBASE_REGIONSERVER_OPTS"
434 # check if the command needs jline
435 declare -a jline_cmds=("zkcli" "org.apache.hadoop.hbase.zookeeper.ZKMainServer")
436 for cmd in "${jline_cmds[@]}"; do
437 if [[ $cmd == "$COMMAND" ]]; then
438 jline_needed=true
439 break
441 done
443 # for jruby
444 # (1) for the commands which need jruby (see jruby_cmds defined below)
445 # A. when JRUBY_HOME is specified explicitly, eg. export JRUBY_HOME=/usr/local/share/jruby
446 # CLASSPATH and HBASE_OPTS are updated according to JRUBY_HOME specified
447 # B. when JRUBY_HOME is not specified explicitly
448 # add jruby packaged with HBase to CLASSPATH
449 # (2) for other commands, do nothing
451 # check if the commmand needs jruby
452 declare -a jruby_cmds=("shell" "org.jruby.Main")
453 for cmd in "${jruby_cmds[@]}"; do
454 if [[ $cmd == "$COMMAND" ]]; then
455 jruby_needed=true
456 break
458 done
460 add_maven_deps_to_classpath() {
461 f="${HBASE_HOME}/hbase-build-configuration/target/$1"
463 if [ ! -f "${f}" ]; then
464 echo "As this is a development environment, we need ${f} to be generated from maven (command: mvn install -DskipTests)"
465 exit 1
467 CLASSPATH=${CLASSPATH}:$(cat "${f}")
470 add_jdk11_deps_to_classpath() {
471 for f in ${HBASE_HOME}/lib/jdk11/*; do
472 if [ -f "${f}" ]; then
473 CLASSPATH="${CLASSPATH}:${f}"
475 done
478 #Add the development env class path stuff
479 if $in_dev_env; then
480 add_maven_deps_to_classpath "cached_classpath.txt"
482 if [[ $jline_needed ]]; then
483 add_maven_deps_to_classpath "cached_classpath_jline.txt"
484 elif [[ $jruby_needed ]]; then
485 add_maven_deps_to_classpath "cached_classpath_jruby.txt"
489 # the command needs jruby
490 if [[ $jruby_needed ]]; then
491 if [ "$JRUBY_HOME" != "" ]; then # JRUBY_HOME is specified explicitly, eg. export JRUBY_HOME=/usr/local/share/jruby
492 # add jruby.jar into CLASSPATH
493 CLASSPATH="$JRUBY_HOME/lib/jruby.jar:$CLASSPATH"
495 # add jruby to HBASE_OPTS
496 HBASE_OPTS="$HBASE_OPTS -Djruby.home=$JRUBY_HOME -Djruby.lib=$JRUBY_HOME/lib"
498 else # JRUBY_HOME is not specified explicitly
499 if ! $in_dev_env; then # not in dev environment
500 # add jruby packaged with HBase to CLASSPATH
501 JRUBY_PACKAGED_WITH_HBASE="$HBASE_HOME/lib/ruby/*.jar"
502 for jruby_jar in $JRUBY_PACKAGED_WITH_HBASE; do
503 CLASSPATH=$jruby_jar:$CLASSPATH;
504 done
509 # figure out which class to run
510 if [ "$COMMAND" = "shell" ] ; then
511 #find the hbase ruby sources
512 # assume we are in a binary install if lib/ruby exists
513 if [ -d "$HBASE_HOME/lib/ruby" ]; then
514 # We want jruby to consume these things rather than our bootstrap script;
515 # jruby will look for the env variable 'JRUBY_OPTS'.
516 JRUBY_OPTS="${JRUBY_OPTS} -X+O"
517 export JRUBY_OPTS
518 # hbase-shell.jar contains a 'jar-bootstrap.rb'
519 # for more info see
520 # https://github.com/jruby/jruby/wiki/StandaloneJarsAndClasses#standalone-executable-jar-files
521 CLASS="org.jruby.JarBootstrapMain"
522 # otherwise assume we are running in a source checkout
523 else
524 HBASE_OPTS="$HBASE_OPTS -Dhbase.ruby.sources=$HBASE_HOME/hbase-shell/src/main/ruby"
525 CLASS="org.jruby.Main -X+O ${JRUBY_OPTS} ${HBASE_HOME}/hbase-shell/src/main/ruby/jar-bootstrap.rb"
527 HBASE_OPTS="$HBASE_OPTS $HBASE_SHELL_OPTS"
528 elif [ "$COMMAND" = "hbck" ] ; then
529 # Look for the -j /path/to/HBCK2.jar parameter. Else pass through to hbck.
530 case "${1}" in
532 # Found -j parameter. Add arg to CLASSPATH and set CLASS to HBCK2.
533 shift
534 JAR="${1}"
535 if [ ! -f "${JAR}" ]; then
536 echo "${JAR} file not found!"
537 echo "Usage: hbase [<options>] hbck -jar /path/to/HBCK2.jar [<args>]"
538 exit 1
540 CLASSPATH="${JAR}:${CLASSPATH}";
541 CLASS="org.apache.hbase.HBCK2"
542 shift # past argument=value
545 CLASS='org.apache.hadoop.hbase.util.HBaseFsck'
547 esac
548 elif [ "$COMMAND" = "wal" ] ; then
549 CLASS='org.apache.hadoop.hbase.wal.WALPrettyPrinter'
550 elif [ "$COMMAND" = "hfile" ] ; then
551 CLASS='org.apache.hadoop.hbase.io.hfile.HFilePrettyPrinter'
552 elif [ "$COMMAND" = "zkcli" ] ; then
553 CLASS="org.apache.hadoop.hbase.zookeeper.ZKMainServer"
554 for f in $HBASE_HOME/lib/zkcli/*.jar; do
555 CLASSPATH="${CLASSPATH}:$f";
556 done
557 elif [ "$COMMAND" = "backup" ] ; then
558 CLASS='org.apache.hadoop.hbase.backup.BackupDriver'
559 if [ -n "${shaded_jar}" ] ; then
560 for f in "${HBASE_HOME}"/lib/hbase-backup*.jar; do
561 if [ -f "${f}" ]; then
562 CLASSPATH="${CLASSPATH}:${f}"
563 break
565 done
567 elif [ "$COMMAND" = "restore" ] ; then
568 CLASS='org.apache.hadoop.hbase.backup.RestoreDriver'
569 if [ -n "${shaded_jar}" ] ; then
570 for f in "${HBASE_HOME}"/lib/hbase-backup*.jar; do
571 if [ -f "${f}" ]; then
572 CLASSPATH="${CLASSPATH}:${f}"
573 break
575 done
576 for f in "${HBASE_HOME}"/lib/commons-lang3*.jar; do
577 if [ -f "${f}" ]; then
578 CLASSPATH="${CLASSPATH}:${f}"
579 break
581 done
583 elif [ "$COMMAND" = "upgrade" ] ; then
584 echo "This command was used to upgrade to HBase 0.96, it was removed in HBase 2.0.0."
585 echo "Please follow the documentation at http://hbase.apache.org/book.html#upgrading."
586 exit 1
587 elif [ "$COMMAND" = "snapshot" ] ; then
588 SUBCOMMAND=$1
589 shift
590 if [ "$SUBCOMMAND" = "create" ] ; then
591 CLASS="org.apache.hadoop.hbase.snapshot.CreateSnapshot"
592 elif [ "$SUBCOMMAND" = "info" ] ; then
593 CLASS="org.apache.hadoop.hbase.snapshot.SnapshotInfo"
594 elif [ "$SUBCOMMAND" = "export" ] ; then
595 CLASS="org.apache.hadoop.hbase.snapshot.ExportSnapshot"
596 else
597 echo "Usage: hbase [<options>] snapshot <subcommand> [<args>]"
598 echo "$options_string"
599 echo ""
600 echo "Subcommands:"
601 echo " create Create a new snapshot of a table"
602 echo " info Tool for dumping snapshot information"
603 echo " export Export an existing snapshot"
604 exit 1
606 elif [ "$COMMAND" = "master" ] ; then
607 CLASS='org.apache.hadoop.hbase.master.HMaster'
608 if [ "$1" != "stop" ] && [ "$1" != "clear" ] ; then
609 HBASE_OPTS="$HBASE_OPTS $HBASE_MASTER_OPTS"
611 elif [ "$COMMAND" = "regionserver" ] ; then
612 CLASS='org.apache.hadoop.hbase.regionserver.HRegionServer'
613 if [ "$1" != "stop" ] ; then
614 HBASE_OPTS="$HBASE_OPTS $HBASE_REGIONSERVER_OPTS"
616 elif [ "$COMMAND" = "thrift" ] ; then
617 CLASS='org.apache.hadoop.hbase.thrift.ThriftServer'
618 if [ "$1" != "stop" ] ; then
619 HBASE_OPTS="$HBASE_OPTS $HBASE_THRIFT_OPTS"
621 elif [ "$COMMAND" = "thrift2" ] ; then
622 CLASS='org.apache.hadoop.hbase.thrift2.ThriftServer'
623 if [ "$1" != "stop" ] ; then
624 HBASE_OPTS="$HBASE_OPTS $HBASE_THRIFT_OPTS"
626 elif [ "$COMMAND" = "rest" ] ; then
627 CLASS='org.apache.hadoop.hbase.rest.RESTServer'
628 if [ "$1" != "stop" ] ; then
629 HBASE_OPTS="$HBASE_OPTS $HBASE_REST_OPTS"
631 elif [ "$COMMAND" = "zookeeper" ] ; then
632 CLASS='org.apache.hadoop.hbase.zookeeper.HQuorumPeer'
633 if [ "$1" != "stop" ] ; then
634 HBASE_OPTS="$HBASE_OPTS $HBASE_ZOOKEEPER_OPTS"
636 elif [ "$COMMAND" = "clean" ] ; then
637 case $1 in
638 --cleanZk|--cleanHdfs|--cleanAll)
639 matches="yes" ;;
640 *) ;;
641 esac
642 if [ $# -ne 1 -o "$matches" = "" ]; then
643 echo "Usage: hbase clean (--cleanZk|--cleanHdfs|--cleanAll)"
644 echo "Options: "
645 echo " --cleanZk cleans hbase related data from zookeeper."
646 echo " --cleanHdfs cleans hbase related data from hdfs."
647 echo " --cleanAll cleans hbase related data from both zookeeper and hdfs."
648 exit 1;
650 "$bin"/hbase-cleanup.sh --config ${HBASE_CONF_DIR} $@
651 exit $?
652 elif [ "$COMMAND" = "mapredcp" ] ; then
653 # If we didn't find a jar above, this will just be blank and the
654 # check below will then default back to the internal classpath.
655 shaded_jar="${shaded_mapreduce}"
656 if [ "${INTERNAL_CLASSPATH}" != "true" ] && [ -f "${shaded_jar}" ]; then
657 echo -n "${shaded_jar}"
658 for f in "${HBASE_HOME}"/lib/client-facing-thirdparty/*.jar; do
659 if [[ ! "${f}" =~ ^.*/htrace-core-3.*\.jar$ ]] && \
660 [ "${f}" != "htrace-core.jar$" ] && \
661 [[ ! "${f}" =~ ^.*/slf4j-log4j.*$ ]]; then
662 echo -n ":${f}"
664 done
665 echo ""
666 exit 0
668 CLASS='org.apache.hadoop.hbase.util.MapreduceDependencyClasspathTool'
669 elif [ "$COMMAND" = "classpath" ] ; then
670 echo "$CLASSPATH"
671 exit 0
672 elif [ "$COMMAND" = "pe" ] ; then
673 CLASS='org.apache.hadoop.hbase.PerformanceEvaluation'
674 HBASE_OPTS="$HBASE_OPTS $HBASE_PE_OPTS"
675 elif [ "$COMMAND" = "ltt" ] ; then
676 CLASS='org.apache.hadoop.hbase.util.LoadTestTool'
677 HBASE_OPTS="$HBASE_OPTS $HBASE_LTT_OPTS"
678 elif [ "$COMMAND" = "canary" ] ; then
679 CLASS='org.apache.hadoop.hbase.tool.CanaryTool'
680 HBASE_OPTS="$HBASE_OPTS $HBASE_CANARY_OPTS"
681 elif [ "$COMMAND" = "version" ] ; then
682 CLASS='org.apache.hadoop.hbase.util.VersionInfo'
683 elif [ "$COMMAND" = "regionsplitter" ] ; then
684 CLASS='org.apache.hadoop.hbase.util.RegionSplitter'
685 elif [ "$COMMAND" = "rowcounter" ] ; then
686 CLASS='org.apache.hadoop.hbase.mapreduce.RowCounter'
687 elif [ "$COMMAND" = "cellcounter" ] ; then
688 CLASS='org.apache.hadoop.hbase.mapreduce.CellCounter'
689 elif [ "$COMMAND" = "pre-upgrade" ] ; then
690 CLASS='org.apache.hadoop.hbase.tool.PreUpgradeValidator'
691 elif [ "$COMMAND" = "completebulkload" ] ; then
692 CLASS='org.apache.hadoop.hbase.tool.BulkLoadHFilesTool'
693 elif [ "$COMMAND" = "hbtop" ] ; then
694 CLASS='org.apache.hadoop.hbase.hbtop.HBTop'
695 if [ -n "${shaded_jar}" ] ; then
696 for f in "${HBASE_HOME}"/lib/hbase-hbtop*.jar; do
697 if [ -f "${f}" ]; then
698 CLASSPATH="${CLASSPATH}:${f}"
699 break
701 done
702 for f in "${HBASE_HOME}"/lib/commons-lang3*.jar; do
703 if [ -f "${f}" ]; then
704 CLASSPATH="${CLASSPATH}:${f}"
705 break
707 done
710 if [ -f "${HBASE_HOME}/conf/log4j-hbtop.properties" ] ; then
711 HBASE_HBTOP_OPTS="${HBASE_HBTOP_OPTS} -Dlog4j.configuration=file:${HBASE_HOME}/conf/log4j-hbtop.properties"
713 HBASE_OPTS="${HBASE_OPTS} ${HBASE_HBTOP_OPTS}"
714 else
715 CLASS=$COMMAND
718 # Add lib/jdk11 jars to the classpath
720 if [ "${DEBUG}" = "true" ]; then
721 echo "Deciding on addition of lib/jdk11 jars to the classpath"
724 addJDK11Jars=false
726 if [ "${HBASE_JDK11}" != "" ]; then
727 # Use the passed Environment Variable HBASE_JDK11
728 if [ "${HBASE_JDK11}" = "include" ]; then
729 addJDK11Jars=true
730 if [ "${DEBUG}" = "true" ]; then
731 echo "HBASE_JDK11 set as 'include' hence adding JDK11 jars to classpath."
733 elif [ "${HBASE_JDK11}" = "exclude" ]; then
734 if [ "${DEBUG}" = "true" ]; then
735 echo "HBASE_JDK11 set as 'exclude' hence skipping JDK11 jars to classpath."
737 else
738 echo "[HBASE_JDK11] contains unsupported value(s) - ${HBASE_JDK11}. Ignoring passed value."
739 echo "[HBASE_JDK11] supported values: [include, exclude]."
741 else
742 # Use JDK detection
743 version="$(read_java_version)"
744 major_version_number="$(parse_java_major_version "$version")"
746 if [ "${DEBUG}" = "true" ]; then
747 echo "HBASE_JDK11 not set hence using JDK detection."
748 echo "Extracted JDK version - ${version}, major_version_number - ${major_version_number}"
751 if [[ "$major_version_number" -ge "11" ]]; then
752 if [ "${DEBUG}" = "true" ]; then
753 echo "Version ${version} is greater-than/equal to 11 hence adding JDK11 jars to classpath."
755 addJDK11Jars=true
756 elif [ "${DEBUG}" = "true" ]; then
757 echo "Version ${version} is lesser than 11 hence skipping JDK11 jars from classpath."
761 if [ "${addJDK11Jars}" = "true" ]; then
762 add_jdk11_deps_to_classpath
763 if [ "${DEBUG}" = "true" ]; then
764 echo "Added JDK11 jars to classpath."
766 elif [ "${DEBUG}" = "true" ]; then
767 echo "JDK11 jars skipped from classpath."
770 # Have JVM dump heap if we run out of memory. Files will be 'launch directory'
771 # and are named like the following: java_pid21612.hprof. Apparently it doesn't
772 # 'cost' to have this flag enabled. Its a 1.6 flag only. See:
773 # http://blogs.sun.com/alanb/entry/outofmemoryerror_looks_a_bit_better
774 HBASE_OPTS="$HBASE_OPTS -Dhbase.log.dir=$HBASE_LOG_DIR"
775 HBASE_OPTS="$HBASE_OPTS -Dhbase.log.file=$HBASE_LOGFILE"
776 HBASE_OPTS="$HBASE_OPTS -Dhbase.home.dir=$HBASE_HOME"
777 HBASE_OPTS="$HBASE_OPTS -Dhbase.id.str=$HBASE_IDENT_STRING"
778 HBASE_OPTS="$HBASE_OPTS -Dhbase.root.logger=${HBASE_ROOT_LOGGER:-INFO,console}"
779 if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then
780 HBASE_OPTS="$HBASE_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH"
781 export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$JAVA_LIBRARY_PATH"
784 # Enable security logging on the master and regionserver only
785 if [ "$COMMAND" = "master" ] || [ "$COMMAND" = "regionserver" ]; then
786 HBASE_OPTS="$HBASE_OPTS -Dhbase.security.logger=${HBASE_SECURITY_LOGGER:-INFO,RFAS}"
787 else
788 HBASE_OPTS="$HBASE_OPTS -Dhbase.security.logger=${HBASE_SECURITY_LOGGER:-INFO,NullAppender}"
791 HEAP_SETTINGS="$JAVA_HEAP_MAX $JAVA_OFFHEAP_MAX"
792 # by now if we're running a command it means we need logging
793 for f in ${HBASE_HOME}/lib/client-facing-thirdparty/slf4j-log4j*.jar; do
794 if [ -f "${f}" ]; then
795 CLASSPATH="${CLASSPATH}:${f}"
796 break
798 done
800 # Exec unless HBASE_NOEXEC is set.
801 export CLASSPATH
802 if [ "${DEBUG}" = "true" ]; then
803 echo "classpath=${CLASSPATH}" >&2
804 HBASE_OPTS="${HBASE_OPTS} -Xdiag"
807 if [ "${HBASE_NOEXEC}" != "" ]; then
808 "$JAVA" -Dproc_$COMMAND -XX:OnOutOfMemoryError="kill -9 %p" $HEAP_SETTINGS $HBASE_OPTS $CLASS "$@"
809 else
810 export JVM_PID="$$"
811 exec "$JAVA" -Dproc_$COMMAND -XX:OnOutOfMemoryError="kill -9 %p" $HEAP_SETTINGS $HBASE_OPTS $CLASS "$@"