code: private void determinePartitionLeaders(Map<Integer, Host> hostLeaderMap){
          if (hostLeaderMap.isEmpty() || m_callbacks.isEmpty()) {
              return;
          }
          tmLog.info(WHOMIM + "Recalculate partition leaders after node down is detected.");
          // iterate through all partitions to see if its current leaders are on the failed hosts.
          for (PartitionCallback cb : m_callbacks.values()) {
              SortedSet<Host> hosts = new TreeSet<Host>();
              hosts.addAll(hostLeaderMap.values());
              int hostId = CoreUtils.getHostIdFromHSId(cb.m_currentLeader);
              //This partition has a valid leader
              if (hostLeaderMap.containsKey(hostId)) {
                  continue;
              }
              for (Host host : hosts) {
                  //The host does not have a replica of this partition
                  if (!(host.partitions.contains(cb.m_partitionId))) {
                      continue;
                  }
  
                  //find the host which has the lowest leader count.
                  host.increasePartitionLeader();
                  cb.newLeaderHostId = host.id;
                  if (tmLog.isDebugEnabled()) {
                      tmLog.debug(WHOMIM + String.format("Move partition leader to host %d from %d for partition %d.",
                              host.id, hostId, cb.m_partitionId));
                  }
                  break;
              }
          }
      }
docs: On a partition call back, an accurate view of the whole topology is not guaranteed since every partition callback
  tries to determine its own new leader. To ensure more even distribution of the partition leaders among the surviving nodes,
  the new partition leaders for the partitions are calculated based on the topology view when nodes are down:
  place the leaders of partitions to hosts with the lowest leader count
  
  If the host determined to host the partition leader is down due to further topology change after the new leaders are calculated,
  the site with the lowest host id will be picked up as the new partition leader.
  @param hostLeaderMap the partition leader info