HMaster启动流程简析

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

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

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

0.2 通过HbaseRPC创建一个RPCServer

0.2.1 首先获取RPCEngineWritableRPCEngine),并通过其对RPCServer进初始化(ServerHBaseServerRPCServer

0.2.1.1 初始化CallQueueipc.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),以及SizeBasedThrottlerthreshold=ipc.server.max.callqueue.size,ListenerResponder

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.sizethreadpool并对ipc.server.read.threadpool.sizeReader进行初始化并启动,最后注册连接事件;

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取出Callrpcserver调用,并将返回值发送到responder进行处理

013418729.png

0.4HMaster传入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 初始化ActiveMasterManagerZookeeperListener

1.1.2 zookeeperWatcher注册到ActiveMasterManager来进行监听

1.1.3 stallIfBackupMastes略过不表

1.1.4 初始化ClusterStatusTrackerZookeeperNodeTracker,并启动,注册HMasterClusterStatusTracker

1.1.5 blockUntilBecomingActiveMasterAdd 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,则初始化SplitLogManagerZookeeperListener

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 初始化所有基于ZKtracker:

1.2.5.1初始化CatalogTracker

1.2.5.1.1 获取一个HConnection

1.2.5.1.2 初始化RootRegionTrackerZookeeperNodeTrackerrootServerZnode

1.2.5.1.3 初始化MetaRegionTrackerZookeeperNodeTracker(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的分配:包括初始化timeoutMonitorhbase.master.assignment.timeoutmonitor.period默认10shbase.master.assignment.timeoutmonitor.timeout默认30min),timerUpdaterhbase.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_REGIONhbase.master.executor.openregion.threads5),MASTER_CLOSE_REGIONhbase.master.executor.closeregion.threads5),MASTER_SERVER_OPERATIONShbase.master.executor.serverops.threads3),MASTER_META_SERVER_OPERATIONShbase.master.executor.serverops.threads5),MASTER_TABLE_OPERATIONS;以及初始化并运行LogCleanerHFileCleaner,最后启动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,如果不在线则加入到splitlogManagerdeadWorkers列表并在Zk对所有的hlogsplitlog路径下创建一个znode,等待其他RegionServerSplitlogWorker获取任务后进行处理(细节见下篇RegionServer启动流程),若关闭hbase.master.distributed.log.splitting,则由HMaster处理,此处不表

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

1.2.13.1

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

1.2.15 AssginmentManager 进行JoinCluster:将InDisablingStateEnabingState的表进行恢复

1.2.16 fix region

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

1.2.18 startCatalogJanitorChore启动

1.2.16 执行postCP post Master startup

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

完毕

你可能感兴趣的:(hbase,startup,internal)