Clean up wiki ID and DB domain ID handling
Bug: T174017 Change-Id: I42299a393c6691d39817db1d83a176a17df2474b
This commit is contained in:
parent
9617de6144
commit
a005f1de98
11 changed files with 68 additions and 24 deletions
|
|
@ -362,7 +362,7 @@ class Revision implements IDBAccessObject {
|
|||
$row = self::fetchFromConds( $db, $conditions, $flags );
|
||||
if ( $row ) {
|
||||
$rev = new Revision( $row );
|
||||
$rev->mWiki = $db->getWikiID();
|
||||
$rev->mWiki = $db->getDomainID();
|
||||
|
||||
return $rev;
|
||||
}
|
||||
|
|
@ -1941,7 +1941,7 @@ class Revision implements IDBAccessObject {
|
|||
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
|
||||
return $cache->getWithSetCallback(
|
||||
// Page/rev IDs passed in from DB to reflect history merges
|
||||
$cache->makeGlobalKey( 'revision', $db->getWikiID(), $pageId, $revId ),
|
||||
$cache->makeGlobalKey( 'revision', $db->getDomainID(), $pageId, $revId ),
|
||||
$cache::TTL_WEEK,
|
||||
function ( $curValue, &$ttl, array &$setOpts ) use ( $db, $pageId, $revId ) {
|
||||
$setOpts += Database::getCacheSetOptions( $db );
|
||||
|
|
|
|||
|
|
@ -766,7 +766,7 @@ class WatchedItemStore implements StatsdAwareInterface {
|
|||
);
|
||||
if ( count( $watchersChunks ) > 1 ) {
|
||||
$factory->commitAndWaitForReplication(
|
||||
__METHOD__, $ticket, [ 'wiki' => $dbw->getWikiID() ]
|
||||
__METHOD__, $ticket, [ 'domain' => $dbw->getDomainID() ]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
*/
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\Rdbms\DatabaseDomain;
|
||||
|
||||
/**
|
||||
* Helper tools for dealing with other locally-hosted wikis.
|
||||
|
|
@ -239,4 +240,22 @@ class WikiMap {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the wiki ID of a database domain
|
||||
*
|
||||
* This is like DatabaseDomain::getId() without encoding (for legacy reasons)
|
||||
*
|
||||
* @param string|DatabaseDomain $domain
|
||||
* @return string
|
||||
*/
|
||||
public static function getWikiIdFromDomain( $domain ) {
|
||||
if ( !( $domain instanceof DatabaseDomain ) ) {
|
||||
$domain = DatabaseDomain::newFromId( $domain );
|
||||
}
|
||||
|
||||
return strlen( $domain->getTablePrefix() )
|
||||
? "{$domain->getDatabase()}-{$domain->getTablePrefix()}"
|
||||
: $domain->getDatabase();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ class LinksDeletionUpdate extends DataUpdate implements EnqueueableDataUpdate {
|
|||
$this->page->updateCategoryCounts( [], $catBatch, $id );
|
||||
if ( count( $catBatches ) > 1 ) {
|
||||
$lbFactory->commitAndWaitForReplication(
|
||||
__METHOD__, $this->ticket, [ 'wiki' => $dbw->getWikiID() ]
|
||||
__METHOD__, $this->ticket, [ 'domain' => $dbw->getDomainID() ]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -187,7 +187,7 @@ class LinksDeletionUpdate extends DataUpdate implements EnqueueableDataUpdate {
|
|||
$dbw->delete( 'recentchanges', [ 'rc_id' => $rcIdBatch ], __METHOD__ );
|
||||
if ( count( $rcIdBatches ) > 1 ) {
|
||||
$lbFactory->commitAndWaitForReplication(
|
||||
__METHOD__, $this->ticket, [ 'wiki' => $dbw->getWikiID() ]
|
||||
__METHOD__, $this->ticket, [ 'domain' => $dbw->getDomainID() ]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -209,7 +209,7 @@ class LinksDeletionUpdate extends DataUpdate implements EnqueueableDataUpdate {
|
|||
if ( count( $pkDeleteConds ) >= $bSize ) {
|
||||
$dbw->delete( $table, $dbw->makeList( $pkDeleteConds, LIST_OR ), __METHOD__ );
|
||||
$lbFactory->commitAndWaitForReplication(
|
||||
__METHOD__, $this->ticket, [ 'wiki' => $dbw->getWikiID() ]
|
||||
__METHOD__, $this->ticket, [ 'domain' => $dbw->getDomainID() ]
|
||||
);
|
||||
$pkDeleteConds = [];
|
||||
}
|
||||
|
|
@ -230,7 +230,7 @@ class LinksDeletionUpdate extends DataUpdate implements EnqueueableDataUpdate {
|
|||
|
||||
public function getAsJobSpecification() {
|
||||
return [
|
||||
'wiki' => $this->getDB()->getWikiID(),
|
||||
'wiki' => WikiMap::getWikiIdFromDomain( $this->getDB()->getDomainID() ),
|
||||
'job' => new JobSpecification(
|
||||
'deleteLinks',
|
||||
[ 'pageId' => $this->pageId, 'timestamp' => $this->timestamp ],
|
||||
|
|
|
|||
|
|
@ -366,20 +366,22 @@ class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate {
|
|||
return;
|
||||
}
|
||||
|
||||
$wikiId = $this->getDB()->getWikiID();
|
||||
$domainId = $this->getDB()->getDomainID();
|
||||
$wp = WikiPage::factory( $this->mTitle );
|
||||
$lbf = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
||||
// T163801: try to release any row locks to reduce contention
|
||||
$lbf->commitAndWaitForReplication( __METHOD__, $this->ticket, [ 'wiki' => $wikiId ] );
|
||||
$lbf->commitAndWaitForReplication( __METHOD__, $this->ticket, [ 'domain' => $domainId ] );
|
||||
|
||||
foreach ( array_chunk( array_keys( $added ), $wgUpdateRowsPerQuery ) as $addBatch ) {
|
||||
$wp->updateCategoryCounts( $addBatch, [], $this->mId );
|
||||
$lbf->commitAndWaitForReplication( __METHOD__, $this->ticket, [ 'wiki' => $wikiId ] );
|
||||
$lbf->commitAndWaitForReplication(
|
||||
__METHOD__, $this->ticket, [ 'domain' => $domainId ] );
|
||||
}
|
||||
|
||||
foreach ( array_chunk( array_keys( $deleted ), $wgUpdateRowsPerQuery ) as $deleteBatch ) {
|
||||
$wp->updateCategoryCounts( [], $deleteBatch, $this->mId );
|
||||
$lbf->commitAndWaitForReplication( __METHOD__, $this->ticket, [ 'wiki' => $wikiId ] );
|
||||
$lbf->commitAndWaitForReplication(
|
||||
__METHOD__, $this->ticket, [ 'domain' => $domainId ] );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -450,10 +452,12 @@ class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate {
|
|||
}
|
||||
}
|
||||
|
||||
$domainId = $this->getDB()->getDomainID();
|
||||
|
||||
foreach ( $deleteWheres as $deleteWhere ) {
|
||||
$this->getDB()->delete( $table, $deleteWhere, __METHOD__ );
|
||||
$lbf->commitAndWaitForReplication(
|
||||
__METHOD__, $this->ticket, [ 'wiki' => $this->getDB()->getWikiID() ]
|
||||
__METHOD__, $this->ticket, [ 'domain' => $domainId ]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -461,7 +465,7 @@ class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate {
|
|||
foreach ( $insertBatches as $insertBatch ) {
|
||||
$this->getDB()->insert( $table, $insertBatch, __METHOD__, 'IGNORE' );
|
||||
$lbf->commitAndWaitForReplication(
|
||||
__METHOD__, $this->ticket, [ 'wiki' => $this->getDB()->getWikiID() ]
|
||||
__METHOD__, $this->ticket, [ 'domain' => $domainId ]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -1143,7 +1147,7 @@ class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate {
|
|||
}
|
||||
|
||||
return [
|
||||
'wiki' => $this->getDB()->getWikiID(),
|
||||
'wiki' => WikiMap::getWikiIdFromDomain( $this->getDB()->getDomainID() ),
|
||||
'job' => new JobSpecification(
|
||||
'refreshLinksPrioritized',
|
||||
[
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class WANCacheReapUpdate implements DeferrableUpdate {
|
|||
[ $this, 'getTitleChangeEvents' ],
|
||||
[ $this, 'getEventAffectedKeys' ],
|
||||
[
|
||||
'channel' => 'table:recentchanges:' . $this->db->getWikiID(),
|
||||
'channel' => 'table:recentchanges:' . $this->db->getDomainID(),
|
||||
'logger' => $this->logger
|
||||
]
|
||||
);
|
||||
|
|
|
|||
|
|
@ -346,6 +346,7 @@ interface IDatabase {
|
|||
* Alias for getDomainID()
|
||||
*
|
||||
* @return string
|
||||
* @deprecated 1.30
|
||||
*/
|
||||
public function getWikiID();
|
||||
|
||||
|
|
|
|||
|
|
@ -373,7 +373,7 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule {
|
|||
if ( $module instanceof self ) {
|
||||
$mDB = $module->getDB();
|
||||
// Subclasses may disable getDB and implement getTitleInfo differently
|
||||
if ( $mDB && $mDB->getWikiID() === $db->getWikiID() ) {
|
||||
if ( $mDB && $mDB->getDomainID() === $db->getDomainID() ) {
|
||||
$wikiModules[] = $module;
|
||||
$allPages += $module->getPages( $context );
|
||||
}
|
||||
|
|
@ -395,14 +395,17 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule {
|
|||
|
||||
$cache = ObjectCache::getMainWANInstance();
|
||||
$allInfo = $cache->getWithSetCallback(
|
||||
$cache->makeGlobalKey( 'resourceloader', 'titleinfo', $db->getWikiID(), $hash ),
|
||||
$cache->makeGlobalKey( 'resourceloader', 'titleinfo', $db->getDomainID(), $hash ),
|
||||
$cache::TTL_HOUR,
|
||||
function ( $curVal, &$ttl, array &$setOpts ) use ( $func, $pageNames, $db, $fname ) {
|
||||
$setOpts += Database::getCacheSetOptions( $db );
|
||||
|
||||
return call_user_func( $func, $db, $pageNames, $fname );
|
||||
},
|
||||
[ 'checkKeys' => [ $cache->makeGlobalKey( 'resourceloader', 'titleinfo', $db->getWikiID() ) ] ]
|
||||
[
|
||||
'checkKeys' => [
|
||||
$cache->makeGlobalKey( 'resourceloader', 'titleinfo', $db->getDomainID() ) ]
|
||||
]
|
||||
);
|
||||
|
||||
foreach ( $wikiModules as $wikiModule ) {
|
||||
|
|
|
|||
|
|
@ -277,11 +277,11 @@ class UserRightsProxy {
|
|||
__METHOD__
|
||||
);
|
||||
|
||||
$wikiId = $this->db->getWikiID();
|
||||
$domainId = $this->db->getDomainID();
|
||||
$userId = $this->id;
|
||||
$this->db->onTransactionPreCommitOrIdle(
|
||||
function () use ( $wikiId, $userId ) {
|
||||
User::purge( $wikiId, $userId );
|
||||
function () use ( $domainId, $userId ) {
|
||||
User::purge( $domainId, $userId );
|
||||
},
|
||||
__METHOD__
|
||||
);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
/**
|
||||
* Usage:
|
||||
|
|
@ -45,9 +46,8 @@ class PopulateContentModel extends Maintenance {
|
|||
public function execute() {
|
||||
$dbw = $this->getDB( DB_MASTER );
|
||||
|
||||
$this->wikiId = $dbw->getWikiID();
|
||||
|
||||
$this->wanCache = ObjectCache::getMainWANInstance();
|
||||
$this->wikiId = $dbw->getDomainID();
|
||||
$this->wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
|
||||
|
||||
$ns = $this->getOption( 'ns' );
|
||||
if ( !ctype_digit( $ns ) && $ns !== 'all' ) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
use Wikimedia\Rdbms\DatabaseDomain;
|
||||
|
||||
/**
|
||||
* @covers WikiMap
|
||||
|
|
@ -233,4 +234,20 @@ class WikiMapTest extends MediaWikiLangTestCase {
|
|||
public function testGetWikiFromUrl( $url, $wiki ) {
|
||||
$this->assertEquals( $wiki, WikiMap::getWikiFromUrl( $url ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideGetWikiIdFromDomain
|
||||
* @covers WikiMap::getWikiIdFromDomain()
|
||||
*/
|
||||
public function testGetWikiIdFromDomain( $domain, $wikiId ) {
|
||||
$this->assertEquals( $wikiId, WikiMap::getWikiIdFromDomain( $domain ) );
|
||||
}
|
||||
|
||||
public function provideGetWikiIdFromDomain() {
|
||||
return [
|
||||
[ 'db-prefix', 'db-prefix' ],
|
||||
[ wfWikiID(), wfWikiID() ],
|
||||
[ new DatabaseDomain( 'db-dash', null, 'prefix' ), 'db-dash-prefix' ]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue