|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectvoldemort.utils.RebalanceUtils
public class RebalanceUtils
RebalanceUtils provide basic functionality for rebalancing.
| Field Summary | |
|---|---|
static java.util.List<java.lang.String> |
canRebalanceList
|
static java.lang.String |
finalClusterFileName
|
static java.lang.String |
initialClusterFileName
|
| Constructor Summary | |
|---|---|
RebalanceUtils()
|
|
| Method Summary | |
|---|---|
static Node |
addPartitionToNode(Node node,
java.lang.Integer donatedPartition)
Add a partition to the node provided |
static Node |
addPartitionToNode(Node node,
java.util.Set<java.lang.Integer> donatedPartitions)
Add the set of partitions to the node provided |
static void |
assertSameDonor(java.util.List<RebalancePartitionsInfo> partitionInfos,
int expectedDonorId)
Given a list of partition informations check all of them belong to the same donor 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. |
static boolean |
checkPartitionBelongsToNode(int partition,
int replicaType,
int nodeId,
Cluster cluster,
StoreDefinition storeDef)
|
static void |
combinePartitionTuples(java.util.Map<java.lang.Integer,java.util.Set<Pair<java.lang.Integer,java.lang.Integer>>> existingPartitionTuples,
java.util.Map<java.lang.Integer,java.util.Set<Pair<java.lang.Integer,java.lang.Integer>>> newPartitionTuples)
Given a mapping of existing node ids to their partition tuples and another new set of node ids to partition tuples, combines them together and puts it into the existing partition tuples |
static boolean |
containsNode(Cluster cluster,
int nodeId)
Given a cluster and a node id checks if the node exists |
static boolean |
containsPreferenceList(Cluster cluster,
java.util.List<java.lang.Integer> preferenceList,
int nodeId)
Given a preference list and a node id, check if any one of the partitions is on the node in picture |
static java.util.concurrent.ExecutorService |
createExecutors(int numThreads)
|
static AdminClient |
createTempAdminClient(VoldemortConfig voldemortConfig,
Cluster cluster,
int numConnPerNode)
|
static Cluster |
createUpdatedCluster(Cluster currentCluster,
int stealerNodeId,
java.util.List<java.lang.Integer> donatedPartitions)
Updates the existing cluster such that we remove partitions mentioned from the stealer node and add them to the donor node |
static void |
dumpCluster(Cluster initialCluster,
Cluster finalCluster,
java.io.File outputDir)
Given the initial and final cluster dumps it into the output directory |
static void |
executorShutDown(java.util.concurrent.ExecutorService executorService,
long timeOutSec)
Wait to shutdown service |
static java.util.List<RebalancePartitionsInfo> |
filterPartitionPlanWithStores(java.util.List<RebalancePartitionsInfo> existingPlanList,
java.util.List<StoreDefinition> storeDefs)
Given a list of partition plans and a set of stores, copies the store names to every individual plan and creates a new list |
static java.util.List<StoreDefinition> |
filterStores(java.util.List<StoreDefinition> storeDefs,
boolean isReadOnly)
Given a list of store definitions, filters the list depending on the boolean |
static java.util.List<RebalancePartitionsInfo> |
flattenNodePlans(java.util.List<RebalanceNodePlan> rebalanceNodePlanList)
Given a list of node plans flattens it into a list of partitions info |
static java.util.Set<Pair<java.lang.Integer,java.lang.Integer>> |
flattenPartitionTuples(java.util.HashMap<java.lang.Integer,java.util.List<java.lang.Integer>> replicaToPartitionList)
Given a map of replica_type to partition mapping gives back a set of tuples of [replica_type, partition] |
static java.util.HashMap<java.lang.Integer,java.util.List<java.lang.Integer>> |
flattenPartitionTuples(java.util.Set<Pair<java.lang.Integer,java.lang.Integer>> partitionTuples)
Given a list of tuples of [replica_type, partition], flattens it and generates a map of replica_type to partition mapping |
static Pair<Cluster,java.lang.Integer> |
generateMinCluster(Cluster currentCluster,
Cluster targetCluster,
java.util.List<StoreDefinition> storeDefs)
Takes the current cluster metadata and target cluster metadata ( which contains all the nodes of current cluster + new nodes with empty partitions ), and generates a new cluster with some partitions moved to the new node |
static void |
generateMinCluster(Cluster currentCluster,
Cluster targetCluster,
java.util.List<StoreDefinition> storeDefs,
java.lang.String outputDir,
int tries)
Outputs an optimized cluster based on the existing cluster and the new nodes that are being added. |
static Cluster |
getClusterWithNewNodes(Cluster currentCluster,
Cluster targetCluster)
Given the current cluster and a target cluster, generates a cluster with new nodes ( which in turn contain empty partition lists ) |
static int |
getCrossZoneMoves(Cluster targetCluster,
RebalanceClusterPlan plan)
Return the number of cross zone copying that is going to take place |
static java.util.Map<java.lang.Integer,java.lang.Integer> |
getCurrentPartitionMapping(Cluster currentCluster)
Given the cluster metadata returns a mapping of partition to node |
static Versioned<Cluster> |
getLatestCluster(java.util.List<java.lang.Integer> requiredNodes,
AdminClient adminClient)
Get the latest cluster from all available nodes in the cluster Throws exception if: A) Any node in the required nodes list fails to respond. B) Cluster is in inconsistent state with concurrent versions for cluster metadata on any two nodes. |
static Node |
getNodeByPartitionId(Cluster cluster,
int partitionId)
Returns the Node associated to the provided partition. |
static java.util.List<java.lang.Integer> |
getNodeIds(java.util.List<Node> nodes)
Given a list of nodes, retrieves the list of node ids |
static java.util.Map<java.lang.Integer,java.util.Set<Pair<java.lang.Integer,java.lang.Integer>>> |
getNodeIdToAllPartitions(Cluster cluster,
StoreDefinition storeDef,
boolean includePrimary)
For a particular cluster creates a mapping of node id to their corresponding list of [ replicaType, partition ] tuple |
static java.util.HashMap<java.lang.Integer,java.util.List<java.lang.Integer>> |
getOptimizedReplicaToPartitionList(int stealerNodeId,
Cluster cluster,
StoreDefinition storeDef,
java.util.HashMap<java.lang.Integer,java.util.List<java.lang.Integer>> currentReplicaToPartitionList)
Given the current replica to partition list, try to check if the donor node would already contain that partition and if yes, ignore it |
static java.util.List<java.lang.Integer> |
getPartitionsFromTuples(java.util.Set<Pair<java.lang.Integer,java.lang.Integer>> tuples)
Given a set of [ replica, partition ] tuples, flatten it to retrieve only the partitions |
static java.util.Map<java.lang.Integer,java.util.Set<Pair<java.lang.Integer,java.lang.Integer>>> |
getStolenPartitionTuples(Cluster currentCluster,
Cluster targetCluster,
StoreDefinition storeDef)
Find all [replica_type, partition] tuples to be stolen |
static java.util.List<java.lang.Integer> |
getStolenPrimaryPartitions(Cluster currentCluster,
Cluster targetCluster,
int stealNodeId)
For a particular stealer node find all the "primary" |
static java.util.List<StoreDefinition> |
getStoreDefinition(Cluster cluster,
AdminClient adminClient)
Given the cluster metadata and admin client, retrieves the list of store definitions. |
static StoreDefinition |
getStoreDefinitionWithName(java.util.List<StoreDefinition> storeDefs,
java.lang.String storeName)
Given a store name and a list of store definitions, returns the appropriate store definition ( if it exists ) |
static java.util.List<java.lang.String> |
getStoreNames(java.util.List<StoreDefinition> storeDefList)
Given a list of store definitions return a list of store names |
static int |
getTotalMoves(RebalanceClusterPlan plan)
Return the number of total moves |
static java.util.HashMap<java.lang.Integer,java.util.List<RebalancePartitionsInfo>> |
groupPartitionsInfoByNode(java.util.List<RebalancePartitionsInfo> rebalancePartitionPlanList,
boolean groupByStealerNode)
Given a list of partition infos, generates a map of stealer / donor node to list of partition infos |
static void |
printErrorLog(int taskId,
org.apache.log4j.Logger logger,
java.lang.String message,
java.lang.Exception e)
Print log to the following logger ( Error level ) |
static void |
printLog(int taskId,
org.apache.log4j.Logger logger,
java.lang.String message)
Print log to the following logger ( Info level ) |
static java.lang.String |
printMap(java.util.Map<java.lang.Integer,java.util.Set<Pair<java.lang.Integer,java.lang.Integer>>> nodeIdToAllPartitions)
Returns a string representation of the cluster |
static void |
propagateCluster(AdminClient adminClient,
Cluster cluster)
Attempt to propagate a cluster definition to all nodes. |
static Node |
removePartitionToNode(Node node,
java.lang.Integer donatedPartition)
Remove a partition from the node provided |
static Node |
removePartitionToNode(Node node,
java.util.Set<java.lang.Integer> donatedPartitions)
Remove the set of partitions from the node provided |
static Cluster |
updateCluster(Cluster currentCluster,
java.util.List<Node> updatedNodeList)
Concatenates the list of current nodes in the given cluster with the new nodes provided and returns an updated cluster metadata. |
static Node |
updateNode(Node node,
java.util.List<java.lang.Integer> partitionsList)
Creates a replica of the node with the new partitions list |
static void |
validateClusterState(Cluster cluster,
AdminClient adminClient)
Check the execution state of the server by checking the state of MetadataStore.VoldemortState This function checks if the nodes are all in normal state ( MetadataStore.VoldemortState.NORMAL_SERVER). |
static void |
validateReadOnlyStores(Cluster cluster,
java.util.List<StoreDefinition> storeDefs,
AdminClient adminClient)
Given a list of store definitions, cluster and admin client returns a boolean indicating if all RO stores are in the correct format. |
static java.util.List<StoreDefinition> |
validateRebalanceStore(java.util.List<StoreDefinition> storeDefList)
Given a list of store definitions, makes sure that rebalance supports all of them. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.util.List<java.lang.String> canRebalanceList
public static final java.lang.String initialClusterFileName
public static final java.lang.String finalClusterFileName
| Constructor Detail |
|---|
public RebalanceUtils()
| Method Detail |
|---|
public static java.util.HashMap<java.lang.Integer,java.util.List<java.lang.Integer>> getOptimizedReplicaToPartitionList(int stealerNodeId,
Cluster cluster,
StoreDefinition storeDef,
java.util.HashMap<java.lang.Integer,java.util.List<java.lang.Integer>> currentReplicaToPartitionList)
stealerNodeId - Stealer node idcluster - Cluster metadatastoreDef - Store definitioncurrentReplicaToPartitionList - Current replica to partition list
public static Versioned<Cluster> getLatestCluster(java.util.List<java.lang.Integer> requiredNodes,
AdminClient adminClient)
requiredNodes - List of nodes from which we definitely need an
answeradminClient - Admin client used to query the nodes
public static int getCrossZoneMoves(Cluster targetCluster,
RebalanceClusterPlan plan)
targetCluster - Target cluster metadataplan - The rebalance plan
public static int getTotalMoves(RebalanceClusterPlan plan)
plan - The rebalance plan
public static void assertSameDonor(java.util.List<RebalancePartitionsInfo> partitionInfos,
int expectedDonorId)
partitionInfos - List of partition infosexpectedDonorId - Expected donor node id ( If -1, then just checks
if all are same )
public static void generateMinCluster(Cluster currentCluster,
Cluster targetCluster,
java.util.List<StoreDefinition> storeDefs,
java.lang.String outputDir,
int tries)
currentCluster - Current cluster metadatatargetCluster - The target cluster metadata which contains the nodes
of the current cluster + new nodes with empty partitionsstoreDefs - List of store definitionsoutputDir - The output directory where we'll store the cluster
metadata ( if not null )tries - Number of times we'll try to optimize the metadata
generation
public static Pair<Cluster,java.lang.Integer> generateMinCluster(Cluster currentCluster,
Cluster targetCluster,
java.util.List<StoreDefinition> storeDefs)
currentCluster - Current cluster metadatatargetCluster - Target cluster metadata ( which contains old nodes +
new nodes [ empty partitions ])storeDefs - List of store definitions
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)
nodeId - Node on which this is running ( generally stealer node )key - The key to checkreplicaToPartitionList - Mapping of replica type to partition listcluster - Cluster metadatastoreDef - The store definition
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)
keyPartitions - Preference list of the keynodePartitions - Partition list on this nodereplicaToPartitionList - Mapping of replica type to partition list
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)
key - Byte array of keystealerNodeToMappingTuples - Pairs of stealer node id to their
corresponding [ partition - replica ] tuplescluster - Cluster metadatastoreDef - Store definitions
public static boolean checkPartitionBelongsToNode(int partition,
int replicaType,
int nodeId,
Cluster cluster,
StoreDefinition storeDef)
public static boolean checkKeyBelongsToNode(byte[] key,
int nodeId,
Cluster cluster,
StoreDefinition storeDef)
key - nodeId - cluster - storeDef -
public static boolean checkPartitionBelongsToNode(int partition,
int nodeId,
Cluster cluster,
StoreDefinition storeDef)
partition - nodeId - cluster - storeDef -
public static void validateClusterState(Cluster cluster,
AdminClient adminClient)
MetadataStore.VoldemortState MetadataStore.VoldemortState.NORMAL_SERVER).
cluster - Cluster metadata whose nodes we are checkingadminClient - Admin client used to query
VoldemortRebalancingException - if any node is not in normal state
public static Cluster getClusterWithNewNodes(Cluster currentCluster,
Cluster targetCluster)
currentCluster - Current cluster metadatatargetCluster - Target cluster metadata
public static Cluster updateCluster(Cluster currentCluster,
java.util.List<Node> updatedNodeList)
currentCluster - The current cluster metadataupdatedNodeList - The list of new nodes to be added
public static boolean containsNode(Cluster cluster,
int nodeId)
cluster - The cluster metadata to check innodeId - The node id to search for
public static boolean containsPreferenceList(Cluster cluster,
java.util.List<java.lang.Integer> preferenceList,
int nodeId)
cluster - Cluster metadatapreferenceList - Preference list of partition idsnodeId - Node id which we are checking for
public static Cluster createUpdatedCluster(Cluster currentCluster,
int stealerNodeId,
java.util.List<java.lang.Integer> donatedPartitions)
currentCluster - Existing cluster metadata. Both stealer and donor
node should already exist in this metadatastealerNodeId - Id of node from which we are stealing the partitionsdonatedPartitions - List of partitions we are movingpartitionList - List of partitions we are moving
public static Node updateNode(Node node,
java.util.List<java.lang.Integer> partitionsList)
node - The node whose replica we are creatingpartitionsList - The new partitions list
public static Node addPartitionToNode(Node node,
java.lang.Integer donatedPartition)
node - The node to which we'll add the partitiondonatedPartition - The partition to add
public static Node removePartitionToNode(Node node,
java.lang.Integer donatedPartition)
node - The node from which we're removing the partitiondonatedPartition - The partitions to remove
public static Node addPartitionToNode(Node node,
java.util.Set<java.lang.Integer> donatedPartitions)
node - The node to which we'll add the partitionsdonatedPartitions - The list of partitions to add
public static Node removePartitionToNode(Node node,
java.util.Set<java.lang.Integer> donatedPartitions)
node - The node from which we're removing the partitionsdonatedPartitions - The list of partitions to remove
public static java.util.Map<java.lang.Integer,java.lang.Integer> getCurrentPartitionMapping(Cluster currentCluster)
currentCluster - Cluster metadata
public static void propagateCluster(AdminClient adminClient,
Cluster cluster)
adminClient - AdminClient
instance to use.cluster - Cluster definition to propagate
public static java.util.List<java.lang.Integer> getStolenPrimaryPartitions(Cluster currentCluster,
Cluster targetCluster,
int stealNodeId)
currentCluster - The cluster definition of the existing clustertargetCluster - The target cluster definitionstealNodeId - Node id of the stealer node
public static java.util.Map<java.lang.Integer,java.util.Set<Pair<java.lang.Integer,java.lang.Integer>>> getStolenPartitionTuples(Cluster currentCluster,
Cluster targetCluster,
StoreDefinition storeDef)
currentCluster - Current cluster metadatatargetCluster - Target cluster metadatastoreDef - Store Definition
public static void combinePartitionTuples(java.util.Map<java.lang.Integer,java.util.Set<Pair<java.lang.Integer,java.lang.Integer>>> existingPartitionTuples,
java.util.Map<java.lang.Integer,java.util.Set<Pair<java.lang.Integer,java.lang.Integer>>> newPartitionTuples)
existingPartitionTuples - Existing partition tuples ( Will include
the new partition tuples at the end of this function )newPartitionTuples - New partition tuples
public static java.util.Map<java.lang.Integer,java.util.Set<Pair<java.lang.Integer,java.lang.Integer>>> getNodeIdToAllPartitions(Cluster cluster,
StoreDefinition storeDef,
boolean includePrimary)
cluster - The cluster metadatastoreDef - The store definitionincludePrimary - Include the primary partition?
public static void dumpCluster(Cluster initialCluster,
Cluster finalCluster,
java.io.File outputDir)
initialCluster - Initial cluster metadatafinalCluster - Final cluster metadataoutputDir - Output directory where to dump this file
java.io.IOException
public static void printLog(int taskId,
org.apache.log4j.Logger logger,
java.lang.String message)
taskId - Task idlogger - Logger classmessage - The message to print
public static void printErrorLog(int taskId,
org.apache.log4j.Logger logger,
java.lang.String message,
java.lang.Exception e)
taskId - Stealer node idlogger - Logger classmessage - The message to print
public static Node getNodeByPartitionId(Cluster cluster,
int partitionId)
cluster - The cluster in which to find the nodepartitionId - Partition id for which we want the corresponding node
public static AdminClient createTempAdminClient(VoldemortConfig voldemortConfig,
Cluster cluster,
int numConnPerNode)
public static java.util.List<StoreDefinition> getStoreDefinition(Cluster cluster,
AdminClient adminClient)
cluster - The cluster metadataadminClient - The admin client to use to retrieve the store
definitions
public static java.util.List<StoreDefinition> validateRebalanceStore(java.util.List<StoreDefinition> storeDefList)
storeDefList - List of store definitions
public static void validateReadOnlyStores(Cluster cluster,
java.util.List<StoreDefinition> storeDefs,
AdminClient adminClient)
cluster - Cluster metadatastoreDefs - Complete list of store definitionsadminClient - Admin clientpublic static java.lang.String printMap(java.util.Map<java.lang.Integer,java.util.Set<Pair<java.lang.Integer,java.lang.Integer>>> nodeIdToAllPartitions)
Current Cluster: 0 - [0, 1, 2, 3] + [7, 8, 9] 1 - [4, 5, 6] + [0, 1, 2, 3] 2 - [7, 8, 9] + [4, 5, 6]
nodeIdToAllPartitions - Mapping of node id to all tuples
public static java.util.HashMap<java.lang.Integer,java.util.List<java.lang.Integer>> flattenPartitionTuples(java.util.Set<Pair<java.lang.Integer,java.lang.Integer>> partitionTuples)
partitionTuples - Set of public static java.util.Set<Pair<java.lang.Integer,java.lang.Integer>> flattenPartitionTuples(java.util.HashMap<java.lang.Integer,java.util.List<java.lang.Integer>> replicaToPartitionList)
replicaToPartitionList - Map of replica_type to set of partitions
public static java.util.List<RebalancePartitionsInfo> flattenNodePlans(java.util.List<RebalanceNodePlan> rebalanceNodePlanList)
rebalanceNodePlanList - Complete list of rebalance node plan
public static java.util.List<java.lang.Integer> getPartitionsFromTuples(java.util.Set<Pair<java.lang.Integer,java.lang.Integer>> tuples)
tuples - The [ replica, partition ] tuples
public static java.util.List<RebalancePartitionsInfo> filterPartitionPlanWithStores(java.util.List<RebalancePartitionsInfo> existingPlanList,
java.util.List<StoreDefinition> storeDefs)
existingPlanList - Existing partition plan liststoreDefs - List of store names we are rebalancing
public static java.util.HashMap<java.lang.Integer,java.util.List<RebalancePartitionsInfo>> groupPartitionsInfoByNode(java.util.List<RebalancePartitionsInfo> rebalancePartitionPlanList,
boolean groupByStealerNode)
rebalancePartitionPlanList - Complete list of partition plansgroupByStealerNode - Boolean indicating if we want to group by
stealer node ( or donor node )
public static StoreDefinition getStoreDefinitionWithName(java.util.List<StoreDefinition> storeDefs,
java.lang.String storeName)
storeDefs - List of store definitionsstoreName - The store name whose store definition is required
public static java.util.List<StoreDefinition> filterStores(java.util.List<StoreDefinition> storeDefs,
boolean isReadOnly)
storeDefs - Complete list of store definitionsisReadOnly - Boolean indicating whether filter on read-only or not?
public static java.util.List<java.lang.String> getStoreNames(java.util.List<StoreDefinition> storeDefList)
storeDefList - The list of store definitions
public static java.util.List<java.lang.Integer> getNodeIds(java.util.List<Node> nodes)
nodes - The list of nodes
public static void executorShutDown(java.util.concurrent.ExecutorService executorService,
long timeOutSec)
executorService - Executor service to shutdowntimeOutSec - Time we wait forpublic static java.util.concurrent.ExecutorService createExecutors(int numThreads)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||