MediaWiki master
|
Version of PoolCounter that uses Redis. More...
Inherits MediaWiki\PoolCounter\PoolCounter.
Public Member Functions | |
__construct ( $conf, $type, $key) | |
acquireForAnyone ( $timeout=null) | |
I want to do this task, but if anyone else does it instead, it's also fine for me. | |
acquireForMe ( $timeout=null) | |
I want to do this task and I need to do it myself. | |
release () | |
I have successfully finished my task. | |
![]() | |
__construct (array $conf, string $type, string $key) | |
getKey () | |
getLogger () | |
isFastStaleEnabled () | |
Is fast stale mode (T250248) enabled? This may be overridden by the PoolCounterWork subclass. | |
setLogger (LoggerInterface $logger) | |
setTracer (TracerInterface $tracer) | |
Static Public Member Functions | |
static | releaseAll () |
Try to make sure that locks get released (even with exceptions and fatals) | |
Protected Member Functions | |
getConnection () | |
getSlotListKey () | |
getSlotRTimeSetKey () | |
getWaitSetKey () | |
getWakeupListKey () | |
initAndPopPoolSlotList (RedisConnRef $conn, $now) | |
registerAcquisitionTime (RedisConnRef $conn, $slot, $now) | |
waitForSlotOrNotif ( $doWakeup, $timeout=null) | |
![]() | |
hashKeyIntoSlots ( $type, $key, $slots) | |
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). | |
onAcquire () | |
Update any lock tracking information when the lock is acquired. | |
onRelease () | |
Update any lock tracking information when the lock is released. | |
precheckAcquire () | |
Checks that the lock request is sensible. | |
Protected Attributes | |
RedisConnRef null | $conn |
string | $keySha1 |
SHA-1 of the key. | |
int | $lockTTL |
TTL for locks to expire (work should finish in this time) | |
int null | $onRelease |
AWAKE_* constant. | |
RedisConnectionPool | $pool |
HashRing | $ring |
array | $serversByLabel |
(server label => host) map | |
string | $session |
Unique string to identify this process. | |
string null | $slot |
Pool slot value. | |
float null | $slotTime |
UNIX timestamp. | |
![]() | |
SpanInterface | $heldLockSpan = null |
string | $key |
All workers with the same key share the lock. | |
LoggerInterface | $logger |
int | $maxqueue |
If this number of workers are already working/waiting, fail instead of wait. | |
int | $slots = 0 |
Maximum number of workers working on this task type, regardless of key. | |
int | $timeout |
Maximum time in seconds to wait for the lock. | |
TracerInterface | $tracer |
string | $type |
int | $workers |
Maximum number of workers working on tasks with the same key simultaneously. | |
Static Protected Attributes | |
static PoolCounterRedis[] | $active = null |
List of active PoolCounterRedis objects in this script. | |
Additional Inherited Members | |
![]() | |
const | DONE = 3 |
const | ERROR = -1 |
const | LOCK_HELD = -5 |
const | LOCKED = 1 |
const | NOT_LOCKED = -2 |
const | QUEUE_FULL = -3 |
const | RELEASED = 2 |
const | TIMEOUT = -4 |
Version of PoolCounter that uses Redis.
There are four main redis keys used to track each pool counter key:
For a given pool key, all the redis keys start off non-existing and are deleted if not used for a while to prevent garbage from building up on the server. They are atomically re-initialized as needed. The "z-renewtime" key is used for detecting sessions which got slots but then disappeared. Stale entries from there have their timestamp updated and the corresponding slots freed up. The "z-wait" key is used for detecting processes registered as waiting but that disappeared. Stale entries from there are deleted and the corresponding slots are freed up. The worker count is included in all the redis key names as it does not vary within each $wgPoolCounterConf type and doing so handles configuration changes.
This class requires Redis 2.6 as it makes use Lua scripts for fast atomic operations. Also this should be on a server plenty of RAM for the working set to avoid evictions. Evictions could temporarily allow wait queues to double in size or temporarily cause pools to appear as full when they are not. Using volatile-ttl and bumping memory-samples in redis.conf can be helpful otherwise.
Definition at line 62 of file PoolCounterRedis.php.
MediaWiki\PoolCounter\PoolCounterRedis::__construct | ( | $conf, | |
$type, | |||
$key ) |
Definition at line 90 of file PoolCounterRedis.php.
References MediaWiki\PoolCounter\PoolCounter\$key, and MediaWiki\PoolCounter\PoolCounter\$type.
MediaWiki\PoolCounter\PoolCounterRedis::acquireForAnyone | ( | $timeout = null | ) |
I want to do this task, but if anyone else does it instead, it's also fine for me.
I will read its cached data.
int | null | $timeout | Wait timeout, or null to use value passed to the constructor |
Reimplemented from MediaWiki\PoolCounter\PoolCounter.
Definition at line 142 of file PoolCounterRedis.php.
References MediaWiki\PoolCounter\PoolCounter\$timeout, MediaWiki\PoolCounter\PoolCounter\precheckAcquire(), and MediaWiki\PoolCounter\PoolCounterRedis\waitForSlotOrNotif().
MediaWiki\PoolCounter\PoolCounterRedis::acquireForMe | ( | $timeout = null | ) |
I want to do this task and I need to do it myself.
int | null | $timeout | Wait timeout, or null to use value passed to the constructor |
Reimplemented from MediaWiki\PoolCounter\PoolCounter.
Definition at line 133 of file PoolCounterRedis.php.
References MediaWiki\PoolCounter\PoolCounter\$timeout, MediaWiki\PoolCounter\PoolCounter\precheckAcquire(), and MediaWiki\PoolCounter\PoolCounterRedis\waitForSlotOrNotif().
|
protected |
Definition at line 114 of file PoolCounterRedis.php.
References MediaWiki\PoolCounter\PoolCounterRedis\$conn.
Referenced by MediaWiki\PoolCounter\PoolCounterRedis\release(), and MediaWiki\PoolCounter\PoolCounterRedis\waitForSlotOrNotif().
|
protected |
Definition at line 407 of file PoolCounterRedis.php.
Referenced by MediaWiki\PoolCounter\PoolCounterRedis\initAndPopPoolSlotList(), MediaWiki\PoolCounter\PoolCounterRedis\registerAcquisitionTime(), MediaWiki\PoolCounter\PoolCounterRedis\release(), and MediaWiki\PoolCounter\PoolCounterRedis\waitForSlotOrNotif().
|
protected |
Definition at line 414 of file PoolCounterRedis.php.
Referenced by MediaWiki\PoolCounter\PoolCounterRedis\initAndPopPoolSlotList(), MediaWiki\PoolCounter\PoolCounterRedis\registerAcquisitionTime(), and MediaWiki\PoolCounter\PoolCounterRedis\release().
|
protected |
Definition at line 421 of file PoolCounterRedis.php.
Referenced by MediaWiki\PoolCounter\PoolCounterRedis\initAndPopPoolSlotList(), MediaWiki\PoolCounter\PoolCounterRedis\registerAcquisitionTime(), MediaWiki\PoolCounter\PoolCounterRedis\release(), and MediaWiki\PoolCounter\PoolCounterRedis\waitForSlotOrNotif().
|
protected |
Definition at line 428 of file PoolCounterRedis.php.
Referenced by MediaWiki\PoolCounter\PoolCounterRedis\release(), and MediaWiki\PoolCounter\PoolCounterRedis\waitForSlotOrNotif().
|
protected |
RedisConnRef | $conn | |
float | $now | UNIX timestamp |
Definition at line 305 of file PoolCounterRedis.php.
References MediaWiki\PoolCounter\PoolCounterRedis\$conn, MediaWiki\PoolCounter\PoolCounterRedis\getSlotListKey(), MediaWiki\PoolCounter\PoolCounterRedis\getSlotRTimeSetKey(), MediaWiki\PoolCounter\PoolCounterRedis\getWaitSetKey(), and Wikimedia\ObjectCache\RedisConnRef\luaEval().
Referenced by MediaWiki\PoolCounter\PoolCounterRedis\waitForSlotOrNotif().
|
protected |
RedisConnRef | $conn | |
string | $slot | |
float | $now |
Definition at line 373 of file PoolCounterRedis.php.
References MediaWiki\PoolCounter\PoolCounterRedis\$conn, MediaWiki\PoolCounter\PoolCounterRedis\$slot, MediaWiki\PoolCounter\PoolCounterRedis\getSlotListKey(), MediaWiki\PoolCounter\PoolCounterRedis\getSlotRTimeSetKey(), MediaWiki\PoolCounter\PoolCounterRedis\getWaitSetKey(), and Wikimedia\ObjectCache\RedisConnRef\luaEval().
Referenced by MediaWiki\PoolCounter\PoolCounterRedis\waitForSlotOrNotif().
MediaWiki\PoolCounter\PoolCounterRedis::release | ( | ) |
I have successfully finished my task.
Lets another one grab the lock, and returns the workers waiting on acquireForAnyone()
Reimplemented from MediaWiki\PoolCounter\PoolCounter.
Definition at line 151 of file PoolCounterRedis.php.
References MediaWiki\PoolCounter\PoolCounterRedis\$conn, MediaWiki\PoolCounter\PoolCounterRedis\getConnection(), MediaWiki\PoolCounter\PoolCounterRedis\getSlotListKey(), MediaWiki\PoolCounter\PoolCounterRedis\getSlotRTimeSetKey(), MediaWiki\PoolCounter\PoolCounterRedis\getWaitSetKey(), MediaWiki\PoolCounter\PoolCounterRedis\getWakeupListKey(), Wikimedia\ObjectCache\RedisConnRef\luaEval(), MediaWiki\PoolCounter\PoolCounter\NOT_LOCKED, MediaWiki\PoolCounter\PoolCounter\onRelease(), and MediaWiki\PoolCounter\PoolCounter\RELEASED.
|
static |
Try to make sure that locks get released (even with exceptions and fatals)
Definition at line 435 of file PoolCounterRedis.php.
|
protected |
int | $doWakeup | AWAKE_* constant |
int | float | null | $timeout |
Definition at line 241 of file PoolCounterRedis.php.
References MediaWiki\PoolCounter\PoolCounterRedis\$conn, MediaWiki\PoolCounter\PoolCounterRedis\$session, MediaWiki\PoolCounter\PoolCounterRedis\$slot, MediaWiki\PoolCounter\PoolCounterRedis\$slotTime, MediaWiki\PoolCounter\PoolCounter\$timeout, MediaWiki\PoolCounter\PoolCounter\DONE, MediaWiki\PoolCounter\PoolCounterRedis\getConnection(), MediaWiki\PoolCounter\PoolCounterRedis\getSlotListKey(), MediaWiki\PoolCounter\PoolCounterRedis\getWaitSetKey(), MediaWiki\PoolCounter\PoolCounterRedis\getWakeupListKey(), MediaWiki\PoolCounter\PoolCounterRedis\initAndPopPoolSlotList(), MediaWiki\PoolCounter\PoolCounter\LOCK_HELD, MediaWiki\PoolCounter\PoolCounter\LOCKED, MediaWiki\PoolCounter\PoolCounter\onAcquire(), MediaWiki\PoolCounter\PoolCounter\onRelease(), MediaWiki\PoolCounter\PoolCounter\QUEUE_FULL, MediaWiki\PoolCounter\PoolCounterRedis\registerAcquisitionTime(), and MediaWiki\PoolCounter\PoolCounter\TIMEOUT.
Referenced by MediaWiki\PoolCounter\PoolCounterRedis\acquireForAnyone(), and MediaWiki\PoolCounter\PoolCounterRedis\acquireForMe().
|
staticprotected |
List of active PoolCounterRedis objects in this script.
Definition at line 88 of file PoolCounterRedis.php.
|
protected |
Definition at line 74 of file PoolCounterRedis.php.
Referenced by MediaWiki\PoolCounter\PoolCounterRedis\getConnection(), MediaWiki\PoolCounter\PoolCounterRedis\initAndPopPoolSlotList(), MediaWiki\PoolCounter\PoolCounterRedis\registerAcquisitionTime(), MediaWiki\PoolCounter\PoolCounterRedis\release(), and MediaWiki\PoolCounter\PoolCounterRedis\waitForSlotOrNotif().
|
protected |
SHA-1 of the key.
Definition at line 70 of file PoolCounterRedis.php.
|
protected |
TTL for locks to expire (work should finish in this time)
Definition at line 72 of file PoolCounterRedis.php.
|
protected |
AWAKE_* constant.
Definition at line 78 of file PoolCounterRedis.php.
|
protected |
Definition at line 66 of file PoolCounterRedis.php.
|
protected |
Definition at line 64 of file PoolCounterRedis.php.
|
protected |
(server label => host) map
Definition at line 68 of file PoolCounterRedis.php.
|
protected |
Unique string to identify this process.
Definition at line 80 of file PoolCounterRedis.php.
Referenced by MediaWiki\PoolCounter\PoolCounterRedis\waitForSlotOrNotif().
|
protected |
Pool slot value.
Definition at line 76 of file PoolCounterRedis.php.
Referenced by MediaWiki\PoolCounter\PoolCounterRedis\registerAcquisitionTime(), and MediaWiki\PoolCounter\PoolCounterRedis\waitForSlotOrNotif().
|
protected |
UNIX timestamp.
Definition at line 82 of file PoolCounterRedis.php.
Referenced by MediaWiki\PoolCounter\PoolCounterRedis\waitForSlotOrNotif().