码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-05-21 09:23:05      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:des   style   c   code   tar   color   

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);
  }

Hbase0.96源代码之HMaster(三)Hmaster主要循环,布布扣,bubuko.com

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

标签:des   style   c   code   tar   color   

原文地址:http://blog.csdn.net/luyee2010/article/details/26420265

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!