Documentation

KetamaRing extends HashRing
in package

This class implements an hashring-based distributor that uses the same algorithm of libketama to distribute keys in a cluster using client-side sharding.

Tags
author

Daniele Alessandri suppakilla@gmail.com

author

Lorenzo Castelli lcastelli@gmail.com

Table of Contents

DEFAULT_REPLICAS  = 160
DEFAULT_WEIGHT  = 100
$nodeHashCallback  : mixed
$nodes  : mixed
$replicas  : mixed
$ring  : mixed
$ringKeys  : mixed
$ringKeysCount  : mixed
__construct()  : mixed
add()  : mixed
Adds a node to the ring with an optional weight.
get()  : mixed
Returns a node from the distributor mapping to the specified value.
getByHash()  : mixed
Returns a node from the distributor using the computed hash of a key.
getBySlot()  : mixed|null
Returns a node from the distributor using its assigned slot ID.
getHashGenerator()  : HashGeneratorInterface
Returns the underlying hash generator instance.
getSlot()  : mixed
Returns the corresponding slot of a node from the distributor using the computed hash of a key.
hash()  : int
Generates an hash from a string to be used for distribution.
remove()  : mixed
Removes a node from the distributor.
addNodeToRing()  : mixed
Implements the logic needed to add a node to the hashring.
getNodeHash()  : mixed
{@inheritdoc}
wrapAroundStrategy()  : int
Implements a strategy to deal with wrap-around errors during binary searches.
computeTotalWeight()  : int
Calculates the total weight of all the nodes in the distributor.
initialize()  : mixed
Initializes the distributor.
isInitialized()  : bool
Returns the initialization status of the distributor.
reset()  : mixed
Resets the distributor.

Constants

DEFAULT_REPLICAS

public mixed DEFAULT_REPLICAS = 160

DEFAULT_WEIGHT

public mixed DEFAULT_WEIGHT = 100

Properties

$nodeHashCallback

private mixed $nodeHashCallback

$ringKeysCount

private mixed $ringKeysCount

Methods

__construct()

public __construct([mixed $nodeHashCallback = null ]) : mixed
Parameters
$nodeHashCallback : mixed = null

Callback returning a string used to calculate the hash of nodes.

Return values
mixed

add()

Adds a node to the ring with an optional weight.

public add(mixed $node[, int $weight = null ]) : mixed
Parameters
$node : mixed

Node object.

$weight : int = null

Weight for the node.

Return values
mixed

get()

Returns a node from the distributor mapping to the specified value.

public get(mixed $value) : mixed
Parameters
$value : mixed
Return values
mixed

getByHash()

Returns a node from the distributor using the computed hash of a key.

public getByHash(mixed $hash) : mixed
Parameters
$hash : mixed
Return values
mixed

getBySlot()

Returns a node from the distributor using its assigned slot ID.

public getBySlot(mixed $slot) : mixed|null
Parameters
$slot : mixed
Return values
mixed|null

getSlot()

Returns the corresponding slot of a node from the distributor using the computed hash of a key.

public getSlot(mixed $hash) : mixed
Parameters
$hash : mixed
Return values
mixed

hash()

Generates an hash from a string to be used for distribution.

public hash(mixed $value) : int
Parameters
$value : mixed

String value.

Return values
int

remove()

Removes a node from the distributor.

public remove(mixed $node) : mixed
Parameters
$node : mixed

Node object.

Return values
mixed

addNodeToRing()

Implements the logic needed to add a node to the hashring.

protected addNodeToRing(mixed &$ring, mixed $node, mixed $totalNodes, mixed $replicas, mixed $weightRatio) : mixed
Parameters
$ring : mixed

Source hashring.

$node : mixed

Node object to be added.

$totalNodes : mixed

Total number of nodes.

$replicas : mixed

Number of replicas in the ring.

$weightRatio : mixed

Weight ratio for the node.

Return values
mixed

getNodeHash()

{@inheritdoc}

protected getNodeHash(mixed $nodeObject) : mixed
Parameters
$nodeObject : mixed
Return values
mixed

wrapAroundStrategy()

Implements a strategy to deal with wrap-around errors during binary searches.

protected wrapAroundStrategy(mixed $upper, mixed $lower, mixed $ringKeysCount) : int
Parameters
$upper : mixed
$lower : mixed
$ringKeysCount : mixed
Return values
int

computeTotalWeight()

Calculates the total weight of all the nodes in the distributor.

private computeTotalWeight() : int
Return values
int

initialize()

Initializes the distributor.

private initialize() : mixed
Return values
mixed

isInitialized()

Returns the initialization status of the distributor.

private isInitialized() : bool
Return values
bool

reset()

Resets the distributor.

private reset() : mixed
Return values
mixed

Search results