private Map<Integer, Set> groupByBucketOnClientSide(Region region,
      ClientPartitionAdvisor prAdvisor, Collection routingKeys, boolean bucketsAsFilter) {

    Map<Integer, Set> bucketToKeysMap = new HashMap<>();
    int totalNumberOfBuckets = prAdvisor.getTotalNumBuckets();
    for (final Object key : routingKeys) {
      int bucketId = bucketsAsFilter ? (Integer) key
          : extractBucketID(region, prAdvisor, totalNumberOfBuckets, key);
      Set bucketKeys = bucketToKeysMap.get(bucketId);
      if (bucketKeys == null) {
        bucketKeys = new HashSet(); // faster if this was an ArrayList
        bucketToKeysMap.put(bucketId, bucketKeys);
      }
      bucketKeys.add(key);
    }
    if (logger.isDebugEnabled()) {
      logger.debug("Bucket to keys map : {}", bucketToKeysMap);
    }
    return bucketToKeysMap;
  }
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