MediaWiki REL1_31
HashRing Class Reference

Convenience class for weighted consistent hash rings. More...

Collaboration diagram for HashRing:

Public Member Functions

 __construct (array $map)
 
 ejectFromLiveRing ( $location, $ttl)
 Remove a location from the "live" hash ring.
 
 getLiveLocation ( $item)
 Get the location of an item on the "live" ring.
 
 getLiveLocations ( $item, $limit)
 Get the location of an item on the "live" ring, as well as the next locations.
 
 getLiveLocationWeights ()
 Get the map of "live" locations to weight (ignores 0-weight items)
 
 getLocation ( $item)
 Get the location of an item on the ring.
 
 getLocations ( $item, $limit)
 Get the location of an item on the ring, as well as the next locations.
 
 getLocationWeights ()
 Get the map of locations to weight (ignores 0-weight items)
 

Public Attributes

const RING_SIZE = 268435456
 

Protected Member Functions

 getLiveRing ()
 Get the "live" hash ring (which does not include ejected locations)
 

Protected Attributes

array $ejectionExpiries = []
 (location => UNIX timestamp)
 
int $ejectionNextExpiry = INF
 UNIX timestamp.
 
HashRing null $liveRing
 
array $ring = []
 (location => (start, end))
 
array $sourceMap = []
 (location => weight)
 

Detailed Description

Convenience class for weighted consistent hash rings.

Since
1.22

Definition at line 28 of file HashRing.php.

Constructor & Destructor Documentation

◆ __construct()

HashRing::__construct ( array $map)
Parameters
array$map(location => weight)

Definition at line 46 of file HashRing.php.

References $hashes, key, and RING_SIZE.

Member Function Documentation

◆ ejectFromLiveRing()

HashRing::ejectFromLiveRing ( $location,
$ttl )

Remove a location from the "live" hash ring.

Parameters
string$location
int$ttlSeconds
Returns
bool Whether some non-ejected locations are left

Definition at line 146 of file HashRing.php.

Referenced by JobQueueFederated\tryJobInsertions().

◆ getLiveLocation()

HashRing::getLiveLocation ( $item)

Get the location of an item on the "live" ring.

Parameters
string$item
Returns
string Location
Exceptions
UnexpectedValueException

Definition at line 201 of file HashRing.php.

References getLiveRing().

Referenced by JobQueueFederated\tryJobInsertions().

◆ getLiveLocations()

HashRing::getLiveLocations ( $item,
$limit )

Get the location of an item on the "live" ring, as well as the next locations.

Parameters
string$item
int$limitMaximum number of locations to return
Returns
array List of locations
Exceptions
UnexpectedValueException

Definition at line 213 of file HashRing.php.

References getLiveRing().

◆ getLiveLocationWeights()

HashRing::getLiveLocationWeights ( )

Get the map of "live" locations to weight (ignores 0-weight items)

Returns
array
Exceptions
UnexpectedValueException

Definition at line 223 of file HashRing.php.

References getLiveRing().

Referenced by JobQueueFederated\doBatchPush(), and JobQueueFederated\tryJobInsertions().

◆ getLiveRing()

HashRing::getLiveRing ( )
protected

Get the "live" hash ring (which does not include ejected locations)

Returns
HashRing
Exceptions
UnexpectedValueException

Definition at line 164 of file HashRing.php.

References $liveRing.

Referenced by getLiveLocation(), getLiveLocations(), and getLiveLocationWeights().

◆ getLocation()

HashRing::getLocation ( $item)
final

Get the location of an item on the ring.

Parameters
string$item
Returns
string Location

Definition at line 86 of file HashRing.php.

References getLocations().

◆ getLocations()

HashRing::getLocations ( $item,
$limit )

Get the location of an item on the ring, as well as the next locations.

Parameters
string$item
int$limitMaximum number of locations to return
Returns
array List of locations

Definition at line 99 of file HashRing.php.

References key.

Referenced by getLocation().

◆ getLocationWeights()

HashRing::getLocationWeights ( )

Get the map of locations to weight (ignores 0-weight items)

Returns
array

Definition at line 135 of file HashRing.php.

References $sourceMap.

Member Data Documentation

◆ $ejectionExpiries

array HashRing::$ejectionExpiries = []
protected

(location => UNIX timestamp)

Definition at line 37 of file HashRing.php.

◆ $ejectionNextExpiry

int HashRing::$ejectionNextExpiry = INF
protected

UNIX timestamp.

Definition at line 39 of file HashRing.php.

◆ $liveRing

HashRing null HashRing::$liveRing
protected

Definition at line 35 of file HashRing.php.

Referenced by getLiveRing().

◆ $ring

array HashRing::$ring = []
protected

(location => (start, end))

Definition at line 32 of file HashRing.php.

◆ $sourceMap

array HashRing::$sourceMap = []
protected

(location => weight)

Definition at line 30 of file HashRing.php.

Referenced by getLocationWeights().

◆ RING_SIZE

const HashRing::RING_SIZE = 268435456

Definition at line 41 of file HashRing.php.

Referenced by __construct().


The documentation for this class was generated from the following file: