[JobQueue] Added unit tests for job queue code.
[lhc/web/wiklou.git] / includes / job / JobQueueDB.php
1 <?php
2 /**
3 * Database-backed job queue code.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @author Aaron Schulz
22 */
23
24 /**
25 * Class to handle job queues stored in the DB
26 *
27 * @ingroup JobQueue
28 * @since 1.21
29 */
30 class JobQueueDB extends JobQueue {
31 const ROOTJOB_TTL = 1209600; // integer; seconds to remember root jobs (14 days)
32 const CACHE_TTL_SHORT = 30; // integer; seconds to cache info without re-validating
33 const CACHE_TTL_LONG = 300; // integer; seconds to cache info that is kept up to date
34 const MAX_AGE_PRUNE = 604800; // integer; seconds a job can live once claimed
35 const MAX_JOB_RANDOM = 2147483647; // integer; 2^31 - 1, used for job_random
36 const MAX_OFFSET = 255; // integer; maximum number of rows to skip
37
38 protected $cluster = false; // string; name of an external DB cluster
39
40 /**
41 * Additional parameters include:
42 * - cluster : The name of an external cluster registered via LBFactory.
43 * If not specified, the primary DB cluster for the wiki will be used.
44 * This can be overridden with a custom cluster so that DB handles will
45 * be retrieved via LBFactory::getExternalLB() and getConnection().
46 * @param $params array
47 */
48 protected function __construct( array $params ) {
49 parent::__construct( $params );
50 $this->cluster = isset( $params['cluster'] ) ? $params['cluster'] : false;
51 }
52
53 /**
54 * @see JobQueue::doIsEmpty()
55 * @return bool
56 */
57 protected function doIsEmpty() {
58 global $wgMemc;
59
60 $key = $this->getCacheKey( 'empty' );
61
62 $isEmpty = $wgMemc->get( $key );
63 if ( $isEmpty === 'true' ) {
64 return true;
65 } elseif ( $isEmpty === 'false' ) {
66 return false;
67 }
68
69 list( $dbr, $scope ) = $this->getSlaveDB();
70 $found = $dbr->selectField( // unclaimed job
71 'job', '1', array( 'job_cmd' => $this->type, 'job_token' => '' ), __METHOD__
72 );
73 $wgMemc->add( $key, $found ? 'false' : 'true', self::CACHE_TTL_LONG );
74
75 return !$found;
76 }
77
78 /**
79 * @see JobQueue::doGetSize()
80 * @return integer
81 */
82 protected function doGetSize() {
83 global $wgMemc;
84
85 $key = $this->getCacheKey( 'size' );
86
87 $size = $wgMemc->get( $key );
88 if ( is_int( $size ) ) {
89 return $size;
90 }
91
92 list( $dbr, $scope ) = $this->getSlaveDB();
93 $size = (int)$dbr->selectField( 'job', 'COUNT(*)',
94 array( 'job_cmd' => $this->type, 'job_token' => '' ),
95 __METHOD__
96 );
97 $wgMemc->set( $key, $size, self::CACHE_TTL_SHORT );
98
99 return $size;
100 }
101
102 /**
103 * @see JobQueue::doGetAcquiredCount()
104 * @return integer
105 */
106 protected function doGetAcquiredCount() {
107 global $wgMemc;
108
109 if ( $this->claimTTL <= 0 ) {
110 return 0; // no acknowledgements
111 }
112
113 $key = $this->getCacheKey( 'acquiredcount' );
114
115 $count = $wgMemc->get( $key );
116 if ( is_int( $count ) ) {
117 return $count;
118 }
119
120 list( $dbr, $scope ) = $this->getSlaveDB();
121 $count = (int)$dbr->selectField( 'job', 'COUNT(*)',
122 array( 'job_cmd' => $this->type, "job_token != {$dbr->addQuotes( '' )}" ),
123 __METHOD__
124 );
125 $wgMemc->set( $key, $count, self::CACHE_TTL_SHORT );
126
127 return $count;
128 }
129
130 /**
131 * @see JobQueue::doBatchPush()
132 * @param array $jobs
133 * @param $flags
134 * @throws DBError|Exception
135 * @return bool
136 */
137 protected function doBatchPush( array $jobs, $flags ) {
138 if ( count( $jobs ) ) {
139 list( $dbw, $scope ) = $this->getMasterDB();
140
141 $rowSet = array(); // (sha1 => job) map for jobs that are de-duplicated
142 $rowList = array(); // list of jobs for jobs that are are not de-duplicated
143
144 foreach ( $jobs as $job ) {
145 $row = $this->insertFields( $job );
146 if ( $job->ignoreDuplicates() ) {
147 $rowSet[$row['job_sha1']] = $row;
148 } else {
149 $rowList[] = $row;
150 }
151 }
152
153 $atomic = ( $flags & self::QoS_Atomic );
154 $key = $this->getCacheKey( 'empty' );
155 $ttl = self::CACHE_TTL_LONG;
156
157 $dbw->onTransactionIdle(
158 function() use ( $dbw, $rowSet, $rowList, $atomic, $key, $ttl, $scope
159 ) {
160 global $wgMemc;
161
162 if ( $atomic ) {
163 $dbw->begin( __METHOD__ ); // wrap all the job additions in one transaction
164 }
165 try {
166 // Strip out any duplicate jobs that are already in the queue...
167 if ( count( $rowSet ) ) {
168 $res = $dbw->select( 'job', 'job_sha1',
169 array(
170 // No job_type condition since it's part of the job_sha1 hash
171 'job_sha1' => array_keys( $rowSet ),
172 'job_token' => '' // unclaimed
173 ),
174 __METHOD__
175 );
176 foreach ( $res as $row ) {
177 wfDebug( "Job with hash '{$row->job_sha1}' is a duplicate." );
178 unset( $rowSet[$row->job_sha1] ); // already enqueued
179 }
180 }
181 // Build the full list of job rows to insert
182 $rows = array_merge( $rowList, array_values( $rowSet ) );
183 // Insert the job rows in chunks to avoid slave lag...
184 foreach ( array_chunk( $rows, 50 ) as $rowBatch ) {
185 $dbw->insert( 'job', $rowBatch, __METHOD__ );
186 }
187 wfIncrStats( 'job-insert', count( $rows ) );
188 wfIncrStats( 'job-insert-duplicate',
189 count( $rowSet ) + count( $rowList ) - count( $rows ) );
190 } catch ( DBError $e ) {
191 if ( $atomic ) {
192 $dbw->rollback( __METHOD__ );
193 }
194 throw $e;
195 }
196 if ( $atomic ) {
197 $dbw->commit( __METHOD__ );
198 }
199
200 $wgMemc->set( $key, 'false', $ttl ); // queue is not empty
201 } );
202 }
203
204 return true;
205 }
206
207 /**
208 * @see JobQueue::doPop()
209 * @return Job|bool
210 */
211 protected function doPop() {
212 global $wgMemc;
213
214 if ( $wgMemc->get( $this->getCacheKey( 'empty' ) ) === 'true' ) {
215 return false; // queue is empty
216 }
217
218 list( $dbw, $scope ) = $this->getMasterDB();
219 $dbw->commit( __METHOD__, 'flush' ); // flush existing transaction
220
221 $uuid = wfRandomString( 32 ); // pop attempt
222 $job = false; // job popped off
223 do { // retry when our row is invalid or deleted as a duplicate
224 // Try to reserve a row in the DB...
225 if ( in_array( $this->order, array( 'fifo', 'timestamp' ) ) ) {
226 $row = $this->claimOldest( $uuid );
227 } else { // random first
228 $rand = mt_rand( 0, self::MAX_JOB_RANDOM ); // encourage concurrent UPDATEs
229 $gte = (bool)mt_rand( 0, 1 ); // find rows with rand before/after $rand
230 $row = $this->claimRandom( $uuid, $rand, $gte );
231 }
232 // Check if we found a row to reserve...
233 if ( !$row ) {
234 $wgMemc->set( $this->getCacheKey( 'empty' ), 'true', self::CACHE_TTL_LONG );
235 break; // nothing to do
236 }
237 wfIncrStats( 'job-pop' );
238 // Get the job object from the row...
239 $title = Title::makeTitleSafe( $row->job_namespace, $row->job_title );
240 if ( !$title ) {
241 $dbw->delete( 'job', array( 'job_id' => $row->job_id ), __METHOD__ );
242 wfDebugLog( 'JobQueueDB', "Row has invalid title '{$row->job_title}'." );
243 continue; // try again
244 }
245 $job = Job::factory( $row->job_cmd, $title,
246 self::extractBlob( $row->job_params ), $row->job_id );
247 $job->id = $row->job_id; // XXX: work around broken subclasses
248 // Flag this job as an old duplicate based on its "root" job...
249 if ( $this->isRootJobOldDuplicate( $job ) ) {
250 wfIncrStats( 'job-pop-duplicate' );
251 $job = DuplicateJob::newFromJob( $job ); // convert to a no-op
252 }
253 break; // done
254 } while( true );
255
256 return $job;
257 }
258
259 /**
260 * Reserve a row with a single UPDATE without holding row locks over RTTs...
261 *
262 * @param $uuid string 32 char hex string
263 * @param $rand integer Random unsigned integer (31 bits)
264 * @param $gte bool Search for job_random >= $random (otherwise job_random <= $random)
265 * @return Row|false
266 */
267 protected function claimRandom( $uuid, $rand, $gte ) {
268 global $wgMemc;
269
270 list( $dbw, $scope ) = $this->getMasterDB();
271 // Check cache to see if the queue has <= OFFSET items
272 $tinyQueue = $wgMemc->get( $this->getCacheKey( 'small' ) );
273
274 $row = false; // the row acquired
275 $invertedDirection = false; // whether one job_random direction was already scanned
276 // This uses a replication safe method for acquiring jobs. One could use UPDATE+LIMIT
277 // instead, but that either uses ORDER BY (in which case it deadlocks in MySQL) or is
278 // not replication safe. Due to http://bugs.mysql.com/bug.php?id=6980, subqueries cannot
279 // be used here with MySQL.
280 do {
281 if ( $tinyQueue ) { // queue has <= MAX_OFFSET rows
282 // For small queues, using OFFSET will overshoot and return no rows more often.
283 // Instead, this uses job_random to pick a row (possibly checking both directions).
284 $ineq = $gte ? '>=' : '<=';
285 $dir = $gte ? 'ASC' : 'DESC';
286 $row = $dbw->selectRow( 'job', '*', // find a random job
287 array(
288 'job_cmd' => $this->type,
289 'job_token' => '', // unclaimed
290 "job_random {$ineq} {$dbw->addQuotes( $rand )}" ),
291 __METHOD__,
292 array( 'ORDER BY' => "job_random {$dir}" )
293 );
294 if ( !$row && !$invertedDirection ) {
295 $gte = !$gte;
296 $invertedDirection = true;
297 continue; // try the other direction
298 }
299 } else { // table *may* have >= MAX_OFFSET rows
300 // Bug 42614: "ORDER BY job_random" with a job_random inequality causes high CPU
301 // in MySQL if there are many rows for some reason. This uses a small OFFSET
302 // instead of job_random for reducing excess claim retries.
303 $row = $dbw->selectRow( 'job', '*', // find a random job
304 array(
305 'job_cmd' => $this->type,
306 'job_token' => '', // unclaimed
307 ),
308 __METHOD__,
309 array( 'OFFSET' => mt_rand( 0, self::MAX_OFFSET ) )
310 );
311 if ( !$row ) {
312 $tinyQueue = true; // we know the queue must have <= MAX_OFFSET rows
313 $wgMemc->set( $this->getCacheKey( 'small' ), 1, 30 );
314 continue; // use job_random
315 }
316 }
317 if ( $row ) { // claim the job
318 $dbw->update( 'job', // update by PK
319 array(
320 'job_token' => $uuid,
321 'job_token_timestamp' => $dbw->timestamp(),
322 'job_attempts = job_attempts+1' ),
323 array( 'job_cmd' => $this->type, 'job_id' => $row->job_id, 'job_token' => '' ),
324 __METHOD__
325 );
326 // This might get raced out by another runner when claiming the previously
327 // selected row. The use of job_random should minimize this problem, however.
328 if ( !$dbw->affectedRows() ) {
329 $row = false; // raced out
330 }
331 } else {
332 break; // nothing to do
333 }
334 } while ( !$row );
335
336 return $row;
337 }
338
339 /**
340 * Reserve a row with a single UPDATE without holding row locks over RTTs...
341 *
342 * @param $uuid string 32 char hex string
343 * @return Row|false
344 */
345 protected function claimOldest( $uuid ) {
346 list( $dbw, $scope ) = $this->getMasterDB();
347
348 $row = false; // the row acquired
349 do {
350 if ( $dbw->getType() === 'mysql' ) {
351 // Per http://bugs.mysql.com/bug.php?id=6980, we can't use subqueries on the
352 // same table being changed in an UPDATE query in MySQL (gives Error: 1093).
353 // Oracle and Postgre have no such limitation. However, MySQL offers an
354 // alternative here by supporting ORDER BY + LIMIT for UPDATE queries.
355 $dbw->query( "UPDATE {$dbw->tableName( 'job' )} " .
356 "SET " .
357 "job_token = {$dbw->addQuotes( $uuid ) }, " .
358 "job_token_timestamp = {$dbw->addQuotes( $dbw->timestamp() )}, " .
359 "job_attempts = job_attempts+1 " .
360 "WHERE ( " .
361 "job_cmd = {$dbw->addQuotes( $this->type )} " .
362 "AND job_token = {$dbw->addQuotes( '' )} " .
363 ") ORDER BY job_id ASC LIMIT 1",
364 __METHOD__
365 );
366 } else {
367 // Use a subquery to find the job, within an UPDATE to claim it.
368 // This uses as much of the DB wrapper functions as possible.
369 $dbw->update( 'job',
370 array(
371 'job_token' => $uuid,
372 'job_token_timestamp' => $dbw->timestamp(),
373 'job_attempts = job_attempts+1' ),
374 array( 'job_id = (' .
375 $dbw->selectSQLText( 'job', 'job_id',
376 array( 'job_cmd' => $this->type, 'job_token' => '' ),
377 __METHOD__,
378 array( 'ORDER BY' => 'job_id ASC', 'LIMIT' => 1 ) ) .
379 ')'
380 ),
381 __METHOD__
382 );
383 }
384 // Fetch any row that we just reserved...
385 if ( $dbw->affectedRows() ) {
386 $row = $dbw->selectRow( 'job', '*',
387 array( 'job_cmd' => $this->type, 'job_token' => $uuid ), __METHOD__
388 );
389 if ( !$row ) { // raced out by duplicate job removal
390 wfDebugLog( 'JobQueueDB', "Row deleted as duplicate by another process." );
391 }
392 } else {
393 break; // nothing to do
394 }
395 } while ( !$row );
396
397 return $row;
398 }
399
400 /**
401 * Recycle or destroy any jobs that have been claimed for too long
402 *
403 * @return integer Number of jobs recycled/deleted
404 */
405 public function recycleAndDeleteStaleJobs() {
406 global $wgMemc;
407
408 $now = time();
409 list( $dbw, $scope ) = $this->getMasterDB();
410 $count = 0; // affected rows
411
412 if ( !$dbw->lock( "jobqueue-recycle-{$this->type}", __METHOD__, 1 ) ) {
413 return $count; // already in progress
414 }
415
416 // Remove claims on jobs acquired for too long if enabled...
417 if ( $this->claimTTL > 0 ) {
418 $claimCutoff = $dbw->timestamp( $now - $this->claimTTL );
419 // Get the IDs of jobs that have be claimed but not finished after too long.
420 // These jobs can be recycled into the queue by expiring the claim. Selecting
421 // the IDs first means that the UPDATE can be done by primary key (less deadlocks).
422 $res = $dbw->select( 'job', 'job_id',
423 array(
424 'job_cmd' => $this->type,
425 "job_token != {$dbw->addQuotes( '' )}", // was acquired
426 "job_token_timestamp < {$dbw->addQuotes( $claimCutoff )}", // stale
427 "job_attempts < {$dbw->addQuotes( self::MAX_ATTEMPTS )}" ), // retries left
428 __METHOD__
429 );
430 $ids = array_map( function( $o ) { return $o->job_id; }, iterator_to_array( $res ) );
431 if ( count( $ids ) ) {
432 // Reset job_token for these jobs so that other runners will pick them up.
433 // Set the timestamp to the current time, as it is useful to now that the job
434 // was already tried before (the timestamp becomes the "released" time).
435 $dbw->update( 'job',
436 array(
437 'job_token' => '',
438 'job_token_timestamp' => $dbw->timestamp( $now ) ), // time of release
439 array(
440 'job_id' => $ids ),
441 __METHOD__
442 );
443 $count += $dbw->affectedRows();
444 wfIncrStats( 'job-recycle', $dbw->affectedRows() );
445 $wgMemc->set( $this->getCacheKey( 'empty' ), 'false', self::CACHE_TTL_LONG );
446 }
447 }
448
449 // Just destroy any stale jobs...
450 $pruneCutoff = $dbw->timestamp( $now - self::MAX_AGE_PRUNE );
451 $conds = array(
452 'job_cmd' => $this->type,
453 "job_token != {$dbw->addQuotes( '' )}", // was acquired
454 "job_token_timestamp < {$dbw->addQuotes( $pruneCutoff )}" // stale
455 );
456 if ( $this->claimTTL > 0 ) { // only prune jobs attempted too many times...
457 $conds[] = "job_attempts >= {$dbw->addQuotes( self::MAX_ATTEMPTS )}";
458 }
459 // Get the IDs of jobs that are considered stale and should be removed. Selecting
460 // the IDs first means that the UPDATE can be done by primary key (less deadlocks).
461 $res = $dbw->select( 'job', 'job_id', $conds, __METHOD__ );
462 $ids = array_map( function( $o ) { return $o->job_id; }, iterator_to_array( $res ) );
463 if ( count( $ids ) ) {
464 $dbw->delete( 'job', array( 'job_id' => $ids ), __METHOD__ );
465 $count += $dbw->affectedRows();
466 }
467
468 $dbw->unlock( "jobqueue-recycle-{$this->type}", __METHOD__ );
469
470 return $count;
471 }
472
473 /**
474 * @see JobQueue::doAck()
475 * @param Job $job
476 * @throws MWException
477 * @return Job|bool
478 */
479 protected function doAck( Job $job ) {
480 if ( !$job->getId() ) {
481 throw new MWException( "Job of type '{$job->getType()}' has no ID." );
482 }
483
484 list( $dbw, $scope ) = $this->getMasterDB();
485 $dbw->commit( __METHOD__, 'flush' ); // flush existing transaction
486
487 // Delete a row with a single DELETE without holding row locks over RTTs...
488 $dbw->delete( 'job',
489 array( 'job_cmd' => $this->type, 'job_id' => $job->getId() ), __METHOD__ );
490
491 return true;
492 }
493
494 /**
495 * @see JobQueue::doDeduplicateRootJob()
496 * @param Job $job
497 * @throws MWException
498 * @return bool
499 */
500 protected function doDeduplicateRootJob( Job $job ) {
501 $params = $job->getParams();
502 if ( !isset( $params['rootJobSignature'] ) ) {
503 throw new MWException( "Cannot register root job; missing 'rootJobSignature'." );
504 } elseif ( !isset( $params['rootJobTimestamp'] ) ) {
505 throw new MWException( "Cannot register root job; missing 'rootJobTimestamp'." );
506 }
507 $key = $this->getRootJobCacheKey( $params['rootJobSignature'] );
508 // Callers should call batchInsert() and then this function so that if the insert
509 // fails, the de-duplication registration will be aborted. Since the insert is
510 // deferred till "transaction idle", do the same here, so that the ordering is
511 // maintained. Having only the de-duplication registration succeed would cause
512 // jobs to become no-ops without any actual jobs that made them redundant.
513 list( $dbw, $scope ) = $this->getMasterDB();
514 $dbw->onTransactionIdle( function() use ( $params, $key, $scope ) {
515 global $wgMemc;
516
517 $timestamp = $wgMemc->get( $key ); // current last timestamp of this job
518 if ( $timestamp && $timestamp >= $params['rootJobTimestamp'] ) {
519 return true; // a newer version of this root job was enqueued
520 }
521
522 // Update the timestamp of the last root job started at the location...
523 return $wgMemc->set( $key, $params['rootJobTimestamp'], JobQueueDB::ROOTJOB_TTL );
524 } );
525
526 return true;
527 }
528
529 /**
530 * Check if the "root" job of a given job has been superseded by a newer one
531 *
532 * @param $job Job
533 * @return bool
534 */
535 protected function isRootJobOldDuplicate( Job $job ) {
536 global $wgMemc;
537
538 $params = $job->getParams();
539 if ( !isset( $params['rootJobSignature'] ) ) {
540 return false; // job has no de-deplication info
541 } elseif ( !isset( $params['rootJobTimestamp'] ) ) {
542 trigger_error( "Cannot check root job; missing 'rootJobTimestamp'." );
543 return false;
544 }
545
546 // Get the last time this root job was enqueued
547 $timestamp = $wgMemc->get( $this->getRootJobCacheKey( $params['rootJobSignature'] ) );
548
549 // Check if a new root job was started at the location after this one's...
550 return ( $timestamp && $timestamp > $params['rootJobTimestamp'] );
551 }
552
553 /**
554 * @see JobQueue::doWaitForBackups()
555 * @return void
556 */
557 protected function doWaitForBackups() {
558 wfWaitForSlaves();
559 }
560
561 /**
562 * @return Array
563 */
564 protected function doGetPeriodicTasks() {
565 return array(
566 'recycleAndDeleteStaleJobs' => array(
567 'callback' => array( $this, 'recycleAndDeleteStaleJobs' ),
568 'period' => ceil( $this->claimTTL / 2 )
569 )
570 );
571 }
572
573 /**
574 * @return void
575 */
576 protected function doFlushCaches() {
577 global $wgMemc;
578
579 foreach ( array( 'empty', 'size', 'acquiredcount' ) as $type ) {
580 $wgMemc->delete( $this->getCacheKey( $type ) );
581 }
582 }
583
584 /**
585 * @return Array (DatabaseBase, ScopedCallback)
586 */
587 protected function getSlaveDB() {
588 return $this->getDB( DB_SLAVE );
589 }
590
591 /**
592 * @return Array (DatabaseBase, ScopedCallback)
593 */
594 protected function getMasterDB() {
595 return $this->getDB( DB_MASTER );
596 }
597
598 /**
599 * @param $index integer (DB_SLAVE/DB_MASTER)
600 * @return Array (DatabaseBase, ScopedCallback)
601 */
602 protected function getDB( $index ) {
603 $lb = ( $this->cluster !== false )
604 ? wfGetLBFactory()->getExternalLB( $this->cluster, $this->wiki )
605 : wfGetLB( $this->wiki );
606 $conn = $lb->getConnection( $index, array(), $this->wiki );
607 return array(
608 $conn,
609 new ScopedCallback( function() use ( $lb, $conn ) {
610 $lb->reuseConnection( $conn );
611 } )
612 );
613 }
614
615 /**
616 * @param $job Job
617 * @return array
618 */
619 protected function insertFields( Job $job ) {
620 list( $dbw, $scope ) = $this->getMasterDB();
621 return array(
622 // Fields that describe the nature of the job
623 'job_cmd' => $job->getType(),
624 'job_namespace' => $job->getTitle()->getNamespace(),
625 'job_title' => $job->getTitle()->getDBkey(),
626 'job_params' => self::makeBlob( $job->getParams() ),
627 // Additional job metadata
628 'job_id' => $dbw->nextSequenceValue( 'job_job_id_seq' ),
629 'job_timestamp' => $dbw->timestamp(),
630 'job_sha1' => wfBaseConvert(
631 sha1( serialize( $job->getDeduplicationInfo() ) ),
632 16, 36, 31
633 ),
634 'job_random' => mt_rand( 0, self::MAX_JOB_RANDOM )
635 );
636 }
637
638 /**
639 * @return string
640 */
641 private function getCacheKey( $property ) {
642 list( $db, $prefix ) = wfSplitWikiID( $this->wiki );
643 return wfForeignMemcKey( $db, $prefix, 'jobqueue', $this->type, $property );
644 }
645
646 /**
647 * @param string $signature Hash identifier of the root job
648 * @return string
649 */
650 private function getRootJobCacheKey( $signature ) {
651 list( $db, $prefix ) = wfSplitWikiID( $this->wiki );
652 return wfForeignMemcKey( $db, $prefix, 'jobqueue', $this->type, 'rootjob', $signature );
653 }
654
655 /**
656 * @param $params
657 * @return string
658 */
659 protected static function makeBlob( $params ) {
660 if ( $params !== false ) {
661 return serialize( $params );
662 } else {
663 return '';
664 }
665 }
666
667 /**
668 * @param $blob
669 * @return bool|mixed
670 */
671 protected static function extractBlob( $blob ) {
672 if ( (string)$blob !== '' ) {
673 return unserialize( $blob );
674 } else {
675 return false;
676 }
677 }
678 }