Update wikimedia/timestamp to v2.2.0
[lhc/web/wiklou.git] / includes / jobqueue / JobQueueGroup.php
index ef0ecb3..820c492 100644 (file)
@@ -37,6 +37,8 @@ class JobQueueGroup {
        protected $wiki;
        /** @var string|bool Read only rationale (or false if r/w) */
        protected $readOnlyReason;
+       /** @var bool Whether the wiki is not recognized in configuration */
+       protected $invalidWiki = false;
 
        /** @var array Map of (bucket => (queue => JobQueue, types => list of types) */
        protected $coalescedQueues;
@@ -60,7 +62,7 @@ class JobQueueGroup {
        protected function __construct( $wiki, $readOnlyReason ) {
                $this->wiki = $wiki;
                $this->readOnlyReason = $readOnlyReason;
-               $this->cache = new ProcessCacheLRU( 10 );
+               $this->cache = new MapCacheLRU( 10 );
        }
 
        /**
@@ -68,9 +70,17 @@ class JobQueueGroup {
         * @return JobQueueGroup
         */
        public static function singleton( $wiki = false ) {
+               global $wgLocalDatabases;
+
                $wiki = ( $wiki === false ) ? wfWikiID() : $wiki;
+
                if ( !isset( self::$instances[$wiki] ) ) {
                        self::$instances[$wiki] = new self( $wiki, wfConfiguredReadOnlyReason() );
+                       // Make sure jobs are not getting pushed to bogus wikis. This can confuse
+                       // the job runner system into spawning endless RPC requests that fail (T171371).
+                       if ( $wiki !== wfWikiID() && !in_array( $wiki, $wgLocalDatabases ) ) {
+                               self::$instances[$wiki]->invalidWiki = true;
+                       }
                }
 
                return self::$instances[$wiki];
@@ -101,7 +111,7 @@ class JobQueueGroup {
                        $conf = $conf + $wgJobTypeConf['default'];
                }
                $conf['aggregator'] = JobQueueAggregator::singleton();
-               if ( $this->readOnlyReason !== false ) {
+               if ( !isset( $conf['readOnlyReason'] ) ) {
                        $conf['readOnlyReason'] = $this->readOnlyReason;
                }
 
@@ -121,6 +131,13 @@ class JobQueueGroup {
        public function push( $jobs ) {
                global $wgJobTypesExcludedFromDefaultQueue;
 
+               if ( $this->invalidWiki ) {
+                       // Do not enqueue job that cannot be run (T171371)
+                       $e = new LogicException( "Domain '{$this->wiki}' is not recognized." );
+                       MWExceptionHandler::logException( $e );
+                       return;
+               }
+
                $jobs = is_array( $jobs ) ? $jobs : [ $jobs ];
                if ( !count( $jobs ) ) {
                        return;
@@ -137,8 +154,8 @@ class JobQueueGroup {
                        $this->get( $type )->push( $jobs );
                }
 
-               if ( $this->cache->has( 'queues-ready', 'list' ) ) {
-                       $list = $this->cache->get( 'queues-ready', 'list' );
+               if ( $this->cache->hasField( 'queues-ready', 'list' ) ) {
+                       $list = $this->cache->getField( 'queues-ready', 'list' );
                        if ( count( array_diff( array_keys( $jobsByType ), $list ) ) ) {
                                $this->cache->clear( 'queues-ready' );
                        }
@@ -171,6 +188,11 @@ class JobQueueGroup {
         * @since 1.26
         */
        public function lazyPush( $jobs ) {
+               if ( $this->invalidWiki ) {
+                       // Do not enqueue job that cannot be run (T171371)
+                       throw new LogicException( "Domain '{$this->wiki}' is not recognized." );
+               }
+
                if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) {
                        $this->push( $jobs );
                        return;
@@ -222,10 +244,10 @@ class JobQueueGroup {
                        }
                } else { // any job in the "default" jobs types
                        if ( $flags & self::USE_CACHE ) {
-                               if ( !$this->cache->has( 'queues-ready', 'list', self::PROC_CACHE_TTL ) ) {
-                                       $this->cache->set( 'queues-ready', 'list', $this->getQueuesWithJobs() );
+                               if ( !$this->cache->hasField( 'queues-ready', 'list', self::PROC_CACHE_TTL ) ) {
+                                       $this->cache->setField( 'queues-ready', 'list', $this->getQueuesWithJobs() );
                                }
-                               $types = $this->cache->get( 'queues-ready', 'list' );
+                               $types = $this->cache->getField( 'queues-ready', 'list' );
                        } else {
                                $types = $this->getQueuesWithJobs();
                        }