Merge "Include the backtrace in the log for job exceptions"
[lhc/web/wiklou.git] / includes / HashRing.php
index 227a287..cd39ad8 100644 (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
@@ -49,6 +49,7 @@ class HashRing {
                        return strcmp( $hashes[$a], $hashes[$b] );
                } );
                // Fit the map to weight-proportionate one with a space of size RING_SIZE
+               $sum = array_sum( $map );
                $standardMap = array();
                foreach ( $map as $location => $weight ) {
                        $standardMap[$location] = (int)floor( $weight / $sum * self::RING_SIZE );