core/src/main/java/org/infinispan/distribution/topologyaware/TopologyInfo.java
/**
    * The nodes collection must be sorted in descending order by their capacity.
    */
The nodes collection must be sorted in descending order by their capacity.
The nodes collection must be sorted in descending order by their capacity .
private double computeMaxSegmentsForNode(int numSegments, double numCopies, Collection<Address> nodes,
                                           Address node) {
      if (capacityFactors == null) {
         if (nodes.size() < numCopies) {
            return numSegments;
         } else {
            return numCopies * numSegments / nodes.size();
         }
      }
      Float nodeCapacityFactor = capacityFactors.get(node);
      if (nodeCapacityFactor == 0)
         return 0;
      double remainingCapacity = computeTotalCapacity(nodes, capacityFactors);
      double remainingCopies = numCopies * numSegments;
      for (Address a : nodes) {
         float capacityFactor = capacityFactors.get(a);
         double nodeSegments = capacityFactor / remainingCapacity * remainingCopies;
         if (nodeSegments > numSegments) {
            nodeSegments = numSegments;
            remainingCapacity -= capacityFactor;
            remainingCopies -= nodeSegments;
            if (node.equals(a))
               return nodeSegments;
         } else {
            if (!node.equals(a)) {
               nodeSegments = nodeCapacityFactor / remainingCapacity * remainingCopies;
            }
            return nodeSegments;
         }
      }
      throw new IllegalStateException("The nodes collection does not include " + node);
   }
private double computeMaxSegmentsForNode ( int numSegments , double numCopies , Collection < Address > nodes , Address node ) { if ( capacityFactors == null ) { if ( nodes . size ( ) < numCopies ) { return numSegments ; } else { return numCopies * numSegments / nodes . size ( ) ; } } Float nodeCapacityFactor = capacityFactors . get ( node ) ; if ( nodeCapacityFactor == 0 ) return 0 ; double remainingCapacity = computeTotalCapacity ( nodes , capacityFactors ) ; double remainingCopies = numCopies * numSegments ; for ( Address a : nodes ) { float capacityFactor = capacityFactors . get ( a ) ; double nodeSegments = capacityFactor / remainingCapacity * remainingCopies ; if ( nodeSegments > numSegments ) { nodeSegments = numSegments ; remainingCapacity -= capacityFactor ; remainingCopies -= nodeSegments ; if ( node . equals ( a ) ) return nodeSegments ; } else { if ( ! node . equals ( a ) ) { nodeSegments = nodeCapacityFactor / remainingCapacity * remainingCopies ; } return nodeSegments ; } } throw new IllegalStateException ( "The nodes collection does not include " + node ) ; }
The nodes collection must be sorted in descending order by their capacity.
The nodes collection must be sorted in descending order by their capacity .
// The number of segment copies on each node should be the same // All the nodes from now on will have less than numSegments segments, so we can stop the iteration