@Override
    public ReplicateWALEntryResponse replicateToReplica(RpcController controller,
      ReplicateWALEntryRequest request) throws ServiceException {
      List<WALEntry> entries = request.getEntryList();
      if (CollectionUtils.isEmpty(entries)) {
        return ReplicateWALEntryResponse.getDefaultInstance();
      }
      ByteString regionName = entries.get(0).getKey().getEncodedRegionName();
      HRegion region;
      try {
        region = server.getRegionByEncodedName(regionName.toStringUtf8());
      } catch (NotServingRegionException e) {
        throw new ServiceException(e);
      }

      AtomicInteger counter =
        ConcurrentMapUtils.computeIfAbsent(regionToCounter, region, () -> new AtomicInteger(0));

      // fail the first several request
      if (region.getRegionInfo().getReplicaId() == 1 && counter.addAndGet(entries.size()) < 100) {
        throw new ServiceException("Inject error!");
      }
      return super.replicateToReplica(controller, request);
    }
Test region replication when error occur.
<p/>
We can not simply move the secondary replicas as we will trigger a flush for the primary replica
when secondary replica is online, which will always make the data of the two regions in sync. So
here we need to simulate request errors.
hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionReplicaReplicationError.java