@VisibleForTesting protected int replicateEntries(List<Entry> entries, int batchIndex) throws IOException { SinkPeer sinkPeer = null; try { int entriesHashCode = System.identityHashCode(entries); if (LOG.isTraceEnabled()) { long size = entries.stream().mapToLong(this::getEstimatedEntrySize).sum(); LOG.trace("Replicating batch {} of {} entries with total size {} bytes to {}", entriesHashCode, entries.size(), size, replicationClusterId); } sinkPeer = replicationSinkMgr.getReplicationSink(); BlockingInterface rrs = sinkPeer.getRegionServer(); try { ReplicationProtbufUtil.replicateWALEntry(rrs, entries.toArray(new Entry[entries.size()]), replicationClusterId, baseNamespaceDir, hfileArchiveDir); LOG.trace("Completed replicating batch {}", entriesHashCode); } catch (IOException e) { LOG.trace("Failed replicating batch {}", entriesHashCode, e); throw e; } replicationSinkMgr.reportSinkSuccess(sinkPeer); } catch (IOException ioe) { if (sinkPeer != null) { replicationSinkMgr.reportBadSink(sinkPeer); } throw ioe; } return batchIndex; }
/** * Create a new ReplicateWALEntryRequest from a list of WAL entries * * @param entries the WAL entries to be replicated * @return a pair of ReplicateWALEntryRequest and a CellScanner over all the WALEdit values * found. */ public static Pair<AdminProtos.ReplicateWALEntryRequest, CellScanner> buildReplicateWALEntryRequest(final Entry[] entries) throws IOException { return buildReplicateWALEntryRequest(entries, null, null, null, null); }
all.add(b); all.add(c); CellScanner scanner = ReplicationProtbufUtil.getCellScanner(all, 0); testAdvancetHasSameRow(scanner, akv);
getCellScanner(allCells, size));
all.add(b); all.add(c); CellScanner scanner = ReplicationProtbufUtil.getCellScanner(all, 0); testAdvancetHasSameRow(scanner, akv);
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 = ReplicationProtbufUtil .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); } } }
protected final void verifyReplicationRequestRejection(HBaseTestingUtility utility, boolean expectedRejection) throws Exception { HRegionServer regionServer = utility.getRSForFirstRegionInTable(TABLE_NAME); ClusterConnection connection = regionServer.getClusterConnection(); Entry[] entries = new Entry[10]; for (int i = 0; i < entries.length; i++) { entries[i] = new Entry(new WALKeyImpl(HConstants.EMPTY_BYTE_ARRAY, TABLE_NAME, 0), new WALEdit()); } if (!expectedRejection) { ReplicationProtbufUtil.replicateWALEntry(connection.getAdmin(regionServer.getServerName()), entries, null, null, null); } else { try { ReplicationProtbufUtil.replicateWALEntry(connection.getAdmin(regionServer.getServerName()), entries, null, null, null); fail("Should throw IOException when sync-replication state is in A or DA"); } catch (DoNotRetryIOException e) { assertTrue(e.getMessage().contains("Reject to apply to sink cluster")); assertTrue(e.getMessage().contains(TABLE_NAME.toString())); } } }
getCellScanner(allCells, size));
ReplicationProtbufUtil.buildReplicateWALEntryRequest(entriesArray, location .getRegionInfo().getEncodedNameAsBytes(), null, null, null); controller.setCellScanner(p.getSecond());
@Override public Integer call() throws IOException { SinkPeer sinkPeer = null; try { sinkPeer = replicationSinkMgr.getReplicationSink(); BlockingInterface rrs = sinkPeer.getRegionServer(); ReplicationProtbufUtil.replicateWALEntry(rrs, entries.toArray(new Entry[entries.size()])); replicationSinkMgr.reportSinkSuccess(sinkPeer); return ordinal; } catch (IOException ioe) { if (sinkPeer != null) { replicationSinkMgr.reportBadSink(sinkPeer); } throw ioe; } }
/** * A helper to replicate a list of WAL entries using admin protocol. * @param admin Admin service * @param entries Array of WAL entries to be replicated * @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 * @throws java.io.IOException */ public static void replicateWALEntry(final AdminService.BlockingInterface admin, final Entry[] entries, String replicationClusterId, Path sourceBaseNamespaceDir, Path sourceHFileArchiveDir) throws IOException { Pair<AdminProtos.ReplicateWALEntryRequest, CellScanner> p = buildReplicateWALEntryRequest(entries, null, replicationClusterId, sourceBaseNamespaceDir, sourceHFileArchiveDir); HBaseRpcController controller = new HBaseRpcControllerImpl(p.getSecond()); try { admin.replicateWALEntry(controller, p.getFirst()); } catch (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException e) { throw ProtobufUtil.getServiceException(e); } }
/** * Create a new ReplicateWALEntryRequest from a list of WAL entries * * @param entries the WAL entries to be replicated * @return a pair of ReplicateWALEntryRequest and a CellScanner over all the WALEdit values * found. */ public static Pair<AdminProtos.ReplicateWALEntryRequest, CellScanner> buildReplicateWALEntryRequest(final Entry[] entries) { // Accumulate all the Cells seen in here. return buildReplicateWALEntryRequest(entries, null); }
private void replayToServer(HRegionInfo regionInfo, List<Entry> entries) throws IOException, ServiceException { if (entries.isEmpty()) return; Entry[] entriesArray = new Entry[entries.size()]; entriesArray = entries.toArray(entriesArray); AdminService.BlockingInterface remoteSvr = conn.getAdmin(getLocation().getServerName()); Pair<AdminProtos.ReplicateWALEntryRequest, CellScanner> p = ReplicationProtbufUtil.buildReplicateWALEntryRequest(entriesArray); PayloadCarryingRpcController controller = rpcControllerFactory.newController(p.getSecond()); try { remoteSvr.replay(controller, p.getFirst()); } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); } }
/** * A helper to replicate a list of WAL entries using admin protocol. * * @param admin * @param entries * @throws java.io.IOException */ public static void replicateWALEntry(final AdminService.BlockingInterface admin, final Entry[] entries) throws IOException { Pair<AdminProtos.ReplicateWALEntryRequest, CellScanner> p = buildReplicateWALEntryRequest(entries, null); PayloadCarryingRpcController controller = new PayloadCarryingRpcController(p.getSecond()); try { admin.replicateWALEntry(controller, p.getFirst()); } catch (ServiceException se) { throw ProtobufUtil.getRemoteException(se); } }
ReplicationProtbufUtil.buildReplicateWALEntryRequest( entriesArray, location.getRegionInfo().getEncodedNameAsBytes()); try {