Search in sources :

Example 11 with ReplicationPeer

use of org.apache.hadoop.hbase.replication.ReplicationPeer 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 12 with ReplicationPeer

use of org.apache.hadoop.hbase.replication.ReplicationPeer 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 13 with ReplicationPeer

use of org.apache.hadoop.hbase.replication.ReplicationPeer in project hbase by apache.

the class TestReplicationSource method testTerminateTimeout.

/**
 * Tests that {@link ReplicationSource#terminate(String)} will timeout properly
 * Moved here from TestReplicationSource because doesn't need cluster.
 */
@Test
public void testTerminateTimeout() throws Exception {
    ReplicationSource source = new ReplicationSource();
    ReplicationEndpoint replicationEndpoint = new DoNothingReplicationEndpoint();
    try {
        replicationEndpoint.start();
        ReplicationPeer mockPeer = Mockito.mock(ReplicationPeer.class);
        Mockito.when(mockPeer.getPeerBandwidth()).thenReturn(0L);
        Configuration testConf = HBaseConfiguration.create();
        testConf.setInt("replication.source.maxretriesmultiplier", 1);
        ReplicationSourceManager manager = Mockito.mock(ReplicationSourceManager.class);
        Mockito.when(manager.getTotalBufferUsed()).thenReturn(new AtomicLong());
        source.init(testConf, null, manager, null, mockPeer, null, "testPeer", null, p -> OptionalLong.empty(), null);
        ExecutorService executor = Executors.newSingleThreadExecutor();
        Future<?> future = executor.submit(() -> source.terminate("testing source termination"));
        long sleepForRetries = testConf.getLong("replication.source.sleepforretries", 1000);
        Waiter.waitFor(testConf, sleepForRetries * 2, (Waiter.Predicate<Exception>) future::isDone);
    } finally {
        replicationEndpoint.stop();
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ReplicationEndpoint(org.apache.hadoop.hbase.replication.ReplicationEndpoint) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) ExecutorService(java.util.concurrent.ExecutorService) Waiter(org.apache.hadoop.hbase.Waiter) ReplicationPeer(org.apache.hadoop.hbase.replication.ReplicationPeer) IOException(java.io.IOException) Test(org.junit.Test)

Example 14 with ReplicationPeer

use of org.apache.hadoop.hbase.replication.ReplicationPeer 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)

Example 15 with ReplicationPeer

use of org.apache.hadoop.hbase.replication.ReplicationPeer in project hbase by apache.

the class TestReplicationSource method testDefaultSkipsMetaWAL.

/**
 * Test the default ReplicationSource skips queuing hbase:meta WAL files.
 */
@Test
public void testDefaultSkipsMetaWAL() throws IOException {
    ReplicationSource rs = new ReplicationSource();
    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));
    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));
    try {
        rs.startup();
        assertTrue(rs.isSourceActive());
        assertEquals(0, rs.getSourceMetrics().getSizeOfLogQueue());
        rs.enqueueLog(new Path("a.1" + META_WAL_PROVIDER_ID));
        assertEquals(0, rs.getSourceMetrics().getSizeOfLogQueue());
        rs.enqueueLog(new Path("a.1"));
        assertEquals(1, rs.getSourceMetrics().getSizeOfLogQueue());
    } finally {
        rs.terminate("Done");
        rss.stop("Done");
    }
}
Also used : Path(org.apache.hadoop.fs.Path) AtomicLong(java.util.concurrent.atomic.AtomicLong) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) 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) Test(org.junit.Test)

Aggregations

ReplicationPeer (org.apache.hadoop.hbase.replication.ReplicationPeer)16 ReplicationPeerConfig (org.apache.hadoop.hbase.replication.ReplicationPeerConfig)10 Test (org.junit.Test)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)6 Configuration (org.apache.hadoop.conf.Configuration)6 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)5 ArrayList (java.util.ArrayList)4 Path (org.apache.hadoop.fs.Path)4 RegionServerServices (org.apache.hadoop.hbase.regionserver.RegionServerServices)4 HashMap (java.util.HashMap)2 NavigableSet (java.util.NavigableSet)2 TreeSet (java.util.TreeSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Cell (org.apache.hadoop.hbase.Cell)2 ReplicationEndpoint (org.apache.hadoop.hbase.replication.ReplicationEndpoint)2 WALEntryFilter (org.apache.hadoop.hbase.replication.WALEntryFilter)2 WAL (org.apache.hadoop.hbase.wal.WAL)2 WALEdit (org.apache.hadoop.hbase.wal.WALEdit)2 WALKeyImpl (org.apache.hadoop.hbase.wal.WALKeyImpl)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1