X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FPoolCounter.php;h=452dbc547f73a2e8a166ee6af1e424e0e4e3ffc6;hb=a5028bfe5f638e53ab002114435e8e480ef4bbc9;hp=c24993e8350aa776b3fc6b555bd9b7b0c25237b0;hpb=3342af373caa4545c237b3870ca383d2fdf0e0c9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/PoolCounter.php b/includes/PoolCounter.php index c24993e835..452dbc547f 100644 --- a/includes/PoolCounter.php +++ b/includes/PoolCounter.php @@ -1,67 +1,98 @@ key = $key; $this->workers = $conf['workers']; @@ -83,18 +114,28 @@ abstract class PoolCounter { } class PoolCounter_Stub extends PoolCounter { + + /** + * @return Status + */ function acquireForMe() { return Status::newGood( PoolCounter::LOCKED ); } + /** + * @return Status + */ function acquireForAnyone() { return Status::newGood( PoolCounter::LOCKED ); } + /** + * @return Status + */ function release() { return Status::newGood( PoolCounter::RELEASED ); } - + public function __construct() { /* No parameters needed */ } @@ -105,7 +146,7 @@ class PoolCounter_Stub extends PoolCounter { */ abstract class PoolCounterWork { protected $cacheable = false; //Does this override getCachedWork() ? - + /** * Actually perform the work, caching it if needed. */ @@ -120,30 +161,35 @@ abstract class PoolCounterWork { } /** - * A work not so good (eg. expired one) but better than an error + * A work not so good (eg. expired one) but better than an error * message. * @return mixed work result or false */ function fallback() { return false; } - + /** * Do something with the error, like showing it to the user. + * @return bool */ - function error( $status ) { + function error( $status ) { return false; } /** * Log an error + * + * @param $status Status */ function logError( $status ) { wfDebugLog( 'poolcounter', $status->getWikiText() ); } - + /** * Get the result of the work (whatever it is), or false. + * @param $skipcache bool + * @return bool|mixed */ function execute( $skipcache = false ) { if ( $this->cacheable && !$skipcache ) { @@ -151,46 +197,49 @@ abstract class PoolCounterWork { } else { $status = $this->poolCounter->acquireForMe(); } - - if ( $status->isOK() ) { - switch ( $status->value ) { - case PoolCounter::LOCKED: - $result = $this->doWork(); - $this->poolCounter->release(); - return $result; - - case PoolCounter::DONE: - $result = $this->getCachedWork(); - if ( $result === false ) { - /* That someone else work didn't serve us. - * Acquire the lock for me - */ - return $this->execute( true ); - } + + if ( !$status->isOK() ) { + // Respond gracefully to complete server breakage: just log it and do the work + $this->logError( $status ); + return $this->doWork(); + } + + switch ( $status->value ) { + case PoolCounter::LOCKED: + $result = $this->doWork(); + $this->poolCounter->release(); + return $result; + + case PoolCounter::DONE: + $result = $this->getCachedWork(); + if ( $result === false ) { + /* That someone else work didn't serve us. + * Acquire the lock for me + */ + return $this->execute( true ); + } + return $result; + + case PoolCounter::QUEUE_FULL: + case PoolCounter::TIMEOUT: + $result = $this->fallback(); + + if ( $result !== false ) { return $result; - - case PoolCounter::QUEUE_FULL: - case PoolCounter::TIMEOUT: - $result = $this->fallback(); - - if ( $result !== false ) { - return $result; - } - /* no break */ - - /* These two cases should never be hit... */ - case PoolCounter::ERROR: - default: - $errors = array( PoolCounter::QUEUE_FULL => 'pool-queuefull', PoolCounter::TIMEOUT => 'pool-timeout' ); - - $status = Status::newFatal( isset($errors[$status->value]) ? $errors[$status->value] : 'pool-errorunknown' ); - /* continue to the error */ - } + } + /* no break */ + + /* These two cases should never be hit... */ + case PoolCounter::ERROR: + default: + $errors = array( PoolCounter::QUEUE_FULL => 'pool-queuefull', PoolCounter::TIMEOUT => 'pool-timeout' ); + + $status = Status::newFatal( isset( $errors[$status->value] ) ? $errors[$status->value] : 'pool-errorunknown' ); + $this->logError( $status ); + return $this->error( $status ); } - $this->logError( $status ); - return $this->error( $status ); } - + function __construct( $type, $key ) { $this->poolCounter = PoolCounter::factory( $type, $key ); }