use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class HBaseTestingUtility method getRSForFirstRegionInTable.
/**
* 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;
}
use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class HBaseTestingUtility method assertRegionOnlyOnServer.
/**
* Check to make sure the region is open on the specified
* region server, but not on any other one.
*/
public void assertRegionOnlyOnServer(final RegionInfo hri, final ServerName server, final long timeout) throws IOException, InterruptedException {
long timeoutTime = EnvironmentEdgeManager.currentTime() + timeout;
while (true) {
List<RegionInfo> regions = getAdmin().getRegions(server);
if (regions.stream().anyMatch(r -> RegionInfo.COMPARATOR.compare(r, hri) == 0)) {
List<JVMClusterUtil.RegionServerThread> rsThreads = getHBaseCluster().getLiveRegionServerThreads();
for (JVMClusterUtil.RegionServerThread rsThread : rsThreads) {
HRegionServer rs = rsThread.getRegionServer();
if (server.equals(rs.getServerName())) {
continue;
}
Collection<HRegion> hrs = rs.getOnlineRegionsLocalContext();
for (HRegion r : hrs) {
if (r.getRegionInfo().getRegionId() == hri.getRegionId()) {
throw new AssertionError("Region should not be double assigned");
}
}
}
// good, we are happy
return;
}
long now = EnvironmentEdgeManager.currentTime();
if (now > timeoutTime)
break;
Thread.sleep(10);
}
throw new AssertionError("Could not find region " + hri.getRegionNameAsString() + " on server " + server);
}
use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class MiniHBaseCluster method getServerWith.
/**
* Get the location of the specified region
* @param regionName Name of the region in bytes
* @return Index into List of {@link MiniHBaseCluster#getRegionServerThreads()}
* of HRS carrying hbase:meta. Returns -1 if none found.
*/
public int getServerWith(byte[] regionName) {
int index = 0;
for (JVMClusterUtil.RegionServerThread rst : getRegionServerThreads()) {
HRegionServer hrs = rst.getRegionServer();
if (!hrs.isStopped()) {
Region region = hrs.getOnlineRegion(regionName);
if (region != null) {
return index;
}
}
index++;
}
return -1;
}
use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class TestScannersFromClientSide method testScanOnReopenedRegion.
/**
* Test from client side for scan while the region is reopened
* on the same region server.
*/
@Test
public void testScanOnReopenedRegion() throws Exception {
final TableName tableName = name.getTableName();
byte[][] QUALIFIERS = HTestConst.makeNAscii(QUALIFIER, 2);
Table ht = TEST_UTIL.createTable(tableName, FAMILY);
Put put;
Scan scan;
Result result;
ResultScanner scanner;
boolean toLog = false;
List<Cell> kvListExp;
// table: row, family, c0:0, c1:1
put = new Put(ROW);
for (int i = 0; i < QUALIFIERS.length; i++) {
KeyValue kv = new KeyValue(ROW, FAMILY, QUALIFIERS[i], i, VALUE);
put.add(kv);
}
ht.put(put);
scan = new Scan().withStartRow(ROW);
scanner = ht.getScanner(scan);
HRegionLocation loc;
try (RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName)) {
loc = locator.getRegionLocation(ROW);
}
RegionInfo hri = loc.getRegion();
SingleProcessHBaseCluster cluster = TEST_UTIL.getMiniHBaseCluster();
byte[] regionName = hri.getRegionName();
int i = cluster.getServerWith(regionName);
HRegionServer rs = cluster.getRegionServer(i);
LOG.info("Unassigning " + hri);
TEST_UTIL.getAdmin().unassign(hri.getRegionName(), true);
long startTime = EnvironmentEdgeManager.currentTime();
long timeOut = 10000;
boolean offline = false;
while (true) {
if (rs.getOnlineRegion(regionName) == null) {
offline = true;
break;
}
assertTrue("Timed out in closing the testing region", EnvironmentEdgeManager.currentTime() < startTime + timeOut);
}
assertTrue(offline);
LOG.info("Assigning " + hri);
TEST_UTIL.getAdmin().assign(hri.getRegionName());
startTime = EnvironmentEdgeManager.currentTime();
while (true) {
rs = cluster.getRegionServer(cluster.getServerWith(regionName));
if (rs != null && rs.getOnlineRegion(regionName) != null) {
offline = false;
break;
}
assertTrue("Timed out in open the testing region", EnvironmentEdgeManager.currentTime() < startTime + timeOut);
}
assertFalse(offline);
// c0:0, c1:1
kvListExp = new ArrayList<>();
kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[0], 0, VALUE));
kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[1], 1, VALUE));
result = scanner.next();
verifyResult(result, kvListExp, toLog, "Testing scan on re-opened region");
}
use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.
the class TestSeparateClientZKCluster method testMetaMoveDuringClientZkClusterRestart.
@Test
public void testMetaMoveDuringClientZkClusterRestart() throws Exception {
TableName tn = name.getTableName();
// create table
Connection conn = TEST_UTIL.getConnection();
try (Admin admin = conn.getAdmin();
Table table = conn.getTable(tn)) {
ColumnFamilyDescriptorBuilder cfDescBuilder = ColumnFamilyDescriptorBuilder.newBuilder(family);
TableDescriptorBuilder tableDescBuilder = TableDescriptorBuilder.newBuilder(tn).setColumnFamily(cfDescBuilder.build());
admin.createTable(tableDescBuilder.build());
// put some data
Put put = new Put(row);
put.addColumn(family, qualifier, value);
table.put(put);
// invalid connection cache
conn.clearRegionLocationCache();
// stop client zk cluster
clientZkCluster.shutdown();
// stop current meta server and confirm the server shutdown process
// is not affected by client ZK crash
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
int metaServerId = cluster.getServerWithMeta();
HRegionServer metaServer = cluster.getRegionServer(metaServerId);
metaServer.stop("Stop current RS holding meta region");
while (metaServer.isAlive()) {
Thread.sleep(200);
}
// wait for meta region online
AssignmentTestingUtil.waitForAssignment(cluster.getMaster().getAssignmentManager(), RegionInfoBuilder.FIRST_META_REGIONINFO);
// wait some long time to make sure we will retry sync data to client ZK until data set
Thread.sleep(10000);
clientZkCluster.startup(clientZkDir);
// new request should pass
Get get = new Get(row);
Result result = table.get(get);
LOG.debug("Result: " + Bytes.toString(result.getValue(family, qualifier)));
assertArrayEquals(value, result.getValue(family, qualifier));
}
}
Aggregations