Search in sources :

Example 1 with ReplicateWALEntryRequest

use of org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.ReplicateWALEntryRequest in project hbase by apache.

the class ReplaySyncReplicationWALCallable method replayWAL.

private void replayWAL(String wal) throws IOException {
    try (Reader reader = getReader(wal)) {
        List<Entry> entries = readWALEntries(reader);
        while (!entries.isEmpty()) {
            Pair<AdminProtos.ReplicateWALEntryRequest, CellScanner> pair = ReplicationProtobufUtil.buildReplicateWALEntryRequest(entries.toArray(new Entry[entries.size()]));
            ReplicateWALEntryRequest request = pair.getFirst();
            rs.getReplicationSinkService().replicateLogEntries(request.getEntryList(), pair.getSecond(), request.getReplicationClusterId(), request.getSourceBaseNamespaceDirPath(), request.getSourceHFileArchiveDirPath());
            // Read next entries.
            entries = readWALEntries(reader);
        }
    }
}
Also used : Entry(org.apache.hadoop.hbase.wal.WAL.Entry) Reader(org.apache.hadoop.hbase.wal.WAL.Reader) ReplicateWALEntryRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.ReplicateWALEntryRequest) CellScanner(org.apache.hadoop.hbase.CellScanner)

Example 2 with ReplicateWALEntryRequest

use of org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.ReplicateWALEntryRequest in project hbase by apache.

the class ReplicationProtobufUtil method buildReplicateWALEntryRequest.

/**
 * Create a new ReplicateWALEntryRequest from a list of WAL entries
 * @param entries the WAL entries to be replicated
 * @param encodedRegionName alternative region name to use if not null
 * @param replicationClusterId Id which will uniquely identify source cluster FS client
 *          configurations in the replication configuration directory
 * @param sourceBaseNamespaceDir Path to source cluster base namespace directory
 * @param sourceHFileArchiveDir Path to the source cluster hfile archive directory
 * @return a pair of ReplicateWALEntryRequest and a CellScanner over all the WALEdit values found.
 */
public static Pair<ReplicateWALEntryRequest, CellScanner> buildReplicateWALEntryRequest(final Entry[] entries, byte[] encodedRegionName, String replicationClusterId, Path sourceBaseNamespaceDir, Path sourceHFileArchiveDir) {
    // Accumulate all the Cells seen in here.
    List<List<? extends Cell>> allCells = new ArrayList<>(entries.length);
    int size = 0;
    WALEntry.Builder entryBuilder = WALEntry.newBuilder();
    ReplicateWALEntryRequest.Builder builder = ReplicateWALEntryRequest.newBuilder();
    for (Entry entry : entries) {
        entryBuilder.clear();
        WALProtos.WALKey.Builder keyBuilder;
        try {
            keyBuilder = entry.getKey().getBuilder(WALCellCodec.getNoneCompressor());
        } catch (IOException e) {
            throw new AssertionError("There should not throw exception since NoneCompressor do not throw any exceptions", e);
        }
        if (encodedRegionName != null) {
            keyBuilder.setEncodedRegionName(UnsafeByteOperations.unsafeWrap(encodedRegionName));
        }
        entryBuilder.setKey(keyBuilder.build());
        WALEdit edit = entry.getEdit();
        List<Cell> cells = edit.getCells();
        // Add up the size.  It is used later serializing out the kvs.
        for (Cell cell : cells) {
            size += PrivateCellUtil.estimatedSerializedSizeOf(cell);
        }
        // Collect up the cells
        allCells.add(cells);
        // Write out how many cells associated with this entry.
        entryBuilder.setAssociatedCellCount(cells.size());
        builder.addEntry(entryBuilder.build());
    }
    if (replicationClusterId != null) {
        builder.setReplicationClusterId(replicationClusterId);
    }
    if (sourceBaseNamespaceDir != null) {
        builder.setSourceBaseNamespaceDirPath(sourceBaseNamespaceDir.toString());
    }
    if (sourceHFileArchiveDir != null) {
        builder.setSourceHFileArchiveDirPath(sourceHFileArchiveDir.toString());
    }
    return new Pair<>(builder.build(), getCellScanner(allCells, size));
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) Entry(org.apache.hadoop.hbase.wal.WAL.Entry) WALEntry(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.WALEntry) WALEdit(org.apache.hadoop.hbase.wal.WALEdit) ReplicateWALEntryRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.ReplicateWALEntryRequest) ArrayList(java.util.ArrayList) List(java.util.List) WALEntry(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.WALEntry) Cell(org.apache.hadoop.hbase.Cell) Pair(org.apache.hadoop.hbase.util.Pair)

Example 3 with ReplicateWALEntryRequest

use of org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.ReplicateWALEntryRequest in project hbase by apache.

the class TestReplicateToReplica method replicate.

private void replicate(Pair<List<WAL.Entry>, CompletableFuture<Void>> pair) throws IOException {
    Pair<ReplicateWALEntryRequest, CellScanner> params = ReplicationProtobufUtil.buildReplicateWALEntryRequest(pair.getFirst().toArray(new WAL.Entry[0]), secondary.getRegionInfo().getEncodedNameAsBytes(), null, null, null);
    for (WALEntry entry : params.getFirst().getEntryList()) {
        secondary.replayWALEntry(entry, params.getSecond());
    }
    pair.getSecond().complete(null);
}
Also used : WALEntry(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.WALEntry) ReplicateWALEntryRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.ReplicateWALEntryRequest) WALEntry(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.WALEntry) CellScanner(org.apache.hadoop.hbase.CellScanner)

Aggregations

ReplicateWALEntryRequest (org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.ReplicateWALEntryRequest)3 CellScanner (org.apache.hadoop.hbase.CellScanner)2 WALEntry (org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.WALEntry)2 Entry (org.apache.hadoop.hbase.wal.WAL.Entry)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Cell (org.apache.hadoop.hbase.Cell)1 Pair (org.apache.hadoop.hbase.util.Pair)1 Reader (org.apache.hadoop.hbase.wal.WAL.Reader)1 WALEdit (org.apache.hadoop.hbase.wal.WALEdit)1