Search in sources :

Example 91 with TableName

use of org.apache.hadoop.hbase.TableName in project hbase by apache.

the class TestMasterObserver method testRegionTransitionOperations.

@Test(timeout = 180000)
public void testRegionTransitionOperations() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    MiniHBaseCluster cluster = UTIL.getHBaseCluster();
    HMaster master = cluster.getMaster();
    MasterCoprocessorHost host = master.getMasterCoprocessorHost();
    CPMasterObserver cp = (CPMasterObserver) host.findCoprocessor(CPMasterObserver.class.getName());
    cp.enableBypass(false);
    cp.resetStates();
    Table table = UTIL.createMultiRegionTable(tableName, TEST_FAMILY);
    try (RegionLocator r = UTIL.getConnection().getRegionLocator(tableName)) {
        UTIL.waitUntilAllRegionsAssigned(tableName);
        List<HRegionLocation> regions = r.getAllRegionLocations();
        HRegionLocation firstGoodPair = null;
        for (HRegionLocation e : regions) {
            if (e.getServerName() != null) {
                firstGoodPair = e;
                break;
            }
        }
        assertNotNull("Found a non-null entry", firstGoodPair);
        LOG.info("Found " + firstGoodPair.toString());
        // Try to force a move
        Collection<ServerName> servers = master.getClusterStatus().getServers();
        String destName = null;
        String serverNameForFirstRegion = firstGoodPair.getServerName().toString();
        LOG.info("serverNameForFirstRegion=" + serverNameForFirstRegion);
        ServerName masterServerName = master.getServerName();
        boolean found = false;
        // Find server that is NOT carrying the first region
        for (ServerName info : servers) {
            LOG.info("ServerName=" + info);
            if (!serverNameForFirstRegion.equals(info.getServerName()) && !masterServerName.equals(info)) {
                destName = info.toString();
                found = true;
                break;
            }
        }
        assertTrue("Found server", found);
        LOG.info("Found " + destName);
        master.getMasterRpcServices().moveRegion(null, RequestConverter.buildMoveRegionRequest(firstGoodPair.getRegionInfo().getEncodedNameAsBytes(), Bytes.toBytes(destName)));
        assertTrue("Coprocessor should have been called on region move", cp.wasMoveCalled());
        // make sure balancer is on
        master.balanceSwitch(true);
        assertTrue("Coprocessor should have been called on balance switch", cp.wasBalanceSwitchCalled());
        // turn balancer off
        master.balanceSwitch(false);
        // wait for assignments to finish, if any
        UTIL.waitUntilNoRegionsInTransition();
        // move half the open regions from RS 0 to RS 1
        HRegionServer rs = cluster.getRegionServer(0);
        byte[] destRS = Bytes.toBytes(cluster.getRegionServer(1).getServerName().toString());
        //Make sure no regions are in transition now
        UTIL.waitUntilNoRegionsInTransition();
        List<HRegionInfo> openRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices());
        int moveCnt = openRegions.size() / 2;
        for (int i = 0; i < moveCnt; i++) {
            HRegionInfo info = openRegions.get(i);
            if (!info.isMetaTable()) {
                master.getMasterRpcServices().moveRegion(null, RequestConverter.buildMoveRegionRequest(openRegions.get(i).getEncodedNameAsBytes(), destRS));
            }
        }
        //Make sure no regions are in transition now
        UTIL.waitUntilNoRegionsInTransition();
        // now trigger a balance
        master.balanceSwitch(true);
        boolean balanceRun = master.balance();
        assertTrue("Coprocessor should be called on region rebalancing", cp.wasBalanceCalled());
    } finally {
        Admin admin = UTIL.getAdmin();
        admin.disableTable(tableName);
        deleteTable(admin, tableName);
    }
}
Also used : RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) Table(org.apache.hadoop.hbase.client.Table) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) Admin(org.apache.hadoop.hbase.client.Admin) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) Test(org.junit.Test)

Example 92 with TableName

use of org.apache.hadoop.hbase.TableName in project hbase by apache.

the class TestCoprocessorHost method testDoubleLoadingAndPriorityValue.

@Test
public void testDoubleLoadingAndPriorityValue() {
    final Configuration conf = HBaseConfiguration.create();
    CoprocessorHost<CoprocessorEnvironment> host = new CoprocessorHost<CoprocessorEnvironment>(new TestAbortable()) {

        final Configuration cpHostConf = conf;

        @Override
        public CoprocessorEnvironment createEnvironment(Class<?> implClass, final Coprocessor instance, final int priority, int sequence, Configuration conf) {
            return new CoprocessorEnvironment() {

                final Coprocessor envInstance = instance;

                @Override
                public int getVersion() {
                    return 0;
                }

                @Override
                public String getHBaseVersion() {
                    return "0.0.0";
                }

                @Override
                public Coprocessor getInstance() {
                    return envInstance;
                }

                @Override
                public int getPriority() {
                    return priority;
                }

                @Override
                public int getLoadSequence() {
                    return 0;
                }

                @Override
                public Configuration getConfiguration() {
                    return cpHostConf;
                }

                @Override
                public Table getTable(TableName tableName) throws IOException {
                    return null;
                }

                @Override
                public Table getTable(TableName tableName, ExecutorService service) throws IOException {
                    return null;
                }

                @Override
                public ClassLoader getClassLoader() {
                    return null;
                }
            };
        }
    };
    final String key = "KEY";
    final String coprocessor = "org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver";
    // Try and load a coprocessor three times
    conf.setStrings(key, coprocessor, coprocessor, coprocessor, SimpleRegionObserverV2.class.getName());
    host.loadSystemCoprocessors(conf, key);
    // Two coprocessors(SimpleRegionObserver and SimpleRegionObserverV2) loaded
    Assert.assertEquals(2, host.coprocessors.size());
    // Check the priority value
    CoprocessorEnvironment simpleEnv = host.findCoprocessorEnvironment(SimpleRegionObserver.class.getName());
    CoprocessorEnvironment simpleEnv_v2 = host.findCoprocessorEnvironment(SimpleRegionObserverV2.class.getName());
    assertNotNull(simpleEnv);
    assertNotNull(simpleEnv_v2);
    assertEquals(Coprocessor.PRIORITY_SYSTEM, simpleEnv.getPriority());
    assertEquals(Coprocessor.PRIORITY_SYSTEM + 1, simpleEnv_v2.getPriority());
}
Also used : TableName(org.apache.hadoop.hbase.TableName) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) Coprocessor(org.apache.hadoop.hbase.Coprocessor) ExecutorService(java.util.concurrent.ExecutorService) CoprocessorEnvironment(org.apache.hadoop.hbase.CoprocessorEnvironment) Test(org.junit.Test)

Example 93 with TableName

use of org.apache.hadoop.hbase.TableName in project hbase by apache.

the class TestCoprocessorInterface method testSharedData.

@Test
public void testSharedData() throws IOException {
    TableName tableName = TableName.valueOf(name.getMethodName());
    byte[][] families = { fam1, fam2, fam3 };
    Configuration hc = initConfig();
    Region region = initHRegion(tableName, name.getMethodName(), hc, new Class<?>[] {}, families);
    for (int i = 0; i < 3; i++) {
        HBaseTestCase.addContent(region, fam3);
        region.flush(true);
    }
    region.compact(false);
    region = reopenRegion(region, CoprocessorImpl.class, CoprocessorII.class);
    Coprocessor c = region.getCoprocessorHost().findCoprocessor(CoprocessorImpl.class.getName());
    Coprocessor c2 = region.getCoprocessorHost().findCoprocessor(CoprocessorII.class.getName());
    Object o = ((CoprocessorImpl) c).getSharedData().get("test1");
    Object o2 = ((CoprocessorII) c2).getSharedData().get("test2");
    assertNotNull(o);
    assertNotNull(o2);
    // to coprocessors get different sharedDatas
    assertFalse(((CoprocessorImpl) c).getSharedData() == ((CoprocessorII) c2).getSharedData());
    c = region.getCoprocessorHost().findCoprocessor(CoprocessorImpl.class.getName());
    c2 = region.getCoprocessorHost().findCoprocessor(CoprocessorII.class.getName());
    // make sure that all coprocessor of a class have identical sharedDatas
    assertTrue(((CoprocessorImpl) c).getSharedData().get("test1") == o);
    assertTrue(((CoprocessorII) c2).getSharedData().get("test2") == o2);
    // now have all Environments fail
    try {
        byte[] r = region.getRegionInfo().getStartKey();
        if (r == null || r.length <= 0) {
            // Its the start row.  Can't ask for null.  Ask for minimal key instead.
            r = new byte[] { 0 };
        }
        Get g = new Get(r);
        region.get(g);
        fail();
    } catch (org.apache.hadoop.hbase.DoNotRetryIOException xc) {
    }
    assertNull(region.getCoprocessorHost().findCoprocessor(CoprocessorII.class.getName()));
    c = region.getCoprocessorHost().findCoprocessor(CoprocessorImpl.class.getName());
    assertTrue(((CoprocessorImpl) c).getSharedData().get("test1") == o);
    c = c2 = null;
    // perform a GC
    System.gc();
    // reopen the region
    region = reopenRegion(region, CoprocessorImpl.class, CoprocessorII.class);
    c = region.getCoprocessorHost().findCoprocessor(CoprocessorImpl.class.getName());
    // CPimpl is unaffected, still the same reference
    assertTrue(((CoprocessorImpl) c).getSharedData().get("test1") == o);
    c2 = region.getCoprocessorHost().findCoprocessor(CoprocessorII.class.getName());
    // new map and object created, hence the reference is different
    // hence the old entry was indeed removed by the GC and new one has been created
    Object o3 = ((CoprocessorII) c2).getSharedData().get("test2");
    assertFalse(o3 == o2);
    HBaseTestingUtility.closeRegionAndWAL(region);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) TableName(org.apache.hadoop.hbase.TableName) Coprocessor(org.apache.hadoop.hbase.Coprocessor) Get(org.apache.hadoop.hbase.client.Get) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) Region(org.apache.hadoop.hbase.regionserver.Region) Test(org.junit.Test)

Example 94 with TableName

use of org.apache.hadoop.hbase.TableName in project hbase by apache.

the class TestCoprocessorMetrics method testRegionObserverAfterRegionClosed.

@Test
public void testRegionObserverAfterRegionClosed() throws IOException {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
        Admin admin = connection.getAdmin()) {
        admin.createTable(new HTableDescriptor(tableName).addFamily(new HColumnDescriptor(foo)).addCoprocessor(CustomRegionObserver.class.getName()), // create with 2 regions
        new byte[][] { foo });
        try (Table table = connection.getTable(tableName)) {
            table.get(new Get(foo));
            // 2 gets
            table.get(new Get(foo));
        }
        assertPreGetRequestsCounter(CustomRegionObserver.class);
        // close one of the regions
        try (RegionLocator locator = connection.getRegionLocator(tableName)) {
            HRegionLocation loc = locator.getRegionLocation(foo);
            admin.closeRegion(loc.getServerName(), loc.getRegionInfo());
            HRegionServer server = UTIL.getMiniHBaseCluster().getRegionServer(loc.getServerName());
            UTIL.waitFor(30000, () -> server.getOnlineRegion(loc.getRegionInfo().getRegionName()) == null);
            assertNull(server.getOnlineRegion(loc.getRegionInfo().getRegionName()));
        }
        // with only 1 region remaining, we should still be able to find the Counter
        assertPreGetRequestsCounter(CustomRegionObserver.class);
        // close the table
        admin.disableTable(tableName);
        MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForRegionCoprocessor(CustomRegionObserver.class.getName());
        // ensure that MetricRegistry is deleted
        Optional<MetricRegistry> registry = MetricRegistries.global().get(info);
        assertFalse(registry.isPresent());
    }
}
Also used : RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) Table(org.apache.hadoop.hbase.client.Table) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) MetricRegistry(org.apache.hadoop.hbase.metrics.MetricRegistry) Connection(org.apache.hadoop.hbase.client.Connection) Admin(org.apache.hadoop.hbase.client.Admin) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) TableName(org.apache.hadoop.hbase.TableName) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) Get(org.apache.hadoop.hbase.client.Get) MetricRegistryInfo(org.apache.hadoop.hbase.metrics.MetricRegistryInfo) Test(org.junit.Test)

Example 95 with TableName

use of org.apache.hadoop.hbase.TableName in project hbase by apache.

the class TestCoprocessorMetrics method testRegionObserverMultiTable.

@Test
public void testRegionObserverMultiTable() throws IOException {
    final TableName tableName1 = TableName.valueOf(name.getMethodName() + "1");
    final TableName tableName2 = TableName.valueOf(name.getMethodName() + "2");
    try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
        Admin admin = connection.getAdmin()) {
        admin.createTable(new HTableDescriptor(tableName1).addFamily(new HColumnDescriptor(foo)).addCoprocessor(CustomRegionObserver.class.getName()));
        admin.createTable(new HTableDescriptor(tableName2).addFamily(new HColumnDescriptor(foo)).addCoprocessor(CustomRegionObserver.class.getName()));
        try (Table table1 = connection.getTable(tableName1);
            Table table2 = connection.getTable(tableName2)) {
            table1.get(new Get(bar));
            // 2 gets to 2 separate tables
            table2.get(new Get(foo));
        }
    }
    assertPreGetRequestsCounter(CustomRegionObserver.class);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) Get(org.apache.hadoop.hbase.client.Get) Connection(org.apache.hadoop.hbase.client.Connection) Admin(org.apache.hadoop.hbase.client.Admin) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Aggregations

TableName (org.apache.hadoop.hbase.TableName)1033 Test (org.junit.Test)695 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)257 Table (org.apache.hadoop.hbase.client.Table)228 IOException (java.io.IOException)225 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)215 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)203 Result (org.apache.hadoop.hbase.client.Result)125 ArrayList (java.util.ArrayList)120 Put (org.apache.hadoop.hbase.client.Put)118 Path (org.apache.hadoop.fs.Path)113 Connection (org.apache.hadoop.hbase.client.Connection)103 Scan (org.apache.hadoop.hbase.client.Scan)98 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)89 ServerName (org.apache.hadoop.hbase.ServerName)85 Admin (org.apache.hadoop.hbase.client.Admin)85 Cell (org.apache.hadoop.hbase.Cell)77 HashMap (java.util.HashMap)75 Delete (org.apache.hadoop.hbase.client.Delete)66 InterruptedIOException (java.io.InterruptedIOException)63