ConsistentHashRing (Apache Hadoop HDFS-RBF 3.5.0 API)
Description: declaration: package: org.apache.hadoop.hdfs.server.federation.utils, class: ConsistentHashRing

Package org.apache.hadoop.hdfs.server.federation.utils

# 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 Summary

  Constructors
  Constructor
  Description
  `ConsistentHashRing(Set<String> locations)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addLocation(String location)`
  Add entry to consistent hash ring.
  `void`
  `addLocation(String location, int numVirtualNodes)`
  Add entry to consistent hash ring.
  `String`
  `getHash(String key)`
  `String`
  `getLocation(String item)`
  Return location (owner) of specified item.
  `Set<String>`
  `getLocations()`
  Get the locations in the ring.
  `void`
  `removeLocation(String location)`
  Remove specified entry from hash ring.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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.