int getReplicaCountForStateInExternalView(ReplicaState state, ExternalView externalView, boolean checkDatacenter) {
    int result = 0;
    for (String partition : externalView.getPartitionSet()) {
      Map<String, String> states = externalView.getStateMap(partition);
      if (!states.isEmpty()) {
        result += states.entrySet().stream().filter(ent -> {
          if (state != null && !ent.getValue().equals(state.name())) { // if state is null, then include all states
            return false;
          }
          if (checkDatacenter) {
            AmbryDataNode dataNode = instanceNameToAmbryDataNode.get(ent.getKey());
            return dataNode != null && dataNode.getDatacenterName().equals(clusterMapConfig.clusterMapDatacenterName);
          }
          return true;
        }).count();
      }
    }
    return result;
  }
Callback method when this data node is becoming SEMI AUTO from FULL AUTO.
ambry-clustermap/src/main/java/com/github/ambry/clustermap/HelixClusterManager.java