The ironic.common.hash_ring
Module¶
-
class
ironic.common.hash_ring.
HashRing
(hosts, replicas=None)[source]¶ Bases:
object
A stable hash ring.
We map item N to a host Y based on the closest lower hash:
- hash(item) -> partition
- hash(host) -> divider
- closest lower divider is the host to use
- we hash each host many times to spread load more finely as otherwise adding a host gets (on average) 50% of the load of just one other host assigned to it.
-
get_hosts
(data, ignore_hosts=None)[source]¶ Get the list of hosts which the supplied data maps onto.
Parameters: - data – A string identifier to be mapped across the ring.
- ignore_hosts – A list of hosts to skip when performing the hash. Useful to temporarily skip down hosts without performing a full rebalance. Default: None.
Returns: a list of hosts. The length of this list depends on the number of replicas this HashRing was created with. It may be less than this if ignore_hosts is not None.