1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.regionserver;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import org.apache.hadoop.hbase.classification.InterfaceAudience;
25 import org.apache.hadoop.conf.Configuration;
26 import org.apache.hadoop.hbase.CoordinatedStateManagerFactory;
27 import org.apache.hadoop.hbase.HConstants;
28 import org.apache.hadoop.hbase.LocalHBaseCluster;
29 import org.apache.hadoop.hbase.CoordinatedStateManager;
30 import org.apache.hadoop.hbase.util.ServerCommandLine;
31
32
33
34
35
36 @InterfaceAudience.Private
37 public class HRegionServerCommandLine extends ServerCommandLine {
38 private static final Log LOG = LogFactory.getLog(HRegionServerCommandLine.class);
39
40 private final Class<? extends HRegionServer> regionServerClass;
41
42 private static final String USAGE =
43 "Usage: HRegionServer [-D conf.param=value] start";
44
45 public HRegionServerCommandLine(Class<? extends HRegionServer> clazz) {
46 this.regionServerClass = clazz;
47 }
48
49 protected String getUsage() {
50 return USAGE;
51 }
52
53 private int start() throws Exception {
54 Configuration conf = getConf();
55 CoordinatedStateManager cp = CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);
56 try {
57
58
59 if (LocalHBaseCluster.isLocal(conf)) {
60 LOG.warn("Not starting a distinct region server because "
61 + HConstants.CLUSTER_DISTRIBUTED + " is false");
62 } else {
63 logProcessInfo(getConf());
64 HRegionServer hrs = HRegionServer.constructRegionServer(regionServerClass, conf, cp);
65 hrs.start();
66 hrs.join();
67 if (hrs.isAborted()) {
68 throw new RuntimeException("HRegionServer Aborted");
69 }
70 }
71 } catch (Throwable t) {
72 LOG.error("Region server exiting", t);
73 return 1;
74 }
75 return 0;
76 }
77
78 public int run(String args[]) throws Exception {
79 if (args.length != 1) {
80 usage(null);
81 return 1;
82 }
83
84 String cmd = args[0];
85
86 if ("start".equals(cmd)) {
87 return start();
88 } else if ("stop".equals(cmd)) {
89 System.err.println(
90 "To shutdown the regionserver run " +
91 "bin/hbase-daemon.sh stop regionserver or send a kill signal to" +
92 "the regionserver pid");
93 return 1;
94 } else {
95 usage("Unknown command: " + args[0]);
96 return 1;
97 }
98 }
99 }