private void getReplicaIdsByStateInRoutingTableSnapshot(RoutingTableSnapshot routingTableSnapshot, String dc,
        String resourceName, String partitionName, ReplicaState state, Set<AmbryReplica> replicas) {
      List<InstanceConfig> instanceConfigs =
          routingTableSnapshot.getInstancesForResource(resourceName, partitionName, state.name());
      Set<String> missingInstances = new HashSet<>();

      for (InstanceConfig instanceConfig : instanceConfigs) {
        String instanceName = instanceConfig.getInstanceName();
        if (!instanceNameToAmbryDataNode.containsKey(instanceName)) {
          missingInstances.add(instanceName);
          continue;
        }
        AmbryDataNode dataNode = instanceNameToAmbryDataNode.get(instanceName);
        if (dataNode.getDatacenterName().equals(dc)) {
          AmbryReplica replica = ambryDataNodeToAmbryReplicas.get(dataNode).get(partitionName);
          if (replica != null) {
            replicas.add(replica);
          }
        }
      }

      if (!missingInstances.isEmpty()) {
        logger.error("Instances are present in external view but missing in data node configs {}", missingInstances);
      }
    }
{@inheritDoc}
If dcName is null, then get replicas by given state from all datacenters.
If no routing table snapshot is found for dc name, or no resource name found for given partition, return empty list.
ambry-clustermap/src/main/java/com/github/ambry/clustermap/HelixClusterManager.java