use of org.apache.hadoop.hbase.SingleProcessHBaseCluster in project hbase by apache.
the class TestStartupWithLegacyRegionReplicationEndpoint method test.
@Test
public void test() throws Exception {
ReplicationPeerConfig peerConfig = ReplicationPeerConfig.newBuilder().setClusterKey("127.0.0.1:2181:/hbase").setReplicationEndpointImpl(ReplicationUtils.LEGACY_REGION_REPLICATION_ENDPOINT_NAME).build();
SingleProcessHBaseCluster cluster = UTIL.getMiniHBaseCluster();
HMaster master = cluster.getMaster();
// can not use Admin.addPeer as it will fail with ClassNotFound
master.getReplicationPeerManager().addPeer("legacy", peerConfig, true);
// add a wal file to the queue
ServerName rsName = cluster.getRegionServer(0).getServerName();
master.getReplicationPeerManager().getQueueStorage().addWAL(rsName, ServerRegionReplicaUtil.REGION_REPLICA_REPLICATION_PEER, "test-wal-file");
cluster.stopRegionServer(0);
RegionServerThread rst = cluster.startRegionServer();
// we should still have this peer
assertNotNull(UTIL.getAdmin().getReplicationPeerConfig("legacy"));
// but at RS side, we should not have this peer loaded as replication source
assertTrue(rst.getRegionServer().getReplicationSourceService().getReplicationManager().getSources().isEmpty());
UTIL.shutdownMiniHBaseCluster();
UTIL.restartHBaseCluster(1);
// now we should have removed the peer
assertThrows(ReplicationPeerNotFoundException.class, () -> UTIL.getAdmin().getReplicationPeerConfig("legacy"));
// at rs side, we should not have the peer this time, not only for not having replication source
assertTrue(UTIL.getMiniHBaseCluster().getRegionServer(0).getReplicationSourceService().getReplicationManager().getReplicationPeers().getAllPeerIds().isEmpty());
// make sure that we can finish the SCP and delete the test-wal-file
UTIL.waitFor(15000, () -> UTIL.getMiniHBaseCluster().getMaster().getProcedures().stream().filter(p -> p instanceof ServerCrashProcedure).map(p -> (ServerCrashProcedure) p).allMatch(Procedure::isSuccess));
assertTrue(UTIL.getMiniHBaseCluster().getMaster().getReplicationPeerManager().getQueueStorage().getAllQueues(rsName).isEmpty());
}
use of org.apache.hadoop.hbase.SingleProcessHBaseCluster in project hbase by apache.
the class TestAccessController method testGlobalAuthorizationForNewRegisteredRS.
@Test
public void testGlobalAuthorizationForNewRegisteredRS() throws Exception {
LOG.debug("Test for global authorization for a new registered RegionServer.");
SingleProcessHBaseCluster hbaseCluster = TEST_UTIL.getHBaseCluster();
final Admin admin = TEST_UTIL.getAdmin();
TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(TEST_TABLE2).setColumnFamily(ColumnFamilyDescriptorBuilder.of(TEST_FAMILY)).build();
createTable(TEST_UTIL, tableDescriptor);
// Starting a new RegionServer.
JVMClusterUtil.RegionServerThread newRsThread = hbaseCluster.startRegionServer();
final HRegionServer newRs = newRsThread.getRegionServer();
// Move region to the new RegionServer.
List<HRegionLocation> regions;
try (RegionLocator locator = systemUserConnection.getRegionLocator(TEST_TABLE2)) {
regions = locator.getAllRegionLocations();
}
HRegionLocation location = regions.get(0);
final RegionInfo hri = location.getRegion();
final ServerName server = location.getServerName();
try (Table table = systemUserConnection.getTable(TEST_TABLE2)) {
AccessTestAction moveAction = new AccessTestAction() {
@Override
public Object run() throws Exception {
admin.move(hri.getEncodedNameAsBytes(), newRs.getServerName());
return null;
}
};
SUPERUSER.runAs(moveAction);
final int RETRIES_LIMIT = 10;
int retries = 0;
while (newRs.getRegions(TEST_TABLE2).size() < 1 && retries < RETRIES_LIMIT) {
LOG.debug("Waiting for region to be opened. Already retried " + retries + " times.");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
retries++;
if (retries == RETRIES_LIMIT - 1) {
fail("Retry exhaust for waiting region to be opened.");
}
}
// Verify write permission for user "admin2" who has the global
// permissions.
AccessTestAction putAction = new AccessTestAction() {
@Override
public Object run() throws Exception {
Put put = new Put(Bytes.toBytes("test"));
put.addColumn(TEST_FAMILY, Bytes.toBytes("qual"), Bytes.toBytes("value"));
table.put(put);
return null;
}
};
USER_ADMIN.runAs(putAction);
}
}
use of org.apache.hadoop.hbase.SingleProcessHBaseCluster in project hbase by apache.
the class TestRegionMover2 method testFailedRegionMove.
@Test
public void testFailedRegionMove() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
Admin admin = TEST_UTIL.getAdmin();
Table table = TEST_UTIL.getConnection().getTable(tableName);
List<Put> puts = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
puts.add(new Put(Bytes.toBytes("rowkey_" + i)).addColumn(Bytes.toBytes("fam1"), Bytes.toBytes("q1"), Bytes.toBytes("val_" + i)));
}
table.put(puts);
admin.flush(tableName);
HRegionServer regionServer = cluster.getRegionServer(0);
String rsName = regionServer.getServerName().getAddress().toString();
int numRegions = regionServer.getNumberOfOnlineRegions();
List<HRegion> hRegions = regionServer.getRegions().stream().filter(hRegion -> hRegion.getRegionInfo().getTable().equals(tableName)).collect(Collectors.toList());
RegionMover.RegionMoverBuilder rmBuilder = new RegionMover.RegionMoverBuilder(rsName, TEST_UTIL.getConfiguration()).ack(true).maxthreads(8);
try (RegionMover rm = rmBuilder.build()) {
LOG.debug("Unloading {}", regionServer.getServerName());
rm.unload();
Assert.assertEquals(0, regionServer.getNumberOfOnlineRegions());
LOG.debug("Successfully Unloaded, now Loading");
admin.offline(hRegions.get(0).getRegionInfo().getRegionName());
// loading regions will fail because of offline region
Assert.assertFalse(rm.load());
}
}
use of org.apache.hadoop.hbase.SingleProcessHBaseCluster in project hbase by apache.
the class TestRegionMover2 method testWithSplitRegions.
@Test
public void testWithSplitRegions() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
Admin admin = TEST_UTIL.getAdmin();
Table table = TEST_UTIL.getConnection().getTable(tableName);
List<Put> puts = new ArrayList<>();
for (int i = 10; i < 50000; i++) {
puts.add(new Put(Bytes.toBytes(i)).addColumn(Bytes.toBytes("fam1"), Bytes.toBytes("q1"), Bytes.toBytes("val_" + i)));
}
table.put(puts);
admin.flush(tableName);
admin.compact(tableName);
HRegionServer regionServer = cluster.getRegionServer(0);
String rsName = regionServer.getServerName().getAddress().toString();
int numRegions = regionServer.getNumberOfOnlineRegions();
List<HRegion> hRegions = regionServer.getRegions().stream().filter(hRegion -> hRegion.getRegionInfo().getTable().equals(tableName)).collect(Collectors.toList());
RegionMover.RegionMoverBuilder rmBuilder = new RegionMover.RegionMoverBuilder(rsName, TEST_UTIL.getConfiguration()).ack(true).maxthreads(8);
try (RegionMover rm = rmBuilder.build()) {
LOG.debug("Unloading {}", regionServer.getServerName());
rm.unload();
Assert.assertEquals(0, regionServer.getNumberOfOnlineRegions());
LOG.debug("Successfully Unloaded, now Loading");
HRegion hRegion = hRegions.get(1);
if (hRegion.getRegionInfo().getStartKey().length == 0) {
hRegion = hRegions.get(0);
}
int startKey = 0;
int endKey = Integer.MAX_VALUE;
if (hRegion.getRegionInfo().getStartKey().length > 0) {
startKey = Bytes.toInt(hRegion.getRegionInfo().getStartKey());
}
if (hRegion.getRegionInfo().getEndKey().length > 0) {
endKey = Bytes.toInt(hRegion.getRegionInfo().getEndKey());
}
int midKey = startKey + (endKey - startKey) / 2;
admin.splitRegionAsync(hRegion.getRegionInfo().getRegionName(), Bytes.toBytes(midKey)).get(5, TimeUnit.SECONDS);
Assert.assertTrue(rm.load());
Assert.assertEquals(numRegions - 1, regionServer.getNumberOfOnlineRegions());
}
}
use of org.apache.hadoop.hbase.SingleProcessHBaseCluster in project hbase by apache.
the class TestRegionMover2 method testWithMergedRegions.
@Test
public void testWithMergedRegions() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
Admin admin = TEST_UTIL.getAdmin();
Table table = TEST_UTIL.getConnection().getTable(tableName);
List<Put> puts = new ArrayList<>();
for (int i = 0; i < 10000; i++) {
puts.add(new Put(Bytes.toBytes("rowkey_" + i)).addColumn(Bytes.toBytes("fam1"), Bytes.toBytes("q1"), Bytes.toBytes("val_" + i)));
}
table.put(puts);
admin.flush(tableName);
HRegionServer regionServer = cluster.getRegionServer(0);
String rsName = regionServer.getServerName().getAddress().toString();
int numRegions = regionServer.getNumberOfOnlineRegions();
List<HRegion> hRegions = regionServer.getRegions().stream().filter(hRegion -> hRegion.getRegionInfo().getTable().equals(tableName)).collect(Collectors.toList());
RegionMover.RegionMoverBuilder rmBuilder = new RegionMover.RegionMoverBuilder(rsName, TEST_UTIL.getConfiguration()).ack(true).maxthreads(8);
try (RegionMover rm = rmBuilder.build()) {
LOG.debug("Unloading {}", regionServer.getServerName());
rm.unload();
Assert.assertEquals(0, regionServer.getNumberOfOnlineRegions());
LOG.debug("Successfully Unloaded, now Loading");
admin.mergeRegionsAsync(new byte[][] { hRegions.get(0).getRegionInfo().getRegionName(), hRegions.get(1).getRegionInfo().getRegionName() }, true).get(5, TimeUnit.SECONDS);
Assert.assertTrue(rm.load());
Assert.assertEquals(numRegions - 2, regionServer.getNumberOfOnlineRegions());
}
}
Aggregations