Strengthened validation for HashRing a bit.
Change-Id: Ib0331662c785d806063ca730905dd88b6545d8f0
This commit is contained in:
parent
e87bb70a67
commit
9d1cd9ad55
1 changed files with 2 additions and 2 deletions
|
|
@ -36,8 +36,8 @@ class HashRing {
|
|||
* @param array $map (location => weight)
|
||||
*/
|
||||
public function __construct( array $map ) {
|
||||
$sum = array_sum( $map );
|
||||
if ( !count( $map ) || $sum <= 0 ) {
|
||||
$map = array_filter( $map, function( $w ) { return $w > 0; } );
|
||||
if ( !count( $map ) ) {
|
||||
throw new MWException( "Ring is empty or all weights are zero." );
|
||||
}
|
||||
// Sort the locations based on the hash of their names
|
||||
|
|
|
|||
Loading…
Reference in a new issue