MediaWiki
1.32.5
|
Convenience class for weighted consistent hash rings. More...
Public Member Functions | |
__construct (array $map, $algo='sha1', array $ejections=[]) | |
Make a consistent hash ring given a set of locations and their weight values. More... | |
ejectFromLiveRing ( $location, $ttl) | |
Remove a location from the "live" hash ring. More... | |
getLiveLocation ( $item) | |
Get the location of an item on the "live" ring. More... | |
getLiveLocations ( $item, $limit) | |
Get the location of an item on the "live" ring, as well as the next locations. More... | |
getLiveLocationWeights () | |
Get the map of "live" locations to weight (does not include zero weight items) More... | |
getLocation ( $item) | |
Get the location of an item on the ring. More... | |
getLocations ( $item, $limit, $from=self::RING_ALL) | |
Get the location of an item on the ring, as well as the next locations. More... | |
getLocationWeights () | |
Get the map of locations to weight (does not include zero weight items) More... | |
serialize () | |
unserialize ( $serialized) | |
Public Attributes | |
const | KEY_LOCATION = 1 |
const | KEY_POS = 0 |
Protected Member Functions | |
getCurrentTime () | |
getLiveRing () | |
Get the "live" hash ring (which does not include ejected locations) More... | |
init (array $map, $algo, array $ejections) | |
Protected Attributes | |
string | $algo |
Hashing algorithm for hash() More... | |
array[] | $baseRing |
Non-empty list of (float, node name, location name) More... | |
int[] | $ejectExpiryByLocation |
Map of (location => UNIX timestamp) More... | |
array[] | $liveRing |
Non-empty list of (float, node name, location name) More... | |
int[] | $weightByLocation |
Non-empty (location => integer weight) More... | |
Private Member Functions | |
buildLocationRing (array $weightByLocation, $algo) | |
findNodeIndexForPosition ( $position, $ring) | |
getItemPosition ( $item) | |
getNextClockwiseNodeIndex ( $i, $ring) | |
getNodePositionQuartet ( $nodeGroupName) | |
Convenience class for weighted consistent hash rings.
This deterministically maps "keys" to a set of "locations" while avoiding clumping
Each location is represented by a number of nodes on a ring proportionate to the ratio of its weight compared to the total location weight. Note positions are deterministically derived from the hash of the location name. Nodes are responsible for the portion of the ring, counter-clockwise, up until the next node. Locations are responsible for all portions of the ring that the location's nodes are responsible for.
A location that is temporarily "ejected" is said to be absent from the "live" ring. If no location ejections are active, then the base ring and live ring are identical.
Definition at line 39 of file HashRing.php.
Make a consistent hash ring given a set of locations and their weight values.
int[] | $map | Map of (location => weight) |
string | $algo | Hashing algorithm listed in hash_algos() [optional] |
int[] | $ejections | Map of (location => UNIX timestamp) for ejection expiries |
Definition at line 75 of file HashRing.php.
|
private |
int[] | $weightByLocation | |
string | $algo | Hashing algorithm |
Definition at line 266 of file HashRing.php.
References $weightByLocation, as, captcha-old\count, getNodePositionQuartet(), and string.
Referenced by init().
HashRing::ejectFromLiveRing | ( | $location, | |
$ttl | |||
) |
Remove a location from the "live" hash ring.
string | $location | |
int | $ttl | Seconds |
UnexpectedValueException |
Definition at line 205 of file HashRing.php.
References captcha-old\count, and getCurrentTime().
Referenced by JobQueueFederated\tryJobInsertions().
|
private |
float | $position | |
array[] | $ring | Either the base or live ring |
Definition at line 157 of file HashRing.php.
References captcha-old\count, and KEY_POS.
Referenced by getLocations().
|
protected |
Definition at line 410 of file HashRing.php.
Referenced by ejectFromLiveRing(), getLiveLocationWeights(), and getLiveRing().
|
private |
string | $item | Key |
Definition at line 318 of file HashRing.php.
Referenced by getLocations().
|
final |
Get the location of an item on the "live" ring.
string | $item |
UnexpectedValueException |
Definition at line 225 of file HashRing.php.
References getLocations().
Referenced by JobQueueFederated\tryJobInsertions().
|
final |
Get the location of an item on the "live" ring, as well as the next locations.
string | $item | |
int | $limit | Maximum number of locations to return |
UnexpectedValueException |
Definition at line 237 of file HashRing.php.
References getLocations().
HashRing::getLiveLocationWeights | ( | ) |
Get the map of "live" locations to weight (does not include zero weight items)
UnexpectedValueException |
Definition at line 247 of file HashRing.php.
References getCurrentTime(), and use.
Referenced by JobQueueFederated\doBatchPush(), and JobQueueFederated\tryJobInsertions().
|
protected |
Get the "live" hash ring (which does not include ejected locations)
UnexpectedValueException |
Definition at line 368 of file HashRing.php.
References $baseRing, $liveRing, as, captcha-old\count, getCurrentTime(), KEY_LOCATION, and use.
Referenced by getLocations().
|
final |
Get the location of an item on the ring.
string | $item |
UnexpectedValueException |
Definition at line 109 of file HashRing.php.
References getLocations().
HashRing::getLocations | ( | $item, | |
$limit, | |||
$from = self::RING_ALL |
|||
) |
Get the location of an item on the ring, as well as the next locations.
string | $item | |
int | $limit | Maximum number of locations to return |
int | $from | One of the RING_* class constants |
UnexpectedValueException |
Definition at line 122 of file HashRing.php.
References $baseRing, captcha-old\count, findNodeIndexForPosition(), getItemPosition(), getLiveRing(), getNextClockwiseNodeIndex(), and KEY_LOCATION.
Referenced by getLiveLocation(), getLiveLocations(), and getLocation().
HashRing::getLocationWeights | ( | ) |
Get the map of locations to weight (does not include zero weight items)
Definition at line 193 of file HashRing.php.
References $weightByLocation.
|
private |
int | $i | Valid index for a node in the ring |
array[] | $ring | Either the base or live ring |
Definition at line 352 of file HashRing.php.
References captcha-old\count.
Referenced by getLocations().
|
private |
string | $nodeGroupName |
Definition at line 333 of file HashRing.php.
References as.
Referenced by buildLocationRing().
int[] | $map | Map of (location => integer) |
string | $algo | Hashing algorithm |
int[] | $ejections | Map of (location => UNIX timestamp) for ejection expires |
Definition at line 84 of file HashRing.php.
References $algo, $weightByLocation, and buildLocationRing().
Referenced by __construct(), and unserialize().
HashRing::serialize | ( | ) |
Definition at line 414 of file HashRing.php.
HashRing::unserialize | ( | $serialized | ) |
Definition at line 422 of file HashRing.php.
References $serialized, and init().
|
protected |
Hashing algorithm for hash()
Definition at line 41 of file HashRing.php.
Referenced by __construct(), and init().
|
protected |
Non-empty list of (float, node name, location name)
Definition at line 48 of file HashRing.php.
Referenced by getLiveRing(), and getLocations().
|
protected |
Map of (location => UNIX timestamp)
Definition at line 45 of file HashRing.php.
|
protected |
Non-empty list of (float, node name, location name)
Definition at line 50 of file HashRing.php.
Referenced by getLiveRing().
|
protected |
Non-empty (location => integer weight)
Definition at line 43 of file HashRing.php.
Referenced by buildLocationRing(), getLocationWeights(), and init().
const HashRing::KEY_LOCATION = 1 |
Definition at line 60 of file HashRing.php.
Referenced by getLiveRing(), and getLocations().
const HashRing::KEY_POS = 0 |
Definition at line 59 of file HashRing.php.
Referenced by findNodeIndexForPosition(), and HashRingTest\testHashRingKetamaMode().