managed/src/main/java/com/yugabyte/yw/common/PlacementInfoUtil.java
// Select the number of AZs for each deployment.
Select the number of AZs for each deployment.
Select the number of AZs for each deployment .
public static void selectNumMastersAZ(PlacementInfo pi, int numTotalMasters) {
    int totalAZs = 0;
    for (PlacementCloud pc : pi.cloudList) {
      for (PlacementRegion pr : pc.regionList) {
        totalAZs += pr.azList.size();
      }
    }
    for (PlacementCloud pc : pi.cloudList) {
      int remainingMasters = numTotalMasters;
      int azsRemaining = totalAZs;
      for (PlacementRegion pr : pc.regionList) {
        int numAzsInRegion = pr.azList.size();
        int mastersInRegion = (int) Math.round(remainingMasters * ((double) numAzsInRegion / azsRemaining));
        int mastersAdded = 0;
        int saturated = 0;
        int count = 0;
        while (mastersInRegion != mastersAdded && saturated != numAzsInRegion ) {
          saturated = 0;
          for (PlacementAZ pa : pr.azList) {
            if ((count + 1) <= pa.numNodesInAZ) {
              pa.replicationFactor = count + 1;
              mastersAdded++;
            } else {
              saturated++;
            }
            if (mastersInRegion == 0) {
              break;
            }
          }
          count++;
        }
        remainingMasters -= mastersAdded;
        azsRemaining -= numAzsInRegion;
      }
    }
  }
public static void selectNumMastersAZ ( PlacementInfo pi , int numTotalMasters ) { int totalAZs = 0 ; for ( PlacementCloud pc : pi . cloudList ) { for ( PlacementRegion pr : pc . regionList ) { totalAZs += pr . azList . size ( ) ; } } for ( PlacementCloud pc : pi . cloudList ) { int remainingMasters = numTotalMasters ; int azsRemaining = totalAZs ; for ( PlacementRegion pr : pc . regionList ) { int numAzsInRegion = pr . azList . size ( ) ; int mastersInRegion = ( int ) Math . round ( remainingMasters * ( ( double ) numAzsInRegion / azsRemaining ) ) ; int mastersAdded = 0 ; int saturated = 0 ; int count = 0 ; while ( mastersInRegion != mastersAdded && saturated != numAzsInRegion ) { saturated = 0 ; for ( PlacementAZ pa : pr . azList ) { if ( ( count + 1 ) <= pa . numNodesInAZ ) { pa . replicationFactor = count + 1 ; mastersAdded ++ ; } else { saturated ++ ; } if ( mastersInRegion == 0 ) { break ; } } count ++ ; } remainingMasters -= mastersAdded ; azsRemaining -= numAzsInRegion ; } } }
Select the number of AZs for each deployment.
Select the number of AZs for each deployment .
// Distribute masters in each region according to the number of AZs in each region. // The number of masters in an AZ cannot exceed the number of tservers.