Search in sources :

Example 1 with ClusterStatusChore

use of org.apache.hadoop.hbase.master.balancer.ClusterStatusChore in project hbase by apache.

the class HMaster method finishActiveMasterInitialization.

/**
   * Finish initialization of HMaster after becoming the primary master.
   *
   * <ol>
   * <li>Initialize master components - file system manager, server manager,
   *     assignment manager, region server tracker, etc</li>
   * <li>Start necessary service threads - balancer, catalog janior,
   *     executor services, etc</li>
   * <li>Set cluster as UP in ZooKeeper</li>
   * <li>Wait for RegionServers to check-in</li>
   * <li>Split logs and perform data recovery, if necessary</li>
   * <li>Ensure assignment of meta/namespace regions<li>
   * <li>Handle either fresh cluster start or master failover</li>
   * </ol>
   */
private void finishActiveMasterInitialization(MonitoredTask status) throws IOException, InterruptedException, KeeperException, CoordinatedStateException {
    activeMaster = true;
    Thread zombieDetector = new Thread(new InitializationMonitor(this), "ActiveMasterInitializationMonitor-" + System.currentTimeMillis());
    zombieDetector.start();
    /*
     * 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.walManager = new MasterWalManager(this);
    // enable table descriptors cache
    this.tableDescriptors.setCacheOn();
    // set the META's descriptor to the correct replication
    this.tableDescriptors.get(TableName.META_TABLE_NAME).setRegionReplication(conf.getInt(HConstants.META_REPLICAS_NUM, HConstants.DEFAULT_META_REPLICA_NUM));
    // warm-up HTDs cache on master initialization
    if (preLoadTableDescriptors) {
        status.setStatus("Pre-loading table descriptors");
        this.tableDescriptors.getAll();
    }
    // publish cluster ID
    status.setStatus("Publishing Cluster ID in ZooKeeper");
    ZKClusterId.setClusterId(this.zooKeeper, fileSystemManager.getClusterId());
    this.initLatch.countDown();
    this.serverManager = createServerManager(this);
    this.tableStateManager = new TableStateManager(this);
    status.setStatus("Initializing ZK system trackers");
    initializeZKBasedSystemTrackers();
    // This is for backwards compatibility
    // See HBASE-11393
    status.setStatus("Update TableCFs node in ZNode");
    TableCFsUpdater tableCFsUpdater = new TableCFsUpdater(zooKeeper, conf, this.clusterConnection);
    tableCFsUpdater.update();
    // initialize master side coprocessors before we start handling requests
    status.setStatus("Initializing master coprocessors");
    this.cpHost = new MasterCoprocessorHost(this, this.conf);
    // start up all service threads.
    status.setStatus("Initializing master service threads");
    startServiceThreads();
    // Wake up this server to check in
    sleeper.skipSleepCycle();
    // Wait for region servers to report in
    status.setStatus("Wait for region servers to report in");
    waitForRegionServers(status);
    // get a list for previously failed RS which need log splitting work
    // we recover hbase:meta region servers inside master initialization and
    // handle other failed servers in SSH in order to start up master node ASAP
    MasterMetaBootstrap metaBootstrap = createMetaBootstrap(this, status);
    metaBootstrap.splitMetaLogsBeforeAssignment();
    this.initializationBeforeMetaAssignment = true;
    if (this.balancer instanceof FavoredNodesPromoter) {
        favoredNodesManager = new FavoredNodesManager(this);
    }
    // Wait for regionserver to finish initialization.
    if (BaseLoadBalancer.tablesOnMaster(conf)) {
        waitForServerOnline();
    }
    //initialize load balancer
    this.balancer.setMasterServices(this);
    this.balancer.setClusterStatus(getClusterStatus());
    this.balancer.initialize();
    // in initializing the regionserver or the balancer.
    if (isStopped())
        return;
    // Make sure meta assigned before proceeding.
    status.setStatus("Assigning Meta Region");
    metaBootstrap.assignMeta();
    // assigned when master is shutting down
    if (isStopped())
        return;
    //Initialize after meta as it scans meta
    if (favoredNodesManager != null) {
        SnapshotOfRegionAssignmentFromMeta snapshotOfRegionAssignment = new SnapshotOfRegionAssignmentFromMeta(getConnection());
        snapshotOfRegionAssignment.initialize();
        favoredNodesManager.initialize(snapshotOfRegionAssignment);
    }
    // and recovery process treat states properly.
    for (Map.Entry<TableName, TableState.State> entry : ZKDataMigrator.queryForTableStates(getZooKeeper()).entrySet()) {
        LOG.info("Converting state from zk to new states:" + entry);
        tableStateManager.setTableState(entry.getKey(), entry.getValue());
    }
    ZKUtil.deleteChildrenRecursively(getZooKeeper(), getZooKeeper().znodePaths.tableZNode);
    status.setStatus("Submitting log splitting work for previously failed region servers");
    metaBootstrap.processDeadServers();
    // Fix up assignment manager status
    status.setStatus("Starting assignment manager");
    this.assignmentManager.joinCluster();
    // set cluster status again after user regions are assigned
    this.balancer.setClusterStatus(getClusterStatus());
    // 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);
    getChoreService().scheduleChore(clusterStatusChore);
    this.balancerChore = new BalancerChore(this);
    getChoreService().scheduleChore(balancerChore);
    this.normalizerChore = new RegionNormalizerChore(this);
    getChoreService().scheduleChore(normalizerChore);
    this.catalogJanitorChore = new CatalogJanitor(this);
    getChoreService().scheduleChore(catalogJanitorChore);
    // Do Metrics periodically
    periodicDoMetricsChore = new PeriodicDoMetrics(msgInterval, this);
    getChoreService().scheduleChore(periodicDoMetricsChore);
    status.setStatus("Starting cluster schema service");
    initClusterSchemaService();
    if (this.cpHost != null) {
        try {
            this.cpHost.preMasterInitialization();
        } catch (IOException e) {
            LOG.error("Coprocessor preMasterInitialization() hook failed", e);
        }
    }
    status.markComplete("Initialization successful");
    LOG.info("Master has completed initialization");
    configurationManager.registerObserver(this.balancer);
    // Set master as 'initialized'.
    setInitialized(true);
    status.setStatus("Assign meta replicas");
    metaBootstrap.assignMetaReplicas();
    status.setStatus("Starting quota manager");
    initQuotaManager();
    // clear the dead servers with same host name and port of online server because we are not
    // removing dead server with same hostname and port of rs which is trying to check in before
    // master initialization. See HBASE-5916.
    this.serverManager.clearDeadServersWithSameHostNameAndPortOfOnlineServer();
    // Check and set the znode ACLs if needed in case we are overtaking a non-secure configuration
    status.setStatus("Checking ZNode ACLs");
    zooKeeper.checkAndSetZNodeAcls();
    status.setStatus("Initializing MOB Cleaner");
    initMobCleaner();
    status.setStatus("Calling postStartMaster coprocessors");
    if (this.cpHost != null) {
        // don't let cp initialization errors kill the master
        try {
            this.cpHost.postStartMaster();
        } catch (IOException ioe) {
            LOG.error("Coprocessor postStartMaster() hook failed", ioe);
        }
    }
    zombieDetector.interrupt();
}
Also used : FavoredNodesPromoter(org.apache.hadoop.hbase.favored.FavoredNodesPromoter) BalancerChore(org.apache.hadoop.hbase.master.balancer.BalancerChore) FavoredNodesManager(org.apache.hadoop.hbase.favored.FavoredNodesManager) ClusterStatusChore(org.apache.hadoop.hbase.master.balancer.ClusterStatusChore) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) HasThread(org.apache.hadoop.hbase.util.HasThread) RegionNormalizerChore(org.apache.hadoop.hbase.master.normalizer.RegionNormalizerChore) TableName(org.apache.hadoop.hbase.TableName) TableCFsUpdater(org.apache.hadoop.hbase.replication.master.TableCFsUpdater) CompactionState(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoResponse.CompactionState) TableState(org.apache.hadoop.hbase.client.TableState) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)1 TableName (org.apache.hadoop.hbase.TableName)1 TableState (org.apache.hadoop.hbase.client.TableState)1 FavoredNodesManager (org.apache.hadoop.hbase.favored.FavoredNodesManager)1 FavoredNodesPromoter (org.apache.hadoop.hbase.favored.FavoredNodesPromoter)1 BalancerChore (org.apache.hadoop.hbase.master.balancer.BalancerChore)1 ClusterStatusChore (org.apache.hadoop.hbase.master.balancer.ClusterStatusChore)1 RegionNormalizerChore (org.apache.hadoop.hbase.master.normalizer.RegionNormalizerChore)1 TableCFsUpdater (org.apache.hadoop.hbase.replication.master.TableCFsUpdater)1 CompactionState (org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoResponse.CompactionState)1 HasThread (org.apache.hadoop.hbase.util.HasThread)1