Class RackAwarePlacement
java.lang.Object
com.loomcache.server.cluster.RackAwarePlacement
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceRepresents the cluster topology for placement calculations.static final recordConstraints for rack-aware placement.static classSimple implementation of ClusterTopology. -
Constructor Summary
ConstructorsConstructorDescriptionRackAwarePlacement(RackAwarePlacement.ClusterTopology clusterTopology) Create a new RackAwarePlacement with default constraints.RackAwarePlacement(RackAwarePlacement.ClusterTopology clusterTopology, RackAwarePlacement.PlacementConstraint constraint) Create a new RackAwarePlacement with specified constraints. -
Method Summary
Modifier and TypeMethodDescriptionsuggestPlacement(String partitionId, int replicaCount) Suggest an optimal placement for a new partition.booleanvalidatePlacement(String partitionId, List<String> replicas) Validate that a partition's replica placement respects constraints.
-
Constructor Details
-
RackAwarePlacement
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 informationconstraint- the placement constraints to enforce
-
-
Method Details
-
validatePlacement
Validate that a partition's replica placement respects constraints.- Parameters:
partitionId- the partition IDreplicas- 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
Suggest an optimal placement for a new partition.Algorithm:
- Identify available racks
- Distribute replicas across racks to minimize failure correlation
- Respect maxReplicasPerRack constraint
- Parameters:
partitionId- the partition IDreplicaCount- desired number of replicas- Returns:
- list of node IDs for the replicas, or empty list if placement impossible
- Throws:
IllegalArgumentException- if parameters are invalid
-