Hbase0.96源码之HMaster(三)Hmaster主要循环

1。Master初始化

1.1

 if (!this.stopped) {
    finishInitialization(startupStatus, false);
    loop();
  }

1.2 finishInitialization()。这里主要完毕master组件components:filesystem manager,servermanager,assignmentmanager,regionservertracker, catalogtracker等
1.2.1 设置为active master

isActiveMaster = true;

1.2.2 生成MasterFileSystem(fileSystemManager),管理一些文件系统的操作,包括deleteregion,deletetable,modifyColumn,addColumn,deleteFamilyFromFS以及splitlog,splitMetaLog等
1.2.2.1 check rootdir以及temp文件夹都存在。且清除temp文件夹

 this.oldLogDir = createInitialFileSystemLayout();

1.2.2.1.1clean tempdir

// check if the root directory exists
checkRootDir(this.rootdir, conf, this.fs);

// check if temp directory exists and clean it
checkTempDir(this.tempdir, conf, this.fs);

1.2.2.1.2在checkRootDir()中检測meta的

    // Make sure the meta region directory exists!
    if (!FSUtils.metaRegionExists(fs, rd)) {
      bootstrap(rd, c);
    } else {
      // Migrate table descriptor files if necessary
      org.apache.hadoop.hbase.util.FSTableDescriptorMigrationToSubdir
        .migrateFSTableDescriptorsIfNecessary(fs, rd);
    }

1.2.2.1.2.1 假设meta数据文件夹不存在。创建meta?

private static void bootstrap(final Path rd, final Configuration c)
  throws IOException {
    LOG.info("BOOTSTRAP: creating hbase:meta region");
    try {
      // Bootstrapping, make sure blockcache is off.  Else, one will be
      // created here in bootstrap and it'll need to be cleaned up.  Better to
      // not make it in first place.  Turn off block caching for bootstrap.
      // Enable after.
      HRegionInfo metaHRI = new HRegionInfo(HRegionInfo.FIRST_META_REGIONINFO);
      setInfoFamilyCachingForMeta(false);
      HRegion meta = HRegion.createHRegion(metaHRI, rd, c,
          HTableDescriptor.META_TABLEDESC);
      setInfoFamilyCachingForMeta(true);
      HRegion.closeHRegion(meta);
    } catch (IOException e) {
      e = RemoteExceptionHandler.checkIOException(e);
      LOG.error("bootstrap", e);
      throw e;
    }
  }

1.2.2.2 splitLogManager的创建

this.splitLogManager = new SplitLogManager(master.getZooKeeper(),
      master.getConfiguration(), master, services,
      master.getServerName(), masterRecovery);

1.2.3 创建executorService与serverManager,当中executorService维护一个ExecutorMap,EventType与Executor。提交不正确应的EventHandler来异步处理事件;serverManager管理regionserver

if (!masterRecovery) {
  this.executorService = new ExecutorService(getServerName().toShortString());
  this.serverManager = createServerManager(this, this);
}

1.2.4 initializeZKBasedSystemTrackers
1.2.4.1 create CatalogTracker 监听-ROOT-和.META.的Server地址信息变化以及事件处理
1.2.4.2 LoadBalancerTracker
1.2.4.3 AssignmentManager管理和分配region,监听zk上关于region的event,依据event来完毕region的上下线
1.2.4.4 RegionServerTracker watch zk中中regionSerrver的变化及事件处理。下线
1.2.4.5 DrainingServerTracker
1.2.4.6 SnapshotManager Snapshot快照管理祥光

  void initializeZKBasedSystemTrackers() throws IOException,
      InterruptedException, KeeperException {
    this.catalogTracker = createCatalogTracker(this.zooKeeper, this.conf, this);
    this.catalogTracker.start();

    this.balancer = LoadBalancerFactory.getLoadBalancer(conf);
    this.loadBalancerTracker = new LoadBalancerTracker(zooKeeper, this);
    this.loadBalancerTracker.start();
    this.assignmentManager = new AssignmentManager(this, serverManager,
      this.catalogTracker, this.balancer, this.executorService, this.metricsMaster,
      this.tableLockManager);
    zooKeeper.registerListenerFirst(assignmentManager);

    this.regionServerTracker = new RegionServerTracker(zooKeeper, this,
        this.serverManager);
    this.regionServerTracker.start();

    this.drainingServerTracker = new DrainingServerTracker(zooKeeper, this,
      this.serverManager);
    this.drainingServerTracker.start();

    // Set the cluster as up.  If new RSs, they'll be waiting on this before
    // going ahead with their startup.
    boolean wasUp = this.clusterStatusTracker.isClusterUp();
    if (!wasUp) this.clusterStatusTracker.setClusterUp();

    LOG.info("Server active/primary master=" + this.serverName +
        ", sessionid=0x" +
        Long.toHexString(this.zooKeeper.getRecoverableZooKeeper().getSessionId()) +
        ", setting cluster-up flag (Was=" + wasUp + ")");

    // create the snapshot manager
    this.snapshotManager = new SnapshotManager(this, this.metricsMaster);
  }
posted @ 2019-05-31 10:59  ldxsuanfa  阅读(132)  评论(0编辑  收藏  举报