* Follow-up r84610: don't assume a Parser object is attached
[lhc/web/wiklou.git] / includes / PoolCounter.php
index caf7e12..25bdd2d 100644 (file)
@@ -134,6 +134,13 @@ abstract class PoolCounterWork {
        function error( $status ) {     
                return false;
        }
+
+       /**
+        * Log an error
+        */
+       function logError( $status ) {
+               wfDebugLog( 'poolcounter', $status->getWikiText() );
+       }
        
        /**
         * Get the result of the work (whatever it is), or false.
@@ -144,45 +151,47 @@ abstract class PoolCounterWork {
                } else {
                        $status = $this->poolCounter->acquireForMe();
                }
-               
-               $result = false;
-               
-               if ( $status->isOK() ) {
-                       switch ( $status->value ) {
-                               case PoolCounter::LOCKED:
-                                       $result = $this->doWork();
-                                       $this->poolCounter->release();
-                                       return $result;
+
+               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();
                                
-                               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 ( $result !== false ) {
                                        return $result;
-                                       
-                               case PoolCounter::QUEUE_FULL:
-                               case PoolCounter::TIMEOUT:
-                                       $result = $this->fallback();
-                                       
-                                       if ( $result !== false ) {
-                                               return $result;
-                                       }
-                                       /* no break */
+                               }
+                               /* no break */
+                       
+                       /* These two cases should never be hit... */
+                       case PoolCounter::ERROR:
+                       default:
+                               $errors = array( PoolCounter::QUEUE_FULL => 'pool-queuefull', PoolCounter::TIMEOUT => 'pool-timeout' );
                                
-                               /* 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 */
-                       }
+                               $status = Status::newFatal( isset($errors[$status->value]) ? $errors[$status->value] : 'pool-errorunknown' );
+                               $this->logError( $status );
+                               return $this->error( $status );
                }
-               return $this->error( $status );
        }
        
        function __construct( $type, $key ) {