24use Wikimedia\ObjectFactory;
95 $this->workers = $conf[
'workers'];
96 $this->maxqueue = $conf[
'maxqueue'];
97 $this->timeout = $conf[
'timeout'];
98 if ( isset( $conf[
'slots'] ) ) {
99 $this->slots = $conf[
'slots'];
101 $this->fastStale = $conf[
'fastStale'] ??
false;
103 if ( $this->slots ) {
108 $this->isMightWaitKey = !preg_match(
'/^nowait:/', $this->key );
127 $poolCounter = ObjectFactory::getObjectFromSpec(
131 'assertClass' => self::class
179 if ( $this->isMightWaitKey ) {
180 if ( self::$acquiredMightWaitKey ) {
189 return Status::newFatal(
'poolcounter-usage-error',
190 'You may only aquire a single non-nowait lock.' );
192 } elseif ( $this->timeout !== 0 ) {
193 return Status::newFatal(
'poolcounter-usage-error',
194 'Locks starting in nowait: must have 0 timeout.' );
196 return Status::newGood();
228 return $type .
':' . ( hexdec( substr( sha1(
$key ), 0, 4 ) ) %
$slots );
$wgPoolCounterConf
Configuration for processing pool control, for use in high-traffic wikis.
A default PoolCounter, which provides no locking.
When you have many workers (threads/servers) giving service, and a cached item expensive to produce e...
int $workers
Maximum number of workers working on tasks with the same key simultaneously.
acquireForAnyone( $timeout=null)
I want to do this task, but if anyone else does it instead, it's also fine for me.
bool $isMightWaitKey
Whether the key is a "might wait" key.
onAcquire()
Update any lock tracking information when the lock is acquired.
__construct(array $conf, string $type, string $key)
bool $fastStale
Enable fast stale mode (T250248).
int $maxqueue
If this number of workers are already working/waiting, fail instead of wait.
isFastStaleEnabled()
Is fast stale mode (T250248) enabled? This may be overridden by the PoolCounterWork subclass.
string $key
All workers with the same key share the lock.
int $slots
Maximum number of workers working on this task type, regardless of key.
hashKeyIntoSlots( $type, $key, $slots)
Given a key (any string) and the number of lots, returns a slot key (a prefix with a suffix integer f...
release()
I have successfully finished my task.
precheckAcquire()
Checks that the lock request is sane.
static bool $acquiredMightWaitKey
Whether this process holds a "might wait" lock key.
static factory(string $type, string $key)
Create a Pool counter.
acquireForMe( $timeout=null)
I want to do this task and I need to do it myself.
int $timeout
Maximum time in seconds to wait for the lock.
onRelease()
Update any lock tracking information when the lock is released.