HMaster启动流程简析

很多细节不便在本篇写的过于详细,等后续细节分析

沈阳网站建设公司创新互联,沈阳网站设计制作,有大型网站制作公司丰富经验。已为沈阳近1000家提供企业网站建设服务。企业网站搭建\成都外贸网站建设要多少钱,请找那个售后服务好的沈阳做网站的公司定做!

0.由HBaseCommandLine首先对HMaster进行初始化

0.1检查是否进行了IP绑定(https://issues.apache.org/jira/browse/HBASE-8148),获取地址

0.2通过HbaseRPC创建一个RPCServer

0.2.1首先获取RPCEngine(WritableRPCEngine),并通过其对RPCServer进初始化(Server:HBaseServer:RPCServer)

0.2.1.1初始化CallQueue(ipc.server.max.queue.size:向后兼容,ipc.server.max.callqueue.length,默认值为handler* DEFAULT_MAX_CALLQUEUE_LENGTH_PER_HANDLER)和ReplicationQueue(ipc.server.max.callqueue.size,默认值为1024×1024×1024),以及SizeBasedThrottler(threshold=ipc.server.max.callqueue.size),Listener和Responder等

0.2.1.1.1初始化Responder,创建一个selector,其中频率为purgeTimeout(默认值2×DEFAULT_HBASE_RPC_TIMEOUT)

0.2.1.1.2初始化Listener,获取监听地址并绑定到ServerSocket,其中backlog length= ipc.server.listen.queue.size,并初始化一个大小为ipc.server.read.threadpool.size的threadpool并对ipc.server.read.threadpool.size个Reader进行初始化并启动,最后注册连接事件;

0.3对已经初始化完毕的RPCServer启动

0.3.1启动Responder,从responseQueue取出response写回,这里Responder有一处类似HADOOP RPC的优化就是当responseQueue只有一个值时立刻响应.

0.3.2启动Listener:每10秒并且连接数超过ipc.client.idlethreshold则对ConnectionList进行一次检查,若超时2×ipc.client.connection.maxidletime,则进行清理,最多清理ipc.client.kill.max(默认10个)

0.3.3启动Handler,从CallQueue取出Call对rpcserver调用,并将返回值发送到responder进行处理

HMaster启动流程简析

0.4将HMaster传入ZookeeperWatcher初始化

0.4.1初始化ZookeeperWatcher:通过Zkutil或者一个Zookeeper Client对象,其中sessionTimeout=zookeeper.session.timeout(默认180s),maxretry=zookeeper.recovery.retry以及retryIntervalMillis=zookeeper.recovery.retry.intervalmill

0.4.1.1进入到Zookeeper环节(下回分解)

0.5初始化Health Check Thread,检查频率为hbase.node.health.script.frequency默认10秒

1.HMaster执行startup进行启动流程

1.1调用becomeActiveMaster,进入阻塞状态直到Active

1.1.1初始化ActiveMasterManager:ZookeeperListener

1.1.2将zookeeperWatcher注册到ActiveMasterManager来进行监听

1.1.3 stallIfBackupMastes略过不表

1.1.4初始化ClusterStatusTracker:ZookeeperNodeTracker,并启动,注册HMaster到ClusterStatusTracker上

1.1.5 blockUntilBecomingActiveMaster:Add a ZNode for ourselves in the backup master directory since we are notthe active master.If we become the active master later, ActiveMasterManagerwill delete this node explicitly. If wecrash before then, ZooKeeper will delete this node for us since it isephemeral.

1.2调用finishInitialization进入初始化完成阶段

1.2.1初始化filesystemManager:MasterFileSystem

1.2.1.1如果开启hbase.master.distributed.log.splitting,则初始化SplitLogManager:ZookeeperListener

1.2.1.1.1

1.2.1.2创建初始化目录:检查rootdir是否存在,检查tempdir是否存在并清理,创建oldlogdir

1.2.2初始化FSTableDescriptors->tableDescriptor

1.2.3初始化ExecutorService

1.2.4初始化ServerManager:其中是通过HConnectionManager获取一个HConnection,其中连接池的大小为hbase.zookeeper.properties.maxClientCnXns(默认300)+1

1.2.5初始化所有基于ZK的tracker:

1.2.5.1初始化CatalogTracker

1.2.5.1.1获取一个HConnection

1.2.5.1.2初始化RootRegionTracker:ZookeeperNodeTracker(rootServerZnode)

1.2.5.1.3初始化MetaRegionTracker:ZookeeperNodeTracker(assignmentnode/first_meta_region)

1.2.5.2启动CalalogTracker

1.2.5.2.1启动RootRegionTracker:开始track RR

1.2.5.2.2启动MetaRegionTracker:开始trackMR

1.2.5.3通过LoadBalancerFactory获取balancer实例

1.2.5.4初始化AssginmentManager,管理region的分配:包括初始化timeoutMonitor(hbase.master.assignment.timeoutmonitor.period默认10s,hbase.master.assignment.timeoutmonitor.timeout默认30min),timerUpdater(hbase.master.assignment.timerupdater.period默认10s)

1.2.5.5将zookeeperWatcher注册到assginmentManager,并加到ListenerList的第一位

1.2.5.6初始化RegionServerTracker...

1.2.5.7启动RegionServerTracker...

1.2.5.8初始化DrainingServerTracker...

1.2.5.9启动DrainingServerTracker...

1.2.5.10初始化SnapshotManager...

1.2.7初始化MasterCoprocessorHost

1.2.8启动服务线程:包括MASTER_OPEN_REGION(hbase.master.executor.openregion.threads,5),MASTER_CLOSE_REGION(hbase.master.executor.closeregion.threads,5),MASTER_SERVER_OPERATIONS(hbase.master.executor.serverops.threads,3),MASTER_META_SERVER_OPERATIONS(hbase.master.executor.serverops.threads,5),MASTER_TABLE_OPERATIONS;以及初始化并运行LogCleaner,HFileCleaner,最后启动HealCheckChore,并且RPCServer开始接受请求

1.2.9等待RS状态汇报:等到以下三个条件满足:

a.themaster is stopped

b.the'hbase.master.wait.on.regionservers.maxtostart' number of region servers is reached

c.the 'hbase.master.wait.on.regionservers.mintostart' is reached AND

there have been no new region serverin for 'hbase.master.wait.on.regionservers.interval默认1.5s' time AND

the'hbase.master.wait.on.regionservers.timeout默认4.5s'is reached

1.2.10检查哪些RS没有注册到ZK:将启动的RS进行注册并记录到serverManager

1.2.11启动AssignManager:启动TimeoutMonitor

1.2.12进行一次splitlog操作:由MasterFileSystem进行,扫描hlogdir查看其所属regionserver是否online,如果不在线则加入到splitlogManager的deadWorkers列表并在Zk对所有的hlog在splitlog路径下创建一个znode,等待其他RegionServer的SplitlogWorker获取任务后进行处理(细节见下篇RegionServer启动流程),若关闭hbase.master.distributed.log.splitting,则由HMaster处理,此处不表

1.2.13分配ROOT和MATA region:检查—ROOT—和.META.是否已经分配,若没有则由AssignmentManager进行分配:

1.2.13.1

1.2.14开启shutdownHandler:由ServerManager对deadNotExpiredServers进行过期检查,对expiredServer进行处理并提交关闭流程到ExecutorService

1.2.15 AssginmentManager进行JoinCluster:将InDisablingState和EnabingState的表进行恢复

1.2.16 fix子region

1.2.17启动Balancer并交由Chore每300s运行一次,并且是单线程运行:当Region正处于转换或者RS正在下线则不进行balance;

1.2.18 startCatalogJanitorChore启动

1.2.16执行postCP post Master startup

1.3启动Stop Check Thread,每秒检查一次

完毕


标题名称:HMaster启动流程简析
文章位置:http://pwwzsj.com/article/jsjipp.html