private ServerLocation findNextServer(Set<Map.Entry<ServerLocation, Set<Integer>>> entrySet,
      Set<Integer> currentBucketSet) {

    ServerLocation server = null;
    int max = -1;
    List<ServerLocation> nodesOfEqualSize = new ArrayList<>();
    for (Map.Entry<ServerLocation, Set<Integer>> entry : entrySet) {
      Set<Integer> buckets = new HashSet<>(entry.getValue());
      buckets.removeAll(currentBucketSet);

      if (max < buckets.size()) {
        max = buckets.size();
        server = entry.getKey();
        nodesOfEqualSize.clear();
        nodesOfEqualSize.add(server);
      } else if (max == buckets.size()) {
        nodesOfEqualSize.add(server);
      }
    }

    Random r = new Random();
    if (nodesOfEqualSize.size() > 0) {
      return nodesOfEqualSize.get(r.nextInt(nodesOfEqualSize.size()));
    }

    return null;
  }
This function should make a map of server to buckets it is hosting. If for some bucket servers
are not available due to mismatch in metadata it should fill up a random server for it.
geode-core/src/main/java/org/apache/geode/cache/client/internal/ClientMetadataService.java