public class

ConsistentHashingMasterSlaveStrategy

extends Object
java.lang.Object
   ↳ org.apache.helix.controller.strategy.ConsistentHashingMasterSlaveStrategy

Summary

Nested Classes
class ConsistentHashingMasterSlaveStrategy.FnvHash The default string hash function. 
interface ConsistentHashingMasterSlaveStrategy.HashFunction Interface to calculate the hash function value of a string  
Public Constructors
ConsistentHashingMasterSlaveStrategy()
Public Methods
static ZNRecord calculateIdealState(List<String> instanceNames, int partitions, int replicas, String resourceName, ConsistentHashingMasterSlaveStrategy.HashFunction hashFunc, int hashRingSize)
Calculate the ideal state for list of instances clusters using consistent hashing.
static ZNRecord calculateIdealState(List<String> instanceNames, int partitions, int replicas, String resourceName, ConsistentHashingMasterSlaveStrategy.HashFunction hashFunc)
Calculate the ideal state for list of instances clusters using consistent hashing.
static void compareHashrings(int[] ring1, int[] ring2)
Helper function to compare the difference between two hashing buffers
static int[] generateEvenHashRing(List<String> instanceNames, int hashRingSize)
static int[] generateHashRing(List<String> instanceNames, int hashRingSize)
Generate the has ring for consistent hashing.
static void main(String[] args)
static void printDiff(ZNRecord record1, ZNRecord record2)
Helper function to see how many partitions are mapped to different instances in two ideal states
static void printHashRingStat(int[] hashRing)
static void printIdealStateStats(ZNRecord record, String value)
Helper function to calculate and print the standard deviation of the partition assignment ideal state, also the min/max of master partitions that is hosted on each node
static void printNodeOfflineOverhead(ZNRecord record)
static void putNodeOnHashring(int[] result, int nodeValue, int numberOfNodes, int randomSeed)
Uniformly put node values on the hash ring.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ConsistentHashingMasterSlaveStrategy ()

Public Methods

public static ZNRecord calculateIdealState (List<String> instanceNames, int partitions, int replicas, String resourceName, ConsistentHashingMasterSlaveStrategy.HashFunction hashFunc, int hashRingSize)

Calculate the ideal state for list of instances clusters using consistent hashing.

Parameters
instanceNames List of instance names.
partitions the partition number of the database
replicas the replication degree
resourceName the name of the database
hashRingSize the size of the hash ring used by consistent hashing
Returns
  • The ZNRecord that contains the ideal state

public static ZNRecord calculateIdealState (List<String> instanceNames, int partitions, int replicas, String resourceName, ConsistentHashingMasterSlaveStrategy.HashFunction hashFunc)

Calculate the ideal state for list of instances clusters using consistent hashing.

Parameters
instanceNames List of instance names.
partitions the partition number of the database
replicas the replication degree
resourceName the name of the database
Returns
  • The ZNRecord that contains the ideal state

public static void compareHashrings (int[] ring1, int[] ring2)

Helper function to compare the difference between two hashing buffers

public static int[] generateEvenHashRing (List<String> instanceNames, int hashRingSize)

public static int[] generateHashRing (List<String> instanceNames, int hashRingSize)

Generate the has ring for consistent hashing.

Parameters
instanceNames List of instance names.
hashRingSize the size of the hash ring used by consistent hashing
Returns
  • The int array as the hashing. it contains random values ranges from 0..size of instanceNames-1

public static void main (String[] args)

Throws
Exception

public static void printDiff (ZNRecord record1, ZNRecord record2)

Helper function to see how many partitions are mapped to different instances in two ideal states

public static void printHashRingStat (int[] hashRing)

public static void printIdealStateStats (ZNRecord record, String value)

Helper function to calculate and print the standard deviation of the partition assignment ideal state, also the min/max of master partitions that is hosted on each node

public static void printNodeOfflineOverhead (ZNRecord record)

public static void putNodeOnHashring (int[] result, int nodeValue, int numberOfNodes, int randomSeed)

Uniformly put node values on the hash ring. Derived from the shuffling algorithm

Parameters
result the hash ring array.
nodeValue the int value to be added to the hash ring this time
numberOfNodes number of node values to put on the hash ring array
randomSeed the random seed