Class ConsistentHashRing

java.lang.Object
org.apache.hadoop.hdfs.server.federation.utils.ConsistentHashRing

public class ConsistentHashRing extends Object
Consistent hash ring to distribute items across nodes (locations). If we add or remove nodes, it minimizes the item migration.
  • Constructor Details

    • ConsistentHashRing

      public ConsistentHashRing(Set<String> locations)
  • Method Details

    • addLocation

      public void addLocation(String location)
      Add entry to consistent hash ring.
      Parameters:
      location - Node to add to the ring.
    • addLocation

      public void addLocation(String location, int numVirtualNodes)
      Add entry to consistent hash ring.
      Parameters:
      location - Node to add to the ring.
      numVirtualNodes - Number of virtual nodes to add.
    • removeLocation

      public void removeLocation(String location)
      Remove specified entry from hash ring.
      Parameters:
      location - Node to remove from the ring.
    • getLocation

      public String getLocation(String item)
      Return location (owner) of specified item. Owner is the next entry on the hash ring (with a hash value > hash value of item).
      Parameters:
      item - Item to look for.
      Returns:
      The location of the item.
    • getHash

      public String getHash(String key)
    • getLocations

      public Set<String> getLocations()
      Get the locations in the ring.
      Returns:
      Set of locations in the ring.