HBASEHRegionServer启动分析
regionserver的启动入口是HRegionServer.main方法
生成HRegionServercommandLine实例,并执行doMain方法,
此方法中通过ToolRunner.run去调用HRegionServercommandLine.run方法
a.判断传入参数是start还是stop,如果是start,调用HRegionServercommandLine.start()方法
b.调用HRegionServer(Configuration)生成regionserver实例,请点这里
c.通过Thread的start去调用regionserver.run方法,请点这里
publicstaticvoidmain(String[]args)throws Exception {
VersionInfo.logVersion();
Configurationconf= HBaseConfiguration.create();
@SuppressWarnings("unchecked")
Class<?extendsHRegionServer>regionServerClass= (Class<?extendsHRegionServer>)conf
.getClass(HConstants.REGION_SERVER_IMPL,HRegionServer.class);
newHRegionServerCommandLine(regionServerClass).doMain(args);
}
生成HRegionServer实例
1.通过hbase.regionserver.codecs配置regionserver的压缩
2.0检查通过hbase对hdfs进行本地读取时,是否需要检验,
dfs.client.read.shortcircuit.skip.checksum,默认为false
2.1通过hbase.regionserver.checksum.verify来配置regionserver读取到数据后是否检验
publicHRegionServer(Configurationconf)
throwsIOException, InterruptedException {
this.fsOk=true;
this.conf=conf;
this.isOnline=false;//默认情况下,rs是非在线状态
.........此处省去一些代码
//读取client的最大重试次数hbase.client.retries.number,default=31
this.numRetries=this.conf.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
Hconstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
得到hbase.server.thread.wakefrequency的值,默认为10*1000ms,
检查memstore是否超过hbase.hregion.memstore.flush.size设置的flush大小的时间间隔
this.threadWakeFrequency=conf.getInt(HConstants.THREAD_WAKE_FREQUENCY,10 * 1000);
定时向master发送此rs的报告的间隔时间,默认为3s=3000ms
this.msgInterval=conf.getInt("hbase.regionserver.msginterval",3 * 1000);
this.sleeper=newSleeper(this.msgInterval,this);
通过hbase.client.scanner.max.result.size配置client的最大响应字节数,默认为long.maxvalue,也就是不设置
this.maxScannerResultSize=conf.getLong(
HConstants.HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY,
HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE);
配置向master进行region的region个数,
this.numRegionsToReport=conf.getInt(
"hbase.regionserver.numregionstoreport",10);
通过hbase.rpc.shortoperation.timeout配置rpc的超时时间,默认为10000ms=10s
this.rpcTimeout=conf.getInt(
HConstants.HBASE_RPC_SHORTOPERATION_TIMEOUT_KEY,
HConstants.DEFAULT_HBASE_RPC_SHORTOPERATION_TIMEOUT);
this.abortRequested=false;
this.stopped=false;
通过hbase.client.scanner.timeout.period配置client的scan租约到期时间,默认为60000ms=60s
老版本通过hbase.regionserver.lease.period配置
this.scannerLeaseTimeoutPeriod= HBaseConfiguration.getInt(conf,
HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD,
HConstants.HBASE_REGIONSERVER_LEASE_PERIOD_KEY,
HConstants.DEFAULT_HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD);
//Server to handle client requests.
Stringhostname=conf.get("hbase.regionserver.ipc.address",
.........此处省去DNS解析代码
得到通过hbase.regionserver.port配置的rs的rpc端口,默认为60020
intport =conf.getInt(HConstants.REGIONSERVER_PORT,
HConstants.DEFAULT_REGIONSERVER_PORT);
//Creation of a HSA will force a resolve.
InetSocketAddressinitialIsa=newInetSocketAddress(hostname,port);
.........此处省去一些判断的代码
this.rand=newRandom(initialIsa.hashCode());
Stringname="regionserver/"+initialIsa.toString();
//Set how many times to retry talking to another server overHconnection.
设置Hconnection的执行重试次数,
hbase.client.retries.number*hbase.client.serverside.retries.multiplier,default=31*10
HConnectionManager.setServerSideHConnectionRetries(this.conf,name,LOG);
生成rpcserver,通过hostname与port,读取rpchandler的线程数
this.rpcServer=