Java Code Examples for org.apache.hadoop.hbase.zookeeper.MetaTableLocator#getMetaRegionLocation()

The following examples show how to use org.apache.hadoop.hbase.zookeeper.MetaTableLocator#getMetaRegionLocation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestMetaTableLocator.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Test waiting on meat w/ no timeout specified.
 */
@Test
public void testNoTimeoutWaitForMeta() throws IOException, InterruptedException, KeeperException {
  ServerName hsa = MetaTableLocator.getMetaRegionLocation(watcher);
  assertNull(hsa);

  // Now test waiting on meta location getting set.
  Thread t = new WaitOnMetaThread();
  startWaitAliveThenWaitItLives(t, 1);
  // Set a meta location.
  MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPEN);
  hsa = SN;
  // Join the thread... should exit shortly.
  t.join();
  // Now meta is available.
  assertTrue(MetaTableLocator.getMetaRegionLocation(watcher).equals(hsa));
}
 
Example 2
Source File: MasterMetaBootstrap.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * For assigning hbase:meta replicas only.
 * TODO: The way this assign runs, nothing but chance to stop all replicas showing up on same
 * server as the hbase:meta region.
 */
void assignMetaReplicas()
    throws IOException, InterruptedException, KeeperException {
  int numReplicas = master.getConfiguration().getInt(HConstants.META_REPLICAS_NUM,
         HConstants.DEFAULT_META_REPLICA_NUM);
  if (numReplicas <= 1) {
    // No replicaas to assign. Return.
    return;
  }
  final AssignmentManager assignmentManager = master.getAssignmentManager();
  if (!assignmentManager.isMetaLoaded()) {
    throw new IllegalStateException("hbase:meta must be initialized first before we can " +
        "assign out its replicas");
  }
  ServerName metaServername = MetaTableLocator.getMetaRegionLocation(this.master.getZooKeeper());
  for (int i = 1; i < numReplicas; i++) {
    // Get current meta state for replica from zk.
    RegionState metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper(), i);
    RegionInfo hri = RegionReplicaUtil.getRegionInfoForReplica(
        RegionInfoBuilder.FIRST_META_REGIONINFO, i);
    LOG.debug(hri.getRegionNameAsString() + " replica region state from zookeeper=" + metaState);
    if (metaServername.equals(metaState.getServerName())) {
      metaState = null;
      LOG.info(hri.getRegionNameAsString() +
        " old location is same as current hbase:meta location; setting location as null...");
    }
    // These assigns run inline. All is blocked till they complete. Only interrupt is shutting
    // down hosting server which calls AM#stop.
    if (metaState != null && metaState.getServerName() != null) {
      // Try to retain old assignment.
      assignmentManager.assignAsync(hri, metaState.getServerName());
    } else {
      assignmentManager.assignAsync(hri);
    }
  }
  unassignExcessMetaReplica(numReplicas);
}
 
Example 3
Source File: MasterRpcServices.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public UnassignRegionResponse unassignRegion(RpcController controller,
    UnassignRegionRequest req) throws ServiceException {
  try {
    final byte [] regionName = req.getRegion().getValue().toByteArray();
    RegionSpecifierType type = req.getRegion().getType();
    final boolean force = req.getForce();
    UnassignRegionResponse urr = UnassignRegionResponse.newBuilder().build();

    master.checkInitialized();
    if (type != RegionSpecifierType.REGION_NAME) {
      LOG.warn("unassignRegion specifier type: expected: " + RegionSpecifierType.REGION_NAME
        + " actual: " + type);
    }
    Pair<RegionInfo, ServerName> pair =
      MetaTableAccessor.getRegion(master.getConnection(), regionName);
    if (Bytes.equals(RegionInfoBuilder.FIRST_META_REGIONINFO.getRegionName(), regionName)) {
      pair = new Pair<>(RegionInfoBuilder.FIRST_META_REGIONINFO,
        MetaTableLocator.getMetaRegionLocation(master.getZooKeeper()));
    }
    if (pair == null) {
      throw new UnknownRegionException(Bytes.toString(regionName));
    }

    RegionInfo hri = pair.getFirst();
    if (master.cpHost != null) {
      master.cpHost.preUnassign(hri, force);
    }
    LOG.debug(master.getClientIdAuditPrefix() + " unassign " + hri.getRegionNameAsString()
        + " in current location if it is online and reassign.force=" + force);
    master.getAssignmentManager().unassign(hri);
    if (master.cpHost != null) {
      master.cpHost.postUnassign(hri, force);
    }

    return urr;
  } catch (IOException ioe) {
    throw new ServiceException(ioe);
  }
}
 
Example 4
Source File: TestRegionServerNoMaster.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static void stopMasterAndAssignMeta(HBaseTestingUtility HTU)
    throws IOException, InterruptedException {
  // Stop master
  HMaster master = HTU.getHBaseCluster().getMaster();
  Thread masterThread = HTU.getHBaseCluster().getMasterThread();
  ServerName masterAddr = master.getServerName();
  master.stopMaster();

  LOG.info("Waiting until master thread exits");
  while (masterThread != null && masterThread.isAlive()) {
    Threads.sleep(100);
  }

  HRegionServer.TEST_SKIP_REPORTING_TRANSITION = true;
  // Master is down, so is the meta. We need to assign it somewhere
  // so that regions can be assigned during the mocking phase.
  HRegionServer hrs = HTU.getHBaseCluster()
    .getLiveRegionServerThreads().get(0).getRegionServer();
  ZKWatcher zkw = hrs.getZooKeeper();
  ServerName sn = MetaTableLocator.getMetaRegionLocation(zkw);
  if (sn != null && !masterAddr.equals(sn)) {
    return;
  }

  ProtobufUtil.openRegion(null, hrs.getRSRpcServices(),
    hrs.getServerName(), RegionInfoBuilder.FIRST_META_REGIONINFO);
  while (true) {
    sn = MetaTableLocator.getMetaRegionLocation(zkw);
    if (sn != null && sn.equals(hrs.getServerName())
        && hrs.getOnlineRegions().containsKey(
          RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedName())) {
      break;
    }
    Thread.sleep(100);
  }
}
 
Example 5
Source File: MasterStatusServlet.java    From hbase with Apache License 2.0 4 votes vote down vote up
private ServerName getMetaLocationOrNull(HMaster master) {
  return MetaTableLocator.getMetaRegionLocation(master.getZooKeeper());
}
 
Example 6
Source File: MetaWithReplicasTestBase.java    From hbase with Apache License 2.0 4 votes vote down vote up
protected static void startCluster() throws Exception {
  TEST_UTIL.getConfiguration().setInt("zookeeper.session.timeout", 30000);
  TEST_UTIL.getConfiguration().setInt(HConstants.META_REPLICAS_NUM, 3);
  TEST_UTIL.getConfiguration()
    .setInt(StorefileRefresherChore.REGIONSERVER_STOREFILE_REFRESH_PERIOD, 1000);
  StartMiniClusterOption option = StartMiniClusterOption.builder().numAlwaysStandByMasters(1)
    .numMasters(1).numRegionServers(REGIONSERVERS_COUNT).build();
  TEST_UTIL.startMiniCluster(option);
  AssignmentManager am = TEST_UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager();
  Set<ServerName> sns = new HashSet<ServerName>();
  ServerName hbaseMetaServerName =
    MetaTableLocator.getMetaRegionLocation(TEST_UTIL.getZooKeeperWatcher());
  LOG.info("HBASE:META DEPLOY: on " + hbaseMetaServerName);
  sns.add(hbaseMetaServerName);
  for (int replicaId = 1; replicaId < 3; replicaId++) {
    RegionInfo h = RegionReplicaUtil
      .getRegionInfoForReplica(RegionInfoBuilder.FIRST_META_REGIONINFO, replicaId);
    AssignmentTestingUtil.waitForAssignment(am, h);
    ServerName sn = am.getRegionStates().getRegionServerOfRegion(h);
    assertNotNull(sn);
    LOG.info("HBASE:META DEPLOY: " + h.getRegionNameAsString() + " on " + sn);
    sns.add(sn);
  }
  // Fun. All meta region replicas have ended up on the one server. This will cause this test
  // to fail ... sometimes.
  if (sns.size() == 1) {
    int count = TEST_UTIL.getMiniHBaseCluster().getLiveRegionServerThreads().size();
    assertTrue("count=" + count, count == REGIONSERVERS_COUNT);
    LOG.warn("All hbase:meta replicas are on the one server; moving hbase:meta: " + sns);
    int metaServerIndex = TEST_UTIL.getHBaseCluster().getServerWithMeta();
    int newServerIndex = metaServerIndex;
    while (newServerIndex == metaServerIndex) {
      newServerIndex = (newServerIndex + 1) % REGIONSERVERS_COUNT;
    }
    assertNotEquals(metaServerIndex, newServerIndex);
    ServerName destinationServerName =
      TEST_UTIL.getHBaseCluster().getRegionServer(newServerIndex).getServerName();
    ServerName metaServerName =
      TEST_UTIL.getHBaseCluster().getRegionServer(metaServerIndex).getServerName();
    assertNotEquals(destinationServerName, metaServerName);
    TEST_UTIL.getAdmin().move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes(),
      destinationServerName);
  }
  // Disable the balancer
  LoadBalancerTracker l =
    new LoadBalancerTracker(TEST_UTIL.getZooKeeperWatcher(), new Abortable() {
      AtomicBoolean aborted = new AtomicBoolean(false);

      @Override
      public boolean isAborted() {
        return aborted.get();
      }

      @Override
      public void abort(String why, Throwable e) {
        aborted.set(true);
      }
    });
  l.setBalancerOn(false);
  LOG.debug("All meta replicas assigned");
}