Use DB domain in JobQueueGroup and make WikiMap domain ID methods stricter
authorAaron Schulz <aschulz@wikimedia.org>
Sat, 13 Oct 2018 07:29:23 +0000 (00:29 -0700)
committerKrinkle <krinklemail@gmail.com>
Wed, 7 Nov 2018 04:46:56 +0000 (04:46 +0000)
Using domains means thats JobQueueDB has the right value to use for calls
like LoadBalancer::getConnection(). The full domain includes the schema in
the case of Postgres. This makes calls to getConnection() less awkward by
not relying on the fallback logic in reallyOpenConnection() for null schemas.

Make getWikiIdFromDomain/isCurrentWikiDomain account for the schema if it
is both defined and is not simply the generic "mediawiki" schema MediaWiki
uses by default. If all wikis use the default schema, the wiki IDs can get
by with DB/prefix alone, which various config and methods may be built around.
Otherwise, the config callbacks must account for schema and the config must
include it in various wiki domain ID lists to properly disambiguate wikis.

Also, clean up SiteConfiguration::siteFromDB() since it is not meant
to handle schemas unless the callback method was taylored to do so.

Finally, add more comments to DefaultSettings.php about already existing
limitations of wiki domain IDs and their components.

Change-Id: I8d94a650e5c99a19ee50551c5be9544318eb05b1

14 files changed:
includes/DefaultSettings.php
includes/SiteConfiguration.php
includes/WikiMap.php
includes/installer/i18n/en.json
includes/jobqueue/JobQueue.php
includes/jobqueue/JobQueueDB.php
includes/jobqueue/JobQueueFederated.php
includes/jobqueue/JobQueueGroup.php
includes/jobqueue/JobQueueMemory.php
includes/jobqueue/JobQueueRedis.php
includes/jobqueue/aggregator/JobQueueAggregator.php
maintenance/manageJobs.php
tests/phpunit/includes/WikiMapTest.php
tests/phpunit/includes/jobqueue/JobQueueTest.php

index 01e9002..2d1681c 100644 (file)
@@ -1867,7 +1867,7 @@ $wgDBserver = 'localhost';
 $wgDBport = 5432;
 
 /**
- * Name of the database
+ * Name of the database; this should be alphanumeric and not contain spaces nor hyphens
  */
 $wgDBname = 'my_wiki';
 
@@ -1934,7 +1934,7 @@ $wgSearchType = null;
 $wgSearchTypeAlternatives = null;
 
 /**
- * Table name prefix
+ * Table name prefix; this should be alphanumeric and not contain spaces nor hyphens
  */
 $wgDBprefix = '';
 
@@ -1952,7 +1952,7 @@ $wgDBTableOptions = 'ENGINE=InnoDB, DEFAULT CHARSET=binary';
 $wgSQLMode = '';
 
 /**
- * Mediawiki schema
+ * Mediawiki schema; this should be alphanumeric and not contain spaces nor hyphens
  */
 $wgDBmwschema = null;
 
@@ -2164,7 +2164,15 @@ $wgDBOracleDRCP = false;
 /**
  * Other wikis on this site, can be administered from a single developer account.
  *
- * Array numeric key => database name
+ * @var string[] List of wiki DB domain IDs; the format of each ID consist of 1-3 hyphen
+ *   delimited alphanumeric components (each with no hyphens nor spaces) of any of the forms:
+ *   - "<DB NAME>-<DB SCHEMA>-<TABLE PREFIX>"
+ *   - "<DB NAME>-<TABLE PREFIX>"
+ *   - "<DB NAME>"
+ * If hyphens appear in any of the components, then the domain ID parsing may not work
+ * in all cases and site functionality might be affected. If the schema ($wgDBmwschema)
+ * is left to the default "mediawiki" for all wikis, then the schema should be omitted
+ * from these IDs.
  */
 $wgLocalDatabases = [];
 
index af65e45..7af80dc 100644 (file)
@@ -483,13 +483,13 @@ class SiteConfiguration {
 
        /**
         * Work out the site and language name from a database name
-        * @param string $db
+        * @param string $wiki Wiki ID
         *
         * @return array
         */
-       public function siteFromDB( $db ) {
+       public function siteFromDB( $wiki ) {
                // Allow override
-               $def = $this->getWikiParams( $db );
+               $def = $this->getWikiParams( $wiki );
                if ( !is_null( $def['suffix'] ) && !is_null( $def['lang'] ) ) {
                        return [ $def['suffix'], $def['lang'] ];
                }
@@ -499,15 +499,16 @@ class SiteConfiguration {
                foreach ( $this->suffixes as $altSite => $suffix ) {
                        if ( $suffix === '' ) {
                                $site = '';
-                               $lang = $db;
+                               $lang = $wiki;
                                break;
-                       } elseif ( substr( $db, -strlen( $suffix ) ) == $suffix ) {
+                       } elseif ( substr( $wiki, -strlen( $suffix ) ) == $suffix ) {
                                $site = is_numeric( $altSite ) ? $suffix : $altSite;
-                               $lang = substr( $db, 0, strlen( $db ) - strlen( $suffix ) );
+                               $lang = substr( $wiki, 0, strlen( $wiki ) - strlen( $suffix ) );
                                break;
                        }
                }
                $lang = str_replace( '_', '-', $lang );
+
                return [ $site, $lang ];
        }
 
index b731d7b..3305f9f 100644 (file)
@@ -246,6 +246,7 @@ class WikiMap {
         * Get the wiki ID of a database domain
         *
         * This is like DatabaseDomain::getId() without encoding (for legacy reasons)
+        * and without the schema if it merely set to the generic value "mediawiki"
         *
         * @param string|DatabaseDomain $domain
         * @return string
@@ -253,9 +254,19 @@ class WikiMap {
        public static function getWikiIdFromDomain( $domain ) {
                $domain = DatabaseDomain::newFromId( $domain );
 
+               if ( !in_array( $domain->getSchema(), [ null, 'mediawiki' ], true ) ) {
+                       // Include the schema if it is set and is not the default placeholder.
+                       // This means a site admin may have specifically taylored the schemas.
+                       // Domain IDs might use the form <DB>-<project>-<language>, meaning that
+                       // the schema portion must be accounted for to disambiguate wikis.
+                       return "{$domain->getDatabase()}-{$domain->getSchema()}-{$domain->getTablePrefix()}";
+               }
+
+               // Note that if this wiki ID is passed a a domain ID to LoadBalancer, then it can
+               // handle the schema by assuming the generic "mediawiki" schema if needed.
                return strlen( $domain->getTablePrefix() )
                        ? "{$domain->getDatabase()}-{$domain->getTablePrefix()}"
-                       : $domain->getDatabase();
+                       : (string)$domain->getDatabase();
        }
 
        /**
@@ -277,9 +288,16 @@ class WikiMap {
                $domain = DatabaseDomain::newFromId( $domain );
                $curDomain = self::getCurrentWikiDomain();
 
+               if ( !in_array( $curDomain->getSchema(), [ null, 'mediawiki' ], true ) ) {
+                       // Include the schema if it is set and is not the default placeholder.
+                       // This means a site admin may have specifically taylored the schemas.
+                       // Domain IDs might use the form <DB>-<project>-<language>, meaning that
+                       // the schema portion must be accounted for to disambiguate wikis.
+                       return $curDomain->equals( $domain );
+               }
+
                return (
                        $curDomain->getDatabase() === $domain->getDatabase() &&
-                       // @TODO: check schema instead of assuming it's ""/"mediawiki" and never collides
                        $curDomain->getTablePrefix() === $domain->getTablePrefix()
                );
        }
index 5a63d32..baf2b5b 100644 (file)
@@ -82,7 +82,7 @@
        "config-db-host-oracle": "Database TNS:",
        "config-db-host-oracle-help": "Enter a valid [http://download.oracle.com/docs/cd/B28359_01/network.111/b28317/tnsnames.htm Local Connect Name]; a tnsnames.ora file must be visible to this installation.<br />If you are using client libraries 10g or newer you can also use the [http://download.oracle.com/docs/cd/E11882_01/network.112/e10836/naming.htm Easy Connect] naming method.",
        "config-db-wiki-settings": "Identify this wiki",
-       "config-db-name": "Database name:",
+       "config-db-name": "Database name (no hyphens):",
        "config-db-name-help": "Choose a name that identifies your wiki.\nIt should not contain spaces.\n\nIf you are using shared web hosting, your hosting provider will either give you a specific database name to use or let you create databases via a control panel.",
        "config-db-name-oracle": "Database schema:",
        "config-db-account-oracle-warn": "There are three supported scenarios for installing Oracle as database backend:\n\nIf you wish to create database account as part of the installation process, please supply an account with SYSDBA role as database account for installation and specify the desired credentials for the web-access account, otherwise you can either create the web-access account manually and supply only that account (if it has required permissions to create the schema objects) or supply two different accounts, one with create privileges and a restricted one for web access.\n\nScript for creating an account with required privileges can be found in \"maintenance/oracle/\" directory of this installation. Keep in mind that using a restricted account will disable all maintenance capabilities with the default account.",
        "config-db-account-lock": "Use the same username and password during normal operation",
        "config-db-wiki-account": "User account for normal operation",
        "config-db-wiki-help": "Enter the username and password that will be used to connect to the database during normal wiki operation.\nIf the account does not exist, and the installation account has sufficient privileges, this user account will be created with the minimum privileges required to operate the wiki.",
-       "config-db-prefix": "Database table prefix:",
+       "config-db-prefix": "Database table prefix (no hyphens):",
        "config-db-prefix-help": "If you need to share one database between multiple wikis, or between MediaWiki and another web application, you may choose to add a prefix to all the table names to avoid conflicts.\nDo not use spaces.\n\nThis field is usually left empty.",
        "config-mysql-old": "MySQL $1 or later is required. You have $2.",
        "config-db-port": "Database port:",
-       "config-db-schema": "Schema for MediaWiki:",
+       "config-db-schema": "Schema for MediaWiki  (no hyphens):",
        "config-db-schema-help": "This schema will usually be fine.\nOnly change it if you know you need to.",
        "config-pg-test-error": "Cannot connect to database <strong>$1</strong>: $2",
        "config-sqlite-dir": "SQLite data directory:",
index 22d5c33..7d34f32 100644 (file)
@@ -30,7 +30,7 @@ use MediaWiki\MediaWikiServices;
  */
 abstract class JobQueue {
        /** @var string Wiki ID */
-       protected $wiki;
+       protected $domain;
        /** @var string Job type */
        protected $type;
        /** @var string Job priority for pop() */
@@ -56,7 +56,7 @@ abstract class JobQueue {
         * @throws MWException
         */
        protected function __construct( array $params ) {
-               $this->wiki = $params['wiki'];
+               $this->domain = $params['domain'] ?? $params['wiki']; // b/c
                $this->type = $params['type'];
                $this->claimTTL = $params['claimTTL'] ?? 0;
                $this->maxTries = $params['maxTries'] ?? 3;
@@ -117,8 +117,16 @@ abstract class JobQueue {
        /**
         * @return string Wiki ID
         */
+       final public function getDomain() {
+               return $this->domain;
+       }
+
+       /**
+        * @return string Wiki ID
+        * @deprecated 1.33
+        */
        final public function getWiki() {
-               return $this->wiki;
+               return $this->domain;
        }
 
        /**
@@ -330,7 +338,7 @@ abstract class JobQueue {
                }
 
                $this->doBatchPush( $jobs, $flags );
-               $this->aggr->notifyQueueNonEmpty( $this->wiki, $this->type );
+               $this->aggr->notifyQueueNonEmpty( $this->domain, $this->type );
 
                foreach ( $jobs as $job ) {
                        if ( $job->isRootJob() ) {
@@ -358,8 +366,9 @@ abstract class JobQueue {
                global $wgJobClasses;
 
                $this->assertNotReadOnly();
-               if ( !WikiMap::isCurrentWikiId( $this->wiki ) ) {
-                       throw new MWException( "Cannot pop '{$this->type}' job off foreign wiki queue." );
+               if ( !WikiMap::isCurrentWikiDomain( $this->domain ) ) {
+                       throw new MWException(
+                               "Cannot pop '{$this->type}' job off foreign '{$this->domain}' wiki queue." );
                } elseif ( !isset( $wgJobClasses[$this->type] ) ) {
                        // Do not pop jobs if there is no class for the queue type
                        throw new MWException( "Unrecognized job type '{$this->type}'." );
@@ -368,7 +377,7 @@ abstract class JobQueue {
                $job = $this->doPop();
 
                if ( !$job ) {
-                       $this->aggr->notifyQueueEmpty( $this->wiki, $this->type );
+                       $this->aggr->notifyQueueEmpty( $this->domain, $this->type );
                }
 
                // Flag this job as an old duplicate based on its "root" job...
@@ -522,9 +531,13 @@ abstract class JobQueue {
         * @return string
         */
        protected function getRootJobCacheKey( $signature ) {
-               list( $db, $prefix ) = wfSplitWikiID( $this->wiki );
-
-               return wfForeignMemcKey( $db, $prefix, 'jobqueue', $this->type, 'rootjob', $signature );
+               $this->dupCache->makeGlobalKey(
+                       'jobqueue',
+                       $this->domain,
+                       $this->type,
+                       'rootjob',
+                       $signature
+               );
        }
 
        /**
index 0ae106d..c572559 100644 (file)
@@ -542,7 +542,8 @@ class JobQueueDB extends JobQueue {
         */
        protected function doWaitForBackups() {
                $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
-               $lbFactory->waitForReplication( [ 'wiki' => $this->wiki, 'cluster' => $this->cluster ] );
+               $lbFactory->waitForReplication(
+                       [ 'domain' => $this->domain, 'cluster' => $this->cluster ] );
        }
 
        /**
@@ -598,8 +599,8 @@ class JobQueueDB extends JobQueue {
 
        public function getCoalesceLocationInternal() {
                return $this->cluster
-                       ? "DBCluster:{$this->cluster}:{$this->wiki}"
-                       : "LBFactory:{$this->wiki}";
+                       ? "DBCluster:{$this->cluster}:{$this->domain}"
+                       : "LBFactory:{$this->domain}";
        }
 
        protected function doGetSiblingQueuesWithJobs( array $types ) {
@@ -681,7 +682,7 @@ class JobQueueDB extends JobQueue {
                                        $affected = $dbw->affectedRows();
                                        $count += $affected;
                                        JobQueue::incrStats( 'recycles', $this->type, $affected );
-                                       $this->aggr->notifyQueueNonEmpty( $this->wiki, $this->type );
+                                       $this->aggr->notifyQueueNonEmpty( $this->domain, $this->type );
                                }
                        }
 
@@ -772,14 +773,14 @@ class JobQueueDB extends JobQueue {
                $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
                $lb = ( $this->cluster !== false )
                        ? $lbFactory->getExternalLB( $this->cluster )
-                       : $lbFactory->getMainLB( $this->wiki );
+                       : $lbFactory->getMainLB( $this->domain );
 
                return ( $lb->getServerType( $lb->getWriterIndex() ) !== 'sqlite' )
                        // Keep a separate connection to avoid contention and deadlocks;
                        // However, SQLite has the opposite behavior due to DB-level locking.
-                       ? $lb->getConnectionRef( $index, [], $this->wiki, $lb::CONN_TRX_AUTOCOMMIT )
+                       ? $lb->getConnectionRef( $index, [], $this->domain, $lb::CONN_TRX_AUTOCOMMIT )
                        // Jobs insertion will be defered until the PRESEND stage to reduce contention.
-                       : $lb->getConnectionRef( $index, [], $this->wiki );
+                       : $lb->getConnectionRef( $index, [], $this->domain );
        }
 
        /**
@@ -790,7 +791,12 @@ class JobQueueDB extends JobQueue {
                $cluster = is_string( $this->cluster ) ? $this->cluster : 'main';
 
                return $this->cache->makeGlobalKey(
-                       'jobqueue', $this->wiki, $cluster, $this->type, $property );
+                       'jobqueue',
+                       $this->domain,
+                       $cluster,
+                       $this->type,
+                       $property
+               );
        }
 
        /**
index 0f8fcfb..26886b7 100644 (file)
@@ -73,7 +73,7 @@ class JobQueueFederated extends JobQueue {
         */
        protected function __construct( array $params ) {
                parent::__construct( $params );
-               $section = $params['sectionsByWiki'][$this->wiki] ?? 'default';
+               $section = $params['sectionsByWiki'][$this->domain] ?? 'default';
                if ( !isset( $params['partitionsBySection'][$section] ) ) {
                        throw new MWException( "No configuration for section '$section'." );
                }
@@ -419,7 +419,7 @@ class JobQueueFederated extends JobQueue {
        }
 
        public function getCoalesceLocationInternal() {
-               return "JobQueueFederated:wiki:{$this->wiki}" .
+               return "JobQueueFederated:wiki:{$this->domain}" .
                        sha1( serialize( array_keys( $this->partitionQueues ) ) );
        }
 
index 3d88089..b103b8e 100644 (file)
@@ -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::getCurrentWikiDomain()->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::getWikiIdFromDomain( $domain );
+                       if (
+                               !WikiMap::isCurrentWikiDomain( $domain ) &&
+                               !in_array( $wikiId, $wgLocalDatabases )
+                       ) {
+                               self::$instances[$domain]->invalidDomain = true;
                        }
                }
 
-               return self::$instances[$wiki];
+               return self::$instances[$domain];
        }
 
        /**
@@ -101,8 +108,12 @@ class JobQueueGroup {
        public function get( $type ) {
                global $wgJobTypeConf;
 
-               $conf = [ 'wiki' => $this->wiki, 'type' => $type ];
-               $conf += $wgJobTypeConf[$type] ?? $wgJobTypeConf['default'];
+               $conf = [ 'domain' => $this->domain, 'type' => $type ];
+               if ( isset( $wgJobTypeConf[$type] ) ) {
+                       $conf = $conf + $wgJobTypeConf[$type];
+               } else {
+                       $conf = $conf + $wgJobTypeConf['default'];
+               }
                $conf['aggregator'] = JobQueueAggregator::singleton();
                if ( !isset( $conf['readOnlyReason'] ) ) {
                        $conf['readOnlyReason'] = $this->readOnlyReason;
@@ -124,9 +135,9 @@ 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;
                }
@@ -156,13 +167,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 +192,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 +207,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 +335,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 ) {
@@ -393,7 +404,7 @@ class JobQueueGroup {
                        $this->coalescedQueues = [];
                        foreach ( $wgJobTypeConf as $type => $conf ) {
                                $queue = JobQueue::factory(
-                                       [ 'wiki' => $this->wiki, 'type' => 'null' ] + $conf );
+                                       [ 'wiki' => $this->domain, 'type' => 'null' ] + $conf );
                                $loc = $queue->getCoalesceLocationInternal();
                                if ( !isset( $this->coalescedQueues[$loc] ) ) {
                                        $this->coalescedQueues[$loc]['queue'] = $queue;
@@ -419,17 +430,17 @@ class JobQueueGroup {
         */
        private function getCachedConfigVar( $name ) {
                // @TODO: cleanup this whole method with a proper config system
-               if ( WikiMap::isCurrentWikiId( $this->wiki ) ) {
+               if ( WikiMap::isCurrentWikiDomain( $this->domain ) ) {
                        return $GLOBALS[$name]; // common case
                } else {
-                       $wiki = $this->wiki;
-                       $cache = ObjectCache::getMainWANInstance();
+                       $wiki = WikiMap::getWikiIdFromDomain( $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 ]
index f9e2c3d..9b1fbdf 100644 (file)
@@ -155,8 +155,8 @@ class JobQueueMemory extends JobQueue {
         * @see JobQueue::doDelete
         */
        protected function doDelete() {
-               if ( isset( self::$data[$this->type][$this->wiki] ) ) {
-                       unset( self::$data[$this->type][$this->wiki] );
+               if ( isset( self::$data[$this->type][$this->domain] ) ) {
+                       unset( self::$data[$this->type][$this->domain] );
                        if ( !self::$data[$this->type] ) {
                                unset( self::$data[$this->type] );
                        }
@@ -217,14 +217,14 @@ class JobQueueMemory extends JobQueue {
         * @return mixed
         */
        private function &getQueueData( $field, $init = null ) {
-               if ( !isset( self::$data[$this->type][$this->wiki][$field] ) ) {
+               if ( !isset( self::$data[$this->type][$this->domain][$field] ) ) {
                        if ( $init !== null ) {
-                               self::$data[$this->type][$this->wiki][$field] = $init;
+                               self::$data[$this->type][$this->domain][$field] = $init;
                        } else {
                                return $init;
                        }
                }
 
-               return self::$data[$this->type][$this->wiki][$field];
+               return self::$data[$this->type][$this->domain][$field];
        }
 }
index e9505bc..b868128 100644 (file)
@@ -776,7 +776,7 @@ LUA;
         * @return string JSON
         */
        private function encodeQueueName() {
-               return json_encode( [ $this->type, $this->wiki ] );
+               return json_encode( [ $this->type, $this->domain ] );
        }
 
        /**
@@ -809,8 +809,9 @@ LUA;
         */
        private function getQueueKey( $prop, $type = null ) {
                $type = is_string( $type ) ? $type : $this->type;
-               list( $db, $prefix ) = wfSplitWikiID( $this->wiki );
-               $keyspace = $prefix ? "$db-$prefix" : $db;
+
+               // Use wiki ID for b/c
+               $keyspace = WikiMap::getWikiIdFromDomain( $this->domain );
 
                $parts = [ $keyspace, 'jobqueue', $type, $prop ];
 
index 433de93..27ad88e 100644 (file)
@@ -148,9 +148,9 @@ abstract class JobQueueAggregator {
                global $wgLocalDatabases;
 
                $pendingDBs = []; // (job type => (db list))
-               foreach ( $wgLocalDatabases as $db ) {
-                       foreach ( JobQueueGroup::singleton( $db )->getQueuesWithJobs() as $type ) {
-                               $pendingDBs[$type][] = $db;
+               foreach ( $wgLocalDatabases as $wikiId ) {
+                       foreach ( JobQueueGroup::singleton( $wikiId )->getQueuesWithJobs() as $type ) {
+                               $pendingDBs[$type][] = $wikiId;
                        }
                }
 
index 488c915..e31f1f9 100644 (file)
@@ -60,7 +60,7 @@ class ManageJobs extends Maintenance {
 
        private function repushAbandoned( JobQueue $queue ) {
                $cache = ObjectCache::getInstance( CACHE_DB );
-               $key = $cache->makeGlobalKey( 'last-job-repush', $queue->getWiki(), $queue->getType() );
+               $key = $cache->makeGlobalKey( 'last-job-repush', $queue->getDomain(), $queue->getType() );
 
                $now = wfTimestampNow();
                $lastRepushTime = $cache->get( $key );
index 199f638..1fb8aff 100644 (file)
@@ -239,7 +239,11 @@ class WikiMapTest extends MediaWikiLangTestCase {
                return [
                        [ 'db-prefix', 'db-prefix' ],
                        [ wfWikiID(), wfWikiID() ],
-                       [ new DatabaseDomain( 'db-dash', null, 'prefix' ), 'db-dash-prefix' ]
+                       [ new DatabaseDomain( 'db-dash', null, 'prefix' ), 'db-dash-prefix' ],
+                       [ wfWikiID(), wfWikiID() ],
+                       [ new DatabaseDomain( 'db-dash', null, 'prefix' ), 'db-dash-prefix' ],
+                       [ new DatabaseDomain( 'db', 'mediawiki', 'prefix' ), 'db-prefix' ], // schema ignored
+                       [ new DatabaseDomain( 'db', 'custom', 'prefix' ), 'db-custom-prefix' ],
                ];
        }
 
@@ -273,12 +277,17 @@ class WikiMapTest extends MediaWikiLangTestCase {
        public function provideIsCurrentWikiId() {
                return [
                        [ 'db', 'db', null, '' ],
-                       [ 'db','db', 'schema', '' ],
+                       [ 'db-schema-','db', 'schema', '' ],
+                       [ 'db','db', 'mediawiki', '' ], // common b/c case
                        [ 'db-prefix', 'db', null, 'prefix' ],
-                       [ 'db-prefix', 'db', 'schema', 'prefix' ],
+                       [ 'db-schema-prefix', 'db', 'schema', 'prefix' ],
+                       [ 'db-prefix', 'db', 'mediawiki', 'prefix' ], // common b/c case
                        // Bad hyphen cases (best effort support)
                        [ 'db-stuff', 'db-stuff', null, '' ],
-                       [ 'db-stuff-prefix', 'db-stuff', null, 'prefix' ]
+                       [ 'db-stuff-prefix', 'db-stuff', null, 'prefix' ],
+                       [ 'db-stuff-schema-', 'db-stuff', 'schema', '' ],
+                       [ 'db-stuff-schema-prefix', 'db-stuff', 'schema', 'prefix' ],
+                       [ 'db-stuff-prefix', 'db-stuff', 'mediawiki', 'prefix' ] // common b/c case
                ];
        }
 
index 64dde77..0421fe7 100644 (file)
@@ -75,6 +75,7 @@ class JobQueueTest extends MediaWikiTestCase {
                        $this->markTestSkipped( $desc );
                }
                $this->assertEquals( wfWikiID(), $queue->getWiki(), "Proper wiki ID ($desc)" );
+               $this->assertEquals( wfWikiID(), $queue->getDomain(), "Proper wiki ID ($desc)" );
        }
 
        /**
@@ -388,6 +389,6 @@ class JobQueueDBSingle extends JobQueueDB {
        protected function getDB( $index ) {
                $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
                // Override to not use CONN_TRX_AUTOCOMMIT so that we see the same temporary `job` table
-               return $lb->getConnection( $index, [], $this->wiki );
+               return $lb->getConnection( $index, [], $this->domain );
        }
 }