public class

ResourceAssignment

extends HelixProperty
java.lang.Object
   ↳ org.apache.helix.HelixProperty
     ↳ org.apache.helix.model.ResourceAssignment

Class Overview

Represents the assignments of replicas for an entire resource, keyed on partitions of the resource. Each partition has its replicas assigned to a node, and each replica is in a state. For example, if there is a partition p with 2 replicas, a valid assignment is:

p: {(n1, s1), (n2, s2)}

This means one replica of p is located at node n1 and is in state s1, and another is in node n2 and is in state s2. n1 cannot be equal to n2, but s1 can be equal to s2 if at least two replicas can be in s1.

Summary

[Expand]
Inherited Fields
From class org.apache.helix.HelixProperty
Public Constructors
ResourceAssignment(ResourceId resourceId)
Initialize an empty mapping
ResourceAssignment(ZNRecord record)
Instantiate from a record.
Public Methods
void addReplicaMap(PartitionId partitionId, Map<ParticipantIdState> replicaMap)
Add participant, state pairs for a partition
List<? extends PartitionId> getMappedPartitionIds()
Get the currently mapped partitions
Map<ParticipantIdState> getReplicaMap(PartitionId partitionId)
Get the participant, state pairs for a partition
ResourceId getResourceId()
Get the resource for which this assignment was created
Map<? extends PartitionIdMap<ParticipantIdState>> getResourceMap()
Get the entire map of a resource
static Map<ParticipantIdState> replicaMapFromStringMap(Map<StringString> rawMap)
Helper for converting a map of strings to a concrete replica map
static Map<? extends PartitionIdMap<ParticipantIdState>> replicaMapsFromStringMaps(Map<StringMap<StringString>> rawMaps)
Convert a full replica mapping as strings into participant state maps
static Map<StringString> stringMapFromReplicaMap(Map<ParticipantIdState> replicaMap)
Helper for converting a replica map to a map of strings
static Map<StringMap<StringString>> stringMapsFromReplicaMaps(Map<? extends PartitionIdMap<ParticipantIdState>> replicaMaps)
Convert a full state mapping into a mapping of string names
[Expand]
Inherited Methods
From class org.apache.helix.HelixProperty
From class java.lang.Object

Public Constructors

public ResourceAssignment (ResourceId resourceId)

Initialize an empty mapping

Parameters
resourceId the resource being mapped

public ResourceAssignment (ZNRecord record)

Instantiate from a record. This supports reading the assignment directly from the backing store

Parameters
record backing record

Public Methods

public void addReplicaMap (PartitionId partitionId, Map<ParticipantIdState> replicaMap)

Add participant, state pairs for a partition

Parameters
partitionId the partition to set
replicaMap map of (participant name, state)

public List<? extends PartitionId> getMappedPartitionIds ()

Get the currently mapped partitions

Returns
  • list of Partition objects (immutable)

public Map<ParticipantIdState> getReplicaMap (PartitionId partitionId)

Get the participant, state pairs for a partition

Returns
  • map of (participant id, state)

public ResourceId getResourceId ()

Get the resource for which this assignment was created

Returns
  • resource id

public Map<? extends PartitionIdMap<ParticipantIdState>> getResourceMap ()

Get the entire map of a resource

Returns
  • map of partition to participant to state

public static Map<ParticipantIdState> replicaMapFromStringMap (Map<StringString> rawMap)

Helper for converting a map of strings to a concrete replica map

Parameters
rawMap map of participant name to state name
Returns
  • map of participant id to state

public static Map<? extends PartitionIdMap<ParticipantIdState>> replicaMapsFromStringMaps (Map<StringMap<StringString>> rawMaps)

Convert a full replica mapping as strings into participant state maps

Parameters
rawMaps the map of partition name to participant name and state
Returns
  • converted maps

public static Map<StringString> stringMapFromReplicaMap (Map<ParticipantIdState> replicaMap)

Helper for converting a replica map to a map of strings

Parameters
replicaMap map of participant id to state
Returns
  • map of participant name to state name

public static Map<StringMap<StringString>> stringMapsFromReplicaMaps (Map<? extends PartitionIdMap<ParticipantIdState>> replicaMaps)

Convert a full state mapping into a mapping of string names

Parameters
replicaMaps the map of partition id to participant id and state
Returns
  • converted maps