Search in sources :

Example 16 with RegionServerServices

use of org.apache.hadoop.hbase.regionserver.RegionServerServices in project hbase by apache.

the class TestCoprocessorConfiguration method testReadOnlyConfiguration.

/**
 * Rough test that Coprocessor Environment is Read-Only.
 * Just check a random CP and see that it returns a read-only config.
 */
@Test
public void testReadOnlyConfiguration() throws Exception {
    Configuration conf = new Configuration(CONF);
    HRegion region = mock(HRegion.class);
    when(region.getRegionInfo()).thenReturn(REGIONINFO);
    when(region.getTableDescriptor()).thenReturn(TABLEDESC);
    RegionServerServices rsServices = mock(RegionServerServices.class);
    RegionCoprocessorHost rcp = new RegionCoprocessorHost(region, rsServices, conf);
    boolean found = false;
    for (String cpStr : rcp.getCoprocessors()) {
        CoprocessorEnvironment cpenv = rcp.findCoprocessorEnvironment(cpStr);
        if (cpenv != null) {
            found = true;
        }
        Configuration c = cpenv.getConfiguration();
        thrown.expect(UnsupportedOperationException.class);
        c.set("one.two.three", "four.five.six");
    }
    assertTrue("Should be at least one CP found", found);
}
Also used : HRegion(org.apache.hadoop.hbase.regionserver.HRegion) RegionServerServices(org.apache.hadoop.hbase.regionserver.RegionServerServices) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) RegionCoprocessorHost(org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost) CoprocessorEnvironment(org.apache.hadoop.hbase.CoprocessorEnvironment) Test(org.junit.Test)

Example 17 with RegionServerServices

use of org.apache.hadoop.hbase.regionserver.RegionServerServices in project hbase by apache.

the class TestCoprocessorConfiguration method testRegionCoprocessorHostDefaults.

@Test
public void testRegionCoprocessorHostDefaults() throws Exception {
    Configuration conf = new Configuration(CONF);
    HRegion region = mock(HRegion.class);
    when(region.getRegionInfo()).thenReturn(REGIONINFO);
    when(region.getTableDescriptor()).thenReturn(TABLEDESC);
    RegionServerServices rsServices = mock(RegionServerServices.class);
    systemCoprocessorLoaded.set(false);
    tableCoprocessorLoaded.set(false);
    new RegionCoprocessorHost(region, rsServices, conf);
    assertEquals("System coprocessors loading default was not honored", CoprocessorHost.DEFAULT_COPROCESSORS_ENABLED, systemCoprocessorLoaded.get());
    assertEquals("Table coprocessors loading default was not honored", CoprocessorHost.DEFAULT_COPROCESSORS_ENABLED && CoprocessorHost.DEFAULT_USER_COPROCESSORS_ENABLED, tableCoprocessorLoaded.get());
}
Also used : HRegion(org.apache.hadoop.hbase.regionserver.HRegion) RegionServerServices(org.apache.hadoop.hbase.regionserver.RegionServerServices) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) RegionCoprocessorHost(org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost) Test(org.junit.Test)

Example 18 with RegionServerServices

use of org.apache.hadoop.hbase.regionserver.RegionServerServices in project hbase by apache.

the class TestReplicationSource method setupForAbortTests.

private RegionServerServices setupForAbortTests(ReplicationSource rs, Configuration conf, String endpointName) throws IOException {
    conf.setInt("replication.source.maxretriesmultiplier", 1);
    ReplicationPeer mockPeer = Mockito.mock(ReplicationPeer.class);
    Mockito.when(mockPeer.getConfiguration()).thenReturn(conf);
    Mockito.when(mockPeer.getPeerBandwidth()).thenReturn(0L);
    ReplicationPeerConfig peerConfig = Mockito.mock(ReplicationPeerConfig.class);
    FaultyReplicationEndpoint.count = 0;
    Mockito.when(peerConfig.getReplicationEndpointImpl()).thenReturn(endpointName);
    Mockito.when(mockPeer.getPeerConfig()).thenReturn(peerConfig);
    ReplicationSourceManager manager = Mockito.mock(ReplicationSourceManager.class);
    Mockito.when(manager.getTotalBufferUsed()).thenReturn(new AtomicLong());
    Mockito.when(manager.getGlobalMetrics()).thenReturn(mock(MetricsReplicationGlobalSourceSource.class));
    String queueId = "qid";
    RegionServerServices rss = TEST_UTIL.createMockRegionServerService(ServerName.parseServerName("a.b.c,1,1"));
    rs.init(conf, null, manager, null, mockPeer, rss, queueId, null, p -> OptionalLong.empty(), new MetricsSource(queueId));
    return rss;
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) RegionServerServices(org.apache.hadoop.hbase.regionserver.RegionServerServices) ReplicationPeer(org.apache.hadoop.hbase.replication.ReplicationPeer)

Example 19 with RegionServerServices

use of org.apache.hadoop.hbase.regionserver.RegionServerServices in project hbase by apache.

the class TestReplicationSource method testAgeOfOldestWal.

/*
    Test age of oldest wal metric.
  */
@Test
public void testAgeOfOldestWal() throws Exception {
    try {
        ManualEnvironmentEdge manualEdge = new ManualEnvironmentEdge();
        EnvironmentEdgeManager.injectEdge(manualEdge);
        String id = "1";
        MetricsSource metrics = new MetricsSource(id);
        Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
        conf.setInt("replication.source.maxretriesmultiplier", 1);
        ReplicationPeer mockPeer = Mockito.mock(ReplicationPeer.class);
        Mockito.when(mockPeer.getConfiguration()).thenReturn(conf);
        Mockito.when(mockPeer.getPeerBandwidth()).thenReturn(0L);
        ReplicationPeerConfig peerConfig = Mockito.mock(ReplicationPeerConfig.class);
        Mockito.when(peerConfig.getReplicationEndpointImpl()).thenReturn(DoNothingReplicationEndpoint.class.getName());
        Mockito.when(mockPeer.getPeerConfig()).thenReturn(peerConfig);
        ReplicationSourceManager manager = Mockito.mock(ReplicationSourceManager.class);
        Mockito.when(manager.getTotalBufferUsed()).thenReturn(new AtomicLong());
        Mockito.when(manager.getGlobalMetrics()).thenReturn(mock(MetricsReplicationGlobalSourceSource.class));
        RegionServerServices rss = TEST_UTIL.createMockRegionServerService(ServerName.parseServerName("a.b.c,1,1"));
        ReplicationSource source = new ReplicationSource();
        source.init(conf, null, manager, null, mockPeer, rss, id, null, p -> OptionalLong.empty(), metrics);
        final Path log1 = new Path(logDir, "log-walgroup-a.8");
        manualEdge.setValue(10);
        // Diff of current time (10) and  log-walgroup-a.8 timestamp will be 2.
        source.enqueueLog(log1);
        MetricsReplicationSourceSource metricsSource1 = getSourceMetrics(id);
        assertEquals(2, metricsSource1.getOldestWalAge());
        final Path log2 = new Path(logDir, "log-walgroup-b.4");
        // Diff of current time (10) and log-walgroup-b.4 will be 6 so oldestWalAge should be 6
        source.enqueueLog(log2);
        assertEquals(6, metricsSource1.getOldestWalAge());
        // Clear all metrics.
        metrics.clear();
    } finally {
        EnvironmentEdgeManager.reset();
    }
}
Also used : Path(org.apache.hadoop.fs.Path) RegionServerServices(org.apache.hadoop.hbase.regionserver.RegionServerServices) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) ReplicationPeer(org.apache.hadoop.hbase.replication.ReplicationPeer) AtomicLong(java.util.concurrent.atomic.AtomicLong) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) ManualEnvironmentEdge(org.apache.hadoop.hbase.util.ManualEnvironmentEdge) Test(org.junit.Test)

Example 20 with RegionServerServices

use of org.apache.hadoop.hbase.regionserver.RegionServerServices in project hbase by apache.

the class TestReplicationSource method testWALEntryFilter.

/**
 * Test that we filter out meta edits, etc.
 */
@Test
public void testWALEntryFilter() throws IOException {
    // To get the fully constructed default WALEntryFilter, need to create a ReplicationSource
    // instance and init it.
    ReplicationSource rs = new ReplicationSource();
    UUID uuid = UUID.randomUUID();
    Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
    ReplicationPeer mockPeer = Mockito.mock(ReplicationPeer.class);
    Mockito.when(mockPeer.getConfiguration()).thenReturn(conf);
    Mockito.when(mockPeer.getPeerBandwidth()).thenReturn(0L);
    ReplicationPeerConfig peerConfig = Mockito.mock(ReplicationPeerConfig.class);
    Mockito.when(peerConfig.getReplicationEndpointImpl()).thenReturn(DoNothingReplicationEndpoint.class.getName());
    Mockito.when(mockPeer.getPeerConfig()).thenReturn(peerConfig);
    ReplicationSourceManager manager = Mockito.mock(ReplicationSourceManager.class);
    Mockito.when(manager.getTotalBufferUsed()).thenReturn(new AtomicLong());
    String queueId = "qid";
    RegionServerServices rss = TEST_UTIL.createMockRegionServerService(ServerName.parseServerName("a.b.c,1,1"));
    rs.init(conf, null, manager, null, mockPeer, rss, queueId, uuid, p -> OptionalLong.empty(), new MetricsSource(queueId));
    try {
        rs.startup();
        TEST_UTIL.waitFor(30000, () -> rs.getWalEntryFilter() != null);
        WALEntryFilter wef = rs.getWalEntryFilter();
        // Test non-system WAL edit.
        WALEdit we = new WALEdit().add(CellBuilderFactory.create(CellBuilderType.DEEP_COPY).setRow(HConstants.EMPTY_START_ROW).setFamily(HConstants.CATALOG_FAMILY).setType(Cell.Type.Put).build());
        WAL.Entry e = new WAL.Entry(new WALKeyImpl(HConstants.EMPTY_BYTE_ARRAY, TableName.valueOf("test"), -1, -1, uuid), we);
        assertTrue(wef.filter(e) == e);
        // Test system WAL edit.
        e = new WAL.Entry(new WALKeyImpl(HConstants.EMPTY_BYTE_ARRAY, TableName.META_TABLE_NAME, -1, -1, uuid), we);
        assertNull(wef.filter(e));
    } finally {
        rs.terminate("Done");
        rss.stop("Done");
    }
}
Also used : RegionServerServices(org.apache.hadoop.hbase.regionserver.RegionServerServices) WAL(org.apache.hadoop.hbase.wal.WAL) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) ReplicationPeer(org.apache.hadoop.hbase.replication.ReplicationPeer) AtomicLong(java.util.concurrent.atomic.AtomicLong) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) WALEntryFilter(org.apache.hadoop.hbase.replication.WALEntryFilter) WALEdit(org.apache.hadoop.hbase.wal.WALEdit) WALKeyImpl(org.apache.hadoop.hbase.wal.WALKeyImpl) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

RegionServerServices (org.apache.hadoop.hbase.regionserver.RegionServerServices)26 Configuration (org.apache.hadoop.conf.Configuration)18 Test (org.junit.Test)17 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)15 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)7 IOException (java.io.IOException)5 Path (org.apache.hadoop.fs.Path)5 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)5 RegionCoprocessorEnvironment (org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment)5 RegionCoprocessorHost (org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)4 ReplicationPeer (org.apache.hadoop.hbase.replication.ReplicationPeer)4 ReplicationPeerConfig (org.apache.hadoop.hbase.replication.ReplicationPeerConfig)4 TableName (org.apache.hadoop.hbase.TableName)3 HasRegionServerServices (org.apache.hadoop.hbase.coprocessor.HasRegionServerServices)3 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)2 Put (org.apache.hadoop.hbase.client.Put)2 Scan (org.apache.hadoop.hbase.client.Scan)2 SpaceQuotaStatus (org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus)2