Java 类org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer 实例源码

项目:ditb    文件:HMaster.java   
/**
 * If configured to put regions on active master,
 * wait till a backup master becomes active.
 * Otherwise, loop till the server is stopped or aborted.
 */
@Override
protected void waitForMasterActive(){
  boolean tablesOnMaster = BaseLoadBalancer.tablesOnMaster(conf);
  while (!(tablesOnMaster && isActiveMaster)
      && !isStopped() && !isAborted()) {
    sleeper.sleep();
  }
}
项目:ditb    文件:HMaster.java   
@Override
protected void configureInfoServer() {
  infoServer.addServlet("master-status", "/master-status", MasterStatusServlet.class);
  infoServer.setAttribute(MASTER, this);
  if (BaseLoadBalancer.tablesOnMaster(conf)) {
    super.configureInfoServer();
  }
}
项目:pbase    文件:HMaster.java   
/**
 * If configured to put regions on active master,
 * wait till a backup master becomes active.
 * Otherwise, loop till the server is stopped or aborted.
 */
@Override
protected void waitForMasterActive() {
    boolean tablesOnMaster = BaseLoadBalancer.tablesOnMaster(conf);
    while (!(tablesOnMaster && isActiveMaster)
            && !isStopped() && !isAborted()) {
        sleeper.sleep();
    }
}
项目:pbase    文件:HMaster.java   
@Override
protected void configureInfoServer() {
    infoServer.addServlet("master-status", "/master-status", MasterStatusServlet.class);
    infoServer.setAttribute(MASTER, this);
    if (BaseLoadBalancer.tablesOnMaster(conf)) {
        super.configureInfoServer();
    }
}
项目:hbase    文件:TestAsyncMetaRegionLocator.java   
@BeforeClass
public static void setUp() throws Exception {
  TEST_UTIL.getConfiguration().set(BaseLoadBalancer.TABLES_ON_MASTER, "none");
  TEST_UTIL.startMiniCluster(3);
  TEST_UTIL.waitUntilAllSystemRegionsAssigned();
  TEST_UTIL.getAdmin().setBalancerRunning(false, true);
  REGISTRY = AsyncRegistryFactory.getRegistry(TEST_UTIL.getConfiguration());
  LOCATOR = new AsyncMetaRegionLocator(REGISTRY);
}
项目:hbase    文件:TestTableFavoredNodes.java   
@BeforeClass
public static void setupBeforeClass() throws Exception {
  Configuration conf = TEST_UTIL.getConfiguration();
  // Setting FavoredNodeBalancer will enable favored nodes
  conf.setClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS,
      LoadOnlyFavoredStochasticBalancer.class, LoadBalancer.class);
  conf.set(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, "" + SLAVES);

  // This helps test if RS get the appropriate FN updates.
  conf.set(BaseLoadBalancer.TABLES_ON_MASTER, "none");
  TEST_UTIL.startMiniCluster(SLAVES);
  TEST_UTIL.getMiniHBaseCluster().waitForActiveAndReadyMaster(WAIT_TIMEOUT);
}
项目:ditb    文件:HMaster.java   
void move(final byte[] encodedRegionName,
    final byte[] destServerName) throws HBaseIOException {
  RegionState regionState = assignmentManager.getRegionStates().
    getRegionState(Bytes.toString(encodedRegionName));
  if (regionState == null) {
    throw new UnknownRegionException(Bytes.toStringBinary(encodedRegionName));
  }

  HRegionInfo hri = regionState.getRegion();
  ServerName dest;
  if (destServerName == null || destServerName.length == 0) {
    LOG.info("Passed destination servername is null/empty so " +
      "choosing a server at random");
    final List<ServerName> destServers = this.serverManager.createDestinationServersList(
      regionState.getServerName());
    dest = balancer.randomAssignment(hri, destServers);
    if (dest == null) {
      LOG.debug("Unable to determine a plan to assign " + hri);
      return;
    }
  } else {
    dest = ServerName.valueOf(Bytes.toString(destServerName));
    if (dest.equals(serverName) && balancer instanceof BaseLoadBalancer
        && !((BaseLoadBalancer)balancer).shouldBeOnMaster(hri)) {
      // To avoid unnecessary region moving later by balancer. Don't put user
      // regions on master. Regions on master could be put on other region
      // server intentionally by test however.
      LOG.debug("Skipping move of region " + hri.getRegionNameAsString()
        + " to avoid unnecessary region moving later by load balancer,"
        + " because it should not be on master");
      return;
    }
  }

  if (dest.equals(regionState.getServerName())) {
    LOG.debug("Skipping move of region " + hri.getRegionNameAsString()
      + " because region already assigned to the same server " + dest + ".");
    return;
  }

  // Now we can do the move
  RegionPlan rp = new RegionPlan(hri, regionState.getServerName(), dest);

  try {
    checkInitialized();
    if (this.cpHost != null) {
      if (this.cpHost.preMove(hri, rp.getSource(), rp.getDestination())) {
        return;
      }
    }
    // warmup the region on the destination before initiating the move. this call
    // is synchronous and takes some time. doing it before the source region gets
    // closed
    serverManager.sendRegionWarmup(rp.getDestination(), hri);

    LOG.info(getClientIdAuditPrefix() + " move " + rp + ", running balancer");
    this.assignmentManager.balance(rp);
    if (this.cpHost != null) {
      this.cpHost.postMove(hri, rp.getSource(), rp.getDestination());
    }
  } catch (IOException ioe) {
    if (ioe instanceof HBaseIOException) {
      throw (HBaseIOException)ioe;
    }
    throw new HBaseIOException(ioe);
  }
}
项目:pbase    文件:HMaster.java   
void move(final byte[] encodedRegionName,
          final byte[] destServerName) throws HBaseIOException {
    RegionState regionState = assignmentManager.getRegionStates().
            getRegionState(Bytes.toString(encodedRegionName));
    if (regionState == null) {
        throw new UnknownRegionException(Bytes.toStringBinary(encodedRegionName));
    }

    HRegionInfo hri = regionState.getRegion();
    ServerName dest;
    if (destServerName == null || destServerName.length == 0) {
        LOG.info("Passed destination servername is null/empty so " +
                "choosing a server at random");
        final List<ServerName> destServers = this.serverManager.createDestinationServersList(
                regionState.getServerName());
        dest = balancer.randomAssignment(hri, destServers);
        if (dest == null) {
            LOG.debug("Unable to determine a plan to assign " + hri);
            return;
        }
    } else {
        dest = ServerName.valueOf(Bytes.toString(destServerName));
        if (dest.equals(serverName) && balancer instanceof BaseLoadBalancer
                && !((BaseLoadBalancer) balancer).shouldBeOnMaster(hri)) {
            // To avoid unnecessary region moving later by balancer. Don't put user
            // regions on master. Regions on master could be put on other region
            // server intentionally by test however.
            LOG.debug("Skipping move of region " + hri.getRegionNameAsString()
                    + " to avoid unnecessary region moving later by load balancer,"
                    + " because it should not be on master");
            return;
        }
    }

    if (dest.equals(regionState.getServerName())) {
        LOG.debug("Skipping move of region " + hri.getRegionNameAsString()
                + " because region already assigned to the same server " + dest + ".");
        return;
    }

    // Now we can do the move
    RegionPlan rp = new RegionPlan(hri, regionState.getServerName(), dest);

    try {
        checkInitialized();
        if (this.cpHost != null) {
            if (this.cpHost.preMove(hri, rp.getSource(), rp.getDestination())) {
                return;
            }
        }
        LOG.info(getClientIdAuditPrefix() + " move " + rp + ", running balancer");
        this.assignmentManager.balance(rp);
        if (this.cpHost != null) {
            this.cpHost.postMove(hri, rp.getSource(), rp.getDestination());
        }
    } catch (IOException ioe) {
        if (ioe instanceof HBaseIOException) {
            throw (HBaseIOException) ioe;
        }
        throw new HBaseIOException(ioe);
    }
}
项目:hbase    文件:TestSafemodeBringsDownMaster.java   
private static void setupConf(Configuration conf) {
  conf.setInt(MasterProcedureConstants.MASTER_PROCEDURE_THREADS, 1);
  conf.set(BaseLoadBalancer.TABLES_ON_MASTER, "none");
}