下面继续从HMaster.finishActiveMasterInitialization方法开始分析HBase 0.99 Master启动过程。HMaster.finishActiveMasterInitialization方法主要完成如下功能:
1. 初始化Master功能组件:file system manager, server manager, assignment manager, region server tracker 等。
2. 启动服务线程:balancer,catalog janitor, executor services 等。
3. 在ZooKeeper中设置集群状态为UP
4. 等待Region server登录
5. 如果需要的话,拆分Log, 执行数据恢复
6. 分配meta, namespace和region
7. 处理集群启动或master failover
8. 调用coprocessor
HMaster.finishActiveMasterInitialization方法源代码比较长,下面我们逐步进行分析。
private void finishActiveMasterInitialization(MonitoredTask status)
throws IOException, InterruptedException, KeeperException, CoordinatedStateException {
isActiveMaster = true;
/*
* We are active master now... go initialize components we need to run.
* Note, there may be dross in zk from previous runs; it'll get addressed
* below after we determine if cluster startup or failover.
*/
status.setStatus("Initializing Master file system");
this.masterActiveTime = System.currentTimeMillis();
// TODO: Do this using Dependency Injection, using PicoContainer, Guice or Spring.
this.fileSystemManager = new MasterFileSystem(this, this);
// publish cluster ID
status.setStatus("Publishing Cluster ID in ZooKeeper");
ZKClusterId.setClusterId(this.zooKeeper, fileSystemManager.getClusterId());
this.serverManager = createServerManager(this, this);
synchronized (this) {
if (shortCircuitConnection == null) {
shortCircuitConnection = createShortCircuitConnection();
metaTableLocator = new MetaTableLocator();
}
}
// Invalidate all write locks held previously
this.tableLockManager.reapWriteLocks();
this.tableStateManager = new TableStateManager(this);
this.tableStateManager.start();
status.setStatus("Initializing ZK system trackers");
initializeZKBasedSystemTrackers();
// initialize master side coprocessors before we start handling requests
status.setStatus("Initializing master coprocessors");
this.cpHost = new MasterCoprocessorHost(this, this.conf);
上面代码执行了如下功能:
1. 设置本Master的isActiveMaster标志为true
2. 设置masterActiveTime为当前系统时间
3. 初始化filesystem manager类MasterFileSystem,该类包装了Master与底层文件系统交互时的一些操作,例如Log分割,检查文件系统状态等。初始化时读取配置并设置HBase跟路径,临时路径等,并初始化SplitLogManager
4. 向ZooK