Search in sources :

Example 76 with SingleProcessHBaseCluster

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());
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Assert.assertNotNull(org.junit.Assert.assertNotNull) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) Assert.assertThrows(org.junit.Assert.assertThrows) Assert.assertTrue(org.junit.Assert.assertTrue) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) IOException(java.io.IOException) SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) ReplicationPeerNotFoundException(org.apache.hadoop.hbase.ReplicationPeerNotFoundException) ServerRegionReplicaUtil(org.apache.hadoop.hbase.util.ServerRegionReplicaUtil) RegionServerTests(org.apache.hadoop.hbase.testclassification.RegionServerTests) ServerCrashProcedure(org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure) ClassRule(org.junit.ClassRule) HMaster(org.apache.hadoop.hbase.master.HMaster) ServerName(org.apache.hadoop.hbase.ServerName) ReplicationUtils(org.apache.hadoop.hbase.replication.ReplicationUtils) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) ServerCrashProcedure(org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread) Test(org.junit.Test)

Example 77 with SingleProcessHBaseCluster

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);
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) Table(org.apache.hadoop.hbase.client.Table) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Admin(org.apache.hadoop.hbase.client.Admin) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Put(org.apache.hadoop.hbase.client.Put) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) JVMClusterUtil(org.apache.hadoop.hbase.util.JVMClusterUtil) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Example 78 with SingleProcessHBaseCluster

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());
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) BeforeClass(org.junit.BeforeClass) LoggerFactory(org.slf4j.LoggerFactory) SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) ArrayList(java.util.ArrayList) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TestName(org.junit.rules.TestName) After(org.junit.After) ClassRule(org.junit.ClassRule) Before(org.junit.Before) MiscTests(org.apache.hadoop.hbase.testclassification.MiscTests) TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Put(org.apache.hadoop.hbase.client.Put) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) LargeTests(org.apache.hadoop.hbase.testclassification.LargeTests) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Rule(org.junit.Rule) Admin(org.apache.hadoop.hbase.client.Admin) Table(org.apache.hadoop.hbase.client.Table) Assert(org.junit.Assert) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Table(org.apache.hadoop.hbase.client.Table) ArrayList(java.util.ArrayList) Admin(org.apache.hadoop.hbase.client.Admin) Put(org.apache.hadoop.hbase.client.Put) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) TableName(org.apache.hadoop.hbase.TableName) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) Test(org.junit.Test)

Example 79 with SingleProcessHBaseCluster

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());
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) BeforeClass(org.junit.BeforeClass) LoggerFactory(org.slf4j.LoggerFactory) SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) ArrayList(java.util.ArrayList) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TestName(org.junit.rules.TestName) After(org.junit.After) ClassRule(org.junit.ClassRule) Before(org.junit.Before) MiscTests(org.apache.hadoop.hbase.testclassification.MiscTests) TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Put(org.apache.hadoop.hbase.client.Put) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) LargeTests(org.apache.hadoop.hbase.testclassification.LargeTests) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Rule(org.junit.Rule) Admin(org.apache.hadoop.hbase.client.Admin) Table(org.apache.hadoop.hbase.client.Table) Assert(org.junit.Assert) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Table(org.apache.hadoop.hbase.client.Table) ArrayList(java.util.ArrayList) Admin(org.apache.hadoop.hbase.client.Admin) Put(org.apache.hadoop.hbase.client.Put) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) TableName(org.apache.hadoop.hbase.TableName) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) Test(org.junit.Test)

Example 80 with SingleProcessHBaseCluster

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());
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) BeforeClass(org.junit.BeforeClass) LoggerFactory(org.slf4j.LoggerFactory) SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) ArrayList(java.util.ArrayList) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TestName(org.junit.rules.TestName) After(org.junit.After) ClassRule(org.junit.ClassRule) Before(org.junit.Before) MiscTests(org.apache.hadoop.hbase.testclassification.MiscTests) TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Put(org.apache.hadoop.hbase.client.Put) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) LargeTests(org.apache.hadoop.hbase.testclassification.LargeTests) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Collectors(java.util.stream.Collectors) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Rule(org.junit.Rule) Admin(org.apache.hadoop.hbase.client.Admin) Table(org.apache.hadoop.hbase.client.Table) Assert(org.junit.Assert) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Table(org.apache.hadoop.hbase.client.Table) ArrayList(java.util.ArrayList) Admin(org.apache.hadoop.hbase.client.Admin) Put(org.apache.hadoop.hbase.client.Put) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) TableName(org.apache.hadoop.hbase.TableName) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) Test(org.junit.Test)

Aggregations

SingleProcessHBaseCluster (org.apache.hadoop.hbase.SingleProcessHBaseCluster)85 Test (org.junit.Test)69 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)31 TableName (org.apache.hadoop.hbase.TableName)26 Admin (org.apache.hadoop.hbase.client.Admin)24 Table (org.apache.hadoop.hbase.client.Table)22 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)22 HMaster (org.apache.hadoop.hbase.master.HMaster)21 ServerName (org.apache.hadoop.hbase.ServerName)18 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)18 HBaseTestingUtil (org.apache.hadoop.hbase.HBaseTestingUtil)14 MasterCoprocessorHost (org.apache.hadoop.hbase.master.MasterCoprocessorHost)13 IOException (java.io.IOException)12 Configuration (org.apache.hadoop.conf.Configuration)12 Put (org.apache.hadoop.hbase.client.Put)12 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)12 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)10 File (java.io.File)9 Path (org.apache.hadoop.fs.Path)9 RegionMoverBuilder (org.apache.hadoop.hbase.util.RegionMover.RegionMoverBuilder)9