org.apache.hadoop.hbase.zookeeper.MetaTableLocator Java Examples

The following examples show how to use org.apache.hadoop.hbase.zookeeper.MetaTableLocator. 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: HBaseClientCompatibilityTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
/**
 * Ensure Armeria's dependencies do not cause a trouble with hbase-shaded-client.
 *
 * @see <a href="https://issues.apache.org/jira/browse/HBASE-14963">HBASE-14963</a>
 */
@Test(expected = NotAllMetaRegionsOnlineException.class)
public void testGuavaConflict() throws Exception {
    // Make sure Armeria is available in the class path.
    assertThat(Version.getAll(Server.class.getClassLoader())).isNotNull();
    // Make sure newer Guava is available in the class path.
    assertThat(Stopwatch.class.getDeclaredConstructor().getModifiers()).is(new Condition<>(
            value -> !Modifier.isPublic(value),
            "Recent Guava Stopwatch should have non-public default constructor."));

    final MetaTableLocator locator = new MetaTableLocator();
    final ZooKeeperWatcher zkw = mock(ZooKeeperWatcher.class);
    final RecoverableZooKeeper zk = mock(RecoverableZooKeeper.class);
    when(zkw.getRecoverableZooKeeper()).thenReturn(zk);
    when(zk.exists(any(), any())).thenReturn(new Stat(0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0));

    locator.waitMetaRegionLocation(zkw, 100);
}
 
Example #2
Source File: MasterMetaBootstrap.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void unassignExcessMetaReplica(int numMetaReplicasConfigured) {
  final ZKWatcher zooKeeper = master.getZooKeeper();
  // unassign the unneeded replicas (for e.g., if the previous master was configured
  // with a replication of 3 and now it is 2, we need to unassign the 1 unneeded replica)
  try {
    List<String> metaReplicaZnodes = zooKeeper.getMetaReplicaNodes();
    for (String metaReplicaZnode : metaReplicaZnodes) {
      int replicaId = zooKeeper.getZNodePaths().getMetaReplicaIdFromZnode(metaReplicaZnode);
      if (replicaId >= numMetaReplicasConfigured) {
        RegionState r = MetaTableLocator.getMetaRegionState(zooKeeper, replicaId);
        LOG.info("Closing excess replica of meta region " + r.getRegion());
        // send a close and wait for a max of 30 seconds
        ServerManager.closeRegionSilentlyAndWait(master.getAsyncClusterConnection(),
            r.getServerName(), r.getRegion(), 30000);
        ZKUtil.deleteNode(zooKeeper, zooKeeper.getZNodePaths().getZNodeForReplica(replicaId));
      }
    }
  } catch (Exception ex) {
    // ignore the exception since we don't want the master to be wedged due to potential
    // issues in the cleanup of the extra regions. We can do that cleanup via hbck or manually
    LOG.warn("Ignoring exception " + ex);
  }
}
 
Example #3
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 #4
Source File: RegionStateStore.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void updateMetaLocation(RegionInfo regionInfo, ServerName serverName, State state)
    throws IOException {
  try {
    MetaTableLocator.setMetaLocation(master.getZooKeeper(), serverName, regionInfo.getReplicaId(),
      state);
  } catch (KeeperException e) {
    throw new IOException(e);
  }
}
 
Example #5
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 #6
Source File: TestMetaRegionLocationCache.java    From hbase with Apache License 2.0 5 votes vote down vote up
private List<HRegionLocation> getCurrentMetaLocations(ZKWatcher zk) throws Exception {
  List<HRegionLocation> result = new ArrayList<>();
  for (String znode: zk.getMetaReplicaNodes()) {
    String path = ZNodePaths.joinZNode(zk.getZNodePaths().baseZNode, znode);
    int replicaId = zk.getZNodePaths().getMetaReplicaIdFromPath(path);
    RegionState state = MetaTableLocator.getMetaRegionState(zk, replicaId);
    result.add(new HRegionLocation(state.getRegion(), state.getServerName()));
  }
  return result;
}
 
Example #7
Source File: TestMetaTableLocator.java    From hbase with Apache License 2.0 5 votes vote down vote up
void doWaiting() throws InterruptedException {
  try {
    for (;;) {
      if (MetaTableLocator.waitMetaRegionLocation(watcher, 10000) != null) {
        break;
      }
    }
  } catch (NotAllMetaRegionsOnlineException e) {
    // Ignore
  }
}
 
Example #8
Source File: TestMetaTableLocator.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Test normal operations
 */
@Test
public void testMetaLookup()
    throws IOException, InterruptedException, ServiceException, KeeperException {
  final ClientProtos.ClientService.BlockingInterface client =
    Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);

  Mockito.when(client.get((RpcController) Mockito.any(), (GetRequest) Mockito.any()))
    .thenReturn(GetResponse.newBuilder().build());

  assertNull(MetaTableLocator.getMetaRegionLocation(this.watcher));
  for (RegionState.State state : RegionState.State.values()) {
    if (state.equals(RegionState.State.OPEN)) {
      continue;
    }
    MetaTableLocator.setMetaLocation(this.watcher, SN, state);
    assertNull(MetaTableLocator.getMetaRegionLocation(this.watcher));
    assertEquals(state, MetaTableLocator.getMetaRegionState(this.watcher).getState());
  }
  MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPEN);
  assertEquals(SN, MetaTableLocator.getMetaRegionLocation(this.watcher));
  assertEquals(RegionState.State.OPEN,
    MetaTableLocator.getMetaRegionState(this.watcher).getState());

  MetaTableLocator.deleteMetaLocation(this.watcher);
  assertNull(MetaTableLocator.getMetaRegionState(this.watcher).getServerName());
  assertEquals(RegionState.State.OFFLINE,
    MetaTableLocator.getMetaRegionState(this.watcher).getState());
  assertNull(MetaTableLocator.getMetaRegionLocation(this.watcher));
}
 
Example #9
Source File: TestMetaTableLocator.java    From hbase with Apache License 2.0 5 votes vote down vote up
@After
public void after() {
  try {
    // Clean out meta location or later tests will be confused... they presume
    // start fresh in zk.
    MetaTableLocator.deleteMetaLocation(this.watcher);
  } catch (KeeperException e) {
    LOG.warn("Unable to delete hbase:meta location", e);
  }

  this.watcher.close();
}
 
Example #10
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 #11
Source File: ProcedureSyncWait.java    From hbase with Apache License 2.0 5 votes vote down vote up
protected static void waitMetaRegions(final MasterProcedureEnv env) throws IOException {
  int timeout = env.getMasterConfiguration().getInt("hbase.client.catalog.timeout", 10000);
  try {
    if (MetaTableLocator.waitMetaRegionLocation(env.getMasterServices().getZooKeeper(),
      timeout) == null) {
      throw new NotAllMetaRegionsOnlineException();
    }
  } catch (InterruptedException e) {
    throw (InterruptedIOException) new InterruptedIOException().initCause(e);
  }
}
 
Example #12
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 #13
Source File: AssignmentManager.java    From hbase with Apache License 2.0 5 votes vote down vote up
public void start() throws IOException, KeeperException {
  if (!running.compareAndSet(false, true)) {
    return;
  }

  LOG.trace("Starting assignment manager");

  // Start the Assignment Thread
  startAssignmentThread();

  // load meta region state
  ZKWatcher zkw = master.getZooKeeper();
  // it could be null in some tests
  if (zkw != null) {
    // here we are still in the early steps of active master startup. There is only one thread(us)
    // can access AssignmentManager and create region node, so here we do not need to lock the
    // region node.
    RegionState regionState = MetaTableLocator.getMetaRegionState(zkw);
    RegionStateNode regionNode =
      regionStates.getOrCreateRegionStateNode(RegionInfoBuilder.FIRST_META_REGIONINFO);
    regionNode.setRegionLocation(regionState.getServerName());
    regionNode.setState(regionState.getState());
    if (regionNode.getProcedure() != null) {
      regionNode.getProcedure().stateLoaded(this, regionNode);
    }
    if (regionState.getServerName() != null) {
      regionStates.addRegionToServer(regionNode);
    }
    setMetaAssigned(regionState.getRegion(), regionState.getState() == State.OPEN);
  }
}
 
Example #14
Source File: TestMetaTableAccessor.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetRegionsFromMetaTable() throws IOException, InterruptedException {
  List<RegionInfo> regions = MetaTableLocator.getMetaRegions(UTIL.getZooKeeperWatcher());
  assertTrue(regions.size() >= 1);
  assertTrue(MetaTableLocator.getMetaRegionsAndLocations(UTIL.getZooKeeperWatcher()).size() >= 1);
}
 
Example #15
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 #16
Source File: TestMetaTableLocator.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test(expected = NotAllMetaRegionsOnlineException.class)
public void testTimeoutWaitForMeta() throws IOException, InterruptedException {
  MetaTableLocator.waitMetaRegionLocation(watcher, 100);
}
 
Example #17
Source File: MasterSnapshotVerifier.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Check that all the regions in the snapshot are valid, and accounted for.
 * @param manifest snapshot manifest to inspect
 * @throws IOException if we can't reach hbase:meta or read the files from the FS
 */
private void verifyRegions(final SnapshotManifest manifest) throws IOException {
  List<RegionInfo> regions;
  if (TableName.META_TABLE_NAME.equals(tableName)) {
    regions = MetaTableLocator.getMetaRegions(services.getZooKeeper());
  } else {
    regions = MetaTableAccessor.getTableRegions(services.getConnection(), tableName);
  }
  // Remove the non-default regions
  RegionReplicaUtil.removeNonDefaultRegions(regions);

  Map<String, SnapshotRegionManifest> regionManifests = manifest.getRegionManifestsMap();
  if (regionManifests == null) {
    String msg = "Snapshot " + ClientSnapshotDescriptionUtils.toString(snapshot) + " looks empty";
    LOG.error(msg);
    throw new CorruptedSnapshotException(msg);
  }

  String errorMsg = "";
  boolean hasMobStore = false;
  // the mob region is a dummy region, it's not a real region in HBase.
  // the mob region has a special name, it could be found by the region name.
  if (regionManifests.get(MobUtils.getMobRegionInfo(tableName).getEncodedName()) != null) {
    hasMobStore = true;
  }
  int realRegionCount = hasMobStore ? regionManifests.size() - 1 : regionManifests.size();
  if (realRegionCount != regions.size()) {
    errorMsg = "Regions moved during the snapshot '" +
                 ClientSnapshotDescriptionUtils.toString(snapshot) + "'. expected=" +
                 regions.size() + " snapshotted=" + realRegionCount + ".";
    LOG.error(errorMsg);
  }

  // Verify RegionInfo
  for (RegionInfo region : regions) {
    SnapshotRegionManifest regionManifest = regionManifests.get(region.getEncodedName());
    if (regionManifest == null) {
      // could happen due to a move or split race.
      String mesg = " No snapshot region directory found for region:" + region;
      if (errorMsg.isEmpty()) errorMsg = mesg;
      LOG.error(mesg);
      continue;
    }

    verifyRegionInfo(region, regionManifest);
  }

  if (!errorMsg.isEmpty()) {
    throw new CorruptedSnapshotException(errorMsg);
  }

  // Verify Snapshot HFiles
  // Requires the root directory file system as HFiles are stored in the root directory
  SnapshotReferenceUtil.verifySnapshot(services.getConfiguration(),
    CommonFSUtils.getRootDirFileSystem(services.getConfiguration()), manifest);
}
 
Example #18
Source File: TestMetaRegionLocationCache.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Tests MetaRegionLocationCache's init procedure to make sure that it correctly watches the base
 * znode for notifications.
 */
@Test public void testMetaRegionLocationCache() throws Exception {
  final String parentZnodeName = "/randomznodename";
  Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
  conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, parentZnodeName);
  ServerName sn = ServerName.valueOf("localhost", 1234, 5678);
  try (ZKWatcher zkWatcher = new ZKWatcher(conf, null, null, true)) {
    // A thread that repeatedly creates and drops an unrelated child znode. This is to simulate
    // some ZK activity in the background.
    MultithreadedTestUtil.TestContext ctx = new MultithreadedTestUtil.TestContext(conf);
    ctx.addThread(new MultithreadedTestUtil.RepeatingTestThread(ctx) {
      @Override public void doAnAction() throws Exception {
        final String testZnode = parentZnodeName + "/child";
        ZKUtil.createNodeIfNotExistsAndWatch(zkWatcher, testZnode, testZnode.getBytes());
        ZKUtil.deleteNode(zkWatcher, testZnode);
      }
    });
    ctx.startThreads();
    try {
      MetaRegionLocationCache metaCache = new MetaRegionLocationCache(zkWatcher);
      // meta znodes do not exist at this point, cache should be empty.
      assertFalse(metaCache.getMetaRegionLocations().isPresent());
      // Set the meta locations for a random meta replicas, simulating an active hmaster meta
      // assignment.
      for (int i = 0; i < 3; i++) {
        // Updates the meta znodes.
        MetaTableLocator.setMetaLocation(zkWatcher, sn, i, RegionState.State.OPEN);
      }
      // Wait until the meta cache is populated.
      int iters = 0;
      while (iters++ < 10) {
        if (metaCache.getMetaRegionLocations().isPresent()
          && metaCache.getMetaRegionLocations().get().size() == 3) {
          break;
        }
        Thread.sleep(1000);
      }
      List<HRegionLocation> metaLocations = metaCache.getMetaRegionLocations().get();
      assertEquals(3, metaLocations.size());
      for (HRegionLocation location : metaLocations) {
        assertEquals(sn, location.getServerName());
      }
    } finally {
      // clean up.
      ctx.stop();
      ZKUtil.deleteChildrenRecursively(zkWatcher, parentZnodeName);
    }
  }
}
 
Example #19
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");
}
 
Example #20
Source File: TestMetaShutdownHandler.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * This test will test the expire handling of a meta-carrying
 * region server.
 * After HBaseMiniCluster is up, we will delete the ephemeral
 * node of the meta-carrying region server, which will trigger
 * the expire of this region server on the master.
 * On the other hand, we will slow down the abort process on
 * the region server so that it is still up during the master SSH.
 * We will check that the master SSH is still successfully done.
 */
@Test
public void testExpireMetaRegionServer() throws Exception {
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  HMaster master = cluster.getMaster();
  RegionStates regionStates = master.getAssignmentManager().getRegionStates();
  ServerName metaServerName =
    regionStates.getRegionServerOfRegion(RegionInfoBuilder.FIRST_META_REGIONINFO);
  if (master.getServerName().equals(metaServerName) || metaServerName == null ||
    !metaServerName.equals(cluster.getServerHoldingMeta())) {
    // Move meta off master
    metaServerName =
      cluster.getLiveRegionServerThreads().get(0).getRegionServer().getServerName();
    master.move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes(),
      Bytes.toBytes(metaServerName.getServerName()));
    TEST_UTIL.waitUntilNoRegionsInTransition(60000);
    metaServerName =
      regionStates.getRegionServerOfRegion(RegionInfoBuilder.FIRST_META_REGIONINFO);
  }
  RegionState metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper());
  assertEquals("Wrong state for meta!", RegionState.State.OPEN, metaState.getState());
  assertNotEquals("Meta is on master!", metaServerName, master.getServerName());

  // Delete the ephemeral node of the meta-carrying region server.
  // This is trigger the expire of this region server on the master.
  String rsEphemeralNodePath =
      ZNodePaths.joinZNode(master.getZooKeeper().getZNodePaths().rsZNode,
              metaServerName.toString());
  ZKUtil.deleteNode(master.getZooKeeper(), rsEphemeralNodePath);
  LOG.info("Deleted the znode for the RegionServer hosting hbase:meta; waiting on SSH");
  // Wait for SSH to finish
  final ServerManager serverManager = master.getServerManager();
  final ServerName priorMetaServerName = metaServerName;
  TEST_UTIL.waitFor(120000, 200, new Waiter.Predicate<Exception>() {
    @Override
    public boolean evaluate() throws Exception {
      return !serverManager.isServerOnline(priorMetaServerName)
          && !serverManager.areDeadServersInProgress();
    }
  });
  LOG.info("Past wait on RIT");
  TEST_UTIL.waitUntilNoRegionsInTransition(60000);
  // Now, make sure meta is assigned
  assertTrue("Meta should be assigned",
    regionStates.isRegionOnline(RegionInfoBuilder.FIRST_META_REGIONINFO));
  // Now, make sure meta is registered in zk
  metaState = MetaTableLocator.getMetaRegionState(master.getZooKeeper());
  assertEquals("Meta should not be in transition", RegionState.State.OPEN, metaState.getState());
  assertEquals("Meta should be assigned", metaState.getServerName(),
    regionStates.getRegionServerOfRegion(RegionInfoBuilder.FIRST_META_REGIONINFO));
  assertNotEquals("Meta should be assigned on a different server", metaState.getServerName(),
    metaServerName);
}
 
Example #21
Source File: TestMasterFailover.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Test meta in transition when master failover.
 * This test used to manipulate region state up in zk. That is not allowed any more in hbase2
 * so I removed that messing. That makes this test anemic.
 */
@Test
public void testMetaInTransitionWhenMasterFailover() throws Exception {
  // Start the cluster
  HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
  TEST_UTIL.startMiniCluster();
  try {
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    LOG.info("Cluster started");

    HMaster activeMaster = cluster.getMaster();
    ServerName metaServerName = cluster.getServerHoldingMeta();
    HRegionServer hrs = cluster.getRegionServer(metaServerName);

    // Now kill master, meta should remain on rs, where we placed it before.
    LOG.info("Aborting master");
    activeMaster.abort("test-kill");
    cluster.waitForMasterToStop(activeMaster.getServerName(), 30000);
    LOG.info("Master has aborted");

    // meta should remain where it was
    RegionState metaState = MetaTableLocator.getMetaRegionState(hrs.getZooKeeper());
    assertEquals("hbase:meta should be online on RS",
        metaState.getServerName(), metaServerName);
    assertEquals("hbase:meta should be online on RS", State.OPEN, metaState.getState());

    // Start up a new master
    LOG.info("Starting up a new master");
    activeMaster = cluster.startMaster().getMaster();
    LOG.info("Waiting for master to be ready");
    cluster.waitForActiveAndReadyMaster();
    LOG.info("Master is ready");

    // ensure meta is still deployed on RS
    metaState = MetaTableLocator.getMetaRegionState(activeMaster.getZooKeeper());
    assertEquals("hbase:meta should be online on RS",
        metaState.getServerName(), metaServerName);
    assertEquals("hbase:meta should be online on RS", State.OPEN, metaState.getState());

    // Done, shutdown the cluster
  } finally {
    TEST_UTIL.shutdownMiniCluster();
  }
}
 
Example #22
Source File: BaseHRegionServer.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
public MetaTableLocator getMetaTableLocator() {
    throw new UnsupportedOperationException("Not implemented");
}