Merge "mw.ui: button: Update focus state"
[lhc/web/wiklou.git] / includes / jobqueue / JobQueueFederated.php
index 01d7ec4..a0a4b7b 100644 (file)
@@ -54,15 +54,9 @@ class JobQueueFederated extends JobQueue {
        /** @var array (partition name => JobQueue) reverse sorted by weight */
        protected $partitionQueues = array();
 
-       /** @var BagOStuff */
-       protected $cache;
-
        /** @var int Maximum number of partitions to try */
        protected $maxPartitionsTry;
 
-       const CACHE_TTL_SHORT = 30; // integer; seconds to cache info without re-validating
-       const CACHE_TTL_LONG = 300; // integer; seconds to cache info that is kept up to date
-
        /**
         * @param array $params Possible keys:
         *  - sectionsByWiki      : A map of wiki IDs to section names.
@@ -72,7 +66,7 @@ class JobQueueFederated extends JobQueue {
         *                          have explicitly defined sections.
         *  - configByPartition   : Map of queue partition names to configuration arrays.
         *                          These configuration arrays are passed to JobQueue::factory().
-        *                          The options set here are overriden by those passed to this
+        *                          The options set here are overridden by those passed to this
         *                          the federated queue itself (e.g. 'order' and 'claimTTL').
         *  - partitionsNoPush    : List of partition names that can handle pop() but not push().
         *                          This can be used to migrate away from a certain partition.
@@ -126,8 +120,6 @@ class JobQueueFederated extends JobQueue {
                } else {
                        $this->partitionPushRing = new HashRing( $partitionPushMap );
                }
-               // Aggregate cache some per-queue values if there are multiple partition queues
-               $this->cache = count( $partitionMap ) > 1 ? wfGetMainCache() : new EmptyBagOStuff();
        }
 
        protected function supportedOrders() {
@@ -144,15 +136,6 @@ class JobQueueFederated extends JobQueue {
        }
 
        protected function doIsEmpty() {
-               $key = $this->getCacheKey( 'empty' );
-
-               $isEmpty = $this->cache->get( $key );
-               if ( $isEmpty === 'true' ) {
-                       return true;
-               } elseif ( $isEmpty === 'false' ) {
-                       return false;
-               }
-
                $empty = true;
                $failed = 0;
                foreach ( $this->partitionQueues as $queue ) {
@@ -160,12 +143,11 @@ class JobQueueFederated extends JobQueue {
                                $empty = $empty && $queue->doIsEmpty();
                        } catch ( JobQueueError $e ) {
                                ++$failed;
-                               MWExceptionHandler::logException( $e );
+                               $this->logException( $e );
                        }
                }
                $this->throwErrorIfAllPartitionsDown( $failed );
 
-               $this->cache->add( $key, $empty ? 'true' : 'false', self::CACHE_TTL_LONG );
                return $empty;
        }
 
@@ -191,26 +173,18 @@ class JobQueueFederated extends JobQueue {
         * @return int
         */
        protected function getCrossPartitionSum( $type, $method ) {
-               $key = $this->getCacheKey( $type );
-
-               $count = $this->cache->get( $key );
-               if ( $count !== false ) {
-                       return $count;
-               }
-
+               $count = 0;
                $failed = 0;
                foreach ( $this->partitionQueues as $queue ) {
                        try {
                                $count += $queue->$method();
                        } catch ( JobQueueError $e ) {
                                ++$failed;
-                               MWExceptionHandler::logException( $e );
+                               $this->logException( $e );
                        }
                }
                $this->throwErrorIfAllPartitionsDown( $failed );
 
-               $this->cache->set( $key, $count, self::CACHE_TTL_SHORT );
-
                return $count;
        }
 
@@ -277,12 +251,9 @@ class JobQueueFederated extends JobQueue {
                                $queue->doBatchPush( $jobBatch, $flags | self::QOS_ATOMIC );
                        } catch ( JobQueueError $e ) {
                                $ok = false;
-                               MWExceptionHandler::logException( $e );
+                               $this->logException( $e );
                        }
-                       if ( $ok ) {
-                               $key = $this->getCacheKey( 'empty' );
-                               $this->cache->set( $key, 'false', JobQueueDB::CACHE_TTL_LONG );
-                       } else {
+                       if ( !$ok ) {
                                if ( !$partitionRing->ejectFromLiveRing( $partition, 5 ) ) { // blacklist
                                        throw new JobQueueError( "Could not insert job(s), no partitions available." );
                                }
@@ -299,12 +270,9 @@ class JobQueueFederated extends JobQueue {
                                $queue->doBatchPush( $jobBatch, $flags | self::QOS_ATOMIC );
                        } catch ( JobQueueError $e ) {
                                $ok = false;
-                               MWExceptionHandler::logException( $e );
+                               $this->logException( $e );
                        }
-                       if ( $ok ) {
-                               $key = $this->getCacheKey( 'empty' );
-                               $this->cache->set( $key, 'false', JobQueueDB::CACHE_TTL_LONG );
-                       } else {
+                       if ( !$ok ) {
                                if ( !$partitionRing->ejectFromLiveRing( $partition, 5 ) ) { // blacklist
                                        throw new JobQueueError( "Could not insert job(s), no partitions available." );
                                }
@@ -316,13 +284,6 @@ class JobQueueFederated extends JobQueue {
        }
 
        protected function doPop() {
-               $key = $this->getCacheKey( 'empty' );
-
-               $isEmpty = $this->cache->get( $key );
-               if ( $isEmpty === 'true' ) {
-                       return false;
-               }
-
                $partitionsTry = $this->partitionRing->getLiveLocationWeights(); // (partition => weight)
 
                $failed = 0;
@@ -338,7 +299,7 @@ class JobQueueFederated extends JobQueue {
                                $job = $queue->pop();
                        } catch ( JobQueueError $e ) {
                                ++$failed;
-                               MWExceptionHandler::logException( $e );
+                               $this->logException( $e );
                                $job = false;
                        }
                        if ( $job ) {
@@ -351,8 +312,6 @@ class JobQueueFederated extends JobQueue {
                }
                $this->throwErrorIfAllPartitionsDown( $failed );
 
-               $this->cache->set( $key, 'true', JobQueueDB::CACHE_TTL_LONG );
-
                return false;
        }
 
@@ -404,7 +363,7 @@ class JobQueueFederated extends JobQueue {
                                $queue->doDelete();
                        } catch ( JobQueueError $e ) {
                                ++$failed;
-                               MWExceptionHandler::logException( $e );
+                               $this->logException( $e );
                        }
                }
                $this->throwErrorIfAllPartitionsDown( $failed );
@@ -419,7 +378,7 @@ class JobQueueFederated extends JobQueue {
                                $queue->waitForBackups();
                        } catch ( JobQueueError $e ) {
                                ++$failed;
-                               MWExceptionHandler::logException( $e );
+                               $this->logException( $e );
                        }
                }
                $this->throwErrorIfAllPartitionsDown( $failed );
@@ -446,10 +405,6 @@ class JobQueueFederated extends JobQueue {
                        'abandonedcount'
                );
 
-               foreach ( $types as $type ) {
-                       $this->cache->delete( $this->getCacheKey( $type ) );
-               }
-
                /** @var JobQueue $queue */
                foreach ( $this->partitionQueues as $queue ) {
                        $queue->doFlushCaches();
@@ -501,7 +456,7 @@ class JobQueueFederated extends JobQueue {
                                }
                        } catch ( JobQueueError $e ) {
                                ++$failed;
-                               MWExceptionHandler::logException( $e );
+                               $this->logException( $e );
                        }
                }
                $this->throwErrorIfAllPartitionsDown( $failed );
@@ -525,7 +480,7 @@ class JobQueueFederated extends JobQueue {
                                }
                        } catch ( JobQueueError $e ) {
                                ++$failed;
-                               MWExceptionHandler::logException( $e );
+                               $this->logException( $e );
                        }
                }
                $this->throwErrorIfAllPartitionsDown( $failed );
@@ -533,6 +488,10 @@ class JobQueueFederated extends JobQueue {
                return $result;
        }
 
+       protected function logException( Exception $e ) {
+               wfDebugLog( 'JobQueueFederated', $e->getMessage() . "\n" . $e->getTraceAsString() );
+       }
+
        /**
         * Throw an error if no partitions available
         *
@@ -552,14 +511,4 @@ class JobQueueFederated extends JobQueue {
                        $queue->setTestingPrefix( $key );
                }
        }
-
-       /**
-        * @param string $property
-        * @return string
-        */
-       private function getCacheKey( $property ) {
-               list( $db, $prefix ) = wfSplitWikiID( $this->wiki );
-
-               return wfForeignMemcKey( $db, $prefix, 'jobqueue', $this->type, $property );
-       }
 }