Java Code Examples for org.apache.hadoop.hbase.regionserver.HRegionServer#getServerName()

The following examples show how to use org.apache.hadoop.hbase.regionserver.HRegionServer#getServerName() . 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: ClientPushbackTestBase.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testMutateRowStats() throws IOException {
  HRegionServer rs = UTIL.getHBaseCluster().getRegionServer(0);
  Region region = rs.getRegions(tableName).get(0);

  RowMutations mutations = new RowMutations(Bytes.toBytes("row"));
  Put p = new Put(Bytes.toBytes("row"));
  p.addColumn(family, qualifier, Bytes.toBytes("value2"));
  mutations.add(p);
  mutateRow(mutations);

  ServerStatisticTracker stats = getStatisticsTracker();
  assertNotNull("No stats configured for the client!", stats);
  // get the names so we can query the stats
  ServerName server = rs.getServerName();
  byte[] regionName = region.getRegionInfo().getRegionName();

  // check to see we found some load on the memstore
  ServerStatistics serverStats = stats.getStats(server);
  ServerStatistics.RegionStatistics regionStats = serverStats.getStatsForRegion(regionName);

  assertNotNull(regionStats);
  assertTrue(regionStats.getMemStoreLoadPercent() > 0);
}
 
Example 2
Source File: TestHbck.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testScheduleSCP() throws Exception {
  HRegionServer testRs = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME);
  TEST_UTIL.loadTable(TEST_UTIL.getConnection().getTable(TABLE_NAME), Bytes.toBytes("family1"),
    true);
  ServerName serverName = testRs.getServerName();
  Hbck hbck = getHbck();
  List<Long> pids =
    hbck.scheduleServerCrashProcedure(Arrays.asList(ProtobufUtil.toServerName(serverName)));
  assertTrue(pids.get(0) > 0);
  LOG.info("pid is {}", pids.get(0));

  List<Long> newPids =
    hbck.scheduleServerCrashProcedure(Arrays.asList(ProtobufUtil.toServerName(serverName)));
  assertTrue(newPids.get(0) < 0);
  LOG.info("pid is {}", newPids.get(0));
  waitOnPids(pids);
}
 
Example 3
Source File: TestAsyncRegionAdminApi.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testMoveRegion() throws Exception {
  admin.balancerSwitch(false).join();

  RegionInfo hri = createTableAndGetOneRegion(tableName);
  RawAsyncHBaseAdmin rawAdmin = (RawAsyncHBaseAdmin) ASYNC_CONN.getAdmin();
  ServerName serverName = rawAdmin.getRegionLocation(hri.getRegionName()).get().getServerName();

  HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
  ServerManager serverManager = master.getServerManager();
  ServerName destServerName = null;
  List<JVMClusterUtil.RegionServerThread> regionServers =
      TEST_UTIL.getHBaseCluster().getLiveRegionServerThreads();
  for (JVMClusterUtil.RegionServerThread regionServer : regionServers) {
    HRegionServer destServer = regionServer.getRegionServer();
    destServerName = destServer.getServerName();
    if (!destServerName.equals(serverName) && serverManager.isServerOnline(destServerName)) {
      break;
    }
  }

  assertTrue(destServerName != null && !destServerName.equals(serverName));
  admin.move(hri.getRegionName(), destServerName).get();

  long timeoutTime = System.currentTimeMillis() + 30000;
  while (true) {
    ServerName sn = rawAdmin.getRegionLocation(hri.getRegionName()).get().getServerName();
    if (sn != null && sn.equals(destServerName)) {
      break;
    }
    long now = System.currentTimeMillis();
    if (now > timeoutTime) {
      fail("Failed to move the region in time: " + hri);
    }
    Thread.sleep(100);
  }
  admin.balancerSwitch(true).join();
}
 
Example 4
Source File: TestSplitWALProcedure.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testMasterRestart() throws Exception {
  Table table = TEST_UTIL.createTable(TABLE_NAME, FAMILY, TEST_UTIL.KEYS_FOR_HBA_CREATE_TABLE);
  for (int i = 0; i < 10; i++) {
    TEST_UTIL.loadTable(table, FAMILY);
  }
  HRegionServer testServer = TEST_UTIL.getHBaseCluster().getRegionServer(0);
  List<FileStatus> wals = splitWALManager.getWALsToSplit(testServer.getServerName(), false);
  Assert.assertEquals(1, wals.size());
  SplitWALProcedure splitWALProcedure =
      new SplitWALProcedure(wals.get(0).getPath().toString(), testServer.getServerName());
  long pid = ProcedureTestingUtility.submitProcedure(master.getMasterProcedureExecutor(),
      splitWALProcedure, HConstants.NO_NONCE, HConstants.NO_NONCE);
  TEST_UTIL.waitFor(5000, () -> splitWALProcedure.getWorker() != null);
  // Kill master
  TEST_UTIL.getHBaseCluster().killMaster(master.getServerName());
  TEST_UTIL.getHBaseCluster().waitForMasterToStop(master.getServerName(), 20000);
  // restart master
  TEST_UTIL.getHBaseCluster().startMaster();
  TEST_UTIL.getHBaseCluster().waitForActiveAndReadyMaster();
  this.master = TEST_UTIL.getHBaseCluster().getMaster();
  ProcedureTestingUtility.waitProcedure(master.getMasterProcedureExecutor(), pid);
  Optional<Procedure<?>> procedure =
      master.getProcedures().stream().filter(p -> p.getProcId() == pid).findAny();
  // make sure procedure is successful and wal is deleted
  Assert.assertTrue(procedure.isPresent());
  Assert.assertTrue(procedure.get().isSuccess());
  Assert.assertFalse(TEST_UTIL.getTestFileSystem().exists(wals.get(0).getPath()));
}
 
Example 5
Source File: TestFromClientSide5.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Tests the non cached version of getRegionLocator by moving a region.
 */
@Test
public void testNonCachedGetRegionLocation() throws Exception {
  // Test Initialization.
  final TableName tableName = name.getTableName();
  byte [] family1 = Bytes.toBytes("f1");
  byte [] family2 = Bytes.toBytes("f2");
  try (Table ignored = TEST_UTIL.createTable(tableName, new byte[][] {family1, family2}, 10);
      Admin admin = TEST_UTIL.getAdmin();
      RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName)) {
    List<HRegionLocation> allRegionLocations = locator.getAllRegionLocations();
    assertEquals(1, allRegionLocations.size());
    RegionInfo regionInfo = allRegionLocations.get(0).getRegion();
    ServerName addrBefore = allRegionLocations.get(0).getServerName();
    // Verify region location before move.
    HRegionLocation addrCache = locator.getRegionLocation(regionInfo.getStartKey(), false);
    HRegionLocation addrNoCache = locator.getRegionLocation(regionInfo.getStartKey(),  true);

    assertEquals(addrBefore.getPort(), addrCache.getPort());
    assertEquals(addrBefore.getPort(), addrNoCache.getPort());


    // Make sure more than one server.
    if (TEST_UTIL.getMiniHBaseCluster().getLiveRegionServerThreads().size() <= 1) {
      TEST_UTIL.getMiniHBaseCluster().startRegionServer();
      Waiter.waitFor(TEST_UTIL.getConfiguration(), 30000, new Waiter.Predicate<Exception>() {
        @Override public boolean evaluate() throws Exception {
          return TEST_UTIL.getMiniHBaseCluster().getLiveRegionServerThreads().size() > 1;
        }
      });
    }

    ServerName addrAfter = null;
    // Now move the region to a different server.
    for (int i = 0; i < TEST_UTIL.getMiniHBaseCluster().getLiveRegionServerThreads().size();
         i++) {
      HRegionServer regionServer = TEST_UTIL.getHBaseCluster().getRegionServer(i);
      ServerName addr = regionServer.getServerName();
      if (addr.getPort() != addrBefore.getPort()) {
        admin.move(regionInfo.getEncodedNameAsBytes(), addr);
        // Wait for the region to move.
        Thread.sleep(5000);
        addrAfter = addr;
        break;
      }
    }

    // Verify the region was moved.
    addrCache = locator.getRegionLocation(regionInfo.getStartKey(), false);
    addrNoCache = locator.getRegionLocation(regionInfo.getStartKey(), true);
    assertNotNull(addrAfter);
    assertTrue(addrAfter.getPort() != addrCache.getPort());
    assertEquals(addrAfter.getPort(), addrNoCache.getPort());
  }
}
 
Example 6
Source File: ClientPushbackTestBase.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testClientTracksServerPushback() throws Exception {
  HRegionServer rs = UTIL.getHBaseCluster().getRegionServer(0);
  Region region = rs.getRegions(tableName).get(0);

  LOG.debug("Writing some data to " + tableName);
  // write some data
  Put p = new Put(Bytes.toBytes("row"));
  p.addColumn(family, qualifier, Bytes.toBytes("value1"));
  mutate(p);

  // get the current load on RS. Hopefully memstore isn't flushed since we wrote the the data
  int load = (int) ((region.getMemStoreHeapSize() * 100) / flushSizeBytes);
  LOG.debug("Done writing some data to " + tableName);

  // get the stats for the region hosting our table
  ClientBackoffPolicy backoffPolicy = getBackoffPolicy();
  assertTrue("Backoff policy is not correctly configured",
    backoffPolicy instanceof ExponentialClientBackoffPolicy);

  ServerStatisticTracker stats = getStatisticsTracker();
  assertNotNull("No stats configured for the client!", stats);
  // get the names so we can query the stats
  ServerName server = rs.getServerName();
  byte[] regionName = region.getRegionInfo().getRegionName();

  // check to see we found some load on the memstore
  ServerStatistics serverStats = stats.getStats(server);
  ServerStatistics.RegionStatistics regionStats = serverStats.getStatsForRegion(regionName);
  assertEquals("We did not find some load on the memstore", load,
    regionStats.getMemStoreLoadPercent());
  // check that the load reported produces a nonzero delay
  long backoffTime = backoffPolicy.getBackoffTime(server, regionName, serverStats);
  assertNotEquals("Reported load does not produce a backoff", 0, backoffTime);
  LOG.debug("Backoff calculated for " + region.getRegionInfo().getRegionNameAsString() + " @ " +
    server + " is " + backoffTime);

  CountDownLatch latch = new CountDownLatch(1);
  AtomicLong endTime = new AtomicLong();
  long startTime = EnvironmentEdgeManager.currentTime();
  mutate(p, endTime, latch);
  // Currently the ExponentialClientBackoffPolicy under these test conditions
  // produces a backoffTime of 151 milliseconds. This is long enough so the
  // wait and related checks below are reasonable. Revisit if the backoff
  // time reported by above debug logging has significantly deviated.
  MetricsConnection metrics = getConnectionMetrics();
  String name = server.getServerName() + "," + Bytes.toStringBinary(regionName);
  MetricsConnection.RegionStats rsStats = metrics.serverStats.get(server).get(regionName);
  assertEquals(name, rsStats.name);
  assertEquals(rsStats.heapOccupancyHist.getSnapshot().getMean(),
    (double) regionStats.getHeapOccupancyPercent(), 0.1);
  assertEquals(rsStats.memstoreLoadHist.getSnapshot().getMean(),
    (double) regionStats.getMemStoreLoadPercent(), 0.1);

  MetricsConnection.RunnerStats runnerStats = metrics.runnerStats;

  assertEquals(1, runnerStats.delayRunners.getCount());
  assertEquals(1, runnerStats.normalRunners.getCount());
  assertEquals("", runnerStats.delayIntevalHist.getSnapshot().getMean(), (double) backoffTime,
    0.1);

  latch.await(backoffTime * 2, TimeUnit.MILLISECONDS);
  assertNotEquals("AsyncProcess did not submit the work time", 0, endTime.get());
  assertTrue("AsyncProcess did not delay long enough", endTime.get() - startTime >= backoffTime);
}
 
Example 7
Source File: TestClusterRestartFailover.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * Test for HBASE-22964
 */
@Test
public void test() throws Exception {
  setupCluster();
  setupTable();

  // Find server that does not have hbase:namespace on it. This tests holds up SCPs. If it
  // holds up the server w/ hbase:namespace, the Master initialization will be held up
  // because this table is not online and test fails.
  for (JVMClusterUtil.RegionServerThread rst:
      UTIL.getHBaseCluster().getLiveRegionServerThreads()) {
    HRegionServer rs = rst.getRegionServer();
    if (rs.getRegions(TableName.NAMESPACE_TABLE_NAME).isEmpty()) {
      SERVER_FOR_TEST = rs.getServerName();
    }
  }
  UTIL.waitFor(60000, () -> getServerStateNode(SERVER_FOR_TEST) != null);
  ServerStateNode serverNode = getServerStateNode(SERVER_FOR_TEST);
  assertNotNull(serverNode);
  assertTrue("serverNode should be ONLINE when cluster runs normally",
      serverNode.isInState(ServerState.ONLINE));

  SCP_LATCH = new CountDownLatch(1);

  // Shutdown cluster and restart
  List<Integer> ports =
      UTIL.getHBaseCluster().getMaster().getServerManager().getOnlineServersList().stream()
          .map(serverName -> serverName.getPort()).collect(Collectors.toList());
  LOG.info("Shutting down cluster");
  UTIL.getHBaseCluster().killAll();
  UTIL.getHBaseCluster().waitUntilShutDown();
  LOG.info("Restarting cluster");
  UTIL.restartHBaseCluster(StartMiniClusterOption.builder().masterClass(HMasterForTest.class)
      .numMasters(1).numRegionServers(3).rsPorts(ports).build());
  LOG.info("Started cluster");
  UTIL.waitFor(60000, () -> UTIL.getHBaseCluster().getMaster().isInitialized());
  LOG.info("Started cluster master, waiting for {}", SERVER_FOR_TEST);
  UTIL.waitFor(60000, () -> getServerStateNode(SERVER_FOR_TEST) != null);
  serverNode = getServerStateNode(SERVER_FOR_TEST);
  assertFalse("serverNode should not be ONLINE during SCP processing",
      serverNode.isInState(ServerState.ONLINE));
  Optional<Procedure<?>> procedure = UTIL.getHBaseCluster().getMaster().getProcedures().stream()
      .filter(p -> (p instanceof ServerCrashProcedure) &&
          ((ServerCrashProcedure) p).getServerName().equals(SERVER_FOR_TEST)).findAny();
  assertTrue("Should have one SCP for " + SERVER_FOR_TEST, procedure.isPresent());
  assertTrue("Submit the SCP for the same serverName " + SERVER_FOR_TEST + " which should fail",
    UTIL.getHBaseCluster().getMaster().getServerManager().expireServer(SERVER_FOR_TEST) ==
        Procedure.NO_PROC_ID);

  // Wait the SCP to finish
  LOG.info("Waiting on latch");
  SCP_LATCH.countDown();
  UTIL.waitFor(60000, () -> procedure.get().isFinished());

  assertFalse("Even when the SCP is finished, the duplicate SCP should not be scheduled for " +
          SERVER_FOR_TEST,
    UTIL.getHBaseCluster().getMaster().getServerManager().expireServer(SERVER_FOR_TEST) ==
      Procedure.NO_PROC_ID);
  serverNode = UTIL.getHBaseCluster().getMaster().getAssignmentManager().getRegionStates()
      .getServerNode(SERVER_FOR_TEST);
  assertNull("serverNode should be deleted after SCP finished", serverNode);

  MetricsMasterSource masterSource = UTIL.getHBaseCluster().getMaster().getMasterMetrics()
    .getMetricsSource();
  metricsHelper.assertCounter(MetricsMasterSource.SERVER_CRASH_METRIC_PREFIX+"SubmittedCount",
    4, masterSource);
}