voldemort.routing
Class StoreRoutingPlan

java.lang.Object
  extended by voldemort.routing.StoreRoutingPlan

public class StoreRoutingPlan
extends java.lang.Object

This class wraps up a Cluster object and a StoreDefinition. The methods are effectively helper or util style methods for querying the routing plan that will be generated for a given routing strategy upon store and cluster topology information. This object can be expensive to construct. Invocations of getters should be O(1) if possible. Lazy initialization of cached values is ideal... The intermingling of key-based interfaces and partition-based interfaces is ugly in this class. Partition-based interfaces should be in an underlying class and then key-based interfaces should wrap those up. Or, all of these types of class should implement the getMasterPartition(byte[]) interface from RoutingStrategy. Then the caller always does translation from key to partition ID, and the *StoreRouting* classes only offer partition-based interfaces.


Constructor Summary
StoreRoutingPlan(Cluster cluster, StoreDefinition storeDefinition)
           
 
Method Summary
 boolean checkKeyBelongsToNode(byte[] key, int nodeId)
          Determines if the key replicates to the given node
static boolean checkKeyBelongsToNode(byte[] key, int nodeId, Cluster cluster, StoreDefinition storeDef)
           
static java.util.List<java.lang.Integer> checkKeyBelongsToPartition(byte[] key, java.util.Set<Pair<java.lang.Integer,java.util.HashMap<java.lang.Integer,java.util.List<java.lang.Integer>>>> stealerNodeToMappingTuples, Cluster cluster, StoreDefinition storeDef)
          Given a key and a list of steal infos give back a list of stealer node ids which will steal this.
static boolean checkKeyBelongsToPartition(int nodeId, byte[] key, java.util.HashMap<java.lang.Integer,java.util.List<java.lang.Integer>> replicaToPartitionList, Cluster cluster, StoreDefinition storeDef)
          Check that the key belongs to one of the partitions in the map of replica type to partitions
static boolean checkKeyBelongsToPartition(java.util.List<java.lang.Integer> keyPartitions, java.util.List<java.lang.Integer> nodePartitions, java.util.HashMap<java.lang.Integer,java.util.List<java.lang.Integer>> replicaToPartitionList)
          Check that the key belongs to one of the partitions in the map of replica type to partitions
static boolean checkPartitionBelongsToNode(int partition, int nodeId, Cluster cluster, StoreDefinition storeDef)
          Checks if a given partition is stored in the node.
 Cluster getCluster()
           
 int getMasterPartitionId(byte[] key)
          Determines master partition ID for the key.
 int getNodeIdForPartitionId(int partitionId)
          Determines node ID that hosts the specified partition ID.
 int getNodeIdForZoneNary(int zoneId, int zoneNary, int partitionId)
          Determines which node hosts partition id with specified n-ary level in specified zone.
 java.lang.Integer getNodesPartitionIdForKey(int nodeId, byte[] key)
          Determines the partition ID that replicates the key on the given node.
 java.util.List<java.lang.Integer> getReplicatingPartitionList(byte[] key)
          Determines list of partition IDs that replicate the key.
 java.util.List<java.lang.Integer> getReplicatingPartitionList(int masterPartitionId)
          Determines list of partition IDs that replicate the master partition ID.
 java.util.List<java.lang.Integer> getReplicationNodeList(int partitionId)
          Returns the list of node ids this partition replicates to.
 StoreDefinition getStoreDefinition()
           
 int getZoneNaryForNodesPartition(int zoneId, int nodeId, int partitionId)
          Determines the zone n-ary replica level of the specified partitionId on the node id in zone id.
 java.util.List<java.lang.Integer> getZoneNAryPartitionIds(int nodeId)
          Returns all (zone n-ary) partition IDs hosted on the node.
 java.util.List<java.lang.Integer> getZonePrimaryPartitionIds(int nodeId)
          Returns all zone-primary partition IDs on node.
 boolean zoneNAryExists(int zoneId, int zoneNAry, int partitionId)
          checks if zone has a zone n-ary for partition Id.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StoreRoutingPlan

public StoreRoutingPlan(Cluster cluster,
                        StoreDefinition storeDefinition)
Method Detail

getCluster

public Cluster getCluster()

getStoreDefinition

public StoreDefinition getStoreDefinition()

getReplicatingPartitionList

public java.util.List<java.lang.Integer> getReplicatingPartitionList(int masterPartitionId)
Determines list of partition IDs that replicate the master partition ID.

Parameters:
masterPartitionId -
Returns:
List of partition IDs that replicate the master partition ID.

getReplicatingPartitionList

public java.util.List<java.lang.Integer> getReplicatingPartitionList(byte[] key)
Determines list of partition IDs that replicate the key.

Parameters:
key -
Returns:
List of partition IDs that replicate the given key

getMasterPartitionId

public int getMasterPartitionId(byte[] key)
Determines master partition ID for the key.

Parameters:
key -
Returns:
master partition id

getNodeIdForPartitionId

public int getNodeIdForPartitionId(int partitionId)
Determines node ID that hosts the specified partition ID.

Parameters:
partitionId -
Returns:
node id that hosts primary partition id.

getNodesPartitionIdForKey

public java.lang.Integer getNodesPartitionIdForKey(int nodeId,
                                                   byte[] key)
Determines the partition ID that replicates the key on the given node.

Parameters:
nodeId - of the node
key - to look up.
Returns:
partitionId if found, otherwise null.

getReplicationNodeList

public java.util.List<java.lang.Integer> getReplicationNodeList(int partitionId)
                                                         throws VoldemortException
Returns the list of node ids this partition replicates to. TODO ideally the RoutingStrategy should house a routeRequest(int partition) method

Parameters:
partitionId -
Returns:
list of node ids
Throws:
VoldemortException

getZoneNAryPartitionIds

public java.util.List<java.lang.Integer> getZoneNAryPartitionIds(int nodeId)
Returns all (zone n-ary) partition IDs hosted on the node.

Parameters:
nodeId -
Returns:
all zone n-ary partition IDs hosted on the node in an unordered list.

getZonePrimaryPartitionIds

public java.util.List<java.lang.Integer> getZonePrimaryPartitionIds(int nodeId)
Returns all zone-primary partition IDs on node. A zone-primary means zone n-ary==0. Zone-primary nodes are generally pseudo-masters in the zone and receive get traffic for some partition Id.

Parameters:
nodeId -
Returns:
all primary partition IDs (zone n-ary == 0) hosted on the node.

zoneNAryExists

public boolean zoneNAryExists(int zoneId,
                              int zoneNAry,
                              int partitionId)
checks if zone has a zone n-ary for partition Id. False should only be returned in zone expansion use cases.

Parameters:
zoneId -
zoneNAry - zone n-ary replica to confirm
partitionId -
Returns:
true iff partitionId has zone-nary replica in zone id .

getZoneNaryForNodesPartition

public int getZoneNaryForNodesPartition(int zoneId,
                                        int nodeId,
                                        int partitionId)
Determines the zone n-ary replica level of the specified partitionId on the node id in zone id.

Parameters:
zoneId -
nodeId -
partitionId -
Returns:
zone n-ary replica level of the partition id on the node id in the zone id (primary == 0, secondary == 1, ...)

checkKeyBelongsToNode

public boolean checkKeyBelongsToNode(byte[] key,
                                     int nodeId)
Determines if the key replicates to the given node

Parameters:
key -
nodeId -
Returns:
true if the key belongs to the node as some replica

checkKeyBelongsToPartition

public static boolean checkKeyBelongsToPartition(java.util.List<java.lang.Integer> keyPartitions,
                                                 java.util.List<java.lang.Integer> nodePartitions,
                                                 java.util.HashMap<java.lang.Integer,java.util.List<java.lang.Integer>> replicaToPartitionList)
Check that the key belongs to one of the partitions in the map of replica type to partitions

Parameters:
keyPartitions - Preference list of the key
nodePartitions - Partition list on this node
replicaToPartitionList - Mapping of replica type to partition list
Returns:
Returns a boolean to indicate if this belongs to the map

checkKeyBelongsToPartition

public static boolean checkKeyBelongsToPartition(int nodeId,
                                                 byte[] key,
                                                 java.util.HashMap<java.lang.Integer,java.util.List<java.lang.Integer>> replicaToPartitionList,
                                                 Cluster cluster,
                                                 StoreDefinition storeDef)
Check that the key belongs to one of the partitions in the map of replica type to partitions

Parameters:
nodeId - Node on which this is running ( generally stealer node )
key - The key to check
replicaToPartitionList - Mapping of replica type to partition list
cluster - Cluster metadata
storeDef - The store definition
Returns:
Returns a boolean to indicate if this belongs to the map

checkKeyBelongsToPartition

public static java.util.List<java.lang.Integer> checkKeyBelongsToPartition(byte[] key,
                                                                           java.util.Set<Pair<java.lang.Integer,java.util.HashMap<java.lang.Integer,java.util.List<java.lang.Integer>>>> stealerNodeToMappingTuples,
                                                                           Cluster cluster,
                                                                           StoreDefinition storeDef)
Given a key and a list of steal infos give back a list of stealer node ids which will steal this.

Parameters:
key - Byte array of key
stealerNodeToMappingTuples - Pairs of stealer node id to their corresponding [ partition - replica ] tuples
cluster - Cluster metadata
storeDef - Store definitions
Returns:
List of node ids

checkPartitionBelongsToNode

public static boolean checkPartitionBelongsToNode(int partition,
                                                  int nodeId,
                                                  Cluster cluster,
                                                  StoreDefinition storeDef)
Checks if a given partition is stored in the node.

Parameters:
partition -
nodeId -
cluster -
storeDef -
Returns:
true if partition belongs to node for given store

checkKeyBelongsToNode

public static boolean checkKeyBelongsToNode(byte[] key,
                                            int nodeId,
                                            Cluster cluster,
                                            StoreDefinition storeDef)
Parameters:
key -
nodeId -
cluster -
storeDef -
Returns:
true if the key belongs to the node as some replica

getNodeIdForZoneNary

public int getNodeIdForZoneNary(int zoneId,
                                int zoneNary,
                                int partitionId)
Determines which node hosts partition id with specified n-ary level in specified zone.

Parameters:
zoneId -
zoneNary -
partitionId -
Returns:
node ID that hosts zone n-ary replica of partition.


Jay Kreps, Roshan Sumbaly, Alex Feinberg, Bhupesh Bansal, Lei Gao, Chinmay Soman, Vinoth Chandar, Zhongjie Wu