MediaWiki REL1_28
HashRing Class Reference

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

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)
 
 getLiveRing ()
 Get the "live" hash ring (which does not include ejected locations)
 
 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)
 
 newWithoutLocation ( $location)
 Get a new hash ring with a location removed from the ring.
 

Public Attributes

const RING_SIZE = 268435456
 

Protected Attributes

Array $ejectionExpiries = []
 (location => UNIX timestamp)
 
integer $ejectionNextExpiry = INF
 UNIX timestamp.
 
Array $liveRing
 (location => (start, end))
 
Array $ring = []
 (location => (start, end))
 
Array $sourceMap = []
 (location => weight)
 

Detailed Description

Convenience class for weighted consistent hash rings.

Since
1.22

Definition at line 29 of file HashRing.php.

Constructor & Destructor Documentation

◆ __construct()

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

Definition at line 47 of file HashRing.php.

References $hashes, as, key, RING_SIZE, and use.

Member Function Documentation

◆ ejectFromLiveRing()

HashRing::ejectFromLiveRing (   $location,
  $ttl 
)

Remove a location from the "live" hash ring.

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

Definition at line 159 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 214 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
integer$limitMaximum number of locations to return
Returns
array List of locations
Exceptions
UnexpectedValueException

Definition at line 226 of file HashRing.php.

References $limit, and getLiveRing().

◆ getLiveLocationWeights()

HashRing::getLiveLocationWeights ( )

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

Returns
array
Exceptions
UnexpectedValueException

Definition at line 236 of file HashRing.php.

References getLiveRing().

Referenced by JobQueueFederated\tryJobInsertions().

◆ getLiveRing()

HashRing::getLiveRing ( )

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

Returns
HashRing
Exceptions
UnexpectedValueException

Definition at line 177 of file HashRing.php.

References $liveRing, and use.

Referenced by JobQueueFederated\doBatchPush(), getLiveLocation(), getLiveLocations(), and getLiveLocationWeights().

◆ getLocation()

HashRing::getLocation (   $item)

Get the location of an item on the ring.

Parameters
string$item
Returns
string Location

Definition at line 87 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
integer$limitMaximum number of locations to return
Returns
array List of locations

Definition at line 100 of file HashRing.php.

References $limit, as, and list.

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.

◆ newWithoutLocation()

HashRing::newWithoutLocation (   $location)

Get a new hash ring with a location removed from the ring.

Parameters
string$location
Returns
HashRing|bool Returns false if no non-zero weighted spots are left

Definition at line 145 of file HashRing.php.

References $sourceMap.

Member Data Documentation

◆ $ejectionExpiries

Array HashRing::$ejectionExpiries = []
protected

(location => UNIX timestamp)

Definition at line 38 of file HashRing.php.

◆ $ejectionNextExpiry

integer HashRing::$ejectionNextExpiry = INF
protected

UNIX timestamp.

Definition at line 40 of file HashRing.php.

◆ $liveRing

Array HashRing::$liveRing
protected

(location => (start, end))

Definition at line 36 of file HashRing.php.

Referenced by getLiveRing().

◆ $ring

Array HashRing::$ring = []
protected

(location => (start, end))

Definition at line 33 of file HashRing.php.

◆ $sourceMap

Array HashRing::$sourceMap = []
protected

(location => weight)

Definition at line 31 of file HashRing.php.

Referenced by getLocationWeights(), and newWithoutLocation().

◆ RING_SIZE

const HashRing::RING_SIZE = 268435456

Definition at line 42 of file HashRing.php.

Referenced by __construct().


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