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