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