3 * Redis-backed job queue code.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
21 * @author Aaron Schulz
23 use Psr\Log\LoggerInterface
;
26 * Class to handle job queues stored in Redis
28 * This is a faster and less resource-intensive job queue than JobQueueDB.
29 * All data for a queue using this class is placed into one redis server.
30 * The mediawiki/services/jobrunner background service must be set up and running.
32 * There are eight main redis keys (per queue) used to track jobs:
33 * - l-unclaimed : A list of job IDs used for ready unclaimed jobs
34 * - z-claimed : A sorted set of (job ID, UNIX timestamp as score) used for job retries
35 * - z-abandoned : A sorted set of (job ID, UNIX timestamp as score) used for broken jobs
36 * - z-delayed : A sorted set of (job ID, UNIX timestamp as score) used for delayed jobs
37 * - h-idBySha1 : A hash of (SHA1 => job ID) for unclaimed jobs used for de-duplication
38 * - h-sha1ById : A hash of (job ID => SHA1) for unclaimed jobs used for de-duplication
39 * - h-attempts : A hash of (job ID => attempt count) used for job claiming/retries
40 * - h-data : A hash of (job ID => serialized blobs) for job storage
41 * A job ID can be in only one of z-delayed, l-unclaimed, z-claimed, and z-abandoned.
42 * If an ID appears in any of those lists, it should have a h-data entry for its ID.
43 * If a job has a SHA1 de-duplication value and its ID is in l-unclaimed or z-delayed, then
44 * there should be no other such jobs with that SHA1. Every h-idBySha1 entry has an h-sha1ById
45 * entry and every h-sha1ById must refer to an ID that is l-unclaimed. If a job has its
46 * ID in z-claimed or z-abandoned, then it must also have an h-attempts entry for its ID.
48 * The following keys are used to track queue states:
49 * - s-queuesWithJobs : A set of all queues with non-abandoned jobs
51 * The background service takes care of undelaying, recycling, and pruning jobs as well as
52 * removing s-queuesWithJobs entries as queues empty.
54 * Additionally, "rootjob:* keys track "root jobs" used for additional de-duplication.
55 * Aside from root job keys, all keys have no expiry, and are only removed when jobs are run.
56 * All the keys are prefixed with the relevant wiki ID information.
58 * This class requires Redis 2.6 as it makes use Lua scripts for fast atomic operations.
59 * Additionally, it should be noted that redis has different persistence modes, such
60 * as rdb snapshots, journaling, and no persistence. Appropriate configuration should be
61 * made on the servers based on what queues are using it and what tolerance they have.
67 class JobQueueRedis
extends JobQueue
{
68 /** @var RedisConnectionPool */
70 /** @var LoggerInterface */
73 /** @var string Server address */
75 /** @var string Compression method to use */
76 protected $compression;
79 * @param array $params Possible keys:
80 * - redisConfig : An array of parameters to RedisConnectionPool::__construct().
81 * Note that the serializer option is ignored as "none" is always used.
82 * - redisServer : A hostname/port combination or the absolute path of a UNIX socket.
83 * If a hostname is specified but no port, the standard port number
84 * 6379 will be used. Required.
85 * - compression : The type of compression to use; one of (none,gzip).
86 * - daemonized : Set to true if the redisJobRunnerService runs in the background.
87 * This will disable job recycling/undelaying from the MediaWiki side
88 * to avoid redundance and out-of-sync configuration.
89 * @throws InvalidArgumentException
91 public function __construct( array $params ) {
92 parent
::__construct( $params );
93 $params['redisConfig']['serializer'] = 'none'; // make it easy to use Lua
94 $this->server
= $params['redisServer'];
95 $this->compression
= isset( $params['compression'] ) ?
$params['compression'] : 'none';
96 $this->redisPool
= RedisConnectionPool
::singleton( $params['redisConfig'] );
97 if ( empty( $params['daemonized'] ) ) {
98 throw new InvalidArgumentException(
99 "Non-daemonized mode is no longer supported. Please install the " .
100 "mediawiki/services/jobrunner service and update \$wgJobTypeConf as needed." );
102 $this->logger
= \MediaWiki\Logger\LoggerFactory
::getInstance( 'redis' );
105 protected function supportedOrders() {
106 return [ 'timestamp', 'fifo' ];
109 protected function optimalOrder() {
113 protected function supportsDelayedJobs() {
118 * @see JobQueue::doIsEmpty()
120 * @throws JobQueueError
122 protected function doIsEmpty() {
123 return $this->doGetSize() == 0;
127 * @see JobQueue::doGetSize()
129 * @throws JobQueueError
131 protected function doGetSize() {
132 $conn = $this->getConnection();
134 return $conn->lSize( $this->getQueueKey( 'l-unclaimed' ) );
135 } catch ( RedisException
$e ) {
136 $this->throwRedisException( $conn, $e );
141 * @see JobQueue::doGetAcquiredCount()
143 * @throws JobQueueError
145 protected function doGetAcquiredCount() {
146 $conn = $this->getConnection();
148 $conn->multi( Redis
::PIPELINE
);
149 $conn->zSize( $this->getQueueKey( 'z-claimed' ) );
150 $conn->zSize( $this->getQueueKey( 'z-abandoned' ) );
152 return array_sum( $conn->exec() );
153 } catch ( RedisException
$e ) {
154 $this->throwRedisException( $conn, $e );
159 * @see JobQueue::doGetDelayedCount()
161 * @throws JobQueueError
163 protected function doGetDelayedCount() {
164 $conn = $this->getConnection();
166 return $conn->zSize( $this->getQueueKey( 'z-delayed' ) );
167 } catch ( RedisException
$e ) {
168 $this->throwRedisException( $conn, $e );
173 * @see JobQueue::doGetAbandonedCount()
175 * @throws JobQueueError
177 protected function doGetAbandonedCount() {
178 $conn = $this->getConnection();
180 return $conn->zSize( $this->getQueueKey( 'z-abandoned' ) );
181 } catch ( RedisException
$e ) {
182 $this->throwRedisException( $conn, $e );
187 * @see JobQueue::doBatchPush()
188 * @param IJobSpecification[] $jobs
191 * @throws JobQueueError
193 protected function doBatchPush( array $jobs, $flags ) {
194 // Convert the jobs into field maps (de-duplicated against each other)
195 $items = []; // (job ID => job fields map)
196 foreach ( $jobs as $job ) {
197 $item = $this->getNewJobFields( $job );
198 if ( strlen( $item['sha1'] ) ) { // hash identifier => de-duplicate
199 $items[$item['sha1']] = $item;
201 $items[$item['uuid']] = $item;
205 if ( !count( $items ) ) {
206 return; // nothing to do
209 $conn = $this->getConnection();
211 // Actually push the non-duplicate jobs into the queue...
212 if ( $flags & self
::QOS_ATOMIC
) {
213 $batches = [ $items ]; // all or nothing
215 $batches = array_chunk( $items, 100 ); // avoid tying up the server
219 foreach ( $batches as $itemBatch ) {
220 $added = $this->pushBlobs( $conn, $itemBatch );
221 if ( is_int( $added ) ) {
224 $failed +
= count( $itemBatch );
227 JobQueue
::incrStats( 'inserts', $this->type
, count( $items ) );
228 JobQueue
::incrStats( 'inserts_actual', $this->type
, $pushed );
229 JobQueue
::incrStats( 'dupe_inserts', $this->type
,
230 count( $items ) - $failed - $pushed );
232 $err = "Could not insert {$failed} {$this->type} job(s).";
233 wfDebugLog( 'JobQueueRedis', $err );
234 throw new RedisException( $err );
236 } catch ( RedisException
$e ) {
237 $this->throwRedisException( $conn, $e );
242 * @param RedisConnRef $conn
243 * @param array $items List of results from JobQueueRedis::getNewJobFields()
244 * @return int Number of jobs inserted (duplicates are ignored)
245 * @throws RedisException
247 protected function pushBlobs( RedisConnRef
$conn, array $items ) {
248 $args = [ $this->encodeQueueName() ];
249 // Next args come in 4s ([id, sha1, rtime, blob [, id, sha1, rtime, blob ... ] ] )
250 foreach ( $items as $item ) {
251 $args[] = (string)$item['uuid'];
252 $args[] = (string)$item['sha1'];
253 $args[] = (string)$item['rtimestamp'];
254 $args[] = (string)$this->serialize( $item );
258 local kUnclaimed, kSha1ById, kIdBySha1, kDelayed, kData, kQwJobs = unpack(KEYS)
259 -- First argument is the queue ID
260 local queueId = ARGV[1]
261 -- Next arguments all come in 4s (one per job)
262 local variadicArgCount = #ARGV - 1
263 if variadicArgCount % 4 ~= 0 then
264 return redis.error_reply('Unmatched arguments')
266 -- Insert each job into this queue as needed
269 local id,sha1,rtimestamp,blob = ARGV[i],ARGV[i+1],ARGV[i+2],ARGV[i+3]
270 if sha1 == '' or redis.call('hExists',kIdBySha1,sha1) == 0 then
271 if 1*rtimestamp > 0 then
272 -- Insert into delayed queue (release time as score)
273 redis.call('zAdd',kDelayed,rtimestamp,id)
275 -- Insert into unclaimed queue
276 redis.call('lPush',kUnclaimed,id)
279 redis.call('hSet',kSha1ById,id,sha1)
280 redis.call('hSet',kIdBySha1,sha1,id)
282 redis.call('hSet',kData,id,blob)
286 -- Mark this queue as having jobs
287 redis.call('sAdd',kQwJobs,queueId)
290 return $conn->luaEval( $script,
293 $this->getQueueKey( 'l-unclaimed' ), # KEYS[1]
294 $this->getQueueKey( 'h-sha1ById' ), # KEYS[2]
295 $this->getQueueKey( 'h-idBySha1' ), # KEYS[3]
296 $this->getQueueKey( 'z-delayed' ), # KEYS[4]
297 $this->getQueueKey( 'h-data' ), # KEYS[5]
298 $this->getGlobalKey( 's-queuesWithJobs' ), # KEYS[6]
302 6 # number of first argument(s) that are keys
307 * @see JobQueue::doPop()
309 * @throws JobQueueError
311 protected function doPop() {
314 $conn = $this->getConnection();
317 $blob = $this->popAndAcquireBlob( $conn );
318 if ( !is_string( $blob ) ) {
319 break; // no jobs; nothing to do
322 JobQueue
::incrStats( 'pops', $this->type
);
323 $item = $this->unserialize( $blob );
324 if ( $item === false ) {
325 wfDebugLog( 'JobQueueRedis', "Could not unserialize {$this->type} job." );
329 // If $item is invalid, the runner loop recyling will cleanup as needed
330 $job = $this->getJobFromFields( $item ); // may be false
331 } while ( !$job ); // job may be false if invalid
332 } catch ( RedisException
$e ) {
333 $this->throwRedisException( $conn, $e );
340 * @param RedisConnRef $conn
341 * @return array Serialized string or false
342 * @throws RedisException
344 protected function popAndAcquireBlob( RedisConnRef
$conn ) {
347 local kUnclaimed, kSha1ById, kIdBySha1, kClaimed, kAttempts, kData = unpack(KEYS)
348 local rTime = unpack(ARGV)
349 -- Pop an item off the queue
350 local id = redis.call('rPop',kUnclaimed)
354 -- Allow new duplicates of this job
355 local sha1 = redis.call('hGet',kSha1ById,id)
356 if sha1 then redis.call('hDel',kIdBySha1,sha1) end
357 redis.call('hDel',kSha1ById,id)
358 -- Mark the jobs as claimed and return it
359 redis.call('zAdd',kClaimed,rTime,id)
360 redis.call('hIncrBy',kAttempts,id,1)
361 return redis.call('hGet',kData,id)
363 return $conn->luaEval( $script,
365 $this->getQueueKey( 'l-unclaimed' ), # KEYS[1]
366 $this->getQueueKey( 'h-sha1ById' ), # KEYS[2]
367 $this->getQueueKey( 'h-idBySha1' ), # KEYS[3]
368 $this->getQueueKey( 'z-claimed' ), # KEYS[4]
369 $this->getQueueKey( 'h-attempts' ), # KEYS[5]
370 $this->getQueueKey( 'h-data' ), # KEYS[6]
371 time(), # ARGV[1] (injected to be replication-safe)
373 6 # number of first argument(s) that are keys
378 * @see JobQueue::doAck()
381 * @throws UnexpectedValueException
382 * @throws JobQueueError
384 protected function doAck( Job
$job ) {
385 if ( !isset( $job->metadata
['uuid'] ) ) {
386 throw new UnexpectedValueException( "Job of type '{$job->getType()}' has no UUID." );
389 $uuid = $job->metadata
['uuid'];
390 $conn = $this->getConnection();
394 local kClaimed, kAttempts, kData = unpack(KEYS)
395 local id = unpack(ARGV)
396 -- Unmark the job as claimed
397 local removed = redis.call('zRem',kClaimed,id)
398 -- Check if the job was recycled
402 -- Delete the retry data
403 redis.call('hDel',kAttempts,id)
404 -- Delete the job data itself
405 return redis.call('hDel',kData,id)
407 $res = $conn->luaEval( $script,
409 $this->getQueueKey( 'z-claimed' ), # KEYS[1]
410 $this->getQueueKey( 'h-attempts' ), # KEYS[2]
411 $this->getQueueKey( 'h-data' ), # KEYS[3]
414 3 # number of first argument(s) that are keys
418 wfDebugLog( 'JobQueueRedis', "Could not acknowledge {$this->type} job $uuid." );
423 JobQueue
::incrStats( 'acks', $this->type
);
424 } catch ( RedisException
$e ) {
425 $this->throwRedisException( $conn, $e );
432 * @see JobQueue::doDeduplicateRootJob()
433 * @param IJobSpecification $job
435 * @throws JobQueueError
436 * @throws LogicException
438 protected function doDeduplicateRootJob( IJobSpecification
$job ) {
439 if ( !$job->hasRootJobParams() ) {
440 throw new LogicException( "Cannot register root job; missing parameters." );
442 $params = $job->getRootJobParams();
444 $key = $this->getRootJobCacheKey( $params['rootJobSignature'] );
446 $conn = $this->getConnection();
448 $timestamp = $conn->get( $key ); // current last timestamp of this job
449 if ( $timestamp && $timestamp >= $params['rootJobTimestamp'] ) {
450 return true; // a newer version of this root job was enqueued
453 // Update the timestamp of the last root job started at the location...
454 return $conn->set( $key, $params['rootJobTimestamp'], self
::ROOTJOB_TTL
); // 2 weeks
455 } catch ( RedisException
$e ) {
456 $this->throwRedisException( $conn, $e );
461 * @see JobQueue::doIsRootJobOldDuplicate()
464 * @throws JobQueueError
466 protected function doIsRootJobOldDuplicate( Job
$job ) {
467 if ( !$job->hasRootJobParams() ) {
468 return false; // job has no de-deplication info
470 $params = $job->getRootJobParams();
472 $conn = $this->getConnection();
474 // Get the last time this root job was enqueued
475 $timestamp = $conn->get( $this->getRootJobCacheKey( $params['rootJobSignature'] ) );
476 } catch ( RedisException
$e ) {
478 $this->throwRedisException( $conn, $e );
481 // Check if a new root job was started at the location after this one's...
482 return ( $timestamp && $timestamp > $params['rootJobTimestamp'] );
486 * @see JobQueue::doDelete()
488 * @throws JobQueueError
490 protected function doDelete() {
491 static $props = [ 'l-unclaimed', 'z-claimed', 'z-abandoned',
492 'z-delayed', 'h-idBySha1', 'h-sha1ById', 'h-attempts', 'h-data' ];
494 $conn = $this->getConnection();
497 foreach ( $props as $prop ) {
498 $keys[] = $this->getQueueKey( $prop );
501 $ok = ( $conn->delete( $keys ) !== false );
502 $conn->sRem( $this->getGlobalKey( 's-queuesWithJobs' ), $this->encodeQueueName() );
505 } catch ( RedisException
$e ) {
506 $this->throwRedisException( $conn, $e );
511 * @see JobQueue::getAllQueuedJobs()
513 * @throws JobQueueError
515 public function getAllQueuedJobs() {
516 $conn = $this->getConnection();
518 $uids = $conn->lRange( $this->getQueueKey( 'l-unclaimed' ), 0, -1 );
519 } catch ( RedisException
$e ) {
520 $this->throwRedisException( $conn, $e );
523 return $this->getJobIterator( $conn, $uids );
527 * @see JobQueue::getAllDelayedJobs()
529 * @throws JobQueueError
531 public function getAllDelayedJobs() {
532 $conn = $this->getConnection();
534 $uids = $conn->zRange( $this->getQueueKey( 'z-delayed' ), 0, -1 );
535 } catch ( RedisException
$e ) {
536 $this->throwRedisException( $conn, $e );
539 return $this->getJobIterator( $conn, $uids );
543 * @see JobQueue::getAllAcquiredJobs()
545 * @throws JobQueueError
547 public function getAllAcquiredJobs() {
548 $conn = $this->getConnection();
550 $uids = $conn->zRange( $this->getQueueKey( 'z-claimed' ), 0, -1 );
551 } catch ( RedisException
$e ) {
552 $this->throwRedisException( $conn, $e );
555 return $this->getJobIterator( $conn, $uids );
559 * @see JobQueue::getAllAbandonedJobs()
561 * @throws JobQueueError
563 public function getAllAbandonedJobs() {
564 $conn = $this->getConnection();
566 $uids = $conn->zRange( $this->getQueueKey( 'z-abandoned' ), 0, -1 );
567 } catch ( RedisException
$e ) {
568 $this->throwRedisException( $conn, $e );
571 return $this->getJobIterator( $conn, $uids );
575 * @param RedisConnRef $conn
576 * @param array $uids List of job UUIDs
577 * @return MappedIterator
579 protected function getJobIterator( RedisConnRef
$conn, array $uids ) {
580 return new MappedIterator(
582 function ( $uid ) use ( $conn ) {
583 return $this->getJobFromUidInternal( $uid, $conn );
585 [ 'accept' => function ( $job ) {
586 return is_object( $job );
591 public function getCoalesceLocationInternal() {
592 return "RedisServer:" . $this->server
;
595 protected function doGetSiblingQueuesWithJobs( array $types ) {
596 return array_keys( array_filter( $this->doGetSiblingQueueSizes( $types ) ) );
599 protected function doGetSiblingQueueSizes( array $types ) {
600 $sizes = []; // (type => size)
601 $types = array_values( $types ); // reindex
602 $conn = $this->getConnection();
604 $conn->multi( Redis
::PIPELINE
);
605 foreach ( $types as $type ) {
606 $conn->lSize( $this->getQueueKey( 'l-unclaimed', $type ) );
608 $res = $conn->exec();
609 if ( is_array( $res ) ) {
610 foreach ( $res as $i => $size ) {
611 $sizes[$types[$i]] = $size;
614 } catch ( RedisException
$e ) {
615 $this->throwRedisException( $conn, $e );
622 * This function should not be called outside JobQueueRedis
625 * @param RedisConnRef $conn
626 * @return Job|bool Returns false if the job does not exist
627 * @throws JobQueueError
628 * @throws UnexpectedValueException
630 public function getJobFromUidInternal( $uid, RedisConnRef
$conn ) {
632 $data = $conn->hGet( $this->getQueueKey( 'h-data' ), $uid );
633 if ( $data === false ) {
634 return false; // not found
636 $item = $this->unserialize( $data );
637 if ( !is_array( $item ) ) { // this shouldn't happen
638 throw new UnexpectedValueException( "Could not find job with ID '$uid'." );
640 $title = Title
::makeTitle( $item['namespace'], $item['title'] );
641 $job = Job
::factory( $item['type'], $title, $item['params'] );
642 $job->metadata
['uuid'] = $item['uuid'];
643 $job->metadata
['timestamp'] = $item['timestamp'];
644 // Add in attempt count for debugging at showJobs.php
645 $job->metadata
['attempts'] = $conn->hGet( $this->getQueueKey( 'h-attempts' ), $uid );
648 } catch ( RedisException
$e ) {
649 $this->throwRedisException( $conn, $e );
654 * @return array List of (wiki,type) tuples for queues with non-abandoned jobs
655 * @throws JobQueueConnectionError
656 * @throws JobQueueError
658 public function getServerQueuesWithJobs() {
661 $conn = $this->getConnection();
663 $set = $conn->sMembers( $this->getGlobalKey( 's-queuesWithJobs' ) );
664 foreach ( $set as $queue ) {
665 $queues[] = $this->decodeQueueName( $queue );
667 } catch ( RedisException
$e ) {
668 $this->throwRedisException( $conn, $e );
675 * @param IJobSpecification $job
678 protected function getNewJobFields( IJobSpecification
$job ) {
680 // Fields that describe the nature of the job
681 'type' => $job->getType(),
682 'namespace' => $job->getTitle()->getNamespace(),
683 'title' => $job->getTitle()->getDBkey(),
684 'params' => $job->getParams(),
685 // Some jobs cannot run until a "release timestamp"
686 'rtimestamp' => $job->getReleaseTimestamp() ?
: 0,
687 // Additional job metadata
688 'uuid' => UIDGenerator
::newRawUUIDv4( UIDGenerator
::QUICK_RAND
),
689 'sha1' => $job->ignoreDuplicates()
690 ? Wikimedia\base_convert
( sha1( serialize( $job->getDeduplicationInfo() ) ), 16, 36, 31 )
692 'timestamp' => time() // UNIX timestamp
697 * @param array $fields
700 protected function getJobFromFields( array $fields ) {
701 $title = Title
::makeTitle( $fields['namespace'], $fields['title'] );
702 $job = Job
::factory( $fields['type'], $title, $fields['params'] );
703 $job->metadata
['uuid'] = $fields['uuid'];
704 $job->metadata
['timestamp'] = $fields['timestamp'];
710 * @param array $fields
711 * @return string Serialized and possibly compressed version of $fields
713 protected function serialize( array $fields ) {
714 $blob = serialize( $fields );
715 if ( $this->compression
=== 'gzip'
716 && strlen( $blob ) >= 1024
717 && function_exists( 'gzdeflate' )
719 $object = (object)[ 'blob' => gzdeflate( $blob ), 'enc' => 'gzip' ];
720 $blobz = serialize( $object );
722 return ( strlen( $blobz ) < strlen( $blob ) ) ?
$blobz : $blob;
729 * @param string $blob
730 * @return array|bool Unserialized version of $blob or false
732 protected function unserialize( $blob ) {
733 $fields = unserialize( $blob );
734 if ( is_object( $fields ) ) {
735 if ( $fields->enc
=== 'gzip' && function_exists( 'gzinflate' ) ) {
736 $fields = unserialize( gzinflate( $fields->blob
) );
742 return is_array( $fields ) ?
$fields : false;
746 * Get a connection to the server that handles all sub-queues for this queue
748 * @return RedisConnRef
749 * @throws JobQueueConnectionError
751 protected function getConnection() {
752 $conn = $this->redisPool
->getConnection( $this->server
, $this->logger
);
754 throw new JobQueueConnectionError(
755 "Unable to connect to redis server {$this->server}." );
762 * @param RedisConnRef $conn
763 * @param RedisException $e
764 * @throws JobQueueError
766 protected function throwRedisException( RedisConnRef
$conn, $e ) {
767 $this->redisPool
->handleError( $conn, $e );
768 throw new JobQueueError( "Redis server error: {$e->getMessage()}\n" );
772 * @return string JSON
774 private function encodeQueueName() {
775 return json_encode( [ $this->type
, $this->wiki
] );
779 * @param string $name JSON
780 * @return array (type, wiki)
782 private function decodeQueueName( $name ) {
783 return json_decode( $name );
787 * @param string $name
790 private function getGlobalKey( $name ) {
791 $parts = [ 'global', 'jobqueue', $name ];
792 foreach ( $parts as $part ) {
793 if ( !preg_match( '/[a-zA-Z0-9_-]+/', $part ) ) {
794 throw new InvalidArgumentException( "Key part characters are out of range." );
798 return implode( ':', $parts );
802 * @param string $prop
803 * @param string|null $type Override this for sibling queues
806 private function getQueueKey( $prop, $type = null ) {
807 $type = is_string( $type ) ?
$type : $this->type
;
808 list( $db, $prefix ) = wfSplitWikiID( $this->wiki
);
809 $keyspace = $prefix ?
"$db-$prefix" : $db;
811 $parts = [ $keyspace, 'jobqueue', $type, $prop ];
813 // Parts are typically ASCII, but encode for sanity to escape ":"
814 return implode( ':', array_map( 'rawurlencode', $parts ) );