MediaWiki  REL1_24
HashRing Class Reference

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

Collaboration diagram for HashRing:

List of all members.

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)
 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 = array()
 (location => UNIX timestamp) *
integer $ejectionNextExpiry = INF
 UNIX timestamp *.
Array $liveRing
 (location => (start, end)) *
Array $ring = array()
 (location => (start, end)) *
Array $sourceMap = array()
 (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

Parameters:
array$map(location => weight)

Definition at line 42 of file HashRing.php.

References $hashes, array(), as, key, and RING_SIZE.


Member Function Documentation

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 154 of file HashRing.php.

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

Parameters:
string$item
Returns:
string Location
Exceptions:
UnexpectedValueException

Definition at line 209 of file HashRing.php.

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 221 of file HashRing.php.

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

Returns:
array
Exceptions:
UnexpectedValueException

Definition at line 231 of file HashRing.php.

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

Returns:
HashRing
Exceptions:
UnexpectedValueException

Definition at line 172 of file HashRing.php.

HashRing::getLocation ( item)

Get the location of an item on the ring.

Parameters:
string$item
Returns:
string Location

Definition at line 82 of file HashRing.php.

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 95 of file HashRing.php.

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

Returns:
array

Definition at line 130 of file HashRing.php.

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 140 of file HashRing.php.


Member Data Documentation

Array HashRing::$ejectionExpiries = array() [protected]

(location => UNIX timestamp) *

Definition at line 34 of file HashRing.php.

integer HashRing::$ejectionNextExpiry = INF [protected]

UNIX timestamp *.

Definition at line 35 of file HashRing.php.

Array HashRing::$liveRing [protected]

(location => (start, end)) *

Definition at line 33 of file HashRing.php.

Array HashRing::$ring = array() [protected]

(location => (start, end)) *

Definition at line 31 of file HashRing.php.

Array HashRing::$sourceMap = array() [protected]

(location => weight) *

Definition at line 30 of file HashRing.php.

const HashRing::RING_SIZE = 268435456

Definition at line 37 of file HashRing.php.

Referenced by __construct().


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