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

The following examples show how to use org.apache.hadoop.hbase.regionserver.HRegionServer#abort() . 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: IndexLoadBalancerIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 180000)
public void testRoundRobinAssignmentAfterRegionServerDown() throws Exception {
    ZooKeeperWatcher zkw = UTIL.getZooKeeperWatcher(UTIL);
    MiniHBaseCluster cluster = UTIL.getHBaseCluster();
    HMaster master = cluster.getMaster();
    TableName tableName = TableName.valueOf("testRoundRobinAssignmentAfterRegionServerDown");
    TableName indexTableName =
            TableName.valueOf("testRoundRobinAssignmentAfterRegionServerDown_index");
    createUserAndIndexTable(tableName, indexTableName);
    HRegionServer regionServer = cluster.getRegionServer(1);
    regionServer.abort("Aborting to test random assignment after region server down");
    while (master.getServerManager().areDeadServersInProgress()) {
        Thread.sleep(1000);
    }
    ZKAssign.blockUntilNoRIT(zkw);
    while (master.getAssignmentManager().getRegionStates().isRegionsInTransition()) {
        Threads.sleep(1000);
    }
    boolean isRegionColocated =
            checkForColocation(master, tableName.getNameAsString(), indexTableName
                    .getNameAsString());
    assertTrue("User regions and index regions should colocate.", isRegionColocated);

}
 
Example 2
Source File: TestScannerTimeout.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Test that scanner can continue even if the region server it was reading
 * from failed. Before 2772, it reused the same scanner id.
 * @throws Exception
 */
@Test
public void test2772() throws Exception {
  LOG.info("START************ test2772");
  HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME);
  Scan scan = new Scan();
  // Set a very high timeout, we want to test what happens when a RS
  // fails but the region is recovered before the lease times out.
  // Since the RS is already created, this conf is client-side only for
  // this new table
  Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
  conf.setInt(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, SCANNER_TIMEOUT * 100);

  Connection connection = ConnectionFactory.createConnection(conf);
  Table higherScanTimeoutTable = connection.getTable(TABLE_NAME);
  ResultScanner r = higherScanTimeoutTable.getScanner(scan);
  // This takes way less than SCANNER_TIMEOUT*100
  rs.abort("die!");
  Result[] results = r.next(NB_ROWS);
  assertEquals(NB_ROWS, results.length);
  r.close();
  higherScanTimeoutTable.close();
  connection.close();
  LOG.info("END ************ test2772");

}
 
Example 3
Source File: MiniHBaseCluster.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Cause a region server to exit doing basic clean up only on its way out.
 * @param serverNumber  Used as index into a list.
 */
public String abortRegionServer(int serverNumber) {
  HRegionServer server = getRegionServer(serverNumber);
  LOG.info("Aborting " + server.toString());
  server.abort("Aborting for tests", new Exception("Trace info"));
  return server.toString();
}
 
Example 4
Source File: TestMetaTableAccessor.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsMetaWhenMetaGoesOffline() throws InterruptedException {
  HMaster m = UTIL.getMiniHBaseCluster().getMaster();
  int index = UTIL.getMiniHBaseCluster().getServerWithMeta();
  HRegionServer rsWithMeta = UTIL.getMiniHBaseCluster().getRegionServer(index);
  rsWithMeta.abort("TESTING");
  assertTrue(m.waitForMetaOnline());
}
 
Example 5
Source File: TestScannerTimeout.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Test that scanner won't miss any rows if the region server it was reading
 * from failed. Before 3686, it would skip rows in the scan.
 * @throws Exception
 */
@Test
public void test3686a() throws Exception {
  LOG.info("START ************ TEST3686A---1");
  HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME);
  LOG.info("START ************ TEST3686A---1111");

  Scan scan = new Scan();
  scan.setCaching(SCANNER_CACHING);
  LOG.info("************ TEST3686A");
  MetaTableAccessor.fullScanMetaAndPrint(TEST_UTIL.getAdmin().getConnection());
  // Set a very high timeout, we want to test what happens when a RS
  // fails but the region is recovered before the lease times out.
  // Since the RS is already created, this conf is client-side only for
  // this new table
  Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
  conf.setInt(
      HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, SCANNER_TIMEOUT*100);
  Connection connection = ConnectionFactory.createConnection(conf);
  Table table = connection.getTable(TABLE_NAME);
  LOG.info("START ************ TEST3686A---22");

  ResultScanner r = table.getScanner(scan);
  LOG.info("START ************ TEST3686A---33");

  int count = 1;
  r.next();
  LOG.info("START ************ TEST3686A---44");

  // Kill after one call to next(), which got 5 rows.
  rs.abort("die!");
  while(r.next() != null) {
    count ++;
  }
  assertEquals(NB_ROWS, count);
  r.close();
  table.close();
  connection.close();
  LOG.info("************ END TEST3686A");
}
 
Example 6
Source File: TestServerCrashProcedureStuck.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
  RegionServerThread rsThread = null;
  for (RegionServerThread t : UTIL.getMiniHBaseCluster().getRegionServerThreads()) {
    if (!t.getRegionServer().getRegions(TABLE_NAME).isEmpty()) {
      rsThread = t;
      break;
    }
  }
  HRegionServer rs = rsThread.getRegionServer();
  RegionInfo hri = rs.getRegions(TABLE_NAME).get(0).getRegionInfo();
  HMaster master = UTIL.getMiniHBaseCluster().getMaster();
  ProcedureExecutor<MasterProcedureEnv> executor = master.getMasterProcedureExecutor();
  DummyRegionProcedure proc = new DummyRegionProcedure(executor.getEnvironment(), hri);
  long procId = master.getMasterProcedureExecutor().submitProcedure(proc);
  proc.waitUntilArrive();
  try (AsyncConnection conn =
    ConnectionFactory.createAsyncConnection(UTIL.getConfiguration()).get()) {
    AsyncAdmin admin = conn.getAdmin();
    CompletableFuture<Void> future = admin.move(hri.getRegionName());
    rs.abort("For testing!");

    UTIL.waitFor(30000,
      () -> executor.getProcedures().stream()
        .filter(p -> p instanceof TransitRegionStateProcedure)
        .map(p -> (TransitRegionStateProcedure) p)
        .anyMatch(p -> Bytes.equals(hri.getRegionName(), p.getRegion().getRegionName())));
    proc.resume();
    UTIL.waitFor(30000, () -> executor.isFinished(procId));
    // see whether the move region procedure can finish properly
    future.get(30, TimeUnit.SECONDS);
  }
}
 
Example 7
Source File: TestServerCrashProcedureCarryingMetaStuck.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
  RegionServerThread rsThread = null;
  for (RegionServerThread t : UTIL.getMiniHBaseCluster().getRegionServerThreads()) {
    if (!t.getRegionServer().getRegions(TableName.META_TABLE_NAME).isEmpty()) {
      rsThread = t;
      break;
    }
  }
  HRegionServer rs = rsThread.getRegionServer();
  RegionInfo hri = rs.getRegions(TableName.META_TABLE_NAME).get(0).getRegionInfo();
  HMaster master = UTIL.getMiniHBaseCluster().getMaster();
  ProcedureExecutor<MasterProcedureEnv> executor = master.getMasterProcedureExecutor();
  DummyRegionProcedure proc = new DummyRegionProcedure(executor.getEnvironment(), hri);
  long procId = master.getMasterProcedureExecutor().submitProcedure(proc);
  proc.waitUntilArrive();
  try (AsyncConnection conn =
    ConnectionFactory.createAsyncConnection(UTIL.getConfiguration()).get()) {
    AsyncAdmin admin = conn.getAdmin();
    CompletableFuture<Void> future = admin.move(hri.getRegionName());
    rs.abort("For testing!");

    UTIL.waitFor(30000,
      () -> executor.getProcedures().stream()
        .filter(p -> p instanceof TransitRegionStateProcedure)
        .map(p -> (TransitRegionStateProcedure) p)
        .anyMatch(p -> Bytes.equals(hri.getRegionName(), p.getRegion().getRegionName())));
    proc.resume();
    UTIL.waitFor(30000, () -> executor.isFinished(procId));
    // see whether the move region procedure can finish properly
    future.get(30, TimeUnit.SECONDS);
  }
}
 
Example 8
Source File: TestReportRegionStateTransitionFromDeadServer.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void test() throws HBaseIOException, InterruptedException, ExecutionException {
  RegionInfo region = UTIL.getMiniHBaseCluster().getRegions(NAME).get(0).getRegionInfo();
  AssignmentManager am = UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager();
  RegionStateNode rsn = am.getRegionStates().getRegionStateNode(region);

  // move from rs0 to rs1, and then kill rs0. Later add rs1 to exclude servers, and at last verify
  // that the region should not be on rs1 and rs2 both.
  HRegionServer rs0 = UTIL.getMiniHBaseCluster().getRegionServer(rsn.getRegionLocation());
  HRegionServer rs1 = UTIL.getOtherRegionServer(rs0);
  HRegionServer rs2 = UTIL.getMiniHBaseCluster().getRegionServerThreads().stream()
    .map(t -> t.getRegionServer()).filter(rs -> rs != rs0 && rs != rs1).findAny().get();

  RESUME_REPORT = new CountDownLatch(1);
  ARRIVE_REPORT = new CountDownLatch(1);
  Future<?> future =
    am.moveAsync(new RegionPlan(region, rs0.getServerName(), rs1.getServerName()));
  ARRIVE_REPORT.await();

  RESUME_GET_REGIONS = new CountDownLatch(1);
  ARRIVE_GET_REGIONS = new CountDownLatch(1);
  rs0.abort("For testing!");

  ARRIVE_GET_REGIONS.await();
  RESUME_REPORT.countDown();

  try {
    future.get(15, TimeUnit.SECONDS);
  } catch (TimeoutException e) {
    // after the fix in HBASE-21508 we will get this exception as the TRSP can not be finished any
    // more before SCP interrupts it. It's OK.
  }

  EXCLUDE_SERVERS.add(rs1.getServerName());
  RESUME_GET_REGIONS.countDown();
  // wait until there are no running procedures, no SCP and no TRSP
  UTIL.waitFor(30000, () -> UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor()
    .getActiveProcIds().isEmpty());
  boolean onRS1 = !rs1.getRegions(NAME).isEmpty();
  boolean onRS2 = !rs2.getRegions(NAME).isEmpty();
  assertNotEquals(
    "should either be on rs1 or rs2, but onRS1 is " + onRS1 + " and on RS2 is " + onRS2, onRS1,
    onRS2);
}
 
Example 9
Source File: AbstractTestDLS.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testMasterStartsUpWithLogSplittingWork() throws Exception {
  conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, NUM_RS - 1);
  startCluster(NUM_RS);

  int numRegionsToCreate = 40;
  int numLogLines = 1000;
  // turn off load balancing to prevent regions from moving around otherwise
  // they will consume recovered.edits
  master.balanceSwitch(false);

  try (Table ht = installTable(numRegionsToCreate)) {
    HRegionServer hrs = findRSToKill(false);
    List<RegionInfo> regions = ProtobufUtil.getOnlineRegions(hrs.getRSRpcServices());
    makeWAL(hrs, regions, numLogLines, 100);

    // abort master
    abortMaster(cluster);

    // abort RS
    LOG.info("Aborting region server: " + hrs.getServerName());
    hrs.abort("testing");

    // wait for abort completes
    TEST_UTIL.waitFor(120000, 200, new Waiter.Predicate<Exception>() {
      @Override
      public boolean evaluate() throws Exception {
        return cluster.getLiveRegionServerThreads().size() <= NUM_RS - 1;
      }
    });

    Thread.sleep(2000);
    LOG.info("Current Open Regions:" + HBaseTestingUtility.getAllOnlineRegions(cluster).size());

    // wait for abort completes
    TEST_UTIL.waitFor(120000, 200, new Waiter.Predicate<Exception>() {
      @Override
      public boolean evaluate() throws Exception {
        return (HBaseTestingUtility.getAllOnlineRegions(cluster)
            .size() >= (numRegionsToCreate + 1));
      }
    });

    LOG.info("Current Open Regions After Master Node Starts Up:" +
        HBaseTestingUtility.getAllOnlineRegions(cluster).size());

    assertEquals(numLogLines, TEST_UTIL.countRows(ht));
  }
}
 
Example 10
Source File: TestHBCKSCP.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void test() throws Exception {
  // we are about to do one for it?
  MiniHBaseCluster cluster = this.util.getHBaseCluster();

  // Assert that we have three RegionServers. Test depends on there being multiple.
  assertEquals(RS_COUNT, cluster.getLiveRegionServerThreads().size());

  int count;
  try (Table table = createTable(TableName.valueOf(this.name.getMethodName()))) {
    // Load the table with a bit of data so some logs to split and some edits in each region.
    this.util.loadTable(table, HBaseTestingUtility.COLUMNS[0]);
    count = util.countRows(table);
  }
  assertTrue("expected some rows", count > 0);

  // Make the test easier by not working on server hosting meta...
  // Find another RS. Purge it from Master memory w/o running SCP (if
  // SCP runs, it will clear entries from hbase:meta which frustrates
  // our attempt at manufacturing 'Unknown Servers' condition).
  int metaIndex = this.util.getMiniHBaseCluster().getServerWithMeta();
  int rsIndex = (metaIndex + 1) % RS_COUNT;
  ServerName rsServerName = cluster.getRegionServer(rsIndex).getServerName();
  HMaster master = cluster.getMaster();
  // Get a Region that is on the server.
  RegionInfo rsRI = master.getAssignmentManager().getRegionsOnServer(rsServerName).get(0);
  Result r = MetaTableAccessor.getRegionResult(master.getConnection(), rsRI.getRegionName());
  // Assert region is OPEN.
  assertEquals(RegionState.State.OPEN.toString(),
      Bytes.toString(r.getValue(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER)));
  ServerName serverName = CatalogFamilyFormat.getServerName(r, 0);
  assertEquals(rsServerName, serverName);
  // moveFrom adds to dead servers and adds it to processing list only we will
  // not be processing this server 'normally'. Remove it from processing by
  // calling 'finish' and then remove it from dead servers so rsServerName
  // becomes an 'Unknown Server' even though it is still around.
  master.getServerManager().moveFromOnlineToDeadServers(rsServerName);
  master.getServerManager().getDeadServers().finish(rsServerName);
  master.getServerManager().getDeadServers().removeDeadServer(rsServerName);
  master.getAssignmentManager().getRegionStates().removeServer(rsServerName);
  // Kill the server. Nothing should happen since an 'Unknown Server' as far
  // as the Master is concerned; i.e. no SCP.
  LOG.info("Killing {}", rsServerName);
  HRegionServer hrs = cluster.getRegionServer(rsServerName);
  hrs.abort("KILLED");
  while (!hrs.isStopped()) {
    Threads.sleep(10);
  }
  LOG.info("Dead {}", rsServerName);
  // Now assert still references in hbase:meta to the 'dead' server -- they haven't been
  // cleaned up by an SCP or by anything else.
  assertTrue(searchMeta(master, rsServerName));
  // Assert region is OPEN on dead server still.
  r = MetaTableAccessor.getRegionResult(master.getConnection(), rsRI.getRegionName());
  assertEquals(RegionState.State.OPEN.toString(),
      Bytes.toString(r.getValue(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER)));
  serverName = CatalogFamilyFormat.getServerName(r, 0);
  assertNotNull(cluster.getRegionServer(serverName));
  assertEquals(rsServerName, serverName);

  // I now have 'Unknown Server' references in hbase:meta; i.e. Server references
  // with no corresponding SCP. Queue one.
  MasterProtos.ScheduleServerCrashProcedureResponse response =
      master.getMasterRpcServices().scheduleServerCrashProcedure(null,
          MasterProtos.ScheduleServerCrashProcedureRequest.newBuilder().
              addServerName(ProtobufUtil.toServerName(rsServerName)).build());
  assertEquals(1, response.getPidCount());
  long pid = response.getPid(0);
  assertNotEquals(Procedure.NO_PROC_ID, pid);
  while (master.getMasterProcedureExecutor().getActiveProcIds().contains(pid)) {
    Threads.sleep(10);
  }
  // After SCP, assert region is OPEN on new server.
  r = MetaTableAccessor.getRegionResult(master.getConnection(), rsRI.getRegionName());
  assertEquals(RegionState.State.OPEN.toString(),
      Bytes.toString(r.getValue(HConstants.CATALOG_FAMILY, HConstants.STATE_QUALIFIER)));
  serverName = CatalogFamilyFormat.getServerName(r, 0);
  assertNotNull(cluster.getRegionServer(serverName));
  assertNotEquals(rsServerName, serverName);
  // Make sure no mention of old server post SCP.
  assertFalse(searchMeta(master, rsServerName));
}
 
Example 11
Source File: AbstractTestWALReplay.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 *
 * @throws Exception
 */
@Test
public void testReplayEditsAfterRegionMovedWithMultiCF() throws Exception {
  final TableName tableName =
      TableName.valueOf("testReplayEditsAfterRegionMovedWithMultiCF");
  byte[] family1 = Bytes.toBytes("cf1");
  byte[] family2 = Bytes.toBytes("cf2");
  byte[] qualifier = Bytes.toBytes("q");
  byte[] value = Bytes.toBytes("testV");
  byte[][] familys = { family1, family2 };
  TEST_UTIL.createTable(tableName, familys);
  Table htable = TEST_UTIL.getConnection().getTable(tableName);
  Put put = new Put(Bytes.toBytes("r1"));
  put.addColumn(family1, qualifier, value);
  htable.put(put);
  ResultScanner resultScanner = htable.getScanner(new Scan());
  int count = 0;
  while (resultScanner.next() != null) {
    count++;
  }
  resultScanner.close();
  assertEquals(1, count);

  MiniHBaseCluster hbaseCluster = TEST_UTIL.getMiniHBaseCluster();
  List<HRegion> regions = hbaseCluster.getRegions(tableName);
  assertEquals(1, regions.size());

  // move region to another regionserver
  Region destRegion = regions.get(0);
  int originServerNum = hbaseCluster.getServerWith(destRegion.getRegionInfo().getRegionName());
  assertTrue("Please start more than 1 regionserver",
      hbaseCluster.getRegionServerThreads().size() > 1);
  int destServerNum = 0;
  while (destServerNum == originServerNum) {
    destServerNum++;
  }
  HRegionServer originServer = hbaseCluster.getRegionServer(originServerNum);
  HRegionServer destServer = hbaseCluster.getRegionServer(destServerNum);
  // move region to destination regionserver
  TEST_UTIL.moveRegionAndWait(destRegion.getRegionInfo(), destServer.getServerName());

  // delete the row
  Delete del = new Delete(Bytes.toBytes("r1"));
  htable.delete(del);
  resultScanner = htable.getScanner(new Scan());
  count = 0;
  while (resultScanner.next() != null) {
    count++;
  }
  resultScanner.close();
  assertEquals(0, count);

  // flush region and make major compaction
  HRegion region =
      (HRegion) destServer.getOnlineRegion(destRegion.getRegionInfo().getRegionName());
  region.flush(true);
  // wait to complete major compaction
  for (HStore store : region.getStores()) {
    store.triggerMajorCompaction();
  }
  region.compact(true);

  // move region to origin regionserver
  TEST_UTIL.moveRegionAndWait(destRegion.getRegionInfo(), originServer.getServerName());
  // abort the origin regionserver
  originServer.abort("testing");

  // see what we get
  Result result = htable.get(new Get(Bytes.toBytes("r1")));
  if (result != null) {
    assertTrue("Row is deleted, but we get" + result.toString(),
        (result == null) || result.isEmpty());
  }
  resultScanner.close();
}