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

The following examples show how to use org.apache.hadoop.hbase.regionserver.HRegionServer. These examples are extracted from open source projects. 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 Project: hbase   Source File: TestChangingEncoding.java    License: 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 2
Source Project: hbase   Source File: TestRegionMover.java    License: 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 3
Source Project: phoenix   Source File: BaseTest.java    License: 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 4
Source Project: hbase   Source File: AbstractTestLogRollPeriod.java    License: 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 Project: hbase   Source File: TestReplicationEmptyWALRecovery.java    License: 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 6
Source Project: hbase   Source File: TestSplitWALProcedure.java    License: 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 Project: hbase   Source File: TestRegionMover.java    License: 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 8
Source Project: hbase   Source File: TestWarmupRegion.java    License: 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 9
Source Project: hbase   Source File: TestFileSystemUtilizationChore.java    License: 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 10
Source Project: hbase   Source File: TestRegionLocationFinder.java    License: 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 11
Source Project: hbase   Source File: TestAsyncClusterAdminApi.java    License: 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 12
Source Project: hbase   Source File: TestWarmupRegion.java    License: 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 13
Source Project: hbase   Source File: TestAdmin2.java    License: 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 14
Source Project: hbase   Source File: TestRegionLocationFinder.java    License: 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 15
Source Project: hbase   Source File: TestRegionSizeReportingChore.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultConfigurationProperties() {
  final Configuration conf = getDefaultHBaseConfiguration();
  final HRegionServer rs = mockRegionServer(conf);
  RegionSizeReportingChore chore = new RegionSizeReportingChore(rs);
  assertEquals(
      RegionSizeReportingChore.REGION_SIZE_REPORTING_CHORE_DELAY_DEFAULT,
      chore.getInitialDelay());
  assertEquals(
      RegionSizeReportingChore.REGION_SIZE_REPORTING_CHORE_PERIOD_DEFAULT, chore.getPeriod());
  assertEquals(
      TimeUnit.valueOf(RegionSizeReportingChore.REGION_SIZE_REPORTING_CHORE_TIMEUNIT_DEFAULT),
      chore.getTimeUnit());
}
 
Example 16
Source Project: hbase   Source File: TestRegionRebalancing.java    License: Apache License 2.0 5 votes vote down vote up
private List<HRegionServer> getOnlineRegionServers() {
  List<HRegionServer> list = new ArrayList<>();
  for (JVMClusterUtil.RegionServerThread rst :
      UTIL.getHBaseCluster().getRegionServerThreads()) {
    if (rst.getRegionServer().isOnline()) {
      list.add(rst.getRegionServer());
    }
  }
  return list;
}
 
Example 17
Source Project: hbase   Source File: RefreshPeerCallable.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void init(byte[] parameter, HRegionServer rs) {
  this.rs = rs;
  try {
    RefreshPeerParameter param = RefreshPeerParameter.parseFrom(parameter);
    this.peerId = param.getPeerId();
    this.type = param.getType();
    this.stage = param.getStage();
  } catch (InvalidProtocolBufferException e) {
    initError = e;
  }
}
 
Example 18
Source Project: hbase   Source File: TestFileSystemUtilizationChore.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultConfigurationProperties() {
  final Configuration conf = getDefaultHBaseConfiguration();
  final HRegionServer rs = mockRegionServer(conf);
  final FileSystemUtilizationChore chore = new FileSystemUtilizationChore(rs);
  // Verify that the expected default values are actually represented.
  assertEquals(
      FileSystemUtilizationChore.FS_UTILIZATION_CHORE_PERIOD_DEFAULT, chore.getPeriod());
  assertEquals(
      FileSystemUtilizationChore.FS_UTILIZATION_CHORE_DELAY_DEFAULT, chore.getInitialDelay());
  assertEquals(
      TimeUnit.valueOf(FileSystemUtilizationChore.FS_UTILIZATION_CHORE_TIMEUNIT_DEFAULT),
      chore.getTimeUnit());
}
 
Example 19
Source Project: hbase   Source File: ReplicationSource.java    License: Apache License 2.0 5 votes vote down vote up
private ReplicationEndpoint createReplicationEndpoint()
    throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException {
  RegionServerCoprocessorHost rsServerHost = null;
  if (server instanceof HRegionServer) {
    rsServerHost = ((HRegionServer) server).getRegionServerCoprocessorHost();
  }
  String replicationEndpointImpl = replicationPeer.getPeerConfig().getReplicationEndpointImpl();

  ReplicationEndpoint replicationEndpoint;
  if (replicationEndpointImpl == null) {
    // Default to HBase inter-cluster replication endpoint; skip reflection
    replicationEndpoint = new HBaseInterClusterReplicationEndpoint();
  } else {
    try {
      replicationEndpoint = Class.forName(replicationEndpointImpl)
          .asSubclass(ReplicationEndpoint.class)
          .getDeclaredConstructor()
          .newInstance();
    } catch (NoSuchMethodException | InvocationTargetException e) {
      throw new IllegalArgumentException(e);
    }
  }
  if (rsServerHost != null) {
    ReplicationEndpoint newReplicationEndPoint =
      rsServerHost.postCreateReplicationEndPoint(replicationEndpoint);
    if (newReplicationEndPoint != null) {
      // Override the newly created endpoint from the hook with configured end point
      replicationEndpoint = newReplicationEndPoint;
    }
  }
  return replicationEndpoint;
}
 
Example 20
Source Project: hbase   Source File: TestFileSystemUtilizationChore.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testProcessingLeftoverRegions() {
  final Configuration conf = getDefaultHBaseConfiguration();
  final HRegionServer rs = mockRegionServer(conf);

  // Some leftover regions from a previous chore()
  final List<Long> leftover1Sizes = Arrays.asList(1024L, 4096L);
  final long leftover1Sum = sum(leftover1Sizes);
  final List<Long> leftover2Sizes = Arrays.asList(2048L);
  final long leftover2Sum = sum(leftover2Sizes);

  final Region lr1 = mockRegionWithSize(leftover1Sizes);
  final Region lr2 = mockRegionWithSize(leftover2Sizes);
  final FileSystemUtilizationChore chore = new FileSystemUtilizationChore(rs) {
    @Override
    Iterator<Region> getLeftoverRegions() {
      return Arrays.asList(lr1, lr2).iterator();
    }
  };
  doAnswer(new ExpectedRegionSizeSummationAnswer(sum(Arrays.asList(leftover1Sum, leftover2Sum))))
      .when(rs)
      .reportRegionSizesForQuotas(any(RegionSizeStore.class));

  // We shouldn't compute all of these region sizes, just the leftovers
  final Region r1 = mockRegionWithSize(Arrays.asList(1024L, 2048L));
  final Region r2 = mockRegionWithSize(Arrays.asList(1024L * 1024L));
  final Region r3 = mockRegionWithSize(Arrays.asList(10L * 1024L * 1024L));
  Mockito.doReturn(Arrays.asList(r1, r2, r3, lr1, lr2)).when(rs).getRegions();

  chore.chore();
}
 
Example 21
Source Project: hbase   Source File: TestCloseRegionWhileRSCrash.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  UTIL.getConfiguration().setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 1);
  UTIL.startMiniCluster(3);
  UTIL.createTable(TABLE_NAME, CF);
  UTIL.getAdmin().balancerSwitch(false, true);
  HRegionServer srcRs = UTIL.getRSForFirstRegionInTable(TABLE_NAME);
  if (!srcRs.getRegions(TableName.META_TABLE_NAME).isEmpty()) {
    RegionInfo metaRegion = srcRs.getRegions(TableName.META_TABLE_NAME).get(0).getRegionInfo();
    HRegionServer dstRs = UTIL.getOtherRegionServer(srcRs);
    UTIL.getAdmin().move(metaRegion.getEncodedNameAsBytes(), dstRs.getServerName());
    UTIL.waitFor(30000, () -> !dstRs.getRegions(TableName.META_TABLE_NAME).isEmpty());
  }
}
 
Example 22
Source Project: hbase   Source File: TestFileSystemUtilizationChore.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testNoOnlineRegions() {
  // One region with a store size of one.
  final List<Long> regionSizes = Collections.emptyList();
  final Configuration conf = getDefaultHBaseConfiguration();
  final HRegionServer rs = mockRegionServer(conf);
  final FileSystemUtilizationChore chore = new FileSystemUtilizationChore(rs);
  doAnswer(new ExpectedRegionSizeSummationAnswer(sum(regionSizes)))
      .when(rs)
      .reportRegionSizesForQuotas(any(RegionSizeStore.class));

  final Region region = mockRegionWithSize(regionSizes);
  Mockito.doReturn(Arrays.asList(region)).when(rs).getRegions();
  chore.chore();
}
 
Example 23
Source Project: hbase   Source File: TestFlushFromClient.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAsyncFlushRegionServer() throws Exception {
  AsyncAdmin admin = asyncConn.getAdmin();
  for (HRegionServer rs : TEST_UTIL.getHBaseCluster()
    .getLiveRegionServerThreads()
    .stream().map(JVMClusterUtil.RegionServerThread::getRegionServer)
    .collect(Collectors.toList())) {
    admin.flushRegionServer(rs.getServerName()).get();
    assertFalse(getRegionInfo(rs).stream().anyMatch(r -> r.getMemStoreDataSize() != 0));
  }
}
 
Example 24
Source Project: hbase   Source File: FileSystemUtilizationChore.java    License: Apache License 2.0 5 votes vote down vote up
public FileSystemUtilizationChore(HRegionServer rs) {
  super(FileSystemUtilizationChore.class.getSimpleName(), rs, getPeriod(rs.getConfiguration()),
      getInitialDelay(rs.getConfiguration()), getTimeUnit(rs.getConfiguration()));
  this.rs = rs;
  this.maxIterationMillis = rs.getConfiguration().getLong(
      FS_UTILIZATION_MAX_ITERATION_DURATION_KEY, FS_UTILIZATION_MAX_ITERATION_DURATION_DEFAULT);
}
 
Example 25
Source Project: hbase   Source File: TestScannerTimeout.java    License: 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 26
Source Project: hbase   Source File: TestRegionMover.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testExcludeAndDecomServers() throws Exception {
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  File excludeFile = new File(TEST_UTIL.getDataTestDir().toUri().getPath(), "exclude_file");
  FileWriter fos = new FileWriter(excludeFile);
  HRegionServer excludeServer = cluster.getRegionServer(1);
  String excludeHostname = excludeServer.getServerName().getHostname();
  int excludeServerPort = excludeServer.getServerName().getPort();
  String excludeServerName = excludeHostname + ":" + Integer.toString(excludeServerPort);
  fos.write(excludeServerName);
  fos.close();

  HRegionServer decomServer = cluster.getRegionServer(2);
  TEST_UTIL.getAdmin().decommissionRegionServers(
    Collections.singletonList(decomServer.getServerName()), false);

  waitForServerDecom(decomServer);

  HRegionServer regionServer = cluster.getRegionServer(0);
  String rsName = regionServer.getServerName().getHostname();
  int port = regionServer.getServerName().getPort();
  String sourceServer = rsName + ":" + Integer.toString(port);
  RegionMoverBuilder rmBuilder =
    new RegionMoverBuilder(sourceServer, TEST_UTIL.getConfiguration())
      .ack(true)
      .excludeFile(excludeFile.getCanonicalPath());
  try (RegionMover regionMover = rmBuilder.build()) {
    Assert.assertFalse(regionMover.unload());
  }

  TEST_UTIL.getAdmin().recommissionRegionServer(decomServer.getServerName(),
    Collections.emptyList());
}
 
Example 27
Source Project: hbase   Source File: HBaseTestingUtility.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tool to get the reference to the region server object that holds the
 * region of the specified user table.
 * @param tableName user table to lookup in hbase:meta
 * @return region server that holds it, null if the row doesn't exist
 * @throws IOException
 * @throws InterruptedException
 */
public HRegionServer getRSForFirstRegionInTable(TableName tableName)
    throws IOException, InterruptedException {
  List<RegionInfo> regions = getRegions(tableName);
  if (regions == null || regions.isEmpty()) {
    return null;
  }
  LOG.debug("Found " + regions.size() + " regions for table " +
      tableName);

  byte[] firstRegionName = regions.stream()
      .filter(r -> !r.isOffline())
      .map(RegionInfo::getRegionName)
      .findFirst()
      .orElseThrow(() -> new IOException("online regions not found in table " + tableName));

  LOG.debug("firstRegionName=" + Bytes.toString(firstRegionName));
  long pause = getConfiguration().getLong(HConstants.HBASE_CLIENT_PAUSE,
    HConstants.DEFAULT_HBASE_CLIENT_PAUSE);
  int numRetries = getConfiguration().getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
    HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
  RetryCounter retrier = new RetryCounter(numRetries+1, (int)pause, TimeUnit.MICROSECONDS);
  while(retrier.shouldRetry()) {
    int index = getMiniHBaseCluster().getServerWith(firstRegionName);
    if (index != -1) {
      return getMiniHBaseCluster().getRegionServerThreads().get(index).getRegionServer();
    }
    // Came back -1.  Region may not be online yet.  Sleep a while.
    retrier.sleepUntilNextRetry();
  }
  return null;
}
 
Example 28
@Test
public void testCachedConnections() throws Exception {
  final String tableName = generateUniqueName();
  final String index1Name = generateUniqueName();
  final Connection conn = DriverManager.getConnection(getUrl());

  final HBaseAdmin admin = getUtility().getHBaseAdmin();
  final MiniHBaseCluster cluster = getUtility().getHBaseCluster();
  final HRegionServer regionServer = cluster.getRegionServer(0);
  Configuration conf = admin.getConfiguration();
  final int noOfOrgs = 20;
  final AtomicBoolean flag = new AtomicBoolean();
  flag.set(false);
  // create table and indices
  String createTableSql = "CREATE TABLE " + tableName
      + "(org_id VARCHAR NOT NULL PRIMARY KEY, v1 INTEGER, v2 INTEGER, v3 INTEGER) VERSIONS=1 SPLIT ON ('"
      + ORG_PREFIX + "-" + noOfOrgs / 2 + "')";
  conn.createStatement().execute(createTableSql);
  conn.createStatement().execute("CREATE INDEX " + index1Name + " ON " + tableName + "(v1)");
  List<HRegionInfo> regions = admin.getTableRegions(TableName.valueOf(tableName));
  final HRegionInfo regionInfo = regions.get(0);

  writeToTable(tableName, conn, noOfOrgs);
  int beforeRegionCloseCount = getActiveConnections(regionServer, conf);
  int regionsCount = admin.getOnlineRegions(regionServer.getServerName()).size();
  admin.unassign(regionInfo.getEncodedNameAsBytes(), true);
  while(!(admin.getOnlineRegions(regionServer.getServerName()).size() < regionsCount));
  int afterRegionCloseCount = getActiveConnections(regionServer, conf);
  assertTrue("Cached connections not closed when region closes: ",
  afterRegionCloseCount == beforeRegionCloseCount && afterRegionCloseCount > 0);

}
 
Example 29
Source Project: hbase   Source File: AssignRegionHandler.java    License: Apache License 2.0 5 votes vote down vote up
public AssignRegionHandler(HRegionServer server, RegionInfo regionInfo, long openProcId,
    @Nullable TableDescriptor tableDesc, long masterSystemTime, EventType eventType) {
  super(server, eventType);
  this.regionInfo = regionInfo;
  this.openProcId = openProcId;
  this.tableDesc = tableDesc;
  this.masterSystemTime = masterSystemTime;
  this.retryCounter = HandlerUtil.getRetryCounter();
}
 
Example 30
Source Project: hbase   Source File: AssignRegionHandler.java    License: 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);
}