* that start with "nowait:". However, only 0 timeouts (non-blocking requests)
* can be used with "nowait:" keys.
*
- * By default PoolCounter_Stub is used, which provides no locking. You
+ * By default PoolCounterNull is used, which provides no locking. You
* can get a useful one in the PoolCounter extension.
*/
abstract class PoolCounter {
/**
* @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 ) {
}
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 );
}
/**
* 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
public static function factory( $type, $key ) {
global $wgPoolCounterConf;
if ( !isset( $wgPoolCounterConf[$type] ) ) {
- return new PoolCounter_Stub;
+ return new PoolCounterNull;
}
$conf = $wgPoolCounterConf[$type];
$class = $conf['class'];
}
/**
- * 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;
- }
-}
-
-// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps
-class PoolCounter_Stub extends PoolCounter {
- // @codingStandardsIgnoreEnd
-
- public function __construct() {
- /* No parameters needed */
- }
-
- public function acquireForMe() {
- return Status::newGood( PoolCounter::LOCKED );
- }
-
- public function acquireForAnyone() {
- return Status::newGood( PoolCounter::LOCKED );
- }
-
- public function release() {
- return Status::newGood( PoolCounter::RELEASED );
+ protected function hashKeyIntoSlots( $type, $key, $slots ) {
+ return $type . ':' . ( hexdec( substr( sha1( $key ), 0, 4 ) ) % $slots );
}
}