X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fpoolcounter%2FPoolCounter.php;h=bd7072ab7e58bb3c8d0c248885f1645be0442fe0;hp=1ec14aa1480d63a37662ff594b46a10eed87e011;hb=f43fa6f4f0e2cb60b8543daad661b48a3e0653a9;hpb=dfbbf90b249a3d80ff91a2b52d002812e42991a1 diff --git a/includes/poolcounter/PoolCounter.php b/includes/poolcounter/PoolCounter.php index 1ec14aa148..bd7072ab7e 100644 --- a/includes/poolcounter/PoolCounter.php +++ b/includes/poolcounter/PoolCounter.php @@ -71,17 +71,17 @@ abstract class PoolCounter { protected $timeout; /** - * @var boolean Whether the key is a "might wait" key + * @var bool Whether the key is a "might wait" key */ private $isMightWaitKey; /** - * @var boolean Whether this process holds a "might wait" lock key + * @var bool Whether this process holds a "might wait" lock key */ private static $acquiredMightWaitKey = 0; /** * @param array $conf - * @param string $type + * @param string $type The class of actions to limit concurrency for (task type) * @param string $key */ protected function __construct( $conf, $type, $key ) { @@ -93,8 +93,9 @@ abstract class PoolCounter { } if ( $this->slots ) { - $key = $this->hashKeyIntoSlots( $key, $this->slots ); + $key = $this->hashKeyIntoSlots( $type, $key, $this->slots ); } + $this->key = $key; $this->isMightWaitKey = !preg_match( '/^nowait:/', $this->key ); } @@ -102,7 +103,7 @@ abstract class PoolCounter { /** * Create a Pool counter. This should only be called from the PoolWorks. * - * @param string $type + * @param string $type The class of actions to limit concurrency for (task type) * @param string $key * * @return PoolCounter @@ -192,18 +193,19 @@ abstract class PoolCounter { } /** - * Given a key (any string) and the number of lots, returns a slot number (an integer from - * the [0..($slots-1)] range). This is used for a global limit on the number of instances of - * a given type that can acquire a lock. The hashing is deterministic so that + * Given a key (any string) and the number of lots, returns a slot key (a prefix with a suffix + * integer from the [0..($slots-1)] range). This is used for a global limit on the number of + * instances of a given type that can acquire a lock. The hashing is deterministic so that * PoolCounter::$workers is always an upper limit of how many instances with the same key * can acquire a lock. * + * @param string $type The class of actions to limit concurrency for (task type) * @param string $key PoolCounter instance key (any string) * @param int $slots The number of slots (max allowed value is 65536) - * @return int + * @return string Slot key with the type and slot number */ - protected function hashKeyIntoSlots( $key, $slots ) { - return hexdec( substr( sha1( $key ), 0, 4 ) ) % $slots; + protected function hashKeyIntoSlots( $type, $key, $slots ) { + return $type . ':' . ( hexdec( substr( sha1( $key ), 0, 4 ) ) % $slots ); } }