001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.regionserver; 019 020import io.opentelemetry.api.trace.Span; 021import io.opentelemetry.api.trace.StatusCode; 022import io.opentelemetry.context.Scope; 023import org.apache.hadoop.conf.Configuration; 024import org.apache.hadoop.hbase.HConstants; 025import org.apache.hadoop.hbase.LocalHBaseCluster; 026import org.apache.hadoop.hbase.trace.TraceUtil; 027import org.apache.hadoop.hbase.util.ServerCommandLine; 028import org.apache.yetus.audience.InterfaceAudience; 029import org.slf4j.Logger; 030import org.slf4j.LoggerFactory; 031 032/** 033 * Class responsible for parsing the command line and starting the RegionServer. 034 */ 035@InterfaceAudience.Private 036public class HRegionServerCommandLine extends ServerCommandLine { 037 private static final Logger LOG = LoggerFactory.getLogger(HRegionServerCommandLine.class); 038 039 private final Class<? extends HRegionServer> regionServerClass; 040 041 private static final String USAGE = "Usage: HRegionServer [-D conf.param=value] start"; 042 043 public HRegionServerCommandLine(Class<? extends HRegionServer> clazz) { 044 this.regionServerClass = clazz; 045 } 046 047 @Override 048 protected String getUsage() { 049 return USAGE; 050 } 051 052 private int start() throws Exception { 053 Configuration conf = getConf(); 054 final Span span = TraceUtil.createSpan("HRegionServerCommandLine.start"); 055 try (Scope ignored = span.makeCurrent()) { 056 // If 'local', don't start a region server here. Defer to 057 // LocalHBaseCluster. It manages 'local' clusters. 058 if (LocalHBaseCluster.isLocal(conf)) { 059 LOG.warn("Not starting a distinct region server because " + HConstants.CLUSTER_DISTRIBUTED 060 + " is false"); 061 } else { 062 logProcessInfo(getConf()); 063 HRegionServer hrs = HRegionServer.constructRegionServer(regionServerClass, conf); 064 hrs.start(); 065 hrs.join(); 066 if (hrs.isAborted()) { 067 throw new RuntimeException("HRegionServer Aborted"); 068 } 069 } 070 span.setStatus(StatusCode.OK); 071 } catch (Throwable t) { 072 TraceUtil.setError(span, t); 073 LOG.error("Region server exiting", t); 074 return 1; 075 } finally { 076 span.end(); 077 } 078 return 0; 079 } 080 081 @Override 082 public int run(String args[]) throws Exception { 083 if (args.length != 1) { 084 usage(null); 085 return 1; 086 } 087 088 String cmd = args[0]; 089 090 if ("start".equals(cmd)) { 091 return start(); 092 } else if ("stop".equals(cmd)) { 093 System.err.println("To shutdown the regionserver run " 094 + "hbase-daemon.sh stop regionserver or send a kill signal to " + "the regionserver pid"); 095 return 1; 096 } else { 097 usage("Unknown command: " + args[0]); 098 return 1; 099 } 100 } 101}