X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fjobqueue%2FJobQueueGroup.php;h=b9c4157574054915e70ded1c3714b13a3b9c7dd7;hb=a0f9d54f117bf1d62ab9ace307e1628a3f0115dc;hp=3d88089f39a36b2d96d9bbfdb606bc97239ad20b;hpb=00063e1eb126d6a0917331d46303d7ea180c74bc;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/jobqueue/JobQueueGroup.php b/includes/jobqueue/JobQueueGroup.php index 3d88089f39..b9c4157574 100644 --- a/includes/jobqueue/JobQueueGroup.php +++ b/includes/jobqueue/JobQueueGroup.php @@ -19,6 +19,7 @@ * * @file */ +use MediaWiki\MediaWikiServices; /** * Class to handle enqueueing of background jobs @@ -33,12 +34,12 @@ class JobQueueGroup { /** @var ProcessCacheLRU */ protected $cache; - /** @var string Wiki ID */ - protected $wiki; + /** @var string Wiki domain ID */ + protected $domain; /** @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; + protected $invalidDomain = false; /** @var array Map of (bucket => (queue => JobQueue, types => list of types) */ protected $coalescedQueues; @@ -53,34 +54,40 @@ class JobQueueGroup { const CACHE_VERSION = 1; // integer; cache version /** - * @param string $wiki Wiki ID + * @param string $domain Wiki domain ID * @param string|bool $readOnlyReason Read-only reason or false */ - protected function __construct( $wiki, $readOnlyReason ) { - $this->wiki = $wiki; + protected function __construct( $domain, $readOnlyReason ) { + $this->domain = $domain; $this->readOnlyReason = $readOnlyReason; $this->cache = new MapCacheLRU( 10 ); } /** - * @param bool|string $wiki Wiki ID + * @param bool|string $domain Wiki domain ID * @return JobQueueGroup */ - public static function singleton( $wiki = false ) { + public static function singleton( $domain = false ) { global $wgLocalDatabases; - $wiki = ( $wiki === false ) ? wfWikiID() : $wiki; + if ( $domain === false ) { + $domain = WikiMap::getCurrentWikiDbDomain()->getId(); + } - if ( !isset( self::$instances[$wiki] ) ) { - self::$instances[$wiki] = new self( $wiki, wfConfiguredReadOnlyReason() ); + if ( !isset( self::$instances[$domain] ) ) { + self::$instances[$domain] = new self( $domain, 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 ( !WikiMap::isCurrentWikiId( $wiki ) && !in_array( $wiki, $wgLocalDatabases ) ) { - self::$instances[$wiki]->invalidWiki = true; + $wikiId = WikiMap::getWikiIdFromDbDomain( $domain ); + if ( + !WikiMap::isCurrentWikiDbDomain( $domain ) && + !in_array( $wikiId, $wgLocalDatabases ) + ) { + self::$instances[$domain]->invalidDomain = true; } } - return self::$instances[$wiki]; + return self::$instances[$domain]; } /** @@ -101,9 +108,12 @@ class JobQueueGroup { public function get( $type ) { global $wgJobTypeConf; - $conf = [ 'wiki' => $this->wiki, 'type' => $type ]; - $conf += $wgJobTypeConf[$type] ?? $wgJobTypeConf['default']; - $conf['aggregator'] = JobQueueAggregator::singleton(); + $conf = [ 'domain' => $this->domain, 'type' => $type ]; + if ( isset( $wgJobTypeConf[$type] ) ) { + $conf = $conf + $wgJobTypeConf[$type]; + } else { + $conf = $conf + $wgJobTypeConf['default']; + } if ( !isset( $conf['readOnlyReason'] ) ) { $conf['readOnlyReason'] = $this->readOnlyReason; } @@ -124,15 +134,15 @@ class JobQueueGroup { public function push( $jobs ) { global $wgJobTypesExcludedFromDefaultQueue; - if ( $this->invalidWiki ) { + if ( $this->invalidDomain ) { // Do not enqueue job that cannot be run (T171371) - $e = new LogicException( "Domain '{$this->wiki}' is not recognized." ); + $e = new LogicException( "Domain '{$this->domain}' is not recognized." ); MWExceptionHandler::logException( $e ); return; } $jobs = is_array( $jobs ) ? $jobs : [ $jobs ]; - if ( !count( $jobs ) ) { + if ( $jobs === [] ) { return; } @@ -156,13 +166,13 @@ class JobQueueGroup { $cache = ObjectCache::getLocalClusterInstance(); $cache->set( - $cache->makeGlobalKey( 'jobqueue', $this->wiki, 'hasjobs', self::TYPE_ANY ), + $cache->makeGlobalKey( 'jobqueue', $this->domain, 'hasjobs', self::TYPE_ANY ), 'true', 15 ); if ( array_diff( array_keys( $jobsByType ), $wgJobTypesExcludedFromDefaultQueue ) ) { $cache->set( - $cache->makeGlobalKey( 'jobqueue', $this->wiki, 'hasjobs', self::TYPE_DEFAULT ), + $cache->makeGlobalKey( 'jobqueue', $this->domain, 'hasjobs', self::TYPE_DEFAULT ), 'true', 15 ); @@ -181,9 +191,9 @@ class JobQueueGroup { * @since 1.26 */ public function lazyPush( $jobs ) { - if ( $this->invalidWiki ) { + if ( $this->invalidDomain ) { // Do not enqueue job that cannot be run (T171371) - throw new LogicException( "Domain '{$this->wiki}' is not recognized." ); + throw new LogicException( "Domain '{$this->domain}' is not recognized." ); } if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) { @@ -196,7 +206,7 @@ class JobQueueGroup { // Throw errors now instead of on push(), when other jobs may be buffered $this->assertValidJobs( $jobs ); - DeferredUpdates::addUpdate( new JobQueueEnqueueUpdate( $this->wiki, $jobs ) ); + DeferredUpdates::addUpdate( new JobQueueEnqueueUpdate( $this->domain, $jobs ) ); } /** @@ -324,7 +334,7 @@ class JobQueueGroup { */ public function queuesHaveJobs( $type = self::TYPE_ANY ) { $cache = ObjectCache::getLocalClusterInstance(); - $key = $cache->makeGlobalKey( 'jobqueue', $this->wiki, 'hasjobs', $type ); + $key = $cache->makeGlobalKey( 'jobqueue', $this->domain, 'hasjobs', $type ); $value = $cache->get( $key ); if ( $value === false ) { @@ -342,12 +352,14 @@ class JobQueueGroup { /** * Get the list of job types that have non-empty queues * - * @return array List of job types that have non-empty queues + * @return string[] List of job types that have non-empty queues */ public function getQueuesWithJobs() { $types = []; foreach ( $this->getCoalescedQueues() as $info ) { - $nonEmpty = $info['queue']->getSiblingQueuesWithJobs( $this->getQueueTypes() ); + /** @var JobQueue $queue */ + $queue = $info['queue']; + $nonEmpty = $queue->getSiblingQueuesWithJobs( $this->getQueueTypes() ); if ( is_array( $nonEmpty ) ) { // batching features supported $types = array_merge( $types, $nonEmpty ); } else { // we have to go through the queues in the bucket one-by-one @@ -365,12 +377,14 @@ class JobQueueGroup { /** * Get the size of the queus for a list of job types * - * @return array Map of (job type => size) + * @return int[] Map of (job type => size) */ public function getQueueSizes() { $sizeMap = []; foreach ( $this->getCoalescedQueues() as $info ) { - $sizes = $info['queue']->getSiblingQueueSizes( $this->getQueueTypes() ); + /** @var JobQueue $queue */ + $queue = $info['queue']; + $sizes = $queue->getSiblingQueueSizes( $this->getQueueTypes() ); if ( is_array( $sizes ) ) { // batching features supported $sizeMap = $sizeMap + $sizes; } else { // we have to go through the queues in the bucket one-by-one @@ -384,7 +398,7 @@ class JobQueueGroup { } /** - * @return array + * @return JobQueue[] */ protected function getCoalescedQueues() { global $wgJobTypeConf; @@ -393,7 +407,7 @@ class JobQueueGroup { $this->coalescedQueues = []; foreach ( $wgJobTypeConf as $type => $conf ) { $queue = JobQueue::factory( - [ 'wiki' => $this->wiki, 'type' => 'null' ] + $conf ); + [ 'domain' => $this->domain, 'type' => 'null' ] + $conf ); $loc = $queue->getCoalesceLocationInternal(); if ( !isset( $this->coalescedQueues[$loc] ) ) { $this->coalescedQueues[$loc]['queue'] = $queue; @@ -419,17 +433,17 @@ class JobQueueGroup { */ private function getCachedConfigVar( $name ) { // @TODO: cleanup this whole method with a proper config system - if ( WikiMap::isCurrentWikiId( $this->wiki ) ) { + if ( WikiMap::isCurrentWikiDbDomain( $this->domain ) ) { return $GLOBALS[$name]; // common case } else { - $wiki = $this->wiki; - $cache = ObjectCache::getMainWANInstance(); + $wiki = WikiMap::getWikiIdFromDbDomain( $this->domain ); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $value = $cache->getWithSetCallback( - $cache->makeGlobalKey( 'jobqueue', 'configvalue', $wiki, $name ), + $cache->makeGlobalKey( 'jobqueue', 'configvalue', $this->domain, $name ), $cache::TTL_DAY + mt_rand( 0, $cache::TTL_DAY ), function () use ( $wiki, $name ) { global $wgConf; - + // @TODO: use the full domain ID here return [ 'v' => $wgConf->getConfig( $wiki, $name ) ]; }, [ 'pcTTL' => WANObjectCache::TTL_PROC_LONG ]