org.apache.hadoop.hbase.regionserver.HRegionServer Java Examples

The following examples show how to use org.apache.hadoop.hbase.regionserver.HRegionServer. 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: TestRegionLocationFinder.java    From hbase with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  cluster = TEST_UTIL.startMiniCluster(ServerNum);
  table = TEST_UTIL.createTable(tableName, FAMILY, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
  TEST_UTIL.waitTableAvailable(tableName, 1000);
  TEST_UTIL.loadTable(table, FAMILY);

  for (int i = 0; i < ServerNum; i++) {
    HRegionServer server = cluster.getRegionServer(i);
    for (HRegion region : server.getRegions(tableName)) {
      region.flush(true);
    }
  }

  finder.setConf(TEST_UTIL.getConfiguration());
  finder.setServices(cluster.getMaster());
  finder.setClusterMetrics(cluster.getMaster().getClusterMetrics());
}
 
Example #2
Source File: TestRegionMover.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegionServerPort() {
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  HRegionServer regionServer = cluster.getRegionServer(0);
  String rsName = regionServer.getServerName().getHostname();

  final int PORT = 16021;
  Configuration conf = TEST_UTIL.getConfiguration();
  String originalPort = conf.get(HConstants.REGIONSERVER_PORT);
  conf.set(HConstants.REGIONSERVER_PORT, Integer.toString(PORT));
  RegionMoverBuilder rmBuilder = new RegionMoverBuilder(rsName, conf);
  assertEquals(PORT, rmBuilder.port);
  if (originalPort != null) {
    conf.set(HConstants.REGIONSERVER_PORT, originalPort);
  }
}
 
Example #3
Source File: TestWarmupRegion.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
* Basic client side validation of HBASE-4536
*/
@Test
public void testWarmup() throws Exception {
  int serverid = 0;
  HRegion region = TEST_UTIL.getMiniHBaseCluster().getRegions(TABLENAME).get(0);
  RegionInfo info = region.getRegionInfo();
  runwarmup();
  for (int i = 0; i < 10; i++) {
    HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(serverid);
    byte [] destName = Bytes.toBytes(rs.getServerName().toString());
    assertTrue(destName != null);
    LOG.info("i=" + i );
    TEST_UTIL.getMiniHBaseCluster().getMaster().move(info.getEncodedNameAsBytes(), destName);
    serverid = (serverid + 1) % 2;
  }
}
 
Example #4
Source File: AbstractTestLogRollPeriod.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that the LogRoller perform the roll even if there are no edits
 */
@Test
public void testNoEdits() throws Exception {
  TableName tableName = TableName.valueOf("TestLogRollPeriodNoEdits");
  TEST_UTIL.createTable(tableName, "cf");
  try {
    Table table = TEST_UTIL.getConnection().getTable(tableName);
    try {
      HRegionServer server = TEST_UTIL.getRSForFirstRegionInTable(tableName);
      WAL log = server.getWAL(null);
      checkMinLogRolls(log, 5);
    } finally {
      table.close();
    }
  } finally {
    TEST_UTIL.deleteTable(tableName);
  }
}
 
Example #5
Source File: BaseTest.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * Ensures each region of SYSTEM.CATALOG is on a different region server
 */
private static void moveRegion(HRegionInfo regionInfo, ServerName srcServerName, ServerName dstServerName) throws Exception  {
    Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin();
    HBaseTestingUtility util = getUtility();
    MiniHBaseCluster cluster = util.getHBaseCluster();
    HMaster master = cluster.getMaster();
    AssignmentManager am = master.getAssignmentManager();
   
    HRegionServer dstServer = util.getHBaseCluster().getRegionServer(dstServerName);
    HRegionServer srcServer = util.getHBaseCluster().getRegionServer(srcServerName);
    byte[] encodedRegionNameInBytes = regionInfo.getEncodedNameAsBytes();
    admin.move(encodedRegionNameInBytes, Bytes.toBytes(dstServer.getServerName().getServerName()));
    while (dstServer.getOnlineRegion(regionInfo.getRegionName()) == null
            || dstServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameInBytes)
            || srcServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameInBytes)) {
        // wait for the move to be finished
        Thread.sleep(100);
    }
}
 
Example #6
Source File: TestSplitWALProcedure.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testHandleDeadWorker() 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);
  ProcedureExecutor<MasterProcedureEnv> masterPE = master.getMasterProcedureExecutor();
  List<FileStatus> wals = splitWALManager.getWALsToSplit(testServer.getServerName(), false);
  Assert.assertEquals(1, wals.size());
  TEST_UTIL.getHBaseCluster().killRegionServer(testServer.getServerName());
  TEST_UTIL.waitFor(30000, () -> master.getProcedures().stream()
      .anyMatch(procedure -> procedure instanceof SplitWALProcedure));
  Procedure splitWALProcedure = master.getProcedures().stream()
      .filter(procedure -> procedure instanceof SplitWALProcedure).findAny().get();
  Assert.assertNotNull(splitWALProcedure);
  TEST_UTIL.waitFor(5000, () -> ((SplitWALProcedure) splitWALProcedure).getWorker() != null);
  TEST_UTIL.getHBaseCluster()
      .killRegionServer(((SplitWALProcedure) splitWALProcedure).getWorker());
  ProcedureTestingUtility.waitProcedure(masterPE, splitWALProcedure.getProcId());
  Assert.assertTrue(splitWALProcedure.isSuccess());
  ProcedureTestingUtility.waitAllProcedures(masterPE);
}
 
Example #7
Source File: TestRegionMover.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithAck() throws Exception {
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  HRegionServer regionServer = cluster.getRegionServer(0);
  String rsName = regionServer.getServerName().getAddress().toString();
  int numRegions = regionServer.getNumberOfOnlineRegions();
  RegionMoverBuilder rmBuilder =
    new RegionMoverBuilder(rsName, TEST_UTIL.getConfiguration()).ack(true).maxthreads(8);
  try (RegionMover rm = rmBuilder.build()) {
    LOG.info("Unloading " + regionServer.getServerName());
    rm.unload();
    assertEquals(0, regionServer.getNumberOfOnlineRegions());
    LOG.info("Successfully Unloaded\nNow Loading");
    rm.load();
    assertEquals(numRegions, regionServer.getNumberOfOnlineRegions());
    // Repeat the same load. It should be very fast because all regions are already moved.
    rm.load();
  }
}
 
Example #8
Source File: TestFileSystemUtilizationChore.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testNonHFilesAreIgnored() {
  final Configuration conf = getDefaultHBaseConfiguration();
  final HRegionServer rs = mockRegionServer(conf);

  // Region r1 has two store files, one hfile link and one hfile
  final List<Long> r1StoreFileSizes = Arrays.asList(1024L, 2048L);
  final List<Long> r1HFileSizes = Arrays.asList(0L, 2048L);
  final long r1HFileSizeSum = sum(r1HFileSizes);
  // Region r2 has one store file which is a hfile link
  final List<Long> r2StoreFileSizes = Arrays.asList(1024L * 1024L);
  final List<Long> r2HFileSizes = Arrays.asList(0L);
  final long r2HFileSizeSum = sum(r2HFileSizes);

  // We expect that only the hfiles would be counted (hfile links are ignored)
  final FileSystemUtilizationChore chore = new FileSystemUtilizationChore(rs);
  doAnswer(new ExpectedRegionSizeSummationAnswer(
      sum(Arrays.asList(r1HFileSizeSum, r2HFileSizeSum))))
      .when(rs).reportRegionSizesForQuotas(any(RegionSizeStore.class));

  final Region r1 = mockRegionWithHFileLinks(r1StoreFileSizes, r1HFileSizes);
  final Region r2 = mockRegionWithHFileLinks(r2StoreFileSizes, r2HFileSizes);
  Mockito.doReturn(Arrays.asList(r1, r2)).when(rs).getRegions();
  chore.chore();
}
 
Example #9
Source File: TestRegionLocationFinder.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testInternalGetTopBlockLocation() throws Exception {
  for (int i = 0; i < ServerNum; i++) {
    HRegionServer server = cluster.getRegionServer(i);
    for (HRegion region : server.getRegions(tableName)) {
      // get region's hdfs block distribution by region and RegionLocationFinder,
      // they should have same result
      HDFSBlocksDistribution blocksDistribution1 = region.getHDFSBlocksDistribution();
      HDFSBlocksDistribution blocksDistribution2 = finder.getBlockDistribution(region
          .getRegionInfo());
      assertEquals(blocksDistribution1.getUniqueBlocksTotalWeight(),
        blocksDistribution2.getUniqueBlocksTotalWeight());
      if (blocksDistribution1.getUniqueBlocksTotalWeight() != 0) {
        assertEquals(blocksDistribution1.getTopHosts().get(0), blocksDistribution2.getTopHosts()
            .get(0));
      }
    }
  }
}
 
Example #10
Source File: TestChangingEncoding.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void compactAndWait() throws IOException, InterruptedException {
  LOG.debug("Compacting table " + tableName);
  HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0);
  Admin admin = TEST_UTIL.getAdmin();
  admin.majorCompact(tableName);

  // Waiting for the compaction to start, at least .5s.
  final long maxWaitime = System.currentTimeMillis() + 500;
  boolean cont;
  do {
    cont = rs.compactSplitThread.getCompactionQueueSize() == 0;
    Threads.sleep(1);
  } while (cont && System.currentTimeMillis() < maxWaitime);

  while (rs.compactSplitThread.getCompactionQueueSize() > 0) {
    Threads.sleep(1);
  }
  LOG.debug("Compaction queue size reached 0, continuing");
}
 
Example #11
Source File: TestReplicationEmptyWALRecovery.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Waits until there is only one log(the current writing one) in the replication queue
 * @param numRs number of regionservers
 */
private void waitForLogAdvance(int numRs) throws Exception {
  Waiter.waitFor(CONF1, 10000, new Waiter.Predicate<Exception>() {
    @Override
    public boolean evaluate() throws Exception {
      for (int i = 0; i < numRs; i++) {
        HRegionServer hrs = UTIL1.getHBaseCluster().getRegionServer(i);
        RegionInfo regionInfo =
            UTIL1.getHBaseCluster().getRegions(htable1.getName()).get(0).getRegionInfo();
        WAL wal = hrs.getWAL(regionInfo);
        Path currentFile = ((AbstractFSWAL<?>) wal).getCurrentFileName();
        Replication replicationService = (Replication) UTIL1.getHBaseCluster()
            .getRegionServer(i).getReplicationSourceService();
        for (ReplicationSourceInterface rsi : replicationService.getReplicationManager()
            .getSources()) {
          ReplicationSource source = (ReplicationSource) rsi;
          if (!currentFile.equals(source.getCurrentPath())) {
            return false;
          }
        }
      }
      return true;
    }
  });
}
 
Example #12
Source File: TestAsyncClusterAdminApi.java    From hbase with Apache License 2.0 6 votes vote down vote up
private HRegionServer startAndWriteData(TableName tableName, byte[] value) throws Exception {
  createTableWithDefaultConf(tableName);
  AsyncTable<?> table = ASYNC_CONN.getTable(tableName);
  HRegionServer regionServer = TEST_UTIL.getRSForFirstRegionInTable(tableName);
  for (int i = 1; i <= 256; i++) { // 256 writes should cause 8 log rolls
    Put put = new Put(Bytes.toBytes("row" + String.format("%1$04d", i)));
    put.addColumn(FAMILY, null, value);
    table.put(put).join();
    if (i % 32 == 0) {
      // After every 32 writes sleep to let the log roller run
      try {
        Thread.sleep(2000);
      } catch (InterruptedException e) {
        // continue
      }
    }
  }
  return regionServer;
}
 
Example #13
Source File: TestWarmupRegion.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected void runwarmup()  throws InterruptedException{
  Thread thread = new Thread(new Runnable() {
    @Override
    public void run() {
      HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0);
      HRegion region = TEST_UTIL.getMiniHBaseCluster().getRegions(TABLENAME).get(0);
      RegionInfo info = region.getRegionInfo();

      try {
        TableDescriptor htd = table.getDescriptor();
        for (int i = 0; i < 10; i++) {
          warmupHRegion(info, htd, rs.getWAL(info), rs.getConfiguration(), rs, null);
        }
      } catch (IOException ie) {
        LOG.error("Failed warming up region " + info.getRegionNameAsString(), ie);
      }
    }
  });
  thread.start();
  thread.join();
}
 
Example #14
Source File: TestAdmin2.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testWALRollWriting() throws Exception {
  setUpforLogRolling();
  String className = this.getClass().getName();
  StringBuilder v = new StringBuilder(className);
  while (v.length() < 1000) {
    v.append(className);
  }
  byte[] value = Bytes.toBytes(v.toString());
  HRegionServer regionServer = startAndWriteData(TableName.valueOf(name.getMethodName()), value);
  LOG.info("after writing there are "
      + AbstractFSWALProvider.getNumRolledLogFiles(regionServer.getWAL(null)) + " log files");

  // flush all regions
  for (HRegion r : regionServer.getOnlineRegionsLocalContext()) {
    r.flush(true);
  }
  ADMIN.rollWALWriter(regionServer.getServerName());
  int count = AbstractFSWALProvider.getNumRolledLogFiles(regionServer.getWAL(null));
  LOG.info("after flushing all regions and rolling logs there are " +
      count + " log files");
  assertTrue(("actual count: " + count), count <= 2);
}
 
Example #15
Source File: TestAddToSerialReplicationPeer.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testEnablingTable() throws Exception {
  TableName tableName = createTable();
  try (Table table = UTIL.getConnection().getTable(tableName)) {
    for (int i = 0; i < 100; i++) {
      table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
    }
  }
  RegionInfo region = UTIL.getAdmin().getRegions(tableName).get(0);
  HRegionServer rs = UTIL.getOtherRegionServer(UTIL.getRSForFirstRegionInTable(tableName));
  moveRegionAndArchiveOldWals(region, rs);
  TableStateManager tsm = UTIL.getMiniHBaseCluster().getMaster().getTableStateManager();
  tsm.setTableState(tableName, TableState.State.ENABLING);
  Thread t = new Thread(() -> {
    try {
      addPeer(true);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  });
  t.start();
  Thread.sleep(5000);
  // we will wait on the disabling table so the thread should still be alive.
  assertTrue(t.isAlive());
  tsm.setTableState(tableName, TableState.State.ENABLED);
  t.join();
  try (Table table = UTIL.getConnection().getTable(tableName)) {
    for (int i = 0; i < 100; i++) {
      table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
    }
  }
  waitUntilReplicationDone(100);
  checkOrder(100);
}
 
Example #16
Source File: TestGetLastFlushedSequenceId.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws IOException, InterruptedException {
  testUtil.getAdmin().createNamespace(
    NamespaceDescriptor.create(tableName.getNamespaceAsString()).build());
  Table table = testUtil.createTable(tableName, families);
  table.put(new Put(Bytes.toBytes("k"))
          .addColumn(family, Bytes.toBytes("q"), Bytes.toBytes("v")));
  MiniHBaseCluster cluster = testUtil.getMiniHBaseCluster();
  List<JVMClusterUtil.RegionServerThread> rsts = cluster.getRegionServerThreads();
  Region region = null;
  for (int i = 0; i < cluster.getRegionServerThreads().size(); i++) {
    HRegionServer hrs = rsts.get(i).getRegionServer();
    for (Region r : hrs.getRegions(tableName)) {
      region = r;
      break;
    }
  }
  assertNotNull(region);
  Thread.sleep(2000);
  RegionStoreSequenceIds ids =
      testUtil.getHBaseCluster().getMaster()
          .getLastSequenceId(region.getRegionInfo().getEncodedNameAsBytes());
  assertEquals(HConstants.NO_SEQNUM, ids.getLastFlushedSequenceId());
  // This will be the sequenceid just before that of the earliest edit in memstore.
  long storeSequenceId = ids.getStoreSequenceId(0).getSequenceId();
  assertTrue(storeSequenceId > 0);
  testUtil.getAdmin().flush(tableName);
  Thread.sleep(2000);
  ids =
      testUtil.getHBaseCluster().getMaster()
          .getLastSequenceId(region.getRegionInfo().getEncodedNameAsBytes());
  assertTrue(ids.getLastFlushedSequenceId() + " > " + storeSequenceId,
    ids.getLastFlushedSequenceId() > storeSequenceId);
  assertEquals(ids.getLastFlushedSequenceId(), ids.getStoreSequenceId(0).getSequenceId());
  table.close();
}
 
Example #17
Source File: MiniHBaseCluster.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void killRegionServer(ServerName serverName) throws IOException {
  HRegionServer server = getRegionServer(getRegionServerIndex(serverName));
  if (server instanceof MiniHBaseClusterRegionServer) {
    LOG.info("Killing " + server.toString());
    ((MiniHBaseClusterRegionServer) server).kill();
  } else {
    abortRegionServer(getRegionServerIndex(serverName));
  }
}
 
Example #18
Source File: TestWrongMetaWALFileName.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
  // create a table so that we will write some edits to meta
  TableName tableName = TableName.valueOf("whatever");
  UTIL.createTable(tableName, Bytes.toBytes("family"));
  UTIL.waitTableAvailable(tableName);
  HRegionServer rs = UTIL.getMiniHBaseCluster().getRegionServer(0);
  Path walDir = new Path(rs.getWALRootDir(),
    AbstractFSWALProvider.getWALDirectoryName(rs.getServerName().toString()));
  // we should have meta wal files.
  assertTrue(
    rs.getWALFileSystem().listStatus(walDir, AbstractFSWALProvider::isMetaFile).length > 0);
}
 
Example #19
Source File: TestWALFiltering.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void flushAllRegions(int rsId)
throws ServiceException,
org.apache.hbase.thirdparty.com.google.protobuf.ServiceException, IOException {
  HRegionServer hrs = getRegionServer(rsId);
  for (byte[] regionName : getRegionsByServer(rsId)) {
    FlushRegionRequest request =
      RequestConverter.buildFlushRegionRequest(regionName);
    hrs.getRSRpcServices().flushRegion(null, request);
  }
}
 
Example #20
Source File: TestAdmin2.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testCloseRegionThatFetchesTheHRIFromMeta() throws Exception {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  createTableWithDefaultConf(tableName);

  RegionInfo info = null;
  HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(tableName);
  List<RegionInfo> onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices());
  for (RegionInfo regionInfo : onlineRegions) {
    if (!regionInfo.isMetaRegion()) {
      if (regionInfo.getRegionNameAsString().contains("TestHBACloseRegion2")) {
        info = regionInfo;
        ADMIN.unassign(regionInfo.getRegionName(), true);
      }
    }
  }

  boolean isInList = ProtobufUtil.getOnlineRegions(
    rs.getRSRpcServices()).contains(info);
  long timeout = System.currentTimeMillis() + 10000;
  while ((System.currentTimeMillis() < timeout) && (isInList)) {
    Thread.sleep(100);
    isInList = ProtobufUtil.getOnlineRegions(
      rs.getRSRpcServices()).contains(info);
  }

  assertFalse("The region should not be present in online regions list.",
    isInList);
}
 
Example #21
Source File: TestFlushWithThroughputController.java    From hbase with Apache License 2.0 5 votes vote down vote up
private HStore getStoreWithName(TableName tableName) {
  MiniHBaseCluster cluster = hbtu.getMiniHBaseCluster();
  List<JVMClusterUtil.RegionServerThread> rsts = cluster.getRegionServerThreads();
  for (int i = 0; i < cluster.getRegionServerThreads().size(); i++) {
    HRegionServer hrs = rsts.get(i).getRegionServer();
    for (Region region : hrs.getRegions(tableName)) {
      return ((HRegion) region).getStores().iterator().next();
    }
  }
  return null;
}
 
Example #22
Source File: TestMvccConsistentScanner.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void move() throws IOException, InterruptedException {
  RegionInfo region =
      UTIL.getHBaseCluster().getRegions(tableName).stream().findAny().get().getRegionInfo();
  HRegionServer rs =
      UTIL.getHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer())
          .filter(r -> !r.getOnlineTables().contains(tableName)).findAny().get();
  UTIL.getAdmin().move(region.getEncodedNameAsBytes(), rs.getServerName());
  while (UTIL.getRSForFirstRegionInTable(tableName) != rs) {
    Thread.sleep(100);
  }
}
 
Example #23
Source File: TestRegionAssignedToMultipleRegionServers.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
  RegionInfo region = UTIL.getMiniHBaseCluster().getRegions(NAME).get(0).getRegionInfo();
  AssignmentManager am = UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager();
  RegionStateNode rsn = am.getRegionStates().getRegionStateNode(region);

  ServerName sn = rsn.getRegionLocation();
  ARRIVE = new CountDownLatch(1);
  HALT = true;
  am.moveAsync(new RegionPlan(region, sn, sn));
  ARRIVE.await();

  // let's restart the master
  EXCLUDE_SERVERS.add(rsn.getRegionLocation());
  KILL = true;
  HMaster activeMaster = UTIL.getMiniHBaseCluster().getMaster();
  activeMaster.abort("For testing");
  activeMaster.join();
  KILL = false;

  // sleep a while to reproduce the problem, as after the fix in HBASE-21472 the execution logic
  // is changed so the old code to reproduce the problem can not compile...
  Thread.sleep(10000);
  HALT = false;
  Thread.sleep(5000);

  HRegionServer rs = UTIL.getMiniHBaseCluster().getRegionServer(sn);
  assertNotNull(rs.getRegion(region.getEncodedName()));
  assertNull(UTIL.getOtherRegionServer(rs).getRegion(region.getEncodedName()));
}
 
Example #24
Source File: AssignRegionHandler.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static AssignRegionHandler create(HRegionServer server, RegionInfo regionInfo,
    long openProcId, TableDescriptor tableDesc, long masterSystemTime) {
  EventType eventType;
  if (regionInfo.isMetaRegion()) {
    eventType = EventType.M_RS_CLOSE_META;
  } else if (regionInfo.getTable().isSystemTable() ||
    (tableDesc != null && tableDesc.getPriority() >= HConstants.ADMIN_QOS)) {
    eventType = EventType.M_RS_OPEN_PRIORITY_REGION;
  } else {
    eventType = EventType.M_RS_OPEN_REGION;
  }
  return new AssignRegionHandler(server, regionInfo, openProcId, tableDesc, masterSystemTime,
    eventType);
}
 
Example #25
Source File: TestFavoredStochasticBalancerPickers.java    From hbase with Apache License 2.0 5 votes vote down vote up
private List<RegionInfo> getTableRegionsFromServer(TableName tableName, ServerName source)
    throws IOException {
  List<RegionInfo> regionInfos = Lists.newArrayList();
  HRegionServer regionServer = cluster.getRegionServer(source);
  for (Region region : regionServer.getRegions(tableName)) {
    regionInfos.add(region.getRegionInfo());
  }
  return regionInfos;
}
 
Example #26
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 #27
Source File: TestFIFOCompactionPolicy.java    From hbase with Apache License 2.0 5 votes vote down vote up
private HStore getStoreWithName(TableName tableName) {
  MiniHBaseCluster cluster = TEST_UTIL.getMiniHBaseCluster();
  List<JVMClusterUtil.RegionServerThread> rsts = cluster.getRegionServerThreads();
  for (int i = 0; i < cluster.getRegionServerThreads().size(); i++) {
    HRegionServer hrs = rsts.get(i).getRegionServer();
    for (HRegion region : hrs.getRegions(tableName)) {
      return region.getStores().iterator().next();
    }
  }
  return null;
}
 
Example #28
Source File: SerialReplicationTestBase.java    From hbase with Apache License 2.0 5 votes vote down vote up
protected static void moveRegion(RegionInfo region, HRegionServer rs) throws Exception {
  UTIL.getAdmin().move(region.getEncodedNameAsBytes(), rs.getServerName());
  UTIL.waitFor(30000, new ExplainingPredicate<Exception>() {

    @Override
    public boolean evaluate() throws Exception {
      return rs.getRegion(region.getEncodedName()) != null;
    }

    @Override
    public String explainFailure() throws Exception {
      return region + " is still not on " + rs;
    }
  });
}
 
Example #29
Source File: TestSyncReplicationRemoveRemoteWAL.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveRemoteWAL() throws Exception {
  UTIL2.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID,
    SyncReplicationState.STANDBY);
  UTIL1.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID,
    SyncReplicationState.ACTIVE);

  MasterFileSystem mfs = UTIL2.getMiniHBaseCluster().getMaster().getMasterFileSystem();
  Path remoteWALDir = ReplicationUtils.getPeerRemoteWALDir(
    new Path(mfs.getWALRootDir(), ReplicationUtils.REMOTE_WAL_DIR_NAME), PEER_ID);
  FileStatus[] remoteWALStatus = mfs.getWALFileSystem().listStatus(remoteWALDir);
  assertEquals(1, remoteWALStatus.length);
  Path remoteWAL = remoteWALStatus[0].getPath();
  assertThat(remoteWAL.getName(), endsWith(ReplicationUtils.SYNC_WAL_SUFFIX));
  writeAndVerifyReplication(UTIL1, UTIL2, 0, 100);

  HRegionServer rs = UTIL1.getRSForFirstRegionInTable(TABLE_NAME);
  rs.getWalRoller().requestRollAll();
  // The replicated wal file should be deleted finally
  waitUntilDeleted(UTIL2, remoteWAL);
  remoteWALStatus = mfs.getWALFileSystem().listStatus(remoteWALDir);
  assertEquals(1, remoteWALStatus.length);
  remoteWAL = remoteWALStatus[0].getPath();
  assertThat(remoteWAL.getName(), endsWith(ReplicationUtils.SYNC_WAL_SUFFIX));

  UTIL1.getAdmin().disableReplicationPeer(PEER_ID);
  write(UTIL1, 100, 200);
  UTIL1.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID,
    SyncReplicationState.DOWNGRADE_ACTIVE);

  // should still be there since the peer is disabled and we haven't replicated the data yet
  assertTrue(mfs.getWALFileSystem().exists(remoteWAL));

  UTIL1.getAdmin().enableReplicationPeer(PEER_ID);
  waitUntilReplicationDone(UTIL2, 200);
  verifyThroughRegion(UTIL2, 100, 200);

  // Confirm that we will also remove the remote wal files in DA state
  waitUntilDeleted(UTIL2, remoteWAL);
}
 
Example #30
Source File: TestRegionMover.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void waitForServerDecom(HRegionServer excludeServer) {

    TEST_UTIL.waitFor(3000, () -> {
      try {
        List<ServerName> decomServers = TEST_UTIL.getAdmin().listDecommissionedRegionServers();
        return decomServers.size() == 1
          && decomServers.get(0).equals(excludeServer.getServerName());
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    });
  }