Strengthened validation for HashRing a bit.

Change-Id: Ib0331662c785d806063ca730905dd88b6545d8f0
This commit is contained in:
Aaron Schulz 2013-05-13 11:20:11 -07:00
parent e87bb70a67
commit 9d1cd9ad55

View file

@ -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