MediaWiki
1.28.0
|
Version of PoolCounter that uses Redis. More...
Public Member Functions | |
__construct ($conf, $type, $key) | |
acquireForAnyone () | |
acquireForMe () | |
release () | |
Public Member Functions inherited from PoolCounter | |
acquireForAnyone () | |
I want to do this task, but if anyone else does it instead, it's also fine for me. More... | |
acquireForMe () | |
I want to do this task and I need to do it myself. More... | |
getKey () | |
release () | |
I have successfully finished my task. More... | |
Static Public Member Functions | |
static | releaseAll () |
Try to make sure that locks get released (even with exceptions and fatals) More... | |
Static Public Member Functions inherited from PoolCounter | |
static | factory ($type, $key) |
Create a Pool counter. More... | |
Public Attributes | |
const | AWAKE_ALL = 2 |
const | AWAKE_ONE = 1 |
Public Attributes inherited from PoolCounter | |
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 |
Protected Member Functions | |
getConnection () | |
getSlotListKey () | |
getSlotRTimeSetKey () | |
getWaitSetKey () | |
getWakeupListKey () | |
initAndPopPoolSlotList (RedisConnRef $conn, $now) | |
registerAcquisitionTime (RedisConnRef $conn, $slot, $now) | |
waitForSlotOrNotif ($doWakeup) | |
Protected Member Functions inherited from PoolCounter | |
__construct ($conf, $type, $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 from the [0..($slots-1)] range). More... | |
onAcquire () | |
Update any lock tracking information when the lock is acquired. More... | |
onRelease () | |
Update any lock tracking information when the lock is released. More... | |
precheckAcquire () | |
Checks that the lock request is sane. More... | |
Protected Attributes | |
RedisConnRef | $conn |
string | $keySha1 |
SHA-1 of the key. More... | |
int | $lockTTL |
TTL for locks to expire (work should finish in this time) More... | |
LoggerInterface | $logger |
int | $onRelease |
AWAKE_* constant. More... | |
RedisConnectionPool | $pool |
HashRing | $ring |
array | $serversByLabel |
(server label => host) map More... | |
string | $session |
Unique string to identify this process. More... | |
string | $slot |
Pool slot value. More... | |
int | $slotTime |
UNIX timestamp. More... | |
Protected Attributes inherited from PoolCounter | |
string | $key |
All workers with the same key share the lock. More... | |
int | $maxqueue |
If this number of workers are already working/waiting, fail instead of wait. More... | |
int | $slots = 0 |
Maximum number of workers working on this task type, regardless of key. More... | |
float | $timeout |
Maximum time in seconds to wait for the lock. More... | |
int | $workers |
Maximum number of workers working on tasks with the same key simultaneously. More... | |
Static Protected Attributes | |
static PoolCounterRedis[] | $active = null |
List of active PoolCounterRedis objects in this script. More... | |
Version of PoolCounter that uses Redis.
There are four main redis keys used to track each pool counter key:
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 54 of file PoolCounterRedis.php.
PoolCounterRedis::__construct | ( | $conf, | |
$type, | |||
$key | |||
) |
Definition at line 85 of file PoolCounterRedis.php.
References PoolCounter\$key, $type, MediaWiki\Logger\LoggerFactory\getInstance(), key, and RedisConnectionPool\singleton().
PoolCounterRedis::acquireForAnyone | ( | ) |
Definition at line 136 of file PoolCounterRedis.php.
References $status, PoolCounter\precheckAcquire(), and waitForSlotOrNotif().
PoolCounterRedis::acquireForMe | ( | ) |
Definition at line 127 of file PoolCounterRedis.php.
References $status, PoolCounter\precheckAcquire(), and waitForSlotOrNotif().
|
protected |
Definition at line 108 of file PoolCounterRedis.php.
References $conn, as, ArrayUtils\consistentHashSort(), key, StatusValue\newFatal(), and StatusValue\newGood().
Referenced by release(), and waitForSlotOrNotif().
|
protected |
Definition at line 397 of file PoolCounterRedis.php.
Referenced by initAndPopPoolSlotList(), registerAcquisitionTime(), release(), and waitForSlotOrNotif().
|
protected |
Definition at line 404 of file PoolCounterRedis.php.
Referenced by initAndPopPoolSlotList(), registerAcquisitionTime(), and release().
|
protected |
Definition at line 411 of file PoolCounterRedis.php.
Referenced by initAndPopPoolSlotList(), registerAcquisitionTime(), release(), and waitForSlotOrNotif().
|
protected |
Definition at line 418 of file PoolCounterRedis.php.
Referenced by release(), and waitForSlotOrNotif().
|
protected |
RedisConnRef | $conn | |
float | $now | UNIX timestamp |
Definition at line 293 of file PoolCounterRedis.php.
References add, and(), are, as, free, getSlotListKey(), getSlotRTimeSetKey(), getWaitSetKey(), in, is(), key, list, RedisConnRef\luaEval(), network, not, of, on, or, set, that, the, then, up, and use.
Referenced by waitForSlotOrNotif().
|
protected |
RedisConnRef | $conn | |
string | $slot | |
float | $now |
Definition at line 362 of file PoolCounterRedis.php.
References are, as, getSlotListKey(), getSlotRTimeSetKey(), getWaitSetKey(), is(), RedisConnRef\luaEval(), of, on, that, the, then, up, and use.
Referenced by waitForSlotOrNotif().
PoolCounterRedis::release | ( | ) |
Definition at line 145 of file PoolCounterRedis.php.
References $e, $status, and(), are, as, by, e, free, from, getConnection(), getSlotListKey(), getSlotRTimeSetKey(), getWaitSetKey(), getWakeupListKey(), is(), list, RedisConnRef\luaEval(), made, needed(), StatusValue\newFatal(), StatusValue\newGood(), not, PoolCounter\NOT_LOCKED, of, on, PoolCounter\onRelease(), other(), PoolCounter\RELEASED, save, set, that, the, then, up, use, will, and work().
|
static |
Try to make sure that locks get released (even with exceptions and fatals)
Definition at line 425 of file PoolCounterRedis.php.
|
protected |
int | $doWakeup | AWAKE_* constant |
Definition at line 231 of file PoolCounterRedis.php.
References $e, $keys, $res, $session, $slot, $slotTime, $status, PoolCounter\DONE, getConnection(), getSlotListKey(), getWaitSetKey(), getWakeupListKey(), initAndPopPoolSlotList(), PoolCounter\LOCK_HELD, PoolCounter\LOCKED, StatusValue\newFatal(), StatusValue\newGood(), PoolCounter\onAcquire(), PoolCounter\onRelease(), PoolCounter\QUEUE_FULL, registerAcquisitionTime(), and PoolCounter\TIMEOUT.
Referenced by acquireForAnyone(), and acquireForMe().
|
staticprotected |
List of active PoolCounterRedis objects in this script.
Definition at line 83 of file PoolCounterRedis.php.
|
protected |
Definition at line 69 of file PoolCounterRedis.php.
Referenced by getConnection().
|
protected |
SHA-1 of the key.
Definition at line 64 of file PoolCounterRedis.php.
|
protected |
TTL for locks to expire (work should finish in this time)
Definition at line 66 of file PoolCounterRedis.php.
|
protected |
Definition at line 60 of file PoolCounterRedis.php.
|
protected |
AWAKE_* constant.
Definition at line 73 of file PoolCounterRedis.php.
|
protected |
Definition at line 58 of file PoolCounterRedis.php.
|
protected |
Definition at line 56 of file PoolCounterRedis.php.
|
protected |
(server label => host) map
Definition at line 62 of file PoolCounterRedis.php.
|
protected |
Unique string to identify this process.
Definition at line 75 of file PoolCounterRedis.php.
Referenced by waitForSlotOrNotif().
|
protected |
Pool slot value.
Definition at line 71 of file PoolCounterRedis.php.
Referenced by waitForSlotOrNotif().
|
protected |
UNIX timestamp.
Definition at line 77 of file PoolCounterRedis.php.
Referenced by waitForSlotOrNotif().
const PoolCounterRedis::AWAKE_ALL = 2 |
Definition at line 80 of file PoolCounterRedis.php.
const PoolCounterRedis::AWAKE_ONE = 1 |
Definition at line 79 of file PoolCounterRedis.php.