HBase1.0.0版源码分析之HMaster启动代码分析(2)

在介绍的开始,有必要了解一下HMaster的继承体系,如下图:

接下来具体的进行启动流程的分析:1.启动代码logProcessInfo(getConf());//将系统的运行配置参数以及JVM的状态存到日志中CoordinatedStateManager csm =CoordinatedStateManagerFactory.getCoordinatedStateManager(conf);HMaster master = HMaster.constructMaster(masterClass, conf, csm);2.csm对象的构造,该函数中conf.getClass的函数意义比较蛋疼,此处代码表示的意思是我们需要获取一个协同状态管理类,三个参数分别表示:1.自定义的类的名字(用于获取相应的class文件),2.表示默认的HBase的协同管理类ZKCoordinatedStateManager,3.用于验证所获取的class是不是从CoordinatedManager继承的.默认的class是通过zookeeper实现CoordinatedManager对HBase的集群进行管理然后通过反射机制形成类的实例public static CoordinatedStateManager getCoordinatedStateManager(Configuration conf) { Class<? extends CoordinatedStateManager> coordinatedStateMgrKlass =conf.getClass(HConstants.HBASE_COORDINATED_STATE_MANAGER_CLASS,ZkCoordinatedStateManager.class, CoordinatedStateManager.class); return ReflectionUtils.newInstance(coordinatedStateMgrKlass, conf);}3.接下来就是具体的HMaster的对象的构造过程,/** * Utility for constructing an instance of the passed HMaster class. * @param masterClass * @param conf * @return HMaster instance. */public static HMaster constructMaster(Class<? extends HMaster> masterClass,final Configuration conf, final CoordinatedStateManager cp) { try {Constructor<? extends HMaster> c =masterClass.getConstructor(Configuration.class, CoordinatedStateManager.class);return c.newInstance(conf, cp); }这里使用Configuration和CoordinatedStateManager为参数的构造函数进行构造,但是这里为什么需要使用反射??是为了更好的通过传入类型信息增加程序的可拓展性吗,可是如果增加可扩展性的化还是需要修改调用之处的源代码啊?

接下来我们再来看看这个构造函数:先调用父类的构造函数:(photo here for related class diagram)super(conf, csm);进行各种参数变量的赋值操作,这里有几个关键的步骤(1)创建RPC的服务rpcServices = createRpcServices();(2)连接Zookeeper集群// Open connection to zookeeper and set primary watcherzooKeeper = new ZooKeeperWatcher(conf, getProcessName() + ":" +rpcServices.isa.getPort(), this, canCreateBaseZNode());(3)创建文件系统操作实例this.fs = new HFileSystem(this.conf, useHBaseChecksum);(4)初始化CoordinatedStateManager对象this.csm = (BaseCoordinatedStateManager) csm;this.csm.initialize(this);this.csm.start();

(5)创建各种集群跟踪和管理对象masterAddressTracker = new MasterAddressTracker(getZooKeeper(), this);masterAddressTracker.start();clusterStatusTracker = new ClusterStatusTracker(zooKeeper, this);clusterStatusTracker.start();this.configurationManager = new ConfigurationManager();最后启动rpc的服务and ui:rpcServices.start();putUpWebUI()至此,父类HRegion的实例化过程结束,转入到HMaster拓展部分的实例化HMaster的实例化部分比较复杂,这里也就几个关键的步骤进行分析(1)激活一个工作HMasteractiveMasterManager = new ActiveMasterManager(zooKeeper, this.serverName, this);//注册相应的集群观察者ActiveMasterManager(ZooKeeperWatcher watcher, ServerName sn, Server master) { super(watcher); watcher.registerListener(this); this.sn = sn; this.master = master;}(2)启动Jetty服务

int infoPort = putUpJettyServer();2015-03-23 13:40:49,143 INFO [main] http.HttpRequestLog: Http request log for http.requests.master is not defined2015-03-23 13:40:49,366 INFO [main] http.HttpServer: Added global filter 'safety' (class=org.apache.hadoop.hbase.http.HttpServer$QuotingInputFilter)2015-03-23 13:40:49,423 INFO [main] http.HttpServer: Added filter static_user_filter (class=org.apache.hadoop.hbase.http.lib.StaticUserWebFilter$StaticUserFilter) to context master2015-03-23 13:40:49,425 INFO [main] http.HttpServer: Added filter static_user_filter (class=org.apache.hadoop.hbase.http.lib.StaticUserWebFilter$StaticUserFilter) to context static2015-03-23 13:40:49,812 INFO [main] http.HttpServer: Jetty bound to port 16030(3)激活Master,startActiveMasterManager(infoPort);这里面有几个子步骤,在startActiveMasterManager中首先在Zookeeper中添加一个backupZNode,等到变成activeMaster 之后显式删除该节点master.ActiveMasterManager: Deleting ZNode for /hbase/backup-masters/xiaoyi-PC,52777,1427089138770 from backup master directory激活之后,调用finishActiveMasterInitialization(status);完成Master相应的工作线程的启动过程

(4)创建集群链接setupClusterConnection();(5)初始化Zookeeper集群的trackersinitializeZKBasedSystemTrackers();

(6)启动各种工作服务线程

startServiceThreads();// Start the executor service poolsthis.service.startExecutorService(ExecutorType.MASTER_OPEN_REGION,conf.getInt("hbase.master.executor.openregion.threads", 5));this.service.startExecutorService(ExecutorType.MASTER_CLOSE_REGION,conf.getInt("hbase.master.executor.closeregion.threads", 5));this.service.startExecutorService(ExecutorType.MASTER_SERVER_OPERATIONS,conf.getInt("hbase.master.executor.serverops.threads", 5));this.service.startExecutorService(ExecutorType.MASTER_META_SERVER_OPERATIONS,conf.getInt("hbase.master.executor.serverops.threads", 5));this.service.startExecutorService(ExecutorType.M_LOG_REPLAY_OPS,conf.getInt("hbase.master.executor.logreplayops.threads", 10));等待RegionServer的实例加入其管理集群this.serverManager.waitForRegionServers(status);activeMasterManager] master.ServerManager: Waiting for region servers count to settle;当配置数量的regionservers都加入集群之后集群的初始化工作就完成了,接下来的一个重量级组件就是LoadBalancer,其主要负责regions在HRegions之间的分配检查Hbase的meta是否已经分配,最后启动几个后台线程进行相应的监控处理,至此HMaster的初始化工作就完全完成了// Start balancer and meta catalog janitor after meta and regions have// been assigned.status.setStatus("Starting balancer and catalog janitor");this.clusterStatusChore = new ClusterStatusChore(this, balancer);Threads.setDaemonThreadRunning(clusterStatusChore.getThread());this.balancerChore = new BalancerChore(this);Threads.setDaemonThreadRunning(balancerChore.getThread());this.catalogJanitorChore = new CatalogJanitor(this, this);Threads.setDaemonThreadRunning(catalogJanitorChore.getThread());

,今天的长相厮守,只是尽力而为而已。

HBase1.0.0版源码分析之HMaster启动代码分析(2)

相关文章:

你感兴趣的文章:

标签云: