public void addRemoteReplicaInfo(RemoteReplicaInfo remoteReplicaInfo) {
    lock.lock();
    try {
      allReplicatedPartitions.add(remoteReplicaInfo.getReplicaId().getPartitionId());
      DataNodeId dataNodeId = remoteReplicaInfo.getReplicaId().getDataNodeId();
      // Use a linked hash set to make sure that we maintain a predictable order based on the insertion
      boolean doesRemoteReplicaInfoAlreadyExists = replicasToReplicateGroupedByNode.computeIfAbsent(dataNodeId, key -> new LinkedHashSet<>())
          .add(remoteReplicaInfo);
      if (!doesRemoteReplicaInfoAlreadyExists) {
        replicationMetrics.remoteReplicaInfoAddError.inc();
        // Since VCR is also listening Ambry Clustermap change, this may happen if events happens in following order:
        // 1. VCR in memory ambry-clustermap updated
        // 2. VcrClusterParticipantListener adds remote replicas for the newly added partition
        // 3. ClusterMapChangeListener adds remote replicas
        logger.warn("ReplicaThread: {}, RemoteReplicaInfo {} already exists.", threadName, remoteReplicaInfo);
      } else {
        increaseAssignedRemoteReplicaInfosMetric();
      }
    } finally {
      terminateCurrentContinuousReplicationCycle = true;
      lock.unlock();
    }
    logger.trace("RemoteReplicaInfo {} is added to ReplicaThread {}. Now working on {} dataNodeIds.", remoteReplicaInfo,
        threadName, replicasToReplicateGroupedByNode.keySet().size());
  }
Add a {@link RemoteReplicaInfo} to current {@link ReplicaThread}.
@param remoteReplicaInfo {@link RemoteReplicaInfo} to add.
ambry-replication/src/main/java/com/github/ambry/replication/ReplicaThread.java