Ejemplo n.º 1
0
  /**
   * Compute the new partition IDs to add to the cluster based on the new topology.
   *
   * @param zk Zookeeper client
   * @param topo The new topology which should include the new host count
   * @return A list of partitions IDs to add to the cluster.
   * @throws JSONException
   */
  public static List<Integer> getPartitionsToAdd(ZooKeeper zk, JSONObject topo)
      throws JSONException {
    ClusterConfig clusterConfig = new ClusterConfig(topo);
    List<Integer> newPartitions = new ArrayList<Integer>();
    Set<Integer> existingParts = new HashSet<Integer>(getPartitions(zk));
    // Remove MPI
    existingParts.remove(MpInitiator.MP_INIT_PID);
    int partsToAdd = clusterConfig.getPartitionCount() - existingParts.size();

    if (partsToAdd > 0) {
      hostLog.info(
          "Computing new partitions to add. Total partitions: "
              + clusterConfig.getPartitionCount());
      for (int i = 0; newPartitions.size() != partsToAdd; i++) {
        if (!existingParts.contains(i)) {
          newPartitions.add(i);
        }
      }
      hostLog.info("Adding " + partsToAdd + " partitions: " + newPartitions);
    }
    return newPartitions;
  }
Ejemplo n.º 2
0
 public List<Integer> getIv2PartitionsToReplace(JSONObject topology) throws JSONException {
   ClusterConfig clusterConfig = new ClusterConfig(topology);
   hostLog.info(
       "Computing partitions to replace.  Total partitions: " + clusterConfig.getPartitionCount());
   Map<Integer, Integer> repsPerPart = new HashMap<Integer, Integer>();
   for (int i = 0; i < clusterConfig.getPartitionCount(); i++) {
     repsPerPart.put(i, getReplicaCountForPartition(i));
   }
   List<Integer> partitions =
       computeReplacementPartitions(
           repsPerPart,
           clusterConfig.getReplicationFactor(),
           clusterConfig.getSitesPerHost(),
           clusterConfig.getPartitionCount());
   hostLog.info("IV2 Sites will replicate the following partitions: " + partitions);
   return partitions;
 }