Search in sources :

Example 41 with WALKeyImpl

use of org.apache.hadoop.hbase.wal.WALKeyImpl 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 42 with WALKeyImpl

use of org.apache.hadoop.hbase.wal.WALKeyImpl in project hbase by apache.

the class TestRecoverStandbyProcedure method createWALEntry.

private Entry createWALEntry(byte[] row, byte[] value) {
    WALKeyImpl key = new WALKeyImpl(regionInfo.getEncodedNameAsBytes(), tableName, 1);
    WALEdit edit = new WALEdit();
    edit.add(new KeyValue(row, family, qualifier, timestamp, value));
    return new Entry(key, edit);
}
Also used : Entry(org.apache.hadoop.hbase.wal.WAL.Entry) KeyValue(org.apache.hadoop.hbase.KeyValue) WALEdit(org.apache.hadoop.hbase.wal.WALEdit) WALKeyImpl(org.apache.hadoop.hbase.wal.WALKeyImpl)

Example 43 with WALKeyImpl

use of org.apache.hadoop.hbase.wal.WALKeyImpl in project hbase by apache.

the class TestSerialReplicationChecker method createEntry.

private Entry createEntry(RegionInfo region, long seqId) {
    WALKeyImpl key = mock(WALKeyImpl.class);
    when(key.getTableName()).thenReturn(tableName);
    when(key.getEncodedRegionName()).thenReturn(region.getEncodedNameAsBytes());
    when(key.getSequenceId()).thenReturn(seqId);
    Entry entry = mock(Entry.class);
    when(entry.getKey()).thenReturn(key);
    return entry;
}
Also used : Entry(org.apache.hadoop.hbase.wal.WAL.Entry) WALKeyImpl(org.apache.hadoop.hbase.wal.WALKeyImpl)

Example 44 with WALKeyImpl

use of org.apache.hadoop.hbase.wal.WALKeyImpl in project hbase by apache.

the class AbstractTestDLS method makeWAL.

public void makeWAL(HRegionServer hrs, List<RegionInfo> regions, int numEdits, int editSize, boolean cleanShutdown) throws IOException {
    // remove root and meta region
    regions.remove(RegionInfoBuilder.FIRST_META_REGIONINFO);
    for (Iterator<RegionInfo> iter = regions.iterator(); iter.hasNext(); ) {
        RegionInfo regionInfo = iter.next();
        if (regionInfo.getTable().isSystemTable()) {
            iter.remove();
        }
    }
    byte[] value = new byte[editSize];
    List<RegionInfo> hris = new ArrayList<>();
    for (RegionInfo region : regions) {
        if (region.getTable() != tableName) {
            continue;
        }
        hris.add(region);
    }
    LOG.info("Creating wal edits across " + hris.size() + " regions.");
    for (int i = 0; i < editSize; i++) {
        value[i] = (byte) ('a' + (i % 26));
    }
    int n = hris.size();
    int[] counts = new int[n];
    // sync every ~30k to line up with desired wal rolls
    final int syncEvery = 30 * 1024 / editSize;
    MultiVersionConcurrencyControl mvcc = new MultiVersionConcurrencyControl();
    if (n > 0) {
        for (int i = 0; i < numEdits; i += 1) {
            WALEdit e = new WALEdit();
            RegionInfo curRegionInfo = hris.get(i % n);
            WAL log = hrs.getWAL(curRegionInfo);
            byte[] startRow = curRegionInfo.getStartKey();
            if (startRow == null || startRow.length == 0) {
                startRow = new byte[] { 0, 0, 0, 0, 1 };
            }
            byte[] row = Bytes.incrementBytes(startRow, counts[i % n]);
            // use last 5 bytes because
            row = Arrays.copyOfRange(row, 3, 8);
            // HBaseTestingUtility.createMultiRegions use 5 bytes key
            byte[] qualifier = Bytes.toBytes("c" + Integer.toString(i));
            e.add(new KeyValue(row, COLUMN_FAMILY, qualifier, EnvironmentEdgeManager.currentTime(), value));
            log.appendData(curRegionInfo, new WALKeyImpl(curRegionInfo.getEncodedNameAsBytes(), tableName, EnvironmentEdgeManager.currentTime(), mvcc), e);
            if (0 == i % syncEvery) {
                log.sync();
            }
            counts[i % n] += 1;
        }
    }
    // will cause errors if done after.
    for (RegionInfo info : hris) {
        WAL log = hrs.getWAL(info);
        log.sync();
    }
    if (cleanShutdown) {
        for (RegionInfo info : hris) {
            WAL log = hrs.getWAL(info);
            log.shutdown();
        }
    }
    for (int i = 0; i < n; i++) {
        LOG.info("region " + hris.get(i).getRegionNameAsString() + " has " + counts[i] + " edits");
    }
    return;
}
Also used : WAL(org.apache.hadoop.hbase.wal.WAL) KeyValue(org.apache.hadoop.hbase.KeyValue) WALEdit(org.apache.hadoop.hbase.wal.WALEdit) MultiVersionConcurrencyControl(org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl) ArrayList(java.util.ArrayList) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) WALKeyImpl(org.apache.hadoop.hbase.wal.WALKeyImpl)

Example 45 with WALKeyImpl

use of org.apache.hadoop.hbase.wal.WALKeyImpl in project hbase by apache.

the class TestHBaseInterClusterReplicationEndpointFilterEdits method testFilterNotExistColumnFamilyEdits.

@Test
public void testFilterNotExistColumnFamilyEdits() {
    List<List<Entry>> entryList = new ArrayList<>();
    // should be filtered
    Cell c1 = new KeyValue(ROW, NON_EXISTING_FAMILY, QUALIFIER, EnvironmentEdgeManager.currentTime(), Type.Put, VALUE);
    Entry e1 = new Entry(new WALKeyImpl(new byte[32], TABLE1, EnvironmentEdgeManager.currentTime()), new WALEdit().add(c1));
    entryList.add(Lists.newArrayList(e1));
    // should be kept
    Cell c2 = new KeyValue(ROW, FAMILY, QUALIFIER, EnvironmentEdgeManager.currentTime(), Type.Put, VALUE);
    Entry e2 = new Entry(new WALKeyImpl(new byte[32], TABLE1, EnvironmentEdgeManager.currentTime()), new WALEdit().add(c2));
    entryList.add(Lists.newArrayList(e2, e1));
    List<List<Entry>> filtered = endpoint.filterNotExistColumnFamilyEdits(entryList);
    assertEquals(1, filtered.size());
    assertEquals(1, filtered.get(0).get(0).getEdit().getCells().size());
    Cell cell = filtered.get(0).get(0).getEdit().getCells().get(0);
    assertTrue(CellUtil.matchingFamily(cell, FAMILY));
}
Also used : Entry(org.apache.hadoop.hbase.wal.WAL.Entry) KeyValue(org.apache.hadoop.hbase.KeyValue) WALEdit(org.apache.hadoop.hbase.wal.WALEdit) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) WALKeyImpl(org.apache.hadoop.hbase.wal.WALKeyImpl) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Aggregations

WALKeyImpl (org.apache.hadoop.hbase.wal.WALKeyImpl)59 WALEdit (org.apache.hadoop.hbase.wal.WALEdit)44 Test (org.junit.Test)42 KeyValue (org.apache.hadoop.hbase.KeyValue)24 TreeMap (java.util.TreeMap)22 WAL (org.apache.hadoop.hbase.wal.WAL)20 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)17 Path (org.apache.hadoop.fs.Path)16 IOException (java.io.IOException)13 TableName (org.apache.hadoop.hbase.TableName)12 MultiVersionConcurrencyControl (org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl)12 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)11 WALFactory (org.apache.hadoop.hbase.wal.WALFactory)10 ArrayList (java.util.ArrayList)9 Entry (org.apache.hadoop.hbase.wal.WAL.Entry)9 FileSystem (org.apache.hadoop.fs.FileSystem)8 WALProvider (org.apache.hadoop.hbase.wal.WALProvider)8 CompletableFuture (java.util.concurrent.CompletableFuture)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)7 Configuration (org.apache.hadoop.conf.Configuration)7