本文整理了Java中org.apache.hadoop.hbase.HBaseTestingUtility.getRSForFirstRegionInTable()
方法的一些代码示例,展示了HBaseTestingUtility.getRSForFirstRegionInTable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HBaseTestingUtility.getRSForFirstRegionInTable()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.HBaseTestingUtility
类名称:HBaseTestingUtility
方法名:getRSForFirstRegionInTable
[英]Tool to get the reference to the region server object that holds the region of the specified user table.
[中]工具获取对区域服务器对象的引用,该对象保存指定用户表的区域。
代码示例来源:origin: apache/hbase
private static HRegion find(final TableName tableName)
throws IOException, InterruptedException {
HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(tableName);
List<HRegion> regions = rs.getRegions(tableName);
assertEquals(1, regions.size());
return regions.get(0);
}
代码示例来源:origin: apache/hbase
@Override
public boolean evaluate() throws Exception {
ServerName newServerName = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName();
return newServerName != null && !newServerName.equals(serverName);
}
代码示例来源:origin: apache/hbase
private static List<Path> findStorefilePaths(TableName tableName) throws Exception {
List<Path> paths = new ArrayList<>();
for (Region region : TEST_UTIL.getRSForFirstRegionInTable(tableName)
.getRegions(tableName)) {
for (HStore store : ((HRegion) region).getStores()) {
for (HStoreFile storefile : store.getStorefiles()) {
paths.add(storefile.getPath());
}
}
}
return paths;
}
代码示例来源:origin: apache/hbase
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;
}
代码示例来源:origin: apache/hbase
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(),
Bytes.toBytes(rs.getServerName().getServerName()));
while (UTIL.getRSForFirstRegionInTable(tableName) != rs) {
Thread.sleep(100);
}
}
代码示例来源:origin: apache/hbase
@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));
pids = hbck.scheduleServerCrashProcedure(Arrays.asList(ProtobufUtil.toServerName(serverName)));
assertTrue(pids.get(0) == -1);
LOG.info("pid is {}", pids.get(0));
}
代码示例来源:origin: apache/hbase
@BeforeClass
public static void setup() throws Exception {
final TableName tableName = TableName.valueOf("tableName");
TEST_UTIL = HBaseTestingUtility.createLocalHTU();
CONF = TEST_UTIL.getConfiguration();
THRESHOLD = CONF.getInt(RSRpcServices.BATCH_ROWS_THRESHOLD_NAME,
RSRpcServices.BATCH_ROWS_THRESHOLD_DEFAULT);
TEST_UTIL.startMiniCluster();
TEST_UTIL.createTable(tableName, TEST_FAM);
RS = TEST_UTIL.getRSForFirstRegionInTable(tableName);
}
代码示例来源:origin: apache/hbase
private List<Path> findStorefilePaths(TableName tableName) throws Exception {
List<Path> paths = new ArrayList<>();
for (Region region : TEST_UTIL.getRSForFirstRegionInTable(tableName)
.getRegions(htd.getTableName())) {
for (HStore store : ((HRegion) region).getStores()) {
for (HStoreFile storefile : store.getStorefiles()) {
paths.add(storefile.getPath());
}
}
}
return paths;
}
代码示例来源:origin: apache/hbase
private static List<Path> findStorefilePaths(TableName tableName) throws Exception {
List<Path> paths = new ArrayList<>();
for (Region region:
TEST_UTIL.getRSForFirstRegionInTable(tableName).getRegions(htd.getTableName())) {
for (HStore store : ((HRegion) region).getStores()) {
for (HStoreFile storefile : store.getStorefiles()) {
paths.add(storefile.getPath());
}
}
}
return paths;
}
代码示例来源:origin: apache/hbase
public static void waitForTableToBeOnline(final HBaseTestingUtility util,
final TableName tableName)
throws IOException, InterruptedException {
HRegionServer rs = util.getRSForFirstRegionInTable(tableName);
List<HRegion> onlineRegions = rs.getRegions(tableName);
for (HRegion region : onlineRegions) {
region.waitForFlushesAndCompactions();
}
// Wait up to 60 seconds for a table to be available.
util.waitFor(60000, util.predicateTableAvailable(tableName));
}
代码示例来源:origin: apache/hbase
private static List<Path> findCompactedStorefilePaths(TableName tableName) throws Exception {
List<Path> paths = new ArrayList<>();
for (Region region : TEST_UTIL.getRSForFirstRegionInTable(tableName)
.getRegions(tableName)) {
for (HStore store : ((HRegion) region).getStores()) {
Collection<HStoreFile> compactedfiles =
store.getStoreEngine().getStoreFileManager().getCompactedfiles();
if (compactedfiles != null) {
for (HStoreFile storefile : compactedfiles) {
paths.add(storefile.getPath());
}
}
}
}
return paths;
}
代码示例来源:origin: apache/hbase
@Test
public void testSingleRegionTable() throws IOException, InterruptedException, ExecutionException {
createSingleRegionTable();
ServerName serverName = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName();
for (RegionLocateType locateType : RegionLocateType.values()) {
assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, serverName,
getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType, false).get());
}
byte[] randKey = new byte[ThreadLocalRandom.current().nextInt(128)];
ThreadLocalRandom.current().nextBytes(randKey);
for (RegionLocateType locateType : RegionLocateType.values()) {
assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, serverName,
getDefaultRegionLocation(TABLE_NAME, randKey, locateType, false).get());
}
}
代码示例来源:origin: apache/hbase
protected void startAndWriteData() throws IOException, InterruptedException {
// When the hbase:meta table can be opened, the region servers are running
TEST_UTIL.getConnection().getTable(TableName.META_TABLE_NAME);
this.server = cluster.getRegionServerThreads().get(0).getRegionServer();
Table table = createTestTable(this.tableName);
server = TEST_UTIL.getRSForFirstRegionInTable(table.getName());
for (int i = 1; i <= 256; i++) { // 256 writes should cause 8 log rolls
doPut(table, i);
if (i % 32 == 0) {
// After every 32 writes sleep to let the log roller run
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// continue
}
}
}
}
代码示例来源:origin: apache/hbase
@Test
public void testRegionMove() 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));
moveRegion(region, rs);
try (Table table = UTIL.getConnection().getTable(tableName)) {
for (int i = 100; i < 200; i++) {
table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
}
}
enablePeerAndWaitUntilReplicationDone(200);
checkOrder(200);
}
代码示例来源:origin: apache/hbase
@Test
public void testAddPeer() 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);
addPeer(true);
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);
}
代码示例来源:origin: apache/hbase
@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(),
Bytes.toBytes(dstRs.getServerName().getServerName()));
UTIL.waitFor(30000, () -> !dstRs.getRegions(TableName.META_TABLE_NAME).isEmpty());
}
}
代码示例来源:origin: apache/hbase
@BeforeClass
public static void setUp() throws Exception {
UTIL.getConfiguration().setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 1);
UTIL.getConfiguration().setBoolean("hbase.regionserver.hlog.enabled", false);
UTIL.startMiniCluster(2);
UTIL.createTable(TABLE_NAME, CF);
UTIL.waitTableAvailable(TABLE_NAME);
HRegionServer rs = UTIL.getRSForFirstRegionInTable(TABLE_NAME);
if (!rs.getRegions(TableName.META_TABLE_NAME).isEmpty()) {
HRegionServer rs1 = UTIL.getOtherRegionServer(rs);
UTIL.moveRegionAndWait(
UTIL.getMiniHBaseCluster().getRegions(TABLE_NAME).get(0).getRegionInfo(),
rs1.getServerName());
}
UTIL.getAdmin().balancerSwitch(false, true);
}
代码示例来源:origin: apache/hbase
@Test
public void test() throws IOException, InterruptedException {
HRegion region = UTIL.getMiniHBaseCluster().getRegions(TABLE_NAME).get(0);
long openSeqNum = region.getOpenSeqNum();
HRegionServer src = UTIL.getRSForFirstRegionInTable(TABLE_NAME);
HRegionServer dst = UTIL.getOtherRegionServer(src);
// will fail two times, and then verify that the open sequence number is still openSeqNum + 2
FAILED_OPEN.set(2);
UTIL.getAdmin().move(region.getRegionInfo().getEncodedNameAsBytes(),
Bytes.toBytes(dst.getServerName().getServerName()));
UTIL.waitTableAvailable(TABLE_NAME);
HRegion region1 = UTIL.getMiniHBaseCluster().getRegions(TABLE_NAME).get(0);
long openSeqNum1 = region1.getOpenSeqNum();
assertEquals(openSeqNum + 2, openSeqNum1);
}
}
代码示例来源:origin: apache/hbase
@Test
public void testRecoveryAndDoubleExecutionReopen() throws Exception {
MasterProcedureEnv env =
UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getEnvironment();
HRegionServer rs = UTIL.getRSForFirstRegionInTable(tableName);
HRegion region = rs.getRegions(tableName).get(0);
long openSeqNum = region.getOpenSeqNum();
TransitRegionStateProcedure proc =
TransitRegionStateProcedure.reopen(env, region.getRegionInfo());
testRecoveryAndDoubleExcution(proc);
// should still be on the same RS
HRegion region2 = rs.getRegions(tableName).get(0);
long openSeqNum2 = region2.getOpenSeqNum();
// confirm that the region is successfully opened
assertTrue(openSeqNum2 > openSeqNum);
}
代码示例来源:origin: apache/hbase
@Test
public void testLogRollOnDatanodeDeath() throws IOException, InterruptedException {
dfsCluster.startDataNodes(TEST_UTIL.getConfiguration(), 3, true, null, null);
tableName = getName();
Table table = createTestTable(tableName);
TEST_UTIL.waitUntilAllRegionsAssigned(table.getName());
doPut(table, 1);
server = TEST_UTIL.getRSForFirstRegionInTable(table.getName());
RegionInfo hri = server.getRegions(table.getName()).get(0).getRegionInfo();
AsyncFSWAL wal = (AsyncFSWAL) server.getWAL(hri);
int numRolledLogFiles = AsyncFSWALProvider.getNumRolledLogFiles(wal);
DatanodeInfo[] dnInfos = wal.getPipeline();
DataNodeProperties dnProp = TEST_UTIL.getDFSCluster().stopDataNode(dnInfos[0].getName());
TEST_UTIL.getDFSCluster().restartDataNode(dnProp);
doPut(table, 2);
assertEquals(numRolledLogFiles + 1, AsyncFSWALProvider.getNumRolledLogFiles(wal));
}
}
内容来源于网络,如有侵权,请联系作者删除!