Search in sources :

Example 1 with ReplicationPeer

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

the class ReplicationSource method getCurrentBandwidth.

private long getCurrentBandwidth() {
    ReplicationPeer replicationPeer = this.replicationPeers.getConnectedPeer(peerId);
    long peerBandwidth = replicationPeer != null ? replicationPeer.getPeerBandwidth() : 0;
    // user can set peer bandwidth to 0 to use default bandwidth
    return peerBandwidth != 0 ? peerBandwidth : defaultBandwidth;
}
Also used : ReplicationPeer(org.apache.hadoop.hbase.replication.ReplicationPeer)

Example 2 with ReplicationPeer

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

the class TestRegionReplicaReplicationEndpointNoMaster method testReplayedEditsAreSkipped.

@Test(timeout = 240000)
public void testReplayedEditsAreSkipped() throws Exception {
    openRegion(HTU, rs0, hriSecondary);
    ClusterConnection connection = (ClusterConnection) ConnectionFactory.createConnection(HTU.getConfiguration());
    RegionReplicaReplicationEndpoint replicator = new RegionReplicaReplicationEndpoint();
    ReplicationEndpoint.Context context = mock(ReplicationEndpoint.Context.class);
    when(context.getConfiguration()).thenReturn(HTU.getConfiguration());
    when(context.getMetrics()).thenReturn(mock(MetricsSource.class));
    ReplicationPeer mockPeer = mock(ReplicationPeer.class);
    when(mockPeer.getNamespaces()).thenReturn(null);
    when(mockPeer.getTableCFs()).thenReturn(null);
    when(mockPeer.getPeerConfig()).thenReturn(new ReplicationPeerConfig());
    when(context.getReplicationPeer()).thenReturn(mockPeer);
    replicator.init(context);
    replicator.start();
    // test the filter for the RE, not actual replication
    WALEntryFilter filter = replicator.getWALEntryfilter();
    //load some data to primary
    HTU.loadNumericRows(table, f, 0, 1000);
    Assert.assertEquals(1000, entries.size());
    for (Entry e : entries) {
        Cell _c = e.getEdit().getCells().get(0);
        if (Integer.parseInt(Bytes.toString(_c.getValueArray(), _c.getValueOffset(), _c.getValueLength())) % 2 == 0) {
            // simulate dist log replay by setting orig seq id
            e.getKey().setOrigLogSeqNum(1);
        }
    }
    long skipped = 0, replayed = 0;
    for (Entry e : entries) {
        if (filter.filter(e) == null) {
            skipped++;
        } else {
            replayed++;
        }
    }
    assertEquals(500, skipped);
    assertEquals(500, replayed);
    HTU.deleteNumericRows(table, f, 0, 1000);
    closeRegion(HTU, rs0, hriSecondary);
    connection.close();
}
Also used : ClusterConnection(org.apache.hadoop.hbase.client.ClusterConnection) Entry(org.apache.hadoop.hbase.wal.WAL.Entry) ReplicationEndpoint(org.apache.hadoop.hbase.replication.ReplicationEndpoint) ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) WALEntryFilter(org.apache.hadoop.hbase.replication.WALEntryFilter) ReplicationPeer(org.apache.hadoop.hbase.replication.ReplicationPeer) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 3 with ReplicationPeer

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

the class TestReplicationSource method testTerminateClearsBuffer.

@Test
public void testTerminateClearsBuffer() throws Exception {
    ReplicationSource source = new ReplicationSource();
    ReplicationSourceManager mockManager = mock(ReplicationSourceManager.class);
    MetricsReplicationGlobalSourceSource mockMetrics = mock(MetricsReplicationGlobalSourceSource.class);
    AtomicLong buffer = new AtomicLong();
    Mockito.when(mockManager.getTotalBufferUsed()).thenReturn(buffer);
    Mockito.when(mockManager.getGlobalMetrics()).thenReturn(mockMetrics);
    ReplicationPeer mockPeer = mock(ReplicationPeer.class);
    Mockito.when(mockPeer.getPeerBandwidth()).thenReturn(0L);
    Configuration testConf = HBaseConfiguration.create();
    source.init(testConf, null, mockManager, null, mockPeer, null, "testPeer", null, p -> OptionalLong.empty(), mock(MetricsSource.class));
    ReplicationSourceWALReader reader = new ReplicationSourceWALReader(null, conf, null, 0, null, source, null);
    ReplicationSourceShipper shipper = new ReplicationSourceShipper(conf, null, null, source);
    shipper.entryReader = reader;
    source.workerThreads.put("testPeer", shipper);
    WALEntryBatch batch = new WALEntryBatch(10, logDir);
    WAL.Entry mockEntry = mock(WAL.Entry.class);
    WALEdit mockEdit = mock(WALEdit.class);
    WALKeyImpl mockKey = mock(WALKeyImpl.class);
    when(mockEntry.getEdit()).thenReturn(mockEdit);
    when(mockEdit.isEmpty()).thenReturn(false);
    when(mockEntry.getKey()).thenReturn(mockKey);
    when(mockKey.estimatedSerializedSizeOf()).thenReturn(1000L);
    when(mockEdit.heapSize()).thenReturn(10000L);
    when(mockEdit.size()).thenReturn(0);
    ArrayList<Cell> cells = new ArrayList<>();
    KeyValue kv = new KeyValue(Bytes.toBytes("0001"), Bytes.toBytes("f"), Bytes.toBytes("1"), Bytes.toBytes("v1"));
    cells.add(kv);
    when(mockEdit.getCells()).thenReturn(cells);
    reader.addEntryToBatch(batch, mockEntry);
    reader.entryBatchQueue.put(batch);
    source.terminate("test");
    assertEquals(0, source.getSourceManager().getTotalBufferUsed().get());
}
Also used : WAL(org.apache.hadoop.hbase.wal.WAL) KeyValue(org.apache.hadoop.hbase.KeyValue) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) ArrayList(java.util.ArrayList) ReplicationPeer(org.apache.hadoop.hbase.replication.ReplicationPeer) AtomicLong(java.util.concurrent.atomic.AtomicLong) WALEdit(org.apache.hadoop.hbase.wal.WALEdit) WALKeyImpl(org.apache.hadoop.hbase.wal.WALKeyImpl) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 4 with ReplicationPeer

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

the class TestRefreshPeerWhileRegionServerRestarts method testRestart.

@Test
public void testRestart() throws Exception {
    UTIL1.getMiniHBaseCluster().getConfiguration().setClass(HConstants.REGION_SERVER_IMPL, RegionServerForTest.class, HRegionServer.class);
    CountDownLatch arrive = new CountDownLatch(1);
    ARRIVE = arrive;
    RESUME = new CountDownLatch(1);
    // restart a new region server, and wait until it finish initialization and want to call
    // regionServerReport, so it will load the peer state to peer cache.
    Future<HRegionServer> regionServerFuture = ForkJoinPool.commonPool().submit(() -> UTIL1.getMiniHBaseCluster().startRegionServer().getRegionServer());
    ARRIVE.await();
    // change the peer state, wait until it reach the last state, where we have already get the
    // region server list for refreshing
    Future<Void> future = hbaseAdmin.disableReplicationPeerAsync(PEER_ID2);
    try {
        UTIL1.waitFor(30000, () -> {
            for (Procedure<?> proc : UTIL1.getMiniHBaseCluster().getMaster().getProcedures()) {
                if (proc instanceof DisablePeerProcedure) {
                    return ((DisablePeerProcedure) proc).getCurrentStateId() == MasterProcedureProtos.PeerModificationState.POST_PEER_MODIFICATION_VALUE;
                }
            }
            return false;
        });
    } finally {
        // let the new region server go
        RESUME.countDown();
    }
    // wait the disable peer operation to finish
    future.get();
    // assert that the peer cache on the new region server has also been refreshed
    ReplicationPeer peer = regionServerFuture.get().getReplicationSourceService().getReplicationPeers().getPeer(PEER_ID2);
    assertEquals(PeerState.DISABLED, peer.getPeerState());
}
Also used : DisablePeerProcedure(org.apache.hadoop.hbase.master.replication.DisablePeerProcedure) CountDownLatch(java.util.concurrent.CountDownLatch) ReplicationPeer(org.apache.hadoop.hbase.replication.ReplicationPeer) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 5 with ReplicationPeer

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

the class TestReplicationSourceManager method mockReplicationSource.

private ReplicationSourceInterface mockReplicationSource(String peerId) {
    ReplicationSourceInterface source = mock(ReplicationSourceInterface.class);
    when(source.getPeerId()).thenReturn(peerId);
    when(source.getQueueId()).thenReturn(peerId);
    when(source.isRecovered()).thenReturn(false);
    when(source.isSyncReplication()).thenReturn(true);
    ReplicationPeerConfig config = mock(ReplicationPeerConfig.class);
    when(config.getRemoteWALDir()).thenReturn(remoteLogDir.makeQualified(fs.getUri(), fs.getWorkingDirectory()).toString());
    ReplicationPeer peer = mock(ReplicationPeer.class);
    when(peer.getPeerConfig()).thenReturn(config);
    when(source.getPeer()).thenReturn(peer);
    return source;
}
Also used : ReplicationPeerConfig(org.apache.hadoop.hbase.replication.ReplicationPeerConfig) ReplicationPeer(org.apache.hadoop.hbase.replication.ReplicationPeer)

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