Class RackAwarePlacement

java.lang.Object
com.loomcache.server.cluster.RackAwarePlacement

public class RackAwarePlacement extends Object
Ensures partition replicas are distributed across racks for fault tolerance.

Strategy:

  • Respects placement constraints (min racks, max replicas per rack)
  • Validates existing placements
  • Suggests optimal placement for new partitions

Thread safety: uses ReentrantLock for cluster topology access.

Since:
1.0
  • Constructor Details

    • RackAwarePlacement

      public RackAwarePlacement(RackAwarePlacement.ClusterTopology clusterTopology)
      Create a new RackAwarePlacement with default constraints.
      Parameters:
      clusterTopology - the cluster topology information
    • RackAwarePlacement

      public RackAwarePlacement(RackAwarePlacement.ClusterTopology clusterTopology, RackAwarePlacement.PlacementConstraint constraint)
      Create a new RackAwarePlacement with specified constraints.
      Parameters:
      clusterTopology - the cluster topology information
      constraint - the placement constraints to enforce
  • Method Details

    • validatePlacement

      public boolean validatePlacement(String partitionId, List<String> replicas)
      Validate that a partition's replica placement respects constraints.
      Parameters:
      partitionId - the partition ID
      replicas - list of node IDs that hold this partition's replicas
      Returns:
      true if placement is valid, false otherwise
      Throws:
      IllegalArgumentException - if parameters are invalid
    • suggestPlacement

      public List<String> suggestPlacement(String partitionId, int replicaCount)
      Suggest an optimal placement for a new partition.

      Algorithm:

      1. Identify available racks
      2. Distribute replicas across racks to minimize failure correlation
      3. Respect maxReplicasPerRack constraint
      Parameters:
      partitionId - the partition ID
      replicaCount - desired number of replicas
      Returns:
      list of node IDs for the replicas, or empty list if placement impossible
      Throws:
      IllegalArgumentException - if parameters are invalid