Aaron Schulz has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/380471 )
Change subject: Clean up wiki ID and DB domain ID handling
......................................................................
Clean up wiki ID and DB domain ID handling
Bug: T174017
Change-Id: I42299a393c6691d39817db1d83a176a17df2474b
---
M includes/Revision.php
M includes/WatchedItemStore.php
M includes/WikiMap.php
M includes/deferred/LinksDeletionUpdate.php
M includes/deferred/LinksUpdate.php
M includes/deferred/WANCacheReapUpdate.php
M includes/libs/rdbms/database/IDatabase.php
M includes/resourceloader/ResourceLoaderWikiModule.php
M includes/user/UserRightsProxy.php
M maintenance/populateContentModel.php
M tests/phpunit/includes/WikiMapTest.php
11 files changed, 64 insertions(+), 28 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/71/380471/1
diff --git a/includes/Revision.php b/includes/Revision.php
index 006e700..bcfbe63 100644
--- a/includes/Revision.php
+++ b/includes/Revision.php
@@ -362,7 +362,7 @@
$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 @@
$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 );
diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php
index 69a9df2..60d8b76 100644
--- a/includes/WatchedItemStore.php
+++ b/includes/WatchedItemStore.php
@@ -766,7 +766,7 @@
);
if ( count( $watchersChunks ) >
1 ) {
$factory->commitAndWaitForReplication(
- __METHOD__,
$ticket, [ 'wiki' => $dbw->getWikiID() ]
+ __METHOD__,
$ticket, [ 'domain' => $dbw->getDomainID() ]
);
}
}
diff --git a/includes/WikiMap.php b/includes/WikiMap.php
index 4f3c461..8bb37b5 100644
--- a/includes/WikiMap.php
+++ b/includes/WikiMap.php
@@ -21,6 +21,7 @@
*/
use MediaWiki\MediaWikiServices;
+use Wikimedia\Rdbms\DatabaseDomain;
/**
* Helper tools for dealing with other locally-hosted wikis.
@@ -239,4 +240,22 @@
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();
+ }
}
diff --git a/includes/deferred/LinksDeletionUpdate.php
b/includes/deferred/LinksDeletionUpdate.php
index f579a1f..52e996a 100644
--- a/includes/deferred/LinksDeletionUpdate.php
+++ b/includes/deferred/LinksDeletionUpdate.php
@@ -91,7 +91,7 @@
$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 @@
$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 @@
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 @@
public function getAsJobSpecification() {
return [
- 'wiki' => $this->getDB()->getWikiID(),
+ 'wiki' => WikiMap::getWikiIdFromDomain(
$this->getDB()->getDomainID() ),
'job' => new JobSpecification(
'deleteLinks',
[ 'pageId' => $this->pageId, 'timestamp' =>
$this->timestamp ],
diff --git a/includes/deferred/LinksUpdate.php
b/includes/deferred/LinksUpdate.php
index 33d4e70..dfe89ba 100644
--- a/includes/deferred/LinksUpdate.php
+++ b/includes/deferred/LinksUpdate.php
@@ -366,20 +366,22 @@
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 @@
}
}
+ $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 @@
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 @@
}
return [
- 'wiki' => $this->getDB()->getWikiID(),
+ 'wiki' => WikiMap::getWikiIdFromDomain(
$this->getDB()->getDomainID() ),
'job' => new JobSpecification(
'refreshLinksPrioritized',
[
diff --git a/includes/deferred/WANCacheReapUpdate.php
b/includes/deferred/WANCacheReapUpdate.php
index 2e5298c..5ffc938 100644
--- a/includes/deferred/WANCacheReapUpdate.php
+++ b/includes/deferred/WANCacheReapUpdate.php
@@ -43,7 +43,7 @@
[ $this, 'getTitleChangeEvents' ],
[ $this, 'getEventAffectedKeys' ],
[
- 'channel' => 'table:recentchanges:' .
$this->db->getWikiID(),
+ 'channel' => 'table:recentchanges:' .
$this->db->getDomainID(),
'logger' => $this->logger
]
);
diff --git a/includes/libs/rdbms/database/IDatabase.php
b/includes/libs/rdbms/database/IDatabase.php
index 78889e5..5d0e03f 100644
--- a/includes/libs/rdbms/database/IDatabase.php
+++ b/includes/libs/rdbms/database/IDatabase.php
@@ -346,6 +346,7 @@
* Alias for getDomainID()
*
* @return string
+ * @deprecated 1.30
*/
public function getWikiID();
diff --git a/includes/resourceloader/ResourceLoaderWikiModule.php
b/includes/resourceloader/ResourceLoaderWikiModule.php
index fd31eac..bebc188 100644
--- a/includes/resourceloader/ResourceLoaderWikiModule.php
+++ b/includes/resourceloader/ResourceLoaderWikiModule.php
@@ -373,7 +373,7 @@
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 @@
$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 ) {
diff --git a/includes/user/UserRightsProxy.php
b/includes/user/UserRightsProxy.php
index 98586e7..3c2731a 100644
--- a/includes/user/UserRightsProxy.php
+++ b/includes/user/UserRightsProxy.php
@@ -277,11 +277,11 @@
__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__
);
diff --git a/maintenance/populateContentModel.php
b/maintenance/populateContentModel.php
index 7d83180..74a918a 100644
--- a/maintenance/populateContentModel.php
+++ b/maintenance/populateContentModel.php
@@ -24,6 +24,7 @@
require_once __DIR__ . '/Maintenance.php';
use Wikimedia\Rdbms\IDatabase;
+use MediaWiki\MediaWikiServices;
/**
* Usage:
@@ -45,9 +46,8 @@
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' ) {
diff --git a/tests/phpunit/includes/WikiMapTest.php
b/tests/phpunit/includes/WikiMapTest.php
index 186ffdb..43f3e23 100644
--- a/tests/phpunit/includes/WikiMapTest.php
+++ b/tests/phpunit/includes/WikiMapTest.php
@@ -1,4 +1,5 @@
<?php
+use Wikimedia\Rdbms\DatabaseDomain;
/**
* @covers WikiMap
@@ -227,10 +228,18 @@
}
/**
- * @dataProvider provideGetWikiFromUrl
- * @covers WikiMap::getWikiFromUrl()
+ * @dataProvider provideGetWikiIdFromDomain
+ * @covers WikiMap::provideGetWikiIdFromDomain()
*/
- public function testGetWikiFromUrl( $url, $wiki ) {
- $this->assertEquals( $wiki, WikiMap::getWikiFromUrl( $url ) );
+ 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' ]
+ ];
}
}
--
To view, visit https://gerrit.wikimedia.org/r/380471
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I42299a393c6691d39817db1d83a176a17df2474b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits